mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-27 21:24:47 +01:00
Margins widget refactoring
This commit is contained in:
parent
a1be73fbba
commit
789f314ae8
@ -21,6 +21,7 @@ INCLUDEPATH += ./src
|
||||
HEADERS += src/common/config.h \
|
||||
src/GUI/graphicsscene.h \
|
||||
src/GUI/mapaction.h \
|
||||
src/GUI/marginswidget.h \
|
||||
src/GUI/popup.h \
|
||||
src/common/garmin.h \
|
||||
src/common/staticassert.h \
|
||||
@ -201,6 +202,7 @@ HEADERS += src/common/config.h \
|
||||
src/GUI/pdfexportdialog.h \
|
||||
src/GUI/pngexportdialog.h
|
||||
SOURCES += src/main.cpp \
|
||||
src/GUI/marginswidget.cpp \
|
||||
src/GUI/popup.cpp \
|
||||
src/common/coordinates.cpp \
|
||||
src/common/rectc.cpp \
|
||||
|
@ -2211,7 +2211,7 @@ void GUI::readSettings()
|
||||
.toInt();
|
||||
int mbi = settings.value(PNG_MARGIN_BOTTOM_SETTING, PNG_MARGIN_BOTTOM_DEFAULT)
|
||||
.toInt();
|
||||
_pngExport.margins = Margins(mli, mti, mri, mbi);
|
||||
_pngExport.margins = QMargins(mli, mti, mri, mbi);
|
||||
_pngExport.antialiasing = settings.value(PNG_ANTIALIASING_SETTING,
|
||||
PNG_ANTIALIASING_DEFAULT).toBool();
|
||||
_pngExport.fileName = settings.value(PNG_FILENAME_SETTING,
|
||||
|
@ -4,27 +4,6 @@
|
||||
#include <QtGlobal>
|
||||
#include <QDebug>
|
||||
|
||||
class Margins
|
||||
{
|
||||
public:
|
||||
Margins() {_left = 0; _top = 0; _right = 0; _bottom = 0;}
|
||||
Margins(int left, int top, int right, int bottom)
|
||||
{_left = left, _top = top; _right = right; _bottom = bottom;}
|
||||
|
||||
int left() const {return _left;}
|
||||
int top() const {return _top;}
|
||||
int right() const {return _right;}
|
||||
int bottom() const {return _bottom;}
|
||||
|
||||
int &rleft() {return _left;}
|
||||
int &rtop() {return _top;}
|
||||
int &rright() {return _right;}
|
||||
int &rbottom() {return _bottom;}
|
||||
|
||||
private:
|
||||
int _left, _top, _right, _bottom;
|
||||
};
|
||||
|
||||
class MarginsF
|
||||
{
|
||||
public:
|
||||
@ -37,23 +16,23 @@ public:
|
||||
qreal right() const {return _right;}
|
||||
qreal bottom() const {return _bottom;}
|
||||
|
||||
qreal &rleft() {return _left;}
|
||||
qreal &rtop() {return _top;}
|
||||
qreal &rright() {return _right;}
|
||||
qreal &rbottom() {return _bottom;}
|
||||
|
||||
private:
|
||||
qreal _left, _top, _right, _bottom;
|
||||
};
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
inline QDebug operator<<(QDebug dbg, const Margins &margins)
|
||||
inline MarginsF operator*(const MarginsF &margins, int factor)
|
||||
{
|
||||
dbg.nospace() << "Margins(" << margins.left() << ", " << margins.top()
|
||||
<< ", " << margins.right() << margins.bottom() << ")";
|
||||
return dbg.space();
|
||||
return MarginsF(margins.left() * factor, margins.top() * factor,
|
||||
margins.right() * factor, margins.bottom() * factor);
|
||||
}
|
||||
|
||||
inline MarginsF operator/(const MarginsF &margins, int factor)
|
||||
{
|
||||
return MarginsF(margins.left() / factor, margins.top() / factor,
|
||||
margins.right() / factor, margins.bottom() / factor);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
inline QDebug operator<<(QDebug dbg, const MarginsF &margins)
|
||||
{
|
||||
dbg.nospace() << "MarginsF(" << margins.left() << ", " << margins.top()
|
||||
|
89
src/GUI/marginswidget.cpp
Normal file
89
src/GUI/marginswidget.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#include <QSpinBox>
|
||||
#include <QGridLayout>
|
||||
#include "units.h"
|
||||
#include "marginswidget.h"
|
||||
|
||||
MarginsWidget::MarginsWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
_top = new QSpinBox();
|
||||
_bottom = new QSpinBox();
|
||||
_left = new QSpinBox();
|
||||
_right = new QSpinBox();
|
||||
|
||||
QGridLayout *layout = new QGridLayout();
|
||||
layout->addWidget(_top, 0, 0, 1, 2, Qt::AlignCenter);
|
||||
layout->addWidget(_left, 1, 0, 1, 1, Qt::AlignRight);
|
||||
layout->addWidget(_right, 1, 1, 1, 1, Qt::AlignLeft);
|
||||
layout->addWidget(_bottom, 2, 0, 1, 2, Qt::AlignCenter);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void MarginsWidget::setValue(const QMargins &value)
|
||||
{
|
||||
_top->setValue(value.top());
|
||||
_bottom->setValue(value.bottom());
|
||||
_left->setValue(value.left());
|
||||
_right->setValue(value.right());
|
||||
}
|
||||
|
||||
void MarginsWidget::setUnits(const QString &units)
|
||||
{
|
||||
_top->setSuffix(UNIT_SPACE + units);
|
||||
_bottom->setSuffix(UNIT_SPACE + units);
|
||||
_left->setSuffix(UNIT_SPACE + units);
|
||||
_right->setSuffix(UNIT_SPACE + units);
|
||||
}
|
||||
|
||||
QMargins MarginsWidget::value() const
|
||||
{
|
||||
return QMargins(_left->value(), _top->value(), _right->value(),
|
||||
_bottom->value());
|
||||
}
|
||||
|
||||
|
||||
MarginsFWidget::MarginsFWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
_top = new QDoubleSpinBox();
|
||||
_bottom = new QDoubleSpinBox();
|
||||
_left = new QDoubleSpinBox();
|
||||
_right = new QDoubleSpinBox();
|
||||
|
||||
QGridLayout *layout = new QGridLayout();
|
||||
layout->addWidget(_top, 0, 0, 1, 2, Qt::AlignCenter);
|
||||
layout->addWidget(_left, 1, 0, 1, 1, Qt::AlignRight);
|
||||
layout->addWidget(_right, 1, 1, 1, 1, Qt::AlignLeft);
|
||||
layout->addWidget(_bottom, 2, 0, 1, 2, Qt::AlignCenter);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void MarginsFWidget::setValue(const MarginsF &value)
|
||||
{
|
||||
_top->setValue(value.top());
|
||||
_bottom->setValue(value.bottom());
|
||||
_left->setValue(value.left());
|
||||
_right->setValue(value.right());
|
||||
}
|
||||
|
||||
void MarginsFWidget::setUnits(const QString &units)
|
||||
{
|
||||
_top->setSuffix(UNIT_SPACE + units);
|
||||
_bottom->setSuffix(UNIT_SPACE + units);
|
||||
_left->setSuffix(UNIT_SPACE + units);
|
||||
_right->setSuffix(UNIT_SPACE + units);
|
||||
}
|
||||
|
||||
void MarginsFWidget::setSingleStep(qreal step)
|
||||
{
|
||||
_top->setSingleStep(step);
|
||||
_bottom->setSingleStep(step);
|
||||
_left->setSingleStep(step);
|
||||
_right->setSingleStep(step);
|
||||
}
|
||||
|
||||
MarginsF MarginsFWidget::value() const
|
||||
{
|
||||
return MarginsF(_left->value(), _top->value(), _right->value(),
|
||||
_bottom->value());
|
||||
}
|
48
src/GUI/marginswidget.h
Normal file
48
src/GUI/marginswidget.h
Normal file
@ -0,0 +1,48 @@
|
||||
#ifndef MARGINSWIDGET_H
|
||||
#define MARGINSWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QMargins>
|
||||
#include "margins.h"
|
||||
|
||||
class QSpinBox;
|
||||
class QDoubleSpinBox;
|
||||
|
||||
class MarginsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MarginsWidget(QWidget *parent = 0);
|
||||
|
||||
QMargins value() const;
|
||||
void setValue(const QMargins &value);
|
||||
void setUnits(const QString &units);
|
||||
|
||||
private:
|
||||
QSpinBox *_top;
|
||||
QSpinBox *_bottom;
|
||||
QSpinBox *_left;
|
||||
QSpinBox *_right;
|
||||
};
|
||||
|
||||
class MarginsFWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MarginsFWidget(QWidget *parent = 0);
|
||||
|
||||
MarginsF value() const;
|
||||
void setValue(const MarginsF &value);
|
||||
void setUnits(const QString &units);
|
||||
void setSingleStep(qreal step);
|
||||
|
||||
private:
|
||||
QDoubleSpinBox *_top;
|
||||
QDoubleSpinBox *_bottom;
|
||||
QDoubleSpinBox *_left;
|
||||
QDoubleSpinBox *_right;
|
||||
};
|
||||
|
||||
#endif // MARGINSWIDGET_H
|
@ -9,7 +9,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QTabWidget>
|
||||
#include <QDoubleSpinBox>
|
||||
#include "marginswidget.h"
|
||||
#include "fileselectwidget.h"
|
||||
#include "units.h"
|
||||
#include "pdfexportdialog.h"
|
||||
@ -58,36 +58,11 @@ PDFExportDialog::PDFExportDialog(PDFExport &exp, Units units, QWidget *parent)
|
||||
else
|
||||
_landscape->setChecked(true);
|
||||
|
||||
_topMargin = new QDoubleSpinBox();
|
||||
_bottomMargin = new QDoubleSpinBox();
|
||||
_leftMargin = new QDoubleSpinBox();
|
||||
_rightMargin = new QDoubleSpinBox();
|
||||
QString us = (units == Metric) ? tr("mm") : tr("in");
|
||||
_topMargin->setSuffix(UNIT_SPACE + us);
|
||||
_bottomMargin->setSuffix(UNIT_SPACE + us);
|
||||
_leftMargin->setSuffix(UNIT_SPACE + us);
|
||||
_rightMargin->setSuffix(UNIT_SPACE + us);
|
||||
if (units == Metric) {
|
||||
_topMargin->setValue(_export.margins.top());
|
||||
_bottomMargin->setValue(_export.margins.bottom());
|
||||
_leftMargin->setValue(_export.margins.left());
|
||||
_rightMargin->setValue(_export.margins.right());
|
||||
} else {
|
||||
_topMargin->setValue(_export.margins.top() * MM2IN);
|
||||
_bottomMargin->setValue(_export.margins.bottom() * MM2IN);
|
||||
_leftMargin->setValue(_export.margins.left() * MM2IN);
|
||||
_rightMargin->setValue(_export.margins.right() * MM2IN);
|
||||
_topMargin->setSingleStep(0.1);
|
||||
_bottomMargin->setSingleStep(0.1);
|
||||
_leftMargin->setSingleStep(0.1);
|
||||
_rightMargin->setSingleStep(0.1);
|
||||
}
|
||||
|
||||
QGridLayout *marginsLayout = new QGridLayout();
|
||||
marginsLayout->addWidget(_topMargin, 0, 0, 1, 2, Qt::AlignCenter);
|
||||
marginsLayout->addWidget(_leftMargin, 1, 0, 1, 1, Qt::AlignRight);
|
||||
marginsLayout->addWidget(_rightMargin, 1, 1, 1, 1, Qt::AlignLeft);
|
||||
marginsLayout->addWidget(_bottomMargin, 2, 0, 1, 2, Qt::AlignCenter);
|
||||
_margins = new MarginsFWidget();
|
||||
_margins->setUnits((units == Metric) ? tr("mm") : tr("in"));
|
||||
_margins->setSingleStep(0.1);
|
||||
_margins->setValue((units == Metric)
|
||||
? _export.margins : _export.margins * MM2IN);
|
||||
|
||||
#ifndef Q_OS_MAC
|
||||
QGroupBox *pageSetupBox = new QGroupBox(tr("Page Setup"));
|
||||
@ -96,7 +71,7 @@ PDFExportDialog::PDFExportDialog(PDFExport &exp, Units units, QWidget *parent)
|
||||
pageSetupLayout->addRow(tr("Page size:"), _paperSize);
|
||||
pageSetupLayout->addRow(tr("Resolution:"), _resolution);
|
||||
pageSetupLayout->addRow(tr("Orientation:"), orientationLayout);
|
||||
pageSetupLayout->addRow(tr("Margins:"), marginsLayout);
|
||||
pageSetupLayout->addRow(tr("Margins:"), _margins);
|
||||
#ifdef Q_OS_MAC
|
||||
QFrame *line = new QFrame();
|
||||
line->setFrameShape(QFrame::HLine);
|
||||
@ -153,13 +128,8 @@ void PDFExportDialog::accept()
|
||||
_export.paperSize = paperSize;
|
||||
_export.resolution = resolution;
|
||||
_export.orientation = orientation;
|
||||
if (_units == Imperial)
|
||||
_export.margins = MarginsF(_leftMargin->value() / MM2IN,
|
||||
_topMargin->value() / MM2IN, _rightMargin->value() / MM2IN,
|
||||
_bottomMargin->value() / MM2IN);
|
||||
else
|
||||
_export.margins = MarginsF(_leftMargin->value(), _topMargin->value(),
|
||||
_rightMargin->value(), _bottomMargin->value());
|
||||
_export.margins = (_units == Imperial)
|
||||
? _margins->value() / MM2IN : _margins->value();
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
class QComboBox;
|
||||
class QRadioButton;
|
||||
class FileSelectWidget;
|
||||
class QDoubleSpinBox;
|
||||
class MarginsFWidget;
|
||||
|
||||
struct PDFExport
|
||||
{
|
||||
@ -39,10 +39,7 @@ private:
|
||||
QComboBox *_resolution;
|
||||
QRadioButton *_portrait;
|
||||
QRadioButton *_landscape;
|
||||
QDoubleSpinBox *_topMargin;
|
||||
QDoubleSpinBox *_bottomMargin;
|
||||
QDoubleSpinBox *_leftMargin;
|
||||
QDoubleSpinBox *_rightMargin;
|
||||
MarginsFWidget *_margins;
|
||||
};
|
||||
|
||||
#endif // PDFEXPORTDIALOG_H
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <QCheckBox>
|
||||
#include "units.h"
|
||||
#include "fileselectwidget.h"
|
||||
#include "marginswidget.h"
|
||||
#include "pngexportdialog.h"
|
||||
|
||||
PNGExportDialog::PNGExportDialog(PNGExport &exp, QWidget *parent)
|
||||
@ -33,24 +34,9 @@ PNGExportDialog::PNGExportDialog(PNGExport &exp, QWidget *parent)
|
||||
_height->setValue(_export.size.height());
|
||||
_height->setSuffix(UNIT_SPACE + tr("px"));
|
||||
|
||||
_topMargin = new QSpinBox();
|
||||
_bottomMargin = new QSpinBox();
|
||||
_leftMargin = new QSpinBox();
|
||||
_rightMargin = new QSpinBox();
|
||||
_topMargin->setSuffix(UNIT_SPACE + tr("px"));
|
||||
_bottomMargin->setSuffix(UNIT_SPACE + tr("px"));
|
||||
_leftMargin->setSuffix(UNIT_SPACE + tr("px"));
|
||||
_rightMargin->setSuffix(UNIT_SPACE + tr("px"));
|
||||
_topMargin->setValue(_export.margins.top());
|
||||
_bottomMargin->setValue(_export.margins.bottom());
|
||||
_leftMargin->setValue(_export.margins.left());
|
||||
_rightMargin->setValue(_export.margins.right());
|
||||
|
||||
QGridLayout *marginsLayout = new QGridLayout();
|
||||
marginsLayout->addWidget(_topMargin, 0, 0, 1, 2, Qt::AlignCenter);
|
||||
marginsLayout->addWidget(_leftMargin, 1, 0, 1, 1, Qt::AlignRight);
|
||||
marginsLayout->addWidget(_rightMargin, 1, 1, 1, 1, Qt::AlignLeft);
|
||||
marginsLayout->addWidget(_bottomMargin, 2, 0, 1, 2, Qt::AlignCenter);
|
||||
_margins = new MarginsWidget();
|
||||
_margins->setValue(_export.margins);
|
||||
_margins->setUnits(tr("px"));
|
||||
|
||||
_antialiasing = new QCheckBox(tr("Use anti-aliasing"));
|
||||
_antialiasing->setChecked(_export.antialiasing);
|
||||
@ -61,7 +47,7 @@ PNGExportDialog::PNGExportDialog(PNGExport &exp, QWidget *parent)
|
||||
QFormLayout *pageSetupLayout = new QFormLayout;
|
||||
pageSetupLayout->addRow(tr("Image width:"), _width);
|
||||
pageSetupLayout->addRow(tr("Image height:"), _height);
|
||||
pageSetupLayout->addRow(tr("Margins:"), marginsLayout);
|
||||
pageSetupLayout->addRow(tr("Margins:"), _margins);
|
||||
pageSetupLayout->addWidget(_antialiasing);
|
||||
#ifdef Q_OS_MAC
|
||||
QFrame *line = new QFrame();
|
||||
@ -111,8 +97,7 @@ void PNGExportDialog::accept()
|
||||
|
||||
_export.fileName = _fileSelect->file();
|
||||
_export.size = QSize(_width->value(), _height->value());
|
||||
_export.margins = Margins(_leftMargin->value(), _topMargin->value(),
|
||||
_rightMargin->value(), _bottomMargin->value());
|
||||
_export.margins = _margins->value();
|
||||
_export.antialiasing = _antialiasing->isChecked();
|
||||
|
||||
QDialog::accept();
|
||||
|
@ -2,9 +2,11 @@
|
||||
#define PNGEXPORTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QMargins>
|
||||
#include "margins.h"
|
||||
|
||||
class FileSelectWidget;
|
||||
class MarginsWidget;
|
||||
class QSpinBox;
|
||||
class QCheckBox;
|
||||
|
||||
@ -12,7 +14,7 @@ struct PNGExport
|
||||
{
|
||||
QString fileName;
|
||||
QSize size;
|
||||
Margins margins;
|
||||
QMargins margins;
|
||||
bool antialiasing;
|
||||
};
|
||||
|
||||
@ -32,10 +34,7 @@ private:
|
||||
FileSelectWidget *_fileSelect;
|
||||
QSpinBox *_width;
|
||||
QSpinBox *_height;
|
||||
QSpinBox *_topMargin;
|
||||
QSpinBox *_bottomMargin;
|
||||
QSpinBox *_leftMargin;
|
||||
QSpinBox *_rightMargin;
|
||||
MarginsWidget *_margins;
|
||||
QCheckBox *_antialiasing;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user