File: aboutdialog.cpp

package info (click to toggle)
pineapple-pictures 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,424 kB
  • sloc: cpp: 3,794; xml: 339; sh: 8; makefile: 2
file content (181 lines) | stat: -rw-r--r-- 7,937 bytes parent folder | download
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
180
181
// SPDX-FileCopyrightText: 2025 Gary Wang <git@blumia.net>
//
// SPDX-License-Identifier: MIT

#include "aboutdialog.h"

#include <QAbstractButton>
#include <QDialogButtonBox>
#include <QTextBrowser>
#include <QTabWidget>
#include <QVBoxLayout>
#include <QApplication>
#include <QLabel>
#include <QPushButton>
#include <QFile>

using namespace Qt::Literals::StringLiterals;

AboutDialog::AboutDialog(QWidget *parent)
    : QDialog(parent)
    , m_tabWidget(new QTabWidget)
    , m_buttonBox(new QDialogButtonBox)
    , m_helpTextEdit(new QTextBrowser)
    , m_aboutTextEdit(new QTextBrowser)
    , m_specialThanksTextEdit(new QTextBrowser)
    , m_licenseTextEdit(new QTextBrowser)
    , m_3rdPartyLibsTextEdit(new QTextBrowser)
{
    this->setWindowTitle(tr("About"));

    const QStringList helpStr {
        u"<p>%1</p>"_s.arg(tr("Launch application with image file path as argument to load the file.")),
        u"<p>%1</p>"_s.arg(tr("Drag and drop image file onto the window is also supported.")),
        u"<p>%1</p>"_s.arg(tr("None of the operations in this application will alter the pictures on disk.")),
        u"<p>%1</p>"_s.arg(tr("Context menu option explanation:")),
        u"<ul>"_s,
        // blumia: Chain two arg() here since it seems lupdate will remove one of them if we use
        //         the old `arg(QCoreApp::translate(), tr())` way, but it's worth to mention
        //         `arg(QCoreApp::translate(), this->tr())` works, but lupdate will complain about the usage.
        u"<li><b>%1</b>:<br/>%2</li>"_s
            .arg(QCoreApplication::translate("MainWindow", "Stay on top"))
            .arg(tr("Make window stay on top of all other windows.")),
        u"<li><b>%1</b>:<br/>%2</li>"_s
            .arg(QCoreApplication::translate("MainWindow", "Protected mode"))
            .arg(tr("Avoid close window accidentally. (eg. by double clicking the window)")),
        u"<li><b>%1</b>:<br/>%2</li>"_s
            .arg(QCoreApplication::translate("MainWindow", "Keep transformation", "The 'transformation' means the flip/rotation status that currently applied to the image view"))
            .arg(tr("Avoid resetting the zoom/rotation/flip state that was applied to the image view when switching between images.")),
        u"</ul>"_s
    };

    const QStringList aboutStr {
        u"<center><img width='128' height='128' src=':/icons/app-icon.svg'/><br/>"_s,
        qApp->applicationDisplayName(),
        (u"<br/>"_s + tr("Version: %1").arg(
#ifdef GIT_DESCRIBE_VERSION_STRING
            GIT_DESCRIBE_VERSION_STRING
#else
            qApp->applicationVersion()
#endif // GIT_DESCRIBE_VERSION_STRING
        )),
        u"<hr/>"_s,
        tr("Copyright (c) %1 %2", "%1 is year, %2 is the name of copyright holder(s)")
            .arg(u"2025"_s, u"<a href='https://github.com/BLumia'>@BLumia</a>"_s),
        u"<br/>"_s,
        tr("Logo designed by %1").arg(u"<a href='https://github.com/Lovelyblack'>@Lovelyblack</a>"_s),
        u"<hr/>"_s,
        tr("Built with Qt %1 (%2)").arg(QT_VERSION_STR, QSysInfo::buildCpuArchitecture()),
        QStringLiteral("<br/><a href='%1'>%2</a>").arg("https://github.com/BLumia/pineapple-pictures", tr("Source code")),
        u"</center>"_s
    };

    QFile translaterHtml(u":/plain/translators.html"_s);
    bool canOpenFile = translaterHtml.open(QIODevice::ReadOnly);
    const QByteArray & translatorList = canOpenFile ? translaterHtml.readAll() : QByteArrayLiteral("");

    const QStringList specialThanksStr {
        u"<h1 align='center'>%1</h1><a href='%2'>%3</a><p>%4</p>"_s.arg(
            tr("Contributors"),
            u"https://github.com/BLumia/pineapple-pictures/graphs/contributors"_s,
            tr("List of contributors on GitHub"),
            tr("Thanks to all people who contributed to this project.")
        ),

        u"<h1 align='center'>%1</h1><p>%2</p>%3"_s.arg(
            tr("Translators"),
            tr("I would like to thank the following people who volunteered to translate this application."),
            translatorList
        )
    };

    const QStringList licenseStr {
        u"<h1 align='center'><b>%1</b></h1>"_s.arg(tr("Your Rights")),
        u"<p>%1</p><p>%2</p><ul><li>%3</li><li>%4</li><li>%5</li><li>%6</li></ul>"_s.arg(
            tr("%1 is released under the MIT License."), // %1
            tr("This license grants people a number of freedoms:"), // %2
            tr("You are free to use %1, for any purpose"), // %3
            tr("You are free to distribute %1"), // %4
            tr("You can study how %1 works and change it"), // %5
            tr("You can distribute changed versions of %1") // %6
        ).arg(u"<i>%1</i>"_s),
        u"<p>%1</p>"_s.arg(tr("The MIT license guarantees you this freedom. Nobody is ever permitted to take it away.")),
        u"<hr/><pre>%2</pre>"_s
    };

    const QString mitLicense(QStringLiteral(R"(Expat/MIT License

Copyright &copy; 2025 BLumia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
)"));

    const QStringList thirdPartyLibsStr {
        u"<h1 align='center'><b>%1</b></h1>"_s.arg(tr("Third-party Libraries used by %1")),
        tr("%1 is built on the following free software libraries:", "Free as in freedom"),
        u"<ul>"_s,
#ifdef HAVE_EXIV2_VERSION
        u"<li><a href='%1'>%2</a>: %3</li>"_s.arg("https://www.exiv2.org/", "Exiv2", "GPLv2"),
#endif // EXIV2_VERSION
        u"<li><a href='%1'>%2</a>: %3</li>"_s.arg("https://www.qt.io/", "Qt", "GPLv2 + GPLv3 + LGPLv2.1 + LGPLv3"),
        u"</ul>"_s
    };

    m_helpTextEdit->setText(helpStr.join('\n'));

    m_aboutTextEdit->setText(aboutStr.join('\n'));
    m_aboutTextEdit->setOpenExternalLinks(true);

    m_specialThanksTextEdit->setText(specialThanksStr.join('\n'));
    m_specialThanksTextEdit->setOpenExternalLinks(true);

    m_licenseTextEdit->setText(licenseStr.join('\n').arg(qApp->applicationDisplayName(), mitLicense));

    m_3rdPartyLibsTextEdit->setText(thirdPartyLibsStr.join('\n').arg(u"<i>%1</i>"_s).arg(qApp->applicationDisplayName()));
    m_3rdPartyLibsTextEdit->setOpenExternalLinks(true);

    m_tabWidget->addTab(m_helpTextEdit, tr("&Help"));
    m_tabWidget->addTab(m_aboutTextEdit, tr("&About"));
    m_tabWidget->addTab(m_specialThanksTextEdit, tr("&Special Thanks"));
    m_tabWidget->addTab(m_licenseTextEdit, tr("&License"));
    m_tabWidget->addTab(m_3rdPartyLibsTextEdit, tr("&Third-party Libraries"));

    m_buttonBox->setStandardButtons(QDialogButtonBox::Close);
    connect(m_buttonBox, QOverload<QAbstractButton *>::of(&QDialogButtonBox::clicked), this, [this](){
        this->close();
    });

    setLayout(new QVBoxLayout);

    layout()->addWidget(m_tabWidget);
    layout()->addWidget(m_buttonBox);

    setMinimumSize(361, 161); // not sure why it complain "Unable to set geometry"
    setWindowFlag(Qt::WindowContextHelpButtonHint, false);
}

AboutDialog::~AboutDialog()
{

}

QSize AboutDialog::sizeHint() const
{
    return QSize(520, 350);
}