-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
81 lines (62 loc) · 2.15 KB
/
mainwindow.cpp
File metadata and controls
81 lines (62 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
layout()->setSizeConstraint(QLayout::SetFixedSize);
controlThread = new ControlThread();
connect(ui->startButton, SIGNAL(clicked()), this, SLOT(startApplication()));
connect(ui->stopButton, SIGNAL(clicked()), this, SLOT(stopApplication()));
connect(this, SIGNAL(stop()), controlThread, SLOT(stop()));
restoreAction = new QAction(tr("&Restore"), this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
minimizeAction = new QAction(tr("Mi&nimize"), this);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
trayIconMenu = new QMenu(this);
trayIconMenu->addAction(restoreAction);
trayIconMenu->addAction(minimizeAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,
SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
trayIcon->setIcon(QIcon(":/icons/images/bag.png"));
trayIcon->show();
}
void MainWindow::startApplication() {
ui->startButton->setDisabled(1);
if(!controlThread->isRunning()) {
controlThread->start();
}
ui->stopButton->setDisabled(0);
}
void MainWindow::stopApplication() {
emit stop();
ui->startButton->setDisabled(0);
ui->stopButton->setDisabled(1);
}
void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch (reason) {
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
showNormal();
break;
case QSystemTrayIcon::MiddleClick:
break;
default:
;
}
}
void MainWindow::quit(){
emit stop();
controlThread->wait();
}
MainWindow::~MainWindow() {
delete ui;
delete controlThread;
delete trayIconMenu;
delete trayIcon;
}