2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Kaj Wallin - kaj.wallin@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
29 const int METRIC_STEP = 90; ///< TEST value in pixels
30 const qreal KM_TO_MILE = 1.609344; ///< Kilometer to mile conversion value
31 const int MAPSCALE_HEIGHT = 14; ///< Height of the the map scale
32 const int BASELINE_Y = MAPSCALE_HEIGHT / 2; ///< Y position of the baseline
33 const int MAPSCALE_STOP_HEIGHT = 7; ///< Height of each perpendicular stop on the scale
35 const qreal INPUTVALUE = 450.35; ///< SIMULATED input value: meters/pixel
37 MapScale::MapScale(QWidget *parent) :
40 qDebug() << __PRETTY_FUNCTION__;
41 // setAutoFillBackground(true);
42 setAttribute(Qt::WA_TransparentForMouseEvents, true);
45 void MapScale::paintEvent(QPaintEvent *event)
47 qDebug() << __PRETTY_FUNCTION__;
50 qreal gen_scale = METRIC_STEP * INPUTVALUE;
54 baseScale = roundToBaseScale(gen_scale);
55 qreal baseLineLength = baseScale / INPUTVALUE;
57 qWarning() << gen_scale << ">" << baseScale << ">" << baseLineLength;
59 QLineF BaseLine(0, BASELINE_Y, baseLineLength * KM_TO_MILE, BASELINE_Y);
60 QLineF StartKm(1, BASELINE_Y, 1, (BASELINE_Y) - MAPSCALE_STOP_HEIGHT);
61 QLineF StartMi(1, BASELINE_Y, 1, (BASELINE_Y) + MAPSCALE_STOP_HEIGHT);
62 QLineF StopKm(baseLineLength, BASELINE_Y,
63 baseLineLength, (BASELINE_Y) - MAPSCALE_STOP_HEIGHT);
64 QLineF StopMi(baseLineLength * KM_TO_MILE, BASELINE_Y,
65 baseLineLength * KM_TO_MILE, (BASELINE_Y) + MAPSCALE_STOP_HEIGHT);
67 resize(ceil(baseLineLength * KM_TO_MILE)+1, MAPSCALE_HEIGHT);
69 QPainter painter(this);
70 QPen pen(Qt::black, 2);
73 painter.drawLine(BaseLine);
74 painter.drawLine(StartKm);
75 painter.drawLine(StartMi);
76 painter.drawLine(StopKm);
77 painter.drawLine(StopMi);
80 qreal MapScale::roundToBaseScale(qreal value)
82 qDebug() << __PRETTY_FUNCTION__;
92 else if (value < 0.375)
94 else if (value < 0.75)
98 baseLine = baseLine * (pow(10,scale-1));
99 qWarning() << baseLine;