53 QWidget::paintEvent(event);
55 QStylePainter painter(
this);
56 QStyleOptionButton styleOption;
57 styleOption.initFrom(
this);
59 if (isDown() || isChecked()){
60 styleOption.state |= QStyle::State_On;
63 const QRect
rect = this->rect();
65 const QColor borderColor = QColor(0, 0, 0, 128);
68 const int w = qMin(interiorRect.width(), qMax(8, interiorRect.width() / 2));
69 const int h = qMin(interiorRect.height(), qMax(8, interiorRect.height() / 2));
70 const int marginX = (interiorRect.width() - w) / 2;
71 const int marginY = (interiorRect.height() - h) / 2;
72 interiorRect.adjust(marginX, marginY, -marginX, -marginY);
75 if (
m_d->m_color.alpha() > 0) {
76 QColor fillColor =
m_d->m_color;
78 painter.setBrush(Qt::NoBrush);
79 painter.setPen(QPen(borderColor, 1));
82 fillColor.setAlpha(32);
83 }
else if (!isChecked() && (styleOption.state & QStyle::State_MouseOver) == 0) {
84 fillColor.setAlpha(192);
87 if (isEnabled() && (
m_d->selectionVis ==
FillIn || isChecked())) {
88 painter.fillRect(
rect, fillColor);
89 painter.drawRect(
rect.adjusted(0, 0, -1, -1));
91 painter.fillRect(interiorRect,
92 !isEnabled() ||
m_d->selectionVis ==
Outline || isChecked()
94 : styleOption.palette.window().color());
95 painter.drawRect(interiorRect.adjusted(0, 0, -1, -1));
98 QColor white = QColor(255,255,255);
99 QColor greyOutside = QColor(200,200,200);
100 QColor greyInside = greyOutside;
101 QColor xColor = QColor(0, 0, 0, 128);
105 greyInside.setAlpha(32);
107 }
else if (!isChecked()) {
108 if ((styleOption.state & QStyle::State_MouseOver) == 0) {
109 greyOutside.setAlpha(128);
110 greyInside.setAlpha(128);
111 }
else if (
m_d->selectionVis ==
FillIn) {
112 greyInside.setAlpha(128);
118 painter.setBrush(Qt::NoBrush);
119 painter.setPen(QPen(borderColor, 1));
121 if (isEnabled() && (
m_d->selectionVis ==
FillIn || isChecked())) {
122 painter.fillRect(QRect(
rect.topLeft(),
rect.topRight() + QPoint(0, 2)), greyOutside);
123 painter.fillRect(QRect(
rect.bottomLeft() + QPoint(0, -2),
rect.bottomRight()), greyOutside);
124 painter.fillRect(QRect(
rect.topLeft() + QPoint(0, 3),
rect.bottomLeft() + QPoint(2, -3)), greyOutside);
125 painter.fillRect(QRect(
rect.topRight() + QPoint(-2, 3),
rect.bottomRight() + QPoint(0, -3)), greyOutside);
126 painter.drawRect(
rect.adjusted(0, 0, -1, -1));
128 painter.fillRect(interiorRect, greyInside);
129 const int tileWidth = interiorRect.width() / 2;
130 const int tileHeight = interiorRect.height() / 2;
131 painter.fillRect(interiorRect.adjusted(0, 0, -tileWidth, -tileHeight), white);
132 painter.fillRect(interiorRect.adjusted(tileWidth, tileHeight, 0, 0), white);
133 painter.drawRect(interiorRect.adjusted(0, 0, -1, -1));
134 QRect xRect = interiorRect.adjusted(4, 4, -3, -3);
135 while (xRect.width() <= 8 || xRect.height() <= 8) {
136 xRect.adjust(-1, -1, 1, 1);
138 xRect = xRect.intersected(interiorRect);
139 if (xRect.width() <= 8 || xRect.height() <= 8) {
140 xRect = interiorRect;
141 painter.setPen(QPen(xColor, 1));
143 painter.setPen(QPen(xColor, 2));
145 painter.drawLine(xRect.topLeft(), xRect.bottomRight());
146 painter.drawLine(xRect.bottomLeft(), xRect.topRight());
314 if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) {
315 QMouseEvent* mouseEvent =
static_cast<QMouseEvent*
>(event);
322 }
else if (event->type() == QEvent::MouseButtonRelease) {
323 QMouseEvent* mouseEvent =
static_cast<QMouseEvent*
>(event);
324 QAbstractButton* startingButton =
static_cast<QAbstractButton*
>(obj);
328 if ( startingButton->group() && (mouseEvent->modifiers() & Qt::SHIFT)) {
332 const int buttonsEnabled = viableCheckedButtons.count();
333 const bool shouldChangeIsolation = (buttonsEnabled == 1) && (viableCheckedButtons.first() == startingButton);
334 const bool shouldIsolate = (buttonsEnabled != 1) || !shouldChangeIsolation;
336 Q_FOREACH(QAbstractButton* otherBtn, group->
viableButtons()) {
337 if (otherBtn == startingButton){
338 startingButton->setChecked(
true);
340 otherBtn->setChecked(!shouldIsolate);
345 startingButton->click();
354 }
else if (event->type() == QEvent::MouseMove) {
357 QMouseEvent* mouseEvent =
static_cast<QMouseEvent*
>(event);
358 QWidget* firstClicked =
static_cast<QWidget*
>(obj);
359 const QPointF localPosition = mouseEvent->localPos();
361 if (!firstClicked->rect().contains(localPosition.x(), localPosition.y())) {
362 QAbstractButton* btn =
static_cast<QAbstractButton*
>(obj);
375 QMouseEvent* mouseEvent =
static_cast<QMouseEvent*
>(event);
376 QAbstractButton* startingButton =
static_cast<QAbstractButton*
>(obj);
377 const QPoint currentPosition = mouseEvent->globalPos();
393 const QPoint currentPosition = mouseEvent->globalPos();
395 if (startingButton->group()) {
398 Q_FOREACH(QAbstractButton*
button, allButtons) {
402 const QRect mouseMovement = QRect(upperLeft, lowerRight);