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_drawTriangle(false),
+ m_isDraggable(false),
+ m_direction(0)
{
m_indicatorLeds[OFF].load(":res/images/led_red.png");
m_indicatorLeds[ON].load(":res/images/led_red_s.png");
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),
- (this->height() / 2) - (m_indicatorLeds[ON].height() / 2),
- m_indicatorLeds[ON]);
- else
- painter.drawPixmap((this->width() / 2) - (m_indicatorLeds[OFF].width() / 2),
- (this->height() / 2) - (m_indicatorLeds[OFF].height() / 2),
- m_indicatorLeds[OFF]);
+ const QPointF CENTER = QPointF(this->width(), this->height()) / 2;
+
+ if (isChecked()) {
+ const QPointF offset = QPointF(m_indicatorLeds[ON].width(),
+ m_indicatorLeds[ON].height()) / 2;
+
+ painter.drawPixmap(CENTER - offset, m_indicatorLeds[ON]);
+ } else {
+ const QPointF offset = QPointF(m_indicatorLeds[OFF].width(),
+ m_indicatorLeds[OFF].height()) / 2;
+
+ painter.drawPixmap(CENTER - offset, m_indicatorLeds[OFF]);
+ }
+
+ // draw the direction indicator triangle only when autocentering is disabled and MapEngine
+ // doesn't deny drawing (because GPS location item is visible)
+ if (!isChecked() && m_drawTriangle) {
+ const int TRIANGLE_WIDTH = 10;
+ const int TRIANGLE_HEIGHT = 10;
+ const int TRIANGLE_DISTANCE_FROM_CENTER = 15;
+
+ const int POINTS = 3;
+ const QPointF points[POINTS] = {
+ QPointF(-TRIANGLE_WIDTH / 2, -TRIANGLE_DISTANCE_FROM_CENTER),
+ QPointF(0, -(TRIANGLE_DISTANCE_FROM_CENTER + TRIANGLE_HEIGHT)),
+ QPointF(TRIANGLE_WIDTH / 2, -TRIANGLE_DISTANCE_FROM_CENTER)
+ };
+
+ // base triangle is facing up, and needs to be rotated to the required direction
+ QTransform rotationTransform;
+ rotationTransform.rotate(m_direction);
+
+ // origin is in the top left corner of the button, and needs to be translated to the
+ // center of the button
+ QTransform translateTransform;
+ translateTransform.translate(CENTER.x(), CENTER.y());
+
+ painter.setTransform(rotationTransform * translateTransform);
+
+ // setting the look of the triangle
+ painter.setBrush(Qt::red);
+ painter.setPen(Qt::red);
+
+ painter.drawPolygon(points, POINTS);
+ }
}
void IndicatorButton::timerExpired()
{
qDebug() << __PRETTY_FUNCTION__;
- if(this->isDown())
- m_dragPosition = this->eventPosition();
-
setDraggable(true, m_dragPosition);
}
+
+void IndicatorButton::updateValues(qreal direction, qreal distance, bool draw)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_direction = direction;
+ m_drawTriangle = draw;
+
+ update();
+}