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

📄 qcommonstyle.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 "qcommonstyle.h"#include "qcommonstyle_p.h"#include <qapplication.h>#include <qbitmap.h>#include <qcache.h>#include <qdockwidget.h>#include <qdrawutil.h>#include <qdialogbuttonbox.h>#include <qgroupbox.h>#include <qmenu.h>#include <qpainter.h>#include <qpaintengine.h>#include <qpainterpath.h>#include <qslider.h>#include <qstyleoption.h>#include <qtabbar.h>#include <qtoolbar.h>#include <qtoolbutton.h>#include <qrubberband.h>#include <private/qcommonstylepixmaps_p.h>#include <private/qmath_p.h>#include <qdebug.h>#include <qtextformat.h>#include <qwizard.h>#include <limits.h>/*!    \class QCommonStyle    \brief The QCommonStyle class encapsulates the common Look and Feel of a GUI.    \ingroup appearance    This abstract class implements some of the widget's look and feel    that is common to all GUI styles provided and shipped as part of    Qt.    Since QCommonStyle inherits QStyle, all of its functions are fully documented    in the QStyle documentation.    \omit    , although the    extra functions that QCommonStyle provides, e.g.    drawComplexControl(), drawControl(), drawPrimitive(),    hitTestComplexControl(), subControlRect(), sizeFromContents(), and    subElementRect() are documented here.    \endomit    \sa QStyle, QMotifStyle, QWindowsStyle*//*!    Constructs a QCommonStyle.*/QCommonStyle::QCommonStyle()    : QStyle(*new QCommonStylePrivate){ }/*! \internal*/QCommonStyle::QCommonStyle(QCommonStylePrivate &dd)    : QStyle(dd){ }/*!    \overload    Destroys the style*/QCommonStyle::~QCommonStyle(){ }/*!    \reimp*/void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,                                 const QWidget *widget) const{    switch (pe) {    case PE_FrameButtonBevel:    case PE_FrameButtonTool:        qDrawShadeRect(p, opt->rect, opt->palette,                       opt->state & (State_Sunken | State_On), 1, 0);        break;    case PE_PanelButtonCommand:    case PE_PanelButtonBevel:    case PE_PanelButtonTool:    case PE_IndicatorButtonDropDown:        qDrawShadePanel(p, opt->rect, opt->palette,                        opt->state & (State_Sunken | State_On), 1,                        &opt->palette.brush(QPalette::Button));        break;    case PE_IndicatorViewItemCheck:        drawPrimitive(PE_IndicatorCheckBox, opt, p, widget);        break;    case PE_IndicatorCheckBox:        if (opt->state & State_NoChange) {            p->setPen(opt->palette.foreground().color());            p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));            p->drawRect(opt->rect);            p->drawLine(opt->rect.topLeft(), opt->rect.bottomRight());        } else {            qDrawShadePanel(p, opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height(),                            opt->palette, opt->state & (State_Sunken | State_On), 1,                            &opt->palette.brush(QPalette::Button));        }        break;    case PE_IndicatorRadioButton: {        QRect ir = opt->rect;        p->setPen(opt->palette.dark().color());        p->drawArc(opt->rect, 0, 5760);        if (opt->state & (State_Sunken | State_On)) {            ir.adjust(2, 2, -2, -2);            p->setBrush(opt->palette.foreground());            p->drawEllipse(ir);        }        break; }    case PE_FrameFocusRect:        if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {            QColor bg = fropt->backgroundColor;            QPen oldPen = p->pen();            if (bg.isValid()) {                int h, s, v;                bg.getHsv(&h, &s, &v);                if (v >= 128)                    p->setPen(Qt::black);                else                    p->setPen(Qt::white);            } else {                p->setPen(opt->palette.foreground().color());            }            QRect focusRect = opt->rect.adjusted(1, 1, -1, -1);            p->drawRect(focusRect.adjusted(0, 0, -1, -1)); //draw pen inclusive            p->setPen(oldPen);        }        break;    case PE_IndicatorMenuCheckMark: {        const int markW = opt->rect.width() > 7 ? 7 : opt->rect.width();        const int markH = markW;        int posX = opt->rect.x() + (opt->rect.width() - markW)/2 + 1;        int posY = opt->rect.y() + (opt->rect.height() - markH)/2;        QVector<QLineF> a;        a.reserve(markH);        int i, xx, yy;        xx = posX;        yy = 3 + posY;        for (i = 0; i < markW/2; ++i) {            a << QLineF(xx, yy, xx, yy + 2);            ++xx;            ++yy;        }        yy -= 2;        for (; i < markH; ++i) {            a << QLineF(xx, yy, xx, yy + 2);            ++xx;            --yy;        }        if (!(opt->state & State_Enabled) && !(opt->state & State_On)) {            int pnt;            p->setPen(opt->palette.highlightedText().color());            QPoint offset(1, 1);            for (pnt = 0; pnt < a.size(); ++pnt)                a[pnt].translate(offset.x(), offset.y());            p->drawLines(a);            for (pnt = 0; pnt < a.size(); ++pnt)                a[pnt].translate(offset.x(), offset.y());        }        p->setPen(opt->palette.text().color());        p->drawLines(a);        break; }    case PE_Frame:    case PE_FrameMenu:        if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {            if (pe == PE_FrameMenu || (frame->state & State_Sunken) || (frame->state & State_Raised)) {                qDrawShadePanel(p, frame->rect, frame->palette, frame->state & State_Sunken,                                frame->lineWidth);            } else {                qDrawPlainRect(p, frame->rect, frame->palette.foreground().color(), frame->lineWidth);            }        }        break;#ifndef QT_NO_TOOLBAR    case PE_PanelMenuBar:        if (widget && qobject_cast<QToolBar *>(widget->parentWidget()))            break;        if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)){            qDrawShadePanel(p, frame->rect, frame->palette, false, frame->lineWidth,                            &frame->palette.brush(QPalette::Button));        }        else if (const QStyleOptionToolBar *frame = qstyleoption_cast<const QStyleOptionToolBar *>(opt)){            qDrawShadePanel(p, frame->rect, frame->palette, false, frame->lineWidth,                            &frame->palette.brush(QPalette::Button));        }        break;   case PE_PanelToolBar:       break;#endif // QT_NO_TOOLBAR#ifndef QT_NO_PROGRESSBAR    case PE_IndicatorProgressChunk:        {            bool vertical = false;            if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt))                vertical = (pb2->orientation == Qt::Vertical);            if (!vertical) {                p->fillRect(opt->rect.x(), opt->rect.y() + 3, opt->rect.width() -2, opt->rect.height() - 6,                            opt->palette.brush(QPalette::Highlight));            } else {                p->fillRect(opt->rect.x() + 2, opt->rect.y(), opt->rect.width() -6, opt->rect.height() - 2,                            opt->palette.brush(QPalette::Highlight));            }        }        break;#endif // QT_NO_PROGRESSBAR#ifdef QT3_SUPPORT    case PE_Q3CheckListController:#ifndef QT_NO_IMAGEFORMAT_XPM        p->drawPixmap(opt->rect.topLeft(), QPixmap(check_list_controller_xpm));#endif        break;    case PE_Q3CheckListExclusiveIndicator:        if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {            if (lv->items.isEmpty())                return;            int x = lv->rect.x(),                y = lv->rect.y();#define INTARRLEN(x) sizeof(x)/(sizeof(int)*2)            static const int pts1[] = {                // dark lines                1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };            static const int pts2[] = {                // black lines                2,8, 1,7, 1,4, 2,3, 2,2, 3,2, 4,1, 7,1, 8,2, 9,2 };            static const int pts3[] = {                // background lines                2,9, 3,9, 4,10, 7,10, 8,9, 9,9, 9,8, 10,7, 10,4, 9,3 };            static const int pts4[] = {                // white lines                2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,                11,4, 10,3, 10,2 };            // static const int pts5[] = {                // inner fill            //    4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };            //QPolygon a;            if (lv->state & State_Enabled)                p->setPen(lv->palette.text().color());            else                p->setPen(QPen(lv->viewportPalette.color(QPalette::Disabled, QPalette::Text)));            QPolygon a(INTARRLEN(pts1), pts1);            a.translate(x, y);            //p->setPen(pal.dark());            p->drawPolyline(a);            a.setPoints(INTARRLEN(pts2), pts2);            a.translate(x, y);            p->drawPolyline(a);            a.setPoints(INTARRLEN(pts3), pts3);            a.translate(x, y);            //                p->setPen(black);            p->drawPolyline(a);            a.setPoints(INTARRLEN(pts4), pts4);            a.translate(x, y);            //                        p->setPen(blue);            p->drawPolyline(a);            //                a.setPoints(INTARRLEN(pts5), pts5);            //                a.translate(x, y);            //        QColor fillColor = isDown() ? g.background() : g.base();            //        p->setPen(fillColor);            //        p->setBrush(fillColor);

⌨️ 快捷键说明

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