Skip to content

Commit

Permalink
QMenubar option to show/hide itself
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikko Saarinki committed Feb 29, 2024
1 parent a472ef8 commit 7b78327
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
24 changes: 16 additions & 8 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3700,11 +3700,6 @@ This may cause the affected plugins to malfunction.</source>
<source>Confirm Overwrite Attachment</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Attachment &quot;%1&quot; already exists.
Would you like to overwrite the existing attachment?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Confirm Attachment</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -3734,6 +3729,11 @@ Do you want to save the changes to your database?</source>
Error: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Attachment &quot;%1&quot; already exists.
Would you like to overwrite the existing attachment?</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EntryAttributesModel</name>
Expand Down Expand Up @@ -5380,6 +5380,10 @@ Are you sure you want to continue with this file?</source>
<source>Classic (Platform-native)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show Menubar</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show Toolbar</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -5718,6 +5722,10 @@ We recommend you use the AppImage available on our downloads page.</source>
<source>Set Theme: Classic</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Toggle Show Menubar</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Toggle Show Toolbar</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -9649,15 +9657,15 @@ Example: JBSWY3DPEHPK3PXP</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;p&gt;If you own a &lt;a href=&quot;https://www.yubico.com/&quot;&gt;YubiKey&lt;/a&gt; or &lt;a href=&quot;https://onlykey.io&quot;&gt;OnlyKey&lt;/a&gt;, you can use it for additional security.&lt;/p&gt;&lt;p&gt;The key requires one of its slots to be programmed as &lt;a href=&quot;https://www.yubico.com/products/services-software/challenge-response/&quot;&gt;HMAC-SHA1 Challenge-Response&lt;/a&gt;.&lt;/p&gt;</source>
<source>Detecting hardware keys…</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Detecting hardware keys</source>
<source>No hardware keys detected</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No hardware keys detected</source>
<source>&lt;p&gt;If you own a &lt;a href=&quot;https://www.yubico.com/&quot;&gt;YubiKey&lt;/a&gt; or &lt;a href=&quot;https://onlykey.io&quot;&gt;OnlyKey&lt;/a&gt;, you can use it for additional security.&lt;/p&gt;&lt;p&gt;The key requires one of its slots to be programmed as &lt;a href=&quot;https://docs.yubico.com/yesdk/users-manual/application-otp/challenge-response.html&quot;&gt;HMAC-SHA1 Challenge-Response&lt;/a&gt;.&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
Expand Down
1 change: 1 addition & 0 deletions src/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {

// GUI
{Config::GUI_Language, {QS("GUI/Language"), Roaming, QS("system")}},
{Config::GUI_HideMenubar, {QS("GUI/HideMenubar"), Roaming, false}},
{Config::GUI_HideToolbar, {QS("GUI/HideToolbar"), Roaming, false}},
{Config::GUI_MovableToolbar, {QS("GUI/MovableToolbar"), Roaming, false}},
{Config::GUI_HidePreviewPanel, {QS("GUI/HidePreviewPanel"), 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 @@ -74,6 +74,7 @@ class Config : public QObject
LastDir,

GUI_Language,
GUI_HideMenubar,
GUI_HideToolbar,
GUI_MovableToolbar,
GUI_HidePreviewPanel,
Expand Down
28 changes: 27 additions & 1 deletion src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ MainWindow::MainWindow()
m_ui->menubar->installEventFilter(eventFilter);
m_ui->toolBar->installEventFilter(eventFilter);
m_ui->tabWidget->tabBar()->installEventFilter(eventFilter);
installEventFilter(eventFilter);
#endif

#ifdef Q_OS_MACOS
Expand Down Expand Up @@ -1655,6 +1656,7 @@ void MainWindow::applySettingsChanges()
m_inactivityTimer->deactivate();
}

m_ui->menubar->setHidden(config()->get(Config::GUI_HideMenubar).toBool());
m_ui->toolBar->setHidden(config()->get(Config::GUI_HideToolbar).toBool());
auto movable = config()->get(Config::GUI_MovableToolbar).toBool();
m_ui->toolBar->setMovable(movable);
Expand Down Expand Up @@ -2017,6 +2019,16 @@ void MainWindow::initViewMenu()
}
});

#ifdef Q_OS_MACOS
m_ui->actionShowMenubar->setVisible(false);
#else
m_ui->actionShowMenubar->setChecked(!config()->get(Config::GUI_HideMenubar).toBool());
connect(m_ui->actionShowMenubar, &QAction::toggled, this, [this](bool checked) {
config()->set(Config::GUI_HideMenubar, !checked);
applySettingsChanges();
});
#endif

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 Expand Up @@ -2122,6 +2134,9 @@ void MainWindow::initActionCollection()
m_ui->actionThemeDark,
m_ui->actionThemeClassic,
m_ui->actionCompactMode,
#ifndef Q_OS_MACOS
m_ui->actionShowMenubar,
#endif
m_ui->actionShowToolbar,
m_ui->actionShowPreviewPanel,
m_ui->actionAllowScreenCapture,
Expand Down Expand Up @@ -2199,6 +2214,7 @@ MainWindowEventFilter::MainWindowEventFilter(QObject* parent)

/**
* MainWindow event filter to initiate empty-area drag on the toolbar, menubar, and tabbar.
* Also shows menubar with Alt when menubar itself is hidden.
*/
bool MainWindowEventFilter::eventFilter(QObject* watched, QEvent* event)
{
Expand All @@ -2207,7 +2223,8 @@ bool MainWindowEventFilter::eventFilter(QObject* watched, QEvent* event)
return QObject::eventFilter(watched, event);
}

if (event->type() == QEvent::MouseButtonPress) {
auto eventType = event->type();
if (eventType == QEvent::MouseButtonPress) {
if (watched == mainWindow->m_ui->menubar) {
auto* m = static_cast<QMouseEvent*>(event);
if (!mainWindow->m_ui->menubar->actionAt(m->pos())) {
Expand All @@ -2226,6 +2243,15 @@ bool MainWindowEventFilter::eventFilter(QObject* watched, QEvent* event)
return true;
}
}
} else if (eventType == QEvent::KeyRelease) {
if (watched == mainWindow) {
auto m = static_cast<QKeyEvent*>(event);
if (m->key() == Qt::Key_Alt && config()->get(Config::GUI_HideMenubar).toBool()) {
auto menubar = mainWindow->m_ui->menubar;
menubar->setVisible(!menubar->isVisible());
return false;
}
}
}

return QObject::eventFilter(watched, event);
Expand Down
15 changes: 15 additions & 0 deletions src/gui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
<addaction name="actionAlwaysOnTop"/>
<addaction name="actionAllowScreenCapture"/>
<addaction name="actionShowPreviewPanel"/>
<addaction name="actionShowMenubar"/>
<addaction name="actionShowToolbar"/>
<addaction name="actionHideUsernames"/>
<addaction name="actionHidePasswords"/>
Expand Down Expand Up @@ -1138,6 +1139,20 @@
<string>Set Theme: Classic</string>
</property>
</action>
<action name="actionShowMenubar">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Show Menubar</string>
</property>
<property name="toolTip">
<string>Toggle Show Menubar</string>
</property>
</action>
<action name="actionShowToolbar">
<property name="checkable">
<bool>true</bool>
Expand Down

0 comments on commit 7b78327

Please sign in to comment.