Application now follows "hide/quit on last window close".
This commit is contained in:
parent
0689353540
commit
5f30277e69
@ -12,7 +12,7 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "CompanyName", "@APP_AUTHOR@"
|
||||
VALUE "FileDescription", "@APP_NAME@"
|
||||
VALUE "FileVersion", "1.0.0.0"
|
||||
VALUE "FileVersion", "@APP_VERSION@"
|
||||
VALUE "InternalName", "@APP_AUTHOR@"
|
||||
VALUE "LegalCopyright", "Copyright © 2011-2013 Martin Rotter"
|
||||
VALUE "LegalTrademarks1", "Some rights reserved"
|
||||
|
@ -1,6 +1,7 @@
|
||||
// for testing
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include <QCloseEvent>
|
||||
|
||||
#include "gui/formmain.h"
|
||||
#include "gui/formsettings.h"
|
||||
@ -21,10 +22,6 @@ FormMain::FormMain(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::FormMain
|
||||
|
||||
// Establish connections.
|
||||
createConnections();
|
||||
|
||||
// testing purposes
|
||||
SystemTrayIcon *icon = SystemTrayIcon::getInstance();
|
||||
icon->show();
|
||||
}
|
||||
|
||||
FormMain::~FormMain() {
|
||||
@ -57,7 +54,7 @@ void FormMain::cleanupResources() {
|
||||
qDebug("Cleaning up resources before the application exits.");
|
||||
}
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
#if !defined(Q_OS_WIN)
|
||||
bool FormMain::event(QEvent *event) {
|
||||
if (event->type() == ThemeFactoryEvent::type()) {
|
||||
// Handle the change of icon theme.
|
||||
@ -84,6 +81,24 @@ void FormMain::createConnections() {
|
||||
connect(qApp, &QCoreApplication::aboutToQuit, this, &FormMain::cleanupResources);
|
||||
}
|
||||
|
||||
void FormMain::closeEvent(QCloseEvent *event) {
|
||||
if (SystemTrayIcon::isSystemTrayActivated()) {
|
||||
if (Settings::getInstance()->value(APP_CFG_GUI,
|
||||
"close_win_action",
|
||||
0).toInt() == 0) {
|
||||
// User selected to minimize the application if its main
|
||||
// window gets closed and tray icon is activated.
|
||||
hide();
|
||||
event->ignore();
|
||||
}
|
||||
else {
|
||||
// User selected to quit the application if its main
|
||||
// window gets closed and tray icon is activated.
|
||||
qApp->quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FormMain::showSettings() {
|
||||
FormSettings form_settings(this);
|
||||
form_settings.exec();
|
||||
|
@ -17,8 +17,9 @@ class FormMain : public QMainWindow {
|
||||
|
||||
protected:
|
||||
void createConnections();
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
#if !defined(Q_OS_WIN)
|
||||
bool event(QEvent *event);
|
||||
|
||||
// Sets up proper icons for this widget.
|
||||
|
@ -35,7 +35,6 @@ void FormSettings::saveSettings() {
|
||||
void FormSettings::loadInterface() {
|
||||
// Load settings of tray icon.
|
||||
if (SystemTrayIcon::isSystemTrayAvailable()) {
|
||||
// načti
|
||||
m_ui->m_radioTrayOff->setChecked(!Settings::getInstance()->value(APP_CFG_GUI,
|
||||
"use_tray_icon",
|
||||
true).toBool());
|
||||
@ -43,6 +42,7 @@ void FormSettings::loadInterface() {
|
||||
"close_win_action",
|
||||
0).toInt());
|
||||
}
|
||||
// Tray icon is not supported on this machine.
|
||||
else {
|
||||
m_ui->m_radioTrayOff->setText(tr("disable (Tray icon is not available.)"));
|
||||
m_ui->m_radioTrayOff->setChecked(true);
|
||||
|
@ -45,7 +45,7 @@
|
||||
<item row="0" column="1">
|
||||
<widget class="QStackedWidget" name="m_stackedSettings">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="m_pageGeneral"/>
|
||||
<widget class="QWidget" name="m_pageUi">
|
||||
@ -68,7 +68,7 @@
|
||||
<enum>QTabWidget::North</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="m_tabIconSkin">
|
||||
<attribute name="title">
|
||||
|
@ -58,11 +58,19 @@ void SystemTrayIcon::show_private() {
|
||||
}
|
||||
|
||||
void SystemTrayIcon::show() {
|
||||
#if defined(Q_OS_WIN)
|
||||
// Show immediately.
|
||||
qDebug("Showing tray icon immediately.");
|
||||
show_private();
|
||||
#else
|
||||
// Delay avoids race conditions and tray icon is properly displayed.
|
||||
qDebug("Showing tray icon with 1000 ms delay.");
|
||||
QTimer::singleShot(1000,
|
||||
Qt::CoarseTimer,
|
||||
this, SLOT(show_private()));
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SystemTrayIcon::setNumber(int number) {
|
||||
|
@ -8,7 +8,8 @@
|
||||
class FormMain;
|
||||
|
||||
class SystemTrayIcon : public QSystemTrayIcon {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SystemTrayIcon(const QString &normal_icon,
|
||||
const QString &plain_icon,
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "gui/themefactory.h"
|
||||
#include "gui/formmain.h"
|
||||
#include "gui/formwelcome.h"
|
||||
#include "gui/systemtrayicon.h"
|
||||
#include "qtsingleapplication/qtsingleapplication.h"
|
||||
|
||||
|
||||
@ -69,6 +70,7 @@ int main(int argc, char *argv[]) {
|
||||
// Instantiate main application window.
|
||||
FormMain window;
|
||||
|
||||
// Display welcome dialog if application is launched for the first time.
|
||||
if (Settings::getInstance()->value(APP_CFG_GEN, "first_start", true).toBool()) {
|
||||
Settings::getInstance()->setValue(APP_CFG_GEN, "first_start", false);
|
||||
FormWelcome(&window).exec();
|
||||
@ -77,6 +79,11 @@ int main(int argc, char *argv[]) {
|
||||
// Display main window.
|
||||
window.show();
|
||||
|
||||
// Display tray icon if it is enabled and available.
|
||||
if (SystemTrayIcon::isSystemTrayActivated()) {
|
||||
SystemTrayIcon::getInstance()->show();
|
||||
}
|
||||
|
||||
// Setup single-instance behavior.
|
||||
application.setActivationWindow(&window, true);
|
||||
QObject::connect(&application, &QtSingleApplication::messageReceived,
|
||||
|
Loading…
x
Reference in New Issue
Block a user