1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 23:03:22 +02:00
GPXSee/src/optionsdialog.cpp

502 lines
16 KiB
C++
Raw Normal View History

2016-12-06 01:48:26 +01:00
#include <QVBoxLayout>
#include <QFormLayout>
#include <QDialogButtonBox>
#include <QListWidget>
#include <QListWidgetItem>
#include <QStackedWidget>
#include <QTabWidget>
#include <QSpinBox>
#include <QGroupBox>
#include <QCheckBox>
#include <QComboBox>
#include <QRadioButton>
2017-05-23 12:50:46 +02:00
#include <QLabel>
2016-12-06 01:48:26 +01:00
#include <QSysInfo>
#include "config.h"
#include "icons.h"
#include "colorbox.h"
#include "stylecombobox.h"
#include "oddspinbox.h"
#include "percentslider.h"
2016-12-06 01:48:26 +01:00
#include "optionsdialog.h"
2016-12-06 01:48:26 +01:00
#define MENU_MARGIN 20
2016-12-07 21:38:36 +01:00
#define MENU_ICON_SIZE 32
2016-12-06 01:48:26 +01:00
#ifdef Q_OS_MAC
static QFrame *line()
{
QFrame *l = new QFrame();
l->setFrameShape(QFrame::HLine);
l->setFrameShadow(QFrame::Sunken);
return l;
}
#endif
2016-12-06 01:48:26 +01:00
QWidget *OptionsDialog::createAppearancePage()
{
// Paths
2016-12-06 01:48:26 +01:00
_baseColor = new ColorBox();
_baseColor->setColor(_options->palette.color());
_colorOffset = new QDoubleSpinBox();
_colorOffset->setMinimum(0);
_colorOffset->setMaximum(1.0);
_colorOffset->setSingleStep(0.01);
_colorOffset->setValue(_options->palette.shift());
QFormLayout *paletteLayout = new QFormLayout();
paletteLayout->addRow(tr("Base color:"), _baseColor);
paletteLayout->addRow(tr("Palette shift:"), _colorOffset);
#ifndef Q_OS_MAC
QGroupBox *colorBox = new QGroupBox(tr("Colors"));
colorBox->setLayout(paletteLayout);
#endif
2016-12-06 01:48:26 +01:00
_trackWidth = new QSpinBox();
_trackWidth->setValue(_options->trackWidth);
_trackWidth->setMinimum(1);
_trackStyle = new StyleComboBox();
_trackStyle->setValue(_options->trackStyle);
QFormLayout *trackLayout = new QFormLayout();
2016-12-07 21:38:36 +01:00
trackLayout->addRow(tr("Track width:"), _trackWidth);
trackLayout->addRow(tr("Track style:"), _trackStyle);
#ifndef Q_OS_MAC
QGroupBox *trackBox = new QGroupBox(tr("Tracks"));
2016-12-06 01:48:26 +01:00
trackBox->setLayout(trackLayout);
2016-12-07 21:38:36 +01:00
#endif
2016-12-06 01:48:26 +01:00
_routeWidth = new QSpinBox();
_routeWidth->setValue(_options->routeWidth);
_routeWidth->setMinimum(1);
_routeStyle = new StyleComboBox();
_routeStyle->setValue(_options->routeStyle);
QFormLayout *routeLayout = new QFormLayout();
2016-12-07 21:38:36 +01:00
routeLayout->addRow(tr("Route width:"), _routeWidth);
routeLayout->addRow(tr("Route style:"), _routeStyle);
#ifndef Q_OS_MAC
QGroupBox *routeBox = new QGroupBox(tr("Routes"));
2016-12-06 01:48:26 +01:00
routeBox->setLayout(routeLayout);
2016-12-07 21:38:36 +01:00
#endif // Q_OS_MAC
2016-12-06 01:48:26 +01:00
_pathAA = new QCheckBox(tr("Use anti-aliasing"));
_pathAA->setChecked(_options->pathAntiAliasing);
2016-12-07 21:38:36 +01:00
QFormLayout *pathAALayout = new QFormLayout();
pathAALayout->addWidget(_pathAA);
2016-12-06 01:48:26 +01:00
QWidget *pathTab = new QWidget();
QVBoxLayout *pathTabLayout = new QVBoxLayout();
2016-12-07 21:38:36 +01:00
#ifdef Q_OS_MAC
pathTabLayout->addLayout(paletteLayout);
pathTabLayout->addWidget(line());
2016-12-07 21:38:36 +01:00
pathTabLayout->addLayout(trackLayout);
pathTabLayout->addWidget(line());
2016-12-07 21:38:36 +01:00
pathTabLayout->addLayout(routeLayout);
pathTabLayout->addWidget(line());
2017-05-23 12:50:46 +02:00
#else // Q_OS_MAC
pathTabLayout->addWidget(colorBox);
2016-12-06 01:48:26 +01:00
pathTabLayout->addWidget(trackBox);
pathTabLayout->addWidget(routeBox);
2017-05-23 12:50:46 +02:00
#endif // Q_OS_MAC
2016-12-07 21:38:36 +01:00
pathTabLayout->addLayout(pathAALayout);
2017-05-22 17:04:37 +02:00
pathTabLayout->addStretch();
2016-12-06 01:48:26 +01:00
pathTab->setLayout(pathTabLayout);
// Waypoints
_waypointSize = new QSpinBox();
_waypointSize->setValue(_options->waypointSize);
_waypointColor = new ColorBox();
_waypointColor->setColor(_options->waypointColor);
QFormLayout *waypointLayout = new QFormLayout();
waypointLayout->addRow(tr("Waypoint color:"), _waypointColor);
waypointLayout->addRow(tr("Waypoint size:"), _waypointSize);
#ifndef Q_OS_MAC
QGroupBox *waypointBox = new QGroupBox(tr("Waypoints"));
waypointBox->setLayout(waypointLayout);
#endif // Q_OS_MAC
_poiSize = new QSpinBox();
_poiSize->setValue(_options->poiSize);
_poiColor = new ColorBox();
_poiColor->setColor(_options->poiColor);
QFormLayout *poiLayout = new QFormLayout();
poiLayout->addRow(tr("POI color:"), _poiColor);
poiLayout->addRow(tr("POI size:"), _poiSize);
#ifndef Q_OS_MAC
QGroupBox *poiBox = new QGroupBox(tr("POIs"));
poiBox->setLayout(poiLayout);
#endif // Q_OS_MAC
QWidget *pointTab = new QWidget();
QVBoxLayout *pointTabLayout = new QVBoxLayout();
#ifdef Q_OS_MAC
pointTabLayout->addLayout(waypointLayout);
2017-09-10 12:53:51 +02:00
pointTabLayout->addWidget(line());
pointTabLayout->addLayout(poiLayout);
#else // Q_OS_MAC
pointTabLayout->addWidget(waypointBox);
pointTabLayout->addWidget(poiBox);
#endif // Q_OS_MAC
pointTabLayout->addStretch();
pointTab->setLayout(pointTabLayout);
// Graphs
2016-12-06 01:48:26 +01:00
_graphWidth = new QSpinBox();
_graphWidth->setValue(_options->graphWidth);
_graphWidth->setMinimum(1);
QFormLayout *graphLayout = new QFormLayout();
graphLayout->addRow(tr("Line width:"), _graphWidth);
_graphAA = new QCheckBox(tr("Use anti-aliasing"));
_graphAA->setChecked(_options->graphAntiAliasing);
2016-12-07 21:38:36 +01:00
QFormLayout *graphAALayout = new QFormLayout();
graphAALayout->addWidget(_graphAA);
2016-12-06 01:48:26 +01:00
QWidget *graphTab = new QWidget();
QVBoxLayout *graphTabLayout = new QVBoxLayout();
graphTabLayout->addLayout(graphLayout);
2016-12-07 21:38:36 +01:00
graphTabLayout->addLayout(graphAALayout);
2016-12-06 01:48:26 +01:00
graphTabLayout->addStretch();
graphTab->setLayout(graphTabLayout);
// Map
_mapOpacity = new PercentSlider();
_mapOpacity->setValue(_options->mapOpacity);
_blendColor = new ColorBox();
_blendColor->setColor(_options->blendColor);
QFormLayout *mapLayout = new QFormLayout();
mapLayout->addRow(tr("Background color:"), _blendColor);
mapLayout->addRow(tr("Map opacity:"), _mapOpacity);
QWidget *mapTab = new QWidget();
QVBoxLayout *mapTabLayout = new QVBoxLayout();
mapTabLayout->addLayout(mapLayout);
mapTabLayout->addStretch();
mapTab->setLayout(mapTabLayout);
2016-12-06 01:48:26 +01:00
QTabWidget *appearancePage = new QTabWidget();
appearancePage->addTab(pathTab, tr("Paths"));
appearancePage->addTab(pointTab, tr("Points"));
2016-12-06 01:48:26 +01:00
appearancePage->addTab(graphTab, tr("Graphs"));
appearancePage->addTab(mapTab, tr("Map"));
2016-12-06 01:48:26 +01:00
return appearancePage;
}
2017-05-22 14:54:22 +02:00
QWidget *OptionsDialog::createDataPage()
{
QString filterToolTip = tr("Moving average window size");
_elevationFilter = new OddSpinBox();
2017-05-22 14:54:22 +02:00
_elevationFilter->setValue(_options->elevationFilter);
_elevationFilter->setToolTip(filterToolTip);
_speedFilter = new OddSpinBox();
2017-05-22 14:54:22 +02:00
_speedFilter->setValue(_options->speedFilter);
_speedFilter->setToolTip(filterToolTip);
_heartRateFilter = new OddSpinBox();
2017-05-22 14:54:22 +02:00
_heartRateFilter->setValue(_options->heartRateFilter);
_heartRateFilter->setToolTip(filterToolTip);
_cadenceFilter = new OddSpinBox();
2017-05-22 14:54:22 +02:00
_cadenceFilter->setValue(_options->cadenceFilter);
_cadenceFilter->setToolTip(filterToolTip);
_powerFilter = new OddSpinBox();
2017-05-22 14:54:22 +02:00
_powerFilter->setValue(_options->powerFilter);
_powerFilter->setToolTip(filterToolTip);
2017-05-22 17:04:37 +02:00
QFormLayout *smoothLayout = new QFormLayout();
smoothLayout->addRow(tr("Elevation:"), _elevationFilter);
smoothLayout->addRow(tr("Speed:"), _speedFilter);
smoothLayout->addRow(tr("Heart rate:"), _heartRateFilter);
smoothLayout->addRow(tr("Cadence:"), _cadenceFilter);
smoothLayout->addRow(tr("Power:"), _powerFilter);
2017-05-23 12:50:46 +02:00
#ifndef Q_OS_MAC
2017-05-22 17:04:37 +02:00
QGroupBox *smoothBox = new QGroupBox(tr("Smoothing"));
smoothBox->setLayout(smoothLayout);
2017-05-23 12:50:46 +02:00
#endif // Q_OS_MAC
2017-05-22 14:54:22 +02:00
2017-05-22 17:04:37 +02:00
_outlierEliminate = new QCheckBox(tr("Eliminate GPS outliers"));
2017-05-22 14:54:22 +02:00
_outlierEliminate->setChecked(_options->outlierEliminate);
QFormLayout *outlierLayout = new QFormLayout();
outlierLayout->addWidget(_outlierEliminate);
2017-05-23 12:50:46 +02:00
#ifndef Q_OS_MAC
2017-05-22 17:04:37 +02:00
QGroupBox *outlierBox = new QGroupBox(tr("Outlier elimination"));
outlierBox->setLayout(outlierLayout);
2017-05-23 12:50:46 +02:00
#endif // Q_OS_MAC
2017-05-22 14:54:22 +02:00
QWidget *filterTab = new QWidget();
QVBoxLayout *filterTabLayout = new QVBoxLayout();
2017-05-23 12:50:46 +02:00
#ifdef Q_OS_MAC
filterTabLayout->addWidget(new QLabel(tr("Smoothing:")));
2017-05-23 12:50:46 +02:00
filterTabLayout->addLayout(smoothLayout);
filterTabLayout->addWidget(line());
2017-05-23 12:50:46 +02:00
filterTabLayout->addLayout(outlierLayout);
#else // Q_OS_MAC
2017-05-22 17:04:37 +02:00
filterTabLayout->addWidget(smoothBox);
2017-05-23 13:43:40 +02:00
filterTabLayout->addWidget(outlierBox);
2017-05-23 12:50:46 +02:00
#endif // Q_OS_MAC
2017-05-22 14:54:22 +02:00
filterTabLayout->addStretch();
filterTab->setLayout(filterTabLayout);
2017-05-22 17:04:37 +02:00
2017-05-22 14:54:22 +02:00
_pauseSpeed = new QDoubleSpinBox();
_pauseSpeed->setDecimals(1);
_pauseSpeed->setSingleStep(0.1);
_pauseSpeed->setMinimum(0.1);
if (_options->units == Imperial) {
_pauseSpeed->setValue(_options->pauseSpeed * MS2MIH);
_pauseSpeed->setSuffix(UNIT_SPACE + tr("mi/h"));
} else {
_pauseSpeed->setValue(_options->pauseSpeed * MS2KMH);
_pauseSpeed->setSuffix(UNIT_SPACE + tr("km/h"));
}
_pauseInterval = new QSpinBox();
_pauseInterval->setMinimum(1);
_pauseInterval->setSuffix(UNIT_SPACE + tr("s"));
_pauseInterval->setValue(_options->pauseInterval);
QFormLayout *pauseLayout = new QFormLayout();
pauseLayout->addRow(tr("Minimal speed:"), _pauseSpeed);
pauseLayout->addRow(tr("Minimal duration:"), _pauseInterval);
QWidget *pauseTab = new QWidget();
pauseTab->setLayout(pauseLayout);
QTabWidget *filterPage = new QTabWidget();
filterPage->addTab(filterTab, tr("Filtering"));
filterPage->addTab(pauseTab, tr("Pause detection"));
return filterPage;
}
2016-12-06 01:48:26 +01:00
QWidget *OptionsDialog::createPOIPage()
{
_poiRadius = new QDoubleSpinBox();
_poiRadius->setSingleStep(1);
_poiRadius->setDecimals(1);
2016-12-07 21:38:36 +01:00
if (_options->units == Imperial) {
_poiRadius->setValue(_options->poiRadius / MIINM);
_poiRadius->setSuffix(UNIT_SPACE + tr("mi"));
} else {
_poiRadius->setValue(_options->poiRadius / KMINM);
_poiRadius->setSuffix(UNIT_SPACE + tr("km"));
}
2016-12-06 01:48:26 +01:00
QFormLayout *poiLayout = new QFormLayout();
poiLayout->addRow(tr("POI radius:"), _poiRadius);
QWidget *poiTab = new QWidget();
poiTab->setLayout(poiLayout);
QTabWidget *poiPage = new QTabWidget();
poiPage->addTab(poiTab, tr("POI"));
return poiPage;
}
QWidget *OptionsDialog::createExportPage()
{
_wysiwyg = new QRadioButton(tr("WYSIWYG"));
2017-08-30 13:56:23 +02:00
_hires = new QRadioButton(tr("High-Resolution"));
if (_options->hiresPrint)
_hires->setChecked(true);
else
_wysiwyg->setChecked(true);
QLabel *lw = new QLabel(tr("The printed area is approximately the display"
" area. The map zoom level does not change."));
QLabel *lh = new QLabel(tr("The zoom level will be changed so that"
2017-08-30 13:56:23 +02:00
" the whole content (tracks/waypoints) fits to the printed area and"
" the map resolution is as close as possible to the print resolution."));
QFont f = lw->font();
f.setPointSize(f.pointSize() - 1);
lw->setWordWrap(true);
lh->setWordWrap(true);
lw->setFont(f);
lh->setFont(f);
QVBoxLayout *modeTabLayout = new QVBoxLayout();
modeTabLayout->addWidget(_wysiwyg);
modeTabLayout->addWidget(lw);
modeTabLayout->addSpacing(10);
modeTabLayout->addWidget(_hires);
modeTabLayout->addWidget(lh);
modeTabLayout->addStretch();
QWidget *modeTab = new QWidget();
modeTab->setLayout(modeTabLayout);
_name = new QCheckBox(tr("Name"));
_name->setChecked(_options->printName);
_date = new QCheckBox(tr("Date"));
_date->setChecked(_options->printDate);
_distance = new QCheckBox(tr("Distance"));
_distance->setChecked(_options->printDistance);
_time = new QCheckBox(tr("Time"));
_time->setChecked(_options->printTime);
_movingTime = new QCheckBox(tr("Moving time"));
_movingTime->setChecked(_options->printMovingTime);
_itemCount = new QCheckBox(tr("Item count (>1)"));
_itemCount->setChecked(_options->printItemCount);
QFormLayout *headerTabLayout = new QFormLayout();
headerTabLayout->addWidget(_name);
headerTabLayout->addWidget(_date);
headerTabLayout->addWidget(_distance);
headerTabLayout->addWidget(_time);
headerTabLayout->addWidget(_movingTime);
headerTabLayout->addItem(new QSpacerItem(10, 10));
headerTabLayout->addWidget(_itemCount);
QWidget *headerTab = new QWidget();
headerTab->setLayout(headerTabLayout);
_separateGraphPage = new QCheckBox(tr("Separate graph page"));
_separateGraphPage->setChecked(_options->separateGraphPage);
QFormLayout *graphTabLayout = new QFormLayout();
graphTabLayout->addWidget(_separateGraphPage);
QWidget *graphTab = new QWidget();
graphTab->setLayout(graphTabLayout);
QTabWidget *exportPage = new QTabWidget();
exportPage->addTab(modeTab, tr("Print mode"));
exportPage->addTab(headerTab, tr("Header"));
exportPage->addTab(graphTab, tr("Graphs"));
return exportPage;
}
2016-12-06 01:48:26 +01:00
QWidget *OptionsDialog::createSystemPage()
{
_useOpenGL = new QCheckBox(tr("Use OpenGL"));
_useOpenGL->setChecked(_options->useOpenGL);
_pixmapCache = new QSpinBox();
_pixmapCache->setMinimum(16);
_pixmapCache->setMaximum(1024);
_pixmapCache->setSuffix(UNIT_SPACE + tr("MB"));
_pixmapCache->setValue(_options->pixmapCache);
QFormLayout *cacheLayout = new QFormLayout();
cacheLayout->addRow(tr("Image cache size:"), _pixmapCache);
QFormLayout *openGLLayout = new QFormLayout();
openGLLayout->addWidget(_useOpenGL);
2016-12-06 01:48:26 +01:00
QWidget *systemTab = new QWidget();
QVBoxLayout *systemTabLayout = new QVBoxLayout();
systemTabLayout->addLayout(cacheLayout);
systemTabLayout->addLayout(openGLLayout);
systemTabLayout->addStretch();
systemTab->setLayout(systemTabLayout);
2016-12-06 01:48:26 +01:00
QTabWidget *systemPage = new QTabWidget();
systemPage->addTab(systemTab, tr("System"));
return systemPage;
}
OptionsDialog::OptionsDialog(Options *options, QWidget *parent)
: QDialog(parent), _options(options)
{
QStackedWidget *pages = new QStackedWidget();
pages->addWidget(createAppearancePage());
2017-05-22 14:54:22 +02:00
pages->addWidget(createDataPage());
2016-12-06 01:48:26 +01:00
pages->addWidget(createPOIPage());
pages->addWidget(createExportPage());
2016-12-06 01:48:26 +01:00
pages->addWidget(createSystemPage());
QListWidget *menu = new QListWidget();
2016-12-07 21:38:36 +01:00
menu->setIconSize(QSize(MENU_ICON_SIZE, MENU_ICON_SIZE));
2016-12-06 01:48:26 +01:00
new QListWidgetItem(QIcon(QPixmap(APPEARANCE_ICON)), tr("Appearance"),
menu);
2017-05-22 14:54:22 +02:00
new QListWidgetItem(QIcon(QPixmap(DATA_ICON)), tr("Data"), menu);
2016-12-06 01:48:26 +01:00
new QListWidgetItem(QIcon(QPixmap(POI_ICON)), tr("POI"), menu);
new QListWidgetItem(QIcon(QPixmap(PRINT_EXPORT_ICON)), tr("Print & Export"),
menu);
2016-12-06 01:48:26 +01:00
new QListWidgetItem(QIcon(QPixmap(SYSTEM_ICON)), tr("System"), menu);
QHBoxLayout *contentLayout = new QHBoxLayout();
contentLayout->addWidget(menu);
contentLayout->addWidget(pages);
menu->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
menu->setMaximumWidth(menu->sizeHintForColumn(0) + 2 * menu->frameWidth()
+ MENU_MARGIN);
pages->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
pages->setMinimumWidth(2 * menu->size().width());
connect(menu, SIGNAL(currentRowChanged(int)), pages,
SLOT(setCurrentIndex(int)));
menu->item(0)->setSelected(true);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addLayout(contentLayout);
layout->addWidget(buttonBox);
setLayout(layout);
setWindowTitle(tr("Options"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
}
void OptionsDialog::accept()
{
_options->palette.setColor(_baseColor->color());
_options->palette.setShift(_colorOffset->value());
_options->mapOpacity = _mapOpacity->value();
_options->blendColor = _blendColor->color();
2016-12-06 01:48:26 +01:00
_options->trackWidth = _trackWidth->value();
_options->trackStyle = (Qt::PenStyle) _trackStyle->itemData(
_trackStyle->currentIndex()).toInt();
_options->routeWidth = _routeWidth->value();
_options->routeStyle = (Qt::PenStyle) _routeStyle->itemData(
_routeStyle->currentIndex()).toInt();
_options->pathAntiAliasing = _pathAA->isChecked();
_options->waypointSize = _waypointSize->value();
_options->waypointColor = _waypointColor->color();
_options->poiSize = _poiSize->value();
_options->poiColor = _poiColor->color();
2016-12-06 01:48:26 +01:00
_options->graphWidth = _graphWidth->value();
_options->graphAntiAliasing = _graphAA->isChecked();
2017-05-22 14:54:22 +02:00
_options->elevationFilter = _elevationFilter->value();
_options->speedFilter = _speedFilter->value();
_options->heartRateFilter = _heartRateFilter->value();
_options->cadenceFilter = _cadenceFilter->value();
_options->powerFilter = _powerFilter->value();
_options->outlierEliminate = _outlierEliminate->isChecked();
_options->pauseSpeed = (_options->units == Imperial)
? _pauseSpeed->value() / MS2MIH : _pauseSpeed->value() / MS2KMH;
_options->pauseInterval = _pauseInterval->value();
_options->poiRadius = (_options->units == Imperial)
? _poiRadius->value() * MIINM : _poiRadius->value() * KMINM;
2016-12-06 01:48:26 +01:00
_options->useOpenGL = _useOpenGL->isChecked();
_options->pixmapCache = _pixmapCache->value();
2016-12-06 01:48:26 +01:00
_options->hiresPrint = _hires->isChecked();
_options->printName = _name->isChecked();
_options->printDate = _date->isChecked();
_options->printDistance = _distance->isChecked();
_options->printTime = _time->isChecked();
_options->printMovingTime = _movingTime->isChecked();
_options->printItemCount = _itemCount->isChecked();
_options->separateGraphPage = _separateGraphPage->isChecked();
2016-12-06 01:48:26 +01:00
QDialog::accept();
}