-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdatenotificationbar.cpp
More file actions
96 lines (80 loc) · 3.38 KB
/
updatenotificationbar.cpp
File metadata and controls
96 lines (80 loc) · 3.38 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "updatenotificationbar.h"
#include <QGuiApplication>
#include <QStyleHints>
#include <QStyle>
UpdateNotificationBar::UpdateNotificationBar(QWidget *parent)
: QWidget(parent)
{
// Set background color similar to Qt Creator's notification bar
if(QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Light){
setStyleSheet("UpdateNotificationBar { "
"background-color: #e8f4fc; "
"border-top: 1px solid #87ceeb; "
"}");
// Message label
m_messageLabel = new QLabel(this);
m_messageLabel->setStyleSheet("QLabel { color: #000; }");
// See details button
m_detailsButton = new QPushButton("See Details", this);
m_detailsButton->setFlat(true);
m_detailsButton->setStyleSheet("QPushButton { color: #000; text-decoration: underline; border: none; }"
"QPushButton:hover { color: #8c8c8c; }");
m_detailsButton->setCursor(Qt::PointingHandCursor);
}
else{
setStyleSheet("UpdateNotificationBar { "
"background-color: #3c3c3c; "
"border-top: 1px solid #5b5b5b; "
"}");
// Message label
m_messageLabel = new QLabel(this);
m_messageLabel->setStyleSheet("QLabel { color: #fff; }");
// See details button
m_detailsButton = new QPushButton("See Details", this);
m_detailsButton->setFlat(true);
m_detailsButton->setStyleSheet("QPushButton { color: #8c8c8c; text-decoration: underline; border: none; }"
"QPushButton:hover { color: #393939; }");
m_detailsButton->setCursor(Qt::PointingHandCursor);
}
setFixedHeight(40);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(10, 5, 10, 5);
// Info icon
m_iconLabel = new QLabel(this);
QIcon infoIcon = QIcon::fromTheme(QIcon::ThemeIcon::DialogInformation);
m_iconLabel->setPixmap(infoIcon.pixmap(20, 20));
// Update button
m_updateButton = new QPushButton("Update", this);
// Close button
m_closeButton = new QPushButton("✕", this);
m_closeButton->setFlat(true);
m_closeButton->setFixedSize(20, 20);
m_closeButton->setStyleSheet("QPushButton { border: none; color: #666; font-weight: bold; }"
"QPushButton:hover { color: #000; }");
m_closeButton->setCursor(Qt::PointingHandCursor);
// Add widgets to layout
layout->addWidget(m_iconLabel);
layout->addWidget(m_messageLabel);
layout->addWidget(m_detailsButton);
layout->addWidget(m_updateButton);
layout->addStretch();
layout->addWidget(m_closeButton);
// Connect signals
connect(m_detailsButton, &QPushButton::clicked, this, [this]() {
emit seeDetailsClicked(m_releaseNotesUrl);
});
connect(m_updateButton, &QPushButton::clicked, this, &UpdateNotificationBar::updateClicked);
connect(m_closeButton, &QPushButton::clicked, this, &UpdateNotificationBar::closeClicked);
// Initially hidden
hide();
}
void UpdateNotificationBar::showUpdate(const QString &version, const QString &releaseNotesUrl)
{
m_releaseNotesUrl = releaseNotesUrl;
m_messageLabel->setText(QString("A new version (%1) is available! Start?").arg(version));
show();
}
void UpdateNotificationBar::hideBar()
{
hide();
}