1 Star 0 Fork 3

outersky/dde-sys-monitor-plugin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pluginsettingdialog.cpp 3.91 KB
一键复制 编辑 原始数据 按行查看 历史
juju 提交于 2021-02-16 22:33 . diy text in text mode
#include "pluginsettingdialog.h"
#include "ui_pluginsettingdialog.h"
pluginSettingDialog::pluginSettingDialog(Settings *settings,QWidget *parent) :
QDialog(parent),
ui(new Ui::pluginSettingDialog)
{
ui->setupUi(this);
if(settings->value("chartModeCheckBox").toInt()){
ui->tabWidget->setCurrentIndex(1);
}
else {
ui->tabWidget->setCurrentIndex(0);
}
pal=QPalette();//首先初始化画板
QMapIterator<QString,QVariant> i(*settings);
while(i.hasNext())
{
i.next();
//找到以key为名字的widget
QWidget *obj=findChild<QWidget*>(i.key());
if(obj==0){qDebug()<<"不能找到对象名为:"<<i.key();continue;}
if(obj->metaObject()->className()==QStringLiteral("QComboBox"))
{
QComboBox *cb=(QComboBox*)obj;
cb->setCurrentIndex(i.value().toInt());
}
else if(obj->metaObject()->className()==QStringLiteral("QCheckBox"))
{
QCheckBox *cb=(QCheckBox*)obj;
cb->setChecked(i.value().toInt());
}
else if(obj->metaObject()->className()==QStringLiteral("QSpinBox"))
{
QSpinBox *sb=(QSpinBox*)obj;
sb->setValue(i.value().toInt());
}
else if(obj->metaObject()->className()==QStringLiteral("QWidget"))
{
QWidget *wg=(QWidget*)obj;
pal.setColor(QPalette::Background,i.value().value<QColor>());
wg->setAutoFillBackground(true);
wg->setPalette(pal);
//qDebug()<<"颜色是:"<<i.value().value<QColor>();
}
else if(obj->metaObject()->className()==QStringLiteral("QLineEdit"))
{
QLineEdit *le=(QLineEdit*)obj;
le->setText(i.value().value<QString>());
}
}
foreach(QPushButton* btn,findChildren<QPushButton*>(QRegExp("\\w*ColorPushButton")))
{
connect(btn,SIGNAL(clicked(bool)),this,SLOT(selectColor(void)));
}
}
pluginSettingDialog::~pluginSettingDialog()
{
delete ui;
}
void pluginSettingDialog::getDisplayContentSetting(Settings *settings)
{
QMapIterator<QString,QVariant> i(*settings);
while(i.hasNext())
{
i.next();
//找到以key为名字的widget
QWidget *obj=findChild<QWidget*>(i.key());
if(obj==0){qDebug()<<"不能找到对象名为:"<<i.key();continue;}
if(obj->metaObject()->className()==QStringLiteral("QComboBox"))
{
QComboBox *cb=(QComboBox*)obj;
settings->insert(cb->objectName(),cb->currentIndex());
}
else if(obj->metaObject()->className()==QStringLiteral("QCheckBox"))
{
QCheckBox *cb=(QCheckBox*)obj;
settings->insert(cb->objectName(),cb->isChecked());
}
else if(obj->metaObject()->className()==QStringLiteral("QSpinBox"))
{
QSpinBox *sb=(QSpinBox*)obj;
settings->insert(sb->objectName(),sb->value());
}
else if(obj->metaObject()->className()==QStringLiteral("QWidget"))
{
QWidget *wg=(QWidget*)obj;
settings->insert(wg->objectName(),wg->palette().background().color());
}
else if(obj->metaObject()->className()==QStringLiteral("QLineEdit"))
{
QLineEdit *le=(QLineEdit*)obj;
settings->insert(le->objectName(),le->text());
}
}
}
void pluginSettingDialog::selectColor()
{
QWidget *colorWidget;
//"netUpColorPushButton"-->"netUpWidget"
colorWidget=findChild<QWidget*>(sender()->objectName().replace("ColorPushButton","Widget"));
QColor color = QColorDialog::getColor(colorWidget->palette().background().color(),
this,tr("颜色对话框"),QColorDialog::ShowAlphaChannel);
if(color!=QColor::Invalid)
{
pal.setColor(QPalette::Background,color);
colorWidget->setAutoFillBackground(true);
colorWidget->setPalette(pal);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/outersky/dde-sys-monitor-plugin.git
git@gitee.com:outersky/dde-sys-monitor-plugin.git
outersky
dde-sys-monitor-plugin
dde-sys-monitor-plugin
master

搜索帮助