Fix minimize at startup and decouple various tray and minimization options (#109)

* Hide window on startup when configured to start minimized, fixes #105
* Decouple different systray and minimization options, fixes #64
* Commit missing changes in main.cpp to minimize at startup

* Remove obsolete code
This commit is contained in:
Janek Bevendorff 2016-11-24 00:15:51 +01:00 committed by Jonathan White
parent 02d2ac904d
commit 19a960856c
7 changed files with 22 additions and 60 deletions

View File

@ -113,12 +113,6 @@ void DatabaseOpenWidget::openDatabase()
if (m_db) {
Q_EMIT editFinished(true);
// this is a c++11 equivalent foreach construct
// if c++11 is not available another iteration loop style is needed!
for (auto widget : qApp->topLevelWidgets()) {
if(widget->inherits("QMainWindow"))
static_cast<MainWindow*>(widget)->configuredMinimizeWindow();
}
}
else {
MessageBox::warning(this, tr("Error"), tr("Unable to open the database.").append("\n")

View File

@ -329,14 +329,12 @@ void MainWindow::openDatabase(const QString& fileName, const QString& pw, const
m_ui->tabWidget->openDatabase(fileName, pw, keyFile);
}
void MainWindow::configuredMinimizeWindow()
void MainWindow::minimizeWindow()
{
bool minimize = isTrayIconEnabled() &&
config()->get("GUI/MinimizeToTray").toBool() &&
config()->get("GUI/MinimizeOnClose").toBool() &&
config()->get("GUI/MinimizeOnStartup").toBool();
if (minimize) {
if (isTrayIconEnabled() && config()->get("GUI/MinimizeToTray").toBool()) {
hide();
} else {
setWindowState(Qt::WindowMinimized);
}
}
@ -523,7 +521,6 @@ void MainWindow::databaseTabChanged(int tabIndex)
void MainWindow::closeEvent(QCloseEvent* event)
{
bool minimizeOnClose = isTrayIconEnabled() &&
config()->get("GUI/MinimizeToTray").toBool() &&
config()->get("GUI/MinimizeOnClose").toBool();
if (minimizeOnClose && !appExitCalled)
{

View File

@ -38,7 +38,7 @@ class MainWindow : public QMainWindow
public:
MainWindow();
~MainWindow();
void configuredMinimizeWindow();
void minimizeWindow();
public Q_SLOTS:
void openDatabase(const QString& fileName, const QString& pw = QString(),

View File

@ -74,11 +74,7 @@ SettingsWidget::SettingsWidget(QWidget* parent)
connect(m_generalUi->autoSaveAfterEveryChangeCheckBox, SIGNAL(toggled(bool)),
this, SLOT(enableAutoSaveOnExit(bool)));
connect(m_generalUi->systrayShowCheckBox, SIGNAL(toggled(bool)),
this, SLOT(enableSystrayMinimizeToTray(bool)));
connect(m_generalUi->systrayMinimizeToTrayCheckBox, SIGNAL(toggled(bool)),
this, SLOT(enableSystrayMinimizeToTray2(bool)));
connect(m_generalUi->systrayMinimizeOnCloseCheckBox, SIGNAL(toggled(bool)),
m_generalUi->systrayMinimizeOnStartup, SLOT(setEnabled(bool)));
this, SLOT(enableSystray(bool)));
connect(m_secUi->clearClipboardCheckBox, SIGNAL(toggled(bool)),
m_secUi->clearClipboardSpinBox, SLOT(setEnabled(bool)));
@ -209,18 +205,8 @@ void SettingsWidget::enableAutoSaveOnExit(bool checked)
m_generalUi->autoSaveOnExitCheckBox->setEnabled(!checked);
}
void SettingsWidget::enableSystrayMinimizeToTray(bool checked)
void SettingsWidget::enableSystray(bool checked)
{
m_generalUi->systrayMinimizeToTrayCheckBox->setEnabled(checked);
bool checked2 = m_generalUi->systrayMinimizeToTrayCheckBox->checkState();
m_generalUi->systrayMinimizeOnCloseCheckBox->setEnabled(checked && checked2);
bool checked3 = m_generalUi->systrayMinimizeOnCloseCheckBox->checkState();
m_generalUi->systrayMinimizeOnStartup->setEnabled(checked && checked2 && checked3);
}
void SettingsWidget::enableSystrayMinimizeToTray2(bool checked)
{
m_generalUi->systrayMinimizeOnCloseCheckBox->setEnabled(checked);
bool checked2 = m_generalUi->systrayMinimizeOnCloseCheckBox->checkState();
m_generalUi->systrayMinimizeOnStartup->setEnabled(checked && checked2);
}

View File

@ -51,8 +51,7 @@ private Q_SLOTS:
void saveSettings();
void reject();
void enableAutoSaveOnExit(bool checked);
void enableSystrayMinimizeToTray(bool checked);
void enableSystrayMinimizeToTray2(bool checked);
void enableSystray(bool checked);
private:
QWidget* const m_secWidget;

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>684</width>
<height>394</height>
<height>452</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
@ -37,7 +37,7 @@
<item row="2" column="0">
<widget class="QCheckBox" name="openPreviousDatabasesOnStartupCheckBox">
<property name="text">
<string>Open previous databases on startup</string>
<string>Load previous databases on startup</string>
</property>
</widget>
</item>
@ -113,12 +113,9 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<width>40</width>
<height>20</height>
</size>
</property>
@ -166,7 +163,7 @@
<bool>false</bool>
</property>
<property name="text">
<string>Hide window to system tray instead of App Exit</string>
<string>Hide window to system tray instead of app exit</string>
</property>
</widget>
</item>
@ -177,26 +174,10 @@
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>60</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="systrayMinimizeOnStartup">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Hide window to system tray on App start</string>
<string>Minimize window at application startup</string>
</property>
</widget>
</item>

View File

@ -86,11 +86,11 @@ int main(int argc, char** argv)
#endif
MainWindow mainWindow;
mainWindow.show();
app.setMainWindow(&mainWindow);
mainWindow.show();
QObject::connect(&app, SIGNAL(openFile(QString)), &mainWindow, SLOT(openDatabase(QString)));
for (int ii=0; ii < args.length(); ii++) {
QString filename = args[ii];
if (!filename.isEmpty() && QFile::exists(filename)) {
@ -111,6 +111,11 @@ int main(int argc, char** argv)
}
}
}
// start minimized if configured
if (config()->get("GUI/MinimizeOnStartup").toBool()) {
mainWindow.minimizeWindow();
}
return app.exec();
}