Changeset 178


Ignore:
Timestamp:
Feb 25, 2008, 11:07:51 PM (17 years ago)
Author:
dmik
Message:

styles/Warp4: Increased tool button size hint to avoid cutting contained icons (#9).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/styles/qwarp4style.cpp

    r175 r178  
    17461746  at the same time an accelerator key (string after \t (tab)) and a
    17471747  submenu arrow displayed!
    1748  
     1748
    17491749  btw., the Windows style solves that problem by always having some space left
    17501750  for the arrow, and Motiv overpaints the arrow over the accelerator string,
     
    18841884
    18851885/*! \reimp */
    1886 void QWarp4Style::drawPrimitive(PrimitiveElement pe,
    1887                                 QPainter* p,
    1888                                 QRect const& r,
    1889                                 QColorGroup const& cg,
    1890                                 SFlags flags,
    1891                                 QStyleOption const& opt) const
    1892 {
    1893     QRect rr(r);
     1886void QWarp4Style::drawPrimitive (PrimitiveElement pe,
     1887                                 QPainter *p,
     1888                                 const QRect &r,
     1889                                 const QColorGroup &cg,
     1890                                 SFlags flags,
     1891                                 const QStyleOption &opt) const
     1892{
     1893    QRect rr (r);
    18941894
    18951895    switch (pe)
     
    18981898        case PE_ButtonTool:
    18991899        {
    1900             bool sunken = flags & (Style_Sunken | Style_Down | Style_On),
    1901                  def = flags & Style_ButtonDefault;
    1902             qDrawWarpDefFrame(p, rr, cg, def);
    1903             QBrush fill = cg.brush(QColorGroup::Button);
    1904             rr.addCoords(1, 1, -1, -1);
    1905             qDrawWarpFilledRect(p, rr, cg.dark(), cg.light(), &fill, 2, sunken);
     1900            bool def = flags & Style_ButtonDefault;
     1901            qDrawWarpDefFrame (p, rr, cg, def);
     1902            rr.addCoords (1, 1, -1, -1);
     1903
     1904            bool sunken = flags & (Style_Sunken | Style_Down | Style_On);
     1905            QBrush fill = cg.brush (QColorGroup::Button);
     1906            qDrawWarpFilledRect (p, rr, cg.dark(), cg.light(), &fill, 2, sunken);
    19061907            break;
    19071908        }
     
    26142615    switch (element)
    26152616    {
    2616         #ifndef QT_NO_TABBAR
     2617#ifndef QT_NO_TABBAR
    26172618            case CE_TabBarTab:
    26182619            {
     
    27212722                break;
    27222723            }
    2723         #endif // QT_NO_TABBAR
     2724#endif // QT_NO_TABBAR
    27242725
    27252726        case CE_ToolBoxTab:
     
    27432744        }
    27442745
    2745         #ifndef QT_NO_PROGRESSBAR
     2746#ifndef QT_NO_PROGRESSBAR
    27462747            case CE_ProgressBarContents:
    27472748            {
     
    28372838                break;
    28382839            }
    2839         #endif
    2840 
    2841         #ifndef QT_NO_POPUPMENU
     2840#endif // QT_NO_PROGRESSBAR
     2841
     2842#ifndef QT_NO_POPUPMENU
    28422843            case CE_PopupMenuItem:
    28432844            {
     
    29792980                break;
    29802981            }
    2981         #endif
     2982#endif // QT_NO_POPUPMENU
    29822983
    29832984        case CE_MenuBarItem:
     
    30183019        }
    30193020
    3020         #ifndef QT_NO_TOOLBUTTON
     3021#ifndef QT_NO_TOOLBUTTON
    30213022            case CE_ToolButtonLabel:
    30223023            {
    3023                 if((QString("qt_left_btn") == widget->name()) ||
    3024                    (QString("qt_right_btn") == widget->name()))
     3024                if (!qstrcmp (widget->name(), "qt_left_btn") ||
     3025                    !qstrcmp (widget->name(), "qt_right_btn"))
    30253026                {
    30263027                    // do nothing in this case!
     
    30283029                else
    30293030                {
    3030                     QToolButton const* toolbutton = (QToolButton const*)widget;
     3031                    QToolButton const *toolbutton = (QToolButton const *) widget;
    30313032                    QRect rect = r;
    3032                     // the following line is the only difference to the "commonstyle":
    3033                     // it makes sure that the bitmap and/or label does not overpaint
    3034                     // the button frame
    3035                     rect.addCoords(3, 3, -3, -3);
    30363033                    Qt::ArrowType arrowType = opt.isDefault() ?
    30373034                                              Qt::DownArrow : opt.arrowType();
    30383035
    3039                     if(flags & (Style_Down | Style_On))
    3040                         rect.moveBy(pixelMetric(PM_ButtonShiftHorizontal, widget),
    3041                                     pixelMetric(PM_ButtonShiftVertical, widget));
    3042 
    3043                     if(!opt.isDefault())
     3036                    if (flags & (Style_Down | Style_On))
     3037                        rect.moveBy (pixelMetric(PM_ButtonShiftHorizontal, widget),
     3038                                     pixelMetric(PM_ButtonShiftVertical, widget));
     3039
     3040                    if (!opt.isDefault())
    30443041                    {
    30453042                        PrimitiveElement pe;
     
    30613058                        }
    30623059
    3063                         drawPrimitive(pe, p, rect, cg, flags, opt);
     3060                        drawPrimitive (pe, p, rect, cg, flags, opt);
    30643061                    }
    3065 
    30663062                    else
    30673063                    {
    30683064                        QColor btext = toolbutton->paletteForegroundColor();
    30693065
    3070                         if(toolbutton->iconSet().isNull() &&
    3071                            !toolbutton->text().isNull() &&
    3072                            !toolbutton->usesTextLabel())
     3066                        if (toolbutton->iconSet().isNull() &&
     3067                            !toolbutton->text().isNull() &&
     3068                            !toolbutton->usesTextLabel())
    30733069                        {
    30743070                            int alignment = AlignCenter | AlignVCenter | ShowPrefix;
    30753071
    3076                             if(!styleHint(SH_UnderlineAccelerator, widget,
    3077                                           QStyleOption::Default, 0))
     3072                            if (!styleHint (SH_UnderlineAccelerator, widget,
     3073                                            QStyleOption::Default, 0))
    30783074                                alignment |= NoAccel;
    30793075
    3080                             drawItem(p, rect, alignment, cg,
    3081                                      flags & Style_Enabled, 0, toolbutton->text(),
    3082                                      toolbutton->text().length(), &btext);
     3076                            drawItem (p, rect, alignment, cg,
     3077                                      flags & Style_Enabled, 0, toolbutton->text(),
     3078                                      toolbutton->text().length(), &btext);
    30833079                        }
    3084 
    30853080                        else
    30863081                        {
     
    30943089
    30953090                            QIconSet::Mode mode;
    3096                             if(!toolbutton->isEnabled())
     3091                            if (!toolbutton->isEnabled())
    30973092                                mode = QIconSet::Disabled;
    3098                             else if(flags & (Style_Down | Style_On | Style_Raised))
     3093                            else if (flags & (Style_Down | Style_On | Style_Raised))
    30993094                                mode = QIconSet::Active;
    31003095                            else
     
    31033098                            pm = toolbutton->iconSet().pixmap(size, mode, state);
    31043099
    3105                             if(toolbutton->usesTextLabel())
     3100                            if (toolbutton->usesTextLabel())
    31063101                            {
    3107                                 if(toolbutton->textPosition() == QToolButton::Under)
     3102                                if (toolbutton->textPosition() == QToolButton::Under)
    31083103                                {
    31093104                                    p->setFont(toolbutton->font());
     
    31113106                                    QRect pr = rect, tr = rect;
    31123107                                    int fh = p->fontMetrics().height();
    3113                                     pr.addCoords(0, 1, 0, -fh - 3);
    3114                                     tr.addCoords(0, pr.bottom(), 0, -3);
    3115                                     drawItem(p, pr, AlignCenter, cg, TRUE, &pm, QString::null);
     3108                                    pr.addCoords (0, 1, 0, -fh - 3);
     3109                                    tr.addCoords (0, pr.bottom(), 0, -3);
     3110                                    drawItem (p, pr, AlignCenter, cg, TRUE, &pm, QString::null);
    31163111                                    int alignment = AlignCenter | ShowPrefix;
    31173112
    3118                                     if(!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
     3113                                    if (!styleHint (SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
    31193114                                        alignment |= NoAccel;
    31203115
    3121                                     drawItem(p, tr, alignment, cg,
    3122                                              flags & Style_Enabled, 0, toolbutton->textLabel(),
    3123                                              toolbutton->textLabel().length(), &btext);
     3116                                    drawItem (p, tr, alignment, cg,
     3117                                              flags & Style_Enabled, 0, toolbutton->textLabel(),
     3118                                              toolbutton->textLabel().length(), &btext);
    31243119                                }
    31253120                                else
    31263121                                {
    3127                                     p->setFont(toolbutton->font());
     3122                                    p->setFont (toolbutton->font());
    31283123
    31293124                                    QRect pr = rect, tr = rect;
    3130                                     pr.setWidth(pm.width() + 8);
    3131                                     tr.addCoords(pr.right(), 0, 0, 0);
    3132                                     drawItem(p, pr, AlignCenter, cg, TRUE, &pm, QString::null);
     3125                                    pr.setWidth (pm.width() + 8);
     3126                                    tr.addCoords (pr.right(), 0, 0, 0);
     3127                                    drawItem (p, pr, AlignCenter, cg, TRUE, &pm, QString::null);
    31333128                                    int alignment = AlignLeft | AlignVCenter | ShowPrefix;
    31343129
    3135                                     if(!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
     3130                                    if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
    31363131                                        alignment |= NoAccel;
    31373132
    3138                                     drawItem(p, tr, alignment, cg,
    3139                                              flags & Style_Enabled, 0, toolbutton->textLabel(),
    3140                                              toolbutton->textLabel().length(), &btext);
     3133                                    drawItem (p, tr, alignment, cg,
     3134                                              flags & Style_Enabled, 0, toolbutton->textLabel(),
     3135                                              toolbutton->textLabel().length(), &btext);
    31413136                                }
    31423137                            }
    31433138                            else
    31443139                            {
    3145                                 drawItem(p, rect, AlignCenter, cg, TRUE, &pm, QString::null);
     3140                                drawItem (p, rect, AlignCenter, cg, TRUE, &pm, QString::null);
    31463141                            }
    31473142                        }
     
    31513146                break;
    31523147            }
    3153         #endif
     3148#endif // QT_NO_TOOLBUTTON
    31543149
    31553150        default:
     
    33773372        case CT_PushButton:
    33783373        {
    3379             #ifndef QT_NO_PUSHBUTTON
     3374#ifndef QT_NO_PUSHBUTTON
    33803375                const QPushButton* button = (const QPushButton*)widget;
    33813376                sz = QCommonStyle::sizeFromContents(contents, widget, contentsSize, opt);
     
    33923387
    33933388                sz = QSize(w, h);
    3394             #endif
     3389#endif // QT_NO_PUSHBUTTON
    33953390
    33963391            break;
     
    33993394        case CT_ToolButton:
    34003395        {
    3401             sz = QSize(sz.width() + 6, sz.height() + 5);
     3396            // this includes 3px margin drawn for PE_ButtonTool + 1px spacing
     3397            // around contents + 1px extra width/height for pressed icon shift
     3398            sz = QSize (sz.width() + 9, sz.height() + 9);
    34023399            break;
    34033400        }
     
    34053402        case CT_PopupMenuItem:
    34063403        {
    3407             #ifndef QT_NO_POPUPMENU
     3404#ifndef QT_NO_POPUPMENU
    34083405                if(! widget || opt.isDefault())
    34093406                    break;
     
    34593456
    34603457                sz = QSize(w, h);
    3461             #endif
     3458#endif // QT_NO_POPUPMENU
    34623459
    34633460            break;
Note: See TracChangeset for help on using the changeset viewer.