2
* Copyright (C) 2013 ~ 2015 National University of Defense Technology(NUDT) & Kylin Ltd.
5
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; version 3.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "topbasewidget.h"
21
#include "mainwindow.h"
23
#include <QApplication>
25
#include <QVBoxLayout>
26
#include <QHBoxLayout>
28
#include <QPushButton>
32
// enum SettingModuleID{
47
//const QMap<SettingModuleID::SettingModuleID, QString> titleMap()
49
// QMap<SettingAction::SettingModuleID, QString> m;
50
// m.insert(SettingAction::ThemePage, "a");
51
// m.insert(SettingAction::IconPage, "b");
52
// m.insert(SettingAction::MousePage, "c");
53
// m.insert(SettingAction::SoundPage, "d");
57
//int filterTitleAccordModuleName(SettingAction::SettingModuleID id)
59
// return titleMap().value(id);
62
const QMap<QString, QString> titleMap()
64
QMap<QString, QString> tMap;
65
tMap.insert("ThemePage", QObject::tr("Choose the theme what you want"));
66
tMap.insert("IconPage", QObject::tr("Set the desktop icon theme and the visibility of desktop icons"));
67
tMap.insert("MousePage", QObject::tr("Replace the theme and size of the mouse pointer, and theme change need to restart system"));
68
tMap.insert("SoundPage", QObject::tr("Set the sound theme you want"));
69
tMap.insert("PanelPage", QObject::tr("Setting the panel mode of auto hide and icon size"));
70
tMap.insert("MenuPage", QObject::tr("Manage display of the start menu"));
71
tMap.insert("WindowPage", QObject::tr("Window Manager settings"));
72
tMap.insert("FontPage", QObject::tr("According to personal preferences to set the system default font, click the 'Restore' button, can be restored to the state before the font settings"));
73
tMap.insert("TouchPadPage", QObject::tr("Setting the relevant properties of your touchpad,make the operation more convenient"));
74
tMap.insert("EnergyPage", QObject::tr("Save energy to let the computer longer standby time"));
75
tMap.insert("FMPage", QObject::tr("Manage the file manager. Tips: if the thumbnail's cache time or size is set to -1, it will not be checked"));
80
QString filterTitleAccordModuleName(QString moduleName)
82
return titleMap().value(moduleName);
87
TopBaseWidget::TopBaseWidget(QWidget *parent)
92
this->setFixedSize(900, 150);
93
this->setAutoFillBackground(true);
94
// this->setObjectName("transparentWidget");
99
TopBaseWidget::~TopBaseWidget()
101
if(img_label != NULL) {
105
if(suggest_label != NULL) {
106
delete suggest_label;
107
suggest_label = NULL;
114
while ((child = m_titleLeftLayout->takeAt(0)) != 0) {
116
child->widget()->deleteLater();
119
while ((child = m_titleRightLayout->takeAt(0)) != 0) {
121
child->widget()->deleteLater();
124
while ((child = m_toolLeftLayout->takeAt(0)) != 0) {
126
child->widget()->deleteLater();
129
while ((child = m_toolRightLayout->takeAt(0)) != 0) {
131
child->widget()->deleteLater();
134
while ((child = m_topLayout->takeAt(0)) != 0) {
136
child->widget()->deleteLater();
139
while ((child = m_bottomLayout->takeAt(0)) != 0) {
141
child->widget()->deleteLater();
147
void TopBaseWidget::setTipMessage(const QString &message)
149
this->m_titileMessage = message;
151
suggest_label->setText(message);
154
void TopBaseWidget::setImage(const QString &pic)
156
QPixmap label_pixmap(pic);
157
img_label->setPixmap(label_pixmap);
158
img_label->setFixedSize(label_pixmap.size());
161
//QString TopBaseWidget::getModuleName() /*const*/
163
// return this->m_moduleName;
166
//void SettingAction::setModuleName(const QString &name)
167
//void TopBaseWidget::setModuleName(QString name)
169
//// this->m_moduleName = name;
170
//// back_button->setVisible(true);
171
//// const QString title = filterTitleAccordModuleName(name);
172
//// if (title.isEmpty() || title.isNull()) {
173
//// suggest_label->setText(tr("There may be a mistake."));
176
//// suggest_label->setText(title);
180
//void TopBaseWidget::displayActionSubPage(SettingAction::SettingModuleID moduleId)
181
void TopBaseWidget::displayActionSubPage(QString moduleName)
183
// this->m_moduleName = moduleName;
184
back_button->setVisible(true);
186
const QString title = filterTitleAccordModuleName(moduleName);
187
if (title.isEmpty() || title.isNull()) {
188
suggest_label->setText(tr("There may be a mistake."));
191
suggest_label->setText(title);
195
void TopBaseWidget::initTitlebarLeftContent()
197
QWidget *w = new QWidget;
198
m_titleLeftLayout = new QHBoxLayout(w);
199
m_titleLeftLayout->setContentsMargins(6, 0, 0, 0);
200
m_titleLeftLayout->setSpacing(0);
202
QLabel *appLabel = new QLabel;
203
appLabel->setStyleSheet("QLabel{background-color:transparent;color:#ffffff; font-size:12px;}");
204
appLabel->setText(tr("Kylin Assistant"));
205
m_titleLeftLayout->addWidget(appLabel);
207
m_topLayout->addWidget(w, 1, Qt::AlignLeft);
210
void TopBaseWidget::initTitlebarRightContent()
212
QWidget *w = new QWidget;
213
m_titleRightLayout = new QHBoxLayout(w);
214
m_titleRightLayout->setContentsMargins(0, 0, 1, 0);
215
m_titleRightLayout->setSpacing(0);
217
m_topLayout->addWidget(w, 1, Qt::AlignRight);
219
SystemButton *min_button = new SystemButton();
220
SystemButton *close_button = new SystemButton();
221
// SystemButton *skin_button = new SystemButton();
222
SystemButton *main_menu_button = new SystemButton();
223
min_button->loadPixmap(":/sys/res/sysBtn/min_button.png");
224
close_button->loadPixmap(":/sys/res/sysBtn/close_button.png");
225
// skin_button->loadPixmap(":/sys/res/sysBtn/skin_button.png");
226
main_menu_button->loadPixmap(":/sys/res/sysBtn/main_menu.png");
227
min_button->setFocusPolicy(Qt::NoFocus);
228
close_button->setFocusPolicy(Qt::NoFocus);
229
// skin_button->setFocusPolicy(Qt::NoFocus);
230
main_menu_button->setFocusPolicy(Qt::NoFocus);
232
m_titleRightLayout->addWidget(main_menu_button);
233
// m_titleRightLayout->addWidget(skin_button);
234
m_titleRightLayout->addWidget(min_button);
235
m_titleRightLayout->addWidget(close_button);
237
connect(main_menu_button, &SystemButton::clicked, this, [=] {
238
emit this->showMenu();
240
// connect(skin_button, &SystemButton::clicked, this, [=] {
241
// emit this->showSkinCenter();
243
connect(min_button, &SystemButton::clicked, this, [=] {
244
emit this->showMin();
246
connect(close_button, &SystemButton::clicked, this, [=] {
247
emit this->closeApp();//window()->close();
251
void TopBaseWidget::initContentLeftContent()
253
QWidget *w = new QWidget;
254
w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
255
m_toolLeftLayout = new QHBoxLayout(w);
256
m_toolLeftLayout->setContentsMargins(0, 0, 0, 0);
258
img_label = new QLabel();
259
suggest_label = new QLabel();
261
img_label->setScaledContents(true);//自动缩放,显示图像大小自动调整为Qlabel大小
263
suggest_label->setObjectName("whiteLabel");
264
suggest_label->setWordWrap(true);//QLabel自动换行
265
suggest_label->setFixedWidth(650);
267
m_toolLeftLayout->setSpacing(10);
268
m_toolLeftLayout->addStretch();
269
m_toolLeftLayout->addWidget(img_label, 0, Qt::AlignHCenter);
270
m_toolLeftLayout->addWidget(suggest_label, 0, Qt::AlignHCenter);
271
m_toolLeftLayout->addStretch();
273
// m_bottomLayout->addWidget(w);
274
m_bottomLayout->addWidget(w, 1, Qt::AlignLeft);
277
void TopBaseWidget::initActionRightContent()
279
QWidget *w = new QWidget;
280
m_toolRightLayout = new QHBoxLayout(w);
281
m_toolRightLayout->setContentsMargins(0, 3, 0, 10);
282
m_toolRightLayout->setSpacing(0);
284
back_button = new QPushButton();
285
back_button->setCursor(Qt::PointingHandCursor);
286
back_button->setFixedSize(91,39);
287
back_button->setFocusPolicy(Qt::NoFocus);
288
QPixmap pixmap("://res/back-arrow.png");
289
back_button->setIcon(pixmap);
290
back_button->setIconSize(pixmap.size());
291
back_button->setObjectName("backgroundButton");
292
back_button->setText(tr("Back"));
293
back_button->setVisible(false);
294
connect(back_button, &QPushButton::clicked, this, [=] {
295
suggest_label->setText(this->m_titileMessage);
296
back_button->setVisible(false);
297
emit this->notifyContentPageToMain();
300
m_toolRightLayout->addWidget(back_button);
301
m_bottomLayout->addWidget(w, 1, Qt::AlignRight);
304
void TopBaseWidget::initWidgets()
306
m_layout = new QVBoxLayout(this);
307
m_layout->setContentsMargins(0, 0, 0, 0);
308
m_layout->setSpacing(0);
310
QWidget *topWidget = new QWidget;
311
m_topLayout = new QHBoxLayout(topWidget);
312
m_topLayout->setContentsMargins(0, 0, 0, 0);
313
m_topLayout->setSpacing(0);
314
m_layout->addWidget(topWidget, 0, Qt::AlignTop);
316
QWidget *bottomWidget = new QWidget;
317
m_bottomLayout = new QHBoxLayout(bottomWidget);
318
m_bottomLayout->setContentsMargins(19, 0, 0, 26);
319
m_bottomLayout->setSpacing(0);
320
m_layout->addWidget(bottomWidget, 0, Qt::AlignBottom);
322
this->setLayout(m_layout);
324
initTitlebarLeftContent();
325
initTitlebarRightContent();
326
initContentLeftContent();
327
initActionRightContent();