You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.8 KiB
76 lines
1.8 KiB
#include "editorsettingsoptions.h"
|
|
#include <QStyle>
|
|
#include <QVariant>
|
|
#include <qdebug.h>
|
|
|
|
// 重载<<运算符,将枚举类型的值输出到标准输出流
|
|
EditorSettingsOptions::EditorSettingsOptions(QObject *) { }
|
|
|
|
//选用switch来选择要输出的枚举值
|
|
std::ostream &operator<<(std::ostream &os, const FontTypeface::Value &fontTypeface)
|
|
{
|
|
switch (fontTypeface) {
|
|
case FontTypeface::SansSerif:
|
|
os << "SansSerif";
|
|
break;
|
|
case FontTypeface::Serif:
|
|
os << "Serif";
|
|
break;
|
|
case FontTypeface::Mono:
|
|
os << "Mono";
|
|
break;
|
|
}
|
|
return os;
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &os, const Theme::Value &theme)
|
|
{
|
|
switch (theme) {
|
|
case Theme::Light:
|
|
os << "Light";
|
|
break;
|
|
case Theme::Dark:
|
|
os << "Dark";
|
|
break;
|
|
case Theme::Sepia:
|
|
os << "Sepia";
|
|
break;
|
|
}
|
|
return os;
|
|
}
|
|
|
|
//使用str()函数来重载to_string函数
|
|
std::string to_string(FontTypeface::Value fontTypeface)
|
|
{
|
|
std::ostringstream oss;
|
|
oss << fontTypeface;
|
|
return oss.str();
|
|
}
|
|
|
|
std::string to_string(Theme::Value theme)
|
|
{
|
|
std::ostringstream oss;
|
|
oss << theme;
|
|
return oss.str();
|
|
}
|
|
|
|
//函数调用,没看懂什么意思,是要再进行功能扩展吗
|
|
void setCSSThemeAndUpdate(QWidget *obj, Theme::Value theme)
|
|
{
|
|
//标准输入输出
|
|
setCSSClassesAndUpdate(obj, QString::fromStdString(to_string(theme)).toLower().toStdString());
|
|
}
|
|
//更新
|
|
void setCSSClassesAndUpdate(QWidget *obj, std::string classNames)
|
|
{
|
|
if (obj->styleSheet().isEmpty()) {
|
|
qWarning() << "setCSSClassesAndUpdate: styleSheet is empty for widget with name "
|
|
<< obj->objectName();
|
|
}
|
|
// set the class
|
|
obj->setProperty("class", classNames.c_str());
|
|
// update the widget
|
|
obj->style()->polish(obj);
|
|
obj->update();
|
|
}
|