~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to src/topbasewidget.cpp

  • Committer: lixiang
  • Date: 2018-03-06 03:13:06 UTC
  • Revision ID: lixiang@kylinos.cn-20180306031306-fd7qnru3vm4a1xjd
Rewrite with Qt5, and add system monitor

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 ~ 2015 National University of Defense Technology(NUDT) & Kylin Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *  Kobe Lee    xiangli@ubuntukylin.com/kobe24_lixiang@126.com
 
6
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 */
 
19
 
 
20
#include "topbasewidget.h"
 
21
#include "mainwindow.h"
 
22
 
 
23
#include <QApplication>
 
24
#include <QDebug>
 
25
#include <QVBoxLayout>
 
26
#include <QHBoxLayout>
 
27
#include <QPixmap>
 
28
#include <QPushButton>
 
29
#include <QCursor>
 
30
 
 
31
 
 
32
//    enum SettingModuleID{
 
33
//        ThemePage = 0,
 
34
//        IconPage,
 
35
//        MousePage,
 
36
//        SoundPage,
 
37
//        PanelPage,
 
38
//        MenuPage,
 
39
//        WindowPage,
 
40
//        FontPage,
 
41
//        TouchPadPage,
 
42
//        EnergyPage,
 
43
//        FMPage
 
44
//    };
 
45
 
 
46
namespace {
 
47
//const QMap<SettingModuleID::SettingModuleID, QString> titleMap()
 
48
//{
 
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");
 
54
//    return m;
 
55
//}
 
56
 
 
57
//int filterTitleAccordModuleName(SettingAction::SettingModuleID id)
 
58
//{
 
59
//    return titleMap().value(id);
 
60
//}
 
61
 
 
62
const QMap<QString, QString> titleMap()
 
63
{
 
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"));
 
76
 
 
77
    return tMap;
 
78
}
 
79
 
 
80
QString filterTitleAccordModuleName(QString moduleName)
 
81
{
 
82
    return titleMap().value(moduleName);
 
83
}
 
84
 
 
85
}
 
86
 
 
87
TopBaseWidget::TopBaseWidget(QWidget *parent)
 
88
        : QWidget(parent)
 
89
{
 
90
    m_titileMessage = "";
 
91
 
 
92
    this->setFixedSize(900, 150);
 
93
    this->setAutoFillBackground(true);
 
94
//    this->setObjectName("transparentWidget");
 
95
 
 
96
    this->initWidgets();
 
97
}
 
98
 
 
99
TopBaseWidget::~TopBaseWidget()
 
100
{
 
101
    if(img_label != NULL) {
 
102
        delete img_label;
 
103
        img_label = NULL;
 
104
    }
 
105
    if(suggest_label != NULL) {
 
106
        delete suggest_label;
 
107
        suggest_label = NULL;
 
108
    }
 
109
 
 
110
    delete back_button;
 
111
 
 
112
    //Segmentation fault
 
113
    QLayoutItem *child;
 
114
    while ((child = m_titleLeftLayout->takeAt(0)) != 0) {
 
115
        if (child->widget())
 
116
            child->widget()->deleteLater();
 
117
        delete child;
 
118
    }
 
119
    while ((child = m_titleRightLayout->takeAt(0)) != 0) {
 
120
        if (child->widget())
 
121
            child->widget()->deleteLater();
 
122
        delete child;
 
123
    }
 
124
    while ((child = m_toolLeftLayout->takeAt(0)) != 0) {
 
125
        if (child->widget())
 
126
            child->widget()->deleteLater();
 
127
        delete child;
 
128
    }
 
129
    while ((child = m_toolRightLayout->takeAt(0)) != 0) {
 
130
        if (child->widget())
 
131
            child->widget()->deleteLater();
 
132
        delete child;
 
133
    }
 
134
    while ((child = m_topLayout->takeAt(0)) != 0) {
 
135
        if (child->widget())
 
136
            child->widget()->deleteLater();
 
137
        delete child;
 
138
    }
 
139
    while ((child = m_bottomLayout->takeAt(0)) != 0) {
 
140
        if (child->widget())
 
141
            child->widget()->deleteLater();
 
142
        delete child;
 
143
    }
 
144
    delete m_layout;
 
145
}
 
146
 
 
147
void TopBaseWidget::setTipMessage(const QString &message)
 
148
{
 
149
    this->m_titileMessage = message;
 
150
 
 
151
    suggest_label->setText(message);
 
152
}
 
153
 
 
154
void TopBaseWidget::setImage(const QString &pic)
 
155
{
 
156
    QPixmap label_pixmap(pic);
 
157
    img_label->setPixmap(label_pixmap);
 
158
    img_label->setFixedSize(label_pixmap.size());
 
159
}
 
160
 
 
161
//QString TopBaseWidget::getModuleName() /*const*/
 
162
//{
 
163
//    return this->m_moduleName;
 
164
//}
 
165
 
 
166
//void SettingAction::setModuleName(const QString &name)
 
167
//void TopBaseWidget::setModuleName(QString name)
 
168
//{
 
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."));
 
174
////    }
 
175
////    else {
 
176
////        suggest_label->setText(title);
 
177
////    }
 
178
//}
 
179
 
 
180
//void TopBaseWidget::displayActionSubPage(SettingAction::SettingModuleID moduleId)
 
181
void TopBaseWidget::displayActionSubPage(QString moduleName)
 
182
{
 
183
//    this->m_moduleName = moduleName;
 
184
    back_button->setVisible(true);
 
185
 
 
186
    const QString title = filterTitleAccordModuleName(moduleName);
 
187
    if (title.isEmpty() || title.isNull()) {
 
188
        suggest_label->setText(tr("There may be a mistake."));
 
189
    }
 
190
    else {
 
191
        suggest_label->setText(title);
 
192
    }
 
193
}
 
194
 
 
195
void TopBaseWidget::initTitlebarLeftContent()
 
196
{
 
197
    QWidget *w = new QWidget;
 
198
    m_titleLeftLayout = new QHBoxLayout(w);
 
199
    m_titleLeftLayout->setContentsMargins(6, 0, 0, 0);
 
200
    m_titleLeftLayout->setSpacing(0);
 
201
 
 
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);
 
206
 
 
207
    m_topLayout->addWidget(w, 1, Qt::AlignLeft);
 
208
}
 
209
 
 
210
void TopBaseWidget::initTitlebarRightContent()
 
211
{
 
212
    QWidget *w = new QWidget;
 
213
    m_titleRightLayout = new QHBoxLayout(w);
 
214
    m_titleRightLayout->setContentsMargins(0, 0, 1, 0);
 
215
    m_titleRightLayout->setSpacing(0);
 
216
 
 
217
    m_topLayout->addWidget(w, 1, Qt::AlignRight);
 
218
 
 
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);
 
231
 
 
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);
 
236
 
 
237
    connect(main_menu_button, &SystemButton::clicked, this, [=] {
 
238
        emit this->showMenu();
 
239
    });
 
240
//    connect(skin_button, &SystemButton::clicked, this, [=] {
 
241
//        emit this->showSkinCenter();
 
242
//    });
 
243
    connect(min_button, &SystemButton::clicked, this, [=] {
 
244
        emit this->showMin();
 
245
    });
 
246
    connect(close_button, &SystemButton::clicked, this, [=] {
 
247
        emit this->closeApp();//window()->close();
 
248
    });
 
249
}
 
250
 
 
251
void TopBaseWidget::initContentLeftContent()
 
252
{
 
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);
 
257
 
 
258
    img_label = new QLabel();
 
259
    suggest_label = new QLabel();
 
260
 
 
261
    img_label->setScaledContents(true);//自动缩放,显示图像大小自动调整为Qlabel大小
 
262
 
 
263
    suggest_label->setObjectName("whiteLabel");
 
264
    suggest_label->setWordWrap(true);//QLabel自动换行
 
265
    suggest_label->setFixedWidth(650);
 
266
 
 
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();
 
272
 
 
273
//    m_bottomLayout->addWidget(w);
 
274
    m_bottomLayout->addWidget(w, 1, Qt::AlignLeft);
 
275
}
 
276
 
 
277
void TopBaseWidget::initActionRightContent()
 
278
{
 
279
    QWidget *w = new QWidget;
 
280
    m_toolRightLayout = new QHBoxLayout(w);
 
281
    m_toolRightLayout->setContentsMargins(0, 3, 0, 10);
 
282
    m_toolRightLayout->setSpacing(0);
 
283
 
 
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();
 
298
    });
 
299
 
 
300
    m_toolRightLayout->addWidget(back_button);
 
301
    m_bottomLayout->addWidget(w, 1, Qt::AlignRight);
 
302
}
 
303
 
 
304
void TopBaseWidget::initWidgets()
 
305
{
 
306
    m_layout = new QVBoxLayout(this);
 
307
    m_layout->setContentsMargins(0, 0, 0, 0);
 
308
    m_layout->setSpacing(0);
 
309
 
 
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);
 
315
 
 
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);
 
321
 
 
322
    this->setLayout(m_layout);
 
323
 
 
324
    initTitlebarLeftContent();
 
325
    initTitlebarRightContent();
 
326
    initContentLeftContent();
 
327
    initActionRightContent();
 
328
}