diff options
author | Saturneric <[email protected]> | 2023-02-19 01:44:35 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2023-02-19 01:44:35 +0000 |
commit | 4de9027729c597e54836e3df1cd5514328c8d349 (patch) | |
tree | b74f22c5cf47808fd9e7a3355e586cc4de1a466d | |
parent | fix: open about page no refreshing gnupg info (diff) | |
download | GpgFrontend-4de9027729c597e54836e3df1cd5514328c8d349.tar.gz GpgFrontend-4de9027729c597e54836e3df1cd5514328c8d349.zip |
fix: improve some ui logicsdev/2.0.10/saturneric
-rw-r--r-- | src/ui/dialog/GeneralDialog.cpp | 62 | ||||
-rw-r--r-- | src/ui/dialog/GeneralDialog.h | 4 | ||||
-rw-r--r-- | src/ui/dialog/import_export/KeyUploadDialog.cpp | 2 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyDetailsDialog.cpp | 2 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyPairUIDTab.cpp | 1 |
5 files changed, 40 insertions, 31 deletions
diff --git a/src/ui/dialog/GeneralDialog.cpp b/src/ui/dialog/GeneralDialog.cpp index 9367aa44..b477a65b 100644 --- a/src/ui/dialog/GeneralDialog.cpp +++ b/src/ui/dialog/GeneralDialog.cpp @@ -27,6 +27,9 @@ #include "GeneralDialog.h" +#include <exception> + +#include "spdlog/spdlog.h" #include "ui/struct/SettingsObject.h" GpgFrontend::UI::GeneralDialog::GeneralDialog(std::string name, QWidget *parent) @@ -53,7 +56,7 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { int width = general_windows_state.Check("window_size").Check("width", 400), height = - general_windows_state.Check("window_size").Check("height", 247); + general_windows_state.Check("window_size").Check("height", 300); size_ = {width, height}; @@ -86,21 +89,16 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { SPDLOG_DEBUG("this dialog size width: {} height: {}", size_.width(), size_.height()); + } - if (parent_pos != QPoint{0, 0}) { - QPoint parent_center{parent_pos.x() + parent_size.width() / 2, - parent_pos.y() + parent_size.height() / 2}; - - pos_ = {parent_center.x() - size_.width() / 2, - parent_center.y() - size_.height() / 2}; - - // record parent_pos_ - this->parent_pos_ = parent_pos; - this->parent_size_ = parent_size; - } + // By default move to center of parent + // Or, move to center of screen + if (parent() != nullptr) { + movePos2CenterOfParent(); + } else { + movePos2CenterOfScreen(); } - this->move(pos_); this->resize(size_); } @@ -129,7 +127,7 @@ void GpgFrontend::UI::GeneralDialog::slot_save_settings() noexcept { } } -void GpgFrontend::UI::GeneralDialog::setPosCenterOfScreen() { +void GpgFrontend::UI::GeneralDialog::movePos2CenterOfScreen() { auto *screen = QGuiApplication::primaryScreen(); QRect geo = screen->availableGeometry(); int screen_width = geo.width(); @@ -147,22 +145,32 @@ void GpgFrontend::UI::GeneralDialog::setPosCenterOfScreen() { * @brief * */ -void GpgFrontend::UI::GeneralDialog::movePosition2CenterOfParent() { - SPDLOG_DEBUG("parent pos x: {} y: {}", parent_pos_.x(), parent_pos_.y()); +void GpgFrontend::UI::GeneralDialog::movePos2CenterOfParent() { + try { + SPDLOG_DEBUG("parent pos x: {} y: {}", parent_pos_.x(), parent_pos_.y()); - SPDLOG_DEBUG("parent size width: {}", parent_size_.width(), - "height:", parent_size_.height()); + SPDLOG_DEBUG("parent size width: {}, height: {}", parent_size_.width(), + parent_size_.height()); - if (parent_pos_ != QPoint{0, 0} && parent_size_ != QSize{0, 0}) { - SPDLOG_DEBUG("update current dialog position now"); - QPoint parent_center{parent_pos_.x() + parent_size_.width() / 2, - parent_pos_.y() + parent_size_.height() / 2}; + if (parent_pos_ != QPoint{0, 0} && parent_size_ != QSize{0, 0}) { + SPDLOG_DEBUG("update current dialog position now"); + QPoint parent_center{parent_pos_.x() + parent_size_.width() / 2, + parent_pos_.y() + parent_size_.height() / 2}; - // update size of current dialog - size_ = this->size(); + // update size of current dialog + size_ = this->size(); - pos_ = {parent_center.x() - size_.width() / 2, - parent_center.y() - size_.height() / 2}; - this->move(pos_); + pos_ = {parent_center.x() - size_.width() / 2, + parent_center.y() - size_.height() / 2}; + SPDLOG_DEBUG("target dialog position, x: {}, y: {}", pos_.x(), pos_.y()); + this->move(pos_); + } + } catch (std::exception &e) { + SPDLOG_WARN( + "error occurred when move to poition of center of parent, exception: " + "{}", + e.what()); + } catch (...) { + SPDLOG_WARN("error occurred when move to poition of center of parent."); } }
\ No newline at end of file diff --git a/src/ui/dialog/GeneralDialog.h b/src/ui/dialog/GeneralDialog.h index 41018105..527ae616 100644 --- a/src/ui/dialog/GeneralDialog.h +++ b/src/ui/dialog/GeneralDialog.h @@ -49,13 +49,13 @@ class GeneralDialog : public QDialog { /** * */ - void setPosCenterOfScreen(); + void movePos2CenterOfScreen(); /** * @brief * */ - void movePosition2CenterOfParent(); + void movePos2CenterOfParent(); private slots: /** diff --git a/src/ui/dialog/import_export/KeyUploadDialog.cpp b/src/ui/dialog/import_export/KeyUploadDialog.cpp index 5e05da2d..81fbe5ad 100644 --- a/src/ui/dialog/import_export/KeyUploadDialog.cpp +++ b/src/ui/dialog/import_export/KeyUploadDialog.cpp @@ -55,7 +55,7 @@ KeyUploadDialog::KeyUploadDialog(const KeyIdArgsListPtr& keys_ids, this->setModal(true); this->setWindowTitle(_("Uploading Public Key")); this->setFixedSize(240, 42); - this->setPosCenterOfScreen(); + this->movePos2CenterOfScreen(); } void KeyUploadDialog::SlotUpload() { diff --git a/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp b/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp index ed578aa7..80b53124 100644 --- a/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp +++ b/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp @@ -59,7 +59,7 @@ KeyDetailsDialog::KeyDetailsDialog(const GpgKey& key, QWidget* parent) // this->setMinimumSize({520, 600}); // move to center of the parent - this->movePosition2CenterOfParent(); + this->movePos2CenterOfParent(); this->show(); } diff --git a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp index d55e44d8..35a5871f 100644 --- a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp @@ -51,6 +51,7 @@ KeyPairUIDTab::KeyPairUIDTab(const std::string& key_id, QWidget* parent) manageUIDButton->setMenu(manage_selected_uid_menu_); } else { manageUIDButton->setDisabled(true); + addUIDButton->setDisabled(true); } uidButtonsLayout->addWidget(addUIDButton, 0, 1); |