mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 07:35:41 +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 <QDebug>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
#include <QPainter>
|
#include <QStylePainter>
|
||||||
|
#include <QAbstractScrollArea>
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
@@ -324,16 +325,28 @@ namespace BlackGui
|
|||||||
return dirPath;
|
return dirPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CStyleSheetUtility::useStyleSheetInDerivedWidget(QWidget *usedWidget, QStyle::PrimitiveElement element)
|
bool CStyleSheetUtility::useStyleSheetInDerivedWidget(QWidget *usedWidget, QStyle::PrimitiveElement element)
|
||||||
{
|
{
|
||||||
Q_ASSERT(usedWidget);
|
Q_ASSERT(usedWidget);
|
||||||
if (!usedWidget) { return; }
|
if (!usedWidget) { return false; }
|
||||||
|
|
||||||
Q_ASSERT(usedWidget->style());
|
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;
|
QStyleOption opt;
|
||||||
opt.initFrom(usedWidget);
|
opt.initFrom(usedWidget);
|
||||||
QPainter p(usedWidget);
|
p.drawPrimitive(element, opt);
|
||||||
usedWidget->style()->drawPrimitive(element, &opt, &p, usedWidget);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CStyleSheetUtility::styleForIconCheckBox(const QString &checkedIcon, const QString &uncheckedIcon, const QString &width, const QString &height)
|
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); }";
|
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);
|
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
|
//! Use style sheets in derived widgets
|
||||||
//! \sa QWidget::paintEvent
|
//! \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
|
//! 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");
|
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:
|
signals:
|
||||||
//! Sheets have been changed
|
//! Sheets have been changed
|
||||||
void styleSheetsChanged();
|
void styleSheetsChanged();
|
||||||
|
|||||||
Reference in New Issue
Block a user