164 lines
3.9 KiB
C++
164 lines
3.9 KiB
C++
#include "aboutwindow.h"
|
|
#include "ui_aboutwindow.h"
|
|
#include "qad_types.h"
|
|
#include <QApplication>
|
|
#include <QScreen>
|
|
#include <QFile>
|
|
|
|
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
|
|
# define MOBILE_VIEW
|
|
#endif
|
|
|
|
QImage AboutWindow::logo;
|
|
QVector<AboutWindow::SSPair> AboutWindow::versions, AboutWindow::builds;
|
|
QString AboutWindow::comment;
|
|
|
|
|
|
AboutWindow::AboutWindow(QWidget * parent): QDialog(parent), ui(new Ui::AboutWindow) {
|
|
#ifdef ANDROID
|
|
setStyleSheet("font: 12pt \"DejaVu Sans\";");
|
|
#endif
|
|
ui->setupUi(this);
|
|
QImage logo_im = logo;
|
|
if (logo_im.isNull())
|
|
logo_im.load(":/icons/splash.png");
|
|
setWindowTitle(QApplication::applicationName() + " - " + tr("About"));
|
|
QIcon ic = QApplication::windowIcon();
|
|
if (ic.isNull()) {
|
|
QWidgetList tlw = QApplication::topLevelWidgets();
|
|
foreach (QWidget * w, tlw)
|
|
if (!w->windowIcon().isNull()) {
|
|
ic = w->windowIcon();
|
|
break;
|
|
}
|
|
}
|
|
if (ic.isNull())
|
|
ic = QIcon(QPixmap::fromImage(logo_im));
|
|
setWindowIcon(ic);
|
|
QFormLayout * lay = (QFormLayout*)(ui->groupVersions->layout());
|
|
foreach (SSPair p, versions) {
|
|
lay->addRow(p.first, new QLabel(p.second));
|
|
}
|
|
lay = (QFormLayout*)(ui->groupBuild->layout());
|
|
foreach (SSPair p, builds) {
|
|
lay->addRow(p.first, new QLabel(p.second));
|
|
}
|
|
ui->imageView->setPixmap(QPixmap::fromImage(logo_im));
|
|
ui->labelComment->setText(comment);
|
|
ui->labelComment->setHidden(comment.isEmpty());
|
|
//ui->labelArch->setText(QSysInfo::currentCpuArchitecture());
|
|
ui->labelAuthors->setText(authors());
|
|
connect(ui->buttonQt, SIGNAL(clicked()), qApp, SLOT(aboutQt()));
|
|
#ifdef MOBILE_VIEW
|
|
ui->layoutMain->insertWidget(0, ui->imageView);
|
|
//ui->verticalSpacer->changeSize(1, 1, QSizePolicy::Preferred, QSizePolicy::Preferred);
|
|
#endif
|
|
#ifdef MOBILE_VIEW
|
|
ui->layoutMain->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Preferred, QSizePolicy::Expanding));
|
|
#else
|
|
QScreen * scr =
|
|
# if QT_VERSION >= 0x050A00
|
|
QApplication::screenAt(QCursor::pos());
|
|
# else
|
|
QApplication::screens()[0];
|
|
# endif
|
|
if (scr) {
|
|
QRect r;
|
|
r.setSize(scr->availableSize() / 2);
|
|
r.moveCenter(scr->availableGeometry().center());
|
|
setGeometry(r);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
|
|
AboutWindow::~AboutWindow() {
|
|
delete ui;
|
|
}
|
|
|
|
|
|
void AboutWindow::setLogo(QImage im) {
|
|
logo = im;
|
|
}
|
|
|
|
|
|
void AboutWindow::setLogo(QString path) {
|
|
logo = QImage(path);
|
|
}
|
|
|
|
|
|
void AboutWindow::addVersion(QString name, QString version) {
|
|
if (!name.endsWith(":")) name.append(":");
|
|
foreach (const SSPair & p, versions) {
|
|
if (p.first == name) return;
|
|
}
|
|
versions << SSPair(name, version);
|
|
}
|
|
|
|
|
|
void AboutWindow::addBuildInfo(QString name, QString value) {
|
|
if (!name.endsWith(":")) name.append(":");
|
|
foreach (const SSPair & p, builds) {
|
|
if (p.first == name) return;
|
|
}
|
|
builds << SSPair(name, value);
|
|
}
|
|
|
|
|
|
void AboutWindow::setComment(QString text) {
|
|
comment = text;
|
|
}
|
|
|
|
|
|
void AboutWindow::show() {
|
|
AboutWindow w;
|
|
w.exec();
|
|
}
|
|
|
|
|
|
int AboutWindow::exec() {
|
|
#ifdef MOBILE_VIEW
|
|
showFullScreen();
|
|
//setWindowState(Qt::WindowFullScreen);
|
|
#endif
|
|
return QDialog::exec();
|
|
}
|
|
|
|
|
|
void AboutWindow::changeEvent(QEvent *e) {
|
|
QDialog::changeEvent(e);
|
|
switch (e->type()) {
|
|
case QEvent::LanguageChange:
|
|
ui->retranslateUi(this);
|
|
break;
|
|
case QEvent::FontChange:
|
|
case QEvent::Polish:
|
|
ui->buttonOK->setIconSize(preferredIconSize(2., this));
|
|
ui->buttonQt->setIconSize(preferredIconSize(2., this));
|
|
break;
|
|
default: break;
|
|
}
|
|
}
|
|
|
|
|
|
QString AboutWindow::authors() {
|
|
QFile f(":/authors.txt");
|
|
if (!f.open(QIODevice::ReadOnly)) return QString();
|
|
QString ret;
|
|
QTextStream ts(&f);
|
|
ts.readLine();
|
|
QStringList sl;
|
|
while (!ts.atEnd()) {
|
|
QString l = ts.readLine();
|
|
if (l.isEmpty()) continue;
|
|
QString name, mail;
|
|
sl = l.split(";");
|
|
if (sl.size() > 0) name = sl[0].trimmed();
|
|
if (sl.size() > 1) mail = sl[1].trimmed();
|
|
if (!ret.isEmpty()) ret += "\n";
|
|
ret += QString("%1 (%2)").arg(name, mail);
|
|
}
|
|
return ret;
|
|
}
|
|
|