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.
120 lines
4.6 KiB
120 lines
4.6 KiB
#include "stylehelper.h"
|
|
#include <QApplication>
|
|
|
|
/**
|
|
* 样式助手实现
|
|
* 提供统一的UI样式和主题管理
|
|
*/
|
|
|
|
QString StyleHelper::getGlobalStyleSheet() {
|
|
return R"(
|
|
*{font-family:'Segoe UI','PingFang SC','Microsoft YaHei','WenQuanYi Micro Hei',sans-serif;}
|
|
QWidget{background:#fafafa;color:#222;}
|
|
QGroupBox{border:1px solid #e0e0e0;border-radius:8px;margin-top:8px;padding-top:12px;}
|
|
QGroupBox::title{subcontrol-origin: margin;left:10px;padding:0 6px;color:#111;font-weight:bold;}
|
|
QFrame{background:white;border:1px solid #e6e6e6;border-radius:8px;}
|
|
#headerBar{background:#ffffff;border:1px solid #e6e6e6;border-radius:10px;}
|
|
#sideNav{background:#ffffff;border:1px solid #e6e6e6;border-radius:10px;}
|
|
#rightPanel{background:transparent;}
|
|
QToolButton{background:#ffffff;border:1px solid #e6e6e6;border-radius:8px;padding:6px;}
|
|
QToolButton:hover{background:#f2f7ff;border-color:#d0dcff;}
|
|
QPushButton{background:#ffffff;border:1px solid #d9d9d9;border-radius:8px;padding:6px 10px;}
|
|
QPushButton:hover{background:#f8f8f8;border-color:#c8c8c8;}
|
|
QPushButton:pressed{background:#f0f0f0;}
|
|
QPushButton[primary='true']{background:#2979ff;color:#fff;border:1px solid #1f6ae6;}
|
|
QPushButton[primary='true']:hover{background:#1565c0;border-color:#155bb0;}
|
|
QLabel.section{font-weight:bold;padding:4px 0;}
|
|
QLineEdit,QComboBox{background:#ffffff;border:1px solid #d9d9d9;border-radius:6px;padding:4px 6px;}
|
|
QComboBox QAbstractItemView{border:1px solid #d9d9d9;background:#ffffff;selection-background-color:#e8f0ff;}
|
|
#recLed{background:#e33;border-radius:7px;}
|
|
)";
|
|
}
|
|
|
|
QString StyleHelper::getButtonStyle(const QString& type) {
|
|
if (type == "primary") {
|
|
return "QPushButton{background:#2979ff;color:#fff;border:1px solid #1f6ae6;border-radius:8px;padding:6px 10px;}"
|
|
"QPushButton:hover{background:#1565c0;border-color:#155bb0;}";
|
|
} else if (type == "success") {
|
|
return "QPushButton{background:#28a745;color:#fff;border:1px solid #1e7e34;border-radius:8px;padding:6px 10px;}"
|
|
"QPushButton:hover{background:#1e7e34;border-color:#1c7430;}";
|
|
} else if (type == "warning") {
|
|
return "QPushButton{background:#fd7e14;color:#fff;border:1px solid #e55a00;border-radius:8px;padding:6px 10px;}"
|
|
"QPushButton:hover{background:#e55a00;border-color:#d35400;}";
|
|
} else if (type == "danger") {
|
|
return "QPushButton{background:#dc3545;color:#fff;border:1px solid #c82333;border-radius:8px;padding:6px 10px;}"
|
|
"QPushButton:hover{background:#c82333;border-color:#bd2130;}";
|
|
} else {
|
|
return "QPushButton{background:#ffffff;border:1px solid #d9d9d9;border-radius:8px;padding:6px 10px;}"
|
|
"QPushButton:hover{background:#f8f8f8;border-color:#c8c8c8;}"
|
|
"QPushButton:pressed{background:#f0f0f0;}";
|
|
}
|
|
}
|
|
|
|
QString StyleHelper::getGroupBoxStyle() {
|
|
return "QGroupBox{border:1px solid #e0e0e0;border-radius:8px;margin-top:8px;padding-top:12px;}"
|
|
"QGroupBox::title{subcontrol-origin: margin;left:10px;padding:0 6px;color:#111;font-weight:bold;}";
|
|
}
|
|
|
|
QString StyleHelper::getFrameStyle() {
|
|
return "QFrame{background:white;border:1px solid #e6e6e6;border-radius:8px;}";
|
|
}
|
|
|
|
QString StyleHelper::getLabelStyle(const QString& type) {
|
|
if (type == "title") {
|
|
return "QLabel{font-weight:bold;font-size:16px;color:#111;}";
|
|
} else if (type == "section") {
|
|
return "QLabel{font-weight:bold;padding:4px 0;color:#495057;}";
|
|
} else if (type == "success") {
|
|
return "QLabel{color:#28a745;font-weight:bold;}";
|
|
} else if (type == "warning") {
|
|
return "QLabel{color:#fd7e14;font-weight:bold;}";
|
|
} else if (type == "danger") {
|
|
return "QLabel{color:#dc3545;font-weight:bold;}";
|
|
} else if (type == "info") {
|
|
return "QLabel{color:#17a2b8;font-weight:bold;}";
|
|
} else {
|
|
return "QLabel{color:#6c757d;}";
|
|
}
|
|
}
|
|
|
|
void StyleHelper::applyStyle(QWidget* widget, const QString& style) {
|
|
widget->setStyleSheet(style);
|
|
}
|
|
|
|
QString StyleHelper::getPrimaryColor() {
|
|
return "#2979ff";
|
|
}
|
|
|
|
QString StyleHelper::getSecondaryColor() {
|
|
return "#6c757d";
|
|
}
|
|
|
|
QString StyleHelper::getSuccessColor() {
|
|
return "#28a745";
|
|
}
|
|
|
|
QString StyleHelper::getWarningColor() {
|
|
return "#fd7e14";
|
|
}
|
|
|
|
QString StyleHelper::getErrorColor() {
|
|
return "#dc3545";
|
|
}
|
|
|
|
QString StyleHelper::getInfoColor() {
|
|
return "#17a2b8";
|
|
}
|
|
|
|
int StyleHelper::getBorderRadius() {
|
|
return 8;
|
|
}
|
|
|
|
int StyleHelper::getPadding() {
|
|
return 6;
|
|
}
|
|
|
|
int StyleHelper::getMargin() {
|
|
return 8;
|
|
}
|
|
|