Save/Restore a last layout settings. Added button RestoreDefaults.
--HG-- branch : develop
This commit is contained in:
parent
56c027686d
commit
c73b2f51e1
|
@ -33,6 +33,8 @@
|
|||
#include <QLocale>
|
||||
#include <QApplication>
|
||||
|
||||
#include "../xml/vabstractmeasurements.h"
|
||||
|
||||
const QString VSettings::SettingConfigurationOsSeparator = QStringLiteral("configuration/osSeparator");
|
||||
const QString VSettings::SettingConfigurationAutosaveState = QStringLiteral("configuration/autosave/state");
|
||||
const QString VSettings::SettingConfigurationAutosaveTime = QStringLiteral("configuration/autosave/time");
|
||||
|
@ -70,6 +72,16 @@ const QString VSettings::SettingCommunityUsername = QStringLitera
|
|||
const QString VSettings::SettingCommunitySavePassword = QStringLiteral("community/savePassword");
|
||||
const QString VSettings::SettingCommunityUserPassword = QStringLiteral("community/userpassword");
|
||||
|
||||
const QString VSettings::SettingLayoutWidth = QStringLiteral("layout/width");
|
||||
const QString VSettings::SettingLayoutSorting = QStringLiteral("layout/sorting");
|
||||
const QString VSettings::SettingLayoutPaperHeight = QStringLiteral("layout/paperHeight");
|
||||
const QString VSettings::SettingLayoutPaperWidth = QStringLiteral("layout/paperWidth");
|
||||
const QString VSettings::SettingLayoutShift = QStringLiteral("layout/shift");
|
||||
const QString VSettings::SettingLayoutRotate = QStringLiteral("layout/Rotate");
|
||||
const QString VSettings::SettingLayoutRotationIncrease = QStringLiteral("layout/rotationIncrease");
|
||||
const QString VSettings::SettingLayoutAutoCrop = QStringLiteral("layout/autoCrop");
|
||||
const QString VSettings::SettingLayoutSaveLength = QStringLiteral("layout/saveLength");
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VSettings::VSettings(Format format, Scope scope, const QString &organization, const QString &application,
|
||||
QObject *parent)
|
||||
|
@ -470,6 +482,218 @@ void VSettings::SetUserPassword(const QString &value)
|
|||
setValue(SettingCommunityUserPassword, value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
int VSettings::GetLayoutPaperHeight() const
|
||||
{
|
||||
const int def = VAbstractMeasurements::UnitConvertor(1189/*A0*/, Unit::Mm, Unit::Px);
|
||||
bool ok = false;
|
||||
const int height = value(SettingLayoutPaperHeight, def).toInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
return height;
|
||||
}
|
||||
else
|
||||
{
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VSettings::SetLayoutPaperHeight(int value)
|
||||
{
|
||||
setValue(SettingLayoutPaperHeight, value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
int VSettings::GetLayoutPaperWidth() const
|
||||
{
|
||||
const int def = VAbstractMeasurements::UnitConvertor(841/*A0*/, Unit::Mm, Unit::Px);
|
||||
bool ok = false;
|
||||
const int width = value(SettingLayoutPaperWidth, def).toInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
return width;
|
||||
}
|
||||
else
|
||||
{
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VSettings::SetLayoutPaperWidth(int value)
|
||||
{
|
||||
setValue(SettingLayoutPaperWidth, value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
unsigned int VSettings::GetLayoutShift() const
|
||||
{
|
||||
const unsigned int def = GetDefLayoutShift();
|
||||
bool ok = false;
|
||||
const unsigned int shift = value(SettingLayoutShift, def).toUInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
return shift;
|
||||
}
|
||||
else
|
||||
{
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
unsigned int VSettings::GetDefLayoutShift()
|
||||
{
|
||||
return VAbstractMeasurements::UnitConvertor(50, Unit::Mm, Unit::Px);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VSettings::SetLayoutShift(unsigned int value)
|
||||
{
|
||||
setValue(SettingLayoutShift, value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
unsigned int VSettings::GetLayoutWidth() const
|
||||
{
|
||||
const unsigned int def = GetDefLayoutWidth();
|
||||
bool ok = false;
|
||||
const unsigned int lWidth = value(SettingLayoutWidth, def).toUInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
return lWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
unsigned int VSettings::GetDefLayoutWidth()
|
||||
{
|
||||
return VAbstractMeasurements::UnitConvertor(2.5, Unit::Mm, Unit::Px);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VSettings::SetLayoutWidth(unsigned int value)
|
||||
{
|
||||
setValue(SettingLayoutWidth, value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
Cases VSettings::GetLayoutGroup() const
|
||||
{
|
||||
const Cases def = GetDefLayoutGroup();
|
||||
bool ok = false;
|
||||
const int g = value(SettingLayoutSorting, static_cast<int>(def)).toInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
if (g >= static_cast<int>(Cases::UnknownCase))
|
||||
{
|
||||
return def;
|
||||
}
|
||||
else
|
||||
{
|
||||
return static_cast<Cases>(g);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
Cases VSettings::GetDefLayoutGroup()
|
||||
{
|
||||
return Cases::CaseDesc;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VSettings::SetLayoutGroup(const Cases &value)
|
||||
{
|
||||
setValue(SettingLayoutSorting, static_cast<int>(value));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VSettings::GetLayoutRotate() const
|
||||
{
|
||||
return value(SettingLayoutRotate, GetDefLayoutRotate()).toBool();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VSettings::GetDefLayoutRotate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VSettings::SetLayoutRotate(bool value)
|
||||
{
|
||||
setValue(SettingLayoutRotate, value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
int VSettings::GetLayoutRotationIncrease() const
|
||||
{
|
||||
const int def = GetDefLayoutRotationIncrease();
|
||||
bool ok = false;
|
||||
const int r = value(SettingLayoutRotationIncrease, def).toInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
if (not (r >= 1 && r <= 180 && 360 % r == 0))
|
||||
{
|
||||
return def;
|
||||
}
|
||||
else
|
||||
{
|
||||
return r;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
int VSettings::GetDefLayoutRotationIncrease()
|
||||
{
|
||||
return 180;/*degree*/
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VSettings::SetLayoutRotationIncrease(int value)
|
||||
{
|
||||
setValue(SettingLayoutRotationIncrease, value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VSettings::GetLayoutAutoCrop() const
|
||||
{
|
||||
return value(SettingLayoutAutoCrop, false).toBool();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VSettings::SetLayoutAutoCrop(bool value)
|
||||
{
|
||||
setValue(SettingLayoutAutoCrop, value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VSettings::GetLayoutSaveLength() const
|
||||
{
|
||||
return value(SettingLayoutSaveLength, false).toBool();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VSettings::SetLayoutSaveLength(bool value)
|
||||
{
|
||||
setValue(SettingLayoutSaveLength, value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VSettings::StandardTablesPath()
|
||||
{
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#define VSETTINGS_H
|
||||
|
||||
#include <QSettings>
|
||||
#include "../../libs/vlayout/vbank.h"
|
||||
|
||||
class VSettings : public QSettings
|
||||
{
|
||||
|
@ -133,6 +134,38 @@ public:
|
|||
QString GetUserPassword() const;
|
||||
void SetUserPassword(const QString &value);
|
||||
|
||||
int GetLayoutPaperHeight() const;
|
||||
void SetLayoutPaperHeight(int value);
|
||||
|
||||
int GetLayoutPaperWidth() const;
|
||||
void SetLayoutPaperWidth(int value);
|
||||
|
||||
unsigned int GetLayoutShift() const;
|
||||
static unsigned int GetDefLayoutShift();
|
||||
void SetLayoutShift(unsigned int value);
|
||||
|
||||
unsigned int GetLayoutWidth() const;
|
||||
static unsigned int GetDefLayoutWidth();
|
||||
void SetLayoutWidth(unsigned int value);
|
||||
|
||||
Cases GetLayoutGroup() const;
|
||||
static Cases GetDefLayoutGroup();
|
||||
void SetLayoutGroup(const Cases &value);
|
||||
|
||||
bool GetLayoutRotate() const;
|
||||
static bool GetDefLayoutRotate();
|
||||
void SetLayoutRotate(bool value);
|
||||
|
||||
int GetLayoutRotationIncrease() const;
|
||||
static int GetDefLayoutRotationIncrease();
|
||||
void SetLayoutRotationIncrease(int value);
|
||||
|
||||
bool GetLayoutAutoCrop() const;
|
||||
void SetLayoutAutoCrop(bool value);
|
||||
|
||||
bool GetLayoutSaveLength() const;
|
||||
void SetLayoutSaveLength(bool value);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VSettings)
|
||||
static const QString SettingConfigurationOsSeparator;
|
||||
|
@ -170,6 +203,16 @@ private:
|
|||
static const QString SettingCommunityUsername;
|
||||
static const QString SettingCommunitySavePassword;
|
||||
static const QString SettingCommunityUserPassword;
|
||||
|
||||
static const QString SettingLayoutWidth;
|
||||
static const QString SettingLayoutSorting;
|
||||
static const QString SettingLayoutPaperHeight;
|
||||
static const QString SettingLayoutPaperWidth;
|
||||
static const QString SettingLayoutShift;
|
||||
static const QString SettingLayoutRotate;
|
||||
static const QString SettingLayoutRotationIncrease;
|
||||
static const QString SettingLayoutAutoCrop;
|
||||
static const QString SettingLayoutSaveLength;
|
||||
};
|
||||
|
||||
#endif // VSETTINGS_H
|
||||
|
|
|
@ -53,11 +53,7 @@ DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget
|
|||
|
||||
qApp->getSettings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale(QLocale::C));
|
||||
|
||||
InitPaperUnits();
|
||||
InitLayoutUnits();
|
||||
InitTemplates();
|
||||
MinimumPaperSize();
|
||||
MinimumLayoutSize();
|
||||
ReadSettings();
|
||||
|
||||
connect(ui->comboBoxTemplates, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||
this, &DialogLayoutSettings::TemplateSelected);
|
||||
|
@ -74,6 +70,9 @@ DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget
|
|||
|
||||
QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
|
||||
connect(bOk, &QPushButton::clicked, this, &DialogLayoutSettings::DialogAccepted);
|
||||
|
||||
QPushButton *bRestoreDefaults = ui->buttonBox->button(QDialogButtonBox::RestoreDefaults);
|
||||
connect(bRestoreDefaults, &QPushButton::clicked, this, &DialogLayoutSettings::RestoreDefaults);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -196,7 +195,7 @@ void DialogLayoutSettings::SetIncrease(int increase)
|
|||
|
||||
if (index == -1)
|
||||
{
|
||||
index = 21;
|
||||
index = 21;//180 degree
|
||||
}
|
||||
|
||||
ui->comboBoxIncrease->setCurrentIndex(index);
|
||||
|
@ -231,15 +230,7 @@ void DialogLayoutSettings::TemplateSelected()
|
|||
{
|
||||
const QSizeF size = Template();
|
||||
|
||||
oldPaperUnit = PaperUnit();
|
||||
ui->doubleSpinBoxPaperWidth->setMaximum(qApp->fromPixel(QIMAGE_MAX, oldPaperUnit));
|
||||
ui->doubleSpinBoxPaperHeight->setMaximum(qApp->fromPixel(QIMAGE_MAX, oldPaperUnit));
|
||||
|
||||
ui->doubleSpinBoxPaperWidth->setValue(size.width());
|
||||
ui->doubleSpinBoxPaperHeight->setValue(size.height());
|
||||
|
||||
CorrectPaperDecimals();
|
||||
PaperSizeChanged();
|
||||
SheetSize(size);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -329,9 +320,22 @@ void DialogLayoutSettings::DialogAccepted()
|
|||
generator->SetAutoCrop(GetAutoCrop());
|
||||
generator->SetSaveLength(IsSaveLength());
|
||||
|
||||
WriteSettings();
|
||||
accepted();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogLayoutSettings::RestoreDefaults()
|
||||
{
|
||||
ui->comboBoxTemplates->setCurrentIndex(0);//A0
|
||||
|
||||
SetLayoutWidth(VSettings::GetDefLayoutWidth());
|
||||
SetShift(VSettings::GetDefLayoutShift());
|
||||
SetGroup(VSettings::GetDefLayoutGroup());
|
||||
SetRotate(VSettings::GetDefLayoutRotate());
|
||||
SetIncrease(VSettings::GetDefLayoutRotationIncrease());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogLayoutSettings::InitPaperUnits()
|
||||
{
|
||||
|
@ -363,9 +367,6 @@ void DialogLayoutSettings::InitLayoutUnits()
|
|||
{
|
||||
ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit);
|
||||
}
|
||||
|
||||
ui->doubleSpinBoxLayoutWidth->setValue(VAbstractMeasurements::UnitConvertor(2.5, Unit::Mm, oldLayoutUnit));
|
||||
ui->doubleSpinBoxShift->setValue(VAbstractMeasurements::UnitConvertor(50, Unit::Mm, oldLayoutUnit));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -393,7 +394,7 @@ void DialogLayoutSettings::InitTemplates()
|
|||
ui->comboBoxTemplates->addItem(icoRoll,
|
||||
tr("Roll 44in ")+pdi, QVariant(static_cast<char>(PaperSizeTemplate::Roll44in)));
|
||||
|
||||
TemplateSelected();
|
||||
ui->comboBoxTemplates->setCurrentIndex(-1);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -596,3 +597,55 @@ void DialogLayoutSettings::MinimumLayoutSize()
|
|||
const qreal value = VAbstractMeasurements::UnitConvertor(1, Unit::Px, oldLayoutUnit);
|
||||
ui->doubleSpinBoxLayoutWidth->setMinimum(value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogLayoutSettings::ReadSettings()
|
||||
{
|
||||
InitPaperUnits();
|
||||
InitLayoutUnits();
|
||||
InitTemplates();
|
||||
MinimumPaperSize();
|
||||
MinimumLayoutSize();
|
||||
|
||||
SetLayoutWidth(qApp->getSettings()->GetLayoutWidth());
|
||||
SetShift(qApp->getSettings()->GetLayoutShift());
|
||||
|
||||
const qreal width = VAbstractMeasurements::UnitConvertor(qApp->getSettings()->GetLayoutPaperWidth(), Unit::Px,
|
||||
LayoutUnit());
|
||||
const qreal height = VAbstractMeasurements::UnitConvertor(qApp->getSettings()->GetLayoutPaperHeight(), Unit::Px,
|
||||
LayoutUnit());
|
||||
SheetSize(QSizeF(width, height));
|
||||
SetGroup(qApp->getSettings()->GetLayoutGroup());
|
||||
SetRotate(qApp->getSettings()->GetLayoutRotate());
|
||||
SetIncrease(qApp->getSettings()->GetLayoutRotationIncrease());
|
||||
SetAutoCrop(qApp->getSettings()->GetLayoutAutoCrop());
|
||||
SetSaveLength(qApp->getSettings()->GetLayoutSaveLength());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogLayoutSettings::WriteSettings() const
|
||||
{
|
||||
qApp->getSettings()->SetLayoutWidth(GetLayoutWidth());
|
||||
qApp->getSettings()->SetLayoutGroup(GetGroup());
|
||||
qApp->getSettings()->SetLayoutPaperHeight(GetPaperHeight());
|
||||
qApp->getSettings()->SetLayoutPaperWidth(GetPaperWidth());
|
||||
qApp->getSettings()->SetLayoutShift(GetShift());
|
||||
qApp->getSettings()->SetLayoutRotate(GetRotate());
|
||||
qApp->getSettings()->SetLayoutRotationIncrease(GetIncrease());
|
||||
qApp->getSettings()->SetLayoutAutoCrop(GetAutoCrop());
|
||||
qApp->getSettings()->SetLayoutSaveLength(IsSaveLength());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogLayoutSettings::SheetSize(const QSizeF &size)
|
||||
{
|
||||
oldPaperUnit = PaperUnit();
|
||||
ui->doubleSpinBoxPaperWidth->setMaximum(qApp->fromPixel(QIMAGE_MAX, oldPaperUnit));
|
||||
ui->doubleSpinBoxPaperHeight->setMaximum(qApp->fromPixel(QIMAGE_MAX, oldPaperUnit));
|
||||
|
||||
ui->doubleSpinBoxPaperWidth->setValue(size.width());
|
||||
ui->doubleSpinBoxPaperHeight->setValue(size.height());
|
||||
|
||||
CorrectPaperDecimals();
|
||||
PaperSizeChanged();
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#ifndef DIALOGLAYOUTSETTINGS_H
|
||||
#define DIALOGLAYOUTSETTINGS_H
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QDialog>
|
||||
|
||||
#include "../../libs/vlayout/vbank.h"
|
||||
|
@ -84,6 +85,7 @@ public slots:
|
|||
void Swap(bool checked);
|
||||
|
||||
void DialogAccepted();
|
||||
void RestoreDefaults();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(DialogLayoutSettings)
|
||||
|
@ -106,6 +108,11 @@ private:
|
|||
|
||||
void MinimumPaperSize();
|
||||
void MinimumLayoutSize();
|
||||
|
||||
void ReadSettings();
|
||||
void WriteSettings() const;
|
||||
|
||||
void SheetSize(const QSizeF &size);
|
||||
};
|
||||
|
||||
#endif // DIALOGLAYOUTSETTINGS_H
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBoxPaperSize">
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Paper size</string>
|
||||
</property>
|
||||
|
@ -492,7 +495,7 @@
|
|||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
class QPointF;
|
||||
class VLayoutDetail;
|
||||
|
||||
enum class Cases : char { CaseThreeGroup, CaseTwoGroup, CaseDesc};
|
||||
enum class Cases : char { CaseThreeGroup, CaseTwoGroup, CaseDesc, UnknownCase};
|
||||
|
||||
class VBank
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user