1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Added map opacity (brightness) settings

This commit is contained in:
Martin Tůma 2017-08-24 17:29:59 +02:00
parent 7b6789e78d
commit f3e4719439
9 changed files with 138 additions and 7 deletions

View File

@ -96,7 +96,8 @@ HEADERS += src/config.h \
src/albersequal.h \ src/albersequal.h \
src/oddspinbox.h \ src/oddspinbox.h \
src/rectc.h \ src/rectc.h \
src/searchpointer.h src/searchpointer.h \
src/percentslider.h
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/gui.cpp \ src/gui.cpp \
src/poi.cpp \ src/poi.cpp \
@ -165,7 +166,8 @@ SOURCES += src/main.cpp \
src/maplist.cpp \ src/maplist.cpp \
src/albersequal.cpp \ src/albersequal.cpp \
src/oddspinbox.cpp \ src/oddspinbox.cpp \
src/rectc.cpp src/rectc.cpp \
src/percentslider.cpp
RESOURCES += gpxsee.qrc RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts \ TRANSLATIONS = lang/gpxsee_cs.ts \
lang/gpxsee_sv.ts \ lang/gpxsee_sv.ts \

View File

@ -877,6 +877,8 @@ void GUI::openOptions()
for (int i = 0; i < _tabs.count(); i++) for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->setPalette(options.palette); _tabs.at(i)->setPalette(options.palette);
} }
if (options.mapOpacity != _options.mapOpacity)
_pathView->setMapOpacity(options.mapOpacity);
if (options.trackWidth != _options.trackWidth) if (options.trackWidth != _options.trackWidth)
_pathView->setTrackWidth(options.trackWidth); _pathView->setTrackWidth(options.trackWidth);
if (options.routeWidth != _options.routeWidth) if (options.routeWidth != _options.routeWidth)
@ -1598,6 +1600,8 @@ void GUI::writeSettings()
settings.setValue(PALETTE_COLOR_SETTING, _options.palette.color()); settings.setValue(PALETTE_COLOR_SETTING, _options.palette.color());
if (_options.palette.shift() != PALETTE_SHIFT_DEFAULT) if (_options.palette.shift() != PALETTE_SHIFT_DEFAULT)
settings.setValue(PALETTE_SHIFT_SETTING, _options.palette.shift()); settings.setValue(PALETTE_SHIFT_SETTING, _options.palette.shift());
if (_options.mapOpacity != MAP_OPACITY_DEFAULT)
settings.setValue(MAP_OPACITY_SETTING, _options.mapOpacity);
if (_options.trackWidth != TRACK_WIDTH_DEFAULT) if (_options.trackWidth != TRACK_WIDTH_DEFAULT)
settings.setValue(TRACK_WIDTH_SETTING, _options.trackWidth); settings.setValue(TRACK_WIDTH_SETTING, _options.trackWidth);
if (_options.routeWidth != ROUTE_WIDTH_DEFAULT) if (_options.routeWidth != ROUTE_WIDTH_DEFAULT)
@ -1793,6 +1797,8 @@ void GUI::readSettings()
qreal ps = settings.value(PALETTE_SHIFT_SETTING, PALETTE_SHIFT_DEFAULT) qreal ps = settings.value(PALETTE_SHIFT_SETTING, PALETTE_SHIFT_DEFAULT)
.toDouble(); .toDouble();
_options.palette = Palette(pc, ps); _options.palette = Palette(pc, ps);
_options.mapOpacity = settings.value(MAP_OPACITY_SETTING,
MAP_OPACITY_DEFAULT).toInt();
_options.trackWidth = settings.value(TRACK_WIDTH_SETTING, _options.trackWidth = settings.value(TRACK_WIDTH_SETTING,
TRACK_WIDTH_DEFAULT).toInt(); TRACK_WIDTH_DEFAULT).toInt();
_options.routeWidth = settings.value(ROUTE_WIDTH_SETTING, _options.routeWidth = settings.value(ROUTE_WIDTH_SETTING,
@ -1845,6 +1851,7 @@ void GUI::readSettings()
SEPARATE_GRAPH_PAGE_DEFAULT).toBool(); SEPARATE_GRAPH_PAGE_DEFAULT).toBool();
_pathView->setPalette(_options.palette); _pathView->setPalette(_options.palette);
_pathView->setMapOpacity(_options.mapOpacity);
_pathView->setTrackWidth(_options.trackWidth); _pathView->setTrackWidth(_options.trackWidth);
_pathView->setRouteWidth(_options.routeWidth); _pathView->setRouteWidth(_options.routeWidth);
_pathView->setTrackStyle(_options.trackStyle); _pathView->setTrackStyle(_options.trackStyle);

View File

@ -16,12 +16,13 @@
#include "colorbox.h" #include "colorbox.h"
#include "stylecombobox.h" #include "stylecombobox.h"
#include "oddspinbox.h" #include "oddspinbox.h"
#include "percentslider.h"
#include "optionsdialog.h" #include "optionsdialog.h"
#define MENU_MARGIN 20 #define MENU_MARGIN 20
#define MENU_ICON_SIZE 32 #define MENU_ICON_SIZE 32
QWidget *OptionsDialog::createAppearancePage() QWidget *OptionsDialog::createAppearancePage()
{ {
_baseColor = new ColorBox(); _baseColor = new ColorBox();
@ -31,14 +32,39 @@ QWidget *OptionsDialog::createAppearancePage()
_colorOffset->setMaximum(1.0); _colorOffset->setMaximum(1.0);
_colorOffset->setSingleStep(0.01); _colorOffset->setSingleStep(0.01);
_colorOffset->setValue(_options->palette.shift()); _colorOffset->setValue(_options->palette.shift());
QFormLayout *paletteLayout = new QFormLayout(); QFormLayout *paletteLayout = new QFormLayout();
paletteLayout->addRow(tr("Base color:"), _baseColor); paletteLayout->addRow(tr("Base color:"), _baseColor);
paletteLayout->addRow(tr("Palette shift:"), _colorOffset); paletteLayout->addRow(tr("Palette shift:"), _colorOffset);
#ifndef Q_OS_MAC
QGroupBox *pathsBox = new QGroupBox(tr("Paths"));
pathsBox->setLayout(paletteLayout);
#endif
_mapOpacity = new PercentSlider();
_mapOpacity->setValue(_options->mapOpacity);
QFormLayout *mapLayout = new QFormLayout();
mapLayout->addRow(tr("Map opacity:"), _mapOpacity);
#ifndef Q_OS_MAC
QGroupBox *mapBox = new QGroupBox(tr("Map"));
mapBox->setLayout(mapLayout);
#endif
QWidget *colorTab = new QWidget(); QWidget *colorTab = new QWidget();
colorTab->setLayout(paletteLayout); QVBoxLayout *colorTabLayout = new QVBoxLayout();
#ifdef Q_OS_MAC
QFrame *l0 = new QFrame();
l0->setFrameShape(QFrame::HLine);
l0->setFrameShadow(QFrame::Sunken);
colorTabLayout->addLayout(paletteLayout);
colorTabLayout->addWidget(l0);
colorTabLayout->addLayout(mapLayout);
#else // Q_OS_MAC
colorTabLayout->addWidget(pathsBox);
colorTabLayout->addWidget(mapBox);
#endif // O_OS_MAC
colorTabLayout->addStretch();
colorTab->setLayout(colorTabLayout);
_trackWidth = new QSpinBox(); _trackWidth = new QSpinBox();
_trackWidth->setValue(_options->trackWidth); _trackWidth->setValue(_options->trackWidth);
@ -369,6 +395,7 @@ void OptionsDialog::accept()
{ {
_options->palette.setColor(_baseColor->color()); _options->palette.setColor(_baseColor->color());
_options->palette.setShift(_colorOffset->value()); _options->palette.setShift(_colorOffset->value());
_options->mapOpacity = _mapOpacity->value();
_options->trackWidth = _trackWidth->value(); _options->trackWidth = _trackWidth->value();
_options->trackStyle = (Qt::PenStyle) _trackStyle->itemData( _options->trackStyle = (Qt::PenStyle) _trackStyle->itemData(
_trackStyle->currentIndex()).toInt(); _trackStyle->currentIndex()).toInt();

View File

@ -12,10 +12,12 @@ class QSpinBox;
class QDoubleSpinBox; class QDoubleSpinBox;
class QComboBox; class QComboBox;
class QCheckBox; class QCheckBox;
class PercentSlider;
struct Options { struct Options {
// Appearance // Appearance
Palette palette; Palette palette;
int mapOpacity;
int trackWidth; int trackWidth;
int routeWidth; int routeWidth;
Qt::PenStyle trackStyle; Qt::PenStyle trackStyle;
@ -71,6 +73,7 @@ private:
// Appearance // Appearance
ColorBox *_baseColor; ColorBox *_baseColor;
QDoubleSpinBox *_colorOffset; QDoubleSpinBox *_colorOffset;
PercentSlider *_mapOpacity;
QSpinBox *_trackWidth; QSpinBox *_trackWidth;
StyleComboBox *_trackStyle; StyleComboBox *_trackStyle;
QSpinBox *_routeWidth; QSpinBox *_routeWidth;

View File

@ -46,6 +46,7 @@ PathView::PathView(Map *map, POI *poi, QWidget *parent)
connect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI())); connect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
_units = Metric; _units = Metric;
_opacity = 1.0;
_showMap = true; _showMap = true;
_showTracks = true; _showTracks = true;
@ -637,11 +638,21 @@ void PathView::setRouteStyle(Qt::PenStyle style)
_routes.at(i)->setStyle(style); _routes.at(i)->setStyle(style);
} }
void PathView::setMapOpacity(int opacity)
{
_opacity = opacity / 100.0;
resetCachedContent();
}
void PathView::drawBackground(QPainter *painter, const QRectF &rect) void PathView::drawBackground(QPainter *painter, const QRectF &rect)
{ {
if (_showMap) if (_showMap) {
if (_opacity < 1.0) {
painter->fillRect(rect, Qt::white);
painter->setOpacity(_opacity);
}
_map->draw(painter, rect); _map->draw(painter, rect);
else } else
painter->fillRect(rect, Qt::white); painter->fillRect(rect, Qt::white);
} }

View File

@ -63,6 +63,7 @@ public slots:
void setRouteWidth(int width); void setRouteWidth(int width);
void setTrackStyle(Qt::PenStyle style); void setTrackStyle(Qt::PenStyle style);
void setRouteStyle(Qt::PenStyle style); void setRouteStyle(Qt::PenStyle style);
void setMapOpacity(int opacity);
private slots: private slots:
void updatePOI(); void updatePOI();
@ -106,6 +107,7 @@ private:
POI *_poi; POI *_poi;
Palette _palette; Palette _palette;
Units _units; Units _units;
qreal _opacity;
bool _showMap; bool _showMap;
bool _showTracks; bool _showTracks;

48
src/percentslider.cpp Normal file
View File

@ -0,0 +1,48 @@
#include <QSlider>
#include <QLabel>
#include <QHBoxLayout>
#include "units.h"
#include "percentslider.h"
static QString format(int value)
{
return QString::number(value) + UNIT_SPACE + QString("%");
}
PercentSlider::PercentSlider(QWidget *parent) : QWidget(parent)
{
_slider = new QSlider(Qt::Horizontal);
_label = new QLabel();
_slider->setMinimum(0);
_slider->setMaximum(100);
QFontMetrics fm(_label->font());
_label->setFixedWidth(fm.boundingRect(format(_slider->maximum())).width());
_label->setAlignment(Qt::AlignRight);
connect(_slider, SIGNAL(sliderMoved(int)), this, SLOT(updateLabel(int)));
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(_slider);
layout->addWidget(_label);
setLayout(layout);
}
void PercentSlider::updateLabel(int value)
{
_label->setText(format(value));
}
int PercentSlider::value() const
{
return _slider->value();
}
void PercentSlider::setValue(int value)
{
_slider->setValue(value);
_label->setText(format(value));
}

29
src/percentslider.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef PERCENTSLIDER_H
#define PERCENTSLIDER_H
#include <QWidget>
class QSlider;
class QLabel;
class PercentSlider : public QWidget
{
Q_OBJECT
public:
PercentSlider(QWidget *parent = 0);
int value() const;
public slots:
void setValue(int value);
private slots:
void updateLabel(int value);
private:
QSlider *_slider;
QLabel *_label;
};
#endif // PERCENTSLIDER_H

View File

@ -76,6 +76,8 @@
#define PALETTE_COLOR_DEFAULT QColor(Qt::blue) #define PALETTE_COLOR_DEFAULT QColor(Qt::blue)
#define PALETTE_SHIFT_SETTING "paletteShift" #define PALETTE_SHIFT_SETTING "paletteShift"
#define PALETTE_SHIFT_DEFAULT 0.62 #define PALETTE_SHIFT_DEFAULT 0.62
#define MAP_OPACITY_SETTING "mapOpacity"
#define MAP_OPACITY_DEFAULT 100
#define TRACK_WIDTH_SETTING "trackWidth" #define TRACK_WIDTH_SETTING "trackWidth"
#define TRACK_WIDTH_DEFAULT 3 #define TRACK_WIDTH_DEFAULT 3
#define ROUTE_WIDTH_SETTING "routeWidth" #define ROUTE_WIDTH_SETTING "routeWidth"