-
Notifications
You must be signed in to change notification settings - Fork 22
/
AboutDialog.cpp
154 lines (123 loc) · 4.75 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
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
/*
File: AboutDialog.cpp
Created on: 15/11/2016
Author: Felix de las Pozas Alvarez
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 3 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, see <http://www.gnu.org/licenses/>.
*/
// Project
#include <AboutDialog.h>
#include <Utils.h>
#include <Provider.h>
// Qt
#include <QtGlobal>
#include <QDateTime>
#include <QApplication>
const QString AboutDialog::VERSION{"1.31.2"};
const QString COPYRIGHT{"Copyright (c) 2016-%1 Félix de las Pozas Álvarez"};
//-----------------------------------------------------------------
AboutDialog::AboutDialog(QWidget *parent, Qt::WindowFlags flags)
: QDialog(parent, flags)
{
setupUi(this);
setWindowFlags(windowFlags() & ~(Qt::WindowContextHelpButtonHint) & ~(Qt::WindowMaximizeButtonHint) & ~(Qt::WindowMinimizeButtonHint));
auto compilation_date = QString(__DATE__);
auto compilation_time = QString(" (") + QString(__TIME__) + QString(")");
const auto verStr = tr("version");
m_compilationDate->setText(tr("Compiled on ") + compilation_date + compilation_time);
m_version->setText(QString("%1 %2").arg(verStr).arg(VERSION));
m_qtVersion->setText(QString("%1 %2").arg(verStr).arg(qVersion()));
m_chartsVersion->setText(QString("%1 %2").arg(verStr).arg("2.1.0"));
m_copyright->setText(COPYRIGHT.arg(QDateTime::currentDateTime().date().year()));
fillTranslationsTable();
fillThemesTable();
fillProvidersTable();
tabWidget->setCurrentIndex(0);
}
//-----------------------------------------------------------------
void AboutDialog::showEvent(QShowEvent *e)
{
QDialog::showEvent(e);
scaleDialog(this);
}
//-----------------------------------------------------------------
void AboutDialog::changeEvent(QEvent *e)
{
if(e && e->type() == QEvent::LanguageChange)
{
retranslateUi(this);
}
QDialog::changeEvent(e);
}
//-----------------------------------------------------------------
void AboutDialog::fillTranslationsTable() const
{
m_translations->clear();
m_translations->verticalHeader()->setVisible(false);
m_translations->horizontalHeader()->setVisible(false);
m_translations->setRowCount(TRANSLATIONS.size());
m_translations->setColumnCount(2);
for(int i = 0; i < TRANSLATIONS.size(); ++i)
{
const auto &lang = TRANSLATIONS.at(i);
auto item = new QTableWidgetItem();
item->setIcon(QIcon(lang.icon));
item->setData(Qt::DisplayRole, lang.name);
m_translations->setItem(i, 0, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, lang.author);
m_translations->setItem(i, 1, item);
}
m_translations->resizeColumnToContents(0);
}
//-----------------------------------------------------------------
void AboutDialog::fillThemesTable() const
{
m_themes->clear();
m_themes->verticalHeader()->setVisible(false);
m_themes->horizontalHeader()->setVisible(false);
m_themes->setRowCount(ICON_THEMES.size());
m_themes->setColumnCount(2);
for(int i = 0; i < ICON_THEMES.size(); ++i)
{
const auto &theme = ICON_THEMES.at(i);
auto item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, theme.name);
m_themes->setItem(i, 0, item);
auto label = new QLabel{QString("<a href=\"%1\">%1</a>").arg(theme.author)};
label->setOpenExternalLinks(true);
m_themes->setCellWidget(i, 1, label);
}
m_themes->resizeColumnToContents(0);
m_themes->horizontalHeader()->setStretchLastSection(true);
}
//-----------------------------------------------------------------
void AboutDialog::fillProvidersTable() const
{
m_providers->clear();
m_providers->verticalHeader()->setVisible(false);
m_providers->horizontalHeader()->setVisible(false);
m_providers->setRowCount(WEATHER_PROVIDERS.size());
m_providers->setColumnCount(2);
Configuration nullConfig;
for(int i = 0; i < WEATHER_PROVIDERS.size(); ++i)
{
const auto &provider = WeatherProviderFactory::createProvider(WEATHER_PROVIDERS.at(i).id, nullConfig);
auto item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, provider->id());
m_providers->setItem(i, 0, item);
auto label = new QLabel{QString("<a href=\"%1\">%1</a>").arg(provider->website())};
label->setOpenExternalLinks(true);
m_providers->setCellWidget(i, 1, label);
}
m_providers->resizeColumnToContents(0);
m_providers->horizontalHeader()->setStretchLastSection(true);
}