aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/coreplugin/versiondialog.cpp
blob: 2e259ec30ec44234f2412a57271a6cbabb66da23 (plain)
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
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "versiondialog.h"

#include "actionmanager/command.h"
#include "coreicons.h"
#include "coreplugintr.h"
#include "icore.h"

#include <utils/algorithm.h>
#include <utils/appinfo.h>
#include <utils/hostosinfo.h>
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <utils/stylehelper.h>
#include <utils/utilsicons.h>

#include <QDialog>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QGuiApplication>
#include <QKeyEvent>
#include <QLabel>
#include <QPushButton>

namespace Core::Internal {

class VersionDialog final : public QDialog
{
public:
    VersionDialog();

    bool event(QEvent *event) final;
};

VersionDialog::VersionDialog()
    : QDialog(ICore::dialogParent())
{
    // We need to set the window icon explicitly here since for some reason the
    // application icon isn't used when the size of the dialog is fixed (at least not on X11/GNOME)
    if (Utils::HostOsInfo::isLinuxHost())
        setWindowIcon(Icons::QTCREATORLOGO_BIG.icon());

    setWindowTitle(Tr::tr("About %1").arg(QGuiApplication::applicationDisplayName()));

    auto logoLabel = new QLabel;
    logoLabel->setPixmap(Icons::QTCREATORLOGO_BIG.pixmap());
    const int margin = Utils::StyleHelper::SpacingTokens::PaddingVL;
    logoLabel->setContentsMargins({margin, margin, margin, margin});

    auto copyRightLabel = new QLabel(ICore::aboutInformationHtml());
    copyRightLabel->setWordWrap(true);
    copyRightLabel->setOpenExternalLinks(true);
    copyRightLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);

    auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
    QPushButton *copyButton
        = buttonBox->addButton(msgCopyToClipboard(), QDialogButtonBox::ActionRole);
    connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
    connect(copyButton, &QPushButton::pressed, this, [] {
        Utils::setClipboardAndSelection(ICore::aboutInformationCompact());
    });

    using namespace Layouting;
    Column {
        Row {
            Column { logoLabel, st },
            Column { copyRightLabel },
        },
        buttonBox,
    }.attachTo(this);

    layout()->setSizeConstraint(QLayout::SetFixedSize);
}

bool VersionDialog::event(QEvent *event)
{
    if (event->type() == QEvent::ShortcutOverride) {
        auto ke = static_cast<QKeyEvent *>(event);
        if (ke->key() == Qt::Key_Escape && !ke->modifiers()) {
            ke->accept();
            return true;
        }
    }
    return QDialog::event(event);
}

static QDialog *s_versionDialog = nullptr;

static void destroyVersionDialog()
{
    if (s_versionDialog) {
        s_versionDialog->deleteLater();
        s_versionDialog = nullptr;
    }
}

void showAboutQtCreator()
{
    if (s_versionDialog) {
        ICore::raiseWindow(s_versionDialog);
    } else {
        s_versionDialog = new VersionDialog;
        QObject::connect(s_versionDialog, &QDialog::finished, &destroyVersionDialog);
        ICore::registerWindow(s_versionDialog, Context("Core.VersionDialog"));
        s_versionDialog->show();
    }
}

} // Core::Internal