Skip to content

Commit

Permalink
Introduce Compact Mode
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
droidmonkey committed Jun 28, 2020
1 parent 4bf6d8d commit fd65a47
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
Expand Down
1 change: 1 addition & 0 deletions src/core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Config : public QObject
GUI_AdvancedSettings,
GUI_MonospaceNotes,
GUI_ApplicationTheme,
GUI_CompactMode,
GUI_CheckForUpdates,
GUI_CheckForUpdatesIncludeBetas,

Expand Down
27 changes: 22 additions & 5 deletions src/core/DatabaseIcons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "DatabaseIcons.h"

#include "core/Config.h"
#include "core/Global.h"
#include "core/Resources.h"
#include "gui/MainWindow.h"
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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();

Expand All @@ -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;
}
}
3 changes: 3 additions & 0 deletions src/core/DatabaseIcons.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ class DatabaseIcons
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)
};
Expand Down
6 changes: 3 additions & 3 deletions src/core/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/core/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down
10 changes: 10 additions & 0 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/gui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@
<addaction name="actionThemeClassic"/>
</widget>
<addaction name="menuTheme"/>
<addaction name="actionCompactMode"/>
<addaction name="actionShowPreviewPanel"/>
<addaction name="actionShowToolbar"/>
</widget>
Expand Down Expand Up @@ -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>
Expand Down
17 changes: 4 additions & 13 deletions src/gui/SearchWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down

0 comments on commit fd65a47

Please sign in to comment.