[Pkg-running-devel] [openambit] 63/131: Added "minimize to tray" functionality. Implements #18
Christian Perrier
bubulle at moszumanska.debian.org
Thu Jul 17 20:19:11 UTC 2014
This is an automated email from the git hooks/post-receive script.
bubulle pushed a commit to branch master
in repository openambit.
commit e89af1e3b540a637f2b8c2a3ccd4dad20f81f869
Author: Emil Ljungdahl <emil at kratern.se>
Date: Wed Jan 22 08:03:48 2014 +0100
Added "minimize to tray" functionality.
Implements #18
---
src/openambit/mainwindow.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++
src/openambit/mainwindow.h | 13 +++++++++
src/openambit/mainwindow.ui | 3 +-
3 files changed, 84 insertions(+), 1 deletion(-)
diff --git a/src/openambit/mainwindow.cpp b/src/openambit/mainwindow.cpp
index 354cca9..8fab96d 100644
--- a/src/openambit/mainwindow.cpp
+++ b/src/openambit/mainwindow.cpp
@@ -23,6 +23,7 @@
#include "ui_mainwindow.h"
#include <QListWidgetItem>
+#include <QCloseEvent>
#define APPKEY "HpF9f1qV5qrDJ1hY1QK1diThyPsX10Mh4JvCw9xVQSglJNLdcwr3540zFyLzIC3e"
#define MOVESCOUNT_DEFAULT_URL "https://uiservices.movescount.com/"
@@ -30,10 +31,12 @@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
+ forceClose(false),
movesCount(NULL),
currentLogMessageRow(NULL)
{
ui->setupUi(this);
+ ui->actionE_xit->setShortcut(QKeySequence(QKeySequence::Quit));
// Setup UI parts
QIcon warningIcon = QIcon::fromTheme("dialog-warning");
@@ -68,7 +71,20 @@ MainWindow::MainWindow(QWidget *parent) :
}
// System tray icon
+ trayIconSyncAction = new QAction(QIcon::fromTheme("view-refresh"), tr("Sync now"), this);
+ trayIconSyncAction->setDisabled(true);
+ trayIconMinimizeRestoreAction = new QAction(tr("Minimize"), this);
+ connect(trayIconSyncAction, SIGNAL(triggered()), this, SLOT(syncNowClicked()));
+ connect(trayIconMinimizeRestoreAction, SIGNAL(triggered()), this, SLOT(showHideWindow()));
+
+ trayIconMenu = new QMenu(this);
+ trayIconMenu->addAction(trayIconSyncAction);
+ trayIconMenu->addSeparator();
+ trayIconMenu->addAction(trayIconMinimizeRestoreAction);
+ trayIconMenu->addAction(ui->actionE_xit);
trayIcon = new QSystemTrayIcon(QIcon(":/icon_disconnected"));
+ trayIcon->setContextMenu(trayIconMenu);
+ connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason)));
trayIcon->show();
// Setup device manager
@@ -105,6 +121,54 @@ MainWindow::~MainWindow()
delete ui;
}
+void MainWindow::changeEvent(QEvent *event)
+{
+ if (event->type() == QEvent::WindowStateChange) {
+ if (isMinimized()) {
+ trayIconMinimizeRestoreAction->setText(tr("Restore"));
+ QTimer::singleShot(0, this, SLOT(hide()));
+ }
+ else {
+ trayIconMinimizeRestoreAction->setText(tr("Minimize"));
+ }
+ }
+ QMainWindow::changeEvent(event);
+}
+
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+ if (forceClose) {
+ event->accept();
+ }
+ else {
+ showHideWindow();
+ event->ignore();
+ }
+}
+
+void MainWindow::closeRequested()
+{
+ forceClose = true;
+ close();
+}
+
+void MainWindow::showHideWindow()
+{
+ if (isMinimized()) {
+ showNormal();
+ }
+ else {
+ showMinimized();
+ }
+}
+
+void MainWindow::trayIconClicked(QSystemTrayIcon::ActivationReason reason)
+{
+ if (reason == QSystemTrayIcon::Trigger) {
+ showHideWindow();
+ }
+}
+
void MainWindow::showSettings()
{
settingsDialog = new SettingsDialog(this);
@@ -140,6 +204,7 @@ void MainWindow::deviceDetected(ambit_device_info_t deviceInfo, bool supported)
ui->chargeIndicator->setHidden(true);
ui->checkBoxResyncAll->setHidden(true);
ui->buttonSyncNow->setHidden(true);
+ trayIconSyncAction->setDisabled(true);
ui->syncProgressBar->setHidden(true);
}
else {
@@ -153,6 +218,7 @@ void MainWindow::deviceDetected(ambit_device_info_t deviceInfo, bool supported)
ui->chargeIndicator->setHidden(false);
ui->checkBoxResyncAll->setHidden(false);
ui->buttonSyncNow->setHidden(false);
+ trayIconSyncAction->setDisabled(false);
movesCountSetup();
if (movesCount != NULL) {
@@ -189,6 +255,7 @@ void MainWindow::deviceRemoved(void)
ui->chargeIndicator->setHidden(true);
ui->checkBoxResyncAll->setHidden(true);
ui->buttonSyncNow->setHidden(true);
+ trayIconSyncAction->setDisabled(true);
ui->syncProgressBar->setHidden(true);
trayIcon->setIcon(QIcon(":/icon_disconnected"));
@@ -219,6 +286,7 @@ void MainWindow::syncFinished(bool success)
ui->checkBoxResyncAll->setChecked(false);
ui->checkBoxResyncAll->setEnabled(true);
ui->buttonSyncNow->setEnabled(true);
+ trayIconSyncAction->setEnabled(true);
ui->syncProgressBar->setHidden(true);
trayIcon->setIcon(QIcon(":/icon_connected"));
@@ -315,6 +383,7 @@ void MainWindow::startSync()
ui->checkBoxResyncAll->setEnabled(false);
ui->buttonSyncNow->setEnabled(false);
+ trayIconSyncAction->setEnabled(false);
currentLogMessageRow = NULL;
QLayoutItem *tmpItem;
while ((tmpItem = ui->verticalLayoutLogMessages->takeAt(0)) != NULL) {
diff --git a/src/openambit/mainwindow.h b/src/openambit/mainwindow.h
index ce4d9f3..29b591b 100644
--- a/src/openambit/mainwindow.h
+++ b/src/openambit/mainwindow.h
@@ -48,7 +48,15 @@ public:
signals:
void syncNow(bool readAll, bool syncTime, bool syncOrbit, bool syncMovescount);
+protected:
+ void changeEvent(QEvent *event);
+ void closeEvent(QCloseEvent *event);
+
private slots:
+ void closeRequested();
+ void showHideWindow();
+ void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
+
void showSettings();
void settingsSaved();
@@ -74,7 +82,12 @@ private:
void movesCountSetup();
Ui::MainWindow *ui;
+ bool forceClose;
+
QSystemTrayIcon *trayIcon;
+ QMenu *trayIconMenu;
+ QAction *trayIconSyncAction;
+ QAction *trayIconMinimizeRestoreAction;
Settings settings;
SettingsDialog *settingsDialog;
diff --git a/src/openambit/mainwindow.ui b/src/openambit/mainwindow.ui
index 6826d40..9cc8b84 100644
--- a/src/openambit/mainwindow.ui
+++ b/src/openambit/mainwindow.ui
@@ -404,7 +404,7 @@
<sender>actionE_xit</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
- <slot>close()</slot>
+ <slot>closeRequested()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
@@ -435,5 +435,6 @@
</connections>
<slots>
<slot>showSettings()</slot>
+ <slot>closeRequested()</slot>
</slots>
</ui>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-running/openambit.git
More information about the Pkg-running-devel
mailing list