-
Notifications
You must be signed in to change notification settings - Fork 1
/
sidebarwidget.cpp
178 lines (148 loc) · 5.79 KB
/
sidebarwidget.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "sidebarwidget.h"
#include <QPushButton>
#include <QFileIconProvider>
#include <QVBoxLayout>
#include <QMouseEvent>
#include <QPropertyAnimation>
#include <QTimer>
#include <QAction>
#include <QMenu>
#include <QApplication>
#include "Settings/settingswidget.h"
SidebarWidget::SidebarWidget(const int desktopWidth, const int desktopHeight, QWidget *parent) :
QWidget(parent), m_desktopWidth(desktopWidth), m_desktopHeight(desktopHeight)
{
// Define Window Position (Right side of Screen, hidden by default)
setContentsMargins(0,0,0,0);
resize(QSize(70,300));
setGeometry(desktopWidth - 2, desktopHeight/2 - 200, 70, 300);
// no Window Border and Close/Minimize-SystemButtons and AlwaysOnTop
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
// Button: Close Widget
m_closeButton = new QPushButton(QIcon(":/DefaultIcons/closeButtonIcon"), "", NULL);
m_closeButton->setIconSize(QSize(25,25));
m_closeButton->setStyleSheet("background:solid;");
QObject::connect(m_closeButton, SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
// Button: Options Dialog
m_optionsButton = new QPushButton(QIcon(":/DefaultIcons/optionsButtonIcon"), "", NULL);
m_optionsButton->setIconSize(QSize(25,25));
m_optionsButton->setStyleSheet("background:solid;");
QObject::connect(m_optionsButton,SIGNAL(clicked()),this,SLOT(openSettingsDialog()));
// example app button, to be removed on settingsdialog completed FIXME
QString exampleAppPath("C:\\Users\\betagan\\Downloads\\putty.exe");
QIcon exampleIcon(QFileIconProvider().icon(QFileInfo(exampleAppPath)));
LaunchButton *putty = new LaunchButton("PuTTY", exampleAppPath, exampleIcon, this);
m_launchButtons.push_back(putty);
LaunchButton *putty2 = new LaunchButton("PuTTY", exampleAppPath, exampleIcon, this);
m_launchButtons.push_back(putty2);
LaunchButton *putty3 = new LaunchButton("PuTTY", exampleAppPath, exampleIcon, this);
m_launchButtons.push_back(putty3);
LaunchButton *putty4 = new LaunchButton("PuTTY", exampleAppPath, exampleIcon, this);
m_launchButtons.push_back(putty4);
LaunchButton *putty5 = new LaunchButton("PuTTY", exampleAppPath, exampleIcon, this);
m_launchButtons.push_back(putty5);
// Layout: Adding Buttons
QVBoxLayout *basicLayout = new QVBoxLayout(NULL);
QHBoxLayout *systemButtonLayout = new QHBoxLayout(NULL);
systemButtonLayout->addWidget(m_optionsButton);
systemButtonLayout->addWidget(m_closeButton);
basicLayout->addLayout(systemButtonLayout);
basicLayout->addWidget(putty);
basicLayout->addWidget(putty2);
basicLayout->addWidget(putty3);
basicLayout->addWidget(putty4);
basicLayout->addWidget(putty5);
// Layout: Remove Spacings
basicLayout->setSpacing(0);
basicLayout->setMargin(0);
basicLayout->setContentsMargins(0,0,0,0);
// Layout: Apply to Widget
setLayout(basicLayout);
initTrayIcon();
QObject::connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
m_trayIcon->setIcon(QIcon(":/DefaultIcons/trayIcon"));
m_trayIcon->setToolTip(tr("QLaunchBar"));
m_trayIcon->show();
// initialize Animation system for sliding widget on mouseover
m_animation = new QPropertyAnimation(this, "geometry");
m_isMoving = false;
m_animationTimer = new QTimer(this);
QObject::connect(m_animationTimer, SIGNAL(timeout()),this,SLOT(hideWidget()));
}
SidebarWidget::~SidebarWidget()
{
delete m_closeButton;
while (!m_launchButtons.empty())
delete m_launchButtons.takeLast();
delete m_animation;
delete m_animationTimer;
}
void SidebarWidget::hideWidget()
{
m_animation->stop();
m_animation->setDuration(250);
m_animation->setStartValue(geometry());
m_animation->setEndValue(QRect(m_desktopWidth - 2, m_desktopHeight/2 - 200, 70, 300));
m_animation->start();
m_isMoving = false;
}
void SidebarWidget::onMouseMoved()
{
if(!m_isMoving)
{
m_isMoving = true;
m_animation->stop();
m_animation->setDuration(500);
m_animation->setStartValue(geometry());
m_animation->setEndValue(QRect(m_desktopWidth - 75, m_desktopHeight/2 - 200, 70, 300));
m_animation->start();
}
m_animationTimer->stop();
m_animationTimer->start(1000);
}
void SidebarWidget::mouseMoveEvent(QMouseEvent* /*event*/)
{
onMouseMoved();
}
void SidebarWidget::closeButtonClicked()
{
QApplication::quit();
}
void SidebarWidget::openSettingsDialog()
{
SettingsWidget settingsWidget;
settingsWidget.exec();
}
void SidebarWidget::initTrayIcon()
{
m_optionsAction = new QAction(tr("&Options"), this);
m_optionsAction->setIcon(QIcon(":/DefaultIcons/optionsButtonIcon"));
connect(m_optionsAction, SIGNAL(triggered()), this, SLOT(openSettingsDialog()));
m_quitAction = new QAction(tr("&Quit"), this);
m_quitAction->setIcon(QIcon(":/DefaultIcons/closeButtonIcon"));
connect(m_quitAction, SIGNAL(triggered()), this, SLOT(closeButtonClicked()));
m_trayIconMenu = new QMenu(this);
m_trayIconMenu->setTitle("QLaunchBar");
m_trayIconMenu->addAction(m_optionsAction);
m_trayIconMenu->addSeparator();
m_trayIconMenu->addAction(m_quitAction);
m_trayIcon = new QSystemTrayIcon(this);
m_trayIcon->setContextMenu(m_trayIconMenu);
}
void SidebarWidget::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch (reason) {
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
onMouseMoved();
m_animationTimer->start(2000);
break;
case QSystemTrayIcon::MiddleClick:
break;
default:
;
}
}