Also added draggability to the panel.
const QString OSM_LICENSE = QString::fromUtf8("© OpenStreetMap contributors, CC-BY-SA");
-const int AUTO_CENTERING_DISABLE_DISTANCE = 100; ///< Distance in pixels
+const int AUTO_CENTERING_DISABLE_DISTANCE = 50; ///< Distance in pixels
//String constants for storing map settings:
const QString MAP_LAST_ZOOMLEVEL = "LAST_MAP_ZOOM_LEVEL"; ///< Maps last zoom level before logout
{
qDebug() << __PRETTY_FUNCTION__;
+ m_gpsPosition = position;
+
// update GPS location item (but only if accuracy is a valid number)
if (!isnan(accuracy)) {
qreal resolution = MapScene::horizontalResolutionAtLatitude(position.latitude());
m_gpsLocationItem->updateItem(SceneCoordinate(position).toPointF(), accuracy, resolution);
}
-m_mapScene->spanItems(currentViewSceneRect());
+ m_mapScene->spanItems(currentViewSceneRect());
// do automatic centering (if enabled)
if (m_autoCenteringEnabled) {
qDebug() << __PRETTY_FUNCTION__;
m_autoCenteringEnabled = enabled;
+
+ if (!m_autoCenteringEnabled && m_gpsLocationItem->isVisible())
+ updateDirectionIndicator();
}
void MapEngine::setCenterPosition(SceneCoordinate coordinate)
{
qDebug() << __PRETTY_FUNCTION__;
- /// @todo implement distance calculation
qreal distance = m_gpsPosition.distanceTo(m_sceneCoordinate);
qreal direction = m_sceneCoordinate.azimuthTo(SceneCoordinate(m_gpsPosition));
Situare - A location system for Facebook
Copyright (C) 2010 Ixonos Plc. Authors:
- Kaj Wallin - kaj.wallin@ixonos.com
Katri Kaikkonen - katri.kaikkonen@ixonos.com
+ Kaj Wallin - kaj.wallin@ixonos.com
Sami Rämö - sami.ramo@ixonos.com
Situare is free software; you can redistribute it and/or
USA.
*/
-#include <QDebug>
-#include <QPainter>
#include <QSettings>
-
-#include "math.h"
+#include <QPainter>
+#include <QDebug>
#include "indicatorbutton.h"
-
-#include "common.h"
#include "panelcommon.h"
+#include "common.h"
+#include "math.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 M_TO_KM = 1000; ///< Meters to kilometers conversion
IndicatorButton::IndicatorButton(QWidget *parent)
: QToolButton(parent),
m_drawTriangle(false),
- m_direction(0),
- m_distance(0)
+ m_direction(0)
{
m_indicatorLeds[OFF].load(":res/images/gps_position.png");
m_indicatorLeds[ON].load(":res/images/gps_position_s.png");
delete m_selectedGradient;
}
-void IndicatorButton::mousePressEvent(QMouseEvent *event)
+void IndicatorButton::setDirection(qreal direction, bool draw)
{
qDebug() << __PRETTY_FUNCTION__;
- QToolButton::mousePressEvent(event);
+ m_direction = direction;
+ m_drawTriangle = draw;
- m_eventPosition = mapToParent(event->pos());
+ update();
}
void IndicatorButton::mouseMoveEvent(QMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
- if(rect().contains(event->pos()))
- m_eventPosition = mapToParent(event->pos());
-
QToolButton::mouseMoveEvent(event);
+
+ event->ignore();
+}
+
+void IndicatorButton::mousePressEvent(QMouseEvent *event)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QToolButton::mousePressEvent(event);
+
+ event->ignore();
}
void IndicatorButton::mouseReleaseEvent(QMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
- if(this->rect().contains(event->pos())) {
- if(isChecked()) {
- setChecked(false);
- emit autoCenteringTriggered(false);
- } else {
- setChecked(true);
- emit autoCenteringTriggered(true);
- }
- }
-
-// QToolButton::mouseReleaseEvent(event);
+ QToolButton::mouseReleaseEvent(event);
+
+ event->ignore();
}
const QPoint& IndicatorButton::eventPosition()
}
}
-void IndicatorButton::updateValues(qreal direction, qreal distance, bool draw)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- qWarning() << distance;
-
- m_direction = direction;
- m_distance = distance;
- m_drawTriangle = draw;
-
- qWarning() << m_distance;
- update();
-}
-
-
#define INDICATORBUTTON_H
#include <QMouseEvent>
-#include <QTimer>
#include <QToolButton>
#include <QWidget>
+#include <QTimer>
/**
* @brief Indicator button class
******************************************************************************/
protected:
/**
- * @brief Move event for the distance indicator button
+ * @brief Event handler for mouse move events
*
* @param event Mouse event
*/
void mouseMoveEvent(QMouseEvent *event);
/**
- * @brief Press event for the distance indicator button
+ * @brief Event handler for mouse press events
*
* @param event Mouse event
*/
const QPoint& eventPosition();
/**
- * @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);
-
+ * @brief Sets direction information for the distance indicator button
+ *
+ * Paints the button and its icon
+ * @param Direction to the GPS position (in degrees)
+ * @param Draw direction triangle
+ */
+ void setDirection(qreal direction, bool draw);
/*******************************************************************************
* SIGNALS
*/
void autoCenteringTriggered(bool enabled);
- /**
- * @brief Dragging mode triggered.
- */
- void draggingModeTriggered();
-
/*******************************************************************************
* DATA MEMBERS
******************************************************************************/
bool m_drawTriangle; ///< Should the direction triange be drawn
qreal m_direction; ///< Direction to the GPS position (in degrees)
- qreal m_distance;
QColor *m_normalColor; ///< Normal background color
Pekka Nissinen - pekka.nissinen@ixonos.com
Kaj Wallin - kaj.wallin@ixonos.com
+ Katri Kaikkonen - katri.kaikkonen@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
USA.
*/
-#include <QDebug>
-#include <QPainter>
#include <QSettings>
+#include <QPainter>
+#include <QDebug>
#include "indicatorbuttonpanel.h"
-#include "common.h"
-#include "panelcommon.h"
#include "indicatorbutton.h"
+#include "panelcommon.h"
+#include "common.h"
-const int ROUNDING_RADIUS = 9; ///< Roundness of the background edges
-const qreal OPACITY = 0.50; ///< Opacity of the background in percents
+
+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_isDraggable(false),
m_distanceText("")
{
+ /**
+ * @brief Horizontal position of direction indicator button
+ *
+ * @var DIRECTION_INDICATOR_POSITION_X
+ */
+ const int DIRECTION_INDICATOR_POSITION_X = 10 + PANEL_PEEK_AMOUNT;
+ const int DIRECTION_INDICATOR_POSITION_Y = 290; ///< Vertical position of indicator button
+
+ const QString DIRECTION_INDICATOR_BUTTON_POSITION = "Direction_Indicator_Position";
+
+ const int MARGIN_LEFT = 0; ///< Inner margin (left)
+ const int MARGIN_TOP = 3; ///< Inner margin (top)
+ const int MARGIN_RIGHT = 0; ///< Inner margin (right)
+ const int MARGIN_BOTTOM = 0; ///< Inner margin (bottom)
+ const int LABEL_MARGIN_TOP = 0; ///< Distance text label inner margin (top)
+
+ const int INDICATOR_BUTTON_PANEL_SPACING = 5; ///< Size of a indicator button spacing
+
+ const int PANEL_WIDTH = 90; ///< Width of the draggable panel
+ const int PANEL_HEIGHT = 100; ///< Height of the draggable panel
+
qDebug() << __PRETTY_FUNCTION__;
QVBoxLayout *verticalLayout = new QVBoxLayout;
setLayout(verticalLayout);
- verticalLayout->setContentsMargins(0, 0, 0, 0);
- verticalLayout->setSpacing(5);
+ verticalLayout->setContentsMargins(MARGIN_LEFT, MARGIN_TOP, MARGIN_RIGHT, MARGIN_BOTTOM);
+ verticalLayout->setSpacing(INDICATOR_BUTTON_PANEL_SPACING);
m_indicatorButton = new IndicatorButton(this);
m_distanceTextLabel = new QLabel();
m_distanceTextLabel->setFont(QFont(NOKIA_FONT_SMALL));
- m_distanceTextLabel->setText(m_distanceText);
m_distanceTextLabel->setAlignment(Qt::AlignHCenter);
- m_distanceTextLabel->setContentsMargins(0, 0, 0, 0);
+ m_distanceTextLabel->setContentsMargins(MARGIN_LEFT, LABEL_MARGIN_TOP, MARGIN_RIGHT
+ , MARGIN_BOTTOM);
m_normalColor = new QColor(Qt::black);
m_normalColor->setAlpha(OPACITY * 255);
verticalLayout->addWidget(m_indicatorButton, 0, Qt::AlignHCenter);
verticalLayout->addWidget(m_distanceTextLabel, 0, Qt::AlignHCenter);
verticalLayout->addStretch();
- setFixedSize(90, 100);
+
+ setFixedSize(PANEL_WIDTH, PANEL_HEIGHT);
QSettings settings(DIRECTORY_NAME, FILE_NAME);
QPoint savedLocation = settings.value(DIRECTION_INDICATOR_BUTTON_POSITION,
m_forceReleaseTimer->setSingleShot(true);
m_forceReleaseTimer->setInterval(FORCE_RELEASE_TIME);
- connect(m_indicatorButton, SIGNAL(pressed()),
- m_dragStartTimer, SLOT(start()));
- connect(m_indicatorButton, SIGNAL(released()),
- m_dragStartTimer, SLOT(stop()));
-
connect(m_dragStartTimer, SIGNAL(timeout()),
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)));
+ this, 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)
setDraggable(false);
QSettings settings(DIRECTORY_NAME, FILE_NAME);
- settings.setValue(ZOOMPANEL_POSITION, pos());
+ settings.setValue(DIRECTION_INDICATOR_BUTTON_POSITION, pos());
releaseMouse();
-
-// m_indicatorButton->setDown();
}
}
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
- QPainterPath backgroundPath;
- QRect distanceLabelRect = m_distanceTextLabel->rect();
+ if (!m_indicatorButton->isChecked()) {
+ const int ADJUST_LEFT = -5; ///< Pixels added to the rectangle (left)
+ const int ADJUST_TOP = 0; ///< Pixels added to the rectangle (top)
+ const int ADJUST_RIGHT = +5; ///< Pixels added to the rectangle (right)
+ const int ADJUST_BOTTOM = 0; ///< Pixels added to the rectangle (bottom)
- distanceLabelRect.translate(m_distanceTextLabel->pos());
- distanceLabelRect.adjust(-5, 0, +5, 0);
- backgroundPath.addRoundedRect(distanceLabelRect, 5, 5);
- painter.fillPath(backgroundPath, QBrush(*m_normalColor));
+ const int RADIUS_WIDTH = 5; ///< Roundness width
+ const int RADIUS_HEIGHT = 5; ///< Roundness height
+
+ QPainterPath backgroundPath;
+ QRect distanceLabelRect = m_distanceTextLabel->rect();
+
+ distanceLabelRect.translate(m_distanceTextLabel->pos());
+ distanceLabelRect.adjust(ADJUST_LEFT, ADJUST_TOP, ADJUST_RIGHT, ADJUST_BOTTOM);
+ backgroundPath.addRoundedRect(distanceLabelRect, RADIUS_WIDTH, RADIUS_HEIGHT);
+ painter.fillPath(backgroundPath, QBrush(*m_normalColor));
+
+ update();
+ }
if(m_isDraggable) {
QPainterPath backgroundPath;
qDebug() << __PRETTY_FUNCTION__;
m_isDraggable = mode;
+ emit draggingModeTriggered();
if(mode) {
grabMouse();
update();
}
+void IndicatorButtonPanel::setIndicatorButtonEnabled(bool enabled)
+{
+ m_indicatorButton->setChecked(enabled);
+}
+
void IndicatorButtonPanel::screenResized(const QSize &newSize)
{
qDebug() << __PRETTY_FUNCTION__;
{
qDebug() << __PRETTY_FUNCTION__;
- if(m_indicatorButton->isDown())
- m_dragPosition = m_indicatorButton->eventPosition();
-
setDraggable(true, m_dragPosition);
}
-QString IndicatorButtonPanel::countDistance(qreal m_distance)
+void IndicatorButtonPanel::updateValues(qreal direction, qreal distance, bool draw)
{
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;
+ const int SMALL_REDUCE = 0.5; ///< 0.5 meter reduce
+ const int BIG_REDUCE = 100; ///< 100 meter reduce
+ const qreal M_TO_KM = 1000.0; ///< Meters to kilometers conversion
-}
+ m_indicatorButton->setDirection(direction, draw);
+
+ m_distance = distance;
+
+ if(m_distance < 10.0)
+ {
+ m_distanceText.setNum(10);
+ m_distanceText.prepend("< ");
+ m_distanceText.append(" m");
+ }
+ else if(m_distance < 1000 - SMALL_REDUCE)
+ {
+ m_distanceText.setNum(m_distance, 0 , 0);
+ m_distanceText.append(" m");
+ }
+ else if(m_distance < 100000 - BIG_REDUCE)
+ {
+ m_distanceText.setNum(m_distance / M_TO_KM, 1, 1);
+ m_distanceText.append(" km");
+ }
+ else {
+ m_distanceText.setNum(m_distance / M_TO_KM, 0, 0);
+ m_distanceText.append(" km");
+ }
+
+ if (!m_indicatorButton->isChecked()) {
+ m_distanceTextLabel->setText(m_distanceText);
+ }
+ else {
+ m_distanceTextLabel->setText("");
+ }
+ update();
+ }
Pekka Nissinen - pekka.nissinen@ixonos.com
Kaj Wallin - kaj.wallin@ixonos.com
+ Katri Kaikkonen - katri.kaikkonen@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
#include <QGraphicsItem>
#include <QGridLayout>
-#include <QTimer>
+#include <QMouseEvent>
#include <QWidget>
+#include <QTimer>
#include <QLabel>
-#include <QLineEdit>
-#include <QMouseEvent>
#include "indicatorbutton.h"
/**
- * @brief Panel for zoom buttons
+ * @brief Draggable panel for indicator button
*
+ * @author Katri Kaikkonen - katri.kaikkonen (at) ixonos.com
* @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
* @author Kaj Wallin - kaj.wallin (at) ixonos.com
*/
******************************************************************************/
protected:
/**
- * @brief Move event for the zoom button panel
+ * @brief Move event for the indicator button panel
*
* @param event Event
*/
void mouseMoveEvent(QMouseEvent *event);
/**
- * @brief Press event for the zoom button panel
+ * @brief Press event for the indicator button panel
*
* @param event Event
*/
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
-public:
-// /**
-// * @brief Getter for the zoom in button
-// *
-// * @return Pointer to the zoomInButton
-// */
-// const IndicatorButton* IndicatorButtonPanel::indicatorButton();
-
public slots:
-// /**
-// * @brief Disables the zoom in button
-// */
-// void disableZoomInButton();
-// /**
-// * @brief Disables the zoom out button
-// */
-// void disableZoomOutButton();
-
-// /**
-// * @brief Reset zoom button states to normal
-// */
-// void resetButtons();
+ /**
+ * @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);
- QString countDistance(qreal m_distance);
+ void setIndicatorButtonEnabled(bool enabled);
/**
* @brief Toggle zoom panel draggability
*/
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
******************************************************************************/
+//public:
+// IndicatorButton *m_indicatorButton; ///< Indicator button
+
private:
+ IndicatorButton *m_indicatorButton; ///< Indicator button
+
bool m_isDraggable; ///< Boolean for tracking the draggability state
+ qreal m_distance; ///< Distance to the GPS position
+
QColor *m_normalColor; ///< Normal background color
- QLabel *m_distanceTextLabel; ///< Pointer to locationLabel
+ QLabel *m_distanceTextLabel; ///< Pointer to distanceTextLabel
QPoint m_dragPosition; ///< Location from where the widget is grabbed
QSize m_screenSize; ///< Store for the screen size
- IndicatorButton *m_indicatorButton; ///< Button for zoom in
-
- QString m_distanceText;
+ QString m_distanceText; ///< Text description of the distance
QTimer *m_dragStartTimer; ///< Timer to init draggability of the zoom panel
QTimer *m_forceReleaseTimer; ///< Timer to run forceMouseRelease;
-
-
};
#endif // INDICATORBUTTONPANEL_H
m_indicatorButtonPanel, SLOT(screenResized(QSize)));
connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
- m_indicatorButtonPanel, SIGNAL(updateValues(qreal, qreal, bool)));
+ m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
this, SIGNAL(draggingModeTriggered()));
{
qDebug() << __PRETTY_FUNCTION__;
-// m_indicatorButton->setChecked(enabled);
-
+ m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
}
void MainWindow::setMapViewScene(QGraphicsScene *scene)
FriendListPanel *m_friendsListPanel; ///< Instance of friends list panel
FullScreenButton *m_fullScreenButton; ///< Instance of the fullscreen toggle button
+// IndicatorButton *m_indicatorButton; ///< Instance of direction indicator button
IndicatorButtonPanel *m_indicatorButtonPanel; ///< Instance of direction indicator button
MapScale *m_mapScale; ///< Instance of the map scale
MapView *m_mapView; ///< Instance of the map view
// Zoom button panel settings
const int ZOOM_BUTTON_PANEL_POSITION_X = 10 +
PANEL_PEEK_AMOUNT; ///< Horizontal position of zoom panel
-const int ZOOM_BUTTON_PANEL_POSITION_Y = 10; ///< Vertical position of zoom panel
-const int ZOOM_BUTTON_PANEL_BUTTON_SPACING = 4; ///< Size of a zoom button spacing
+const int ZOOM_BUTTON_PANEL_POSITION_Y = 10; ///< Vertical position of zoom panel
+const int ZOOM_BUTTON_PANEL_BUTTON_SPACING = 4; ///< Size of a zoom button spacing
const QString ZOOMPANEL_POSITION = "Zoom_Panel_Position";
-// Direction indicator button settings
-/**
- * @brief Horizontal position of direction indicator button
- *
- * @var DIRECTION_INDICATOR_POSITION_X
- */
-const int DIRECTION_INDICATOR_POSITION_X = 10 + PANEL_PEEK_AMOUNT;
-const int DIRECTION_INDICATOR_POSITION_Y = 290; ///< Vertical position of direction indicator button
-
-const QString DIRECTION_INDICATOR_BUTTON_POSITION = "Direction_Indicator_Position";
-
#endif // PANELCOMMON_H