mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
tryicon is made in widget.cpp now
This commit is contained in:
parent
a2adc5edae
commit
7ad723a656
19
src/main.cpp
19
src/main.cpp
|
@ -18,7 +18,6 @@
|
|||
#include "misc/settings.h"
|
||||
#include <QApplication>
|
||||
#include <QFontDatabase>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QDebug>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -38,24 +37,6 @@ int main(int argc, char *argv[])
|
|||
QFontDatabase::addApplicationFont("://DejaVuSans.ttf");
|
||||
|
||||
Widget* w = Widget::getInstance();
|
||||
if (QSystemTrayIcon::isSystemTrayAvailable() == false)
|
||||
{
|
||||
qWarning() << "No system tray detected!";
|
||||
w->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
QSystemTrayIcon *icon = new QSystemTrayIcon(w);
|
||||
QObject::connect(icon,
|
||||
SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
||||
w,
|
||||
SLOT(onIconClick()));
|
||||
icon->setIcon(w->windowIcon());
|
||||
icon->show();
|
||||
if(Settings::getInstance().getAutostartInTray() == false)
|
||||
w->show();
|
||||
}
|
||||
|
||||
|
||||
int errorcode = a.exec();
|
||||
|
||||
|
|
|
@ -61,7 +61,52 @@ Widget::Widget(QWidget *parent)
|
|||
|
||||
void Widget::init()
|
||||
{
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
if (QSystemTrayIcon::isSystemTrayAvailable() == true)
|
||||
{
|
||||
icon = new QSystemTrayIcon(this);
|
||||
icon->setIcon(this->windowIcon());
|
||||
trayMenu = new QMenu;
|
||||
trayMenu->setStyleSheet("QMenu {background: white; color: black; border: 1px solid black;}"
|
||||
"QMenu::item:selected { background: #414141}");
|
||||
|
||||
statusOnline = new QAction(tr("online"), this);
|
||||
statusOnline->setIcon(QIcon(":ui/statusButton/dot_online.png"));
|
||||
connect(statusOnline, SIGNAL(triggered()), this, SLOT(setStatusOnline()));
|
||||
statusAway = new QAction(tr("away"), this);
|
||||
statusAway->setIcon(QIcon(":ui/statusButton/dot_idle.png"));
|
||||
connect(statusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
|
||||
statusBusy = new QAction(tr("busy"), this);
|
||||
connect(statusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
|
||||
statusBusy->setIcon(QIcon(":ui/statusButton/dot_busy.png"));
|
||||
actionQuit = new QAction(tr("&Quit"), this);
|
||||
connect(actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));
|
||||
|
||||
trayMenu->addAction(new QAction(tr("Change status to:"), this));
|
||||
trayMenu->addAction(statusOnline);
|
||||
trayMenu->addAction(statusAway);
|
||||
trayMenu->addAction(statusBusy);
|
||||
trayMenu->addSeparator();
|
||||
trayMenu->addAction(actionQuit);
|
||||
icon->setContextMenu(trayMenu);
|
||||
|
||||
connect(icon,
|
||||
SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
||||
this,
|
||||
SLOT(onIconClick(QSystemTrayIcon::ActivationReason)));
|
||||
|
||||
icon->show();
|
||||
|
||||
if(Settings::getInstance().getAutostartInTray() == false)
|
||||
this->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "No system tray detected!";
|
||||
this->show();
|
||||
}
|
||||
|
||||
ui->statusbar->hide();
|
||||
ui->menubar->hide();
|
||||
|
@ -232,12 +277,19 @@ Widget::~Widget()
|
|||
for (Group* g : GroupList::groupList)
|
||||
delete g;
|
||||
GroupList::groupList.clear();
|
||||
delete statusAway;
|
||||
delete statusBusy;
|
||||
delete statusOnline;
|
||||
delete actionQuit;
|
||||
delete trayMenu;
|
||||
delete icon;
|
||||
delete ui;
|
||||
instance = nullptr;
|
||||
}
|
||||
|
||||
Widget* Widget::getInstance()
|
||||
{
|
||||
|
||||
if (!instance)
|
||||
{
|
||||
instance = new Widget();
|
||||
|
@ -453,12 +505,21 @@ void Widget::onTransferClicked()
|
|||
activeChatroomWidget = nullptr;
|
||||
}
|
||||
|
||||
void Widget::onIconClick()
|
||||
void Widget::onIconClick(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
if(this->isHidden() == true)
|
||||
this->show();
|
||||
else
|
||||
this->hide();
|
||||
switch (reason) {
|
||||
case QSystemTrayIcon::Trigger:
|
||||
if(this->isHidden() == true)
|
||||
this->show();
|
||||
else
|
||||
this->hide();
|
||||
case QSystemTrayIcon::DoubleClick:
|
||||
break;
|
||||
case QSystemTrayIcon::MiddleClick:
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::onSettingsClicked()
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#define WIDGET_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QSystemTrayIcon>
|
||||
#include "form/addfriendform.h"
|
||||
#include "form/settingswidget.h"
|
||||
#include "form/settings/identityform.h"
|
||||
|
@ -114,7 +115,7 @@ private slots:
|
|||
void onMessageSendResult(int friendId, const QString& message, int messageId);
|
||||
void onGroupSendResult(int groupId, const QString& message, int result);
|
||||
void playRingtone();
|
||||
void onIconClick();
|
||||
void onIconClick(QSystemTrayIcon::ActivationReason);
|
||||
void onUserAway();
|
||||
|
||||
private:
|
||||
|
@ -126,6 +127,12 @@ private:
|
|||
void removeGroup(Group* g);
|
||||
QString askProfiles();
|
||||
QString detectProfile();
|
||||
QSystemTrayIcon *icon;
|
||||
QMenu *trayMenu;
|
||||
QAction *statusOnline,
|
||||
*statusAway,
|
||||
*statusBusy,
|
||||
*actionQuit;
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
QSplitter *centralLayout;
|
||||
|
|
Loading…
Reference in New Issue
Block a user