diff options
Diffstat (limited to 'src')
22 files changed, 253 insertions, 50 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a7cf4a8..e47e2bae 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,9 +53,17 @@ if (APPLE) endif() find_package(OpenSSL REQUIRED) -# Introduce Qt -# Support Qt version: 6.x -find_package(Qt6 6 COMPONENTS Core Test Widgets PrintSupport Network Core5Compat LinguistTools REQUIRED) + +if(GPGFRONTEND_QT5_BUILD) + # Introduce Qt + # Support Qt version: 5.15.x + find_package(Qt5 5.15 COMPONENTS Core Widgets PrintSupport Network LinguistTools REQUIRED) +else() + # Introduce Qt + # Support Qt version: 6.x + find_package(Qt6 6 COMPONENTS Core Widgets PrintSupport Network Core5Compat LinguistTools REQUIRED) +endif() + # Qt configuration set(CMAKE_AUTOMOC ON) @@ -277,7 +285,13 @@ if (BUILD_APPLICATION) list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libExEPath}) set(ALL_RUNTIME_DLL_FILES "") - list(APPEND ALL_RUNTIME_DLL_FILES "Qt6Core.dll;Qt6Core5Compat.dll;Qt6Gui.dll;Qt6Network.dll;Qt6PrintSupport.dll;Qt6Svg.dll;Qt6Widgets.dll;libbrotlicommon.dll;libbrotlidec.dll;libdouble-conversion.dll;libzstd.dll;libmd4c.dll;") + + if(GPGFRONTEND_QT5_BUILD) + list(APPEND ALL_RUNTIME_DLL_FILES "Qt5Core.dll;Qt5Gui.dll;Qt5Network.dll;Qt5PrintSupport.dll;Qt5Svg.dll;Qt5Widgets.dll;libbrotlicommon.dll;libbrotlidec.dll;libdouble-conversion.dll;libzstd.dll;libmd4c.dll;") + else() + list(APPEND ALL_RUNTIME_DLL_FILES "Qt6Core.dll;Qt6Core5Compat.dll;Qt6Gui.dll;Qt6Network.dll;Qt6PrintSupport.dll;Qt6Svg.dll;Qt6Widgets.dll;libbrotlicommon.dll;libbrotlidec.dll;libdouble-conversion.dll;libzstd.dll;libmd4c.dll;") + endif() + # find the other dlls foreach (_dllFileName ${ALL_RUNTIME_DLL_FILES}) message(STATUS "DLL FILE ${_dllFileName}") @@ -447,22 +461,56 @@ if (BUILD_APPLICATION) "${LOCALE_TS_PATH}/GpgFrontend.zh_TW.ts" "${LOCALE_TS_PATH}/GpgFrontend.it_IT.ts") file(GLOB_RECURSE ALL_SOURCE_FILES RELACTIVE ${CMAKE_SOURCE_DIR}/src/*.cpp) - qt_add_translations(${AppName} - RESOURCE_PREFIX "/i18n" - TS_FILES ${TS_FILES} - SOURCES ${ALL_SOURCE_FILES} - INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/src) - - file(GLOB QT_TRANSLATIONS_TS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/third_party/qttranslations/translations/*.ts) - list(FILTER QT_TRANSLATIONS_TS INCLUDE REGEX ".*(qt|qtbase)_.*\.ts$") - add_custom_target(qttranslations ALL) - qt_add_lrelease(qttranslations - TS_FILES ${QT_TRANSLATIONS_TS} - QM_FILES_OUTPUT_VARIABLE QT_TRANSLATIONS_QM) - qt_add_resources(${AppName} "qttranslations" - PREFIX "/i18n_qt" - BASE ${CMAKE_CURRENT_BINARY_DIR} - FILES ${QT_TRANSLATIONS_QM}) + + if(GPGFRONTEND_QT5_BUILD) + # TODO + qt5_add_translation(GF_TRANSLATIONS_QM ${TS_FILES}) + message(STATUS "GF_TRANSLATIONS_QM ${GF_TRANSLATIONS_QM}") + + set(GF_QM_TRANSLATIONS_RESOURCE_FILE "${CMAKE_CURRENT_BINARY_DIR}/i18n.qrc") + file(WRITE ${GF_QM_TRANSLATIONS_RESOURCE_FILE} "<!DOCTYPE RCC>\n<RCC version=\"1.0\">\n <qresource prefix=\"i18n\">\n") + foreach(QM_FILE ${GF_TRANSLATIONS_QM}) + file(RELATIVE_PATH QM_FILENAME ${CMAKE_CURRENT_BINARY_DIR} ${QM_FILE}) + file(APPEND ${GF_QM_TRANSLATIONS_RESOURCE_FILE} " <file alias=\"${QM_FILENAME}\">${QM_FILE}</file>\n") + endforeach() + file(APPEND ${GF_QM_TRANSLATIONS_RESOURCE_FILE} " </qresource>\n</RCC>\n") + qt5_add_resources(GF_I18N_RESOURCES ${GF_QM_TRANSLATIONS_RESOURCE_FILE}) + + file(GLOB QT_TRANSLATIONS_TS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/third_party/qttranslations/translations/*.ts) + list(FILTER QT_TRANSLATIONS_TS INCLUDE REGEX ".*(qt|qtbase)_.*\.ts$") + qt5_add_translation(QT_TRANSLATIONS_QM ${QT_TRANSLATIONS_TS}) + + set(QT_QM_TRANSLATIONS_RESOURCE_FILE "${CMAKE_CURRENT_BINARY_DIR}/qt_i18n.qrc") + file(WRITE ${QT_QM_TRANSLATIONS_RESOURCE_FILE} "<!DOCTYPE RCC>\n<RCC version=\"1.0\">\n <qresource prefix=\"qt_i18n\">\n") + foreach(QM_FILE ${QT_TRANSLATIONS_QM}) + file(RELATIVE_PATH QM_FILENAME ${CMAKE_CURRENT_BINARY_DIR} ${QM_FILE}) + file(APPEND ${QT_QM_TRANSLATIONS_RESOURCE_FILE} " <file alias=\"${QM_FILENAME}\">${QM_FILE}</file>\n") + endforeach() + file(APPEND ${QT_QM_TRANSLATIONS_RESOURCE_FILE} " </qresource>\n</RCC>\n") + qt5_add_resources(GF_I18N_RESOURCES ${QT_QM_TRANSLATIONS_RESOURCE_FILE}) + + message(STATUS "GF_I18N_RESOURCES ${GF_I18N_RESOURCES}") + + target_sources(${AppName} PRIVATE ${GF_I18N_RESOURCES}) + else() + qt_add_translations(${AppName} + RESOURCE_PREFIX "/i18n" + TS_FILES ${TS_FILES} + SOURCES ${ALL_SOURCE_FILES} + INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/src) + file(GLOB QT_TRANSLATIONS_TS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/third_party/qttranslations/translations/*.ts) + list(FILTER QT_TRANSLATIONS_TS INCLUDE REGEX ".*(qt|qtbase)_.*\.ts$") + add_custom_target(qttranslations ALL) + qt_add_lrelease(qttranslations + TS_FILES ${QT_TRANSLATIONS_TS} + QM_FILES_OUTPUT_VARIABLE QT_TRANSLATIONS_QM) + qt_add_resources(${AppName} "qttranslations" + PREFIX "/i18n_qt" + BASE ${CMAKE_CURRENT_BINARY_DIR} + FILES ${QT_TRANSLATIONS_QM}) + endif() + + endif() # if building linux package diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index a37ea7ee..b5dd3571 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -99,9 +99,14 @@ endif() # link libarchive target_link_libraries(gpgfrontend_core PRIVATE archive) - -# link Qt core -target_link_libraries(gpgfrontend_core PUBLIC Qt6::Core) + +if(GPGFRONTEND_QT5_BUILD) + # link Qt core + target_link_libraries(gpgfrontend_core PUBLIC Qt5::Core) +else() + # link Qt core + target_link_libraries(gpgfrontend_core PUBLIC Qt6::Core) +endif() # set up pch target_precompile_headers(gpgfrontend_core diff --git a/src/core/function/ArchiveFileOperator.cpp b/src/core/function/ArchiveFileOperator.cpp index 2b76e4ac..475ef434 100644 --- a/src/core/function/ArchiveFileOperator.cpp +++ b/src/core/function/ArchiveFileOperator.cpp @@ -143,7 +143,11 @@ void ArchiveFileOperator::NewArchive2DataExchanger( #endif QFile file(source_path); +#ifdef QT5_BUILD + if (file.open(QIODevice::ReadOnly)) { +#else if (file.open(QIODeviceBase::ReadOnly)) { +#endif // turn absolute path to relative path auto relativ_path_name = base_path.relativeFilePath(source_path); archive_entry_set_pathname(entry, relativ_path_name.toUtf8()); diff --git a/src/core/function/gpg/GpgCommandExecutor.cpp b/src/core/function/gpg/GpgCommandExecutor.cpp index 6d24f9bd..66c18ae1 100644 --- a/src/core/function/gpg/GpgCommandExecutor.cpp +++ b/src/core/function/gpg/GpgCommandExecutor.cpp @@ -41,7 +41,7 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context) const auto &interact_function = context.int_func; const auto &cmd_executor_callback = context.cb_func; - const QString joined_argument = QStringList::fromVector(arguments).join(" "); + const QString joined_argument = arguments.join(" "); GF_CORE_LOG_DEBUG("building task: called cmd {} arguments size: {}", cmd, arguments.size()); diff --git a/src/core/function/gpg/GpgContext.cpp b/src/core/function/gpg/GpgContext.cpp index 6523386c..7c84d3c4 100644 --- a/src/core/function/gpg/GpgContext.cpp +++ b/src/core/function/gpg/GpgContext.cpp @@ -93,13 +93,23 @@ class GpgContext::Impl { const char *passphrase_info, int last_was_bad, int fd) -> gpgme_error_t { size_t res; - QString pass = "abcdefg\n"; +#ifdef QT5_BUILD + QString pass_qstr = "abcdefg\n"; + QByteArray pass = pass_qstr.toUtf8(); +#else + QString pass = "abcdefg\n"; +#endif + auto passpahrase_size = pass.size(); - size_t off = 0; do { +#ifdef QT5_BUILD + const char* p_pass = pass.data(); + res = gpgme_io_write(fd, &p_pass[off], passpahrase_size - off); +#else res = gpgme_io_write(fd, &pass[off], passpahrase_size - off); +#endif if (res > 0) off += res; } while (res > 0 && off != passpahrase_size); diff --git a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp index c965ed30..a1e5cd5a 100644 --- a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp +++ b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp @@ -209,8 +209,11 @@ auto GnuPGInfoGatheringModule::Exec(EventRefrernce event) -> int { getTaskRunner()}); GpgCommandExecutor::ExecuteContexts exec_contexts; - +#ifdef QT5_BUILD + exec_contexts.push_back(GpgCommandExecutor::ExecuteContext{ +#else exec_contexts.emplace_back(GpgCommandExecutor::ExecuteContext{ +#endif gpgconf_path, QStringList{"--list-dirs"}, [this](int exit_code, const QString &p_out, const QString &p_err) { if (exit_code != 0) return; @@ -264,7 +267,11 @@ auto GnuPGInfoGatheringModule::Exec(EventRefrernce event) -> int { continue; } +#ifdef QT5_BUILD + exec_contexts.push_back(GpgCommandExecutor::ExecuteContext{ +#else exec_contexts.emplace_back(GpgCommandExecutor::ExecuteContext{ +#endif gpgconf_path, QStringList{"--list-options", component_info.name}, [this, component_info](int exit_code, const QString &p_out, const QString &p_err) { diff --git a/src/module/integrated/version_checking_module/CMakeLists.txt b/src/module/integrated/version_checking_module/CMakeLists.txt index f122be88..76459b0e 100644 --- a/src/module/integrated/version_checking_module/CMakeLists.txt +++ b/src/module/integrated/version_checking_module/CMakeLists.txt @@ -46,8 +46,13 @@ endif () target_link_libraries(gpgfrontend_integrated_module_version_checking PRIVATE gpgfrontend_module_sdk) -# link Qt -target_link_libraries(gpgfrontend_integrated_module_version_checking PRIVATE Qt6::Network) +if(GPGFRONTEND_QT5_BUILD) + # link Qt + target_link_libraries(gpgfrontend_integrated_module_version_checking PUBLIC Qt5::Network) +else() + # link Qt + target_link_libraries(gpgfrontend_integrated_module_version_checking PUBLIC Qt6::Network) +endif() # property set_property(TARGET gpgfrontend_integrated_module_version_checking PROPERTY AUTOMOC ON) diff --git a/src/pinentry/CMakeLists.txt b/src/pinentry/CMakeLists.txt index b31e4f05..3145719a 100644 --- a/src/pinentry/CMakeLists.txt +++ b/src/pinentry/CMakeLists.txt @@ -37,8 +37,13 @@ add_library(gpgfrontend_pinentry SHARED ${PINENTRY_SOURCE}) target_link_libraries(gpgfrontend_pinentry PUBLIC gpgfrontend_core) -# link Qt core -target_link_libraries(gpgfrontend_pinentry PUBLIC Qt6::Widgets) +if(GPGFRONTEND_QT5_BUILD) + # link Qt core + target_link_libraries(gpgfrontend_pinentry PUBLIC Qt5::Widgets) +else() + # link Qt core + target_link_libraries(gpgfrontend_pinentry PUBLIC Qt6::Widgets) +endif() # spdlog target_link_libraries(gpgfrontend_pinentry PRIVATE spdlog) diff --git a/src/pinentry/pinentry.cpp b/src/pinentry/pinentry.cpp index c648aea6..5f233f5d 100644 --- a/src/pinentry/pinentry.cpp +++ b/src/pinentry/pinentry.cpp @@ -375,19 +375,19 @@ int pinentry_inq_quality(const QString &passphrase) { static_cast<int>(has_digit) + static_cast<int>(has_special); score += variety_count * 10; - for (size_t i = 0; i < passphrase.length() - 1; ++i) { + for (auto i = 0; i < passphrase.length() - 1; ++i) { if (passphrase[i] == passphrase[i + 1]) { score -= 5; } } - std::unordered_map<QChar, int> char_count; + QHash<QChar, int> char_count; for (const auto ch : passphrase) { char_count[ch]++; } for (auto &p : char_count) { - if (p.second > 1) { - score -= (p.second - 1) * 3; + if (p > 1) { + score -= (p - 1) * 3; } } diff --git a/src/pinentry/qti18n.cpp b/src/pinentry/qti18n.cpp index 49c27dd3..198e6cc4 100644 --- a/src/pinentry/qti18n.cpp +++ b/src/pinentry/qti18n.cpp @@ -30,7 +30,7 @@ static bool loadCatalog(const QString &catalog, const QLocale &locale) { auto translator = new QTranslator(QCoreApplication::instance()); if (!translator->load(locale, catalog, QString(), - QLibraryInfo::path(QLibraryInfo::TranslationsPath))) { + QLatin1String(":/i18n_qt"))) { qDebug() << "Loading the" << catalog << "catalog failed for locale" << locale; delete translator; diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index c9c27462..3f0686e2 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -47,9 +47,15 @@ add_library(gpgfrontend_ui SHARED ${UI_SOURCE}) set(_export_file "${CMAKE_CURRENT_SOURCE_DIR}/GpgFrontendUIExport.h") generate_export_header(gpgfrontend_ui EXPORT_FILE_NAME "${_export_file}") -# link Qt -target_link_libraries(gpgfrontend_ui - Qt6::Network Qt6::PrintSupport Qt6::Test Qt6::Core5Compat) +if(GPGFRONTEND_QT5_BUILD) + # link Qt + target_link_libraries(gpgfrontend_ui + Qt5::Core Qt5::Widgets Qt5::Network Qt5::PrintSupport) +else() + # link Qt + target_link_libraries(gpgfrontend_ui + Qt6::Core Qt6::Widgets Qt6::Network Qt6::PrintSupport Qt6::Core5Compat) +endif() # link gpgfrontend_core diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp index 148402d4..08cf012d 100644 --- a/src/ui/GpgFrontendUIInit.cpp +++ b/src/ui/GpgFrontendUIInit.cpp @@ -33,6 +33,7 @@ #include "core/GpgConstants.h" #include "core/function/CoreSignalStation.h" #include "core/function/GlobalSettingStation.h" +#include "core/model/GpgPassphraseContext.h" #include "core/module/ModuleManager.h" #include "ui/UISignalStation.h" #include "ui/UserInterfaceUtils.h" diff --git a/src/ui/dialog/GeneralDialog.h b/src/ui/dialog/GeneralDialog.h index 604c8475..3576319f 100644 --- a/src/ui/dialog/GeneralDialog.h +++ b/src/ui/dialog/GeneralDialog.h @@ -61,7 +61,7 @@ class GeneralDialog : public QDialog { * @brief * */ - [[nodiscard]] bool isRectRestored(); + [[nodiscard]] auto isRectRestored() -> bool; /** * @brief diff --git a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp index 5b71c0f6..dfd6c35a 100644 --- a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp +++ b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp @@ -159,7 +159,7 @@ void KeyImportDetailDialog::create_keys_table() { keys_table_->resizeColumnsToContents(); } -QString KeyImportDetailDialog::get_status_string(int key_status) { +auto KeyImportDetailDialog::get_status_string(int key_status) -> QString { QString status_string; // keystatus is greater than 15, if key is private if (key_status > 15) { diff --git a/src/ui/dialog/import_export/KeyImportDetailDialog.h b/src/ui/dialog/import_export/KeyImportDetailDialog.h index db355570..2af0397d 100644 --- a/src/ui/dialog/import_export/KeyImportDetailDialog.h +++ b/src/ui/dialog/import_export/KeyImportDetailDialog.h @@ -80,7 +80,7 @@ class KeyImportDetailDialog : public GeneralDialog { * @param keyStatus * @return QString */ - static QString get_status_string(int keyStatus); + static auto get_status_string(int) -> QString; QTableWidget* keys_table_{}; ///< QGroupBox* general_info_box_{}; ///< diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp index 6e4a1df0..74f827aa 100644 --- a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp @@ -432,7 +432,12 @@ void KeyPairOperaTab::slot_import_revoke_cert() { } QFile rev_file(rev_file_info.absoluteFilePath()); + +#ifdef QT5_BUILD + if (!rev_file.open(QIODevice::ReadOnly)) { +#else if (!rev_file.open(QIODeviceBase::ReadOnly)) { +#endif QMessageBox::critical( this, tr("Error"), tr("Cannot open this file. Please make sure that this " diff --git a/src/ui/dialog/settings/SettingsDialog.cpp b/src/ui/dialog/settings/SettingsDialog.cpp index a26ddf0b..cb17eb0d 100644 --- a/src/ui/dialog/settings/SettingsDialog.cpp +++ b/src/ui/dialog/settings/SettingsDialog.cpp @@ -137,7 +137,11 @@ auto SettingsDialog::ListLanguages() -> QHash<QString, QString> { auto locale = file.mid(start, end - start); QLocale const q_locale(locale); +#ifdef QT5_BUILD + if (q_locale.nativeCountryName().isEmpty()) continue; +#else if (q_locale.nativeTerritoryName().isEmpty()) continue; +#endif auto language = q_locale.nativeLanguageName() + " (" + locale + ")"; languages.insert(q_locale.name(), language); diff --git a/src/ui/function/RaisePinentry.cpp b/src/ui/function/RaisePinentry.cpp index 216712e8..7c68d67c 100644 --- a/src/ui/function/RaisePinentry.cpp +++ b/src/ui/function/RaisePinentry.cpp @@ -64,17 +64,17 @@ auto RaisePinentry::Exec() -> int { auto* pinentry = new PinEntryDialog(FindTopMostWindow(this), 0, 15, true, ask_for_new, - ask_for_new ? tr("Repeat PIN:") : QString(), + ask_for_new ? tr("Repeat Passphrase:") : QString(), tr("Show passphrase"), tr("Hide passphrase")); if (context_->IsPreWasBad()) { - pinentry->setError(tr("Given PIN was wrong. Please retry.")); + pinentry->setError(tr("Given Passphrase was wrong. Please retry.")); } - pinentry->setPrompt(tr("PIN:")); + pinentry->setPrompt(tr("Passphrase:")); if (!context_->GetUidsInfo().isEmpty()) { - pinentry->setDescription(QString("Please provide PIN of Key:\n%1\n") + pinentry->setDescription(QString("Please provide Passphrase of Key:\n%1\n") .arg(context_->GetUidsInfo())); } diff --git a/src/ui/main_window/GeneralMainWindow.cpp b/src/ui/main_window/GeneralMainWindow.cpp index e3577199..f58326f9 100644 --- a/src/ui/main_window/GeneralMainWindow.cpp +++ b/src/ui/main_window/GeneralMainWindow.cpp @@ -59,9 +59,11 @@ void GpgFrontend::UI::GeneralMainWindow::slot_restore_settings() noexcept { GF_UI_LOG_DEBUG("restore main window state: {}", window_state.window_state_data); - // state sets pos & size of dock-widgets - this->restoreState( - QByteArray::fromBase64(window_state.window_state_data.toUtf8())); + if (!window_state.window_state_data.isEmpty()) { + // state sets pos & size of dock-widgets + this->restoreState( + QByteArray::fromBase64(window_state.window_state_data.toUtf8())); + } // restore window size & location if (window_state.window_save) { @@ -107,6 +109,8 @@ void GpgFrontend::UI::GeneralMainWindow::slot_restore_settings() noexcept { this->move(pos_); this->resize(size_); + } else { + movePosition2CenterOfParent(); } // appearance @@ -148,4 +152,82 @@ void GpgFrontend::UI::GeneralMainWindow::slot_save_settings() noexcept { } } +void GeneralMainWindow::setPosCenterOfScreen() { + // update cache + update_rect_cache(); + + int screen_width = screen_rect_.width(); + int screen_height = screen_rect_.height(); + GF_UI_LOG_DEBUG("dialog current screen available geometry", screen_width, + screen_height); + + // update rect of current dialog + rect_ = this->geometry(); + this->move(screen_rect_.center() - + QPoint(rect_.width() / 2, rect_.height() / 2)); +} + +void GeneralMainWindow::movePosition2CenterOfParent() { + // update cache + update_rect_cache(); + + // log for debug + GF_UI_LOG_DEBUG("parent pos x: {} y: {}", parent_rect_.x(), parent_rect_.y()); + GF_UI_LOG_DEBUG("parent size width: {}, height: {}", parent_rect_.width(), + parent_rect_.height()); + GF_UI_LOG_DEBUG("parent center pos x: {}, y: {}", parent_rect_.center().x(), + parent_rect_.center().y()); + GF_UI_LOG_DEBUG("dialog pos x: {} y: {}", rect_.x(), rect_.y()); + GF_UI_LOG_DEBUG("dialog size width: {} height: {}", rect_.width(), + rect_.height()); + + if (parent_rect_.topLeft() != QPoint{0, 0} && + parent_rect_.size() != QSize{0, 0}) { + if (rect_.width() <= 0) rect_.setWidth(100); + if (rect_.height() <= 0) rect_.setHeight(100); + + QPoint target_position = + parent_rect_.center() - QPoint(rect_.width() / 2, rect_.height() / 2); + + GF_UI_LOG_DEBUG( + "update position to parent's center, target pos, x:{}, y: {}", + target_position.x(), target_position.y()); + + this->move(target_position); + } else { + setPosCenterOfScreen(); + } +} + +void GeneralMainWindow::update_rect_cache() { + // update size of current dialog + rect_ = this->geometry(); + + auto *screen = this->window()->screen(); + screen_rect_ = screen->availableGeometry(); + + // read pos and size from parent + if (this->parent() != nullptr) { + QRect parent_rect; + + auto *parent_widget = qobject_cast<QWidget *>(this->parent()); + if (parent_widget != nullptr) { + parent_rect = parent_widget->geometry(); + } else { + auto *parent_dialog = qobject_cast<QDialog *>(this->parent()); + if (parent_dialog != nullptr) { + parent_rect = parent_dialog->geometry(); + } else { + auto *parent_window = qobject_cast<QMainWindow *>(this->parent()); + if (parent_window != nullptr) { + parent_rect = parent_window->geometry(); + } + } + } + parent_rect_ = parent_rect; + } else { + // reset parent's pos and size + this->parent_rect_ = QRect{0, 0, 0, 0}; + } +} } // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/main_window/GeneralMainWindow.h b/src/ui/main_window/GeneralMainWindow.h index e1ff31bb..70dad5f3 100644 --- a/src/ui/main_window/GeneralMainWindow.h +++ b/src/ui/main_window/GeneralMainWindow.h @@ -55,6 +55,17 @@ class GeneralMainWindow : public QMainWindow { */ void closeEvent(QCloseEvent* event) override; + /** + * + */ + void setPosCenterOfScreen(); + + /** + * @brief + * + */ + void movePosition2CenterOfParent(); + QSize icon_size_{}; ///< int font_size_{}; ///< Qt::ToolButtonStyle icon_style_; ///< @@ -70,9 +81,18 @@ class GeneralMainWindow : public QMainWindow { */ void slot_save_settings() noexcept; + /** + * @brief + * + */ + void update_rect_cache(); + private: QString name_; ///< QPoint pos_; ///< QSize size_; ///< + QRect rect_; + QRect screen_rect_; + QRect parent_rect_; }; } // namespace GpgFrontend::UI diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp index 27634570..a7bd63d8 100644 --- a/src/ui/main_window/MainWindow.cpp +++ b/src/ui/main_window/MainWindow.cpp @@ -32,6 +32,7 @@ #include "core/function/CoreSignalStation.h" #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgAdvancedOperator.h" +#include "core/model/GpgPassphraseContext.h" #include "core/module/ModuleManager.h" #include "ui/UISignalStation.h" #include "ui/main_window/GeneralMainWindow.h" diff --git a/src/ui/widgets/FileTreeView.cpp b/src/ui/widgets/FileTreeView.cpp index b0241b63..7a725e10 100644 --- a/src/ui/widgets/FileTreeView.cpp +++ b/src/ui/widgets/FileTreeView.cpp @@ -67,7 +67,7 @@ void FileTreeView::selectionChanged(const QItemSelection& selected, GF_UI_LOG_DEBUG("file tree view selected target path: {}", selected_path_); emit SignalSelectedChanged(selected_path_); } else { - selected_path_ = {}; + selected_path_ = QString(); if (!this->selectedIndexes().isEmpty()) { selected_path_ = dir_model_->filePath(this->selectedIndexes().front()); emit SignalSelectedChanged(selected_path_); |