src/gui/styles/qwindowsxpstyle.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    45 
    45 
    46 #include <private/qobject_p.h>
    46 #include <private/qobject_p.h>
    47 #include <private/qpaintengine_raster_p.h>
    47 #include <private/qpaintengine_raster_p.h>
    48 #include <private/qapplication_p.h>
    48 #include <private/qapplication_p.h>
    49 #include <private/qstylehelper_p.h>
    49 #include <private/qstylehelper_p.h>
       
    50 #include <private/qwidget_p.h>
    50 #include <qlibrary.h>
    51 #include <qlibrary.h>
    51 #include <qpainter.h>
    52 #include <qpainter.h>
    52 #include <qpaintengine.h>
    53 #include <qpaintengine.h>
    53 #include <qwidget.h>
    54 #include <qwidget.h>
    54 #include <qapplication.h>
    55 #include <qapplication.h>
   297     if (widget && widget->internalWinId())
   298     if (widget && widget->internalWinId())
   298         return widget->internalWinId();
   299         return widget->internalWinId();
   299 
   300 
   300     if (!limboWidget) {
   301     if (!limboWidget) {
   301         limboWidget = new QWidget(0);
   302         limboWidget = new QWidget(0);
       
   303         limboWidget->createWinId();
   302         limboWidget->setObjectName(QLatin1String("xp_limbo_widget"));
   304         limboWidget->setObjectName(QLatin1String("xp_limbo_widget"));
       
   305         // We dont need this internal widget to appear in QApplication::topLevelWidgets()
       
   306         if (QWidgetPrivate::allWidgets)
       
   307             QWidgetPrivate::allWidgets->remove(limboWidget);
   303     }
   308     }
   304 
   309 
   305     return limboWidget->winId();
   310     return limboWidget->winId();
   306 }
   311 }
   307 
   312 
   616     if (!painter || !painter->isActive())
   621     if (!painter || !painter->isActive())
   617         return;
   622         return;
   618 
   623 
   619     painter->save();
   624     painter->save();
   620 
   625 
   621     QMatrix m = painter->matrix();
   626     bool complexXForm = painter->deviceTransform().type() > QTransform::TxTranslate;
   622     bool complexXForm = m.m11() != 1.0 || m.m22() != 1.0 || m.m12() != 0.0 || m.m21() != 0.0;
       
   623 
   627 
   624     bool translucentToplevel = false;
   628     bool translucentToplevel = false;
   625     QPaintDevice *pdev = painter->device();
   629     QPaintDevice *pdev = painter->device();
   626     if (pdev->devType() == QInternal::Widget) {
   630     if (pdev->devType() == QInternal::Widget) {
   627         QWidget *win = ((QWidget *) pdev)->window();
   631         QWidget *win = ((QWidget *) pdev)->window();
  1575                     }
  1579                     }
  1576                 }
  1580                 }
  1577                 // This should work, but currently there's an error in the ::drawBackgroundDirectly()
  1581                 // This should work, but currently there's an error in the ::drawBackgroundDirectly()
  1578                 // code, when using the HDC directly..
  1582                 // code, when using the HDC directly..
  1579                 if (useGradient) {
  1583                 if (useGradient) {
  1580                     QStyleOptionTabWidgetFrame frameOpt = *tab;
  1584                     QStyleOptionTabWidgetFrameV2 frameOpt = *tab;
  1581                     frameOpt.rect = widget->rect();
  1585                     frameOpt.rect = widget->rect();
  1582                     QRect contentsRect = subElementRect(SE_TabWidgetTabContents, &frameOpt, widget);
  1586                     QRect contentsRect = subElementRect(SE_TabWidgetTabContents, &frameOpt, widget);
  1583                     QRegion reg = option->rect;
  1587                     QRegion reg = option->rect;
  1584                     reg -= contentsRect;
  1588                     reg -= contentsRect;
  1585                     p->setClipRegion(reg);
  1589                     p->setClipRegion(reg);
  2834             button = proxy()->subControlRect(cc, toolbutton, SC_ToolButton, widget);
  2838             button = proxy()->subControlRect(cc, toolbutton, SC_ToolButton, widget);
  2835             menuarea = proxy()->subControlRect(cc, toolbutton, SC_ToolButtonMenu, widget);
  2839             menuarea = proxy()->subControlRect(cc, toolbutton, SC_ToolButtonMenu, widget);
  2836 
  2840 
  2837             State bflags = toolbutton->state & ~State_Sunken;
  2841             State bflags = toolbutton->state & ~State_Sunken;
  2838             State mflags = bflags;
  2842             State mflags = bflags;
  2839 
  2843             bool autoRaise = flags & State_AutoRaise;
  2840             if (bflags & State_AutoRaise) {
  2844             if (autoRaise) {
  2841                 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled)) {
  2845                 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled)) {
  2842                     bflags &= ~State_Raised;
  2846                     bflags &= ~State_Raised;
  2843                 }
  2847                 }
  2844             }
  2848             }
  2845 
  2849 
  2854             }
  2858             }
  2855 
  2859 
  2856             QStyleOption tool(0);
  2860             QStyleOption tool(0);
  2857             tool.palette = toolbutton->palette;
  2861             tool.palette = toolbutton->palette;
  2858             if (toolbutton->subControls & SC_ToolButton) {
  2862             if (toolbutton->subControls & SC_ToolButton) {
  2859                 if (flags & (State_Sunken | State_On | State_Raised) || !(flags & State_AutoRaise)) {
  2863                 if (flags & (State_Sunken | State_On | State_Raised) || !autoRaise) {
  2860                     if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup) {
  2864                     if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup && autoRaise) {
  2861                         XPThemeData theme(widget, p, QLatin1String("TOOLBAR"));
  2865                         XPThemeData theme(widget, p, QLatin1String("TOOLBAR"));
  2862                         theme.partId = TP_SPLITBUTTON;
  2866                         theme.partId = TP_SPLITBUTTON;
  2863                         theme.rect = button;
  2867                         theme.rect = button;
  2864                         if (!(bflags & State_Enabled))
  2868                         if (!(bflags & State_Enabled))
  2865                             stateId = TS_DISABLED;
  2869                             stateId = TS_DISABLED;
  2874                         if (option->direction == Qt::RightToLeft)
  2878                         if (option->direction == Qt::RightToLeft)
  2875                             theme.mirrorHorizontally = true;
  2879                             theme.mirrorHorizontally = true;
  2876                         theme.stateId = stateId;
  2880                         theme.stateId = stateId;
  2877                         d->drawBackground(theme);
  2881                         d->drawBackground(theme);
  2878                     } else {
  2882                     } else {
  2879                         tool.rect = button;
  2883                         tool.rect = option->rect;
  2880                         tool.state = bflags;
  2884                         tool.state = bflags;
  2881                         if (widget && !qobject_cast<QToolBar*>(widget->parentWidget())
  2885                         if (autoRaise) // for tool bars
  2882                                    && !(bflags & State_AutoRaise))
  2886                             proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
       
  2887                         else
  2883                             proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, p, widget);
  2888                             proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, p, widget);
  2884                         else
       
  2885                             proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
       
  2886                     }
  2889                     }
  2887                 }
  2890                 }
  2888             }
  2891             }
  2889 
  2892 
  2890             if (toolbutton->state & State_HasFocus) {
  2893             if (toolbutton->state & State_HasFocus) {
  2897                 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, p, widget);
  2900                 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, p, widget);
  2898             }
  2901             }
  2899             QStyleOptionToolButton label = *toolbutton;
  2902             QStyleOptionToolButton label = *toolbutton;
  2900             label.state = bflags;
  2903             label.state = bflags;
  2901             int fw = 2;
  2904             int fw = 2;
       
  2905             if (!autoRaise)
       
  2906                 label.state &= ~State_Sunken;
  2902             label.rect = button.adjusted(fw, fw, -fw, -fw);
  2907             label.rect = button.adjusted(fw, fw, -fw, -fw);
  2903             proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget);
  2908             proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget);
  2904 
  2909 
  2905             if (toolbutton->subControls & SC_ToolButtonMenu) {
  2910             if (toolbutton->subControls & SC_ToolButtonMenu) {
  2906                 tool.rect = menuarea;
  2911                 tool.rect = menuarea;
  2907                 tool.state = mflags;
  2912                 tool.state = mflags;
  2908                 proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, p, widget);
  2913                 if (autoRaise) {
       
  2914                     proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, p, widget);
       
  2915                 } else {
       
  2916                     tool.state = mflags;
       
  2917                     menuarea.adjust(-2, 0, 0, 0);
       
  2918                     // Draw menu button
       
  2919                     if ((bflags & State_Sunken) != (mflags & State_Sunken)){
       
  2920                         p->save();
       
  2921                         p->setClipRect(menuarea);
       
  2922                         tool.rect = option->rect;
       
  2923                         proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, p, 0);
       
  2924                         p->restore();
       
  2925                     }
       
  2926                     // Draw arrow
       
  2927                     p->save();
       
  2928                     p->setPen(option->palette.dark().color());
       
  2929                     p->drawLine(menuarea.left(), menuarea.top() + 3,
       
  2930                                 menuarea.left(), menuarea.bottom() - 3);
       
  2931                     p->setPen(option->palette.light().color());
       
  2932                     p->drawLine(menuarea.left() - 1, menuarea.top() + 3,
       
  2933                                 menuarea.left() - 1, menuarea.bottom() - 3);
       
  2934 
       
  2935                     tool.rect = menuarea.adjusted(2, 3, -2, -1);
       
  2936                     proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, p, widget);
       
  2937                     p->restore();
       
  2938                 }
  2909             } else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
  2939             } else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
  2910                 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget);
  2940                 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget);
  2911                 QRect ir = toolbutton->rect;
  2941                 QRect ir = toolbutton->rect;
  2912                 QStyleOptionToolButton newBtn = *toolbutton;
  2942                 QStyleOptionToolButton newBtn = *toolbutton;
  2913                 newBtn.rect = QRect(ir.right() + 4 - mbi, ir.height() - mbi + 4, mbi - 5, mbi - 5);
  2943                 newBtn.rect = QRect(ir.right() + 4 - mbi, ir.height() - mbi + 4, mbi - 5, mbi - 5);
  3747         {
  3777         {
  3748             res = 1;
  3778             res = 1;
  3749             QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask *>(returnData);
  3779             QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask *>(returnData);
  3750             const QStyleOptionTitleBar *titlebar = qstyleoption_cast<const QStyleOptionTitleBar *>(option);
  3780             const QStyleOptionTitleBar *titlebar = qstyleoption_cast<const QStyleOptionTitleBar *>(option);
  3751             if (mask && titlebar) {
  3781             if (mask && titlebar) {
       
  3782                 // Note certain themes will not return the whole window frame but only the titlebar part when
       
  3783                 // queried This function needs to return the entire window mask, hence we will only fetch the mask for the
       
  3784                 // titlebar itself and add the remaining part of the window rect at the bottom.
       
  3785                 int tbHeight = proxy()->pixelMetric(PM_TitleBarHeight, option, widget);
       
  3786                 QRect titleBarRect = option->rect;
       
  3787                 titleBarRect.setHeight(tbHeight);
  3752                 XPThemeData themeData;
  3788                 XPThemeData themeData;
  3753                 if (titlebar->titleBarState & Qt::WindowMinimized) {
  3789                 if (titlebar->titleBarState & Qt::WindowMinimized) {
  3754                     themeData = XPThemeData(widget, 0, QLatin1String("WINDOW"), WP_MINCAPTION, CS_ACTIVE, option->rect);
  3790                     themeData = XPThemeData(widget, 0, QLatin1String("WINDOW"), WP_MINCAPTION, CS_ACTIVE, titleBarRect);
  3755                 } else
  3791                 } else
  3756                     themeData = XPThemeData(widget, 0, QLatin1String("WINDOW"), WP_CAPTION, CS_ACTIVE, option->rect);
  3792                     themeData = XPThemeData(widget, 0, QLatin1String("WINDOW"), WP_CAPTION, CS_ACTIVE, titleBarRect);
  3757                 mask->region = d->region(themeData);
  3793                 mask->region = d->region(themeData) +
       
  3794                                QRect(0, tbHeight, option->rect.width(), option->rect.height() - tbHeight);
  3758             }
  3795             }
  3759         }
  3796         }
  3760         break;
  3797         break;
  3761 #ifndef QT_NO_RUBBERBAND
  3798 #ifndef QT_NO_RUBBERBAND
  3762     case SH_RubberBand_Mask:
  3799     case SH_RubberBand_Mask: