enum State {OFF, ON}; ///< Enumerator for led state
-const qreal OPACITY = 0.50; ///< Opacity of the background in percents
const int ROUNDING_RADIUS = 9; ///< Roundness of the rounded edge
const int BUTTON_WIDTH = 66; ///< Button width
const int BUTTON_HEIGHT = 66; ///< Button height
+const qreal OPACITY = 0.50; ///< Opacity of the background in percents
+
IndicatorButton::IndicatorButton(QWidget *parent)
: QToolButton(parent),
m_isDraggable(false)
m_selectedGradient->setColorAt(0.75, QColor(82, 195, 255));
m_selectedGradient->setColorAt(0.98, QColor(115, 215, 255));
- // Item shape path
- m_backgroundPath.addRoundedRect(0, 0, this->rect().width(), this->rect().height(),
- ROUNDING_RADIUS, ROUNDING_RADIUS);
-
m_dragStartTimer = new QTimer(this);
m_dragStartTimer->setSingleShot(true);
m_dragStartTimer->setInterval(DRAG_INIT_TIME);
connect(this, SIGNAL(pressed()),
m_dragStartTimer, SLOT(start()));
-
connect(this, SIGNAL(released()),
m_dragStartTimer, SLOT(stop()));
+ connect(this, SIGNAL(clicked(bool)),
+ this, SIGNAL(autoCenteringTriggered(bool)));
connect(m_dragStartTimer, SIGNAL(timeout()),
this, SLOT(timerExpired()));
-
connect(m_forceReleaseTimer, SIGNAL(timeout()),
this, SLOT(forceMouseRelease()));
- connect(this, SIGNAL(clicked(bool)),
- this, SIGNAL(autoCenteringTriggered(bool)));
-
setCheckable(true);
}
m_eventPosition = mapToParent(event->pos());
m_dragStartTimer->start();
+ setDown(true);
}
void IndicatorButton::mouseMoveEvent(QMouseEvent *event)
move(newLocation);
}
} else {
- if(!rect().contains(event->pos()))
+ if(!rect().contains(event->pos())) {
m_dragStartTimer->stop();
+ setDown(false);
+ }
}
-
- QToolButton::mouseMoveEvent(event);
}
void IndicatorButton::mouseReleaseEvent(QMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
- Q_UNUSED(event);
-
m_dragStartTimer->stop();
if(m_isDraggable) {
setDraggable(false);
QSettings settings(DIRECTORY_NAME, FILE_NAME);
settings.setValue(DIRECTION_INDICATOR_BUTTON_POSITION, pos());
- releaseMouse();
} else {
- if(isChecked()) {
- setChecked(false);
- emit autoCenteringTriggered(false);
- } else {
- setChecked(true);
- emit autoCenteringTriggered(true);
+ if(this->rect().contains(event->pos())) {
+ if(isChecked()) {
+ setChecked(false);
+ emit autoCenteringTriggered(false);
+ } else {
+ setChecked(true);
+ emit autoCenteringTriggered(true);
+ }
}
}
-
- QToolButton::mouseReleaseEvent(event);
+ setDown(false);
}
void IndicatorButton::setDraggable(bool mode, QPoint eventPosition)
m_isDraggable = mode;
if(mode) {
- grabMouse();
m_forceReleaseTimer->start();
m_dragPosition = eventPosition;
} else {
- releaseMouse();
m_forceReleaseTimer->stop();
}
-
update();
}
QPoint resizedPosition = pos();
+#ifdef Q_WS_MAEMO_5
if(newSize.height() < DEFAULT_SCREEN_HEIGHT)
resizedPosition.ry() -= SCREEN_HEIGHT_DIFFERENCE;
else
resizedPosition.ry() += SCREEN_HEIGHT_DIFFERENCE;
+#endif // Q_WS_MAEMO_5
move(resizedPosition);
}
Q_UNUSED(event);
+ QPainterPath backgroundPath;
+ backgroundPath.addRoundedRect(this->rect(), ROUNDING_RADIUS, ROUNDING_RADIUS);
+
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
if(m_isDraggable)
- painter.fillPath(m_backgroundPath, QBrush(Qt::Dense4Pattern));
+ painter.fillPath(backgroundPath, QBrush(Qt::Dense4Pattern));
else if (isDown())
- painter.fillPath(m_backgroundPath, QBrush(*m_selectedGradient));
+ painter.fillPath(backgroundPath, QBrush(*m_selectedGradient));
else
- painter.fillPath(m_backgroundPath, QBrush(*m_normalColor));
+ painter.fillPath(backgroundPath, QBrush(*m_normalColor));
if(isChecked())
painter.drawPixmap((this->width() / 2) - (m_indicatorLeds[ON].width() / 2),
{
qDebug() << __PRETTY_FUNCTION__;
- if(this->isDown())
- m_dragPosition = this->eventPosition();
-
setDraggable(true, m_dragPosition);
}