set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets Concurrent)
-find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Concurrent)
+find_package(Qt6 REQUIRED COMPONENTS Widgets Concurrent)
set(PROJECT_SOURCES
main.cpp
uint64validator.h
)
-if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
- qt_add_executable(bigintmandel
- MANUAL_FINALIZATION
- ${PROJECT_SOURCES}
- LICENSE
- )
+qt_add_executable(bigintmandel
+ MANUAL_FINALIZATION
+ ${PROJECT_SOURCES}
+ LICENSE
+)
# Define target properties for Android with Qt 6 as:
-# set_property(TARGET bigintmandel APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
-# ${CMAKE_CURRENT_SOURCE_DIR}/android)
-# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
-else()
- if(ANDROID)
- add_library(bigintmandel SHARED
- ${PROJECT_SOURCES}
- )
-# Define properties for Android with Qt 5 after find_package() calls as:
-# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
- else()
- add_executable(bigintmandel
- ${PROJECT_SOURCES}
- )
- endif()
-endif()
+#set_property(TARGET bigintmandel APPEND PROPERTY
+# QT_ANDROID_PACKAGE_SOURCE_DIR
+# ${CMAKE_CURRENT_SOURCE_DIR}/android)
+# For more information,
+# see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
target_link_libraries(
bigintmandel
PRIVATE
- Qt${QT_VERSION_MAJOR}::Widgets
- Qt${QT_VERSION_MAJOR}::Concurrent
+ Qt6::Widgets
+ Qt6::Concurrent
gmp
)
set_target_properties(bigintmandel PROPERTIES
${BUNDLE_ID_OPTION}
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
- MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
+ MACOSX_BUNDLE_SHORT_VERSION_STRING
+ ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
-if(QT_VERSION_MAJOR EQUAL 6)
- qt_finalize_executable(bigintmandel)
-endif()
+qt_finalize_executable(bigintmandel)
*/
#include <gmpxx.h>
-#include <QPushButton>
-#include <QLabel>
#include <QIntValidator>
+#include <QLabel>
+#include <QMessageBox>
+#include <QPushButton>
#include "settingswidget.h"
#include "uint64validator.h"
edit->setMinimumWidth(256);
}
-void SettingsWidgetFieldBase::add_to_layout(QGridLayout *grid_layout) {
+void SettingsWidgetFieldBase::setup(
+ QGridLayout *grid_layout,
+ SettingsWidget *settings_widget,
+ const char *method_name
+) {
int row_count = grid_layout->rowCount();
grid_layout->addWidget(
new QLabel(label, edit->parentWidget()), row_count, 0
);
grid_layout->addWidget(edit, row_count, 1);
-}
-
-void SettingsWidgetFieldBase::add_on_editing_finished(
- SettingsWidget *settings_widget, const char *method_name
-) {
- QObject::connect(edit, SIGNAL(editingFinished()), settings_widget, method_name);
+ QObject::connect(
+ edit, SIGNAL(editingFinished()), settings_widget, method_name
+ );
}
void SettingsWidgetFieldBase::reset() {
reset();
}
+inline void SettingsWidget::setup_button(
+ QLayout *layout, QPushButton *button, const char *method_name
+) {
+ connect(
+ button,
+ SIGNAL(clicked()),
+ this,
+ method_name
+ );
+ layout->addWidget(button);
+}
+
SettingsWidget::SettingsWidget(QWidget *parent)
: QDialog(parent),
max_iter("max_iter", this),
center_f_x("x", this),
center_f_y("y", this),
one("one", this),
- clear_image_checkbox(new QCheckBox("Clear image", this))
+ clear_image_checkbox(new QCheckBox("Clear image", this)),
+ updating(false)
{
- QPushButton *accept_button = new QPushButton("&Accept");
- QPushButton *reject_button = new QPushButton("&Reject");
QGridLayout *grid_layout = new QGridLayout(this);
QBoxLayout *button_row = new QBoxLayout(QBoxLayout::Direction::RightToLeft);
int i;
- max_iter.add_to_layout(grid_layout);
- width.add_to_layout(grid_layout);
- width.add_on_editing_finished(this, SLOT(update_form()));
- height.add_to_layout(grid_layout);
- height.add_on_editing_finished(this, SLOT(update_form()));
- center_f_x.add_to_layout(grid_layout);
- center_f_x.add_on_editing_finished(this, SLOT(update_form()));
- center_f_y.add_to_layout(grid_layout);
- center_f_y.add_on_editing_finished(this, SLOT(update_form()));
- one.add_to_layout(grid_layout);
- one.add_on_editing_finished(this, SLOT(update_form()));
+ max_iter.setup(grid_layout, this, SLOT(update_form()));
+ width.setup(grid_layout, this, SLOT(update_form()));
+ height.setup(grid_layout, this, SLOT(update_form()));
+ center_f_x.setup(grid_layout, this, SLOT(update_form()));
+ center_f_y.setup(grid_layout, this, SLOT(update_form()));
+ one.setup(grid_layout, this, SLOT(update_form()));
connect(
clear_image_checkbox,
- &QCheckBox::checkStateChanged,
+ &QCheckBox::clicked,
this,
- &SettingsWidget::clear_image_checkbox_changed
+ &SettingsWidget::update_form
);
grid_layout->addWidget(clear_image_checkbox, grid_layout->rowCount(), 1);
- connect(
- accept_button,
- &QPushButton::clicked,
- this,
- &SettingsWidget::accept
+ setup_button(
+ button_row, new QPushButton("C&alculate", this), SLOT(accept())
);
- button_row->addWidget(accept_button);
- connect(
- reject_button,
- &QPushButton::clicked,
- this,
- &SettingsWidget::reject
+ setup_button(
+ button_row, new QPushButton("&Reset", this), SLOT(reset_form())
);
- button_row->addWidget(reject_button);
+ setup_button(button_row, new QPushButton("&Cancel", this), SLOT(reject()));
grid_layout->addLayout(button_row, grid_layout->rowCount(), 0, 1, 2);
}
}
void SettingsWidget::update_form() {
+ bool params_fields_changed = are_params_fields_changed();
+ bool max_iter_is_less = max_iter.get_value() < max_iter.get_orig_value();
if (
- width.is_edited()
- || height.is_edited()
- || center_f_x.is_edited()
- || center_f_y.is_edited()
- || one.is_edited()
+ updating
+ || clear_image_checkbox->isChecked()
+ || (!params_fields_changed && !max_iter_is_less)
)
- // todo: add a messagebox that we do this
+ return;
+ updating = true;
+ if (QMessageBox::question(
+ this,
+ "Bigintmandel Settings",
+ (
+ "Do you want to clear and recalculate the image?\n"
+ "Choosing no will undo your change."
+ )
+ ) == QMessageBox::StandardButton::Yes)
clear_image_checkbox->setChecked(true);
+ else {
+ if (params_fields_changed)
+ reset_params_fields();
+ if (max_iter_is_less)
+ max_iter.reset();
+ }
+ updating = false;
}
-void SettingsWidget::clear_image_checkbox_changed(Qt::CheckState state) {
- if (state == Qt::Unchecked) {
- // todo: add a messagebox if we should do this
- width.reset();
- height.reset();
- center_f_x.reset();
- center_f_y.reset();
- one.reset();
- }
+void SettingsWidget::reset_form() {
+ max_iter.reset();
+ reset_params_fields();
+ clear_image_checkbox->setChecked(false);
}
public:
SettingsWidgetFieldBase(const QString &label, QWidget *parent = nullptr);
inline bool is_edited() const { return edit->text() != orig_value; }
- void add_to_layout(QGridLayout *grid_layout);
- void add_on_editing_finished(
- SettingsWidget *settings_widget, const char *method_name
+ void setup(
+ QGridLayout *grid_layout,
+ SettingsWidget *settings_widget,
+ const char *method_name
);
void reset();
};
inline const quint64 get_value() const {
return edit->text().toULongLong();
}
+ inline const quint64 get_orig_value() const {
+ return orig_value.toULongLong();
+ }
};
template <>
inline const int get_value() const {
return edit->text().toInt();
}
+ inline const int get_orig_value() const {
+ return orig_value.toInt();
+ }
};
template <>
inline const mpz_class get_value() const {
return mpz_class(edit->text().toStdString());
}
+ inline const mpz_class get_orig_value() const {
+ return mpz_class(orig_value.toStdString());
+ }
};
class SettingsWidget : public QDialog {
SettingsWidgetField<int> width, height;
SettingsWidgetField<mpz_class> center_f_x, center_f_y, one;
QCheckBox *clear_image_checkbox;
+ bool updating;
+ inline void setup_button(
+ QLayout *layout, QPushButton *button, const char *method_name
+ );
public:
explicit SettingsWidget(QWidget *parent = nullptr);
void update_fields(const MandelParams ¶ms);
inline const quint64 get_max_iter() const { return max_iter.get_value(); }
+ inline bool are_params_fields_changed() {
+ return (
+ width.is_edited()
+ || height.is_edited()
+ || center_f_x.is_edited()
+ || center_f_y.is_edited()
+ || one.is_edited()
+ );
+ }
+ inline void reset_params_fields() {
+ width.reset();
+ height.reset();
+ center_f_x.reset();
+ center_f_y.reset();
+ one.reset();
+ }
inline const MandelParams get_params() {
return MandelParams(
max_iter.get_value(),
public Q_SLOTS:
void update_form();
- void clear_image_checkbox_changed(Qt::CheckState state);
+ void reset_form();
};
#endif // SETTINGSWIDGET_H