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

📄 qwindowsstyle.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                                  const QWidget *w) const{    // Used to restore across fallthrough cases. Currently only used in PE_IndicatorCheckBox    bool doRestore = false;    switch (pe) {#ifndef QT_NO_TOOLBAR  case PE_IndicatorToolBarSeparator:        {            QRect rect = opt->rect;            const int margin = 2;            QPen oldPen = p->pen();            if(opt->state & State_Horizontal){                const int offset = rect.width()/2;                p->setPen(QPen(opt->palette.dark().color()));                p->drawLine(rect.bottomLeft().x() + offset,                            rect.bottomLeft().y() - margin,                            rect.topLeft().x() + offset,                            rect.topLeft().y() + margin);                p->setPen(QPen(opt->palette.light().color()));                p->drawLine(rect.bottomLeft().x() + offset + 1,                            rect.bottomLeft().y() - margin,                            rect.topLeft().x() + offset + 1,                            rect.topLeft().y() + margin);            }            else{ //Draw vertical separator                const int offset = rect.height()/2;                p->setPen(QPen(opt->palette.dark().color()));                p->drawLine(rect.topLeft().x() + margin ,                            rect.topLeft().y() + offset,                            rect.topRight().x() - margin,                            rect.topRight().y() + offset);                p->setPen(QPen(opt->palette.light().color()));                p->drawLine(rect.topLeft().x() + margin ,                            rect.topLeft().y() + offset + 1,                            rect.topRight().x() - margin,                            rect.topRight().y() + offset + 1);            }            p->setPen(oldPen);        }        break;    case PE_IndicatorToolBarHandle:        p->save();        p->translate(opt->rect.x(), opt->rect.y());        if (opt->state & State_Horizontal) {            int x = opt->rect.width() / 2 - 4;            if (QApplication::layoutDirection() == Qt::RightToLeft)                x -= 2;            if (opt->rect.height() > 4) {                qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,                                opt->palette, false, 1, 0);                qDrawShadePanel(p, x + 3, 2, 3, opt->rect.height() - 4,                                opt->palette, false, 1, 0);            }        } else {            if (opt->rect.width() > 4) {                int y = opt->rect.height() / 2 - 4;                qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3,                                opt->palette, false, 1, 0);                qDrawShadePanel(p, 2, y + 3, opt->rect.width() - 4, 3,                                opt->palette, false, 1, 0);            }        }        p->restore();        break;#endif // QT_NO_TOOLBAR    case PE_FrameButtonTool:    case PE_PanelButtonTool: {        QPen oldPen = p->pen();#ifndef QT_NO_DOCKWIDGET        if (w && w->inherits("QDockWidgetTitleButton")) {           if (const QWidget *dw = w->parentWidget())                if (dw->isWindow()){                    qDrawWinButton(p, opt->rect.adjusted(1, 1, 0, 0), opt->palette, opt->state & (State_Sunken | State_On),                           &opt->palette.button());                    return;                }        }#endif // QT_NO_DOCKWIDGET        QBrush fill;        bool stippled;        bool panel = (pe == PE_PanelButtonTool);        if ((!(opt->state & State_Sunken ))            && (!(opt->state & State_Enabled)                || !(opt->state & State_MouseOver && opt->state & State_AutoRaise))            && (opt->state & State_On) && use2000style) {            fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);            stippled = true;        } else {            fill = opt->palette.brush(QPalette::Button);            stippled = false;        }        if (opt->state & (State_Raised | State_Sunken | State_On)) {            if (opt->state & State_AutoRaise) {                if(opt->state & (State_Enabled | State_Sunken | State_On)){                    if (panel)                        qDrawShadePanel(p, opt->rect, opt->palette,                                        opt->state & (State_Sunken | State_On), 1, &fill);                    else                        qDrawShadeRect(p, opt->rect, opt->palette,                                       opt->state & (State_Sunken | State_On), 1);                }                if (stippled) {                    p->setPen(opt->palette.button().color());                    p->drawRect(opt->rect.adjusted(1,1,-2,-2));                }            } else {                qDrawWinButton(p, opt->rect, opt->palette,                               opt->state & (State_Sunken | State_On), panel ? &fill : 0);            }        } else {            p->fillRect(opt->rect, fill);        }        p->setPen(oldPen);        break; }    case PE_PanelButtonCommand:        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {            QBrush fill;            State flags = opt->state;            QPalette pal = opt->palette;            QRect r = opt->rect;            if (! (flags & State_Sunken) && (flags & State_On))                fill = QBrush(pal.light().color(), Qt::Dense4Pattern);            else                fill = pal.brush(QPalette::Button);            if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) {                p->setPen(pal.dark().color());                p->setBrush(fill);                p->drawRect(r.adjusted(0, 0, -1, -1));            } else if (flags & (State_Raised | State_Sunken | State_On | State_Sunken)) {                qDrawWinButton(p, r, pal, flags & (State_Sunken | State_On),                               &fill);            } else {                p->fillRect(r, fill);            }        }        break;    case PE_FrameDefaultButton: {        QPen oldPen = p->pen();        p->setPen(opt->palette.shadow().color());        QRect rect = opt->rect;        rect.adjust(0, 0, -1, -1);        p->drawRect(rect);        p->setPen(oldPen);        break;    }    case PE_IndicatorArrowUp:    case PE_IndicatorArrowDown:    case PE_IndicatorArrowRight:    case PE_IndicatorArrowLeft:        {            if (opt->rect.width() <= 0 || opt->rect.height() <= 0)                break;            QRect r = opt->rect;            int size = qMin(r.height(), r.width());            QPixmap pixmap;            QString pixmapName;            pixmapName.sprintf("%s-%s-%d-%d-%d-%lld",                               "$qt_ia", metaObject()->className(),                               uint(opt->state), pe,                               size, opt->palette.cacheKey());            if (!QPixmapCache::find(pixmapName, pixmap)) {                int border = size/5;                size = 2*(size/2);                QImage image(size, size, QImage::Format_ARGB32);                image.fill(Qt::transparent);                QPainter imagePainter(&image);                QPolygon a;                switch (pe) {                    case PE_IndicatorArrowUp:                        a.setPoints(3, border, size/2,  size/2, border,  size - border, size/2);                        break;                    case PE_IndicatorArrowDown:                        a.setPoints(3, border, size/2,  size/2, size - border,  size - border, size/2);                        break;                    case PE_IndicatorArrowRight:                        a.setPoints(3, size - border, size/2,  size/2, border,  size/2, size - border);                        break;                    case PE_IndicatorArrowLeft:                        a.setPoints(3, border, size/2,  size/2, border,  size/2, size - border);                        break;                    default:                        break;                }                int bsx = 0;                int bsy = 0;                if (opt->state & State_Sunken) {                    bsx = pixelMetric(PM_ButtonShiftHorizontal);                    bsy = pixelMetric(PM_ButtonShiftVertical);                }                QRect bounds = a.boundingRect();                int sx = size / 2 - bounds.center().x() - 1;                int sy = size / 2 - bounds.center().y() - 1;                imagePainter.translate(sx + bsx, sy + bsy);                imagePainter.setPen(opt->palette.buttonText().color());                imagePainter.setBrush(opt->palette.buttonText());                if (!(opt->state & State_Enabled)) {                    imagePainter.translate(1, 1);                    imagePainter.setBrush(opt->palette.light().color());                    imagePainter.setPen(opt->palette.light().color());                    imagePainter.drawPolygon(a);                    imagePainter.translate(-1, -1);                    imagePainter.setBrush(opt->palette.mid().color());                    imagePainter.setPen(opt->palette.mid().color());                }                imagePainter.drawPolygon(a);                imagePainter.end();                pixmap = QPixmap::fromImage(image);                QPixmapCache::insert(pixmapName, pixmap);            }            int xOffset = r.x() + (r.width() - size)/2;            int yOffset = r.y() + (r.height() - size)/2;            p->drawPixmap(xOffset, yOffset, pixmap);        }        break;    case PE_IndicatorCheckBox: {        QBrush fill;        if (opt->state & State_NoChange)            fill = QBrush(opt->palette.base().color(), Qt::Dense4Pattern);        else if (opt->state & State_Sunken)            fill = opt->palette.button();        else if (opt->state & State_Enabled)            fill = opt->palette.base();        else            fill = opt->palette.background();        p->save();        doRestore = true;        qDrawWinPanel(p, opt->rect, opt->palette, true, &fill);        if (opt->state & State_NoChange)            p->setPen(opt->palette.dark().color());        else            p->setPen(opt->palette.text().color());        } // Fall through!    case PE_IndicatorViewItemCheck:    case PE_Q3CheckListIndicator:        if (!doRestore) {            p->save();            doRestore = true;        }        if (pe == PE_Q3CheckListIndicator || pe == PE_IndicatorViewItemCheck) {            const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt);            p->setPen(itemViewOpt                      && itemViewOpt->showDecorationSelected                      && opt->state & State_Selected                        ? opt->palette.highlightedText().color()                        : opt->palette.text().color());            if (opt->state & State_NoChange)                p->setBrush(opt->palette.brush(QPalette::Button));            p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, 11, 11);        }        if (!(opt->state & State_Off)) {            QLineF lines[7];            int i, xx, yy;            xx = opt->rect.x() + 3;            yy = opt->rect.y() + 5;            for (i = 0; i < 3; ++i) {                lines[i] = QLineF(xx, yy, xx, yy + 2);                ++xx;                ++yy;            }            yy -= 2;            for (i = 3; i < 7; ++i) {                lines[i] = QLineF(xx, yy, xx, yy + 2);                ++xx;                --yy;            }            p->drawLines(lines, 7);        }        if (doRestore)            p->restore();        break;    case PE_FrameFocusRect:        if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {            //### check for d->alt_down            if (!(fropt->state & State_KeyboardFocusChange) && !styleHint(SH_UnderlineShortcut, opt))                return;            QRect r = opt->rect;            p->save();            p->setBackgroundMode(Qt::TransparentMode);            QColor bg_col = fropt->backgroundColor;            if (!bg_col.isValid())                bg_col = p->background().color();            // Create an "XOR" color.            QColor patternCol((bg_col.red() ^ 0xff) & 0xff,                              (bg_col.green() ^ 0xff) & 0xff,                              (bg_col.blue() ^ 0xff) & 0xff);            p->setBrush(QBrush(patternCol, Qt::Dense4Pattern));            p->setBrushOrigin(r.topLeft());            p->setPen(Qt::NoPen);            p->drawRect(r.left(), r.top(), r.width(), 1);    // Top            p->drawRect(r.left(), r.bottom(), r.width(), 1); // Bottom            p->drawRect(r.left(), r.top(), 1, r.height());   // Left            p->drawRect(r.right(), r.top(), 1, r.height());  // Right            p->restore();        }        break;    case PE_IndicatorRadioButton:        {#define PTSARRLEN(x) sizeof(x)/(sizeof(QPoint))            static const QPoint pts1[] = {              // dark lines                QPoint(1, 9), QPoint(1, 8), QPoint(0, 7), QPoint(0, 4), QPoint(1, 3), QPoint(1, 2),                QPoint(2, 1), QPoint(3, 1), QPoint(4, 0), QPoint(7, 0), QPoint(8, 1), QPoint(9, 1)            };            static const QPoint pts2[] = {              // black lines                QPoint(2, 8), QPoint(1, 7), QPoint(1, 4), QPoint(2, 3), QPoint(2, 2), QPoint(3, 2),                QPoint(4, 1), QPoint(7, 1), QPoint(8, 2), QPoint(9, 2)            };            static const QPoint pts3[] = {              // background lines                QPoint(2, 9), QPoint(3, 9), QPoint(4, 10), QPoint(7, 10), QPoint(8, 9), QPoint(9, 9),                QPoint(9, 8), QPoint(10, 7), QPoint(10, 4), QPoint(9, 3)            };            static const QPoint pts4[] = {              // white lines                QPoint(2, 10), QPoint(3, 10), QPoint(4, 11), QPoint(7, 11), QPoint(8, 10),                QPoint(9, 10), QPoint(10, 9), QPoint(10, 8), QPoint(11, 7), QPoint(11, 4),                QPoint(10, 3), QPoint(10, 2)            };            static const QPoint pts5[] = {              // inner fill                QPoint(4, 2), QPoint(7, 2), QPoint(9, 4), QPoint(9, 7), QPoint(7, 9), QPoint(4, 9),                QPoint(2, 7), QPoint(2, 4)            };            // make sure the indicator is square            QRect ir = opt->rect;            if (opt->rect.width() < opt->rect.height()) {                ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2);                ir.setHeight(opt->rect.width());            } else if (opt->rect.height() < opt->rect.width()) {                ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2);                ir.setWidth(opt->rect.height());            }            p->save();            bool down = opt->state & State_Sunken;            bool enabled = opt->state & State_Enabled;            bool on = opt->state & State_On;            QPolygon a;            //center when rect is larger than indicator size            int xOffset = 0;            int yOffset = 0;            int indicatorWidth = pixelMetric(PM_ExclusiveIndicatorWidth);            int indicatorHeight = pixelMetric(PM_ExclusiveIndicatorWidth);            if (ir.width() > indicatorWidth)                xOffset += (ir.width() - indicatorWidth)/2;            if (ir.height() > indicatorHeight)                yOffset += (ir.height() - indicatorHeight)/2;            p->translate(xOffset, yOffset);            p->translate(ir.x(), ir.y());            p->setPen(opt->palette.dark().color());            p->drawPolyline(pts1, PTSARRLEN(pts1));            p->setPen(opt->palette.shadow().color());            p->drawPolyline(pts2, PTSARRLEN(pts2));            p->setPen(opt->palette.midlight().color());            p->drawPolyline(pts3, PTSARRLEN(pts3));            p->setPen(opt->palette.light().color());            p->drawPolyline(pts4, PTSARRLEN(pts4));

⌨️ 快捷键说明

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