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

📄 qmotifstyle.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            if (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedEast ||                tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::RoundedWest) {                p->save();                QRect tabRect = opt->rect;                QColor tabLight = opt->palette.light().color();                QColor tabDark = opt->palette.dark().color();                p->fillRect(opt->rect.adjusted(default_frame, default_frame,                                               -default_frame, -default_frame),                                               tab->palette.background());                if(tab->shape == QTabBar::RoundedWest) {                    tabDark = opt->palette.light().color();                    tabLight = opt->palette.dark().color();                    tabRect = QRect(0, 0, tabRect.height(), tabRect.width());                    p->translate(opt->rect.left(), opt->rect.bottom());                    p->rotate(-90);                } else if(tab->shape == QTabBar::RoundedSouth) {                    tabDark = opt->palette.light().color();                    tabLight = opt->palette.dark().color();                    tabRect = QRect(0, 0, tabRect.width(), tabRect.height());                    p->translate(opt->rect.right(), opt->rect.bottom());                    p->rotate(180);                } else if(tab->shape == QTabBar::RoundedEast) {                    tabRect = QRect(0, 0, tabRect.height(), tabRect.width());                    p->translate(opt->rect.right(), opt->rect.top());                    p->rotate(90);                }                if (default_frame > 1) {                    p->setPen(tabLight);                    p->drawLine(tabRect.left(), tabRect.bottom(),                                tabRect.right(), tabRect.bottom());                    p->setPen(tabLight);                    p->drawLine(tabRect.left(), tabRect.bottom()-1,                                tabRect.right(), tabRect.bottom()-1);                    if (tabRect.left() == 0)                        p->drawPoint(tabRect.bottomLeft());                } else {                    p->setPen(tabLight);                    p->drawLine(tabRect.left(), tabRect.bottom(),                                tabRect.right(), tabRect.bottom());                }                if (opt->state & State_Selected) {                    p->fillRect(QRect(tabRect.left()+1, tabRect.bottom()-frame_offset,                                      tabRect.width()-3, 2),                                tab->palette.brush(QPalette::Active, QPalette::Background));                    p->setPen(tab->palette.background().color());                    p->drawLine(tabRect.left()+1, tabRect.bottom(),                                tabRect.left()+1, tabRect.top()+2);                    p->setPen(tabLight);                } else {                    p->setPen(tabLight);                }                p->drawLine(tabRect.left(), tabRect.bottom()-1,                            tabRect.left(), tabRect.top() + 2);                p->drawPoint(tabRect.left()+1, tabRect.top() + 1);                p->drawLine(tabRect.left()+2, tabRect.top(),                            tabRect.right() - 2, tabRect.top());                p->drawPoint(tabRect.left(), tabRect.bottom());                if (default_frame > 1) {                    p->drawLine(tabRect.left()+1, tabRect.bottom(),                                tabRect.left()+1, tabRect.top() + 2);                    p->drawLine(tabRect.left()+2, tabRect.top()+1,                                tabRect.right() - 2, tabRect.top()+1);                }                p->setPen(tabDark);                p->drawLine(tabRect.right() - 1, tabRect.top() + 2,                            tabRect.right() - 1, tabRect.bottom() - 1 +                            ((opt->state & State_Selected) ? frame_offset : -frame_offset));                if (default_frame > 1) {                    p->drawPoint(tabRect.right() - 1, tabRect.top() + 1);                    p->drawLine(tabRect.right(), tabRect.top() + 2, tabRect.right(),                                tabRect.bottom() -                                ((opt->state & State_Selected) ?                                 ((tab->position == QStyleOptionTab::End) ? 0:1):1+frame_offset));                    p->drawPoint(tabRect.right() - 1, tabRect.top() + 1);                }                p->restore();            } else {                QCommonStyle::drawControl(element, opt, p, widget);            }            break; }#endif // QT_NO_TABBAR    case CE_ProgressBarGroove:        qDrawShadePanel(p, opt->rect, opt->palette, true, 2);        break;    case CE_ProgressBarLabel:        if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {            QTransform oldMatrix = p->transform();            QRect rect = pb->rect;            bool vertical = false;            bool invert = false;            bool bottomToTop = false;            if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) {                vertical = (pb2->orientation == Qt::Vertical);                invert = pb2->invertedAppearance;                bottomToTop = pb2->bottomToTop;            }            if (vertical) {                QTransform m;                rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height                if (bottomToTop) {                    m.translate(0.0, rect.width());                    m.rotate(-90);                } else {                    m.translate(rect.height(), 0.0);                    m.rotate(90);                }                p->setTransform(m);            }            const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, opt, widget);            int u = rect.width() / unit_width;            int p_v = pb->progress - pb->minimum;            int t_s = qMax(0, pb->maximum - pb->minimum);            if (u > 0 && pb->progress >= INT_MAX / u && t_s >= u) {                // scale down to something usable.                p_v /= u;                t_s /= u;            }            if (pb->textVisible && t_s) {                int nu = (u * p_v + t_s/2) / t_s;                int x = unit_width * nu;                QRect left(rect.x(), rect.y(), x, rect.height());                QRect right(rect.x() + x, rect.y(), rect.width() - x, rect.height());                Qt::LayoutDirection dir;                dir = vertical ? (bottomToTop ? Qt::LeftToRight : Qt::RightToLeft) : pb->direction;                if (invert)                    dir = (dir == Qt::LeftToRight) ? Qt::RightToLeft : Qt::LeftToRight;                const QRect highlighted = visualRect(dir, rect, left);                const QRect background = visualRect(dir, rect, right);                p->setPen(opt->palette.highlightedText().color());                p->setClipRect(highlighted);                p->drawText(rect, Qt::AlignCenter | Qt::TextSingleLine, pb->text);                if (pb->progress != pb->maximum) {                    p->setClipRect(background);                    p->setPen(opt->palette.highlight().color());                    p->drawText(rect, Qt::AlignCenter | Qt::TextSingleLine, pb->text);                }            }            p->setTransform(oldMatrix);            break;        }    case CE_MenuTearoff: {        if(opt->state & State_Selected) {            if(pixelMetric(PM_MenuPanelWidth, opt, widget) > 1)                qDrawShadePanel(p, opt->rect.x(), opt->rect.y(), opt->rect.width(),                                opt->rect.height(), opt->palette, false, motifItemFrame,                                &opt->palette.brush(QPalette::Button));            else                qDrawShadePanel(p, opt->rect.x()+1, opt->rect.y()+1, opt->rect.width()-2,                                opt->rect.height()-2, opt->palette, true, 1, &opt->palette.brush(QPalette::Button));        } else {            p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));        }        p->setPen(QPen(opt->palette.dark().color(), 1, Qt::DashLine));        p->drawLine(opt->rect.x()+2, opt->rect.y()+opt->rect.height()/2-1, opt->rect.x()+opt->rect.width()-4,                    opt->rect.y()+opt->rect.height()/2-1);        p->setPen(QPen(opt->palette.light().color(), 1, Qt::DashLine));        p->drawLine(opt->rect.x()+2, opt->rect.y()+opt->rect.height()/2, opt->rect.x()+opt->rect.width()-4,                    opt->rect.y()+opt->rect.height()/2);        break; }    case CE_MenuItem:        if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {            int maxpmw = menuitem->maxIconWidth;            if(menuitem->menuHasCheckableItems)                maxpmw = qMax(maxpmw, motifCheckMarkSpace);            int x, y, w, h;            opt->rect.getRect(&x, &y, &w, &h);            if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) {  // draw separator                int textWidth = 0;                if (!menuitem->text.isEmpty()) {                    QFont oldFont = p->font();                    p->setFont(menuitem->font);                    p->fillRect(x, y, w, h, opt->palette.brush(QPalette::Button));                    drawItemText(p, menuitem->rect.adjusted(10, 0, -5, 0), Qt::AlignLeft | Qt::AlignVCenter,                                 menuitem->palette, menuitem->state & State_Enabled, menuitem->text,                                 QPalette::Text);                    textWidth = menuitem->fontMetrics.width(menuitem->text) + 10;                    y += menuitem->fontMetrics.lineSpacing() / 2;                    p->setFont(oldFont);                }                p->setPen(opt->palette.dark().color());                p->drawLine(x, y, x + 5, y);                p->drawLine(x + 5 + textWidth, y, x+w, y);                p->setPen(opt->palette.light().color());                p->drawLine(x, y + 1, x + 5, y + 1);                p->drawLine(x + 5 + textWidth, y + 1, x+w, y + 1);                return;            }            int pw = motifItemFrame;            if((opt->state & State_Selected) && (opt->state & State_Enabled)) {  // active item frame                if(pixelMetric(PM_MenuPanelWidth, opt) > 1)                    qDrawShadePanel(p, x, y, w, h, opt->palette, false, pw,                                    &opt->palette.brush(QPalette::Button));                else                    qDrawShadePanel(p, x+1, y+1, w-2, h-2, opt->palette, true, 1,                                    &opt->palette.brush(QPalette::Button));            } else  {                               // incognito frame                p->fillRect(x, y, w, h, opt->palette.brush(QPalette::Button));            }            QRect vrect = visualRect(opt->direction, opt->rect,                                     QRect(x+motifItemFrame, y+motifItemFrame, maxpmw,                                           h-2*motifItemFrame));            int xvis = vrect.x();            if (menuitem->checked) {                if(!menuitem->icon.isNull())                    qDrawShadePanel(p, xvis, y+motifItemFrame, maxpmw, h-2*motifItemFrame,                                    opt->palette, true, 1, &opt->palette.brush(QPalette::Midlight));            } else if (!(opt->state & State_Selected)) {                p->fillRect(xvis, y+motifItemFrame, maxpmw, h-2*motifItemFrame,                            opt->palette.brush(QPalette::Button));            }            if(!menuitem->icon.isNull()) {              // draw icon                QIcon::Mode mode = QIcon::Normal; // no disabled icons in Motif                if ((opt->state & State_Selected) && !!(opt->state & State_Enabled))                    mode = QIcon::Active;                QPixmap pixmap;                if (menuitem->checkType != QStyleOptionMenuItem::NotCheckable && menuitem->checked)                    pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);                else                    pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode);                int pixw = pixmap.width();                int pixh = pixmap.height();                QRect pmr(0, 0, pixw, pixh);                pmr.moveCenter(vrect.center());                p->setPen(opt->palette.text().color());                p->drawPixmap(pmr.topLeft(), pixmap);            } else  if (menuitem->checkType != QStyleOptionMenuItem::NotCheckable) {  // just "checking"...                int mh = h - 2*motifItemFrame;                QStyleOptionButton newMenuItem;                newMenuItem.state = menuitem->checked ? State_On : State_None;                if (opt->state & State_Enabled) {                    newMenuItem.state |= State_Enabled;                    if (menuitem->state & State_Sunken)                        newMenuItem.state |= State_Sunken;                }                if (menuitem->checkType & QStyleOptionMenuItem::Exclusive) {                    newMenuItem.rect.setRect(xvis + 2, y + motifItemFrame + mh / 4, 11, 11);                    drawPrimitive(PE_IndicatorRadioButton, &newMenuItem, p, widget);                } else {                    newMenuItem.rect.setRect(xvis + 5, y + motifItemFrame + mh / 4, 9, 9);                    drawPrimitive(PE_IndicatorCheckBox, &newMenuItem, p, widget);                }            }            p->setPen(opt->palette.buttonText().color());            QColor discol;            if (!(opt->state & State_Enabled)) {                discol = opt->palette.text().color();                p->setPen(discol);            }            int xm = motifItemFrame + maxpmw + motifItemHMargin;            vrect = visualRect(opt->direction, opt->rect,                               QRect(x+xm, y+motifItemVMargin, w-xm-menuitem->tabWidth,                                     h-2*motifItemVMargin));            xvis = vrect.x();            QString s = menuitem->text;            if (!s.isNull()) {                        // draw text                int t = s.indexOf(QLatin1Char('\t'));                int m = motifItemVMargin;                int text_flags = Qt::AlignVCenter|Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;                text_flags |= Qt::AlignLeft;                QFont oldFont = p->font();                p->setFont(menuitem->font);                if (t >= 0) {                         // draw tab text                    QRect vr = visualRect(opt->direction, opt->rect,                                          QRect(x+w-menuitem->tabWidth-motifItemHMargin-motifItemFrame,                                                y+motifItemVMargin, menuitem->tabWidth,                                                h-2*motifItemVMargin));                    int xv = vr.x();                    QRect tr(xv, y+m, menuitem->tabWidth, h-2*m);                    p->drawText(tr, text_flags, s.mid(t+1));                    if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))                        p->fillRect(tr, QBrush(p->background().color(), Qt::Dense5Pattern));                    s = s.left(t);                }                QRect tr(xvis, y+m, w - xm - menuitem->tabWidth + 1, h-2*m);                p->drawText(tr, text_flags, s.left(t));                p->setFont(oldFont);                if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))                    p->fillRect(tr, QBrush(p->background().color(), Qt::Dense5Pattern));            }            if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {           // draw sub menu arrow                int dim = (h-2*motifItemFrame) / 2;                QStyle::PrimitiveElement arrow = (opt->direction == Qt::RightToLeft ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight);                QStyleOption arrowOpt = *opt;                arrowOpt.rect = visualRect(opt->direction, opt->rect,                                           QRect(x+w - motifArrowHMargin - motifItemFrame - dim,                                                 y+h/2-dim/2, dim, dim));                if ((opt->state & State_Selected))                    arrowOpt.state = (State_Sunken | ((opt->state & State_Enabled) ? State_Enabled : State_None));                else                    arrowOpt.state = ((opt->state & State_Enabled) ? State_Enabled : State_None);                drawPrimitive(arrow, &arrowOpt, p, widget);            }            break; }

⌨️ 快捷键说明

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