-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
179 lines (150 loc) · 5.51 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
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
179
#include "mainwindow.h"
#include "./ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->time->setText(QTime::currentTime().toString("hh:mm"));
startTimer(1000);
this->showMaximized();
/*QPixmap bkgnd(":/images/background-blue.jpg");
bkgnd = bkgnd.scaled(this->size(), Qt::KeepAspectRatio);
QPalette palette;
palette.setBrush(QPalette::Window, bkgnd);
this->setPalette(palette);*/
setDesign();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::setDesign()
{
QSize iconSize = QSize(32,32);
QColor white(Qt::white);
setStyleSheet(
"QMainWindow {background-image:url(\":/images/background-blue2.jpg\"); "
"background-position: center;}"
);
int id = QFontDatabase::addApplicationFont(":/fonts/VarelaRound-Regular.ttf");
QString fontFamily_title = QFontDatabase::applicationFontFamilies(id).at(0);
QFont font_title(fontFamily_title, 24, QFont::Bold);
ui->mediaCategory->setFont(font_title);
ui->videoGamesCategory->setFont(font_title);
ui->time->setFont(font_title);
ui->logo->setPixmap(QIcon(":/images/logo.svg").pixmap(QSize(100,50)));
loadGameService();
//ui->bt_add->setIcon(QIcon(":/images/add_icon.svg").pixmap(iconSize));
QPixmap pixmap = recolorSvg(":/images/add_icon.svg", white, iconSize);
ui->bt_add->setIcon(QIcon(pixmap));
ui->bt_add->setText("");
ui->bt_add->setIconSize(iconSize);
ui->bt_settings->setIcon(QIcon(recolorSvg(":/images/settings_icon.svg", white, iconSize)));
ui->bt_settings->setText("");
ui->bt_settings->setIconSize(iconSize);
ui->saMedia->widget()->setMaximumHeight(150);
ui->saMedia->setMaximumHeight(150);
ui->saVideoGames->widget()->setMaximumHeight(150);
ui->saVideoGames->setMaximumHeight(150);
for(int i = 0 ; i < 10 ; i++)
{
QPushButton* bt = new QPushButton("Test ");
bt->setMinimumSize(200,100);
bt->setMaximumSize(200,100);
ui->saMedia->widget()->layout()->addWidget(bt);
}
}
void MainWindow::timerEvent(QTimerEvent * event)
{
ui->time->setText(QTime::currentTime().toString("hh:mm"));
}
void MainWindow::loadGameService()
{
QSize gameServiceIconSize = QSize(48,48);
QVector<QString> name_gameService;
// TODO List should be loaded from file
name_gameService << "EA" << "Epic_Games" << "Steam" << "Ubisoft";
int i = 0;
foreach (QString gs, name_gameService) {
try{
m_list_gameService.insert(gs, (QPushButton*)ui->layout_gameService->itemAt(i)->widget());
m_list_gameService[gs]->setIcon(QIcon(":/images/" + gs + "_logo.svg").pixmap(gameServiceIconSize));
}
catch(QException e)
{
if(i>4)
qCritical() << "Impossible to load more services (" + QString(e.what()) + ")";
else
qCritical() << "Unable to load the icon (" + QString(e.what()) + ")";
break;
}
m_list_gameService[gs]->setText("");
m_list_gameService[gs]->setIconSize(gameServiceIconSize);
QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect();
effect->setBlurRadius(1); //Adjust accordingly
effect->setOffset(3,3); //Adjust accordingly
m_list_gameService[gs]->setGraphicsEffect(effect);
//m_list_gameService[gs]->setStyle();
m_list_gameService[gs]->installEventFilter(this);
i++;
}
}
QPixmap MainWindow::recolorSvg(const QString& path, const QColor& color, const QSize& size)
{
QSvgRenderer renderer(path);
QImage image(size, QImage::Format_ARGB32);
image.fill(Qt::transparent);
QPainter painter(&image);
renderer.render(&painter);
// Recolor the image
for (int y = 0; y < image.height(); ++y) {
for (int x = 0; x < image.width(); ++x) {
QColor pixelColor = image.pixelColor(x, y);
if (pixelColor.alpha() > 0) {
// Check if the pixel color is the stroke color
if (pixelColor != Qt::transparent && pixelColor != Qt::white) {
// Set the desired color while preserving the alpha and stroke width
QColor newColor(color);
newColor.setAlpha(pixelColor.alpha());
painter.setPen(newColor);
painter.setBrush(newColor);
}
painter.drawPoint(x, y);
}
}
}
return QPixmap::fromImage(image);
}
void MainWindow::on_bt_gs1_clicked()
{
qDebug() << "Test";
QProcess *process = new QProcess(this);
QString file = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe";
process->start(file);
}
void MainWindow::resizeEvent(QResizeEvent*)
{
ui->banner->setMinimumHeight((int)(0.33 * this->height()));
}
bool MainWindow::eventFilter(QObject* obj, QEvent* event)
{
if(event->type() == QEvent::KeyPress)
{
qDebug() << "Key!";
//QKeyEvent keyEvent = QKeyEvent(*event);
}
auto pushButton = qobject_cast<QPushButton*>(obj);
if (nullptr != pushButton)
{
if (event->type() == QEvent::FocusIn)
{
qDebug() << "Focus in";
QSize sz = QSize(ui->banner->height(), ui->banner->height());
QIcon icon = pushButton->icon();
QPixmap pixmap = icon.pixmap(sz).scaled(sz, Qt::KeepAspectRatio, Qt::SmoothTransformation);
ui->banner->setPixmap(pixmap);
}
}
return QWidget::eventFilter(obj, event);
}