Fixed closing events.

This commit is contained in:
Martin Rotter 2014-01-12 19:41:13 +01:00
parent a9391c1ce4
commit 50cb0ba105
4 changed files with 38 additions and 86 deletions

View File

@ -20,6 +20,7 @@
#include <QRect>
#include <QDesktopWidget>
#include <QReadWriteLock>
#include <QTimer>
FormMain *FormMain::s_instance;
@ -168,16 +169,20 @@ void FormMain::display() {
}
void FormMain::onCommitData(QSessionManager &manager) {
Q_UNUSED(manager)
qDebug("OS asked application to commit its data.");
QFile("/home/martin/Dokumenty/aaa").open(QIODevice::ReadWrite);
manager.release();
}
void FormMain::onSaveState(QSessionManager &manager) {
Q_UNUSED(manager)
qDebug("OS asked application to save its state.");
QFile("/home/martin/Dokumenty/ccc").open(QIODevice::ReadWrite);
manager.release();
}
void FormMain::onAboutToQuit() {
QFile("/home/martin/Dokumenty/bbb").open(QIODevice::ReadWrite);
// Make sure that we obtain close lock
// BEFORE even trying to quit the application.
if (SystemFactory::getInstance()->applicationCloseLock()->tryLockForWrite(CLOSE_LOCK_TIMEOUT)) {
@ -325,22 +330,23 @@ void FormMain::loadWebBrowserMenu(int index) {
m_ui->m_actionCloseCurrentTab->setEnabled(m_ui->m_tabWidget->tabBar()->tabType(index) == TabBar::Closable);
}
void FormMain::closeEvent(QCloseEvent *event) {
void FormMain::changeEvent(QEvent *event) {
switch (event->type()) {
case QEvent::WindowStateChange: {
if (SystemTrayIcon::isSystemTrayActivated()) {
if (Settings::instance()->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();
if (this->windowState() & Qt::WindowMinimized) {
QTimer::singleShot(250, this, SLOT(hide()));
}
}
break;
}
default:
break;
}
QMainWindow::changeEvent(event);
}
void FormMain::showAbout() {

View File

@ -46,7 +46,7 @@ class FormMain : public QMainWindow {
void createConnections();
// Event handler reimplementations.
void closeEvent(QCloseEvent *event);
void changeEvent(QEvent *event);
bool event(QEvent *event);
// Sets up proper icons for this widget.
@ -87,6 +87,7 @@ class FormMain : public QMainWindow {
void showAbout();
private:
bool m_quitting;
Ui::FormMain *m_ui;
QMenu *m_trayMenu;
StatusBar *m_statusBar;

View File

@ -456,9 +456,6 @@ void FormSettings::loadInterface() {
m_ui->m_radioTrayOff->setChecked(!settings->value(APP_CFG_GUI,
"use_tray_icon",
true).toBool());
m_ui->m_cmbTrayClose->setCurrentIndex(settings->value(APP_CFG_GUI,
"close_win_action",
0).toInt());
m_ui->m_checkHidden->setChecked(settings->value(APP_CFG_GUI,
"start_hidden",
false).toBool());
@ -550,8 +547,6 @@ void FormSettings::saveInterface() {
if (SystemTrayIcon::isSystemTrayAvailable()) {
settings->setValue(APP_CFG_GUI, "use_tray_icon",
m_ui->m_radioTrayOn->isChecked());
settings->setValue(APP_CFG_GUI, "close_win_action",
m_ui->m_cmbTrayClose->currentIndex());
settings->setValue(APP_CFG_GUI, "start_hidden",
m_ui->m_checkHidden->isChecked());
if (settings->value(APP_CFG_GUI, "use_tray_icon", true).toBool()) {

View File

@ -17,7 +17,7 @@
<item row="0" column="1">
<widget class="QStackedWidget" name="m_stackedSettings">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="m_pageGeneral">
<layout class="QFormLayout" name="formLayout_5">
@ -51,8 +51,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>576</width>
<height>373</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -79,7 +79,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">
@ -216,6 +216,9 @@
<string>Tray icon</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="m_radioTrayOff">
<property name="text">
@ -233,28 +236,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="m_lblTrayClose">
<property name="text">
<string>When main window is closed, then</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="m_cmbTrayClose">
<item>
<property name="text">
<string>hide it.</string>
</property>
</item>
<item>
<property name="text">
<string>quit the application.</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkHidden">
<property name="text">
<string>Start application hidden</string>
@ -802,38 +784,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>m_radioTrayOn</sender>
<signal>toggled(bool)</signal>
<receiver>m_lblTrayClose</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>508</x>
<y>102</y>
</hint>
<hint type="destinationlabel">
<x>419</x>
<y>128</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_radioTrayOn</sender>
<signal>toggled(bool)</signal>
<receiver>m_cmbTrayClose</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>508</x>
<y>102</y>
</hint>
<hint type="destinationlabel">
<x>678</x>
<y>128</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_radioTrayOn</sender>
<signal>toggled(bool)</signal>