00001 #include "accountstyle.h"
00002 #include <QDockWidget>
00003 #include <QStyleOptionComplex>
00004 #include <QPainter>
00005
00006 AccountStyle::AccountStyle() : QCommonStyle()
00007 {
00008
00009 }
00010
00011 void AccountStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const
00012 {
00013 if(cc == QStyle::CC_TitleBar)
00014 {
00015 if(const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt))
00016 {
00017 QRect ir;
00018 if(opt->subControls & SC_TitleBarLabel)
00019 {
00020 QColor left = tb->palette.highlight().color();
00021 QColor right = tb->palette.base().color();
00022
00023 QBrush fillBrush(left);
00024 if(left != right)
00025 {
00026 QPoint p1(tb->rect.x(), tb->rect.top() + tb->rect.height()/2);
00027 QPoint p2(tb->rect.right(), tb->rect.top() + tb->rect.height()/2);
00028 QLinearGradient lg(p1, p2);
00029 lg.setColorAt(0, left);
00030 lg.setColorAt(1, right);
00031 fillBrush = lg;
00032 }
00033
00034 p->fillRect(opt->rect, fillBrush);
00035
00036 ir = subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, widget);
00037
00038 p->setPen(tb->palette.highlightedText().color());
00039 p->drawText(ir.x() + 2, ir.y(), ir.width() - 2, ir.height(), Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
00040 }
00041
00042 bool down = false;
00043 QPixmap pm;
00044
00045 QStyleOption tool(0);
00046 tool.palette = tb->palette;
00047 if(tb->subControls & SC_TitleBarCloseButton && tb->titleBarFlags & Qt::WindowSystemMenuHint)
00048 {
00049 ir = subControlRect(CC_TitleBar, tb, SC_TitleBarCloseButton, widget);
00050 down = tb->activeSubControls & SC_TitleBarCloseButton && (opt->state & State_Sunken);
00051 if((tb->titleBarFlags & Qt::WindowType_Mask) == Qt::Tool
00052 #ifndef QT_NO_DOCKWIDGET
00053 || qobject_cast<const QDockWidget *>(widget)
00054 #endif
00055 )
00056 {
00057 pm = standardIcon(SP_DockWidgetCloseButton, &tool, widget).pixmap(10, 10);
00058 }
00059 else
00060 {
00061 pm = standardIcon(SP_TitleBarCloseButton, &tool, widget).pixmap(10, 10);
00062 }
00063 tool.rect = ir;
00064 tool.state = down ? State_Sunken : State_Raised;
00065 drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
00066
00067 p->save();
00068 if(down)
00069 {
00070 p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget), pixelMetric(PM_ButtonShiftVertical, tb, widget));
00071 }
00072 drawItemPixmap(p, ir, Qt::AlignCenter, pm);
00073 p->restore();
00074 }
00075
00076 if(tb->subControls & SC_TitleBarMaxButton && tb->titleBarFlags & Qt::WindowMaximizeButtonHint && !(tb->titleBarState & Qt::WindowMaximized))
00077 {
00078 ir = subControlRect(CC_TitleBar, tb, SC_TitleBarMaxButton, widget);
00079
00080 down = tb->activeSubControls & SC_TitleBarMaxButton && (opt->state & State_Sunken);
00081 pm = standardIcon(SP_TitleBarMaxButton, &tool, widget).pixmap(10, 10);
00082 tool.rect = ir;
00083 tool.state = down ? State_Sunken : State_Raised;
00084 drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
00085
00086 p->save();
00087 if(down)
00088 {
00089 p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget), pixelMetric(PM_ButtonShiftVertical, tb, widget));
00090 }
00091 drawItemPixmap(p, ir, Qt::AlignCenter, pm);
00092 p->restore();
00093 }
00094
00095 if(tb->subControls & SC_TitleBarMinButton && tb->titleBarFlags & Qt::WindowMinimizeButtonHint && !(tb->titleBarState & Qt::WindowMinimized))
00096 {
00097 ir = subControlRect(CC_TitleBar, tb, SC_TitleBarMinButton, widget);
00098 down = tb->activeSubControls & SC_TitleBarMinButton && (opt->state & State_Sunken);
00099 pm = standardIcon(SP_TitleBarMinButton, &tool, widget).pixmap(10, 10);
00100 tool.rect = ir;
00101 tool.state = down ? State_Sunken : State_Raised;
00102 drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
00103
00104 p->save();
00105 if(down)
00106 {
00107 p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget), pixelMetric(PM_ButtonShiftVertical, tb, widget));
00108 }
00109 drawItemPixmap(p, ir, Qt::AlignCenter, pm);
00110 p->restore();
00111 }
00112
00113 bool drawNormalButton = (tb->subControls & SC_TitleBarNormalButton) && (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint) && (tb->titleBarState & Qt::WindowMinimized)) || ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint) && (tb->titleBarState & Qt::WindowMaximized)));
00114
00115 if(drawNormalButton)
00116 {
00117 ir = subControlRect(CC_TitleBar, tb, SC_TitleBarNormalButton, widget);
00118 down = tb->activeSubControls & SC_TitleBarNormalButton && (opt->state & State_Sunken);
00119 pm = standardIcon(SP_TitleBarNormalButton, &tool, widget).pixmap(1, 1);
00120 tool.rect = ir;
00121 tool.state = down ? State_Sunken : State_Raised;
00122 drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
00123
00124 p->save();
00125 if(down)
00126 {
00127 p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget), pixelMetric(PM_ButtonShiftVertical, tb, widget));
00128 }
00129 drawItemPixmap(p, ir, Qt::AlignCenter, pm);
00130 p->restore();
00131 }
00132
00133 if(tb->subControls & SC_TitleBarShadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint && !(tb->titleBarState & Qt::WindowMinimized))
00134 {
00135 ir = subControlRect(CC_TitleBar, tb, SC_TitleBarShadeButton, widget);
00136 down = (tb->activeSubControls & SC_TitleBarShadeButton && (opt->state & State_Sunken));
00137 pm = standardIcon(SP_TitleBarShadeButton, &tool, widget).pixmap(1, 1);
00138 tool.rect = ir;
00139 tool.state = down ? State_Sunken : State_Raised;
00140 drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
00141 p->save();
00142 if(down)
00143 {
00144 p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget), pixelMetric(PM_ButtonShiftVertical, tb, widget));
00145 }
00146 drawItemPixmap(p, ir, Qt::AlignCenter, pm);
00147 p->restore();
00148 }
00149
00150 if(tb->subControls & SC_TitleBarUnshadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint && tb->titleBarState & Qt::WindowMinimized)
00151 {
00152 ir = subControlRect(CC_TitleBar, tb, SC_TitleBarUnshadeButton, widget);
00153
00154 down = tb->activeSubControls & SC_TitleBarUnshadeButton && (opt->state & State_Sunken);
00155 pm = standardIcon(SP_TitleBarUnshadeButton, &tool, widget).pixmap(1, 1);
00156 tool.rect = ir;
00157 tool.state = down ? State_Sunken : State_Raised;
00158 drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
00159 p->save();
00160 if(down)
00161 {
00162 p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget), pixelMetric(PM_ButtonShiftVertical, tb, widget));
00163 }
00164 drawItemPixmap(p, ir, Qt::AlignCenter, pm);
00165 p->restore();
00166 }
00167
00168 if(tb->subControls & SC_TitleBarContextHelpButton && tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
00169 {
00170 ir = subControlRect(CC_TitleBar, tb, SC_TitleBarContextHelpButton, widget);
00171
00172 down = tb->activeSubControls & SC_TitleBarContextHelpButton && (opt->state & State_Sunken);
00173 pm = standardIcon(SP_TitleBarContextHelpButton, &tool, widget).pixmap(1, 1);
00174 tool.rect = ir;
00175 tool.state = down ? State_Sunken : State_Raised;
00176 drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
00177 p->save();
00178 if(down)
00179 {
00180 p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget), pixelMetric(PM_ButtonShiftVertical, tb, widget));
00181 }
00182 drawItemPixmap(p, ir, Qt::AlignCenter, pm);
00183 p->restore();
00184 }
00185
00186 if(tb->subControls & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint)
00187 {
00188 ir = subControlRect(CC_TitleBar, tb, SC_TitleBarSysMenu, widget);
00189 if(!tb->icon.isNull())
00190 {
00191 tb->icon.paint(p, ir);
00192 }
00193 else
00194 {
00195 int iconSize = pixelMetric(PM_SmallIconSize, tb, widget);
00196 pm = standardIcon(SP_TitleBarMenuButton, &tool, widget).pixmap(iconSize, iconSize);
00197 tool.rect = ir;
00198 p->save();
00199 drawItemPixmap(p, ir, Qt::AlignCenter, pm);
00200 p->restore();
00201 }
00202 }
00203 }
00204 }
00205 else
00206 {
00207 QCommonStyle::drawComplexControl(cc, opt, p, widget);
00208 }
00209 }