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

📄 qdecorationdefault_qws.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    int titleHeight = hasTitle ? titleBarHeight(widget) : 0;    int bw = hasBorder ? BORDER_WIDTH : 0;    int bbw = hasBorder ? BOTTOM_BORDER_WIDTH : 0;    QRegion region;    switch (decorationRegion) {        case All: {                QRect r(rect.left() - bw,                        rect.top() - titleHeight - bw,                        rect.width() + 2 * bw,                        rect.height() + titleHeight + bw + bbw);                region = r;                region -= rect;            }            break;        case Title: {                QRect r(rect.left()                        + (hasSysMenu ? menu_width : 0),                        rect.top() - titleHeight,                        rect.width()                        - (hasSysMenu ? menu_width : 0)                        - close_width                        - (hasMaximize ? maximize_width : 0)                        - (hasMinimize ? minimize_width : 0)                        - (hasContextHelp ? help_width : 0),                        titleHeight);                if (r.width() > 0)                    region = r;            }            break;        case Top: {                QRect r(rect.left() + CORNER_GRAB,                        rect.top() - titleHeight - bw,                        rect.width() - 2 * CORNER_GRAB,                        bw);                region = r;            }            break;        case Left: {                QRect r(rect.left() - bw,                        rect.top() - titleHeight + CORNER_GRAB,                        bw,                        rect.height() + titleHeight - 2 * CORNER_GRAB);                region = r;            }            break;        case Right: {                QRect r(rect.right() + 1,                        rect.top() - titleHeight + CORNER_GRAB,                        bw,                        rect.height() + titleHeight - 2 * CORNER_GRAB);                region = r;            }            break;        case Bottom: {                QRect r(rect.left() + CORNER_GRAB,                        rect.bottom() + 1,                        rect.width() - 2 * CORNER_GRAB,                        bw);                region = r;            }            break;        case TopLeft: {                QRect r1(rect.left() - bw,                        rect.top() - bw - titleHeight,                        CORNER_GRAB + bw,                        bw);                QRect r2(rect.left() - bw,                        rect.top() - bw - titleHeight,                        bw,                        CORNER_GRAB + bw);                region = QRegion(r1) + r2;            }            break;        case TopRight: {                QRect r1(rect.right() - CORNER_GRAB,                        rect.top() - bw - titleHeight,                        CORNER_GRAB + bw,                        bw);                QRect r2(rect.right() + 1,                        rect.top() - bw - titleHeight,                        bw,                        CORNER_GRAB + bw);                region = QRegion(r1) + r2;            }            break;        case BottomLeft: {                QRect r1(rect.left() - bw,                        rect.bottom() + 1,                        CORNER_GRAB + bw,                        bw);                QRect r2(rect.left() - bw,                        rect.bottom() - CORNER_GRAB,                        bw,                        CORNER_GRAB + bw);                region = QRegion(r1) + r2;            }            break;        case BottomRight: {                QRect r1(rect.right() - CORNER_GRAB,                        rect.bottom() + 1,                        CORNER_GRAB + bw,                        bw);                QRect r2(rect.right() + 1,                        rect.bottom() - CORNER_GRAB,                        bw,                        CORNER_GRAB + bw);                region = QRegion(r1) + r2;            }            break;        case Menu: {                if (hasSysMenu) {                    region = QRect(rect.left(), rect.top() - titleHeight,                                   menu_width, titleHeight);                }            }            break;        case Help: {                if (hasContextHelp) {                    QRect r(rect.right()                            - close_width                            - (hasMaximize ? maximize_width : 0)                            - (hasMinimize ? minimize_width : 0)                            - help_width + 1, rect.top() - titleHeight,                            help_width, titleHeight);                    if (r.left() > rect.left() + titleHeight)                        region = r;                }            }            break;        case Minimize: {                if (hasMinimize && !isMinimized) {                    QRect r(rect.right() - close_width                            - (hasMaximize ? maximize_width : 0)                            - minimize_width + 1, rect.top() - titleHeight,                            minimize_width, titleHeight);                    if (r.left() > rect.left() + titleHeight)                        region = r;                }            }            break;        case Maximize: {                if (hasMaximize && !isMaximized) {                    QRect r(rect.right() - close_width - maximize_width + 1,                            rect.top() - titleHeight, maximize_width, titleHeight);                    if (r.left() > rect.left() + titleHeight)                        region = r;                }            }            break;        case Normalize: {                if (hasMinimize && isMinimized) {                    QRect r(rect.right() - close_width                            - (hasMaximize ? maximize_width : 0)                            - minimize_width + 1, rect.top() - titleHeight,                            minimize_width, titleHeight);                    if (r.left() > rect.left() + titleHeight)                        region = r;                } else if (hasMaximize && isMaximized) {                    QRect r(rect.right() - close_width - maximize_width + 1,                            rect.top() - titleHeight, maximize_width, titleHeight);                    if (r.left() > rect.left() + titleHeight)                        region = r;                }            }            break;        case Close: {                QRect r(rect.right() - close_width + 1, rect.top() - titleHeight,                        close_width, titleHeight);                if (r.left() > rect.left() + titleHeight)                    region = r;            }            break;    default: {        int i = 1;        while (i) {            if (i & decorationRegion)                region += this->region(widget, rect, i);            i <<= 1;        }    }            break;    }    return region;}bool QDecorationDefault::paint(QPainter *painter, const QWidget *widget, int decorationRegion,                               DecorationState state){    if (decorationRegion == None)        return false;    const QRect titleRect = QDecoration::region(widget, Title).boundingRect();    const QPalette pal = QApplication::palette();    int titleHeight = titleRect.height();    int titleWidth = titleRect.width();    QRegion oldClipRegion = painter->clipRegion();    Qt::WindowFlags flags = widget->windowFlags();    bool hasBorder = !widget->isMaximized();    bool hasTitle = flags & Qt::WindowTitleHint;    bool hasSysMenu = flags & Qt::WindowSystemMenuHint;    bool hasContextHelp = flags & Qt::WindowContextHelpButtonHint;    bool hasMinimize = flags & Qt::WindowMinimizeButtonHint;    bool hasMaximize = flags & Qt::WindowMaximizeButtonHint;    bool paintAll = (decorationRegion == int(All));    bool handled = false;    bool porterDuff = painter->paintEngine()->hasFeature(QPaintEngine::PorterDuff);    if ((paintAll || decorationRegion & Borders) && state == Normal && hasBorder) {        if (hasTitle) { // reduce flicker            QRect rect(widget->rect());            QRect r(rect.left(), rect.top() - titleHeight,                    rect.width(), titleHeight);            painter->setClipRegion(oldClipRegion - r);        }        QRect br = QDecoration::region(widget).boundingRect();        if (porterDuff)            painter->setCompositionMode(QPainter::CompositionMode_Source);        qDrawWinPanel(painter, br.x(), br.y(), br.width(),                    br.height(), pal, false,                    &pal.brush(QPalette::Window));        if (porterDuff)            painter->setCompositionMode(QPainter::CompositionMode_SourceOver);        handled |= true;    }    if ((paintAll || decorationRegion & Title && titleWidth > 0) && state == Normal && hasTitle) {        painter->setClipRegion(oldClipRegion);        QBrush titleBrush;        QPen   titlePen;        if (widget == qApp->activeWindow()) {            titleBrush = pal.brush(QPalette::Highlight);            titlePen   = pal.color(QPalette::HighlightedText);        } else {            titleBrush = pal.brush(QPalette::Window);            titlePen   = pal.color(QPalette::Text);        }        if (porterDuff)            painter->setCompositionMode(QPainter::CompositionMode_Source);        qDrawShadePanel(painter,                        titleRect.x(), titleRect.y(), titleRect.width(), titleRect.height(),                        pal, true, 1, &titleBrush);        if (porterDuff)            painter->setCompositionMode(QPainter::CompositionMode_SourceOver);        painter->setPen(titlePen);        painter->drawText(titleRect.x() + 4, titleRect.y(),                          titleRect.width() - 8, titleRect.height(),                          Qt::AlignVCenter, widget->windowTitle());        handled |= true;    }    if (state != Hover) {        painter->setClipRegion(oldClipRegion);        if ((paintAll || decorationRegion & Menu) && hasSysMenu) {            paintButton(painter, widget, Menu, state, pal);            handled |= true;        }        if ((paintAll || decorationRegion & Help) && hasContextHelp) {            paintButton(painter, widget, Help, state, pal);            handled |= true;        }        if ((paintAll || decorationRegion & Minimize) && hasMinimize) {            paintButton(painter, widget, Minimize, state, pal);            handled |= true;        }        if ((paintAll || decorationRegion & Maximize) && hasMaximize) {            paintButton(painter, widget,                        ((widget->windowState() & Qt::WindowMaximized)? Normalize : Maximize),                        state, pal);            handled |= true;        }        if (paintAll || decorationRegion & Close) {            paintButton(painter, widget, Close, state, pal);            handled |= true;        }    }    return handled;}void QDecorationDefault::paintButton(QPainter *painter, const QWidget *widget,                                     int buttonRegion, DecorationState state, const QPalette &pal){    int xoff = 2;    int yoff = 2;    const QPixmap pm = pixmapFor(widget, buttonRegion, xoff, yoff);    QRect brect(QDecoration::region(widget, buttonRegion).boundingRect());    bool porterDuff = painter->paintEngine()->hasFeature(QPaintEngine::PorterDuff);    if (state & QDecoration::Pressed) {        if (porterDuff)            painter->setCompositionMode(QPainter::CompositionMode_Source);        qDrawWinPanel(painter, brect, pal, true, &pal.brush(QPalette::Window));        if (porterDuff)            painter->setCompositionMode(QPainter::CompositionMode_SourceOver);        ++xoff;        ++yoff;    } else {        painter->fillRect(brect, pal.brush(QPalette::Window));    }    if (!pm.isNull())        painter->drawPixmap(brect.x() + xoff, brect.y() + yoff, pm);}#endif // QT_NO_QWS_DECORATION_DEFAULT

⌨️ 快捷键说明

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