IndicatorButton::IndicatorButton(QWidget *parent)
: QToolButton(parent),
m_drawTriangle(false),
-// m_isDraggable(false),
m_direction(0),
- m_distance(0),
- m_distanceText("")
+ m_distance(0)
{
m_indicatorLeds[OFF].load(":res/images/gps_position.png");
m_indicatorLeds[ON].load(":res/images/gps_position_s.png");
setFixedSize(BUTTON_WIDTH, BUTTON_HEIGHT);
-// QSettings settings(DIRECTORY_NAME, FILE_NAME);
-// QPoint savedLocation = settings.value(DIRECTION_INDICATOR_BUTTON_POSITION,
-// QPoint(DIRECTION_INDICATOR_POSITION_X,
-// DIRECTION_INDICATOR_POSITION_Y)).toPoint();
-
-// if(savedLocation.x() > DEFAULT_SCREEN_WIDTH || savedLocation.y() > DEFAULT_SCREEN_HEIGHT) {
-// savedLocation.rx() = DIRECTION_INDICATOR_POSITION_X;
-// savedLocation.ry() = DIRECTION_INDICATOR_POSITION_Y;
-// }
-
-// move(savedLocation);
-
// Normal background
m_normalColor = new QColor(Qt::black);
m_normalColor->setAlpha(floor(OPACITY * 255));
m_selectedGradient->setColorAt(0.75, QColor(82, 195, 255));
m_selectedGradient->setColorAt(0.98, QColor(115, 215, 255));
-// m_dragStartTimer = new QTimer(this);
-// m_dragStartTimer->setSingleShot(true);
-// m_dragStartTimer->setInterval(DRAG_INIT_TIME);
-
-// m_forceReleaseTimer = new QTimer(this);
-// m_forceReleaseTimer->setSingleShot(true);
-// m_forceReleaseTimer->setInterval(FORCE_RELEASE_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()));
-
setCheckable(true);
}
{
qDebug() << __PRETTY_FUNCTION__;
- if (event->button() == Qt::LeftButton)
- m_dragPosition = event->pos();
+ QToolButton::mousePressEvent(event);
m_eventPosition = mapToParent(event->pos());
-// m_dragStartTimer->start();
-// setDown(true);
}
void IndicatorButton::mouseMoveEvent(QMouseEvent *event)
{
-// qDebug() << __PRETTY_FUNCTION__;
-
-// if(m_isDraggable) {
-// if (event->buttons() & Qt::LeftButton) {
-// QPoint newLocation = mapToParent(event->pos()) - m_dragPosition;
-
-// if (newLocation.x() < SIDEBAR_WIDTH)
-// newLocation.rx() = SIDEBAR_WIDTH;
-// else if (newLocation.x() > m_screenSize.width() - width() - SIDEBAR_WIDTH)
-// newLocation.rx() = m_screenSize.width() - width() - SIDEBAR_WIDTH;
-
-// if (newLocation.y() < 0)
-// newLocation.ry() = 0;
-// else if (newLocation.y() > m_screenSize.height() - height())
-// newLocation.ry() = m_screenSize.height() - height();
-
-// move(newLocation);
-// }
-// } else {
-// if(!rect().contains(event->pos())) {
-// m_dragStartTimer->stop();
-// setDown(false);
-// }
-// }
qDebug() << __PRETTY_FUNCTION__;
if(rect().contains(event->pos()))
m_eventPosition = mapToParent(event->pos());
-// QToolButton::mouseMoveEvent(event);
+ QToolButton::mouseMoveEvent(event);
}
void IndicatorButton::mouseReleaseEvent(QMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
-// m_dragStartTimer->stop();
-
-// if(m_isDraggable) {
-// setDraggable(false);
-// QSettings settings(DIRECTORY_NAME, FILE_NAME);
-// settings.setValue(DIRECTION_INDICATOR_BUTTON_POSITION, pos());
-// } else {
if(this->rect().contains(event->pos())) {
if(isChecked()) {
setChecked(false);
emit autoCenteringTriggered(true);
}
}
- }
-// setDown(false);
-//}
-void IndicatorButton::setDraggable(bool mode, QPoint eventPosition)
-{
-// qDebug() << __PRETTY_FUNCTION__;
-
-// m_isDraggable = mode;
-
-// if(mode) {
-// emit draggingModeTriggered();
-// m_forceReleaseTimer->start();
-// m_dragPosition = eventPosition;
-// } else {
-// m_forceReleaseTimer->stop();
-// }
-// update();
-}
-
-void IndicatorButton::screenResized(const QSize &newSize)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
-// int oldHeight = 0;
-// int oldWidth = 0;
-
-// if(m_screenSize.height() < 0)
-// oldHeight = DEFAULT_NON_FULLSCREEN_HEIGHT;
-// else
-// oldHeight = m_screenSize.height();
-
-// if(m_screenSize.width() < 0)
-// oldWidth = DEFAULT_SCREEN_WIDTH;
-// else
-// oldWidth = m_screenSize.width();
-
-// m_screenSize = newSize;
-
-// QPoint resizedPosition = pos();
-// if(resizedPosition.x() > (newSize.width() - rect().width()))
-// resizedPosition.rx() = newSize.width() - rect().width();
-// else if (resizedPosition.x() < SIDEBAR_WIDTH)
-// resizedPosition.rx() = SIDEBAR_WIDTH;
-// if(resizedPosition.y() > (newSize.height() - rect().height()))
-// resizedPosition.ry() = newSize.height() - rect().height();
-// else if (resizedPosition.y() < 0)
-// resizedPosition.ry() = 0;
-
-// if((pos().y() + rect().center().y()) > (oldHeight/2))
-// resizedPosition.ry() = newSize.height() - (oldHeight - pos().y());
-
-// if((pos().x() + rect().center().x()) > (oldWidth/2))
-// resizedPosition.rx() = newSize.width() - (oldWidth - pos().x());
-
-// move(resizedPosition);
+// QToolButton::mouseReleaseEvent(event);
}
const QPoint& IndicatorButton::eventPosition()
return m_eventPosition;
}
-void IndicatorButton::forceMouseRelease()
-{
-// qDebug() << __PRETTY_FUNCTION__;
-
-// releaseMouse();
-// setDraggable(false);
-}
-
void IndicatorButton::paintEvent(QPaintEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
-// if(m_isDraggable)
-// painter.fillPath(backgroundPath, QBrush(Qt::Dense4Pattern));
if (isDown())
painter.fillPath(backgroundPath, QBrush(*m_selectedGradient));
else
painter.drawPixmap(CENTER - offset, m_indicatorLeds[OFF]);
}
- // Distance text
-// painter.setFont(QFont(NOKIA_FONT_SMALL));
-// painter.setPen(Qt::white);
-// painter.drawText(4, 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) {
}
}
-void IndicatorButton::timerExpired()
-{
-// qDebug() << __PRETTY_FUNCTION__;
-
-// setDraggable(true, m_dragPosition);
-}
-
void IndicatorButton::updateValues(qreal direction, qreal distance, bool draw)
{
qDebug() << __PRETTY_FUNCTION__;
+ qWarning() << distance;
+
m_direction = direction;
m_distance = distance;
m_drawTriangle = draw;
- if(m_distance < 0.01)
- {
- m_distanceText.setNum(10);
- m_distanceText.prepend("< ");
- m_distanceText.append(" m");
- }
- 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");
- }
-
+ qWarning() << m_distance;
update();
}
+
+
const QPoint& eventPosition();
/**
- * @brief Slot to redraw the panel after window resize event
- *
- * @param size Size of the new screen
- */
- void screenResized(const QSize &size);
-
- /**
* @brief Called when direction and distance from current map center point to current GPS
* location is changed
*
*/
void updateValues(qreal direction, qreal distance, bool draw);
- /**
- * @brief Toggle distance indicator button draggability
- */
- void setDraggable(bool mode, QPoint eventPosition = QPoint(0,0));
-
-private slots:
- /**
- * @brief Safeguard slot to release mouse grab if something goes horribly wrong
- */
- void forceMouseRelease();
-
- /**
- * @brief Slot that handles drag initialization once timer has timed out
- */
- void timerExpired();
/*******************************************************************************
* SIGNALS
* DATA MEMBERS
******************************************************************************/
private:
- bool m_drawTriangle; ///< Should the direction triange be drawn
- bool m_isDraggable; ///< Boolean for tracking the draggability state
+ bool m_drawTriangle; ///< Should the direction triange be drawn
- qreal m_direction; ///< Direction to the GPS position (in degrees)
+ qreal m_direction; ///< Direction to the GPS position (in degrees)
qreal m_distance;
QColor *m_normalColor; ///< Normal background color
QPixmap m_indicatorLeds[2]; ///< Placeholder for images
- QPoint m_dragPosition; ///< Location from where the widget is grabbed
- QPoint m_eventPosition; ///< Position of mousePressEvent
-
- QSize m_screenSize; ///< Store for the screen size
-
- QString m_distanceText;
-
- QTimer *m_dragStartTimer; ///< Timer to init draggability of the distance indicator button
- QTimer *m_forceReleaseTimer; ///< Timer to run forceMouseRelease
+ QPoint m_dragPosition; ///< Location from where the widget is grabbed
+ QPoint m_eventPosition; ///< Position of mousePressEvent
};
#endif // INDICATORBUTTON_H
#include <QSettings>
#include "indicatorbuttonpanel.h"
-
#include "common.h"
#include "panelcommon.h"
#include "indicatorbutton.h"
-const int ROUNDING_RADIUS = 9; ///< Roundness of the background edges
+const int ROUNDING_RADIUS = 9; ///< Roundness of the background edges
+const qreal OPACITY = 0.50; ///< Opacity of the background in percents
IndicatorButtonPanel::IndicatorButtonPanel(QWidget *parent)
: QWidget(parent),
m_isDraggable(false),
- m_indicatorButton(0)
+ m_indicatorButton(0),
+ m_distanceText("")
{
qDebug() << __PRETTY_FUNCTION__;
- QGridLayout *gridLayout = new QGridLayout(this);
-
+ QVBoxLayout *verticalLayout = new QVBoxLayout;
+ setLayout(verticalLayout);
+ verticalLayout->setContentsMargins(0, 0, 0, 0);
+ verticalLayout->setSpacing(5);
m_indicatorButton = new IndicatorButton(this);
m_distanceTextLabel = new QLabel();
- m_distanceTextLabel->setFixedWidth(85);
- m_distanceTextLabel->setFrameStyle(QFrame::Panel | QFrame::Raised);
m_distanceTextLabel->setFont(QFont(NOKIA_FONT_SMALL));
- m_distanceTextLabel->setText("<font color='black'> 88888 km");
+ m_distanceTextLabel->setText(m_distanceText);
+ m_distanceTextLabel->setAlignment(Qt::AlignHCenter);
+ m_distanceTextLabel->setContentsMargins(0, 0, 0, 0);
- gridLayout->addWidget(m_indicatorButton, 0, 0);
- gridLayout->addWidget(m_distanceTextLabel, 1, 0);
- setFixedSize(85, 100);
+ m_normalColor = new QColor(Qt::black);
+ m_normalColor->setAlpha(OPACITY * 255);
- setLayout(gridLayout);
+ verticalLayout->addWidget(m_indicatorButton, 0, Qt::AlignHCenter);
+ verticalLayout->addWidget(m_distanceTextLabel, 0, Qt::AlignHCenter);
+ verticalLayout->addStretch();
+ setFixedSize(90, 100);
QSettings settings(DIRECTORY_NAME, FILE_NAME);
QPoint savedLocation = settings.value(DIRECTION_INDICATOR_BUTTON_POSITION,
this, SLOT(timerExpired()));
connect(m_forceReleaseTimer, SIGNAL(timeout()),
this, SLOT(forceMouseRelease()));
+
+ connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
+ m_indicatorButton, SLOT(updateValues(qreal, qreal, bool)));
+
+ connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
+ this, SIGNAL(autoCenteringTriggered(bool)));
+
+ connect(this, SIGNAL(draggingModeTriggered()),
+ this, SIGNAL(draggingModeTriggered()));
}
void IndicatorButtonPanel::mouseMoveEvent(QMouseEvent *event)
if(m_isDraggable) {
setDraggable(false);
-// QSettings settings(DIRECTORY_NAME, FILE_NAME);
-// settings.setValue(DIRECTION_INDICATOR_BUTTON_POSITION, pos());
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ settings.setValue(ZOOMPANEL_POSITION, pos());
releaseMouse();
- m_indicatorButton->setDown(false);
+// m_indicatorButton->setDown();
}
}
Q_UNUSED(event);
QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+
+ QPainterPath backgroundPath;
+ QRect distanceLabelRect = m_distanceTextLabel->rect();
+
+ distanceLabelRect.translate(m_distanceTextLabel->pos());
+ distanceLabelRect.adjust(-5, 0, +5, 0);
+ backgroundPath.addRoundedRect(distanceLabelRect, 5, 5);
+ painter.fillPath(backgroundPath, QBrush(*m_normalColor));
if(m_isDraggable) {
QPainterPath backgroundPath;
painter.fillPath(backgroundPath, QBrush(Qt::Dense4Pattern));
painter.setPen(Qt::black);
}
-
-// painter.setFont(QFont(NOKIA_FONT_SMALL));
-// painter.setPen(Qt::black);
-// painter.drawText(m_distanceTextLabel);
}
void IndicatorButtonPanel::setDraggable(bool mode, QPoint eventPosition)
m_forceReleaseTimer->start();
m_dragPosition = eventPosition;
} else {
+ releaseMouse();
m_forceReleaseTimer->stop();
+ m_indicatorButton->setDown(false);
}
update();
}
{
qDebug() << __PRETTY_FUNCTION__;
+ if(m_indicatorButton->isDown())
+ m_dragPosition = m_indicatorButton->eventPosition();
+
setDraggable(true, m_dragPosition);
}
+QString IndicatorButtonPanel::countDistance(qreal m_distance)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+// QString m_distanceText;
+
+// if(m_distance < 0.01)
+// {
+// m_distanceText.setNum(10);
+// m_distanceText.prepend("< ");
+// m_distanceText.append(" m");
+// }
+// else if((m_distance >= 0.01) && (m_distance <= 0.999999))
+// {
+// m_distanceText.setNum(m_distance * 1000,1,1);
+// m_distanceText.append(" m");
+// }
+// else if((m_distance >= 1) && (m_distance <= 100))
+// {
+// m_distanceText.setNum(m_distance,1,1);
+// m_distanceText.append(" km");
+// }
+// else {
+// m_distanceText.setNum(m_distance,0,0);
+// m_distanceText.append(" km");
+// }
+
+// return m_distanceText;
+// qWarning() << m_distanceText;
+
+}
+
#include <QWidget>
#include <QLabel>
#include <QLineEdit>
+#include <QMouseEvent>
#include "indicatorbutton.h"
// */
// void resetButtons();
+ QString countDistance(qreal m_distance);
+
/**
* @brief Toggle zoom panel draggability
*/
void timerExpired();
/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
+signals:
+
+ /**
+ * @brief Automatic centering setting changed by user
+ *
+ * @param enabled True if automatic centering is enabled, otherwise false
+ */
+ void autoCenteringTriggered(bool enabled);
+
+ /**
+ * @brief Signal when direction and distance from current map center point to current GPS
+ * location is changed
+ *
+ * @param direction Direction in degrees
+ * @param distance Distance in kilometers
+ * @param draw Should the indicator triangle be drawn or not
+ */
+ void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
+
+ /**
+ * @brief Dragging mode triggered.
+ */
+ void draggingModeTriggered();
+
+ /**
+ * @brief Called when direction and distance from current map center point to current GPS
+ * location is changed
+ *
+ * @param direction Direction in degrees
+ * @param distance Distance in kilometers
+ * @param draw Should the indicator triangle be drawn or not
+ */
+ void updateValues(qreal direction, qreal distance, bool draw);
+
+/*******************************************************************************
* DATA MEMBERS
******************************************************************************/
private:
- bool m_isDraggable; ///< Boolean for tracking the draggability state
-
- QLabel *m_distanceTextLabel; ///< Pointer to locationLabel
+ bool m_isDraggable; ///< Boolean for tracking the draggability state
- QPoint m_dragPosition; ///< Location from where the widget is grabbed
+ QColor *m_normalColor; ///< Normal background color
-// QIcon::Mode m_zoomInMode; ///< Store for zoom in button mode before dragging
-// QIcon::Mode m_zoomOutMode; ///< Store for zoom out button mode before dragging
+ QLabel *m_distanceTextLabel; ///< Pointer to locationLabel
- QSize m_screenSize; ///< Store for the screen size
+ QPoint m_dragPosition; ///< Location from where the widget is grabbed
- QTimer *m_dragStartTimer; ///< Timer to init draggability of the zoom panel
- QTimer *m_forceReleaseTimer; ///< Timer to run forceMouseRelease;
+ QSize m_screenSize; ///< Store for the screen size
IndicatorButton *m_indicatorButton; ///< Button for zoom in
+ QString m_distanceText;
+
+ QTimer *m_dragStartTimer; ///< Timer to init draggability of the zoom panel
+ QTimer *m_forceReleaseTimer; ///< Timer to run forceMouseRelease;
+
+
+
};
#endif // INDICATORBUTTONPANEL_H
m_indicatorButtonPanel = new IndicatorButtonPanel(this);
-// connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
-// this, SIGNAL(autoCenteringTriggered(bool)));
+ connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
+ this, SIGNAL(autoCenteringTriggered(bool)));
-// connect(m_mapView, SIGNAL(viewResized(QSize)),
-// m_indicatorButton, SLOT(screenResized(QSize)));
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ m_indicatorButtonPanel, SLOT(screenResized(QSize)));
-// connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
-// m_indicatorButton, SLOT(updateValues(qreal, qreal, bool)));
+ connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
+ m_indicatorButtonPanel, SIGNAL(updateValues(qreal, qreal, bool)));
-// connect(m_indicatorButton, SIGNAL(draggingModeTriggered()),
-// this, SIGNAL(draggingModeTriggered()));
+ connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
+ this, SIGNAL(draggingModeTriggered()));
}
void MainWindow::buildInformationBox(const QString &message, bool modal)