⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qstylesheetstyle.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    if (pal->selectionBackground.style() != Qt::NoBrush)        p->setBrush(QPalette::Highlight, pal->selectionBackground);    if (pal->selectionForeground.style() != Qt::NoBrush)        p->setBrush(QPalette::HighlightedText, pal->selectionForeground);    if (pal->alternateBackground.style() != Qt::NoBrush)        p->setBrush(QPalette::AlternateBase, pal->alternateBackground);}void QRenderRule::configurePalette(QPalette *p, QPalette::ColorGroup cg, const QWidget *w, bool embedded){#ifdef QT_NO_COMBOBOX    const bool isReadOnlyCombo = false;#else    const bool isReadOnlyCombo = qobject_cast<const QComboBox *>(w) != 0;#endif    if (bg && bg->brush.style() == Qt::SolidPattern) {        if (isReadOnlyCombo) {            p->setBrush(cg, QPalette::Base, bg->brush); // for windows, windowxp            p->setBrush(cg, QPalette::Button, bg->brush); // for plastique        } else {            p->setBrush(cg, w->backgroundRole(), bg->brush);            //p->setBrush(cg, QPalette::Window, bg->brush);        }    }    if (embedded) {        /* For embedded widgets (ComboBox, SpinBox and ScrollArea) we want the embedded widget         * to be transparent when we have a transparent background or border image */        if ((hasBackground() && background()->isTransparent())            || (hasBorder() && border()->hasBorderImage() && border()->borderImage()->middleRect.isValid()))            p->setBrush(cg, w->backgroundRole(), Qt::NoBrush);    }    if (!hasPalette())        return;    if (pal->foreground.style() != Qt::NoBrush) {        if (isReadOnlyCombo) {            p->setBrush(cg, QPalette::ButtonText, pal->foreground);        } else {            p->setBrush(cg, w->foregroundRole(), pal->foreground);            p->setBrush(cg, QPalette::WindowText, pal->foreground);        }        p->setBrush(cg, QPalette::Text, pal->foreground);    }    if (pal->selectionBackground.style() != Qt::NoBrush)        p->setBrush(cg, QPalette::Highlight, pal->selectionBackground);    if (pal->selectionForeground.style() != Qt::NoBrush)        p->setBrush(cg, QPalette::HighlightedText, pal->selectionForeground);    if (pal->alternateBackground.style() != Qt::NoBrush)        p->setBrush(cg, QPalette::AlternateBase, pal->alternateBackground);}///////////////////////////////////////////////////////////////////////////////// Style rules#define WIDGET(x) (static_cast<QWidget *>(x.ptr))class QStyleSheetStyleSelector : public StyleSelector{public:    QStyleSheetStyleSelector() { }    bool nodeNameEquals(NodePtr node, const QString& name) const    {        if (WIDGET(node)->inherits(name.toLatin1()))            return true;#ifndef QT_NO_TOOLTIP        if (name == QLatin1String("QToolTip")            && QString::fromLatin1("QTipLabel")== QString::fromLatin1(WIDGET(node)->metaObject()->className()))            return true;#endif        const QMetaObject *metaObject = WIDGET(node)->metaObject();        do {            QString className = QString::fromUtf8(metaObject->className());            className.replace(QLatin1Char(':'), QLatin1Char('-'));            if (className == name)                return true;            metaObject = metaObject->superClass();        } while (metaObject != 0);        return false;    }    QString attribute(NodePtr node, const QString& name) const    {        QVariant value = WIDGET(node)->property(name.toLatin1());        if (!value.isValid()) {            if (name == QLatin1String("class")) {                QString className = QString::fromLatin1(WIDGET(node)->metaObject()->className());                className.replace(QLatin1Char(':'), QLatin1Char('-'));                return className;            } else if (name == QLatin1String("style")) {                QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(WIDGET(node)->style());                if (proxy)                    return QString::fromLatin1(proxy->baseStyle()->metaObject()->className());            }        }        return value.toString();    }    bool hasAttribute(NodePtr node, const QString& name) const    { return name == QLatin1String("class")             || name == QLatin1String("style")             || WIDGET(node)->metaObject()->indexOfProperty(name.toLatin1()) != -1             || WIDGET(node)->dynamicPropertyNames().contains(name.toLatin1()); }    bool hasAttributes(NodePtr) const    { return true; }    QStringList nodeIds(NodePtr node) const    { return QStringList(WIDGET(node)->objectName()); }    bool isNullNode(NodePtr node) const    { return node.ptr == 0; }    NodePtr parentNode(NodePtr node) const    { NodePtr n; n.ptr = WIDGET(node)->parentWidget(); return n; }    NodePtr previousSiblingNode(NodePtr) const    { NodePtr n; n.ptr = 0; return n; }    NodePtr duplicateNode(NodePtr node) const    { return node; }    void freeNode(NodePtr) const    { }};static bool unstylable(const QWidget *w){    if (w->windowType() == Qt::Desktop)        return true;    if (!w->styleSheet().isEmpty())        return false;#ifndef QT_NO_SCROLLAREA    if (const QAbstractScrollArea *sa = qobject_cast<const QAbstractScrollArea *>(w->parentWidget())) {        if (sa->viewport() == w)            return true;    }#endif#ifndef QT_NO_LINEEDIT    else if (qobject_cast<const QLineEdit *>(w)) {        if (0#ifndef QT_NO_COMBOBOX            || qobject_cast<const QComboBox *>(w->parentWidget())#endif#ifndef QT_NO_SPINBOX            || qobject_cast<const QAbstractSpinBox *>(w->parentWidget())#endif            )            return true;    }#endif#ifndef QT_NO_FRAME    // detect QComboBoxPrivateContainer    else if (qobject_cast<const QFrame *>(w)) {        if (0#ifndef QT_NO_COMBOBOX            || qobject_cast<const QComboBox *>(w->parentWidget())#endif           )            return true;    }#endif    return false;}QVector<QCss::StyleRule> QStyleSheetStyle::styleRules(const QWidget *w) const{    if (!w)        return QVector<StyleRule>();    if (styleRulesCache->contains(w))        return styleRulesCache->value(w);    QObject::connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(widgetDestroyed(QObject*)));    if (unstylable(w)) {        QVector<StyleRule> emptyRule;        styleRulesCache->insert(w, emptyRule);        return emptyRule;    }    QStyleSheetStyleSelector styleSelector;    StyleSheet defaultSs;    if (!styleSheetCache->contains(0)) {        Parser parser(QLatin1String(":/trolltech/stylesheet/default.qss"), true);        if (!parser.parse(&defaultSs))            qWarning("Could not parse default stylesheet");        defaultSs.origin = StyleSheetOrigin_UserAgent;        styleSheetCache->insert(0, defaultSs);    } else {        defaultSs = styleSheetCache->value(0);    }    styleSelector.styleSheets += defaultSs;    if (!qApp->styleSheet().isEmpty()) {        StyleSheet appSs;        if (!styleSheetCache->contains(qApp)) {            QString ss = qApp->styleSheet();            if (ss.startsWith(QLatin1String("file:///")))                ss.remove(0, 8);            Parser parser1(ss, qApp->styleSheet() != ss);            if (!parser1.parse(&appSs))                qWarning("Could not parse application stylesheet");            appSs.origin = StyleSheetOrigin_Inline;            appSs.depth = 1;            styleSheetCache->insert(qApp, appSs);        } else {            appSs = styleSheetCache->value(qApp);        }        styleSelector.styleSheets += appSs;    }    QVector<QCss::StyleSheet> widgetSs;    for (const QWidget *wid = w; wid; wid = wid->parentWidget()) {        StyleSheet ss;        if (!styleSheetCache->contains(wid)) {            Parser parser(wid->styleSheet());            if (!parser.parse(&ss) && wid == w) {                Parser parser2(QLatin1String("* {") + wid->styleSheet() + QLatin1String("}"));                if (!parser2.parse(&ss))                   qWarning("Could not parse stylesheet of widget %p", wid);            }            ss.origin = StyleSheetOrigin_Inline;            styleSheetCache->insert(wid, ss);        } else {            ss = styleSheetCache->value(wid);        }        widgetSs.prepend(ss);    }    for (int i = 0; i < widgetSs.count(); i++)        widgetSs[i].depth = i + 2;    styleSelector.styleSheets += widgetSs;    StyleSelector::NodePtr n;    n.ptr = (void *)w;    QVector<QCss::StyleRule> rules = styleSelector.styleRulesForNode(n);    if (w->property("_q_stylesheet_polished").toBool() == true)        styleRulesCache->insert(w, rules);    return rules;}/////////////////////////////////////////////////////////////////////////////////////////// Rendering rulesenum PseudoElement {    PseudoElement_None,    PseudoElement_DownArrow,    PseudoElement_UpArrow,    PseudoElement_LeftArrow,    PseudoElement_RightArrow,    PseudoElement_Indicator,    PseudoElement_ExclusiveIndicator,    PseudoElement_PushButtonMenuIndicator,    PseudoElement_ComboBoxDropDown,    PseudoElement_ComboBoxArrow,    PseudoElement_Item,    PseudoElement_SpinBoxUpButton,    PseudoElement_SpinBoxUpArrow,    PseudoElement_SpinBoxDownButton,    PseudoElement_SpinBoxDownArrow,    PseudoElement_GroupBoxTitle,    PseudoElement_GroupBoxIndicator,    PseudoElement_ToolButtonMenu,    PseudoElement_ToolButtonMenuArrow,    PseudoElement_ToolButtonDownArrow,    PseudoElement_ToolBoxTab,    PseudoElement_ScrollBarSlider,    PseudoElement_ScrollBarAddPage,    PseudoElement_ScrollBarSubPage,    PseudoElement_ScrollBarAddLine,    PseudoElement_ScrollBarSubLine,    PseudoElement_ScrollBarFirst,    PseudoElement_ScrollBarLast,    PseudoElement_ScrollBarUpArrow,    PseudoElement_ScrollBarDownArrow,    PseudoElement_ScrollBarLeftArrow,    PseudoElement_ScrollBarRightArrow,    PseudoElement_SplitterHandle,    PseudoElement_ToolBarHandle,    PseudoElement_ToolBarSeparator,    PseudoElement_MenuScroller,    PseudoElement_MenuTearoff,    PseudoElement_MenuCheckMark,    PseudoElement_MenuSeparator,    PseudoElement_MenuIcon,    PseudoElement_MenuRightArrow,    PseudoElement_TreeViewBranch,    PseudoElement_HeaderViewSection,    PseudoElement_HeaderViewUpArrow,    PseudoElement_HeaderViewDownArrow,    PseudoElement_ProgressBarChunk,    PseudoElement_TabBarTab,    PseudoElement_TabBarScroller,    PseudoElement_TabBarTear,    PseudoElement_SliderGroove,    PseudoElement_SliderHandle,    PseudoElement_SliderAddPage,    PseudoElement_SliderSubPage,    PseudoElement_SliderTickmark,    PseudoElement_TabWidgetPane,    PseudoElement_TabWidgetTabBar,    PseudoElement_TabWidgetLeftCorner,    PseudoElement_TabWidgetRightCorner,    NumPseudoElements};struct PseudoElementInfo {    QStyle::SubControl subControl;    const char *name;};static PseudoElementInfo knownPseudoElements[NumPseudoElements] = {    { QStyle::SC_None, "", },    { QStyle::SC_None, "down-arrow" },    { QStyle::SC_None, "up-arrow" },    { QStyle::SC_None, "left-arrow" },    { QStyle::SC_None, "right-arrow" },    { QStyle::SC_None, "indicator" },    { QStyle::SC_None, "indicator" },    { QStyle::SC_None, "menu-indicator" },    { QStyle::SC_ComboBoxArrow, "drop-down" },    { QStyle::SC_ComboBoxArrow, "down-arrow" },    { QStyle::SC_None, "item" },    { QStyle::SC_SpinBoxUp, "up-button" },    { QStyle::SC_SpinBoxUp, "up-arrow" },    { QStyle::SC_SpinBoxDown, "down-button" },    { QStyle::SC_SpinBoxDown, "down-arrow" },    { QStyle::SC_GroupBoxLabel, "title" },    { QStyle::SC_GroupBoxCheckBox, "indicator" },    { QStyle::SC_ToolButtonMenu, "menu-button" },    { QStyle::SC_ToolButtonMenu, "menu-arrow" },    { QStyle::SC_None, "menu-indicator" },    { QStyle::SC_None, "tab" },    { QStyle::SC_ScrollBarSlider, "handle" },    { QStyle::SC_ScrollBarAddPage, "add-page" },    { QStyle::SC_ScrollBarSubPage, "sub-page" },    { QStyle::SC_ScrollBarAddLine, "add-line" },    { QStyle::SC_ScrollBarSubLine, "sub-line" },    { QStyle::SC_ScrollBarFirst, "first" },    { QStyle::SC_ScrollBarLast, "last" },    { QStyle::SC_ScrollBarSubLine, "up-arrow" },    { QStyle::SC_ScrollBarAddLine, "down-arrow" },    { QStyle::SC_ScrollBarSubLine, "left-arrow" },    { QStyle::SC_ScrollBarAddLine, "right-arrow" },    { QStyle::SC_None, "handle" },    { QStyle::SC_None, "handle" },    { QStyle::SC_None, "separator" },    { QStyle::SC_None, "scroller" },    { QStyle::SC_None, "tearoff" },    { QStyle::SC_None, "indicator" },    { QStyle::SC_None, "separator" },

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -