1 /*****************************************************************************
2 * trayicon.cpp - QStarDict, a StarDict clone written with using Qt *
3 * Copyright (C) 2008 Alexander Rodin *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License along *
16 * with this program; if not, write to the Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
18 *****************************************************************************/
27 #include "application.h"
28 #include "mainwindow.h"
29 #include "popupwindow.h"
30 #include "settingsdialog.h"
35 TrayIcon::TrayIcon(QObject *parent)
36 : QSystemTrayIcon(parent)
38 QMenu *trayMenu = new QMenu(tr("QStarDict"));
39 QAction *actionScan = new QAction(tr("&Scan"), this);
40 actionScan->setCheckable(true);
41 actionScan->setChecked(Application::instance()->popupWindow()->isScan());
42 setScanEnabled(Application::instance()->popupWindow()->isScan());
43 connect(actionScan, SIGNAL(toggled(bool)),
44 Application::instance()->popupWindow(), SLOT(setScan(bool)));
45 connect(Application::instance()->popupWindow(), SIGNAL(scanChanged(bool)),
46 actionScan, SLOT(setChecked(bool)));
47 connect(Application::instance()->popupWindow(), SIGNAL(scanChanged(bool)), SLOT(setScanEnabled(bool)));
48 trayMenu->addAction(actionScan);
49 QAction *actionSettings = new QAction(QIcon(":/icons/configure.png"), tr("&Configure QStarDict"), this);
50 connect(actionSettings, SIGNAL(triggered()), SLOT(on_actionSettings_triggered()));
51 trayMenu->addAction(actionSettings);
52 QAction *actionQuit = new QAction(QIcon(":/icons/application-exit.png"), tr("&Quit"), this);
53 connect(actionQuit, SIGNAL(triggered()), Application::instance(), SLOT(quit()));
54 trayMenu->addAction(actionQuit);
55 setContextMenu(trayMenu);
56 connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
57 SLOT(on_activated(QSystemTrayIcon::ActivationReason)));
67 void TrayIcon::on_activated(QSystemTrayIcon::ActivationReason reason)
71 case QSystemTrayIcon::Trigger:
72 Application::instance()->mainWindow()->setVisible(!
73 Application::instance()->mainWindow()->isVisible());
75 case QSystemTrayIcon::MiddleClick:
76 Application::instance()->popupWindow()->showTranslation(Application::clipboard()->text(QClipboard::Selection));
83 void TrayIcon::on_actionSettings_triggered()
85 SettingsDialog dialog(Application::instance()->mainWindow());
89 void TrayIcon::setScanEnabled(bool enabled)
91 QIcon icon(enabled ? ":/icons/qstardict.png" : ":/icons/qstardict-disabled.png");
93 setToolTip(tr("QStarDict: scanning is %1").arg(enabled ? tr("enabled") : tr("disabled")));
96 void TrayIcon::saveSettings()
99 config.setValue("TrayIcon/visible", isVisible());
102 void TrayIcon::loadSettings()
105 setVisible(config.value("TrayIcon/visible", true).toBool());
112 // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc