diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/model/GpgKeyTableModel.cpp | 8 | ||||
-rw-r--r-- | src/ui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotFunction.cpp | 2 | ||||
-rw-r--r-- | src/ui/model/GpgKeyTableProxyModel.cpp (renamed from src/core/model/GpgKeyTableProxyModel.cpp) | 83 | ||||
-rw-r--r-- | src/ui/model/GpgKeyTableProxyModel.h (renamed from src/core/model/GpgKeyTableProxyModel.h) | 12 | ||||
-rw-r--r-- | src/ui/widgets/KeyList.h | 2 | ||||
-rw-r--r-- | src/ui/widgets/KeyTable.cpp | 7 | ||||
-rw-r--r-- | src/ui/widgets/KeyTable.h | 3 |
8 files changed, 101 insertions, 17 deletions
diff --git a/src/core/model/GpgKeyTableModel.cpp b/src/core/model/GpgKeyTableModel.cpp index 8de07b23..edc125ef 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,10 +60,6 @@ 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; @@ -107,7 +101,7 @@ auto GpgKeyTableModel::data(const QModelIndex &index, return key.GetId(); } case 7: { - return key.GetCreateTime(); + return QLocale().toString(key.GetCreateTime()); } case 8: { return key.GetKeyAlgo(); 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/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 19760e0f..15c1ef46 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -692,7 +692,7 @@ void MainWindow::SlotEncryptEML() { } } - LOG_E() << "mime or signature data is missing"; + return 0; }); }); } diff --git a/src/core/model/GpgKeyTableProxyModel.cpp b/src/ui/model/GpgKeyTableProxyModel.cpp index 9e23b707..90ad2c6a 100644 --- a/src/core/model/GpgKeyTableProxyModel.cpp +++ b/src/ui/model/GpgKeyTableProxyModel.cpp @@ -28,8 +28,6 @@ #include "GpgKeyTableProxyModel.h" -#include <utility> - #include "core/function/gpg/GpgKeyGetter.h" #include "core/model/CacheObject.h" #include "core/model/GpgKey.h" @@ -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,81 @@ void GpgKeyTableProxyModel::slot_update_favorites_cache() { favorite_key_ids_ = cache_obj.key_dbs[key_db_name].key_ids; } } + +auto GpgKeyTableProxyModel::data(const QModelIndex &index, + int role) const -> QVariant { + if (role == Qt::FontRole) { + return default_font_; + } + + if (role == Qt::TextAlignmentRole) { + return Qt::AlignCenter; + } + + if (role == Qt::SizeHintRole) { + const QVariant display_data = model_->data(index, Qt::DisplayRole); + if (!display_data.isValid()) { + return {}; + } + + const QString text = display_data.toString(); + + QRect rect = default_metrics_.boundingRect(QRect{}, Qt::AlignCenter, text); + + const int horizontal_padding = 15; + const int vertical_padding = 2; + +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + const int raw_width = default_metrics_.horizontalAdvance(text); +#else + const int raw_width = rect.width(); +#endif + + const int width = + static_cast<int>(raw_width * 1.15) + horizontal_padding * 2; + const int height = rect.height() + vertical_padding * 2; + + LOG_D() << "row text: " << text << "width: " << width; + + return QSize(width, height); + } + + return sourceModel()->data(index, role); +} + +auto GpgKeyTableProxyModel::headerData(int section, Qt::Orientation orientation, + int role) const -> QVariant { + if (role == Qt::FontRole) { + return default_font_; + } + + if (role == Qt::SizeHintRole) { + const QVariant display_data = + model_->headerData(section, orientation, Qt::DisplayRole); + if (!display_data.isValid()) { + return {}; + } + + const QString text = display_data.toString(); + + QRect rect = default_metrics_.boundingRect(QRect{}, Qt::AlignCenter, text); + + const int horizontal_padding = 15; + const int vertical_padding = 2; + +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + const int raw_width = default_metrics_.horizontalAdvance(text); +#else + const int raw_width = rect.width(); +#endif + + const int width = + static_cast<int>(raw_width * 1.15) + horizontal_padding * 2; + const int height = rect.height() + vertical_padding * 2; + + return QSize(width, height); + } + + return sourceModel()->headerData(section, orientation, role); +} } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/model/GpgKeyTableProxyModel.h b/src/ui/model/GpgKeyTableProxyModel.h index 573d938b..ffca5a6f 100644 --- a/src/core/model/GpgKeyTableProxyModel.h +++ b/src/ui/model/GpgKeyTableProxyModel.h @@ -28,7 +28,8 @@ #pragma once -#include <utility> +#include <QFont> +#include <QFontMetrics> #include "core/model/GpgKeyTableModel.h" @@ -49,6 +50,12 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyTableProxyModel void ResetGpgKeyTableModel(QSharedPointer<GpgKeyTableModel> model); + [[nodiscard]] auto data(const QModelIndex &index, + int role) const -> QVariant override; + + [[nodiscard]] auto headerData(int section, Qt::Orientation orientation, + int role) const -> QVariant override; + protected: [[nodiscard]] auto filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent) const -> bool override; @@ -97,6 +104,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 diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h index 4216eba8..490da86d 100644 --- a/src/ui/widgets/KeyList.h +++ b/src/ui/widgets/KeyList.h @@ -239,8 +239,6 @@ class KeyList : public QWidget { */ void SignalRefreshDatabase(); - signals: - /** * @brief * diff --git a/src/ui/widgets/KeyTable.cpp b/src/ui/widgets/KeyTable.cpp index bda294a4..6fe2d966 100644 --- a/src/ui/widgets/KeyTable.cpp +++ b/src/ui/widgets/KeyTable.cpp @@ -54,7 +54,7 @@ KeyTable::KeyTable(QWidget* parent, QSharedPointer<GpgKeyTableModel> model, verticalHeader()->hide(); horizontalHeader()->setStretchLastSection(false); - setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + horizontalHeader()->setResizeContentsPrecision(1000); setShowGrid(false); sortByColumn(2, Qt::AscendingOrder); @@ -68,6 +68,10 @@ KeyTable::KeyTable(QWidget* parent, QSharedPointer<GpgKeyTableModel> model, setAlternatingRowColors(true); setSortingEnabled(true); + for (int i = 1; i < proxy_model_.columnCount(); ++i) { + this->resizeColumnToContents(i); + } + connect(CommonUtils::GetInstance(), &CommonUtils::SignalFavoritesChanged, &proxy_model_, &GpgKeyTableProxyModel::SignalFavoritesChanged); connect(this, &KeyTable::SignalColumnTypeChange, this, @@ -146,4 +150,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 a03a1c83..14a1bc4e 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_; }; |