diff options
Diffstat (limited to '')
-rw-r--r-- | src/core/model/GpgKeyTableModel.cpp | 127 | ||||
-rw-r--r-- | src/ui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/ui/main_window/KeyMgmt.cpp | 4 | ||||
-rw-r--r-- | src/ui/model/GpgKeyTableProxyModel.cpp (renamed from src/core/model/GpgKeyTableProxyModel.cpp) | 11 | ||||
-rw-r--r-- | src/ui/model/GpgKeyTableProxyModel.h (renamed from src/core/model/GpgKeyTableProxyModel.h) | 13 | ||||
-rw-r--r-- | src/ui/widgets/KeyList.cpp | 18 | ||||
-rw-r--r-- | src/ui/widgets/KeyList.h | 17 | ||||
-rw-r--r-- | src/ui/widgets/KeyTable.cpp | 6 | ||||
-rw-r--r-- | src/ui/widgets/KeyTable.h | 3 |
9 files changed, 89 insertions, 111 deletions
diff --git a/src/core/model/GpgKeyTableModel.cpp b/src/core/model/GpgKeyTableModel.cpp index efd7e69d..ec59ceb6 100644 --- a/src/core/model/GpgKeyTableModel.cpp +++ b/src/core/model/GpgKeyTableModel.cpp @@ -28,8 +28,6 @@ #include "GpgKeyTableModel.h" -#include <utility> - #include "core/function/gpg/GpgKeyGetter.h" #include "core/model/GpgKey.h" @@ -62,75 +60,88 @@ auto GpgKeyTableModel::data(const QModelIndex &index, int role) const -> QVariant { if (!index.isValid() || buffered_keys_.empty()) return {}; - if (role == Qt::TextAlignmentRole) { - return Qt::AlignCenter; - } - if (role == Qt::CheckStateRole) { if (index.column() == 0) { return key_check_state_[index.row()] ? Qt::Checked : Qt::Unchecked; } - return {}; } - const auto &key = buffered_keys_.at(index.row()); - - switch (index.column()) { - case 0: { - return index.row(); - } - case 1: { - QString type_sym; - type_sym += key.IsPrivateKey() ? "pub/sec" : "pub"; - if (key.IsPrivateKey() && !key.IsHasMasterKey()) type_sym += "#"; - if (key.IsHasCardKey()) type_sym += "^"; - return type_sym; - } - case 2: { - return key.GetName(); - } - case 3: { - return key.GetEmail(); - } - case 4: { - QString usage_sym; - if (key.IsHasActualCertificationCapability()) usage_sym += "C"; - if (key.IsHasActualEncryptionCapability()) usage_sym += "E"; - if (key.IsHasActualSigningCapability()) usage_sym += "S"; - if (key.IsHasActualAuthenticationCapability()) usage_sym += "A"; - return usage_sym; - } - case 5: { - return key.GetOwnerTrust(); - } - case 6: { - return key.GetId(); + if (role == Qt::DisplayRole) { + const auto &key = buffered_keys_.at(index.row()); + + switch (index.column()) { + case 0: { + return index.row(); + } + case 1: { + QString type_sym; + type_sym += key.IsPrivateKey() ? "pub/sec" : "pub"; + if (key.IsPrivateKey() && !key.IsHasMasterKey()) type_sym += "#"; + if (key.IsHasCardKey()) type_sym += "^"; + return type_sym; + } + case 2: { + return key.GetName(); + } + case 3: { + return key.GetEmail(); + } + case 4: { + QString usage_sym; + if (key.IsHasActualCertificationCapability()) usage_sym += "C"; + if (key.IsHasActualEncryptionCapability()) usage_sym += "E"; + if (key.IsHasActualSigningCapability()) usage_sym += "S"; + if (key.IsHasActualAuthenticationCapability()) usage_sym += "A"; + return usage_sym; + } + case 5: { + return key.GetOwnerTrust(); + } + case 6: { + return key.GetId(); + } + case 7: { + return QLocale().toString(key.GetCreateTime()); + } + case 8: { + return key.GetKeyAlgo(); + } + case 9: { + return static_cast<int>(key.GetSubKeys()->size()); + } + case 10: { + return key.GetComment(); + } + default: + return {}; } - case 7: { - return key.GetCreateTime(); - } - case 8: { - return key.GetKeyAlgo(); - } - case 9: { - return static_cast<int>(key.GetSubKeys()->size()); - } - case 10: { - return key.GetComment(); + } + + if (role == Qt::TextAlignmentRole) { + switch (index.column()) { + case 0: + case 1: + case 4: + case 5: + case 6: + case 7: + case 9: + return Qt::AlignCenter; + default: + return {}; } - default: - return {}; } + + return {}; } auto GpgKeyTableModel::headerData(int section, Qt::Orientation orientation, int role) const -> QVariant { - if (role != Qt::DisplayRole) return {}; - - if (orientation == Qt::Horizontal) { - return column_headers_[section]; + if (role == Qt::DisplayRole) { + if (orientation == Qt::Horizontal) { + return column_headers_[section]; + } } - return {}; } @@ -138,7 +149,7 @@ auto GpgKeyTableModel::flags(const QModelIndex &index) const -> Qt::ItemFlags { if (!index.isValid()) return Qt::NoItemFlags; if (index.column() == 0) { - return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled; + return Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled; } return Qt::ItemIsSelectable | Qt::ItemIsEnabled; diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 0f35fdca..e399068d 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -38,6 +38,7 @@ aux_source_directory(dialog/import_export UI_SOURCE) aux_source_directory(dialog/controller UI_SOURCE) aux_source_directory(dialog UI_SOURCE) aux_source_directory(function UI_SOURCE) +aux_source_directory(model UI_SOURCE) # define libgpgfrontend_ui set(CMAKE_CXX_VISIBILITY_PRESET hidden) diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp index 6c0cea0c..218d1fa4 100644 --- a/src/ui/main_window/KeyMgmt.cpp +++ b/src/ui/main_window/KeyMgmt.cpp @@ -97,10 +97,6 @@ KeyMgmt::KeyMgmt(QWidget* parent) [](const GpgKey& key) -> bool { return key.IsExpired(); }); setCentralWidget(key_list_); - key_list_->SetDoubleClickedAction([this](const GpgKey& key, - QWidget* /*parent*/) { - new KeyDetailsDialog(key_list_->GetCurrentGpgContextChannel(), key, this); - }); key_list_->SlotRefresh(); diff --git a/src/core/model/GpgKeyTableProxyModel.cpp b/src/ui/model/GpgKeyTableProxyModel.cpp index 9e23b707..9dc98bcd 100644 --- a/src/core/model/GpgKeyTableProxyModel.cpp +++ b/src/ui/model/GpgKeyTableProxyModel.cpp @@ -28,15 +28,13 @@ #include "GpgKeyTableProxyModel.h" -#include <utility> - #include "core/function/gpg/GpgKeyGetter.h" #include "core/model/CacheObject.h" #include "core/model/GpgKey.h" #include "core/struct/cache_object/AllFavoriteKeyPairsCO.h" #include "core/utils/GpgUtils.h" -namespace GpgFrontend { +namespace GpgFrontend::UI { GpgKeyTableProxyModel::GpgKeyTableProxyModel( QSharedPointer<GpgKeyTableModel> model, GpgKeyTableDisplayMode display_mode, @@ -45,7 +43,9 @@ GpgKeyTableProxyModel::GpgKeyTableProxyModel( model_(std::move(model)), display_mode_(display_mode), filter_columns_(columns), - custom_filter_(std::move(filter)) { + custom_filter_(std::move(filter)), + default_font_("Arial", 14), + default_metrics_(default_font_) { setSourceModel(model_.get()); connect(this, &GpgKeyTableProxyModel::SignalFavoritesChanged, this, @@ -197,4 +197,5 @@ void GpgKeyTableProxyModel::slot_update_favorites_cache() { favorite_key_ids_ = cache_obj.key_dbs[key_db_name].key_ids; } } -} // namespace GpgFrontend
\ No newline at end of file + +} // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/core/model/GpgKeyTableProxyModel.h b/src/ui/model/GpgKeyTableProxyModel.h index 573d938b..dd086ba9 100644 --- a/src/core/model/GpgKeyTableProxyModel.h +++ b/src/ui/model/GpgKeyTableProxyModel.h @@ -28,14 +28,14 @@ #pragma once -#include <utility> +#include <QFont> +#include <QFontMetrics> #include "core/model/GpgKeyTableModel.h" -namespace GpgFrontend { +namespace GpgFrontend::UI { -class GPGFRONTEND_CORE_EXPORT GpgKeyTableProxyModel - : public QSortFilterProxyModel { +class GpgKeyTableProxyModel : public QSortFilterProxyModel { Q_OBJECT public: using KeyFilter = std::function<bool(const GpgKey &)>; @@ -97,6 +97,9 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyTableProxyModel QString filter_keywords_; QList<QString> favorite_key_ids_; KeyFilter custom_filter_; + + QFont default_font_; + QFontMetrics default_metrics_; }; -} // namespace GpgFrontend
\ No newline at end of file +} // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index d6eeaf55..a7309725 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -33,7 +33,6 @@ #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyGetter.h" -#include "core/module/ModuleManager.h" #include "core/utils/GpgUtils.h" #include "ui/UISignalStation.h" #include "ui/UserInterfaceUtils.h" @@ -539,23 +538,6 @@ void KeyList::import_keys(const QByteArray& in_buffer) { (new KeyImportDetailDialog(current_gpg_context_channel_, result, this)); } -void KeyList::slot_double_clicked(const QModelIndex& index) { - if (ui_->keyGroupTab->size().isEmpty()) return; - - auto* key_table = qobject_cast<KeyTable*>(ui_->keyGroupTab->currentWidget()); - if (m_action_ != nullptr) { - const auto key = GpgKeyGetter::GetInstance(current_gpg_context_channel_) - .GetKey(key_table->GetKeyIdByRow(index.row())); - assert(key.IsGood()); - m_action_(key, this); - } -} - -void KeyList::SetDoubleClickedAction( - std::function<void(const GpgKey&, QWidget*)> action) { - this->m_action_ = std::move(action); -} - auto KeyList::GetSelectedKey() -> QString { if (ui_->keyGroupTab->size().isEmpty()) return {}; diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h index 7053b10c..abcca2b9 100644 --- a/src/ui/widgets/KeyList.h +++ b/src/ui/widgets/KeyList.h @@ -109,14 +109,6 @@ class KeyList : public QWidget { GpgKeyTableColumn custom_columns_filter = GpgKeyTableColumn::kALL); /** - * @brief Set the Double Clicked Action object - * - * @param action - */ - void SetDoubleClickedAction( - std::function<void(const GpgKey&, QWidget*)> action); - - /** * @brief Set the Column Width object * * @param row @@ -239,8 +231,6 @@ class KeyList : public QWidget { */ void SignalRefreshDatabase(); - signals: - /** * @brief * @@ -314,13 +304,6 @@ class KeyList : public QWidget { /** * @brief * - * @param index - */ - void slot_double_clicked(const QModelIndex& index); - - /** - * @brief - * */ void slot_sync_with_key_server(); diff --git a/src/ui/widgets/KeyTable.cpp b/src/ui/widgets/KeyTable.cpp index 9d3511cd..10ebe6eb 100644 --- a/src/ui/widgets/KeyTable.cpp +++ b/src/ui/widgets/KeyTable.cpp @@ -54,8 +54,7 @@ KeyTable::KeyTable(QWidget* parent, QSharedPointer<GpgKeyTableModel> model, verticalHeader()->hide(); horizontalHeader()->setStretchLastSection(false); - setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - + horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); setShowGrid(false); sortByColumn(2, Qt::AscendingOrder); setSelectionBehavior(QAbstractItemView::SelectRows); @@ -77,6 +76,8 @@ KeyTable::KeyTable(QWidget* parent, QSharedPointer<GpgKeyTableModel> model, }); connect(this, &QTableView::doubleClicked, this, [this](const QModelIndex& index) { + if (!index.isValid() || index.column() == 0) return; + auto key = GpgKeyGetter::GetInstance(model_->GetGpgContextChannel()) .GetKey(GetKeyIdByRow(index.row())); if (!key.IsGood()) { @@ -146,4 +147,5 @@ void KeyTable::UncheckAll() { return selected_indexes.first().row(); } + } // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/widgets/KeyTable.h b/src/ui/widgets/KeyTable.h index ae9fcac5..fe73bc98 100644 --- a/src/ui/widgets/KeyTable.h +++ b/src/ui/widgets/KeyTable.h @@ -30,7 +30,7 @@ #include "core/model/GpgKey.h" #include "core/model/GpgKeyTableModel.h" -#include "core/model/GpgKeyTableProxyModel.h" +#include "ui/model/GpgKeyTableProxyModel.h" namespace GpgFrontend::UI { @@ -175,7 +175,6 @@ struct KeyTable : public QTableView { private: QSharedPointer<GpgKeyTableModel> model_; GpgKeyTableProxyModel proxy_model_; - GpgKeyTableColumn column_filter_; }; |