mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
refs #452, style sheet utility
* view port enabled style sheet usage * concat styles
This commit is contained in:
committed by
Mathew Sutcliffe
parent
3e1e1070c1
commit
1bb0afdedd
@@ -14,7 +14,8 @@
|
||||
#include <QDebug>
|
||||
#include <QRegExp>
|
||||
#include <QStyleOption>
|
||||
#include <QPainter>
|
||||
#include <QStylePainter>
|
||||
#include <QAbstractScrollArea>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -324,16 +325,28 @@ namespace BlackGui
|
||||
return dirPath;
|
||||
}
|
||||
|
||||
void CStyleSheetUtility::useStyleSheetInDerivedWidget(QWidget *usedWidget, QStyle::PrimitiveElement element)
|
||||
bool CStyleSheetUtility::useStyleSheetInDerivedWidget(QWidget *usedWidget, QStyle::PrimitiveElement element)
|
||||
{
|
||||
Q_ASSERT(usedWidget);
|
||||
if (!usedWidget) { return; }
|
||||
if (!usedWidget) { return false; }
|
||||
|
||||
Q_ASSERT(usedWidget->style());
|
||||
if (!usedWidget->style()) { return; }
|
||||
QStyle *style = usedWidget->style();
|
||||
if (!style) { return false; }
|
||||
|
||||
// 1) QStylePainter: modern version of
|
||||
// usedWidget->style()->drawPrimitive(element, &opt, &p, usedWidget);
|
||||
// 2) With viewport based widgets viewport has to be used
|
||||
QAbstractScrollArea *sa = qobject_cast<QAbstractScrollArea *>(usedWidget);
|
||||
QStylePainter p(
|
||||
sa ? sa->viewport() :
|
||||
usedWidget);
|
||||
if (!p.isActive()) { return false; }
|
||||
|
||||
QStyleOption opt;
|
||||
opt.initFrom(usedWidget);
|
||||
QPainter p(usedWidget);
|
||||
usedWidget->style()->drawPrimitive(element, &opt, &p, usedWidget);
|
||||
p.drawPrimitive(element, opt);
|
||||
return true;
|
||||
}
|
||||
|
||||
QString CStyleSheetUtility::styleForIconCheckBox(const QString &checkedIcon, const QString &uncheckedIcon, const QString &width, const QString &height)
|
||||
@@ -344,4 +357,16 @@ namespace BlackGui
|
||||
static const QString st = "QCheckBox::indicator { width: %1; height: %2; } QCheckBox::indicator:checked { image: url(%3); } QCheckBox::indicator:unchecked { image: url(%4); }";
|
||||
return st.arg(width).arg(height).arg(checkedIcon).arg(uncheckedIcon);
|
||||
}
|
||||
|
||||
QString CStyleSheetUtility::concatStyles(const QString &style1, const QString &style2)
|
||||
{
|
||||
QString s1(style1.trimmed());
|
||||
QString s2(style2.trimmed());
|
||||
if (s1.isEmpty()) { return s2; }
|
||||
if (s2.isEmpty()) { return s1; }
|
||||
if (!s1.endsWith(";")) { s1 = s1.append("; "); }
|
||||
s1.append(s2);
|
||||
if (!s1.endsWith(";")) { s1 = s1.append(";"); }
|
||||
return s1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,11 +122,14 @@ namespace BlackGui
|
||||
|
||||
//! Use style sheets in derived widgets
|
||||
//! \sa QWidget::paintEvent
|
||||
static void useStyleSheetInDerivedWidget(QWidget *derivedWidget, QStyle::PrimitiveElement element = QStyle::PE_Widget);
|
||||
static bool useStyleSheetInDerivedWidget(QWidget *derivedWidget, QStyle::PrimitiveElement element = QStyle::PE_Widget);
|
||||
|
||||
//! Stylesheet string for a checkbox displayed as 2 icons
|
||||
static QString styleForIconCheckBox(const QString &checkedIcon, const QString &uncheckedIcon, const QString &width = "16px", const QString &height = "16px");
|
||||
|
||||
//! Concatenate 2 styles
|
||||
static QString concatStyles(const QString &style1, const QString &style2);
|
||||
|
||||
signals:
|
||||
//! Sheets have been changed
|
||||
void styleSheetsChanged();
|
||||
|
||||
Reference in New Issue
Block a user