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

📄 arthurstyle.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved.**** This file is part of the demonstration applications 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 "arthurstyle.h"#include "arthurwidgets.h"#include <QLayout>#include <QPainter>#include <QPainterPath>#include <QPixmapCache>#include <QRadioButton>#include <QString>#include <QStyleOption>#include <QtDebug>QPixmap cached(const QString &img){    if (QPixmap *p = QPixmapCache::find(img))        return *p;    QPixmap pm;    pm = QPixmap::fromImage(QImage(img), Qt::OrderedDither | Qt::OrderedAlphaDither);    if (pm.isNull())        return QPixmap();    QPixmapCache::insert(img, pm);    return pm;}ArthurStyle::ArthurStyle()    : QWindowsStyle(){    Q_INIT_RESOURCE(shared);}void ArthurStyle::drawHoverRect(QPainter *painter, const QRect &r) const{    double h = r.height();    double h2 = r.height() / 2.0;    QPainterPath path;    path.addRect(r.x() + h2, r.y() + 0, r.width() - h2 * 2, r.height());    path.addEllipse(r.x(), r.y(), h, h);    path.addEllipse(r.x() + r.width() - h, r.y(), h, h);    path.setFillRule(Qt::WindingFill);    painter->setPen(Qt::NoPen);    painter->setBrush(QColor(191, 215, 191));    painter->setRenderHint(QPainter::Antialiasing);    painter->drawPath(path);}void ArthurStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,                                QPainter *painter, const QWidget *widget) const{    Q_ASSERT(option);    switch (element) {    case PE_FrameFocusRect:        break;    case PE_IndicatorRadioButton:        if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {            bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver);            painter->save();            QPixmap radio;            if (hover)                drawHoverRect(painter, widget->rect());            if (button->state & State_Sunken)                radio = cached(":res/images/radiobutton-on.png");            else if (button->state & State_On)                radio = cached(":res/images/radiobutton_on.png");            else                radio = cached(":res/images/radiobutton_off.png");            painter->drawPixmap(button->rect.topLeft(), radio);            painter->restore();        }        break;    case PE_PanelButtonCommand:        if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {            bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver);            painter->save();            const QPushButton *pushButton = qobject_cast<const QPushButton *>(widget);            Q_ASSERT(pushButton);            QWidget *parent = pushButton->parentWidget();            if (parent && qobject_cast<QGroupBox *>(parent)) {                QLinearGradient lg(0, 0, 0, parent->height());                lg.setColorAt(0, QColor(224,224,224));                lg.setColorAt(1, QColor(255,255,255));                painter->setPen(Qt::NoPen);                painter->setBrush(lg);                painter->setBrushOrigin(-widget->mapToParent(QPoint(0,0)));                painter->drawRect(button->rect);                painter->setBrushOrigin(0,0);            }            bool down = (button->state & State_Sunken) || (button->state & State_On);            QPixmap left, right, mid;            if (down) {                left = cached(":res/images/button_pressed_cap_left.png");                right = cached(":res/images/button_pressed_cap_right.png");                mid = cached(":res/images/button_pressed_stretch.png");            } else {                left = cached(":res/images/button_normal_cap_left.png");                right = cached(":res/images/button_normal_cap_right.png");                mid = cached(":res/images/button_normal_stretch.png");            }            painter->drawPixmap(button->rect.topLeft(), left);            painter->drawTiledPixmap(QRect(button->rect.x() + left.width(),                                           button->rect.y(),                                           button->rect.width() - left.width() - right.width(),                                           left.height()),                                     mid);            painter->drawPixmap(button->rect.x() + button->rect.width() - right.width(),                                button->rect.y(),                                right);            if (hover)                painter->fillRect(widget->rect().adjusted(3,5,-3,-5), QColor(31,127,31,63));            painter->restore();        }        break;    case PE_FrameGroupBox:        if (const QStyleOptionFrameV2 *group                = qstyleoption_cast<const QStyleOptionFrameV2 *>(option)) {            const QRect &r = group->rect;            painter->save();            int radius = 14;            int radius2 = radius*2;            QPainterPath clipPath;            clipPath.moveTo(radius, 0);            clipPath.arcTo(r.right() - radius2, 0, radius2, radius2, 90, -90);            clipPath.arcTo(r.right() - radius2, r.bottom() - radius2, radius2, radius2, 0, -90);            clipPath.arcTo(r.left(), r.bottom() - radius2, radius2, radius2, 270, -90);            clipPath.arcTo(r.left(), r.top(), radius2, radius2, 180, -90);            painter->setClipPath(clipPath);            QPixmap titleStretch = cached(":res/images/title_stretch.png");            QPixmap topLeft = cached(":res/images/groupframe_topleft.png");            QPixmap topRight = cached(":res/images/groupframe_topright.png");            QPixmap bottomLeft = cached(":res/images/groupframe_bottom_left.png");            QPixmap bottomRight = cached(":res/images/groupframe_bottom_right.png");            QPixmap leftStretch = cached(":res/images/groupframe_left_stretch.png");            QPixmap topStretch = cached(":res/images/groupframe_top_stretch.png");            QPixmap rightStretch = cached(":res/images/groupframe_right_stretch.png");            QPixmap bottomStretch = cached(":res/images/groupframe_bottom_stretch.png");            QLinearGradient lg(0, 0, 0, r.height());            lg.setColorAt(0, QColor(224,224,224));            lg.setColorAt(1, QColor(255,255,255));            painter->setPen(Qt::NoPen);            painter->setBrush(lg);            painter->drawRect(r.adjusted(0, titleStretch.height()/2, 0, 0));            painter->setClipping(false);            int topFrameOffset = titleStretch.height()/2 - 2;            painter->drawPixmap(r.topLeft() + QPoint(0, topFrameOffset), topLeft);            painter->drawPixmap(r.topRight() - QPoint(topRight.width()-1, 0)                                + QPoint(0, topFrameOffset), topRight);            painter->drawPixmap(r.bottomLeft() - QPoint(0, bottomLeft.height()-1), bottomLeft);            painter->drawPixmap(r.bottomRight() - QPoint(bottomRight.width()-1,                                bottomRight.height()-1), bottomRight);            QRect left = r;            left.setY(r.y() + topLeft.height() + topFrameOffset);            left.setWidth(leftStretch.width());            left.setHeight(r.height() - topLeft.height() - bottomLeft.height() - topFrameOffset);            painter->drawTiledPixmap(left, leftStretch);            QRect top = r;            top.setX(r.x() + topLeft.width());            top.setY(r.y() + topFrameOffset);            top.setWidth(r.width() - topLeft.width() - topRight.width());            top.setHeight(topLeft.height());            painter->drawTiledPixmap(top, topStretch);            QRect right = r;            right.setX(r.right() - rightStretch.width()+1);            right.setY(r.y() + topRight.height() + topFrameOffset);            right.setWidth(rightStretch.width());            right.setHeight(r.height() - topRight.height()                            - bottomRight.height() - topFrameOffset);            painter->drawTiledPixmap(right, rightStretch);            QRect bottom = r;            bottom.setX(r.x() + bottomLeft.width());            bottom.setY(r.bottom() - bottomStretch.height()+1);

⌨️ 快捷键说明

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