Skip to content

Commit fd65a47

Browse files
committed
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)
1 parent 4bf6d8d commit fd65a47

9 files changed

Lines changed: 58 additions & 25 deletions

File tree

src/core/Config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
101101
{Config::GUI_AdvancedSettings, {QS("GUI/AdvancedSettings"), Roaming, false}},
102102
{Config::GUI_MonospaceNotes, {QS("GUI/MonospaceNotes"), Roaming, false}},
103103
{Config::GUI_ApplicationTheme, {QS("GUI/ApplicationTheme"), Roaming, QS("auto")}},
104+
{Config::GUI_CompactMode, {QS("GUI/CompactMode"), Roaming, false}},
104105
{Config::GUI_CheckForUpdates, {QS("GUI/CheckForUpdates"), Roaming, true}},
105106
{Config::GUI_CheckForUpdatesNextCheck, {QS("GUI/CheckForUpdatesNextCheck"), Local, 0}},
106107
{Config::GUI_CheckForUpdatesIncludeBetas, {QS("GUI/CheckForUpdatesIncludeBetas"), Roaming, false}},

src/core/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class Config : public QObject
8484
GUI_AdvancedSettings,
8585
GUI_MonospaceNotes,
8686
GUI_ApplicationTheme,
87+
GUI_CompactMode,
8788
GUI_CheckForUpdates,
8889
GUI_CheckForUpdatesIncludeBetas,
8990

src/core/DatabaseIcons.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "DatabaseIcons.h"
1919

20+
#include "core/Config.h"
2021
#include "core/Global.h"
2122
#include "core/Resources.h"
2223
#include "gui/MainWindow.h"
@@ -44,6 +45,9 @@ DatabaseIcons::DatabaseIcons()
4445

4546
iconList = QDir(iconDir).entryList(QDir::NoFilter, QDir::Name);
4647
badgeList = QDir(badgeDir).entryList(QDir::NoFilter, QDir::Name);
48+
49+
// Set this early and once to ensure consistent icon size until app restart
50+
m_compactMode = config()->get(Config::GUI_CompactMode).toBool();
4751
}
4852

4953
DatabaseIcons* DatabaseIcons::instance()
@@ -66,13 +70,13 @@ QPixmap DatabaseIcons::icon(int index, IconSize size)
6670
auto icon = m_iconCache.value(cacheKey);
6771
if (icon.isNull()) {
6872
icon.addFile(iconDir + iconList[index]);
69-
icon.addPixmap(icon.pixmap(IconSize::Default));
70-
icon.addPixmap(icon.pixmap(IconSize::Medium));
71-
icon.addPixmap(icon.pixmap(IconSize::Large));
73+
icon.addPixmap(icon.pixmap(iconSize(IconSize::Default)));
74+
icon.addPixmap(icon.pixmap(iconSize(IconSize::Medium)));
75+
icon.addPixmap(icon.pixmap(iconSize(IconSize::Large)));
7276
m_iconCache.insert(cacheKey, icon);
7377
}
7478

75-
return icon.pixmap(size);
79+
return icon.pixmap(iconSize(size));
7680
}
7781

7882
QPixmap DatabaseIcons::applyBadge(const QPixmap& basePixmap, Badges badgeIndex)
@@ -83,7 +87,8 @@ QPixmap DatabaseIcons::applyBadge(const QPixmap& basePixmap, Badges badgeIndex)
8387
qWarning("DatabaseIcons: Out-of-range badge index given to applyBadge: %d", badgeIndex);
8488
} else if (!QPixmapCache::find(cacheKey, &pixmap)) {
8589
int baseSize = basePixmap.width();
86-
int badgeSize = baseSize <= IconSize::Default * basePixmap.devicePixelRatio() ? baseSize * 0.6 : baseSize * 0.5;
90+
int badgeSize =
91+
baseSize <= iconSize(IconSize::Default) * basePixmap.devicePixelRatio() ? baseSize * 0.6 : baseSize * 0.5;
8792
QPoint badgePos(baseSize - badgeSize, baseSize - badgeSize);
8893
badgePos /= basePixmap.devicePixelRatio();
8994

@@ -106,3 +111,15 @@ int DatabaseIcons::count()
106111
{
107112
return iconList.size();
108113
}
114+
115+
int DatabaseIcons::iconSize(IconSize size)
116+
{
117+
switch (size) {
118+
case Medium:
119+
return m_compactMode ? 26 : 30;
120+
case Large:
121+
return m_compactMode ? 30 : 36;
122+
default:
123+
return m_compactMode ? 16 : 22;
124+
}
125+
}

src/core/DatabaseIcons.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ class DatabaseIcons
3939
QPixmap applyBadge(const QPixmap& basePixmap, Badges badgeIndex);
4040
int count();
4141

42+
int iconSize(IconSize size);
43+
4244
private:
4345
DatabaseIcons();
4446

4547
static DatabaseIcons* m_instance;
4648
QHash<QString, QIcon> m_iconCache;
49+
bool m_compactMode;
4750

4851
Q_DISABLE_COPY(DatabaseIcons)
4952
};

src/core/Global.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ static const auto FALSE_STR = QStringLiteral("false");
4848

4949
enum IconSize
5050
{
51-
Default = 22,
52-
Medium = 30,
53-
Large = 36
51+
Default,
52+
Medium,
53+
Large
5454
};
5555

5656
template <typename T> struct AddConst

src/core/Metadata.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <QtCore/QCryptographicHash>
2121

2222
#include "core/Clock.h"
23+
#include "core/DatabaseIcons.h"
2324
#include "core/Entry.h"
2425
#include "core/Group.h"
2526
#include "core/Tools.h"
@@ -186,7 +187,7 @@ QPixmap Metadata::customIconPixmap(const QUuid& uuid, IconSize size) const
186187
if (!hasCustomIcon(uuid)) {
187188
return {};
188189
}
189-
return m_customIcons.value(uuid).pixmap(size);
190+
return m_customIcons.value(uuid).pixmap(databaseIcons()->iconSize(size));
190191
}
191192

192193
QHash<QUuid, QPixmap> Metadata::customIconsPixmaps(IconSize size) const
@@ -380,9 +381,9 @@ void Metadata::addCustomIcon(const QUuid& uuid, const QImage& image)
380381
// Generate QIcon with pre-baked resolutions
381382
auto basePixmap = QPixmap::fromImage(image).scaled(128, 128, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
382383
QIcon icon(basePixmap);
383-
icon.addPixmap(icon.pixmap(IconSize::Default));
384-
icon.addPixmap(icon.pixmap(IconSize::Medium));
385-
icon.addPixmap(icon.pixmap(IconSize::Large));
384+
icon.addPixmap(icon.pixmap(databaseIcons()->iconSize(IconSize::Default)));
385+
icon.addPixmap(icon.pixmap(databaseIcons()->iconSize(IconSize::Medium)));
386+
icon.addPixmap(icon.pixmap(databaseIcons()->iconSize(IconSize::Large)));
386387
m_customIcons.insert(uuid, icon);
387388
} else {
388389
m_customIcons.insert(uuid, QIcon());

src/gui/MainWindow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ MainWindow::MainWindow()
107107

108108
setAcceptDrops(true);
109109

110+
if (config()->get(Config::GUI_CompactMode).toBool()) {
111+
m_ui->toolBar->setIconSize({20, 20});
112+
}
113+
110114
// Setup the search widget in the toolbar
111115
m_searchWidget = new SearchWidget();
112116
m_searchWidget->connectSignals(m_actionMultiplexer);
@@ -1684,6 +1688,12 @@ void MainWindow::initViewMenu()
16841688
}
16851689
});
16861690

1691+
m_ui->actionCompactMode->setChecked(config()->get(Config::GUI_CompactMode).toBool());
1692+
connect(m_ui->actionCompactMode, &QAction::toggled, this, [this](bool checked) {
1693+
config()->set(Config::GUI_CompactMode, checked);
1694+
restartApp(tr("You must restart the application to apply this setting. Would you like to restart now?"));
1695+
});
1696+
16871697
m_ui->actionShowToolbar->setChecked(!config()->get(Config::GUI_HideToolbar).toBool());
16881698
connect(m_ui->actionShowToolbar, &QAction::toggled, this, [this](bool checked) {
16891699
config()->set(Config::GUI_HideToolbar, !checked);

src/gui/MainWindow.ui

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@
367367
<addaction name="actionThemeClassic"/>
368368
</widget>
369369
<addaction name="menuTheme"/>
370+
<addaction name="actionCompactMode"/>
370371
<addaction name="actionShowPreviewPanel"/>
371372
<addaction name="actionShowToolbar"/>
372373
</widget>
@@ -861,6 +862,14 @@
861862
<string>Remove key from SSH Agent</string>
862863
</property>
863864
</action>
865+
<action name="actionCompactMode">
866+
<property name="checkable">
867+
<bool>true</bool>
868+
</property>
869+
<property name="text">
870+
<string>Compact Mode</string>
871+
</property>
872+
</action>
864873
<action name="actionThemeAuto">
865874
<property name="checkable">
866875
<bool>true</bool>

src/gui/SearchWidget.ui

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>630</width>
9+
<width>465</width>
1010
<height>34</height>
1111
</rect>
1212
</property>
13-
<property name="sizePolicy">
14-
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
15-
<horstretch>0</horstretch>
16-
<verstretch>0</verstretch>
17-
</sizepolicy>
18-
</property>
19-
<layout class="QHBoxLayout" name="horizontalLayout" stretch="4">
13+
<layout class="QHBoxLayout" name="horizontalLayout">
2014
<property name="leftMargin">
2115
<number>3</number>
2216
</property>
@@ -32,20 +26,17 @@
3226
<item>
3327
<widget class="QLineEdit" name="searchEdit">
3428
<property name="sizePolicy">
35-
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
29+
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
3630
<horstretch>0</horstretch>
3731
<verstretch>0</verstretch>
3832
</sizepolicy>
3933
</property>
4034
<property name="minimumSize">
4135
<size>
42-
<width>0</width>
36+
<width>150</width>
4337
<height>0</height>
4438
</size>
4539
</property>
46-
<property name="styleSheet">
47-
<string notr="true">padding:3px</string>
48-
</property>
4940
<property name="placeholderText">
5041
<string/>
5142
</property>

0 commit comments

Comments
 (0)