#include "common.h"
#include "panelcommon.h"
--enum State {OFF, ON}; ///< Enumerator for led state
++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
++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 M_TO_KM = 1000; ///< Meters to kilometers conversion
-const qreal OPACITY = 0.50; ///< Opacity of the background in percents
++const qreal M_TO_KM = 1000; ///< Meters to kilometers conversion
IndicatorButton::IndicatorButton(QWidget *parent)
: QToolButton(parent),
+ m_drawTriangle(false),
m_isDraggable(false),
- m_direction(0)
+ m_direction(0),
+ m_distance(0),
- m_distanceText("hetula")
++ m_distanceText("")
{
m_indicatorLeds[OFF].load(":res/images/led_red.png");
m_indicatorLeds[ON].load(":res/images/led_red_s.png");
painter.drawPixmap(CENTER - offset, m_indicatorLeds[OFF]);
}
+ // Distance text
+ painter.setFont(QFont(NOKIA_FONT_SMALL));
+ painter.setPen(Qt::white);
- painter.drawText(10, 60, m_distanceText);
-
- 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)
- };
-
- QTransform rotationTransform;
- rotationTransform.rotate(m_direction);
-
- QTransform translateTransform;
- translateTransform.translate(CENTER.x(), CENTER.y());
-
- painter.setTransform(rotationTransform * translateTransform);
-
- painter.setBrush(Qt::red);
- painter.setPen(Qt::red);
- painter.drawPolygon(points, POINTS);
-
-
++ painter.drawText(2, 60, m_distanceText);
++
+ // 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()
setDraggable(true, m_dragPosition);
}
- void IndicatorButton::updateValues(qreal direction, qreal distance)
+ void IndicatorButton::updateValues(qreal direction, qreal distance, bool draw)
{
- qWarning() << __PRETTY_FUNCTION__ << "direction:" << direction;
+ qDebug() << __PRETTY_FUNCTION__;
m_direction = direction;
+ m_distance = distance;
+ m_drawTriangle = draw;
- qWarning() << "distance:" << distance;
-
- }
-
- qreal IndicatorButton::roundTo(qreal distance)
- {
- qDebug() << __PRETTY_FUNCTION__;
-
- if(distance < M_TO_KM)
++ if(m_distance < 0.01)
+ {
- m_distanceText.setNum(distance * M_TO_KM);
++ m_distanceText.setNum(10);
++ m_distanceText.prepend("< ");
+ m_distanceText.append(" m");
- } else {
- m_distanceText.setNum(distance);
++ }
++ else if((m_distance >= 0.01) && (distance <= 0.999999))
++ {
++ m_distanceText.setNum(distance * 1000,1,1);
++ m_distanceText.append(" m");
++ }
++ else if((m_distance >= 1) && (distance <= 100))
++ {
++ m_distanceText.setNum(distance,1,1);
+ m_distanceText.append(" km");
+ }
++ else {
++ m_distanceText.setNum(distance,0,0);
++ m_distanceText.append(" km");
++ }
++
+ update();
}