forked from user-none/arora
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathaboutdialog.cpp
95 lines (82 loc) · 2.94 KB
/
aboutdialog.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
/*
* Copyright 2007-2008 Benjamin C. Meyer <[email protected]>
* Copyright 2008 Matvey Kozhev <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include "aboutdialog.h"
#include <qdialogbuttonbox.h>
#include <qfile.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qtextedit.h>
#include <qtextstream.h>
#if QT_VERSION >= 0x040600 || defined(WEBKIT_TRUNK)
#include <qwebkitversion.h>
#endif
AboutDialog::AboutDialog(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
setWindowTitle(tr("About %1").arg(qApp->applicationName()));
logo->setPixmap(qApp->windowIcon().pixmap(128, 128));
name->setText(qApp->applicationName());
version->setText(qApp->applicationVersion());
#if QT_VERSION >= 0x040600 || defined(WEBKIT_TRUNK)
webkitVersion->setText(tr("WebKit version: %1").arg(qWebKitVersion()));
#else
webkitVersion->hide();
#endif
connect(authorsButton, SIGNAL(clicked()),
this, SLOT(authorsButtonClicked()));
connect(licenseButton, SIGNAL(clicked()),
this, SLOT(licenseButtonClicked()));
}
void AboutDialog::displayFile(const QString &fileName, const QString &title)
{
QDialog dialog(this);
QVBoxLayout layout(&dialog);
QTextEdit textEdit(&dialog);
QDialogButtonBox buttonBox(QDialogButtonBox::Close, Qt::Horizontal, &dialog);
textEdit.setLayoutDirection(Qt::LeftToRight);
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
return;
QTextStream stream(&file);
stream.setCodec("UTF-8");
QString text = stream.readAll();
// this is done to force the content of the text editor to be LTR, and monospaced.
textEdit.setHtml(QString(QLatin1String("<pre>%1</pre>")).arg(text));
textEdit.setReadOnly(true);
connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(close()));
buttonBox.setCenterButtons(true);
layout.addWidget(&textEdit);
layout.addWidget(&buttonBox);
layout.setMargin(6);
dialog.setLayout(&layout);
dialog.setWindowTitle(title);
dialog.setWindowFlags(Qt::Sheet);
dialog.resize(600, 350);
dialog.exec();
}
void AboutDialog::authorsButtonClicked()
{
displayFile(QLatin1String(":AUTHORS"), tr("Authors"));
}
void AboutDialog::licenseButtonClicked()
{
displayFile(QLatin1String(":LICENSE.GPL2"), tr("License"));
}