5 #include <QApplication> 6 #include <QStyleFactory> 10 #include <QMessageBox> 11 #include <QPushButton> 16 static const QString STYLE_FORMAT =
":/styles/%1";
17 static const QColor LINK_COLOR =
"#2d9ad0";
25 if(widget && widget->inherits(
"QComboBox"))
27 QComboBox* comboBox = (QComboBox*)widget;
28 if(comboBox->view() && comboBox->view()->inherits(
"QComboBoxListView"))
30 comboBox->setView(
new QListView());
31 qApp->processEvents();
34 if(comboBox->view() && comboBox->view()->parentWidget())
36 QWidget* parent = comboBox->view()->parentWidget();
37 parent->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);
38 parent->setAttribute(Qt::WA_TranslucentBackground);
41 if(widget && widget->inherits(
"QMessageBox"))
43 QMessageBox* messageBox = (QMessageBox*)widget;
45 QMessageBox::Icon icon = messageBox->icon();
48 case QMessageBox::Information:
49 iconPixmap = QPixmap(
":/styles/app-icons/message_info");
51 case QMessageBox::Warning:
52 iconPixmap = QPixmap(
":/styles/app-icons/message_warning");
54 case QMessageBox::Critical:
55 iconPixmap = QPixmap(
":/styles/app-icons/message_critical");
57 case QMessageBox::Question:
58 iconPixmap = QPixmap(
":/styles/app-icons/message_question");
61 QProxyStyle::polish(widget);
64 messageBox->setIconPixmap(iconPixmap.scaled(45,49));
66 if(widget && widget->inherits(
"QPushButton"))
68 QPushButton* button = (QPushButton*)widget;
69 button->setText(button->text().toUpper());
71 if(widget && widget->inherits(
"QLineEdit"))
73 QLineEdit* lineEdit = (QLineEdit*)widget;
74 if(lineEdit->isReadOnly())
76 lineEdit->setFocusPolicy(Qt::ClickFocus);
80 QProxyStyle::polish(widget);
95 setObjectStyleSheet<QWidget>(widget, style_name);
100 QStyle* mainStyle = QStyleFactory::create(
"fusion");
102 fabcoinStyle->setBaseStyle(mainStyle);
103 app->setStyle(fabcoinStyle);
105 QPalette mainPalette(app->palette());
106 mainPalette.setColor(QPalette::Link, LINK_COLOR);
107 app->setPalette(mainPalette);
110 QFont font = app->font();
111 qreal fontSize = font.pointSizeF();
112 qreal multiplier = 1;
113 #if defined(Q_OS_WIN) || defined(Q_OS_MAC) 116 font.setPointSizeF(fontSize * multiplier);
119 setObjectStyleSheet<QApplication>(app, style_name);
125 QFile file(STYLE_FORMAT.arg(style_name));
126 if(file.open(QIODevice::ReadOnly))
128 style = file.readAll();
129 m_cacheStyles[style_name] = style;
137 QString style_value = m_cacheStyles.contains(style_name) ? m_cacheStyles[style_name] : getStyleSheet(style_name);
138 object->setStyleSheet(style_value);
static StyleSheet & instance()
QString getStyleSheet(const QString &style_name)
void setStyleSheet(QWidget *widget, const QString &style_name)
Singleton class that manage the styles.
void setObjectStyleSheet(T *object, const QString &style_name)
void polish(QWidget *widget)