1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
3 
4 #include "infowindow.h"
5 #include "src/core/qguiappcurrentscreen.h"
6 #include <QHeaderView>
7 #include <QIcon>
8 #include <QKeyEvent>
9 #include <QLabel>
10 #include <QVBoxLayout>
11 
12 #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
13 #include <QRect>
14 #include <QScreen>
15 #endif
16 
17 // InfoWindow show basic information about the usage of Flameshot
18 
InfoWindow(QWidget * parent)19 InfoWindow::InfoWindow(QWidget* parent)
20   : QWidget(parent)
21 {
22     setAttribute(Qt::WA_DeleteOnClose);
23     setWindowIcon(QIcon(":img/app/flameshot.svg"));
24     setWindowTitle(tr("About"));
25 
26 #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
27     QRect position = frameGeometry();
28     QScreen* screen = QGuiAppCurrentScreen().currentScreen();
29     position.moveCenter(screen->availableGeometry().center());
30     move(position.topLeft());
31 #endif
32 
33     m_layout = new QVBoxLayout(this);
34     m_layout->setAlignment(Qt::AlignHCenter);
35     initLabels();
36     show();
37 }
38 
initLabels()39 void InfoWindow::initLabels()
40 {
41     QLabel* icon = new QLabel();
42     icon->setPixmap(QPixmap(":img/app/flameshot.svg"));
43     icon->setAlignment(Qt::AlignHCenter);
44     m_layout->addWidget(icon);
45 
46     QLabel* licenseTitleLabel = new QLabel(tr("<u><b>License</b></u>"), this);
47     licenseTitleLabel->setAlignment(Qt::AlignHCenter);
48     m_layout->addWidget(licenseTitleLabel);
49 
50     QLabel* licenseLabel = new QLabel(QStringLiteral("GPLv3+"), this);
51     licenseLabel->setAlignment(Qt::AlignHCenter);
52     m_layout->addWidget(licenseLabel);
53     m_layout->addStretch();
54 
55     QLabel* versionTitleLabel = new QLabel(tr("<u><b>Version</b></u>"), this);
56     versionTitleLabel->setAlignment(Qt::AlignHCenter);
57     m_layout->addWidget(versionTitleLabel);
58     QString versionMsg = "Flameshot " + QStringLiteral(APP_VERSION) + " (" +
59                          QStringLiteral(FLAMESHOT_GIT_HASH) +
60                          ")\nCompiled with Qt " + QT_VERSION_STR;
61     QLabel* versionLabel = new QLabel(versionMsg, this);
62     versionLabel->setAlignment(Qt::AlignHCenter);
63     m_layout->addWidget(versionLabel);
64     m_layout->addSpacing(30);
65 }
66 
keyPressEvent(QKeyEvent * e)67 void InfoWindow::keyPressEvent(QKeyEvent* e)
68 {
69     if (e->key() == Qt::Key_Escape) {
70         close();
71     }
72 }
73