Skip to content

Commit

Permalink
Merge branch 'devel-branch'
Browse files Browse the repository at this point in the history
  • Loading branch information
Helios-vmg committed Jun 29, 2016
2 parents 2846a49 + ab4a8ce commit 789d909
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 46 deletions.
7 changes: 5 additions & 2 deletions src/ImageViewerApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@ class DeserializationException : public std::exception {
case DeserializerStream::ErrorType::AllocateAbstractObject:
this->message = "The stream contains a concrete object with an abstract class type ID.";
break;
case DeserializerStream::ErrorType::AllocateObjectOfUnknownType:
this->message = "The stream contains an object of an unknown type. Did you try to import a configuration created by a newer version of the program?";
break;
default:
this->message = "Unknown.";
this->message = "Unknown error.";
break;
}
}
Expand All @@ -171,7 +174,7 @@ void ImageViewerApplication::save_settings(bool with_state){
return;
Settings settings;
settings.main = this->settings;
if (with_state)
if (with_state && this->settings->get_save_state_on_exit())
this->save_current_state(settings.state);
settings.shortcuts = this->shortcuts.save_settings();

Expand Down
13 changes: 12 additions & 1 deletion src/ImageViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ QMatrix translate(const QMatrix &m, const QPointF &offset){

void ImageViewport::paintEvent(QPaintEvent *){
QPainter painter(this);
if (!this->pixmap() && !this->movie()){
painter.setBrush(QBrush(Qt::white));
auto font = painter.font();
font.setPixelSize(48);
painter.setFont(font);
QRect rect(0, 0, 800, 600);
painter.fillRect(rect, Qt::black);
painter.drawText(rect, "No image");
return;
}

painter.setRenderHint(or_flags(QPainter::SmoothPixmapTransform, QPainter::Antialiasing));
painter.setClipping(false);

Expand All @@ -50,7 +61,7 @@ void ImageViewport::paintEvent(QPaintEvent *){
painter.setMatrix(transform);
if (this->pixmap())
painter.drawPixmap(QRect(QPoint(0, 0), this->image_size), *this->pixmap());
else if (this->movie())
else
painter.drawPixmap(QRect(QPoint(0, 0), this->image_size), this->movie()->currentPixmap());
}

Expand Down
2 changes: 2 additions & 0 deletions src/ImageViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class ImageViewport : public QLabel
size = this->compute_quad_no_zoom(size).get_bounding_box().size().toSize();
}
QSize get_size() const{
if (!this->pixmap() && !this->movie())
return QSize(800, 600);
auto ret = this->image_size;
this->compute_size(ret);
return ret;
Expand Down
25 changes: 13 additions & 12 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void MainWindow::set_background(bool force){

QWidget *p1 = this->ui->checkerboard;
QWidget *p2 = this->ui->solid;
if (!this->window_state->get_using_checkerboard_pattern()){
if (!this->window_state->get_using_checkerboard_pattern() && this->displayed_image){
this->set_solid(this->displayed_image->get_background_color());
std::swap(p1, p2);
}
Expand All @@ -222,12 +222,12 @@ void MainWindow::set_background_sizes(){
void MainWindow::show_nothing(){
qDebug() << "MainWindow::show_nothing()";
this->displayed_image.reset();
this->ui->label->setText("no image");
this->ui->label->setAlignment(Qt::AlignCenter);
this->set_solid(Qt::black);
this->resize(800, 600);
this->ui->label->move(0, 0);
this->ui->label->resize(this->size());
this->window_state->reset_border_size();
this->set_background_sizes();
this->resize_to_max();
}

void MainWindow::resize_to_max(){
Expand Down Expand Up @@ -294,7 +294,7 @@ void MainWindow::move_in_direction(bool forward){
this->open_path_and_display_image(**this->directory_iterator);
}

void MainWindow::open_path_and_display_image(QString path){
bool MainWindow::open_path_and_display_image(QString path){
std::shared_ptr<LoadedGraphics> li;
size_t i = 0;
auto &label = this->ui->label;
Expand All @@ -313,26 +313,27 @@ void MainWindow::open_path_and_display_image(QString path){
}else
break;
}
if (li->is_null()){
this->show_nothing();
return;
}
this->color_calculated = false;
label->move(0, 0);
QString current_directory,
current_filename;
split_path(current_directory, current_filename, path);
this->window_state->set_current_directory(current_directory.toStdWString());
this->window_state->set_current_filename(current_filename.toStdWString());
this->setWindowTitle(current_filename);
if (!this->directory_iterator)
this->directory_iterator = this->app->request_directory(current_directory);
if (li->is_null()){
this->show_nothing();
return false;
}
this->color_calculated = false;
label->move(0, 0);
this->setWindowTitle(current_filename);
this->displayed_image = li;

label->reset_transform();
this->set_zoom();

this->apply_zoom(true, 1);
return true;
}

void MainWindow::display_filtered_image(const std::shared_ptr<LoadedGraphics> &graphics){
Expand Down
5 changes: 4 additions & 1 deletion src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class MainWindow : public QMainWindow{
explicit MainWindow(ImageViewerApplication &app, const QStringList &arguments, QWidget *parent = 0);
explicit MainWindow(ImageViewerApplication &app, const std::shared_ptr<WindowState> &state, QWidget *parent = 0);
~MainWindow();
void open_path_and_display_image(QString path);
bool open_path_and_display_image(QString path);
void display_image_in_label(const std::shared_ptr<LoadedGraphics> &graphics, bool first_display);
void display_filtered_image(const std::shared_ptr<LoadedGraphics> &);
std::shared_ptr<WindowState> save_state() const;
Expand All @@ -144,6 +144,9 @@ class MainWindow : public QMainWindow{
}
void process_user_script(const QString &path);
QImage get_image() const;
ImageViewerApplication &get_app(){
return *this->app;
}

public slots:
void label_transform_updated();
Expand Down
6 changes: 4 additions & 2 deletions src/MainWindowSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ void MainWindow::restore_state(const std::shared_ptr<WindowState> &state){
path += QString::fromStdWString(this->window_state->get_current_filename());
auto temp_zoom_mode = this->window_state->get_zoom_mode();
this->window_state->set_zoom_mode(ZoomMode::Locked);
this->open_path_and_display_image(path);
this->ui->label->load_state(*state);
bool success = this->open_path_and_display_image(path);
this->ui->label->load_state(*this->window_state);
this->window_state->set_zoom_mode(temp_zoom_mode);

this->ui->label->move(this->window_state->get_label_pos().to_QPoint());
this->move(this->window_state->get_pos().to_QPoint());
if (!success)
return;
this->resize(this->window_state->get_size().to_QSize());
this->fix_positions_and_zoom();
}
Expand Down
19 changes: 16 additions & 3 deletions src/MainWindowShortcuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ void MainWindow::close_slot(){
}

void MainWindow::zoom_in_slot(){
if (!this->displayed_image)
return;
this->change_zoom(true);
}

void MainWindow::zoom_out_slot(){
if (!this->displayed_image)
return;
this->change_zoom(false);
}

Expand Down Expand Up @@ -144,6 +148,8 @@ void MainWindow::offset_image(const QPoint &offset){
}

void MainWindow::reset_zoom_slot(){
if (!this->displayed_image)
return;
int zoom = this->get_current_zoom();
this->set_current_zoom_mode(ZoomMode::Normal);
this->ui->label->reset_transform();
Expand All @@ -167,6 +173,8 @@ void cycle_zoom_mode(ZoomMode &mode){
}

void MainWindow::cycle_zoom_mode_slot(){
if (!this->displayed_image)
return;
auto mode = this->get_current_zoom_mode();
cycle_zoom_mode(mode);
this->set_current_zoom_mode(mode);
Expand All @@ -181,6 +189,8 @@ void toggle_lock_zoom(ZoomMode &mode){
}

void MainWindow::toggle_lock_zoom_slot(){
if (!this->displayed_image)
return;
auto mode = this->window_state->get_zoom_mode();
toggle_lock_zoom(mode);
this->window_state->set_zoom_mode(mode);
Expand Down Expand Up @@ -214,13 +224,16 @@ void MainWindow::toggle_fullscreen(){
auto zoom = this->get_current_zoom();
this->window_state->set_fullscreen(!this->window_state->get_fullscreen());
if (!this->window_state->get_fullscreen()){
this->apply_zoom(false, zoom);
if (this->displayed_image)
this->apply_zoom(false, zoom);
this->setGeometry(this->window_rect);
this->restore_image_pos();
}else{
this->save_image_pos(true);
this->set_zoom();
this->apply_zoom(false, zoom);
if (this->displayed_image){
this->set_zoom();
this->apply_zoom(false, zoom);
}
this->resolution_to_window_size();
this->reposition_image();
//this->move_image(QPoint(0, 0));
Expand Down
5 changes: 5 additions & 0 deletions src/OptionsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Distributed under a permissive license. See COPYING.txt for details.
#include "ImageViewerApplication.h"
#include <cassert>
#include <algorithm>
#include <QDesktopWidget>

ShortcutListModel::ShortcutListModel(const ApplicationShortcuts &shortcuts): items(shortcuts.get_current_shortcuts()){
this->sort();
Expand Down Expand Up @@ -180,6 +181,8 @@ OptionsDialog::OptionsDialog(ImageViewerApplication &app):
this->setup_shortcuts_list_view();
this->setup_general_options();
this->setup_signals();
auto geom = app.desktop()->availableGeometry(app.desktop()->screenNumber(this));
this->resize(geom.size() / 2);
}

void OptionsDialog::setup_command_input(){
Expand Down Expand Up @@ -209,6 +212,7 @@ void OptionsDialog::setup_general_options(){
this->ui->center_when_displayed_cb->setChecked(this->options->get_center_when_displayed());
this->ui->use_checkerboard_pattern_cb->setChecked(this->options->get_use_checkerboard_pattern());
this->ui->clamp_to_edges_cb->setChecked(this->options->get_clamp_to_edges());
this->ui->save_state_on_exit_cb->setChecked(this->options->get_save_state_on_exit());
this->ui->keep_application_running_cb->setChecked(this->options->get_keep_application_in_background());
this->ui->clamp_strength_spinbox->setValue(this->options->get_clamp_strength());
this->ui->zoom_mode_for_new_windows_cb->set_selected_item(this->options->get_zoom_mode_for_new_windows());
Expand Down Expand Up @@ -284,6 +288,7 @@ std::shared_ptr<MainSettings> OptionsDialog::build_options(){
ret->set_center_when_displayed(this->ui->center_when_displayed_cb->isChecked());
ret->set_use_checkerboard_pattern(this->ui->use_checkerboard_pattern_cb->isChecked());
ret->set_clamp_to_edges(this->ui->clamp_to_edges_cb->isChecked());
ret->set_save_state_on_exit(this->ui->save_state_on_exit_cb->isChecked());
ret->set_keep_application_in_background(this->ui->keep_application_running_cb->isChecked());
ret->set_clamp_strength(this->ui->clamp_strength_spinbox->value());
ret->set_zoom_mode_for_new_windows(this->ui->zoom_mode_for_new_windows_cb->get_selected_item());
Expand Down
59 changes: 41 additions & 18 deletions src/OptionsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,16 @@
<height>494</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
Expand Down Expand Up @@ -205,6 +196,13 @@
<string>Misc</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QCheckBox" name="save_state_on_exit_cb">
<property name="text">
<string>Save application state on exit</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="keep_application_running_cb">
<property name="toolTip">
Expand Down Expand Up @@ -277,19 +275,38 @@
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,0,0,0,0,0">
<item>
<widget class="QComboBox" name="command_input">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QKeySequenceEdit" name="key_sequence_input"/>
<widget class="QKeySequenceEdit" name="key_sequence_input">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="add_button">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Add</string>
</property>
Expand All @@ -307,6 +324,12 @@
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Remove</string>
</property>
Expand All @@ -322,14 +345,14 @@
<item>
<widget class="QPushButton" name="reset_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<width>0</width>
<height>0</height>
</size>
</property>
Expand Down
Loading

0 comments on commit 789d909

Please sign in to comment.