const int MIN_UPDATE_INTERVAL_MSECS = 5*60*1000;
SituareEngine::SituareEngine()
- : //m_autoCenteringEnabled(false),
+ : m_autoCenteringEnabled(false),
m_automaticUpdateFirstStart(true),
m_automaticUpdateRequest(false),
m_userMoved(false),
QSettings settings(DIRECTORY_NAME, FILE_NAME);
settings.setValue(SETTINGS_GPS_ENABLED, m_gps->isRunning());
-// settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
+ settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
}
-//void SituareEngine::changeAutoCenteringSetting(bool enabled)
-//{
-// qDebug() << __PRETTY_FUNCTION__;
+void SituareEngine::changeAutoCenteringSetting(bool enabled)
+{
+ qDebug() << __PRETTY_FUNCTION__;
-// m_autoCenteringEnabled = enabled;
-// enableAutoCentering(enabled);
-//}
+ m_autoCenteringEnabled = enabled;
+ enableAutoCentering(enabled);
+}
-//void SituareEngine::disableAutoCentering()
-//{
-// qDebug() << __PRETTY_FUNCTION__;
+void SituareEngine::disableAutoCentering()
+{
+ qDebug() << __PRETTY_FUNCTION__;
-// changeAutoCenteringSetting(false);
-// m_ui->buildInformationBox(tr("Auto centering disabled"));
-//}
+ changeAutoCenteringSetting(false);
+ m_ui->buildInformationBox(tr("Auto centering disabled"));
+}
-//void SituareEngine::enableAutoCentering(bool enabled)
-//{
-// qDebug() << __PRETTY_FUNCTION__;
+void SituareEngine::enableAutoCentering(bool enabled)
+{
+ qDebug() << __PRETTY_FUNCTION__;
-// m_ui->setAutoCenteringButtonEnabled(enabled);
-// m_mapEngine->setAutoCentering(enabled);
+ m_ui->setIndicatorButtonEnabled(enabled);
+ m_mapEngine->setAutoCentering(enabled);
-// if (enabled)
-// m_gps->requestLastPosition();
-//}
+ if (enabled)
+ m_gps->requestLastPosition();
+}
void SituareEngine::enableGPS(bool enabled)
{
if (enabled && !m_gps->isRunning()) {
m_gps->start();
-// enableAutoCentering(m_autoCenteringEnabled);
+ enableAutoCentering(m_autoCenteringEnabled);
m_gps->requestLastPosition();
if(m_ui->loginState())
}
else if (!enabled && m_gps->isRunning()) {
m_gps->stop();
-// enableAutoCentering(false);
+ enableAutoCentering(false);
enableAutomaticLocationUpdate(false);
}
}
m_gps->enablePowerSave(enabled);
-// if(m_autoCenteringEnabled)
-// m_mapEngine->setAutoCentering(!enabled);
+ if(m_autoCenteringEnabled)
+ m_mapEngine->setAutoCentering(!enabled);
}
void SituareEngine::error(const int context, const int error)
QSettings settings(DIRECTORY_NAME, FILE_NAME);
QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
-// QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
+ QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
if (m_gps->isInitialized()) {
connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
this, SLOT(setFirstStartZoomLevel()));
-// changeAutoCenteringSetting(true);
+ changeAutoCenteringSetting(true);
enableGPS(true);
m_ui->buildInformationBox(tr("GPS enabled"));
m_ui->buildInformationBox(tr("Auto centering enabled"));
} else { // Normal start
-// changeAutoCenteringSetting(autoCenteringEnabled.toBool());
+ changeAutoCenteringSetting(autoCenteringEnabled.toBool());
enableGPS(gpsEnabled.toBool());
if (gpsEnabled.toBool())
m_ui->buildInformationBox(tr("GPS enabled"));
- if (gpsEnabled.toBool()) /*&& autoCenteringEnabled.toBool())*/
+ if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
m_ui->buildInformationBox(tr("Auto centering enabled"));
}
} else {
{
qDebug() << __PRETTY_FUNCTION__;
-// if (m_autoCenteringEnabled) // autocentering is disabled when map is scrolled
-// m_mapEngine->setZoomLevel(DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE);
+ if (m_autoCenteringEnabled) // autocentering is disabled when map is scrolled
+ m_mapEngine->setZoomLevel(DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE);
disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
this, SLOT(setFirstStartZoomLevel()));
m_mapEngine, SLOT(zoomOut()));
// signals from menu buttons
-// connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
-// this, SLOT(changeAutoCenteringSetting(bool)));
-
connect(m_ui, SIGNAL(gpsTriggered(bool)),
this, SLOT(enableGPS(bool)));
// signals from friend list tab
connect(m_ui, SIGNAL(findFriend(GeoCoordinate)),
m_mapEngine, SLOT(centerToCoordinates(GeoCoordinate)));
+
+ // signals from distence indicator button
+ connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
+ this, SLOT(changeAutoCenteringSetting(bool)));
}
void SituareEngine::signalsFromMapEngine()
connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
m_ui, SIGNAL(zoomLevelChanged(int)));
-// connect(m_mapEngine, SIGNAL(mapScrolledManually()),
-// this, SLOT(disableAutoCentering()));
+ connect(m_mapEngine, SIGNAL(mapScrolledManually()),
+ this, SLOT(disableAutoCentering()));
connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
m_ui, SIGNAL(maxZoomLevelReached()));
*
* @param enabled true if enabled, false otherwise
*/
-// void changeAutoCenteringSetting(bool enabled);
+ void changeAutoCenteringSetting(bool enabled);
/**
* @brief Slot for disabling automatic centering when map is scrolled manually
*/
-// void disableAutoCentering();
+ void disableAutoCentering();
/**
* @brief Slot for auto centering enabling.
*
* @param enabled true if auto centering was enabled, false otherwise
*/
-// void enableAutoCentering(bool enabled);
+ void enableAutoCentering(bool enabled);
/**
* @brief Slot for gps enabling.
* DATA MEMBERS
******************************************************************************/
private:
-// bool m_autoCenteringEnabled; ///< Auto centering flag
+ bool m_autoCenteringEnabled; ///< Auto centering flag
bool m_automaticUpdateFirstStart; ///< Automatic location update first start flag
bool m_automaticUpdateRequest; ///< Flag for automatic update request
bool m_userMoved; ///< Flag for user move
const qreal OPACITY = 0.13; ///< Opacity of the background in percents
const int BUTTON_WIDTH = 66; ///< Button width
const int BUTTON_HEIGHT = 66; ///< Button height
+const int DRAGGABLE_BUTTON_WIDTH = 85;
+const int DRAGGABLE_BUTTON_HEIGHT = 85;
IndicatorButton::IndicatorButton(QWidget *parent)
: QToolButton(parent),
setIcon(QIcon::fromTheme(QLatin1String("general_fullsize")));
setFixedSize(BUTTON_WIDTH, BUTTON_HEIGHT);
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ move(settings.value(DIRECTION_INDICATOR_BUTTON_POSITION,
+ QPoint(DIRECTION_INDICATOR_POSITION_X,
+ DIRECTION_INDICATOR_POSITION_Y)).toPoint());
+
QPalette pal = palette();
QColor backgroundColor = pal.color(backgroundRole());
backgroundColor.setAlpha(floor(OPACITY * 255));
connect(m_forceReleaseTimer, SIGNAL(timeout()),
this, SLOT(forceMouseRelease()));
- connect(this, SIGNAL(triggered(bool)),
- this, SIGNAL(autoCenteringTriggered(bool)));
-
- // Create mask to round the corners of the background
- QRegion maskbase(rect());
-
- // left top corner
- QRegion leftTopBase(QRect(0, 0, ROUNDING_RADIUS, ROUNDING_RADIUS));
- QRegion leftTopRounding(QRect(0, 0, 2 * ROUNDING_RADIUS, 2 * ROUNDING_RADIUS), QRegion::Ellipse);
- QRegion leftTopClipped = leftTopBase.subtract(leftTopRounding);
-
- // right top corner
- QRegion rightTopBase(QRect(rect().width() - ROUNDING_RADIUS, 0,
- rect().width(), ROUNDING_RADIUS));
- QRegion rightTopRounding(QRect(rect().width() - 2 * ROUNDING_RADIUS, 0,
- 2 * ROUNDING_RADIUS, 2 * ROUNDING_RADIUS), QRegion::Ellipse);
- QRegion rightTopClipped = rightTopBase.subtract(rightTopRounding);
-
- // left bottom corner
- QRegion leftBottomBase(QRect(0, rect().height() - ROUNDING_RADIUS,
- ROUNDING_RADIUS, rect().height()));
- QRegion leftBottomRounding(QRect(0, rect().height() - 2 * ROUNDING_RADIUS,
- 2 * ROUNDING_RADIUS, 2 * ROUNDING_RADIUS), QRegion::Ellipse);
- QRegion leftBottomClipped = leftBottomBase.subtract(leftBottomRounding);
+ connect(this, SIGNAL(clicked(bool)),
+ this, SIGNAL(autoCenteringTriggered(bool)));
- // right bottom corner
- QRegion rightBottomBase(QRect(rect().width() - ROUNDING_RADIUS, rect().height()- ROUNDING_RADIUS,
- rect().height() - ROUNDING_RADIUS, rect().width()- ROUNDING_RADIUS));
- QRegion rightBottomRounding(QRect(rect().width() - 2 * ROUNDING_RADIUS, rect().height() - 2 * ROUNDING_RADIUS,
- 2 * ROUNDING_RADIUS, 2 * ROUNDING_RADIUS), QRegion::Ellipse);
- QRegion rightBottomClipped = rightBottomBase.subtract(rightBottomRounding);
-
- QRegion cutter = leftTopClipped.unite(rightTopClipped.unite(leftBottomClipped.unite(rightBottomClipped)));
-
- QRegion mask = maskbase.subtract(cutter);
-
- setMask(mask);
+ setCheckable(true);
}
void IndicatorButton::mousePressEvent(QMouseEvent *event)
if (event->button() == Qt::LeftButton) {
m_dragPosition = event->pos();
}
+ m_eventPosition = mapToParent(event->pos());
m_dragStartTimer->start();
- QWidget::mousePressEvent(event);
+// QToolButton::mousePressEvent(event);
}
void IndicatorButton::mouseMoveEvent(QMouseEvent *event)
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;
+// 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();
+// else if (newLocation.y() > m_screenSize.height() - height())
+// newLocation.ry() = m_screenSize.height() - height();
move(newLocation);
}
if(!rect().contains(event->pos()))
m_dragStartTimer->stop();
- QWidget::mouseMoveEvent(event);
+ QToolButton::mouseMoveEvent(event);
}
void IndicatorButton::mouseReleaseEvent(QMouseEvent *event)
Q_UNUSED(event);
if(m_isDraggable) {
setDraggable(false);
-// QSettings settings(DIRECTORY_NAME, FILE_NAME);
-// settings.setValue(ZOOMPANEL_POSITION, pos());
+ 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);
+ }
}
- QWidget::mouseReleaseEvent(event);
+ QToolButton::mouseReleaseEvent(event);
}
void IndicatorButton::setDraggable(bool mode, QPoint eventPosition)
m_isDraggable = mode;
if(mode) {
+ setFixedSize(DRAGGABLE_BUTTON_WIDTH, DRAGGABLE_BUTTON_HEIGHT);
setAutoFillBackground(true);
grabMouse();
m_forceReleaseTimer->start();
m_dragPosition = eventPosition;
} else {
- setAutoFillBackground(false);
+ setFixedSize(BUTTON_WIDTH, BUTTON_HEIGHT);
+ setAutoFillBackground(true);
releaseMouse();
m_forceReleaseTimer->stop();
-
}
}
setDraggable(true, m_dragPosition);
}
+
+//void IndicatorButton::paintEvent(QPaintEvent *event)
+//{
+// qDebug() << __PRETTY_FUNCTION__;
+
+// QToolButton::paintEvent(event);
+
+//}
protected:
/**
- * @brief Move event for the zoom button panel
+ * @brief Move event for the distance indicator button
*
* @param event Event
*/
void mouseMoveEvent(QMouseEvent *event);
/**
- * @brief Press event for the zoom button panel
+ * @brief Press event for the distance indicator button
*
* @param event Event
*/
*/
void mouseReleaseEvent(QMouseEvent *event);
+// void paintEvent(QPaintEvent *event);
+
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
const QPoint& eventPosition();
/**
- * @brief Toggle zoom panel draggability
+ * @brief Toggle distance indicator button draggability
*/
void setDraggable(bool mode, QPoint eventPosition = QPoint(0,0));
-// /**
-// * @brief Slot to redraw the panel after window resize event
-// *
-// * @param size Size of the new screen
-// */
-// void screenResized(const QSize &size);
-
private slots:
/**
* @brief Safeguard slot to release mouse grab if something goes horribly wrong
bool m_isDraggable; ///< Boolean for tracking the draggability state
QPoint m_dragPosition; ///< Location from where the widget is grabbed
- QPoint m_eventPosition; ///< Position of mousePressEvent
+ QPoint m_eventPosition; ///< Position of mousePressEvent
QSize m_screenSize; ///< Store for the screen size
- QTimer *m_dragStartTimer; ///< Timer to init draggability of the zoom panel
+ QTimer *m_dragStartTimer; ///< Timer to init draggability of the distance indicator button
QTimer *m_forceReleaseTimer; ///< Timer to run forceMouseRelease;
};
m_mapScale->stackUnder(m_indicatorButton);
m_mapView->stackUnder(m_mapScale);
-
grabZoomKeys(true);
// Set default screen size
m_indicatorButton = new IndicatorButton(this);
- connect(m_indicatorButton, SIGNAL(triggered(bool)),
+ connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
this, SIGNAL(autoCenteringTriggered(bool)));
-
}
void MainWindow::buildInformationBox(const QString &message, bool modal)
connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
this, SIGNAL(gpsTriggered(bool)));
- // automatic centering
-// m_autoCenteringAct = new QAction(tr("Auto centering"), this);
-// m_autoCenteringAct->setCheckable(true);
-// connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
-// this, SIGNAL(autoCenteringTriggered(bool)));
-
// build the actual menu
m_viewMenu = menuBar()->addMenu(tr("Main"));
m_viewMenu->addAction(m_loginAct);
m_viewMenu->addAction(m_toSettingsAct);
m_viewMenu->addAction(m_gpsToggleAct);
-// m_viewMenu->addAction(m_autoCenteringAct);
m_viewMenu->setObjectName(tr("Menu"));
}
}
}
-void MainWindow::drawIndicatorButton(const QSize &size)
-{
- qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
-
- const int LEFT_SCALE_MARGIN = 10;
- const int BOTTOM_SCALE_MARGIN = 80;
-
- if(m_indicatorButton) {
- if(m_loggedIn) {
- m_indicatorButton->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
- size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
-
- } else {
- m_indicatorButton->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
- size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
- }
- }
-}
-
void MainWindow::drawMapScale(const QSize &size)
{
const int LEFT_SCALE_MARGIN = 10;
m_cookieJar->setAllCookies(cookieList);
m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
-
}
}
settings.setValue(COOKIES, list);
}
-//void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
-//{
-// qDebug() << __PRETTY_FUNCTION__;
-
-// m_autoCenteringAct->setChecked(enabled);
-//}
-
void MainWindow::setGPSButtonEnabled(bool enabled)
{
qDebug() << __PRETTY_FUNCTION__;
m_gpsToggleAct->setChecked(enabled);
setOwnLocationCrosshairVisibility(!enabled);
-
-// m_autoCenteringAct->setVisible(enabled);
}
void MainWindow::setIndicatorButtonEnabled(bool enabled)
m_indicatorButton->setChecked(enabled);
- connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
- this, SIGNAL(autoCenteringTriggered(bool)));
}
void MainWindow::setMapViewScene(QGraphicsScene *scene)
qDebug() << __PRETTY_FUNCTION__;
drawFullScreenButton(m_viewPortSize);
- drawIndicatorButton(m_viewPortSize);
if(m_loggedIn) {
if(!m_friendsListPanel->isVisible()) {
}
}
-//void MainWindow::showIndicatorButton(bool gps, bool autoCentering)
-//{
-// qDebug() << __PRETTY_FUNCTION__;
-
-//}
-
void MainWindow::startLoginProcess()
{
qDebug() << __PRETTY_FUNCTION__;
*/
void readAutomaticLocationUpdateSettings();
- /**
- * @brief Enable / disable auto centering button.
- *
- * @param enabled true if shoud be enabled, false otherwise
- */
+// /**
+// * @brief Enable / disable auto centering button.
+// *
+// * @param enabled true if shoud be enabled, false otherwise
+// */
// void setAutoCenteringButtonEnabled(bool enabled);
/**
void drawFullScreenButton(const QSize &size);
/**
- * @brief Slot for drawing the direction indicator button
- *
- * @param size Size of the screen
- */
- void drawIndicatorButton(const QSize &size);
-
-
- /**
* @brief Slot for drawing the map distance scale
*
* @param size Size of the screen
*
* @param enabled True if automatic centering is enabled, otherwise false
*/
-// void autoCenteringTriggered(bool enabled);
+ void autoCenteringTriggered(bool enabled);
/**
* @brief Signal that indicates when user has cancelled login process
const QString ZOOMPANEL_POSITION = "Zoom_Panel_Position";
// Direction indicator button settings
-//const int DIRECTION_INDICATOR_POSITION_X = 30 + PANEL_PEEK_AMOUNT; ///< Horizontal position of zoom panel
-//const int DIRECTION_INDICATOR_POSITION_Y = 30; ///< Vertical position of zoom panel
+const int DIRECTION_INDICATOR_POSITION_X = 10 + PANEL_PEEK_AMOUNT; ///< Horizontal position of direction indicator button
+const int DIRECTION_INDICATOR_POSITION_Y = 342; ///< Vertical position of direction indicator button
-//const QString DIRECTION_INDICATOR_BUTTON_POSITION = "Direction_indicator_Position";
+const QString DIRECTION_INDICATOR_BUTTON_POSITION = "Direction_Indicator_Position";
#endif // PANELCOMMON_H