-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
131 lines (101 loc) · 2.88 KB
/
mainwindow.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QListWidgetItem>
#include <QSet>
#include <QString>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->initGlobaShortcut();
trayIcon = new QSystemTrayIcon(this);
createActions();
createTrayIcon();
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
QIcon icon = QIcon(":/images/icon.svg");
trayIcon->setIcon(icon);
trayIcon->show();
this->setWindowIcon(icon);
setWindowTitle(trUtf8("quteNote"));
this->setTreeNode();
QSet<QString> set;
}
void MainWindow::setTreeNode()
{
if(this->ui->notesTreeView->children().count() == 0)
{
//new QListWidgetItem(tr("New"),this->ui->notesTreeView);
}
//this->ui->notesTreeView->
}
void MainWindow::initGlobaShortcut()
{
_shortcutDef = QString("Alt+S");
_hotkeyHandle.setShortcut( QKeySequence(_shortcutDef) );
_hotkeyHandle.setEnabled(true);
connect( &_hotkeyHandle, SIGNAL(activated()), this, SLOT(showHide()) );
}
void MainWindow::uninitGlobalShortcut()
{
}
void MainWindow::showHide()
{
if( this->isVisible() && !this->isActiveWindow() )
{
this->activateWindow();
}
else if( this->isVisible() )
{
this->hide();
}
else
{
this->show();
}
}
void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch (reason) {
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
this->showHide();
break;
case QSystemTrayIcon::MiddleClick:
default:
;
}
}
void MainWindow::createActions()
{
minimizeAction = new QAction(tr("Mi&nimize"), this);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
maximizeAction = new QAction(tr("Ma&ximize"), this);
connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
restoreAction = new QAction(tr("&Restore"), this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void MainWindow::createTrayIcon()
{
trayIconMenu = new QMenu(this);
trayIconMenu->addAction(minimizeAction);
trayIconMenu->addAction(maximizeAction);
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
}
MainWindow::~MainWindow()
{
this->uninitGlobalShortcut();
delete this->trayIcon;
delete this->ui;
delete this->minimizeAction;
delete this->maximizeAction;
delete this->restoreAction;
delete this->quitAction;
delete this->trayIconMenu;
}