46 #include <QPainterPath>
47 #include <QPixmapCache>
48 #include <QRadioButton>
50 #include <QStyleOption>
55 if (QPixmap *p = QPixmapCache::find(img))
59 pm = QPixmap::fromImage(QImage(img), Qt::OrderedDither | Qt::OrderedAlphaDither);
63 QPixmapCache::insert(img, pm);
71 Q_INIT_RESOURCE(shared);
78 qreal h2 = r.height() / qreal(2);
80 path.addRect(r.x() + h2, r.y() + 0, r.width() - h2 * 2, r.height());
81 path.addEllipse(r.x(), r.y(), h, h);
82 path.addEllipse(r.x() + r.width() - h, r.y(), h, h);
83 path.setFillRule(Qt::WindingFill);
84 painter->setPen(Qt::NoPen);
85 painter->setBrush(QColor(191, 215, 191));
86 painter->setRenderHint(QPainter::Antialiasing);
87 painter->drawPath(path);
92 QPainter *painter,
const QWidget *widget)
const
97 case PE_FrameFocusRect:
100 case PE_IndicatorRadioButton:
101 if (
const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
102 bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver);
108 if (button->state & State_Sunken)
109 radio =
cached(
":res/images/radiobutton-on.png");
110 else if (button->state & State_On)
111 radio =
cached(
":res/images/radiobutton_on.png");
113 radio =
cached(
":res/images/radiobutton_off.png");
114 painter->drawPixmap(button->rect.topLeft(), radio);
120 case PE_PanelButtonCommand:
121 if (
const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
122 bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver);
125 const QPushButton *pushButton = qobject_cast<
const QPushButton *>(widget);
126 Q_ASSERT(pushButton);
127 QWidget *parent = pushButton->parentWidget();
128 if (parent && qobject_cast<QGroupBox *>(parent)) {
129 QLinearGradient lg(0, 0, 0, parent->height());
130 lg.setColorAt(0, QColor(224,224,224));
131 lg.setColorAt(1, QColor(255,255,255));
132 painter->setPen(Qt::NoPen);
133 painter->setBrush(lg);
134 painter->setBrushOrigin(-widget->mapToParent(QPoint(0,0)));
135 painter->drawRect(button->rect);
136 painter->setBrushOrigin(0,0);
139 bool down = (button->state & State_Sunken) || (button->state & State_On);
141 QPixmap left, right, mid;
143 left =
cached(
":res/images/button_pressed_cap_left.png");
144 right =
cached(
":res/images/button_pressed_cap_right.png");
145 mid =
cached(
":res/images/button_pressed_stretch.png");
147 left =
cached(
":res/images/button_normal_cap_left.png");
148 right =
cached(
":res/images/button_normal_cap_right.png");
149 mid =
cached(
":res/images/button_normal_stretch.png");
151 painter->drawPixmap(button->rect.topLeft(), left);
152 painter->drawTiledPixmap(QRect(button->rect.x() + left.width(),
154 button->rect.width() - left.width() - right.width(),
157 painter->drawPixmap(button->rect.x() + button->rect.width() - right.width(),
161 painter->fillRect(widget->rect().adjusted(3,5,-3,-5), QColor(31,127,31,63));
166 case PE_FrameGroupBox:
167 if (
const QStyleOptionFrameV2 *group
168 = qstyleoption_cast<const QStyleOptionFrameV2 *>(option)) {
169 const QRect &r = group->rect;
173 int radius2 = radius*2;
174 QPainterPath clipPath;
175 clipPath.moveTo(radius, 0);
176 clipPath.arcTo(r.right() - radius2, 0, radius2, radius2, 90, -90);
177 clipPath.arcTo(r.right() - radius2, r.bottom() - radius2, radius2, radius2, 0, -90);
178 clipPath.arcTo(r.left(), r.bottom() - radius2, radius2, radius2, 270, -90);
179 clipPath.arcTo(r.left(), r.top(), radius2, radius2, 180, -90);
180 painter->setClipPath(clipPath);
181 QPixmap titleStretch =
cached(
":res/images/title_stretch.png");
182 QPixmap topLeft =
cached(
":res/images/groupframe_topleft.png");
183 QPixmap topRight =
cached(
":res/images/groupframe_topright.png");
184 QPixmap bottomLeft =
cached(
":res/images/groupframe_bottom_left.png");
185 QPixmap bottomRight =
cached(
":res/images/groupframe_bottom_right.png");
186 QPixmap leftStretch =
cached(
":res/images/groupframe_left_stretch.png");
187 QPixmap topStretch =
cached(
":res/images/groupframe_top_stretch.png");
188 QPixmap rightStretch =
cached(
":res/images/groupframe_right_stretch.png");
189 QPixmap bottomStretch =
cached(
":res/images/groupframe_bottom_stretch.png");
190 QLinearGradient lg(0, 0, 0, r.height());
191 lg.setColorAt(0, QColor(224,224,224));
192 lg.setColorAt(1, QColor(255,255,255));
193 painter->setPen(Qt::NoPen);
194 painter->setBrush(lg);
195 painter->drawRect(r.adjusted(0, titleStretch.height()/2, 0, 0));
196 painter->setClipping(
false);
198 int topFrameOffset = titleStretch.height()/2 - 2;
199 painter->drawPixmap(r.topLeft() + QPoint(0, topFrameOffset), topLeft);
200 painter->drawPixmap(r.topRight() - QPoint(topRight.width()-1, 0)
201 + QPoint(0, topFrameOffset), topRight);
202 painter->drawPixmap(r.bottomLeft() - QPoint(0, bottomLeft.height()-1), bottomLeft);
203 painter->drawPixmap(r.bottomRight() - QPoint(bottomRight.width()-1,
204 bottomRight.height()-1), bottomRight);
207 left.setY(r.y() + topLeft.height() + topFrameOffset);
208 left.setWidth(leftStretch.width());
209 left.setHeight(r.height() - topLeft.height() - bottomLeft.height() - topFrameOffset);
210 painter->drawTiledPixmap(left, leftStretch);
213 top.setX(r.x() + topLeft.width());
214 top.setY(r.y() + topFrameOffset);
215 top.setWidth(r.width() - topLeft.width() - topRight.width());
216 top.setHeight(topLeft.height());
217 painter->drawTiledPixmap(top, topStretch);
220 right.setX(r.right() - rightStretch.width()+1);
221 right.setY(r.y() + topRight.height() + topFrameOffset);
222 right.setWidth(rightStretch.width());
223 right.setHeight(r.height() - topRight.height()
224 - bottomRight.height() - topFrameOffset);
225 painter->drawTiledPixmap(right, rightStretch);
228 bottom.setX(r.x() + bottomLeft.width());
229 bottom.setY(r.bottom() - bottomStretch.height()+1);
230 bottom.setWidth(r.width() - bottomLeft.width() - bottomRight.width());
231 bottom.setHeight(bottomLeft.height());
232 painter->drawTiledPixmap(bottom, bottomStretch);
238 QCommonStyle::drawPrimitive(element, option, painter, widget);
246 QPainter *painter,
const QWidget *widget)
const
250 if (
const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
251 QRect groove =
subControlRect(CC_Slider, option, SC_SliderGroove, widget);
252 QRect handle =
subControlRect(CC_Slider, option, SC_SliderHandle, widget);
256 bool hover = (slider->state & State_Enabled) && (slider->state & State_MouseOver);
258 QRect moderated = widget->rect().adjusted(0, 4, 0, -4);
262 if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
263 QPixmap grv =
cached(
":res/images/slider_bar.png");
264 painter->drawPixmap(QRect(groove.x() + 5, groove.y(),
265 groove.width() - 10, grv.height()),
268 if ((option->subControls & SC_SliderHandle) && handle.isValid()) {
269 QPixmap hndl =
cached(
":res/images/slider_thumb_on.png");
270 painter->drawPixmap(handle.topLeft(), hndl);
277 if (
const QStyleOptionGroupBox *groupBox
278 = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
279 QStyleOptionGroupBox groupBoxCopy(*groupBox);
280 groupBoxCopy.subControls &= ~SC_GroupBoxLabel;
281 QCommonStyle::drawComplexControl(control, &groupBoxCopy, painter, widget);
283 if (groupBox->subControls & SC_GroupBoxLabel) {
284 const QRect &r = groupBox->rect;
285 QPixmap titleLeft =
cached(
":res/images/title_cap_left.png");
286 QPixmap titleRight =
cached(
":res/images/title_cap_right.png");
287 QPixmap titleStretch =
cached(
":res/images/title_stretch.png");
288 int txt_width = groupBox->fontMetrics.width(groupBox->text) + 20;
289 painter->drawPixmap(r.center().x() - txt_width/2, 0, titleLeft);
290 QRect tileRect =
subControlRect(control, groupBox, SC_GroupBoxLabel, widget);
291 painter->drawTiledPixmap(tileRect, titleStretch);
292 painter->drawPixmap(tileRect.x() + tileRect.width(), 0, titleRight);
294 painter->setPen(QColor(0, 0, 0, opacity));
295 painter->drawText(tileRect.translated(0, 1),
296 Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text);
297 painter->drawText(tileRect.translated(2, 1),
298 Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text);
299 painter->setPen(QColor(0, 0, 0, opacity * 2));
300 painter->drawText(tileRect.translated(1, 1),
301 Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text);
302 painter->setPen(Qt::white);
303 painter->drawText(tileRect, Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text);
308 QCommonStyle::drawComplexControl(control, option, painter, widget);
315 QPainter *painter,
const QWidget *widget)
const
318 case CE_RadioButtonLabel:
319 if (
const QStyleOptionButton *button
320 = qstyleoption_cast<const QStyleOptionButton *>(option)) {
322 if (button->text.isEmpty()) {
323 QCommonStyle::drawControl(element, option, painter, widget);
326 painter->setPen(Qt::black);
327 painter->drawText(button->rect, Qt::AlignVCenter, button->text);
332 case CE_PushButtonLabel:
333 if (
const QStyleOptionButton *button
334 = qstyleoption_cast<const QStyleOptionButton *>(option)) {
336 if (button->text.isEmpty()) {
337 QCommonStyle::drawControl(element, option, painter, widget);
340 painter->setPen(Qt::black);
341 painter->drawText(button->rect, Qt::AlignVCenter | Qt::AlignHCenter, button->text);
347 QCommonStyle::drawControl(element, option, painter, widget);
353 SubControl subControl,
const QWidget *widget)
const
359 rect = QCommonStyle::subControlRect(control, option, subControl, widget);
362 if (
const QStyleOptionGroupBox *group
363 = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
364 switch (subControl) {
366 rect = QCommonStyle::subControlRect(control, option, subControl, widget);
368 case SC_GroupBoxContents:
369 rect = QCommonStyle::subControlRect(control, option, subControl, widget);
370 rect.adjust(0, -8, 0, 0);
372 case SC_GroupBoxFrame:
375 case SC_GroupBoxLabel:
376 QPixmap titleLeft =
cached(
":res/images/title_cap_left.png");
377 QPixmap titleRight =
cached(
":res/images/title_cap_right.png");
378 QPixmap titleStretch =
cached(
":res/images/title_stretch.png");
379 int txt_width = group->fontMetrics.width(group->text) + 20;
380 rect = QRect(group->rect.center().x() - txt_width/2 + titleLeft.width(), 0,
381 txt_width - titleLeft.width() - titleRight.width(),
382 titleStretch.height());
389 if (control == CC_Slider && subControl == SC_SliderHandle) {
392 }
else if (control == CC_Slider && subControl == SC_SliderGroove) {
394 rect.moveTop(27/2 - 9/2);
400 const QSize &size,
const QWidget *widget)
const
402 QSize newSize = QCommonStyle::sizeFromContents(type, option, size, widget);
407 newSize += QSize(20, 0);
411 newSize.setHeight(26);
415 newSize.setHeight(27);
427 if (pm == PM_SliderLength)
429 return QCommonStyle::pixelMetric(pm, opt, widget);
434 if (widget->layout() && qobject_cast<QGroupBox *>(widget)) {
435 if (widget->findChildren<QGroupBox *>().size() == 0) {
436 widget->layout()->setSpacing(0);
437 widget->layout()->setMargin(12);
439 widget->layout()->setMargin(13);
443 if (qobject_cast<QPushButton *>(widget)
444 || qobject_cast<QRadioButton *>(widget)
445 || qobject_cast<QSlider *>(widget)) {
446 widget->setAttribute(Qt::WA_Hover);
449 QPalette pal = widget->palette();
450 if (widget->isWindow()) {
451 pal.setColor(QPalette::Background, QColor(241, 241, 241));
452 widget->setPalette(pal);
459 if (qobject_cast<QPushButton *>(widget)
460 || qobject_cast<QRadioButton *>(widget)
461 || qobject_cast<QSlider *>(widget)) {
462 widget->setAttribute(Qt::WA_Hover,
false);
468 palette.setColor(QPalette::Background, QColor(241, 241, 241));
475 case SE_RadioButtonClickRect:
478 case SE_RadioButtonContents:
479 r = widget->rect().adjusted(20, 0, 0, 0);
482 r = QCommonStyle::subElementRect(element, option, widget);
486 if (qobject_cast<const QRadioButton*>(widget))
487 r = r.adjusted(5, 0, -5, 0);