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

📄 qstylesheetstyle.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include <qglobal.h>#ifndef QT_NO_STYLE_STYLESHEET#include "qstylesheetstyle_p.h"#include "private/qcssutil_p.h"#include <qdebug.h>#include <qapplication.h>#include <qmenu.h>#include <qmenubar.h>#include <qpainter.h>#include <qstyleoption.h>#include <qlineedit.h>#include <qwindowsstyle.h>#include <qcombobox.h>#include <qwindowsstyle.h>#include <qplastiquestyle.h>#include "private/qcssparser_p.h"#include "private/qmath_p.h"#include <qabstractscrollarea.h>#include "private/qabstractscrollarea_p.h"#include <qtooltip.h>#include <qshareddata.h>#include <qradiobutton.h>#include <qtoolbutton.h>#include <qscrollbar.h>#include <qstring.h>#include <qfile.h>#include <qcheckbox.h>#include <qstatusbar.h>#include <qheaderview.h>#include <qprogressbar.h>#include <private/qwindowsstyle_p.h>#include <qtabbar.h>#include <QMetaProperty>#include <qmainwindow.h>#include <limits.h>using namespace QCss;class QStyleSheetStylePrivate : public QWindowsStylePrivate{    Q_DECLARE_PUBLIC(QStyleSheetStyle)public:    QStyleSheetStylePrivate() { }};static QHash<const QWidget *, QVector<StyleRule> > *styleRulesCache = 0;typedef QHash<QString, QHash<int, QRenderRule> > QRenderRules;static QHash<const QWidget *, QRenderRules> *renderRulesCache = 0;static QHash<const QWidget *, int> *customPaletteWidgets = 0; // widgets whose palette we tamperedstatic QHash<const void *, StyleSheet> *styleSheetCache = 0; // parsed style sheetsstatic QSet<const QWidget *> *autoFillDisabledWidgets = 0;#define ceil(x) ((int)(x) + ((x) > 0 && (x) != (int)(x)))struct QStyleSheetBorderImageData : public QSharedData{    QStyleSheetBorderImageData()    {        for (int i = 0; i < 4; i++)            cuts[i] = -1;    }    QPixmap topEdge, bottomEdge, leftEdge, rightEdge, middle;    QRect topEdgeRect, bottomEdgeRect, leftEdgeRect, rightEdgeRect, middleRect;    QRect topLeftCorner, topRightCorner, bottomRightCorner, bottomLeftCorner;    int cuts[4];    QPixmap pixmap;    QImage image;    QCss::TileMode horizStretch, vertStretch;    void cutBorderImage();};struct QStyleSheetBackgroundData : public QSharedData{    QStyleSheetBackgroundData(const QBrush& b, const QPixmap& p, QCss::Repeat r,                              Qt::Alignment a, QCss::Origin o, Attachment t, QCss::Origin c)        : brush(b), pixmap(p), repeat(r), position(a), origin(o), attachment(t), clip(c) { }    bool isTransparent() const {        if (brush.style() != Qt::NoBrush)            return !brush.isOpaque();        return pixmap.isNull() ? false : pixmap.hasAlpha();    }    QBrush brush;    QPixmap pixmap;    QCss::Repeat repeat;    Qt::Alignment position;    QCss::Origin origin;    QCss::Attachment attachment;    QCss::Origin clip;};struct QStyleSheetBorderData : public QSharedData{    QStyleSheetBorderData() : bi(0)    {        for (int i = 0; i < 4; i++) {            borders[i] = 0;            styles[i] = QCss::BorderStyle_None;        }    }    QStyleSheetBorderData(int *b, QBrush *c, QCss::BorderStyle *s, QSize *r) : bi(0)    {        for (int i = 0; i < 4; i++) {            borders[i] = b[i];            styles[i] = s[i];            colors[i] = c[i];            radii[i] = r[i];        }    }    int borders[4];    QBrush colors[4];    QCss::BorderStyle styles[4];    QSize radii[4]; // topleft, topright, bottomleft, bottomright    const QStyleSheetBorderImageData *borderImage() const    { return bi; }    bool hasBorderImage() const { return bi!=0; }    QSharedDataPointer<QStyleSheetBorderImageData> bi;};struct QStyleSheetBoxData : public QSharedData{    QStyleSheetBoxData(int *m, int *p, int s) : spacing(s)    {        for (int i = 0; i < 4; i++) {            margins[i] = m[i];            paddings[i] = p[i];        }    }    int margins[4];    int paddings[4];    int spacing;};struct QStyleSheetPaletteData : public QSharedData{    QStyleSheetPaletteData(const QBrush &fg, const QBrush &sfg, const QBrush &sbg,                           const QBrush &abg)        : foreground(fg), selectionForeground(sfg), selectionBackground(sbg),          alternateBackground(abg) { }    QBrush foreground;    QBrush selectionForeground;    QBrush selectionBackground;    QBrush alternateBackground;};struct QStyleSheetGeometryData : public QSharedData{    QStyleSheetGeometryData(int w, int h, int minw, int minh, int maxw, int maxh)        : minWidth(minw), minHeight(minh), width(w), height(h), maxWidth(maxw), maxHeight(maxh) { }    int minWidth, minHeight, width, height, maxWidth, maxHeight;};struct QStyleSheetPositionData : public QSharedData{    QStyleSheetPositionData(int l, int t, int r, int b, Origin o, Qt::Alignment p, QCss::PositionMode m, Qt::Alignment a = 0)        : left(l), top(t), bottom(b), right(r), origin(o), position(p), mode(m), textAlignment(a) { }    int left, top, bottom, right;    Origin origin;    Qt::Alignment position;    QCss::PositionMode mode;    Qt::Alignment textAlignment;};struct QStyleSheetImageData : public QSharedData{    QStyleSheetImageData(const QIcon &i, Qt::Alignment a, const QSize &sz)        : icon(i), alignment(a), size(sz) { }    QIcon icon;    Qt::Alignment alignment;    QSize size;};class QRenderRule{public:    QRenderRule() : features(0), hasFont(false), pal(0), b(0), bg(0), bd(0), geo(0), p(0), img(0), clipset(0) { }    QRenderRule(const QVector<QCss::Declaration> &, const QWidget *);    ~QRenderRule() { }    QRect borderRect(const QRect &r) const;    QRect paddingRect(const QRect &r) const;    QRect contentsRect(const QRect &r) const;    enum { Margin = 1, Border = 2, Padding = 4, All=Margin|Border|Padding };    QRect boxRect(const QRect &r, int flags = All) const;    QSize boxSize(const QSize &s, int flags = All) const;    QRect originRect(const QRect &rect, Origin origin) const;    bool paintsOver(Edge e1, Edge e2);    QPainterPath borderClip(QRect rect);    void drawBorder(QPainter *, const QRect&);    void drawBorderImage(QPainter *, const QRect&);    void drawBackground(QPainter *, const QRect&, const QPoint& = QPoint(0, 0));    void drawBackgroundImage(QPainter *, const QRect&, QPoint = QPoint(0, 0));    void drawFrame(QPainter *, const QRect&);    void drawImage(QPainter *p, const QRect &rect);    void drawRule(QPainter *, const QRect&);    void configurePalette(QPalette *, QPalette::ColorGroup, const QWidget *, bool);    void configurePalette(QPalette *p, QPalette::ColorRole fr, QPalette::ColorRole br);    void getRadii(const QRect &br, QSize *tlr, QSize *trr, QSize *blr, QSize *brr) const;    const QStyleSheetPaletteData *palette() const { return pal; }    const QStyleSheetBoxData *box() const { return b; }    const QStyleSheetBackgroundData *background() const { return bg; }    const QStyleSheetBorderData *border() const { return bd; }    const QStyleSheetGeometryData *geometry() const { return geo; }    const QStyleSheetPositionData *position() const { return p; }    bool hasPalette() const { return pal != 0; }    bool hasBackground() const { return bg != 0; }    bool hasGradientBackground() const { return bg && bg->brush.style() >= Qt::LinearGradientPattern                                                   && bg->brush.style() <= Qt::ConicalGradientPattern; }    bool hasNativeBorder() const {        return bd == 0               || (!bd->hasBorderImage() && bd->styles[0] == BorderStyle_Native);    }    bool nativeBorder() const {        return (bd == 0                || (!bd->hasBorderImage() && bd->styles[0] == BorderStyle_Native));    }    bool baseStyleCanDraw() const {        if (!hasBackground() || background()->brush.style() == Qt::NoBrush)            return true;        if (hasGradientBackground())            return features & StyleFeature_BackgroundGradient;        return features & StyleFeature_BackgroundColor;    }    bool hasBox() const { return b != 0; }    bool hasBorder() const { return bd != 0; }    bool hasPosition() const { return p != 0; }    bool hasGeometry() const { return geo != 0; }    bool hasDrawable() const { return hasBorder() || hasBackground() || hasImage(); }    bool hasImage() const { return img != 0; }    QSize minimumContentsSize() const    { return geo ? QSize(geo->minWidth, geo->minHeight) : QSize(0, 0); }    QSize minimumSize() const    { return boxSize(minimumContentsSize()); }    QSize contentsSize() const    { return geo ? QSize(geo->width, geo->height)                 : ((img && img->size.isValid()) ? img->size : QSize()); }    QSize contentsSize(const QSize &sz) const    {        QSize csz = contentsSize();        if (csz.width() == -1) csz.setWidth(sz.width());        if (csz.height() == -1) csz.setHeight(sz.height());        return csz;    }    bool hasContentsSize() const    { return (geo && (geo->width != -1 || geo->height != -1)) || (img && img->size.isValid()); }    QSize size() const { return boxSize(contentsSize()); }    QSize size(const QSize &sz) const { return boxSize(contentsSize(sz)); }    int features;    QBrush defaultBackground;    QFont font;    bool hasFont;    QHash<QString, int> styleHints;    bool hasStyleHint(const QString& sh) const { return styleHints.contains(sh); }    int styleHint(const QString& sh) const { return styleHints.value(sh); }    void fixupBorder(int);    QSharedDataPointer<QStyleSheetPaletteData> pal;    QSharedDataPointer<QStyleSheetBoxData> b;    QSharedDataPointer<QStyleSheetBackgroundData> bg;    QSharedDataPointer<QStyleSheetBorderData> bd;    QSharedDataPointer<QStyleSheetGeometryData> geo;    QSharedDataPointer<QStyleSheetPositionData> p;    QSharedDataPointer<QStyleSheetImageData> img;    // Shouldn't be here    void setClip(QPainter *p, const QRect &rect);    void unsetClip(QPainter *);    int clipset;    QPainterPath clipPath;};///////////////////////////////////////////////////////////////////////////////////////////static const char *knownStyleHints[] = {    "activate-on-singleclick",    "alignment",    "button-layout",    "combobox-list-mousetracking",    "combobox-popup",    "dither-disable-text",    "etch-disabled-text",    "gridline-color",

⌨️ 快捷键说明

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