quarkai/setting/themewidget.cpp

136 lines
3.4 KiB
C++
Raw Normal View History

2017-12-21 11:51:56 +08:00
/*
2018-02-11 19:02:25 +08:00
* Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd.
2017-12-21 11:51:56 +08:00
*
* Authors:
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
*
* 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; version 3.
*
* 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/>.
*/
#include "themewidget.h"
2018-02-11 19:02:25 +08:00
#include "theme/themeview.h"
2017-12-21 11:51:56 +08:00
#include <QStandardItemModel>
2018-01-17 11:45:16 +08:00
#include <QSignalMapper>
2017-12-21 11:51:56 +08:00
#include <QListWidgetItem>
#include <QLabel>
#include <QDebug>
#include <QGridLayout>
2018-01-17 11:45:16 +08:00
ThemeWidget::ThemeWidget(QWidget *parent) :
SettingModulePage(parent)
2017-12-21 11:51:56 +08:00
{
2018-01-17 11:45:16 +08:00
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// this->resize(parent->size());
// this->setFixedSize(900, 403);
2017-12-21 11:51:56 +08:00
label = new QLabel(this);
label->setObjectName("tipLabel");
2018-02-11 19:02:25 +08:00
label->setFixedHeight(30);
// label->setGeometry(QRect(30, 15, 860, 50));
2017-12-21 11:51:56 +08:00
label->setText(tr("Please choose theme which you need"));
2018-01-17 11:45:16 +08:00
2018-02-11 19:02:25 +08:00
m_themeView = new ThemeView(this);
connect(m_themeView, SIGNAL(sendSelectThemeName(QString)), this, SLOT(changeTheme(QString)));
QVBoxLayout *layout = new QVBoxLayout(this);
2018-02-11 22:38:52 +08:00
layout->setSpacing(5);
2018-02-11 19:02:25 +08:00
layout->setMargin(0);
2018-02-11 22:38:52 +08:00
layout->setContentsMargins(10, 5, 10, 0);
2018-02-11 19:02:25 +08:00
layout->addWidget(label);
layout->addWidget(m_themeView);
this->setLayout(layout);
2017-12-21 11:51:56 +08:00
}
2018-01-17 11:45:16 +08:00
QString ThemeWidget::settingModuleName()
2017-12-21 11:51:56 +08:00
{
2018-01-17 11:45:16 +08:00
return "ThemePage";
2017-12-21 11:51:56 +08:00
}
2018-01-17 11:45:16 +08:00
void ThemeWidget::onReceiveThemeList(const QString &currentTheme, const QStringList &themeList)
{
// qDebug() << "currentTheme="<<currentTheme<<", themeList="<<themeList;
2017-12-21 11:51:56 +08:00
2018-01-17 11:45:16 +08:00
if (!themeList.isEmpty()) {
2018-02-11 19:02:25 +08:00
m_themeView->clearData();
2018-01-17 11:45:16 +08:00
syslist.clear();
syslist = themeList;
2018-02-11 19:02:25 +08:00
//kobe test 2018
for (const QString theme : themeList) {
if(currentTheme == theme)
m_themeView->loadOneTheme(theme, true);
else
m_themeView->loadOneTheme(theme, false);
}
2017-12-21 11:51:56 +08:00
}
2018-01-17 11:45:16 +08:00
}
void ThemeWidget::initSettingData()
{
emit this->requestThemeData();
2017-12-21 11:51:56 +08:00
this->initConnect();
}
ThemeWidget::~ThemeWidget()
2018-01-17 11:45:16 +08:00
{
this->resetUI();
}
void ThemeWidget::resetUI()
2017-12-21 11:51:56 +08:00
{
2018-02-12 12:20:24 +08:00
2017-12-21 11:51:56 +08:00
}
void ThemeWidget::initConnect() {
2018-01-17 11:45:16 +08:00
// connect(sessionproxy, SIGNAL(string_value_notify(QString, QString)), this, SLOT(themewidget_notify_string(QString, QString)));
2017-12-21 11:51:56 +08:00
}
void ThemeWidget::switchUsingLogo(QString index)
{
2018-02-12 12:20:24 +08:00
2017-12-21 11:51:56 +08:00
}
void ThemeWidget::changeTheme(QString name)
{
2018-01-17 11:45:16 +08:00
emit changeSystemTheme(name);
2017-12-21 11:51:56 +08:00
}
void ThemeWidget::themewidget_notify_string(QString key, QString value)
{
if (key == "gtk-theme")
{
QList<QString>::Iterator it = syslist.begin(), itend = syslist.end();
int index = -1;
bool exist = false;
for(;it != itend; it++)
{
++index;
if(*it == value) {
exist = true;
break;
}
}
if(exist)
{
exist = false;
this->switchUsingLogo(QString::number(index, 10));
}
}
}