<context>
<name>FriendListPanel</name>
<message>
- <location filename="../../src/ui/friendlistpanel.cpp" line="34"/>
+ <location filename="../../src/ui/friendlistpanel.cpp" line="44"/>
<source>Show all</source>
- <translation type="unfinished">Näytä kaikki</translation>
+ <translation>Näytä kaikki</translation>
+ </message>
+ <message>
+ <location filename="../../src/ui/friendlistpanel.cpp" line="108"/>
+ <source>Selected: %1</source>
+ <translation>Valittu: %1</translation>
</message>
</context>
<context>
<name>GPSPositionPrivate</name>
<message>
<location filename="../../src/gps/gpspositionprivate.cpp" line="56"/>
+ <location filename="../../src/gps/gpspositionprivateliblocation.cpp" line="59"/>
<source>Unable to use GPS</source>
- <translation type="unfinished">GPS ei käytössä</translation>
+ <translation>GPS ei käytössä</translation>
+ </message>
+</context>
+<context>
+ <name>LiblocationWrapper</name>
+ <message>
+ <location filename="../../src/gps/liblocationwrapper.cpp" line="105"/>
+ <source>Error in GPS</source>
+ <translation>GPS virhe</translation>
</message>
</context>
<context>
<message>
<location filename="../../src/ui/logindialog.cpp" line="32"/>
<source>Login to Situare with Facebook account</source>
- <translation type="unfinished">Kirjaudu Situareen Facebook tunnuksilla</translation>
+ <translation>Kirjaudu Situareen Facebook tunnuksilla</translation>
</message>
<message>
<source>Connect</source>
<message>
<location filename="../../src/ui/logindialog.cpp" line="42"/>
<source>Login</source>
- <translation type="unfinished">Kirjaudu</translation>
+ <translation>Kirjaudu</translation>
</message>
<message>
<location filename="../../src/ui/logindialog.cpp" line="45"/>
<source>E-mail:</source>
- <translation type="unfinished">Sähköposti:</translation>
+ <translation>Sähköposti:</translation>
</message>
<message>
<location filename="../../src/ui/logindialog.cpp" line="46"/>
<source>Password:</source>
- <translation type="unfinished">Salasana:</translation>
+ <translation>Salasana:</translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
- <location filename="../../src/ui/mainwindow.cpp" line="84"/>
- <location filename="../../src/ui/mainwindow.cpp" line="647"/>
+ <location filename="../../src/ui/mainwindow.cpp" line="88"/>
<source>Situare</source>
- <translation type="unfinished">Situare</translation>
+ <translation>Situare</translation>
</message>
<message>
- <location filename="../../src/ui/mainwindow.cpp" line="310"/>
- <location filename="../../src/ui/mainwindow.cpp" line="504"/>
+ <location filename="../../src/ui/mainwindow.cpp" line="375"/>
+ <location filename="../../src/ui/mainwindow.cpp" line="634"/>
<source>Login</source>
- <translation type="unfinished">Kirjaudu</translation>
+ <translation>Kirjaudu</translation>
</message>
<message>
- <location filename="../../src/ui/mainwindow.cpp" line="315"/>
+ <location filename="../../src/ui/mainwindow.cpp" line="380"/>
<source>Settings</source>
- <translation type="unfinished">Asetukset</translation>
+ <translation>Asetukset</translation>
</message>
<message>
- <location filename="../../src/ui/mainwindow.cpp" line="320"/>
+ <location filename="../../src/ui/mainwindow.cpp" line="385"/>
<source>GPS</source>
- <translation type="unfinished">GPS</translation>
+ <translation>GPS</translation>
</message>
<message>
- <location filename="../../src/ui/mainwindow.cpp" line="327"/>
+ <location filename="../../src/ui/mainwindow.cpp" line="392"/>
<source>Auto centering</source>
- <translation type="unfinished">Automaattinen keskitys</translation>
+ <translation>Automaattinen keskitys</translation>
</message>
<message>
- <location filename="../../src/ui/mainwindow.cpp" line="333"/>
+ <location filename="../../src/ui/mainwindow.cpp" line="398"/>
<source>Main</source>
- <translation type="unfinished">Päävalikko</translation>
+ <translation>Päävalikko</translation>
</message>
<message>
- <location filename="../../src/ui/mainwindow.cpp" line="338"/>
+ <location filename="../../src/ui/mainwindow.cpp" line="403"/>
<source>Menu</source>
- <translation type="unfinished">Valikko</translation>
+ <translation>Valikko</translation>
</message>
<message>
- <location filename="../../src/ui/mainwindow.cpp" line="375"/>
+ <location filename="../../src/ui/mainwindow.cpp" line="506"/>
<source>GPS timeout</source>
- <translation type="unfinished"></translation>
+ <translation>GPS pyyntö aikakatkaistiin</translation>
</message>
<message>
- <location filename="../../src/ui/mainwindow.cpp" line="497"/>
+ <location filename="../../src/ui/mainwindow.cpp" line="628"/>
<source>Logout</source>
- <translation type="unfinished">Kirjaudu ulos</translation>
+ <translation>Kirjaudu ulos</translation>
</message>
</context>
<context>
<message>
<location filename="../../src/ui/settingsdialog.cpp" line="44"/>
<source>Settings</source>
- <translation type="unfinished">Asetukset</translation>
+ <translation>Asetukset</translation>
</message>
<message>
<location filename="../../src/ui/settingsdialog.cpp" line="50"/>
<source>Use automatic location update</source>
- <translation type="unfinished">Sijainnin automaattinen päivitys</translation>
+ <translation>Sijainnin automaattinen päivitys</translation>
</message>
<message>
<location filename="../../src/ui/settingsdialog.cpp" line="57"/>
<location filename="../../src/ui/settingsdialog.cpp" line="89"/>
<source>Update interval</source>
- <translation type="unfinished">Päivitysväli</translation>
+ <translation>Päivitysväli</translation>
</message>
<message>
<location filename="../../src/ui/settingsdialog.cpp" line="138"/>
<source>%1 min</source>
- <translation type="unfinished">%1 min</translation>
+ <translation>%1 min</translation>
</message>
</context>
<context>
<message>
<location filename="../../src/engine/engine.cpp" line="136"/>
<source>Auto centering disabled</source>
- <translation type="unfinished">Automaattinen keskitys pois päältä</translation>
+ <translation>Automaattinen keskitys pois päältä</translation>
</message>
<message>
- <location filename="../../src/engine/engine.cpp" line="219"/>
- <location filename="../../src/engine/engine.cpp" line="226"/>
+ <location filename="../../src/engine/engine.cpp" line="220"/>
+ <location filename="../../src/engine/engine.cpp" line="228"/>
<source>GPS enabled</source>
- <translation type="unfinished">GPS päällä</translation>
+ <translation>GPS päällä</translation>
</message>
<message>
- <location filename="../../src/engine/engine.cpp" line="220"/>
- <location filename="../../src/engine/engine.cpp" line="229"/>
+ <location filename="../../src/engine/engine.cpp" line="221"/>
+ <location filename="../../src/engine/engine.cpp" line="231"/>
<source>Auto centering enabled</source>
- <translation type="unfinished">Automaattinen keskitys päällä</translation>
+ <translation>Automaattinen keskitys päällä</translation>
</message>
</context>
<context>
<name>UpdateLocationDialog</name>
<message>
- <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="30"/>
+ <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="31"/>
<source>Update Location</source>
- <translation type="unfinished">Päivitä sijainti</translation>
+ <translation>Päivitä sijainti</translation>
</message>
<message>
- <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="39"/>
+ <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="43"/>
<source>Publish on Facebook</source>
- <translation type="unfinished">Julkaise Facebookissa</translation>
+ <translation>Julkaise Facebookissa</translation>
</message>
<message>
- <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="44"/>
+ <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="49"/>
<source>Send</source>
- <translation type="unfinished">Lähetä</translation>
+ <translation>Lähetä</translation>
</message>
<message>
- <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="47"/>
+ <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="52"/>
<source>Location:</source>
- <translation type="unfinished">Sijainti:</translation>
+ <translation>Sijainti:</translation>
</message>
<message>
- <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="48"/>
+ <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="53"/>
<source>Message:</source>
- <translation type="unfinished">Viesti:</translation>
+ <translation>Viesti:</translation>
+ </message>
+</context>
+<context>
+ <name>UserInfo</name>
+ <message>
+ <location filename="../../src/ui/userinfo.cpp" line="342"/>
+ <source>Location update failed
+
+Your message is saved to textbox until sending will succeed</source>
+ <translatorcomment>Do \n's work properly?</translatorcomment>
+ <translation>Sijainnin päivitys epäonnistui\n\nVistisi on tallennettu kunnes pävitys on onnistunut</translation>
</message>
</context>
</TS>
// QSettings common values
const QString COOKIES = "cookies";
const QString EMPTY = "";
+const QString SETTINGS_AUTOMATIC_UPDATE_ENABLED = "SETTINGS_AUTOMATIC_UPDATE_ENABLED";
+const QString SETTINGS_AUTOMATIC_UPDATE_INTERVAL = "SETTINGS_AUTOMATIC_UPDATE_INTERVAL";
const QColor COLOR_GRAY = QColor(152, 152, 152); ///< Gray color
const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal); ///< Normal font
m_automaticUpdateEnabled = enabled;
+ //Show automatic update confirmation dialog
if (m_automaticUpdateFirstStart && m_gps->isRunning() && m_automaticUpdateEnabled) {
- accepted = m_ui->showEnableAutomaticUpdateLocationDialog(
+ m_ui->showEnableAutomaticUpdateLocationDialog(
tr("Do you want to enable automatic location update with %1 min update interval?")
.arg(updateIntervalMsecs/1000/60));
m_automaticUpdateFirstStart = false;
- m_ui->automaticLocationUpdateEnabled(accepted);
-
- if (accepted && !m_gps->isRunning()) {
- enableGPS(true);
- m_ui->buildInformationBox(tr("GPS enabled"));
- }
}
+ else {
+ if (!m_automaticUpdateFirstStart && m_automaticUpdateEnabled && accepted)
+ m_ui->buildInformationBox(tr("Automatic location update enabled"));
- if (!m_automaticUpdateFirstStart && m_automaticUpdateEnabled && accepted)
- m_ui->buildInformationBox(tr("Automatic location update enabled"));
-
- if (accepted && m_gps->isRunning() && m_automaticUpdateEnabled) {
- if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
- m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
- else
- m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
+ if (accepted && m_gps->isRunning() && m_automaticUpdateEnabled) {
+ if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
+ m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
+ else
+ m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
- m_automaticUpdateIntervalTimer->start();
+ m_automaticUpdateIntervalTimer->start();
- } else {
- m_automaticUpdateIntervalTimer->stop();
+ } else {
+ m_automaticUpdateIntervalTimer->stop();
+ }
}
}
void SituareEngine::loginOk()
{
- qDebug() << __PRETTY_FUNCTION__;
+ qWarning() << __PRETTY_FUNCTION__;
m_loggedIn = true;
m_ui->loggedIn(m_loggedIn);
connect(m_mapEngine, SIGNAL(locationItemClicked(QList<QString>)),
m_ui, SIGNAL(locationItemClicked(QList<QString>)));
+
+ connect(m_mapEngine, SIGNAL(newMapResolution(qreal)),
+ m_ui, SIGNAL(newMapResolution(qreal)));
}
void SituareEngine::signalsFromSituareService()
m_loginCredentials.clearCredentials();
QSettings settings(DIRECTORY_NAME, FILE_NAME);
- if(!keepUsername)
+ if(!keepUsername) {
settings.remove(USERNAME);
+ settings.remove(SETTINGS_AUTOMATIC_UPDATE_ENABLED);
+ settings.remove(SETTINGS_AUTOMATIC_UPDATE_INTERVAL);
+ }
settings.remove(COOKIES);
}
+++ /dev/null
-<RCC>
- <qresource prefix="/">
- <file>resources/arrow_left.png</file>
- <file>resources/arrow_right.png</file>
- <file>resources/bkg_grid.png</file>
- <file>resources/led_red_g.png</file>
- <file>resources/led_red_h.png</file>
- <file>resources/led_red_s.png</file>
- <file>resources/list_item.png</file>
- <file>resources/side_bar_left.png</file>
- <file>resources/side_bar_right.png</file>
- <file>resources/sliding_bar_left.png</file>
- <file>resources/sliding_bar_right.png</file>
- <file>resources/zoom_in.png</file>
- <file>resources/zoom_out.png</file>
- <file>resources/clock.png</file>
- <file>resources/compass.png</file>
- <file>resources/envelope.png</file>
- <file>resources/profile_pic_border.png</file>
- <file>resources/send_position.png</file>
- <file>resources/personal_info_bckgrnd.png</file>
- <file>resources/refresh.png</file>
- </qresource>
-</RCC>
{
QApplication a(argc, argv);
- QTranslator translator;
- bool loaded = translator.load(":/res/languages/situare_" + QLocale::system().name());
- a.installTranslator(&translator);
-
- QString locale = QLocale::system().name();
- qDebug() << "Localization" << locale << "loaded:" << loaded;
+// QTranslator translator;
+// bool loaded = translator.load(":/res/languages/situare_" + QLocale::system().name());
+// a.installTranslator(&translator);
+// QString locale = QLocale::system().name();
+// qDebug() << "Localization" << locale << "loaded:" << loaded;
SituareEngine engine;
int appRet = a.exec();
void FriendGroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
+ Q_UNUSED(event);
+
qDebug() << __PRETTY_FUNCTION__;
if (m_clickEvent) {
const qreal DEFAULT_LONGITUDE = 0.0000; ///< Default longitude value
const qreal DEFAULT_LATITUDE = 0.0000; ///< Default latitude value
+const qreal EARTH_RADIUS = 6371.01; ///< Earth radius in km
+
const int GRID_PADDING = 1; ///< Grid padding used in tile grid calculation
const QString OSM_LICENSE = QString::fromUtf8("© OpenStreetMap contributors, CC-BY-SA");
return (centerTile != temp);
}
+qreal MapEngine::sceneResolution()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ const int SHIFT = 200;
+ const int KM_TO_M = 1000;
+ qreal scale = (1 << (MAX_MAP_ZOOM_LEVEL - m_zoomLevel));
+ QPointF centerCoordinate = centerGeoCoordinate();
+ QPoint shiftedSceneCoordinate = QPoint(m_sceneCoordinate.x() + SHIFT*scale
+ , m_sceneCoordinate.y());
+ QPointF shiftedCoordinate = convertSceneCoordinateToLatLon(m_zoomLevel, shiftedSceneCoordinate);
+ qreal dist = greatCircleDistance(centerCoordinate, shiftedCoordinate) * KM_TO_M;
+ return (dist / SHIFT);
+}
+
void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image)
{
qDebug() << __PRETTY_FUNCTION__;
}
}
+qreal MapEngine::greatCircleDistance(QPointF firstLocation, QPointF secondLocation)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ const qreal TORAD = (M_PI/180);
+
+ qreal dLat = (secondLocation.y() - firstLocation.y())*TORAD;
+ qreal dLon = (secondLocation.x() - firstLocation.x())*TORAD;
+ qreal a = pow(sin(dLat/2),2) + cos(firstLocation.y()*TORAD) * cos(secondLocation.y()*TORAD)
+ * pow(sin(dLon/2),2);
+ qreal c = 2 * atan2(sqrt(a), sqrt(1-a));
+
+ return (EARTH_RADIUS * c);
+}
+
void MapEngine::receiveOwnLocation(User *user)
{
qDebug() << __PRETTY_FUNCTION__;
getTiles(sceneCoordinate);
m_mapScene->removeOutOfViewTiles();
}
+
+ emit newMapResolution(sceneResolution());
}
void MapEngine::setZoomLevel(int newZoomLevel)
emit maxZoomLevelReached();
else if (m_zoomLevel == MIN_VIEW_ZOOM_LEVEL)
emit minZoomLevelReached();
+
+ emit newMapResolution(sceneResolution());
}
void MapEngine::zoomIn()
static QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber);
/**
+ * @brief Calculate great-circle distance between two geographic coordinates
+ *
+ * Calculate great-circle distance between two given geographic locations using
+ * haversine formula
+ *
+ * @param firstLocation Coordinates of the first location
+ * @param secondLocation Coordinates of the second location
+ * @return qreal Distance in kilometers
+ */
+ qreal greatCircleDistance(QPointF firstLocation, QPointF secondLocation);
+
+ /**
* @brief MapEngine initializer
*
* Set initial location and zoom level for the engine. locationChanged and
static QString tilePath(int zoomLevel, int x, int y);
public slots:
+
/**
* @brief Slot to catch user own location data
*
bool isCenterTileChanged(QPoint sceneCoordinate);
/**
+ * @brief Calculate scale at the map center of the map in meters/pixel
+ *
+ * @return qreal Scale of the map in meters/pixel
+ */
+ qreal sceneResolution();
+
+ /**
* @brief Calculate maximum value for tile in this zoom level.
*
* @param zoomLevel zoom level
void minZoomLevelReached();
/**
+ * @brief Signal to pass the scale of the map to map scale
+ */
+ void newMapResolution(qreal scale);
+
+ /**
* @brief Request view changing zoom level
*
* @param newZoomLevel New zoom level
qDebug() << __PRETTY_FUNCTION__ << "Resize:" << event->size();
emit viewResized(event->size());
- emit viewResizedNewSize(viewport()->width(), viewport()->height());
}
void MapView::setViewScale(qreal viewScale)
void viewResized(const QSize &size);
/**
- * @brief Signal for drawing OSM license
- *
- * Signal is emitted when view is resized.
- * @param width Viewport width
- * @param height Viewport height
- */
- void viewResizedNewSize(int width, int height);
-
- /**
* @brief Signal for view scroll events
*
* Signal is emitted when view is scrolled.
network/networkaccessmanager.cpp \
network/networkhandler.cpp \
network/networkcookiejar.cpp \
- network/networkreply.cpp
+ network/networkreply.cpp \
+ ui/mapscale.cpp
HEADERS += ui/mainwindow.h \
map/mapengine.h \
map/mapview.h \
network/networkaccessmanager.h \
network/networkhandler.h \
network/networkcookiejar.h \
- network/networkreply.h
+ network/networkreply.h \
+ ui/mapscale.h
QT += network \
webkit
#include "settingsdialog.h"
#include "userinfopanel.h"
#include "zoombuttonpanel.h"
+#include "mapscale.h"
#include "mainwindow.h"
m_password(),
m_fullScreenButton(0),
m_webView(0),
+ m_mapScale(0),
m_cookieJar(0)
{
qDebug() << __PRETTY_FUNCTION__;
if(m_fullScreenButton) {
m_fullScreenButton->stackUnder(m_zoomButtonPanel);
m_osmLicense->stackUnder(m_fullScreenButton);
- } else
+ } else {
m_osmLicense->stackUnder(m_zoomButtonPanel);
+ }
m_ownLocationCrosshair->stackUnder(m_osmLicense);
- m_mapView->stackUnder(m_ownLocationCrosshair);
+ m_mapScale->stackUnder(m_ownLocationCrosshair);
+ m_mapView->stackUnder(m_mapScale);
this->toggleProgressIndicator(true);
m_error_queue.clear();
}
-void MainWindow::automaticLocationUpdateEnabled(bool enabled)
+void MainWindow::automaticUpdateDialogFinished(int result)
{
- m_settingsDialog->setAutomaticLocationUpdateSettings(enabled);
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (result == QMessageBox::Yes) {
+ m_settingsDialog->setAutomaticLocationUpdateSettings(true);
+ m_settingsDialog->emitAutomaticLocationUpdateSettings();
+ }
+ else {
+ m_settingsDialog->setAutomaticLocationUpdateSettings(false);
+ m_settingsDialog->emitAutomaticLocationUpdateSettings();
+ }
}
void MainWindow::buildFullScreenButton()
connect(this, SIGNAL(locationItemClicked(QList<QString>)),
m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
- connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
- m_friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ m_friendsListPanelSidebar, SLOT(reDrawSidebar(QSize)));
}
void MainWindow::buildInformationBox(const QString &message, bool modal)
m_ownLocationCrosshair->hide();
m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
- connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
- this, SLOT(drawOwnLocationCrosshair(int, int)));
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ this, SLOT(drawOwnLocationCrosshair(QSize)));
}
void MainWindow::buildMap()
buildOsmLicense();
buildManualLocationCrosshair();
buildFullScreenButton();
+ buildMapScale();
connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
this, SIGNAL(mapViewScrolled(QPoint)));
connect(m_mapView, SIGNAL(viewResized(QSize)),
this, SLOT(drawFullScreenButton(QSize)));
- connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
- this, SLOT(setViewPortSize(int, int)));
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ this, SLOT(drawMapScale(QSize)));
+
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ this, SLOT(setViewPortSize(QSize)));
connect(this, SIGNAL(zoomLevelChanged(int)),
m_mapView, SLOT(setZoomLevel(int)));
this, SIGNAL(viewZoomFinished()));
}
+void MainWindow::buildMapScale()
+{
+ m_mapScale = new MapScale(this);
+ connect(this, SIGNAL(newMapResolution(qreal)),
+ m_mapScale, SLOT(updateMapResolution(qreal)));
+}
+
void MainWindow::buildOsmLicense()
{
qDebug() << __PRETTY_FUNCTION__;
}
}
+void MainWindow::drawMapScale(const QSize &size)
+{
+ const int LEFT_SCALE_MARGIN = 10;
+ const int BOTTOM_SCALE_MARGIN = 2;
+ qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
+
+ m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
+ size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
+}
+
void MainWindow::drawOsmLicense(const QSize &size)
{
qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
size.height() - m_osmLicense->fontMetrics().height());
}
-void MainWindow::drawOwnLocationCrosshair(int width, int height)
+void MainWindow::drawOwnLocationCrosshair(const QSize &size)
{
qDebug() << __PRETTY_FUNCTION__;
if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
- m_ownLocationCrosshair->move(width/2 - m_ownLocationCrosshair->pixmap()->width()/2,
- height/2 - m_ownLocationCrosshair->pixmap()->height()/2);
+ m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
+ size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
}
}
qDebug() << __PRETTY_FUNCTION__;
m_settingsDialog->enableSituareSettings(m_gpsToggleAct->isChecked() && m_loggedIn);
+ m_settingsDialog->readSettings();
m_settingsDialog->show();
}
if (visibility) {
m_ownLocationCrosshair->show();
m_drawOwnLocationCrosshair = true;
- drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
+ drawOwnLocationCrosshair(QSize(m_viewPortWidth, m_viewPortHeight));
} else {
m_ownLocationCrosshair->hide();
m_drawOwnLocationCrosshair = false;
m_email = username;
}
-void MainWindow::setViewPortSize(int width, int height)
+void MainWindow::setViewPortSize(const QSize &size)
{
qDebug() << __PRETTY_FUNCTION__;
- m_viewPortWidth = width;
- m_viewPortHeight = height;
+ m_viewPortWidth = size.width();
+ m_viewPortHeight = size.height();
}
bool MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
{
- QMessageBox msgBox(QMessageBox::Question, tr("Automatic location update"), text,
- QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, 0);
- int returnValue = msgBox.exec();
- qWarning() << __PRETTY_FUNCTION__ << returnValue;
- if (returnValue == QMessageBox::Yes)
- return true;
- else
- return false;
+ m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
+ tr("Automatic location update"), text,
+ QMessageBox::Yes | QMessageBox::No |
+ QMessageBox::Cancel, this);
+ connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
+ this, SLOT(automaticUpdateDialogFinished(int)));
+ m_automaticUpdateLocationDialog->show();
}
void MainWindow::toggleFullScreen()
class FacebookAuthentication;
class FriendListPanel;
+class MapScale;
class MapScene;
class MapView;
class SituareService;
class ZoomButtonPanel;
class SettingsDialog;
class QToolButton;
+class QMessageBox;
/**
* @brief Main Window Class
******************************************************************************/
public:
/**
- * @brief Sets automatic location update enabled from settings dialog.
- *
- * @param enabled true if enabled, false otherwise
- */
- void automaticLocationUpdateEnabled(bool enabled);
-
- /**
* @brief Builds information box with message.
*
* @param message Information message
void buildMap();
/**
+ * @brief Build map scale and connect slots
+ */
+ void buildMapScale();
+
+ /**
* @brief Build OSM license and connect slots
*/
void buildOsmLicense();
private slots:
/**
+ * @brief Slot for automatic update dialog finished.
+ *
+ * @result result code
+ */
+ void automaticUpdateDialogFinished(int result);
+
+ /**
* @brief Slot to intercept signal when dialog/information note is processed
*
* @param status Status of the dialog
void drawFullScreenButton(const QSize &size);
/**
+ * @brief Slot for drawing the map distance scale
+ *
+ * @param size Size of the screen
+ */
+ void drawMapScale(const QSize &size);
+
+ /**
* @brief Slot for drawing the Open Street Map license text
*
* @param size Size of the screen
/**
* @brief Slot for drawing the own location crosshair
*
- * @param width Width of the viewport
- * @param height Height of the viewport
+ * @param size Size of the screen
*/
- void drawOwnLocationCrosshair(int width, int height);
+ void drawOwnLocationCrosshair(const QSize &size);
/**
* @brief Slot to intercept signal when error dialog/information note is processed
/**
* @brief Set correnct view port size to datamembers
*
- * @param width Width of the viewport
- * @param height Height of the viewport
+ * @param size Size of the screen
*/
- void setViewPortSize(const int width, const int height);
+ void setViewPortSize(const QSize &size);
/**
* @brief Toggle between fullscreen and normal window mode
void notificateUpdateFailing(const QString &message);
/**
+ * @brief Forwarding signal from MapEngine to MapScale
+ */
+ void newMapResolution(qreal scale);
+
+ /**
* @brief Signal for refreshing user data.
*
*/
QWebView *m_webView; ///< Shows facebook login page
FriendListPanel *m_friendsListPanel; ///< Instance of friends list panel
+ MapScale *m_mapScale; ///< Instance of the map scale
MapView *m_mapView; ///< Instance of the map view
NetworkCookieJar *m_cookieJar; ///< Placeholder for QNetworkCookies
PanelSideBar *m_userPanelSidebar; ///< User panel side bar
SettingsDialog *m_settingsDialog; ///< Settings dialog
+ QMessageBox *m_automaticUpdateLocationDialog;
};
#endif // MAINWINDOW_H
--- /dev/null
+ /*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Kaj Wallin - kaj.wallin@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+ */
+
+#include <QPainter>
+#include <QPen>
+#include <QLine>
+#include <QDebug>
+#include "mapscale.h"
+#include <math.h>
+
+const int TARGET_WIDTH = 140; ///< Target width of the scale in pixels
+const qreal M_TO_FT = 3.2808399; ///< Meter to feet conversion value
+const qreal FT_TO_MI = 5280; ///< Feet to mile conversion
+const qreal M_TO_KM = 1000; ///< Meters to kilometers conversion
+const int MAPSCALE_HEIGHT = 31; ///< Height of the the map scale
+const int CENTERLINE_Y = MAPSCALE_HEIGHT / 2; ///< Y position of the centerline
+const int MAPSCALE_STOP_HEIGHT = 7; ///< Height of each perpendicular stop on the scale
+const int SCALE_TEXT_X = 3; ///< X coordinate for the scale texts
+
+MapScale::MapScale(QWidget *parent) :
+ QWidget(parent),
+ m_centerLineImperial(0),
+ m_centerLineMetric(0),
+ m_imperialText(""),
+ m_metricText("")
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+// updateMapScale(10.0);
+ setAttribute(Qt::WA_TransparentForMouseEvents, true);
+}
+
+void MapScale::paintEvent(QPaintEvent *event)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ Q_UNUSED(event);
+
+ resize(ceil(fmax(m_centerLineMetric,m_centerLineImperial)) + 1, MAPSCALE_HEIGHT);
+
+ QLineF centerLine(0, CENTERLINE_Y, fmax(m_centerLineMetric, m_centerLineImperial), CENTERLINE_Y);
+ QLineF startKm(1, CENTERLINE_Y, 1, CENTERLINE_Y - MAPSCALE_STOP_HEIGHT);
+ QLineF stopKm(m_centerLineMetric, CENTERLINE_Y,
+ m_centerLineMetric, CENTERLINE_Y - MAPSCALE_STOP_HEIGHT);
+
+ QLineF startMi(1, CENTERLINE_Y, 1, CENTERLINE_Y + MAPSCALE_STOP_HEIGHT);
+ QLineF stopMi(m_centerLineImperial, CENTERLINE_Y,
+ m_centerLineImperial, CENTERLINE_Y + MAPSCALE_STOP_HEIGHT);
+
+ QPainter painter(this);
+ QPen pen(Qt::black, 2);
+
+ painter.setFont(QFont("Nokia Sans", 13, QFont::Normal));
+ painter.setPen(pen);
+ painter.drawLine(centerLine);
+ painter.drawLine(startKm);
+ painter.drawLine(stopKm);
+ painter.drawText(SCALE_TEXT_X, MAPSCALE_HEIGHT / 2 - 2, m_metricText);
+
+ painter.drawLine(startMi);
+ painter.drawLine(stopMi);
+ painter.drawText(SCALE_TEXT_X, MAPSCALE_HEIGHT, m_imperialText);
+}
+
+qreal MapScale::roundToBaseScale(qreal value)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ int scale = 0;
+ qreal baseLine;
+ while(value > 1){
+ value = value/10;
+ scale++;
+ }
+ if(value < 0.15)
+ baseLine = 1;
+ else if (value < 0.35)
+ baseLine = 2;
+ else if (value < 0.75)
+ baseLine = 5;
+ else
+ baseLine = 10;
+ baseLine = baseLine * (pow(10,scale-1));
+ return baseLine;
+}
+
+void MapScale::updateMapResolution(const qreal &resolution)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ //Calculate distance scale in metric units
+ qreal genericMetricScale = TARGET_WIDTH * resolution;
+ qreal baseMetricScale = roundToBaseScale(genericMetricScale);
+ if(resolution != 0)
+ m_centerLineMetric = baseMetricScale / resolution;
+ else
+ m_centerLineMetric = baseMetricScale / 0.000001;
+
+ if(baseMetricScale < M_TO_KM)
+ {
+ m_metricText.setNum(baseMetricScale);
+ m_metricText.append(" m");
+ } else {
+ m_metricText.setNum(baseMetricScale/M_TO_KM);
+ m_metricText.append(" km");
+ }
+
+ //Calculate distance scale in imperial units
+ qreal imperialScaleResolution = resolution * M_TO_FT;
+ qreal genericImperialScale = TARGET_WIDTH * imperialScaleResolution;
+ qreal baseImperialScale;
+
+ if(genericImperialScale < FT_TO_MI) {
+ baseImperialScale = roundToBaseScale(genericImperialScale);
+ if(imperialScaleResolution != 0)
+ m_centerLineImperial = baseImperialScale / imperialScaleResolution;
+ else
+ m_centerLineImperial = baseImperialScale / 0.000001;
+ m_imperialText.setNum(baseImperialScale);
+ m_imperialText.append(" ft");
+ } else {
+ baseImperialScale = roundToBaseScale(genericImperialScale / FT_TO_MI);
+ if(imperialScaleResolution != 0)
+ m_centerLineImperial = (baseImperialScale*FT_TO_MI) / imperialScaleResolution;
+ else
+ m_centerLineImperial = baseImperialScale / 0.000001;
+ m_imperialText.setNum(baseImperialScale);
+ m_imperialText.append(" mi");
+ }
+
+ update();
+}
--- /dev/null
+ /*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Kaj Wallin - kaj.wallin@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+ */
+
+
+#ifndef MAPSCALE_H
+#define MAPSCALE_H
+
+#include <QWidget>
+
+class QLineF;
+
+/**
+ * @brief Map distance scale
+ *
+ * @author Kaj Wallin - kaj.wallin (at) ixonos.com
+ */
+class MapScale : public QWidget
+{
+ Q_OBJECT
+
+public:
+ /**
+ * @brief Constructor
+ *
+ * @param parent Parent
+ */
+ MapScale(QWidget *parent = 0);
+
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+ /**
+ * @brief Event handler for paint events
+ *
+ * Paints the scale
+ * @param event Paint event
+ */
+ void paintEvent(QPaintEvent *event);
+
+/******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+private:
+ /**
+ * @brief Rounding function for distances
+ *
+ * Rounds the given value to closest 1,2,5 or 10 in the original scale
+ * @param value Value to be rounded
+ * @return qreal Rounded value
+ */
+ qreal roundToBaseScale(qreal value);
+
+public slots:
+ /**
+ * @brief Slot to update the scale with latest resolution
+ *
+ * @param resolution Resolution of the map in meters/pixel
+ */
+ void updateMapResolution(const qreal &resolution);
+
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
+private:
+ qreal m_centerLineImperial; ///< Length of the imperial scale
+ qreal m_centerLineMetric; ///< Length of the metric scale
+ QString m_imperialText; ///< Text description of the imperial scale
+ QString m_metricText; ///< Text description of the metric scale
+};
+
+#endif // MAPSCALE_H
style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
}
-void PanelSideBar::reDrawSidebar(int width, int height)
+void PanelSideBar::reDrawSidebar(const QSize &size)
{
- Q_UNUSED(height);
qDebug() << __PRETTY_FUNCTION__;
if (objectName() == "SidePanelRight") {
- move(width - SIDEBAR_WIDTH + MARGIN_CORRECTION2, PANEL_TOP_Y);
+ move(size.width() - SIDEBAR_WIDTH + MARGIN_CORRECTION2, PANEL_TOP_Y);
}
}
/**
* @brief Slot to redraw the sidebar after window resize event
*
- * @param width Width of the window after resize
- * @param height Height of the window after resize
+ * @param size Size of the screen
*/
- void reDrawSidebar(int width, int height);
+ void reDrawSidebar(const QSize &size);
};
#endif // PANELSIDEBAR_H
#include "common.h"
#include "settingsdialog.h"
-const QString SETTINGS_AUTOMATIC_UPDATE_ENABLED = "SETTINGS_AUTOMATIC_UPDATE_ENABLED";
-const QString SETTINGS_AUTOMATIC_UPDATE_INTERVAL = "SETTINGS_AUTOMATIC_UPDATE_INTERVAL";
const int LIST_MINUTES_STEP = 5;
const int LIST_MINUTES_MAX = 60;
const int LIST_HOURS_MAX = 1;
SettingsDialog::SettingsDialog(QWidget *parent)
- : QDialog(parent),
- m_automaticLocationUpdateOldValue(false),
- m_automaticLocationUpdateIntervalOldValue(QTime(0, LIST_MINUTES_STEP))
+ : QDialog(parent)
{
qDebug() << __PRETTY_FUNCTION__;
setWindowTitle(tr("Settings"));
connect(m_automaticLocationUpdate, SIGNAL(toggled(bool)),
this, SLOT(toggleAutomaticLocationUpdate(bool)));
connect(saveButton, SIGNAL(clicked()), this, SLOT(saveValues()));
- connect(this, SIGNAL(rejected()), this, SLOT(rejectValues()));
QFormLayout *form = new QFormLayout();
form->setRowWrapPolicy(QFormLayout::WrapAllRows);
readSettings();
}
-SettingsDialog::~SettingsDialog()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- QSettings settings(DIRECTORY_NAME, FILE_NAME);
- settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, m_automaticLocationUpdateOldValue);
- settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL,
- m_automaticLocationUpdateIntervalOldValue);
-}
-
-void SettingsDialog::setAutomaticLocationUpdateSettings(bool checked)
+void SettingsDialog::emitAutomaticLocationUpdateSettings()
{
qDebug() << __PRETTY_FUNCTION__;
- m_automaticLocationUpdate->setChecked(checked);
- m_automaticLocationUpdateOldValue = checked;
+ if (m_automaticLocationUpdate->isChecked()) {
+ QTime emptyTime = QTime();
+ emit enableAutomaticLocationUpdate(true, emptyTime.msecsTo(time()));
+ }
+ else {
+ emit enableAutomaticLocationUpdate(false);
+ }
}
void SettingsDialog::enableSituareSettings(bool enabled)
toggleAutomaticLocationUpdate(false);
}
+void SettingsDialog::populateUpdateIntervalList(QStandardItemModel *model)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ for (int i = LIST_MINUTES_STEP; i <= LIST_MINUTES_MAX; i+=LIST_MINUTES_STEP) {
+ QStandardItem *item = new QStandardItem(QString(tr("%1 min")).arg(i));
+ item->setTextAlignment(Qt::AlignCenter);
+ item->setEditable(false);
+ model->appendRow(item);
+ }
+}
+
void SettingsDialog::readSettings()
{
qDebug() << __PRETTY_FUNCTION__;
setTime(QTime::fromString(automaticUpdateInterval, "hh:mm:ss"));
else
setTime(QTime(0, LIST_MINUTES_STEP));
-
- m_automaticLocationUpdateOldValue = automaticUpdateEnabled;
- m_automaticLocationUpdateIntervalOldValue = time();
}
-void SettingsDialog::emitAutomaticLocationUpdateSettings()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- if (m_automaticLocationUpdate->isChecked()) {
- QTime emptyTime = QTime();
- emit enableAutomaticLocationUpdate(true, emptyTime.msecsTo(time()));
- }
- else {
- emit enableAutomaticLocationUpdate(false);
- }
-}
-
-void SettingsDialog::populateUpdateIntervalList(QStandardItemModel *model)
+void SettingsDialog::saveValues()
{
qDebug() << __PRETTY_FUNCTION__;
- for (int i = LIST_MINUTES_STEP; i <= LIST_MINUTES_MAX; i+=LIST_MINUTES_STEP) {
- QStandardItem *item = new QStandardItem(QString(tr("%1 min")).arg(i));
- item->setTextAlignment(Qt::AlignCenter);
- item->setEditable(false);
- model->appendRow(item);
- }
-}
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, m_automaticLocationUpdate->isChecked());
+ settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, time());
-void SettingsDialog::rejectValues()
-{
- qDebug() << __PRETTY_FUNCTION__;
+ emitAutomaticLocationUpdateSettings();
- m_automaticLocationUpdate->setChecked(m_automaticLocationUpdateOldValue);
- setTime(m_automaticLocationUpdateIntervalOldValue);
+ accept();
}
-void SettingsDialog::saveValues()
+void SettingsDialog::setAutomaticLocationUpdateSettings(bool checked)
{
qDebug() << __PRETTY_FUNCTION__;
- m_automaticLocationUpdateOldValue = m_automaticLocationUpdate->isChecked();
- m_automaticLocationUpdateIntervalOldValue = time();
-
- emitAutomaticLocationUpdateSettings();
+ m_automaticLocationUpdate->setChecked(checked);
- accept();
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, m_automaticLocationUpdate->isChecked());
}
void SettingsDialog::setTime(const QTime &time)
*/
SettingsDialog(QWidget *parent = 0);
- /**
- * @brief Destructor.
- *
- * Saves automatic update interval in settings.
- */
- ~SettingsDialog();
-
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
*/
void emitAutomaticLocationUpdateSettings();
-private slots:
/**
- * @brief Saves settings to file.
+ * @brief Read settings.
*/
- void saveValues();
+ void readSettings();
+private slots:
/**
- * @brief Rejects changes made to settings.
+ * @brief Saves settings to file.
*/
- void rejectValues();
+ void saveValues();
/**
* @brief Toggles automatic location update state.
void populateUpdateIntervalList(QStandardItemModel *model);
/**
- * @brief Read settings.
- */
- void readSettings();
-
- /**
* @brief Sets time.
*
* @param time time to set
******************************************************************************/
private:
QCheckBox *m_automaticLocationUpdate; ///< Pointer to CheckBox
- bool m_automaticLocationUpdateOldValue; ///< Automatic location update state
- QTime m_automaticLocationUpdateIntervalOldValue;///< Automatic location update interval value
#ifdef Q_WS_MAEMO_5
QMaemo5ValueButton *m_automaticLocationUpdateIntervalButton; ///< Maemo 5 value button
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
public:
+ /**
+ * @brief Relative position of the event inside the widget
+ */
const QPoint& eventPosition();
/*******************************************************************************
* @brief Constructor
*
* @param parent Parent
- * @param x Panel x coordinate
- * @param y Panel y coordinate
*/
ZoomButtonPanel(QWidget *parent = 0);