1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Settings improvements and code cleanup

This commit is contained in:
Martin Tůma 2017-09-15 00:07:09 +02:00
parent a7506cfd82
commit b9489afbfe
14 changed files with 131 additions and 124 deletions

View File

@ -310,7 +310,7 @@ void Atlas::draw(QPainter *painter, const QRectF &rect)
}
// Multiple maps
painter->fillRect(rect, Qt::white);
painter->fillRect(rect, _backgroundColor);
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
QRectF ir = rect.intersected(_bounds.at(i).second);
if (!ir.isNull())

View File

@ -70,7 +70,7 @@ qreal EmptyMap::zoomOut()
void EmptyMap::draw(QPainter *painter, const QRectF &rect)
{
painter->fillRect(rect, Qt::white);
painter->fillRect(rect, _backgroundColor);
}
QPointF EmptyMap::ll2xy(const Coordinates &c)

View File

@ -461,3 +461,8 @@ void GraphView::useOpenGL(bool use)
else
setViewport(new QWidget);
}
void GraphView::useAntiAliasing(bool use)
{
setRenderHint(QPainter::Antialiasing, use);
}

View File

@ -56,6 +56,7 @@ public:
void plot(QPainter *painter, const QRectF &target, qreal scale);
void useOpenGL(bool use);
void useAntiAliasing(bool use);
signals:
void sliderPositionChanged(qreal);

View File

@ -857,6 +857,19 @@ void GUI::closePOIFiles()
void GUI::openOptions()
{
#define SET_VIEW_OPTION(option, action) \
if (options.option != _options.option) \
_pathView->action(options.option)
#define SET_TAB_OPTION(option, action) \
if (options.option != _options.option) \
for (int i = 0; i < _tabs.count(); i++) \
_tabs.at(i)->action(options.option)
#define SET_TRACK_OPTION(option, action) \
if (options.option != _options.option) { \
Track::action(options.option); \
reload = true; \
}
Options options(_options);
bool reload = false;
@ -864,83 +877,36 @@ void GUI::openOptions()
if (dialog.exec() != QDialog::Accepted)
return;
if (options.palette != _options.palette) {
_pathView->setPalette(options.palette);
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->setPalette(options.palette);
}
if (options.mapOpacity != _options.mapOpacity)
_pathView->setMapOpacity(options.mapOpacity);
if (options.blendColor != _options.blendColor)
_pathView->setBlendColor(options.blendColor);
if (options.trackWidth != _options.trackWidth)
_pathView->setTrackWidth(options.trackWidth);
if (options.routeWidth != _options.routeWidth)
_pathView->setRouteWidth(options.routeWidth);
if (options.trackStyle != _options.trackStyle)
_pathView->setTrackStyle(options.trackStyle);
if (options.routeStyle != _options.routeStyle)
_pathView->setRouteStyle(options.routeStyle);
if (options.waypointSize != _options.waypointSize)
_pathView->setWaypointSize(options.waypointSize);
if (options.waypointColor != _options.waypointColor)
_pathView->setWaypointColor(options.waypointColor);
if (options.poiSize != _options.poiSize)
_pathView->setPOISize(options.poiSize);
if (options.poiColor != _options.poiColor)
_pathView->setPOIColor(options.poiColor);
if (options.pathAntiAliasing != _options.pathAntiAliasing)
_pathView->setRenderHint(QPainter::Antialiasing,
options.pathAntiAliasing);
if (options.graphWidth != _options.graphWidth)
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->setGraphWidth(options.graphWidth);
if (options.graphAntiAliasing != _options.graphAntiAliasing)
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->setRenderHint(QPainter::Antialiasing,
options.graphAntiAliasing);
SET_VIEW_OPTION(palette, setPalette);
SET_VIEW_OPTION(mapOpacity, setMapOpacity);
SET_VIEW_OPTION(backgroundColor, setBackgroundColor);
SET_VIEW_OPTION(trackWidth, setTrackWidth);
SET_VIEW_OPTION(routeWidth, setRouteWidth);
SET_VIEW_OPTION(trackStyle, setTrackStyle);
SET_VIEW_OPTION(routeStyle, setRouteStyle);
SET_VIEW_OPTION(waypointSize, setWaypointSize);
SET_VIEW_OPTION(waypointColor, setWaypointColor);
SET_VIEW_OPTION(poiSize, setPOISize);
SET_VIEW_OPTION(poiColor, setPOIColor);
SET_VIEW_OPTION(pathAntiAliasing, useAntiAliasing);
SET_VIEW_OPTION(useOpenGL, useOpenGL);
if (options.elevationFilter != _options.elevationFilter) {
Track::setElevationFilter(options.elevationFilter);
reload = true;
}
if (options.speedFilter != _options.speedFilter) {
Track::setSpeedFilter(options.speedFilter);
reload = true;
}
if (options.heartRateFilter != _options.heartRateFilter) {
Track::setHeartRateFilter(options.heartRateFilter);
reload = true;
}
if (options.cadenceFilter != _options.cadenceFilter) {
Track::setCadenceFilter(options.cadenceFilter);
reload = true;
}
if (options.powerFilter != _options.powerFilter) {
Track::setPowerFilter(options.powerFilter);
reload = true;
}
if (options.outlierEliminate != _options.outlierEliminate) {
Track::setOutlierElimination(options.outlierEliminate);
reload = true;
}
if (options.pauseSpeed != _options.pauseSpeed) {
Track::setPauseSpeed(options.pauseSpeed);
reload = true;
}
if (options.pauseInterval != _options.pauseInterval) {
Track::setPauseInterval(options.pauseInterval);
reload = true;
}
SET_TAB_OPTION(palette, setPalette);
SET_TAB_OPTION(graphWidth, setGraphWidth);
SET_TAB_OPTION(graphAntiAliasing, useAntiAliasing);
SET_TAB_OPTION(useOpenGL, useOpenGL);
SET_TRACK_OPTION(elevationFilter, setElevationFilter);
SET_TRACK_OPTION(speedFilter, setSpeedFilter);
SET_TRACK_OPTION(heartRateFilter, setHeartRateFilter);
SET_TRACK_OPTION(cadenceFilter, setCadenceFilter);
SET_TRACK_OPTION(powerFilter, setPowerFilter);
SET_TRACK_OPTION(outlierEliminate, setOutlierElimination);
SET_TRACK_OPTION(pauseSpeed, setPauseSpeed);
SET_TRACK_OPTION(pauseInterval, setPauseInterval);
if (options.poiRadius != _options.poiRadius)
_poi->setRadius(options.poiRadius);
if (options.useOpenGL != _options.useOpenGL) {
_pathView->useOpenGL(options.useOpenGL);
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->useOpenGL(options.useOpenGL);
}
if (options.pixmapCache != _options.pixmapCache)
QPixmapCache::setCacheLimit(options.pixmapCache * 1024);
@ -1618,8 +1584,8 @@ void GUI::writeSettings()
settings.setValue(PALETTE_SHIFT_SETTING, _options.palette.shift());
if (_options.mapOpacity != MAP_OPACITY_DEFAULT)
settings.setValue(MAP_OPACITY_SETTING, _options.mapOpacity);
if (_options.blendColor != BLEND_COLOR_DEFAULT)
settings.setValue(BLEND_COLOR_SETTING, _options.blendColor);
if (_options.backgroundColor != BACKGROUND_COLOR_DEFAULT)
settings.setValue(BACKGROUND_COLOR_SETTING, _options.backgroundColor);
if (_options.trackWidth != TRACK_WIDTH_DEFAULT)
settings.setValue(TRACK_WIDTH_SETTING, _options.trackWidth);
if (_options.routeWidth != ROUTE_WIDTH_DEFAULT)
@ -1829,8 +1795,8 @@ void GUI::readSettings()
_options.palette = Palette(pc, ps);
_options.mapOpacity = settings.value(MAP_OPACITY_SETTING,
MAP_OPACITY_DEFAULT).toInt();
_options.blendColor = settings.value(BLEND_COLOR_SETTING,
BLEND_COLOR_DEFAULT).value<QColor>();
_options.backgroundColor = settings.value(BACKGROUND_COLOR_SETTING,
BACKGROUND_COLOR_DEFAULT).value<QColor>();
_options.trackWidth = settings.value(TRACK_WIDTH_SETTING,
TRACK_WIDTH_DEFAULT).toInt();
_options.routeWidth = settings.value(ROUTE_WIDTH_SETTING,
@ -1894,7 +1860,7 @@ void GUI::readSettings()
_pathView->setPalette(_options.palette);
_pathView->setMapOpacity(_options.mapOpacity);
_pathView->setBlendColor(_options.blendColor);
_pathView->setBackgroundColor(_options.backgroundColor);
_pathView->setTrackWidth(_options.trackWidth);
_pathView->setRouteWidth(_options.routeWidth);
_pathView->setTrackStyle(_options.trackStyle);

View File

@ -4,6 +4,7 @@
#include <QObject>
#include <QString>
#include <QRectF>
#include <QColor>
class QPainter;
class Coordinates;
@ -14,7 +15,7 @@ class Map : public QObject
Q_OBJECT
public:
Map(QObject *parent = 0) : QObject(parent) {}
Map(QObject *parent = 0) : QObject(parent) {_backgroundColor = Qt::white;}
virtual const QString &name() const = 0;
@ -37,8 +38,13 @@ public:
virtual void load() {}
virtual void unload() {}
void setBackgroundColor(const QColor &color) {_backgroundColor = color;}
signals:
void loaded();
protected:
QColor _backgroundColor;
};
#endif // MAP_H

View File

@ -609,7 +609,8 @@ void OfflineMap::drawTiled(QPainter *painter, const QRectF &rect)
int y = tl.y() + j * _tileSize.height();
if (!QRectF(QPointF(x, y), _tileSize).intersects(bounds())) {
painter->fillRect(QRectF(QPoint(x, y), _tileSize), Qt::white);
painter->fillRect(QRectF(QPoint(x, y), _tileSize),
_backgroundColor);
continue;
}
@ -631,7 +632,8 @@ void OfflineMap::drawTiled(QPainter *painter, const QRectF &rect)
if (pixmap.isNull()) {
qWarning("%s: error loading tile image", qPrintable(
_tileName.arg(QString::number(x), QString::number(y))));
painter->fillRect(QRectF(QPoint(x, y), _tileSize), Qt::white);
painter->fillRect(QRectF(QPoint(x, y), _tileSize),
_backgroundColor);
} else
painter->drawPixmap(QPoint(x, y), pixmap);
}
@ -652,7 +654,7 @@ void OfflineMap::drawOZF(QPainter *painter, const QRectF &rect)
if (!QRectF(QPointF(x, y), _ozf.tileSize()).intersects(bounds())) {
painter->fillRect(QRectF(QPoint(x, y), _ozf.tileSize()),
Qt::white);
_backgroundColor);
continue;
}
@ -668,7 +670,7 @@ void OfflineMap::drawOZF(QPainter *painter, const QRectF &rect)
if (pixmap.isNull()) {
qWarning("%s: error loading tile image", qPrintable(key));
painter->fillRect(QRectF(QPoint(x, y), _ozf.tileSize()),
Qt::white);
_backgroundColor);
} else
painter->drawPixmap(QPoint(x, y), pixmap);
}
@ -678,7 +680,7 @@ void OfflineMap::drawOZF(QPainter *painter, const QRectF &rect)
void OfflineMap::drawImage(QPainter *painter, const QRectF &rect)
{
if (!_img || _img->isNull())
painter->fillRect(rect, Qt::white);
painter->fillRect(rect, _backgroundColor);
else {
QRect r(rect.toRect());
painter->drawImage(r.left(), r.top(), *_img, r.left(), r.top(),

View File

@ -34,12 +34,6 @@ static int scale2zoom(qreal scale)
return (int)log2(360.0/(scale * (qreal)TILE_SIZE));
}
static void fillTile(Tile &tile)
{
tile.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE);
tile.pixmap().fill();
}
static bool loadTileFile(Tile &tile, const QString &file)
{
if (!tile.pixmap().load(file)) {
@ -69,6 +63,12 @@ OnlineMap::OnlineMap(const QString &name, const QString &url,
qWarning("Error creating tiles dir: %s\n", qPrintable(path));
}
void OnlineMap::fillTile(Tile &tile)
{
tile.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE);
tile.pixmap().fill(_backgroundColor);
}
void OnlineMap::emitLoaded()
{
emit loaded();

View File

@ -41,6 +41,7 @@ private slots:
void emitLoaded();
private:
void fillTile(Tile &tile);
QString tileUrl(const Tile &tile) const;
QString tileFile(const Tile &tile) const;
void loadTilesAsync(QList<Tile> &list);

View File

@ -51,7 +51,7 @@ QWidget *OptionsDialog::createAppearancePage()
#ifndef Q_OS_MAC
QGroupBox *colorBox = new QGroupBox(tr("Colors"));
colorBox->setLayout(paletteLayout);
#endif
#endif // Q_OS_MAC
_trackWidth = new QSpinBox();
_trackWidth->setValue(_options->trackWidth);
@ -59,12 +59,15 @@ QWidget *OptionsDialog::createAppearancePage()
_trackStyle = new StyleComboBox();
_trackStyle->setValue(_options->trackStyle);
QFormLayout *trackLayout = new QFormLayout();
#ifdef Q_OS_MAC
trackLayout->addRow(tr("Track width:"), _trackWidth);
trackLayout->addRow(tr("Track style:"), _trackStyle);
#ifndef Q_OS_MAC
#else // Q_OS_MAC
trackLayout->addRow(tr("Width:"), _trackWidth);
trackLayout->addRow(tr("Style:"), _trackStyle);
QGroupBox *trackBox = new QGroupBox(tr("Tracks"));
trackBox->setLayout(trackLayout);
#endif
#endif // Q_OS_MAC
_routeWidth = new QSpinBox();
_routeWidth->setValue(_options->routeWidth);
@ -72,9 +75,12 @@ QWidget *OptionsDialog::createAppearancePage()
_routeStyle = new StyleComboBox();
_routeStyle->setValue(_options->routeStyle);
QFormLayout *routeLayout = new QFormLayout();
#ifdef Q_OS_MAC
routeLayout->addRow(tr("Route width:"), _routeWidth);
routeLayout->addRow(tr("Route style:"), _routeStyle);
#ifndef Q_OS_MAC
#else // Q_OS_MAC
routeLayout->addRow(tr("Width:"), _routeWidth);
routeLayout->addRow(tr("Style:"), _routeStyle);
QGroupBox *routeBox = new QGroupBox(tr("Routes"));
routeBox->setLayout(routeLayout);
#endif // Q_OS_MAC
@ -105,25 +111,33 @@ QWidget *OptionsDialog::createAppearancePage()
// Waypoints
_waypointSize = new QSpinBox();
_waypointSize->setMinimum(1);
_waypointSize->setValue(_options->waypointSize);
_waypointColor = new ColorBox();
_waypointColor->setColor(_options->waypointColor);
QFormLayout *waypointLayout = new QFormLayout();
#ifdef Q_OS_MAC
waypointLayout->addRow(tr("Waypoint color:"), _waypointColor);
waypointLayout->addRow(tr("Waypoint size:"), _waypointSize);
#ifndef Q_OS_MAC
#else // Q_OS_MAC
waypointLayout->addRow(tr("Color:"), _waypointColor);
waypointLayout->addRow(tr("Size:"), _waypointSize);
QGroupBox *waypointBox = new QGroupBox(tr("Waypoints"));
waypointBox->setLayout(waypointLayout);
#endif // Q_OS_MAC
_poiSize = new QSpinBox();
_poiSize->setMinimum(1);
_poiSize->setValue(_options->poiSize);
_poiColor = new ColorBox();
_poiColor->setColor(_options->poiColor);
QFormLayout *poiLayout = new QFormLayout();
#ifdef Q_OS_MAC
poiLayout->addRow(tr("POI color:"), _poiColor);
poiLayout->addRow(tr("POI size:"), _poiSize);
#ifndef Q_OS_MAC
#else // Q_OS_MAC
poiLayout->addRow(tr("Color:"), _poiColor);
poiLayout->addRow(tr("Size:"), _poiSize);
QGroupBox *poiBox = new QGroupBox(tr("POIs"));
poiBox->setLayout(poiLayout);
#endif // Q_OS_MAC
@ -165,10 +179,10 @@ QWidget *OptionsDialog::createAppearancePage()
// Map
_mapOpacity = new PercentSlider();
_mapOpacity->setValue(_options->mapOpacity);
_blendColor = new ColorBox();
_blendColor->setColor(_options->blendColor);
_backgroundColor = new ColorBox();
_backgroundColor->setColor(_options->backgroundColor);
QFormLayout *mapLayout = new QFormLayout();
mapLayout->addRow(tr("Background color:"), _blendColor);
mapLayout->addRow(tr("Background color:"), _backgroundColor);
mapLayout->addRow(tr("Map opacity:"), _mapOpacity);
QWidget *mapTab = new QWidget();
@ -457,7 +471,7 @@ void OptionsDialog::accept()
_options->palette.setColor(_baseColor->color());
_options->palette.setShift(_colorOffset->value());
_options->mapOpacity = _mapOpacity->value();
_options->blendColor = _blendColor->color();
_options->backgroundColor = _backgroundColor->color();
_options->trackWidth = _trackWidth->value();
_options->trackStyle = (Qt::PenStyle) _trackStyle->itemData(
_trackStyle->currentIndex()).toInt();
@ -478,12 +492,16 @@ void OptionsDialog::accept()
_options->cadenceFilter = _cadenceFilter->value();
_options->powerFilter = _powerFilter->value();
_options->outlierEliminate = _outlierEliminate->isChecked();
_options->pauseSpeed = (_options->units == Imperial)
qreal pauseSpeed = (_options->units == Imperial)
? _pauseSpeed->value() / MS2MIH : _pauseSpeed->value() / MS2KMH;
if (qAbs(pauseSpeed - _options->pauseSpeed) > 0.01)
_options->pauseSpeed = pauseSpeed;
_options->pauseInterval = _pauseInterval->value();
_options->poiRadius = (_options->units == Imperial)
qreal poiRadius = (_options->units == Imperial)
? _poiRadius->value() * MIINM : _poiRadius->value() * KMINM;
if (qAbs(poiRadius - _options->poiRadius) > 0.01)
_options->poiRadius = poiRadius;
_options->useOpenGL = _useOpenGL->isChecked();
_options->pixmapCache = _pixmapCache->value();

View File

@ -30,7 +30,7 @@ struct Options {
bool pathAntiAliasing;
bool graphAntiAliasing;
int mapOpacity;
QColor blendColor;
QColor backgroundColor;
// Data
int elevationFilter;
int speedFilter;
@ -81,7 +81,7 @@ private:
ColorBox *_baseColor;
QDoubleSpinBox *_colorOffset;
PercentSlider *_mapOpacity;
ColorBox *_blendColor;
ColorBox *_backgroundColor;
QSpinBox *_trackWidth;
StyleComboBox *_trackStyle;
QSpinBox *_routeWidth;

View File

@ -47,7 +47,7 @@ PathView::PathView(Map *map, POI *poi, QWidget *parent)
_units = Metric;
_opacity = 1.0;
_blendColor = Qt::white;
_backgroundColor = Qt::white;
_showMap = true;
_showTracks = true;
@ -70,6 +70,7 @@ PathView::PathView(Map *map, POI *poi, QWidget *parent)
_plot = false;
_digitalZoom = 0;
_map->setBackgroundColor(_backgroundColor);
_scene->setSceneRect(_map->bounds());
_res = _map->resolution(_scene->sceneRect().center());
}
@ -730,9 +731,10 @@ void PathView::setMapOpacity(int opacity)
resetCachedContent();
}
void PathView::setBlendColor(const QColor &color)
void PathView::setBackgroundColor(const QColor &color)
{
_blendColor = color;
_backgroundColor = color;
_map->setBackgroundColor(color);
resetCachedContent();
}
@ -740,12 +742,12 @@ void PathView::drawBackground(QPainter *painter, const QRectF &rect)
{
if (_showMap) {
if (_opacity < 1.0) {
painter->fillRect(rect, _blendColor);
painter->fillRect(rect, _backgroundColor);
painter->setOpacity(_opacity);
}
_map->draw(painter, rect);
} else
painter->fillRect(rect, Qt::white);
painter->fillRect(rect, _backgroundColor);
}
void PathView::resizeEvent(QResizeEvent *event)
@ -794,3 +796,8 @@ void PathView::useOpenGL(bool use)
else
setViewport(new QWidget);
}
void PathView::useAntiAliasing(bool use)
{
setRenderHint(QPainter::Antialiasing, use);
}

View File

@ -45,7 +45,18 @@ public:
void clear();
void setTrackWidth(int width);
void setRouteWidth(int width);
void setTrackStyle(Qt::PenStyle style);
void setRouteStyle(Qt::PenStyle style);
void setWaypointSize(int size);
void setWaypointColor(const QColor &color);
void setPOISize(int size);
void setPOIColor(const QColor &color);
void setMapOpacity(int opacity);
void setBackgroundColor(const QColor &color);
void useOpenGL(bool use);
void useAntiAliasing(bool use);
public slots:
void redraw();
@ -59,16 +70,6 @@ public slots:
void showRoutes(bool show);
void showWaypoints(bool show);
void showRouteWaypoints(bool show);
void setTrackWidth(int width);
void setRouteWidth(int width);
void setTrackStyle(Qt::PenStyle style);
void setRouteStyle(Qt::PenStyle style);
void setWaypointSize(int size);
void setWaypointColor(const QColor &color);
void setPOISize(int size);
void setPOIColor(const QColor &color);
void setMapOpacity(int opacity);
void setBlendColor(const QColor &color);
private slots:
void updatePOI();
@ -114,7 +115,7 @@ private:
Units _units;
qreal _opacity;
QColor _blendColor;
QColor _backgroundColor;
bool _showMap;
bool _showTracks;
bool _showRoutes;

View File

@ -80,8 +80,8 @@
#define PALETTE_SHIFT_DEFAULT 0.62
#define MAP_OPACITY_SETTING "mapOpacity"
#define MAP_OPACITY_DEFAULT 100
#define BLEND_COLOR_SETTING "blendColor"
#define BLEND_COLOR_DEFAULT QColor(Qt::white)
#define BACKGROUND_COLOR_SETTING "backgroundColor"
#define BACKGROUND_COLOR_DEFAULT QColor(Qt::white)
#define TRACK_WIDTH_SETTING "trackWidth"
#define TRACK_WIDTH_DEFAULT 3
#define ROUTE_WIDTH_SETTING "routeWidth"