diff options
author | Jonathan White <support@dmapps.us> | 2020-06-28 15:26:02 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2020-06-28 23:21:50 +0300 |
commit | fd65a47d51e957af876d50adf5f56d8c5462ac95 (patch) | |
tree | 3754efe7c2026becbd6b22e47d1e09a336571932 | |
parent | 4bf6d8d94dd8cf16e5714a922103b73abe1e1ff5 (diff) |
Introduce Compact Mode
* Added to the new view menu, show entry/group icons at 16px and reduce toolbar icons to 22px.
* Fix search widget being too large vertically (removed padding)
-rw-r--r-- | src/core/Config.cpp | 1 | ||||
-rw-r--r-- | src/core/Config.h | 1 | ||||
-rw-r--r-- | src/core/DatabaseIcons.cpp | 27 | ||||
-rw-r--r-- | src/core/DatabaseIcons.h | 3 | ||||
-rw-r--r-- | src/core/Global.h | 6 | ||||
-rw-r--r-- | src/core/Metadata.cpp | 9 | ||||
-rw-r--r-- | src/gui/MainWindow.cpp | 10 | ||||
-rw-r--r-- | src/gui/MainWindow.ui | 9 | ||||
-rw-r--r-- | src/gui/SearchWidget.ui | 17 |
9 files changed, 58 insertions, 25 deletions
diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 75cb383b1..6d55df8c7 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -101,6 +101,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = { {Config::GUI_AdvancedSettings, {QS("GUI/AdvancedSettings"), Roaming, false}}, {Config::GUI_MonospaceNotes, {QS("GUI/MonospaceNotes"), Roaming, false}}, {Config::GUI_ApplicationTheme, {QS("GUI/ApplicationTheme"), Roaming, QS("auto")}}, + {Config::GUI_CompactMode, {QS("GUI/CompactMode"), Roaming, false}}, {Config::GUI_CheckForUpdates, {QS("GUI/CheckForUpdates"), Roaming, true}}, {Config::GUI_CheckForUpdatesNextCheck, {QS("GUI/CheckForUpdatesNextCheck"), Local, 0}}, {Config::GUI_CheckForUpdatesIncludeBetas, {QS("GUI/CheckForUpdatesIncludeBetas"), Roaming, false}}, diff --git a/src/core/Config.h b/src/core/Config.h index b3dc0fb85..9363873c9 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -84,6 +84,7 @@ public: GUI_AdvancedSettings, GUI_MonospaceNotes, GUI_ApplicationTheme, + GUI_CompactMode, GUI_CheckForUpdates, GUI_CheckForUpdatesIncludeBetas, diff --git a/src/core/DatabaseIcons.cpp b/src/core/DatabaseIcons.cpp index 2935d98ff..7b4499026 100644 --- a/src/core/DatabaseIcons.cpp +++ b/src/core/DatabaseIcons.cpp @@ -17,6 +17,7 @@ #include "DatabaseIcons.h" +#include "core/Config.h" #include "core/Global.h" #include "core/Resources.h" #include "gui/MainWindow.h" @@ -44,6 +45,9 @@ DatabaseIcons::DatabaseIcons() iconList = QDir(iconDir).entryList(QDir::NoFilter, QDir::Name); badgeList = QDir(badgeDir).entryList(QDir::NoFilter, QDir::Name); + + // Set this early and once to ensure consistent icon size until app restart + m_compactMode = config()->get(Config::GUI_CompactMode).toBool(); } DatabaseIcons* DatabaseIcons::instance() @@ -66,13 +70,13 @@ QPixmap DatabaseIcons::icon(int index, IconSize size) auto icon = m_iconCache.value(cacheKey); if (icon.isNull()) { icon.addFile(iconDir + iconList[index]); - icon.addPixmap(icon.pixmap(IconSize::Default)); - icon.addPixmap(icon.pixmap(IconSize::Medium)); - icon.addPixmap(icon.pixmap(IconSize::Large)); + icon.addPixmap(icon.pixmap(iconSize(IconSize::Default))); + icon.addPixmap(icon.pixmap(iconSize(IconSize::Medium))); + icon.addPixmap(icon.pixmap(iconSize(IconSize::Large))); m_iconCache.insert(cacheKey, icon); } - return icon.pixmap(size); + return icon.pixmap(iconSize(size)); } QPixmap DatabaseIcons::applyBadge(const QPixmap& basePixmap, Badges badgeIndex) @@ -83,7 +87,8 @@ QPixmap DatabaseIcons::applyBadge(const QPixmap& basePixmap, Badges badgeIndex) qWarning("DatabaseIcons: Out-of-range badge index given to applyBadge: %d", badgeIndex); } else if (!QPixmapCache::find(cacheKey, &pixmap)) { int baseSize = basePixmap.width(); - int badgeSize = baseSize <= IconSize::Default * basePixmap.devicePixelRatio() ? baseSize * 0.6 : baseSize * 0.5; + int badgeSize = + baseSize <= iconSize(IconSize::Default) * basePixmap.devicePixelRatio() ? baseSize * 0.6 : baseSize * 0.5; QPoint badgePos(baseSize - badgeSize, baseSize - badgeSize); badgePos /= basePixmap.devicePixelRatio(); @@ -106,3 +111,15 @@ int DatabaseIcons::count() { return iconList.size(); } + +int DatabaseIcons::iconSize(IconSize size) +{ + switch (size) { + case Medium: + return m_compactMode ? 26 : 30; + case Large: + return m_compactMode ? 30 : 36; + default: + return m_compactMode ? 16 : 22; + } +} diff --git a/src/core/DatabaseIcons.h b/src/core/DatabaseIcons.h index 9f33644ee..2abb8a485 100644 --- a/src/core/DatabaseIcons.h +++ b/src/core/DatabaseIcons.h @@ -39,11 +39,14 @@ public: QPixmap applyBadge(const QPixmap& basePixmap, Badges badgeIndex); int count(); + int iconSize(IconSize size); + private: DatabaseIcons(); static DatabaseIcons* m_instance; QHash<QString, QIcon> m_iconCache; + bool m_compactMode; Q_DISABLE_COPY(DatabaseIcons) }; diff --git a/src/core/Global.h b/src/core/Global.h index ad6cc1f08..aebdb4559 100644 --- a/src/core/Global.h +++ b/src/core/Global.h @@ -48,9 +48,9 @@ static const auto FALSE_STR = QStringLiteral("false"); enum IconSize { - Default = 22, - Medium = 30, - Large = 36 + Default, + Medium, + Large }; template <typename T> struct AddConst diff --git a/src/core/Metadata.cpp b/src/core/Metadata.cpp index 67a58b068..8192bbb71 100644 --- a/src/core/Metadata.cpp +++ b/src/core/Metadata.cpp @@ -20,6 +20,7 @@ #include <QtCore/QCryptographicHash> #include "core/Clock.h" +#include "core/DatabaseIcons.h" #include "core/Entry.h" #include "core/Group.h" #include "core/Tools.h" @@ -186,7 +187,7 @@ QPixmap Metadata::customIconPixmap(const QUuid& uuid, IconSize size) const if (!hasCustomIcon(uuid)) { return {}; } - return m_customIcons.value(uuid).pixmap(size); + return m_customIcons.value(uuid).pixmap(databaseIcons()->iconSize(size)); } QHash<QUuid, QPixmap> Metadata::customIconsPixmaps(IconSize size) const @@ -380,9 +381,9 @@ void Metadata::addCustomIcon(const QUuid& uuid, const QImage& image) // Generate QIcon with pre-baked resolutions auto basePixmap = QPixmap::fromImage(image).scaled(128, 128, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); QIcon icon(basePixmap); - icon.addPixmap(icon.pixmap(IconSize::Default)); - icon.addPixmap(icon.pixmap(IconSize::Medium)); - icon.addPixmap(icon.pixmap(IconSize::Large)); + icon.addPixmap(icon.pixmap(databaseIcons()->iconSize(IconSize::Default))); + icon.addPixmap(icon.pixmap(databaseIcons()->iconSize(IconSize::Medium))); + icon.addPixmap(icon.pixmap(databaseIcons()->iconSize(IconSize::Large))); m_customIcons.insert(uuid, icon); } else { m_customIcons.insert(uuid, QIcon()); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index c0d6397c3..88965fe2c 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -107,6 +107,10 @@ MainWindow::MainWindow() setAcceptDrops(true); + if (config()->get(Config::GUI_CompactMode).toBool()) { + m_ui->toolBar->setIconSize({20, 20}); + } + // Setup the search widget in the toolbar m_searchWidget = new SearchWidget(); m_searchWidget->connectSignals(m_actionMultiplexer); @@ -1684,6 +1688,12 @@ void MainWindow::initViewMenu() } }); + m_ui->actionCompactMode->setChecked(config()->get(Config::GUI_CompactMode).toBool()); + connect(m_ui->actionCompactMode, &QAction::toggled, this, [this](bool checked) { + config()->set(Config::GUI_CompactMode, checked); + restartApp(tr("You must restart the application to apply this setting. Would you like to restart now?")); + }); + m_ui->actionShowToolbar->setChecked(!config()->get(Config::GUI_HideToolbar).toBool()); connect(m_ui->actionShowToolbar, &QAction::toggled, this, [this](bool checked) { config()->set(Config::GUI_HideToolbar, !checked); diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index 71efe1e6e..052a5da31 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -367,6 +367,7 @@ <addaction name="actionThemeClassic"/> </widget> <addaction name="menuTheme"/> + <addaction name="actionCompactMode"/> <addaction name="actionShowPreviewPanel"/> <addaction name="actionShowToolbar"/> </widget> @@ -861,6 +862,14 @@ <string>Remove key from SSH Agent</string> </property> </action> + <action name="actionCompactMode"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="text"> + <string>Compact Mode</string> + </property> + </action> <action name="actionThemeAuto"> <property name="checkable"> <bool>true</bool> diff --git a/src/gui/SearchWidget.ui b/src/gui/SearchWidget.ui index b98f4aea7..74cc468cf 100644 --- a/src/gui/SearchWidget.ui +++ b/src/gui/SearchWidget.ui @@ -6,17 +6,11 @@ <rect> <x>0</x> <y>0</y> - <width>630</width> + <width>465</width> <height>34</height> </rect> </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <layout class="QHBoxLayout" name="horizontalLayout" stretch="4"> + <layout class="QHBoxLayout" name="horizontalLayout"> <property name="leftMargin"> <number>3</number> </property> @@ -32,20 +26,17 @@ <item> <widget class="QLineEdit" name="searchEdit"> <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="minimumSize"> <size> - <width>0</width> + <width>150</width> <height>0</height> </size> </property> - <property name="styleSheet"> - <string notr="true">padding:3px</string> - </property> <property name="placeholderText"> <string/> </property> |