Fixed issue #313. Layout pieces too close to right edge.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-11-09 17:54:30 +02:00
commit fe31989f79
19 changed files with 1575 additions and 350 deletions

View File

@ -63,20 +63,37 @@ const static auto SINGLE_OPTION_GRADATIONSIZE = QStringLiteral("x");
const static auto LONG_OPTION_GRADATIONHEIGHT = QStringLiteral("gheight"); const static auto LONG_OPTION_GRADATIONHEIGHT = QStringLiteral("gheight");
const static auto SINGLE_OPTION_GRADATIONHEIGHT = QStringLiteral("e"); const static auto SINGLE_OPTION_GRADATIONHEIGHT = QStringLiteral("e");
const static auto LONG_OPTION_IGNORE_MARGINS = QStringLiteral("ignoremargins");
const static auto SINGLE_OPTION_IGNORE_MARGINS = QStringLiteral("i");
const static auto LONG_OPTION_LEFT_MARGIN = QStringLiteral("lmargin");
const static auto SINGLE_OPTION_LEFT_MARGIN = QStringLiteral("L");
const static auto LONG_OPTION_RIGHT_MARGIN = QStringLiteral("rmargin");
const static auto SINGLE_OPTION_RIGHT_MARGIN = QStringLiteral("R");
const static auto LONG_OPTION_TOP_MARGIN = QStringLiteral("tmargin");
const static auto SINGLE_OPTION_TOP_MARGIN = QStringLiteral("T");
const static auto LONG_OPTION_BOTTOM_MARGIN = QStringLiteral("bmargin");
const static auto SINGLE_OPTION_BOTTOM_MARGIN = QStringLiteral("B");
#define translate(context, source) QCoreApplication::translate((context), (source)) #define translate(context, source) QCoreApplication::translate((context), (source))
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VCommandLine::VCommandLine() : parser(), optionsUsed(InitOptionsUsed()), isGuiEnabled(false) VCommandLine::VCommandLine() : parser(), optionsUsed(), optionsIndex(), isGuiEnabled(false)
{ {
parser.setApplicationDescription(translate("VCommandLine", "Pattern making program.")); parser.setApplicationDescription(translate("VCommandLine", "Pattern making program."));
parser.addHelpOption(); parser.addHelpOption();
parser.addVersionOption(); parser.addVersionOption();
parser.addPositionalArgument("filename", translate("VCommandLine", "Pattern file.")); parser.addPositionalArgument("filename", translate("VCommandLine", "Pattern file."));
QMap<QString, QCommandLineOption *>::const_iterator i = optionsUsed.constBegin(); InitOptions(optionsUsed, optionsIndex);
VCommandLineOptions::const_iterator i = optionsUsed.constBegin();
while (i != optionsUsed.constEnd()) while (i != optionsUsed.constEnd())
{ {
parser.addOption(*i.value()); parser.addOption(*((*i)));
++i; ++i;
} }
} }
@ -94,45 +111,44 @@ qreal VCommandLine::Pg2Px(const QString& src, const DialogLayoutSettings& conver
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QMap<QString, QCommandLineOption *> VCommandLine::InitOptionsUsed() void VCommandLine::InitOptions(VCommandLineOptions &options, QMap<QString, int> &optionsIndex)
{ {
QMap<QString, QCommandLineOption *> options; int index = 0;
//keep in mind order here - that is how user will see it, so group-up for usability //keep in mind order here - that is how user will see it, so group-up for usability
//================================================================================================================= //=================================================================================================================
options.insert(LONG_OPTION_BASENAME, optionsIndex.insert(LONG_OPTION_BASENAME, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_BASENAME << LONG_OPTION_BASENAME, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_BASENAME << LONG_OPTION_BASENAME,
translate("VCommandLine", "The base filename of exported layout files. Use " translate("VCommandLine", "The base filename of exported layout files. Use "
"it to enable console export mode."), "it to enable console export mode."),
translate("VCommandLine", "The base filename of layout files"))); translate("VCommandLine", "The base filename of layout files")));
options.insert(LONG_OPTION_DESTINATION, optionsIndex.insert(LONG_OPTION_DESTINATION, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_DESTINATION << LONG_OPTION_DESTINATION, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_DESTINATION << LONG_OPTION_DESTINATION,
translate("VCommandLine", "The path to output destination folder."), translate("VCommandLine", "The path to output destination folder."),
translate("VCommandLine", "The destination folder"))); translate("VCommandLine", "The destination folder")));
options.insert(LONG_OPTION_MEASUREFILE, optionsIndex.insert(LONG_OPTION_MEASUREFILE, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_MEASUREFILE << LONG_OPTION_MEASUREFILE, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_MEASUREFILE << LONG_OPTION_MEASUREFILE,
translate("VCommandLine", "Path to custom measure file (export mode)."), translate("VCommandLine", "Path to custom measure file (export mode)."),
translate("VCommandLine", "The measure file"))); translate("VCommandLine", "The measure file")));
options.insert(LONG_OPTION_EXP2FORMAT, optionsIndex.insert(LONG_OPTION_EXP2FORMAT, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_EXP2FORMAT << LONG_OPTION_EXP2FORMAT, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_EXP2FORMAT << LONG_OPTION_EXP2FORMAT,
translate("VCommandLine", "Number corresponding to output format (default = " translate("VCommandLine", "Number corresponding to output format (default = "
"0, export mode): ") + "0, export mode): ") +
DialogSaveLayout::MakeHelpFormatList(), DialogSaveLayout::MakeHelpFormatList(),
translate("VCommandLine", "Format number"), "0")); translate("VCommandLine", "Format number"), "0"));
options.insert(LONG_OPTION_GRADATIONSIZE, optionsIndex.insert(LONG_OPTION_GRADATIONSIZE, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONSIZE << LONG_OPTION_GRADATIONSIZE, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONSIZE << LONG_OPTION_GRADATIONSIZE,
translate("VCommandLine", "Set size value a pattern file, that was opened " translate("VCommandLine", "Set size value a pattern file, that was opened "
"with standard measurements (export mode). Valid " "with standard measurements (export mode). Valid "
"values: %1cm.") "values: %1cm.")
.arg(VMeasurement::WholeListSizes(Unit::Cm).join(", ")), .arg(VMeasurement::WholeListSizes(Unit::Cm).join(", ")),
translate("VCommandLine", "The size value"))); translate("VCommandLine", "The size value")));
options.insert(LONG_OPTION_GRADATIONHEIGHT, optionsIndex.insert(LONG_OPTION_GRADATIONHEIGHT, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONHEIGHT << LONG_OPTION_GRADATIONHEIGHT, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONHEIGHT << LONG_OPTION_GRADATIONHEIGHT,
translate("VCommandLine", "Set height value a pattern file, that was opened " translate("VCommandLine", "Set height value a pattern file, that was opened "
"with standard measurements (export mode). Valid " "with standard measurements (export mode). Valid "
"values: %1cm.") "values: %1cm.")
@ -140,91 +156,123 @@ QMap<QString, QCommandLineOption *> VCommandLine::InitOptionsUsed()
translate("VCommandLine", "The height value"))); translate("VCommandLine", "The height value")));
//================================================================================================================= //=================================================================================================================
optionsIndex.insert(LONG_OPTION_PAGETEMPLATE, index++);
options.insert(LONG_OPTION_PAGETEMPLATE, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGETEMPLATE << LONG_OPTION_PAGETEMPLATE,
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGETEMPLATE << LONG_OPTION_PAGETEMPLATE,
translate("VCommandLine", "Number corresponding to page template (default = " translate("VCommandLine", "Number corresponding to page template (default = "
"0, export mode): ") + "0, export mode): ") +
DialogLayoutSettings::MakeHelpTemplateList(), DialogLayoutSettings::MakeHelpTemplateList(),
translate("VCommandLine", "Template number"), "0")); translate("VCommandLine", "Template number"), "0"));
optionsIndex.insert(LONG_OPTION_PAGEW, index++);
options.insert(LONG_OPTION_PAGEW, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEW << LONG_OPTION_PAGEW,
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEW << LONG_OPTION_PAGEW,
translate("VCommandLine", "Page width in current units like 12.0 (cannot be " translate("VCommandLine", "Page width in current units like 12.0 (cannot be "
"used with \"%1\", export mode).") "used with \"%1\", export mode).")
.arg(LONG_OPTION_PAGETEMPLATE), .arg(LONG_OPTION_PAGETEMPLATE),
translate("VCommandLine", "The page width"))); translate("VCommandLine", "The page width")));
options.insert(LONG_OPTION_PAGEH, optionsIndex.insert(LONG_OPTION_PAGEH, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEH << LONG_OPTION_PAGEH, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEH << LONG_OPTION_PAGEH,
translate("VCommandLine", "Page height in current units like 12.0 (cannot " translate("VCommandLine", "Page height in current units like 12.0 (cannot "
"be used with \"%1\", export mode).") "be used with \"%1\", export mode).")
.arg(LONG_OPTION_PAGETEMPLATE), .arg(LONG_OPTION_PAGETEMPLATE),
("The page height"))); ("The page height")));
options.insert(LONG_OPTION_PAGEUNITS, optionsIndex.insert(LONG_OPTION_PAGEUNITS, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEUNITS << LONG_OPTION_PAGEUNITS, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEUNITS << LONG_OPTION_PAGEUNITS,
translate("VCommandLine", "Page height/width measure units (cannot be used " translate("VCommandLine", "Page height/width measure units (cannot be used "
"with \"%1\", export mode): ") "with \"%1\", export mode): ")
.arg(LONG_OPTION_PAGETEMPLATE) + VDomDocument::UnitsHelpString(), .arg(LONG_OPTION_PAGETEMPLATE) + VDomDocument::UnitsHelpString(),
translate("VCommandLine", "The measure unit"))); translate("VCommandLine", "The measure unit")));
//================================================================================================================= optionsIndex.insert(LONG_OPTION_IGNORE_MARGINS, index++);
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_IGNORE_MARGINS << LONG_OPTION_IGNORE_MARGINS,
translate("VCommandLine",
"Ignore margins printing (export mode). Set all margins to 0.")));
options.insert(LONG_OPTION_ROTATE, optionsIndex.insert(LONG_OPTION_LEFT_MARGIN, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_ROTATE << LONG_OPTION_ROTATE, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_LEFT_MARGIN << LONG_OPTION_LEFT_MARGIN,
translate("VCommandLine",
"Page left margin in current units like 3.0 (export mode). If "
"not set will be used value from default printer. Or 0 if none "
"printers was found."),
("The left margin")));
optionsIndex.insert(LONG_OPTION_RIGHT_MARGIN, index++);
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_RIGHT_MARGIN << LONG_OPTION_RIGHT_MARGIN,
translate("VCommandLine",
"Page right margin in current units like 3.0 (export mode). If "
"not set will be used value from default printer. Or 0 if none "
"printers was found."),
("The right margin")));
optionsIndex.insert(LONG_OPTION_TOP_MARGIN, index++);
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_TOP_MARGIN << LONG_OPTION_TOP_MARGIN,
translate("VCommandLine",
"Page top margin in current units like 3.0 (export mode). If "
"not set will be used value from default printer. Or 0 if none "
"printers was found."),
("The top margin")));
optionsIndex.insert(LONG_OPTION_BOTTOM_MARGIN, index++);
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_BOTTOM_MARGIN << LONG_OPTION_BOTTOM_MARGIN,
translate("VCommandLine",
"Page bottom margin in current units like 3.0 (export mode). If "
"not set will be used value from default printer. Or 0 if none "
"printers was found."),
("The bottom margin")));
//=================================================================================================================
optionsIndex.insert(LONG_OPTION_ROTATE, index++);
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_ROTATE << LONG_OPTION_ROTATE,
translate("VCommandLine", "Rotation in degrees (one of predefined). Default " translate("VCommandLine", "Rotation in degrees (one of predefined). Default "
"(or 0) is no-rotate (export mode)."), "(or 0) is no-rotate (export mode)."),
translate("VCommandLine", "Angle"))); translate("VCommandLine", "Angle")));
options.insert(LONG_OPTION_CROP, optionsIndex.insert(LONG_OPTION_CROP, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_CROP << LONG_OPTION_CROP, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_CROP << LONG_OPTION_CROP,
translate("VCommandLine", "Auto crop unused length (export mode)."))); translate("VCommandLine", "Auto crop unused length (export mode).")));
options.insert(LONG_OPTION_UNITE, optionsIndex.insert(LONG_OPTION_UNITE, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_UNITE << LONG_OPTION_UNITE, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_UNITE << LONG_OPTION_UNITE,
translate("VCommandLine", "Unite pages if possible (export mode)."))); translate("VCommandLine", "Unite pages if possible (export mode).")));
//================================================================================================================= //=================================================================================================================
optionsIndex.insert(LONG_OPTION_SAVELENGTH, index++);
options.insert(LONG_OPTION_SAVELENGTH, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_SAVELENGTH << LONG_OPTION_SAVELENGTH,
new QCommandLineOption(QStringList() << SINGLE_OPTION_SAVELENGTH << LONG_OPTION_SAVELENGTH,
translate("VCommandLine", translate("VCommandLine",
"Save length of the sheet if set. (export mode)."))); "Save length of the sheet if set. (export mode).")));
options.insert(LONG_OPTION_SHIFTUNITS, optionsIndex.insert(LONG_OPTION_SHIFTUNITS, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTUNITS << LONG_OPTION_SHIFTUNITS, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTUNITS << LONG_OPTION_SHIFTUNITS,
translate("VCommandLine", translate("VCommandLine",
"Layout units (as paper's one except px, export mode)."), "Layout units (as paper's one except px, export mode)."),
translate("VCommandLine", "The unit"))); translate("VCommandLine", "The unit")));
options.insert(LONG_OPTION_SHIFTLENGTH, optionsIndex.insert(LONG_OPTION_SHIFTLENGTH, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTLENGTH << LONG_OPTION_SHIFTLENGTH, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTLENGTH << LONG_OPTION_SHIFTLENGTH,
translate("VCommandLine", "Shift layout length measured in layout units " translate("VCommandLine", "Shift layout length measured in layout units "
"(export mode)."), "(export mode)."),
translate("VCommandLine", "Shift length"))); translate("VCommandLine", "Shift length")));
options.insert(LONG_OPTION_GAPWIDTH, optionsIndex.insert(LONG_OPTION_GAPWIDTH, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_GAPWIDTH << LONG_OPTION_GAPWIDTH, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GAPWIDTH << LONG_OPTION_GAPWIDTH,
translate("VCommandLine", translate("VCommandLine",
"Gap width x2, measured in layout units. (export mode)."), "Gap width x2, measured in layout units. (export mode)."),
translate("VCommandLine", "The gap width"))); translate("VCommandLine", "The gap width")));
options.insert(LONG_OPTION_GROUPPING, optionsIndex.insert(LONG_OPTION_GROUPPING, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_GROUPPING << LONG_OPTION_GROUPPING, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GROUPPING << LONG_OPTION_GROUPPING,
translate("VCommandLine", "Sets layout groupping (export mode): ") translate("VCommandLine", "Sets layout groupping (export mode): ")
+ DialogLayoutSettings::MakeGroupsHelp(), + DialogLayoutSettings::MakeGroupsHelp(),
translate("VCommandLine", "Grouping type"), "2")); translate("VCommandLine", "Grouping type"), "2"));
options.insert(LONG_OPTION_TEST, optionsIndex.insert(LONG_OPTION_TEST, index++);
new QCommandLineOption(QStringList() << SINGLE_OPTION_TEST << LONG_OPTION_TEST, options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_TEST << LONG_OPTION_TEST,
translate("VCommandLine", "Run the program in a test mode. The program this " translate("VCommandLine", "Run the program in a test mode. The program this "
"mode load a single pattern file and silently " "mode load a single pattern file and silently "
"quit without showing the main window. The key " "quit without showing the main window. The key "
"have priority before key '%1'.") "have priority before key '%1'.")
.arg(LONG_OPTION_BASENAME))); .arg(LONG_OPTION_BASENAME)));
return options;
} }
//------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------
@ -237,11 +285,11 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
{ {
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined //just anonymous namespace ...don' like to have a,b,c,d everywhere defined
bool x = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGETEMPLATE)); bool x = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGETEMPLATE)));
bool a = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEH)); bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEH)));
bool b = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEW)); bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEW)));
bool c = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEUNITS)); bool c = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)));
if ((a || b || c) && x) if ((a || b || c) && x)
{ {
@ -260,8 +308,8 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
{ {
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined //just anonymous namespace ...don' like to have a,b,c,d everywhere defined
bool a = parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH)); bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTLENGTH)));
bool b = parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTUNITS)); bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS)));
if ((a || b) && !(a && b)) if ((a || b) && !(a && b))
{ {
@ -272,8 +320,8 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
{ {
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined //just anonymous namespace ...don' like to have a,b,c,d everywhere defined
bool a = parser.isSet(*optionsUsed.value(LONG_OPTION_GAPWIDTH)); bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH)));
bool b = parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTUNITS)); bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS)));
if ((a || b) && !(a && b)) if ((a || b) && !(a && b))
{ {
@ -282,6 +330,54 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
} }
} }
{
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_LEFT_MARGIN)));
bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)));
if ((a || b) && !(a && b))
{
qCritical() << translate("VCommandLine", "Left margin must be used together with page units.") << "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
}
{
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_RIGHT_MARGIN)));
bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)));
if ((a || b) && !(a && b))
{
qCritical() << translate("VCommandLine", "Right margin must be used together with page units.") << "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
}
{
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_TOP_MARGIN)));
bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)));
if ((a || b) && !(a && b))
{
qCritical() << translate("VCommandLine", "Top margin must be used together with page units.") << "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
}
{
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BOTTOM_MARGIN)));
bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)));
if ((a || b) && !(a && b))
{
qCritical() << translate("VCommandLine", "Bottom margin must be used together with page units.") << "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
}
int rotateDegree = OptRotation(); int rotateDegree = OptRotation();
diag.SetRotate(rotateDegree != 0 ); diag.SetRotate(rotateDegree != 0 );
@ -302,45 +398,85 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE); const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
} }
if (parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEH))) //at this point we already sure 3 are set or none if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEH))))
{ { //at this point we already sure 3 are set or none
if (!diag.SelectPaperUnit(parser.value(*optionsUsed.value(LONG_OPTION_PAGEUNITS)))) if (!diag.SelectPaperUnit(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)))))
{ {
qCritical() << translate("VCommandLine", "Unsupported paper units.") << "\n"; qCritical() << translate("VCommandLine", "Unsupported paper units.") << "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE); const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
} }
diag.SetPaperHeight (Pg2Px(parser.value(*optionsUsed.value(LONG_OPTION_PAGEH)), diag)); diag.SetPaperHeight (Pg2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEH))), diag));
diag.SetPaperWidth (Pg2Px(parser.value(*optionsUsed.value(LONG_OPTION_PAGEW)), diag)); diag.SetPaperWidth (Pg2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEW))), diag));
} }
if (parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTUNITS))) if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS))))
{ {
if (!diag.SelectLayoutUnit(parser.value(*optionsUsed.value(LONG_OPTION_SHIFTUNITS)))) if (!diag.SelectLayoutUnit(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS)))))
{ {
qCritical() << translate("VCommandLine", "Unsupported layout units.") << "\n"; qCritical() << translate("VCommandLine", "Unsupported layout units.") << "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE); const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
} }
} }
if (parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH))) if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTLENGTH))))
{ {
diag.SetShift(Lo2Px(parser.value(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH)), diag)); diag.SetShift(Lo2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTLENGTH))), diag));
} }
if (parser.isSet(*optionsUsed.value(LONG_OPTION_GAPWIDTH))) if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH))))
{ {
diag.SetLayoutWidth(Lo2Px(parser.value(*optionsUsed.value(LONG_OPTION_GAPWIDTH)), diag)); diag.SetLayoutWidth(Lo2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH))), diag));
} }
diag.SetAutoCrop(parser.isSet(*optionsUsed.value(LONG_OPTION_CROP))); diag.SetAutoCrop(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_CROP))));
diag.SetUnitePages(parser.isSet(*optionsUsed.value(LONG_OPTION_UNITE))); diag.SetUnitePages(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_UNITE))));
diag.SetSaveLength(parser.isSet(*optionsUsed.value(LONG_OPTION_SAVELENGTH))); diag.SetSaveLength(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SAVELENGTH))));
diag.SetGroup(OptGroup()); diag.SetGroup(OptGroup());
if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_IGNORE_MARGINS))))
{
diag.SetIgnoreAllFields(true);
}
else
{
QMarginsF margins = diag.GetFields();
{
const QCommandLineOption *option = optionsUsed.value(optionsIndex.value(LONG_OPTION_LEFT_MARGIN));
if (parser.isSet(*option))
{
margins.setLeft(Pg2Px(parser.value(*option), diag));
}
}
{
const QCommandLineOption *option = optionsUsed.value(optionsIndex.value(LONG_OPTION_RIGHT_MARGIN));
if (parser.isSet(*option))
{
margins.setRight(Pg2Px(parser.value(*option), diag));
}
}
{
const QCommandLineOption *option = optionsUsed.value(optionsIndex.value(LONG_OPTION_TOP_MARGIN));
if (parser.isSet(*option))
{
margins.setTop(Pg2Px(parser.value(*option), diag));
}
}
{
const QCommandLineOption *option = optionsUsed.value(optionsIndex.value(LONG_OPTION_BOTTOM_MARGIN));
if (parser.isSet(*option))
{
margins.setBottom(Pg2Px(parser.value(*option), diag));
}
}
diag.SetFields(margins);
}
diag.DialogAccepted(); // filling VLayoutGenerator diag.DialogAccepted(); // filling VLayoutGenerator
@ -378,7 +514,7 @@ void VCommandLine::Reset()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VCommandLine::IsTestModeEnabled() const bool VCommandLine::IsTestModeEnabled() const
{ {
const bool r = parser.isSet(*optionsUsed.value(LONG_OPTION_TEST)); const bool r = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_TEST)));
if (r && parser.positionalArguments().size() != 1) if (r && parser.positionalArguments().size() != 1)
{ {
qCritical() << translate("VCommandLine", "Test option can be used with single input file only.") << "/n"; qCritical() << translate("VCommandLine", "Test option can be used with single input file only.") << "/n";
@ -390,7 +526,7 @@ bool VCommandLine::IsTestModeEnabled() const
//------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------
bool VCommandLine::IsExportEnabled() const bool VCommandLine::IsExportEnabled() const
{ {
const bool r = parser.isSet(*optionsUsed.value(LONG_OPTION_BASENAME)); const bool r = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BASENAME)));
if (r && parser.positionalArguments().size() != 1) if (r && parser.positionalArguments().size() != 1)
{ {
qCritical() << translate("VCommandLine", "Export options can be used with single input file only.") << "/n"; qCritical() << translate("VCommandLine", "Export options can be used with single input file only.") << "/n";
@ -403,9 +539,9 @@ bool VCommandLine::IsExportEnabled() const
DialogLayoutSettings::PaperSizeTemplate VCommandLine::OptPaperSize() const DialogLayoutSettings::PaperSizeTemplate VCommandLine::OptPaperSize() const
{ {
int ppsize = 0; int ppsize = 0;
if (parser.isSet(*optionsUsed.value(LONG_OPTION_PAGETEMPLATE))) if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGETEMPLATE))))
{ {
ppsize = parser.value(*optionsUsed.value(LONG_OPTION_PAGETEMPLATE)).toInt(); ppsize = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGETEMPLATE))).toInt();
} }
return static_cast<DialogLayoutSettings::PaperSizeTemplate>(ppsize); return static_cast<DialogLayoutSettings::PaperSizeTemplate>(ppsize);
} }
@ -414,9 +550,9 @@ DialogLayoutSettings::PaperSizeTemplate VCommandLine::OptPaperSize() const
int VCommandLine::OptRotation() const int VCommandLine::OptRotation() const
{ {
int rotate = 0; int rotate = 0;
if (parser.isSet(*optionsUsed.value(LONG_OPTION_ROTATE))) if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_ROTATE))))
{ {
rotate = parser.value(*optionsUsed.value(LONG_OPTION_ROTATE)).toInt(); rotate = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_ROTATE))).toInt();
} }
return rotate; return rotate;
@ -425,7 +561,7 @@ int VCommandLine::OptRotation() const
//------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------
Cases VCommandLine::OptGroup() const Cases VCommandLine::OptGroup() const
{ {
int r = parser.value(*optionsUsed.value(LONG_OPTION_GROUPPING)).toInt(); int r = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GROUPPING))).toInt();
if ( r < 0 || r >= static_cast<int>(Cases::UnknownCase)) if ( r < 0 || r >= static_cast<int>(Cases::UnknownCase))
{ {
r = 0; r = 0;
@ -437,11 +573,11 @@ Cases VCommandLine::OptGroup() const
QString VCommandLine::OptMeasurePath() const QString VCommandLine::OptMeasurePath() const
{ {
QString measure; QString measure;
if (parser.isSet(*optionsUsed.value(LONG_OPTION_MEASUREFILE)) if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_MEASUREFILE)))
&& IsExportEnabled() //todo: don't want yet to allow user set measure file for general loading, because need to fix multiply opened windows as well && IsExportEnabled() //todo: don't want yet to allow user set measure file for general loading, because need to fix multiply opened windows as well
) )
{ {
measure = parser.value(*optionsUsed.value(LONG_OPTION_MEASUREFILE)); measure = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_MEASUREFILE)));
} }
return measure; return measure;
@ -453,7 +589,7 @@ QString VCommandLine::OptBaseName() const
QString path; QString path;
if (IsExportEnabled()) if (IsExportEnabled())
{ {
path = parser.value(*optionsUsed.value(LONG_OPTION_BASENAME)); path = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BASENAME)));
} }
return path; return path;
@ -465,7 +601,7 @@ QString VCommandLine::OptDestinationPath() const
QString path; QString path;
if (IsExportEnabled()) if (IsExportEnabled())
{ {
path = parser.value(*optionsUsed.value(LONG_OPTION_DESTINATION)); path = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_DESTINATION)));
} }
return path; return path;
@ -475,9 +611,9 @@ QString VCommandLine::OptDestinationPath() const
int VCommandLine::OptExportType() const int VCommandLine::OptExportType() const
{ {
int r = 0; int r = 0;
if (parser.isSet(*optionsUsed.value(LONG_OPTION_EXP2FORMAT))) if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_EXP2FORMAT))))
{ {
r = parser.value(*optionsUsed.value(LONG_OPTION_EXP2FORMAT)).toInt(); r = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_EXP2FORMAT))).toInt();
} }
return r; return r;
} }
@ -497,19 +633,19 @@ bool VCommandLine::IsGuiEnabled() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VCommandLine::IsSetGradationSize() const bool VCommandLine::IsSetGradationSize() const
{ {
return parser.isSet(*optionsUsed.value(LONG_OPTION_GRADATIONSIZE)); return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONSIZE)));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VCommandLine::IsSetGradationHeight() const bool VCommandLine::IsSetGradationHeight() const
{ {
return parser.isSet(*optionsUsed.value(LONG_OPTION_GRADATIONHEIGHT)); return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONHEIGHT)));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VCommandLine::OptGradationSize() const QString VCommandLine::OptGradationSize() const
{ {
const QString size = parser.value(*optionsUsed.value(LONG_OPTION_GRADATIONSIZE)); const QString size = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONSIZE)));
if (VMeasurement::IsGradationSizeValid(size)) if (VMeasurement::IsGradationSizeValid(size))
{ {
return size; return size;
@ -524,7 +660,7 @@ QString VCommandLine::OptGradationSize() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VCommandLine::OptGradationHeight() const QString VCommandLine::OptGradationHeight() const
{ {
const QString height = parser.value(*optionsUsed.value(LONG_OPTION_GRADATIONHEIGHT)); const QString height = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONHEIGHT)));
if (VMeasurement::IsGradationHeightValid(height)) if (VMeasurement::IsGradationHeightValid(height))
{ {
return height; return height;

View File

@ -17,6 +17,7 @@
class VCommandLine; class VCommandLine;
typedef std::shared_ptr<VCommandLine> VCommandLinePtr; typedef std::shared_ptr<VCommandLine> VCommandLinePtr;
typedef QList<QCommandLineOption *> VCommandLineOptions;
//@brief: class used to install export command line options and parse their values //@brief: class used to install export command line options and parse their values
//QCommandLineParser* object must exists until this object alive //QCommandLineParser* object must exists until this object alive
@ -81,14 +82,15 @@ private:
Q_DISABLE_COPY(VCommandLine) Q_DISABLE_COPY(VCommandLine)
static VCommandLinePtr instance; static VCommandLinePtr instance;
QCommandLineParser parser; QCommandLineParser parser;
QMap<QString, QCommandLineOption *> optionsUsed; VCommandLineOptions optionsUsed;
QMap<QString, int> optionsIndex;
bool isGuiEnabled; bool isGuiEnabled;
friend class VApplication; friend class VApplication;
static qreal Lo2Px(const QString& src, const DialogLayoutSettings& converter); static qreal Lo2Px(const QString& src, const DialogLayoutSettings& converter);
static qreal Pg2Px(const QString& src, const DialogLayoutSettings& converter); static qreal Pg2Px(const QString& src, const DialogLayoutSettings& converter);
static QMap<QString, QCommandLineOption *> InitOptionsUsed(); static void InitOptions(VCommandLineOptions &options, QMap<QString, int> &optionsIndex);
}; };
#endif // VCMDEXPORT_H #endif // VCMDEXPORT_H

View File

@ -38,6 +38,7 @@
# include <QtMath> # include <QtMath>
#endif #endif
#include <QMessageBox>
#include <QPushButton> #include <QPushButton>
//must be the same order as PaperSizeTemplate constants //must be the same order as PaperSizeTemplate constants
@ -98,6 +99,13 @@ DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget
connect(ui->doubleSpinBoxPaperHeight, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), connect(ui->doubleSpinBoxPaperHeight, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogLayoutSettings::FindTemplate); this, &DialogLayoutSettings::FindTemplate);
connect(ui->doubleSpinBoxPaperWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogLayoutSettings::CorrectMaxFileds);
connect(ui->doubleSpinBoxPaperHeight, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogLayoutSettings::CorrectMaxFileds);
connect(ui->checkBoxIgnoreFileds, &QCheckBox::stateChanged, this, &DialogLayoutSettings::IgnoreAllFields);
connect(ui->toolButtonPortrate, &QToolButton::toggled, this, &DialogLayoutSettings::Swap); connect(ui->toolButtonPortrate, &QToolButton::toggled, this, &DialogLayoutSettings::Swap);
connect(ui->toolButtonLandscape, &QToolButton::toggled, this, &DialogLayoutSettings::Swap); connect(ui->toolButtonLandscape, &QToolButton::toggled, this, &DialogLayoutSettings::Swap);
connect(ui->comboBoxLayoutUnit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), connect(ui->comboBoxLayoutUnit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
@ -125,6 +133,7 @@ qreal DialogLayoutSettings::GetPaperHeight() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetPaperHeight(qreal value) void DialogLayoutSettings::SetPaperHeight(qreal value)
{ {
ui->doubleSpinBoxPaperHeight->setMaximum(FromPixel(QIMAGE_MAX, PaperUnit()));
ui->doubleSpinBoxPaperHeight->setValue(UnitConvertor(value, Unit::Px, PaperUnit())); ui->doubleSpinBoxPaperHeight->setValue(UnitConvertor(value, Unit::Px, PaperUnit()));
} }
@ -137,6 +146,7 @@ qreal DialogLayoutSettings::GetPaperWidth() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetPaperWidth(qreal value) void DialogLayoutSettings::SetPaperWidth(qreal value)
{ {
ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, PaperUnit()));
ui->doubleSpinBoxPaperWidth->setValue(UnitConvertor(value, Unit::Px, PaperUnit())); ui->doubleSpinBoxPaperWidth->setValue(UnitConvertor(value, Unit::Px, PaperUnit()));
} }
@ -164,6 +174,26 @@ void DialogLayoutSettings::SetLayoutWidth(qreal value)
ui->doubleSpinBoxLayoutWidth->setValue(UnitConvertor(value, Unit::Px, LayoutUnit())); ui->doubleSpinBoxLayoutWidth->setValue(UnitConvertor(value, Unit::Px, LayoutUnit()));
} }
//---------------------------------------------------------------------------------------------------------------------
QMarginsF DialogLayoutSettings::GetFields() const
{
QMarginsF fields;
fields.setLeft(UnitConvertor(ui->doubleSpinBoxLeftField->value(), oldLayoutUnit, Unit::Px));
fields.setRight(UnitConvertor(ui->doubleSpinBoxRightField->value(), oldLayoutUnit, Unit::Px));
fields.setTop(UnitConvertor(ui->doubleSpinBoxTopField->value(), oldLayoutUnit, Unit::Px));
fields.setBottom(UnitConvertor(ui->doubleSpinBoxBottomField->value(), oldLayoutUnit, Unit::Px));
return fields;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetFields(const QMarginsF &value)
{
ui->doubleSpinBoxLeftField->setValue(UnitConvertor(value.left(), Unit::Px, LayoutUnit()));
ui->doubleSpinBoxRightField->setValue(UnitConvertor(value.right(), Unit::Px, LayoutUnit()));
ui->doubleSpinBoxTopField->setValue(UnitConvertor(value.top(), Unit::Px, LayoutUnit()));
ui->doubleSpinBoxBottomField->setValue(UnitConvertor(value.bottom(), Unit::Px, LayoutUnit()));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
Cases DialogLayoutSettings::GetGroup() const Cases DialogLayoutSettings::GetGroup() const
{ {
@ -271,6 +301,18 @@ void DialogLayoutSettings::SetUnitePages(bool save)
ui->checkBoxUnitePages->setChecked(save); ui->checkBoxUnitePages->setChecked(save);
} }
//---------------------------------------------------------------------------------------------------------------------
bool DialogLayoutSettings::IsIgnoreAllFields() const
{
return ui->checkBoxIgnoreFileds->isChecked();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetIgnoreAllFields(bool value)
{
ui->checkBoxIgnoreFileds->setChecked(value);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::TemplateSelected() void DialogLayoutSettings::TemplateSelected()
{ {
@ -317,6 +359,11 @@ void DialogLayoutSettings::ConvertPaperSize()
const qreal width = ui->doubleSpinBoxPaperWidth->value(); const qreal width = ui->doubleSpinBoxPaperWidth->value();
const qreal height = ui->doubleSpinBoxPaperHeight->value(); const qreal height = ui->doubleSpinBoxPaperHeight->value();
const qreal left = ui->doubleSpinBoxLeftField->value();
const qreal right = ui->doubleSpinBoxRightField->value();
const qreal top = ui->doubleSpinBoxTopField->value();
const qreal bottom = ui->doubleSpinBoxBottomField->value();
ui->doubleSpinBoxPaperWidth->blockSignals(true); ui->doubleSpinBoxPaperWidth->blockSignals(true);
ui->doubleSpinBoxPaperHeight->blockSignals(true); ui->doubleSpinBoxPaperHeight->blockSignals(true);
ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, paperUnit)); ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, paperUnit));
@ -327,12 +374,22 @@ void DialogLayoutSettings::ConvertPaperSize()
const qreal newWidth = UnitConvertor(width, oldPaperUnit, paperUnit); const qreal newWidth = UnitConvertor(width, oldPaperUnit, paperUnit);
const qreal newHeight = UnitConvertor(height, oldPaperUnit, paperUnit); const qreal newHeight = UnitConvertor(height, oldPaperUnit, paperUnit);
const qreal newLeft = UnitConvertor(left, oldPaperUnit, paperUnit);
const qreal newRight = UnitConvertor(right, oldPaperUnit, paperUnit);
const qreal newTop = UnitConvertor(top, oldPaperUnit, paperUnit);
const qreal newBottom = UnitConvertor(bottom, oldPaperUnit, paperUnit);
oldPaperUnit = paperUnit; oldPaperUnit = paperUnit;
CorrectPaperDecimals(); CorrectPaperDecimals();
MinimumPaperSize(); MinimumPaperSize();
ui->doubleSpinBoxPaperWidth->setValue(newWidth); ui->doubleSpinBoxPaperWidth->setValue(newWidth);
ui->doubleSpinBoxPaperHeight->setValue(newHeight); ui->doubleSpinBoxPaperHeight->setValue(newHeight);
ui->doubleSpinBoxLeftField->setValue(newLeft);
ui->doubleSpinBoxRightField->setValue(newRight);
ui->doubleSpinBoxTopField->setValue(newTop);
ui->doubleSpinBoxBottomField->setValue(newBottom);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -433,8 +490,6 @@ void DialogLayoutSettings::PaperSizeChanged()
ui->toolButtonLandscape->setChecked(true); ui->toolButtonLandscape->setChecked(true);
ui->toolButtonLandscape->blockSignals(false); ui->toolButtonLandscape->blockSignals(false);
} }
Label();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -464,8 +519,6 @@ void DialogLayoutSettings::Swap(bool checked)
ui->doubleSpinBoxPaperHeight->blockSignals(true); ui->doubleSpinBoxPaperHeight->blockSignals(true);
ui->doubleSpinBoxPaperHeight->setValue(width); ui->doubleSpinBoxPaperHeight->setValue(width);
ui->doubleSpinBoxPaperHeight->blockSignals(false); ui->doubleSpinBoxPaperHeight->blockSignals(false);
Label();
} }
} }
@ -475,8 +528,8 @@ void DialogLayoutSettings::DialogAccepted()
SCASSERT(generator != nullptr) SCASSERT(generator != nullptr)
generator->SetLayoutWidth(GetLayoutWidth()); generator->SetLayoutWidth(GetLayoutWidth());
generator->SetCaseType(GetGroup()); generator->SetCaseType(GetGroup());
generator->SetPaperHeight(qFloor(GetPaperHeight())); generator->SetPaperHeight(GetPaperHeight());
generator->SetPaperWidth(qFloor(GetPaperWidth())); generator->SetPaperWidth(GetPaperWidth());
generator->SetShift(qFloor(GetShift())); generator->SetShift(qFloor(GetShift()));
generator->SetRotate(GetRotate()); generator->SetRotate(GetRotate());
generator->SetRotationIncrease(GetIncrease()); generator->SetRotationIncrease(GetIncrease());
@ -484,6 +537,48 @@ void DialogLayoutSettings::DialogAccepted()
generator->SetSaveLength(IsSaveLength()); generator->SetSaveLength(IsSaveLength());
generator->SetUnitePages(IsUnitePages()); generator->SetUnitePages(IsUnitePages());
if (IsIgnoreAllFields())
{
generator->SetFields(QMarginsF());
}
else
{
const QMarginsF minFields = RoundMargins(VSettings::GetDefFields());
const QMarginsF fields = RoundMargins(GetFields());
if (fields.left() < minFields.left() || fields.right() < minFields.right() ||
fields.top() < minFields.top() || fields.bottom() < minFields.bottom())
{
QMessageBox::StandardButton answer;
answer = QMessageBox::question(this, tr("Wrong fields."),
tr("Fields go beyond printing. \n\nApply settings anyway?"),
QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
if (answer == QMessageBox::No)
{
if (fields.left() < minFields.left())
{
ui->doubleSpinBoxLeftField->setValue(UnitConvertor(minFields.left(), Unit::Px, LayoutUnit()));
}
if (fields.right() < minFields.right())
{
ui->doubleSpinBoxRightField->setValue(UnitConvertor(minFields.right(), Unit::Px, LayoutUnit()));
}
if (fields.top() < minFields.top())
{
ui->doubleSpinBoxTopField->setValue(UnitConvertor(minFields.top(), Unit::Px, LayoutUnit()));
}
if (fields.bottom() < minFields.bottom())
{
ui->doubleSpinBoxBottomField->setValue(UnitConvertor(minFields.bottom(), Unit::Px, LayoutUnit()));
}
}
}
generator->SetFields(GetFields());
}
//don't want to break visual settings when cmd used //don't want to break visual settings when cmd used
if (disableSettings == false) if (disableSettings == false)
{ {
@ -505,6 +600,36 @@ void DialogLayoutSettings::RestoreDefaults()
SetGroup(VSettings::GetDefLayoutGroup()); SetGroup(VSettings::GetDefLayoutGroup());
SetRotate(VSettings::GetDefLayoutRotate()); SetRotate(VSettings::GetDefLayoutRotate());
SetIncrease(VSettings::GetDefLayoutRotationIncrease()); SetIncrease(VSettings::GetDefLayoutRotationIncrease());
SetFields(VSettings::GetDefFields());
SetIgnoreAllFields(VSettings::GetDefIgnoreAllFields());
CorrectMaxFileds();
IgnoreAllFields(ui->checkBoxIgnoreFileds->isChecked());
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::CorrectMaxFileds()
{
const qreal width = ui->doubleSpinBoxPaperWidth->value();
const qreal height = ui->doubleSpinBoxPaperHeight->value();
// 80%/2 of paper size for each field
const qreal widthField = (width*80.0/100.0)/2.0;
const qreal heightField = (height*80.0/100.0)/2.0;
ui->doubleSpinBoxLeftField->setMaximum(widthField);
ui->doubleSpinBoxRightField->setMaximum(widthField);
ui->doubleSpinBoxTopField->setMaximum(heightField);
ui->doubleSpinBoxBottomField->setMaximum(heightField);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::IgnoreAllFields(int state)
{
ui->doubleSpinBoxLeftField->setDisabled(state);
ui->doubleSpinBoxRightField->setDisabled(state);
ui->doubleSpinBoxTopField->setDisabled(state);
ui->doubleSpinBoxBottomField->setDisabled(state);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -711,6 +836,17 @@ QSizeF DialogLayoutSettings::RoundTemplateSize(qreal width, qreal height) const
return QSizeF(width, height); return QSizeF(width, height);
} }
//---------------------------------------------------------------------------------------------------------------------
QMarginsF DialogLayoutSettings::RoundMargins(const QMarginsF &margins) const
{
QMarginsF newMargins;
newMargins.setLeft(qRound(margins.left() * 100.0) / 100.0);
newMargins.setRight(qRound(margins.right() * 100.0) / 100.0);
newMargins.setTop(qRound(margins.top() * 100.0) / 100.0);
newMargins.setBottom(qRound(margins.bottom() * 100.0) / 100.0);
return newMargins;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
Unit DialogLayoutSettings::PaperUnit() const Unit DialogLayoutSettings::PaperUnit() const
{ {
@ -740,16 +876,23 @@ void DialogLayoutSettings::CorrectPaperDecimals()
{ {
case Unit::Cm: case Unit::Cm:
case Unit::Mm: case Unit::Mm:
case Unit::Px:
ui->doubleSpinBoxPaperWidth->setDecimals(2); ui->doubleSpinBoxPaperWidth->setDecimals(2);
ui->doubleSpinBoxPaperHeight->setDecimals(2); ui->doubleSpinBoxPaperHeight->setDecimals(2);
ui->doubleSpinBoxLeftField->setDecimals(4);
ui->doubleSpinBoxRightField->setDecimals(4);
ui->doubleSpinBoxTopField->setDecimals(4);
ui->doubleSpinBoxBottomField->setDecimals(4);
break; break;
case Unit::Inch: case Unit::Inch:
ui->doubleSpinBoxPaperWidth->setDecimals(5); ui->doubleSpinBoxPaperWidth->setDecimals(5);
ui->doubleSpinBoxPaperHeight->setDecimals(5); ui->doubleSpinBoxPaperHeight->setDecimals(5);
break;
case Unit::Px: ui->doubleSpinBoxLeftField->setDecimals(5);
ui->doubleSpinBoxPaperWidth->setDecimals(2); ui->doubleSpinBoxRightField->setDecimals(5);
ui->doubleSpinBoxPaperHeight->setDecimals(2); ui->doubleSpinBoxTopField->setDecimals(5);
ui->doubleSpinBoxBottomField->setDecimals(5);
break; break;
default: default:
break; break;
@ -763,6 +906,7 @@ void DialogLayoutSettings::CorrectLayoutDecimals()
{ {
case Unit::Cm: case Unit::Cm:
case Unit::Mm: case Unit::Mm:
case Unit::Px:
ui->doubleSpinBoxLayoutWidth->setDecimals(2); ui->doubleSpinBoxLayoutWidth->setDecimals(2);
ui->doubleSpinBoxShift->setDecimals(2); ui->doubleSpinBoxShift->setDecimals(2);
break; break;
@ -770,24 +914,11 @@ void DialogLayoutSettings::CorrectLayoutDecimals()
ui->doubleSpinBoxLayoutWidth->setDecimals(5); ui->doubleSpinBoxLayoutWidth->setDecimals(5);
ui->doubleSpinBoxShift->setDecimals(5); ui->doubleSpinBoxShift->setDecimals(5);
break; break;
case Unit::Px:
ui->doubleSpinBoxLayoutWidth->setDecimals(2);
ui->doubleSpinBoxShift->setDecimals(2);
break;
default: default:
break; break;
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::Label()
{
const int width = qFloor(UnitConvertor(ui->doubleSpinBoxPaperWidth->value(), PaperUnit(), Unit::Px));
const int height = qFloor(UnitConvertor(ui->doubleSpinBoxPaperHeight->value(), PaperUnit(), Unit::Px));
QString text = QString("%1 x %2 px, \n%3 ppi").arg(width).arg(height).arg(PrintDPI);
ui->labelSizeDescription->setText(text);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::MinimumPaperSize() void DialogLayoutSettings::MinimumPaperSize()
{ {
@ -819,8 +950,13 @@ void DialogLayoutSettings::ReadSettings()
SetAutoCrop(settings->GetLayoutAutoCrop()); SetAutoCrop(settings->GetLayoutAutoCrop());
SetSaveLength(settings->GetLayoutSaveLength()); SetSaveLength(settings->GetLayoutSaveLength());
SetUnitePages(settings->GetLayoutUnitePages()); SetUnitePages(settings->GetLayoutUnitePages());
SetFields(settings->GetFields());
SetIgnoreAllFields(settings->GetIgnoreAllFields());
FindTemplate(); FindTemplate();
CorrectMaxFileds();
IgnoreAllFields(ui->checkBoxIgnoreFileds->isChecked());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -837,6 +973,8 @@ void DialogLayoutSettings::WriteSettings() const
settings->SetLayoutAutoCrop(GetAutoCrop()); settings->SetLayoutAutoCrop(GetAutoCrop());
settings->SetLayoutSaveLength(IsSaveLength()); settings->SetLayoutSaveLength(IsSaveLength());
settings->SetLayoutUnitePages(IsUnitePages()); settings->SetLayoutUnitePages(IsUnitePages());
settings->SetFields(GetFields());
settings->SetIgnoreAllFields(IsIgnoreAllFields());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -35,6 +35,7 @@
#include "../vlayout/vbank.h" #include "../vlayout/vbank.h"
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#include "../vlayout/vlayoutgenerator.h" #include "../vlayout/vlayoutgenerator.h"
#include "../vmisc/vmargins.h"
namespace Ui namespace Ui
{ {
@ -75,6 +76,9 @@ public:
qreal GetLayoutWidth() const; qreal GetLayoutWidth() const;
void SetLayoutWidth(qreal value); void SetLayoutWidth(qreal value);
QMarginsF GetFields() const;
void SetFields(const QMarginsF &value);
Cases GetGroup() const; Cases GetGroup() const;
void SetGroup(const Cases &value); void SetGroup(const Cases &value);
@ -93,6 +97,9 @@ public:
bool IsUnitePages() const; bool IsUnitePages() const;
void SetUnitePages(bool save); void SetUnitePages(bool save);
bool IsIgnoreAllFields() const;
void SetIgnoreAllFields(bool value);
//support functions for the command line parser which uses invisible dialog to properly build layout generator //support functions for the command line parser which uses invisible dialog to properly build layout generator
bool SelectTemplate(const PaperSizeTemplate& id); bool SelectTemplate(const PaperSizeTemplate& id);
static QString MakeHelpTemplateList(); static QString MakeHelpTemplateList();
@ -114,7 +121,9 @@ public slots:
void DialogAccepted(); void DialogAccepted();
void RestoreDefaults(); void RestoreDefaults();
private slots:
void CorrectMaxFileds();
void IgnoreAllFields(int state);
private: private:
Q_DISABLE_COPY(DialogLayoutSettings) Q_DISABLE_COPY(DialogLayoutSettings)
typedef QStringList FormatsVector; typedef QStringList FormatsVector;
@ -135,13 +144,13 @@ private:
QSizeF Template(); QSizeF Template();
QSizeF TemplateSize(const PaperSizeTemplate &tmpl) const; QSizeF TemplateSize(const PaperSizeTemplate &tmpl) const;
QSizeF RoundTemplateSize(qreal width, qreal height) const; QSizeF RoundTemplateSize(qreal width, qreal height) const;
QMarginsF RoundMargins(const QMarginsF &margins) const;
Unit PaperUnit() const; Unit PaperUnit() const;
Unit LayoutUnit() const; Unit LayoutUnit() const;
void CorrectPaperDecimals(); void CorrectPaperDecimals();
void CorrectLayoutDecimals(); void CorrectLayoutDecimals();
void Label();
void MinimumPaperSize(); void MinimumPaperSize();
void MinimumLayoutSize(); void MinimumLayoutSize();

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>661</width> <width>661</width>
<height>345</height> <height>453</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -23,12 +23,12 @@
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_5"> <layout class="QVBoxLayout" name="verticalLayout_5">
<item> <item>
<widget class="QGroupBox" name="groupBoxPaperSize"> <widget class="QGroupBox" name="groupBoxPaperFormat">
<property name="autoFillBackground"> <property name="autoFillBackground">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="title"> <property name="title">
<string>Paper size</string> <string>Paper format</string>
</property> </property>
<property name="flat"> <property name="flat">
<bool>false</bool> <bool>false</bool>
@ -72,22 +72,6 @@
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="1" column="2">
<widget class="QComboBox" name="comboBoxPaperSizeUnit">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>124</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="labelWidth"> <widget class="QLabel" name="labelWidth">
<property name="sizePolicy"> <property name="sizePolicy">
@ -146,14 +130,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="2"> <item row="2" column="0">
<widget class="QLabel" name="labelSizeDescription">
<property name="text">
<string notr="true">TextLabel</string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QToolButton" name="toolButtonPortrate"> <widget class="QToolButton" name="toolButtonPortrate">
@ -203,27 +180,163 @@
</item> </item>
</layout> </layout>
</item> </item>
</layout> <item row="2" column="1">
</item> <widget class="QComboBox" name="comboBoxPaperSizeUnit">
<item> <property name="sizePolicy">
<widget class="QCheckBox" name="checkBoxAutoCrop"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<property name="text"> <horstretch>0</horstretch>
<string>Auto crop unused length</string> <verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>124</width>
<height>0</height>
</size>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="checkBoxUnitePages"> <widget class="QGroupBox" name="groupBoxPaperFileds">
<property name="title">
<string>Fields</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelLeftField">
<property name="text"> <property name="text">
<string>Unite pages (if possible)</string> <string>Left:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxLeftField"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelRightField">
<property name="text">
<string>Right:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxRightField"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelTopField">
<property name="text">
<string>Top:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxTopField"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelBottomField">
<property name="text">
<string>Bottom:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxBottomField"/>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="checkBoxIgnoreFileds">
<property name="text">
<string>Ignore fileds</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
</layout>
</item>
<item> <item>
<widget class="Line" name="line_2"> <widget class="QGroupBox" name="groupBoxCreationOptions">
<property name="title">
<string>Creation options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxLayoutWidth">
<property name="minimumSize">
<size>
<width>94</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelLayoutWidth">
<property name="text">
<string>Gap width:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelShiftLength">
<property name="text">
<string>Shift length:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxShift">
<property name="minimumSize">
<size>
<width>94</width>
<height>0</height>
</size>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
<property name="value">
<double>10.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="comboBoxLayoutUnit"/>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string notr="true">×2</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxSaveLength">
<property name="text">
<string>Save length of the sheet</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -378,86 +491,8 @@
</layout> </layout>
</widget> </widget>
</item> </item>
</layout>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBoxCreationOptions"> <widget class="Line" name="line_2">
<property name="title">
<string>Creation options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxLayoutWidth">
<property name="minimumSize">
<size>
<width>94</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelLayoutWidth">
<property name="text">
<string>Gap width:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelShiftLength">
<property name="text">
<string>Shift length:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxShift">
<property name="minimumSize">
<size>
<width>94</width>
<height>0</height>
</size>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
<property name="value">
<double>10.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="comboBoxLayoutUnit"/>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string notr="true">×2</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxSaveLength">
<property name="text">
<string>Save length of the sheet</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -512,6 +547,27 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxAutoCrop">
<property name="text">
<string>Auto crop unused length</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxUnitePages">
<property name="text">
<string>Unite pages (if possible)</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -567,7 +623,7 @@
</connection> </connection>
</connections> </connections>
<buttongroups> <buttongroups>
<buttongroup name="buttonGroup"/>
<buttongroup name="buttonGroupPrinciple"/> <buttongroup name="buttonGroupPrinciple"/>
<buttongroup name="buttonGroup"/>
</buttongroups> </buttongroups>
</ui> </ui>

View File

@ -45,7 +45,6 @@
#include <QProcess> #include <QProcess>
#include <QToolButton> #include <QToolButton>
#include <QtSvg> #include <QtSvg>
#include <QPrinter>
#include <QPrintPreviewDialog> #include <QPrintPreviewDialog>
#include <QPrintDialog> #include <QPrintDialog>
#include <QPrinterInfo> #include <QPrinterInfo>
@ -62,7 +61,7 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent)
pattern(new VContainer(qApp->TrVars(), qApp->patternUnitP())), doc(nullptr), papers(QList<QGraphicsItem *>()), pattern(new VContainer(qApp->TrVars(), qApp->patternUnitP())), doc(nullptr), papers(QList<QGraphicsItem *>()),
shadows(QList<QGraphicsItem *>()), scenes(QList<QGraphicsScene *>()), details(QList<QList<QGraphicsItem *> >()), shadows(QList<QGraphicsItem *>()), scenes(QList<QGraphicsScene *>()), details(QList<QList<QGraphicsItem *> >()),
undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()), undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()),
isLayoutStale(true), isTiled(false) isLayoutStale(true), margins(), paperSize(), isTiled(false)
{ {
InitTempLayoutScene(); InitTempLayoutScene();
} }
@ -132,6 +131,8 @@ bool MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator)
CreateShadows(); CreateShadows();
CreateScenes(); CreateScenes();
PrepareSceneList(); PrepareSceneList();
margins = lGenerator.GetFields();
paperSize = QSizeF(lGenerator.GetPaperWidth(), lGenerator.GetPaperHeight());
isLayoutStale = false; isLayoutStale = false;
break; break;
case LayoutErrors::ProcessStoped: case LayoutErrors::ProcessStoped:
@ -356,7 +357,7 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer)
{ {
index = lastPage - j; index = lastPage - j;
} }
painter.drawImage(QPointF(), poster.at(index)); painter.drawImage(QPointF(margins.left(), margins.top()), poster.at(index));
} }
} }
@ -789,28 +790,18 @@ void MainWindowsNoGUI::PrintPreview()
return; return;
} }
} }
QPrinterInfo def = QPrinterInfo::defaultPrinter();
//if there is no default printer set the print preview won't show QSharedPointer<QPrinter> printer = DefaultPrinter();
if(def.isNull() || def.printerName().isEmpty()) if (printer.isNull())
{
if(QPrinterInfo::availablePrinters().isEmpty())
{ {
qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")), qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")),
qUtf8Printable(tr("Cannot proceed because there are no available printers in your system."))); qUtf8Printable(tr("Cannot proceed because there are no available printers in your system.")));
return; return;
} }
else
{
def = QPrinterInfo::availablePrinters().first();
}
}
QPrinter printer(def, QPrinter::ScreenResolution); SetPrinterSettings(printer.data(), false);
printer.setResolution(static_cast<int>(PrintDPI));
SetPrinterSettings(&printer);
// display print preview dialog // display print preview dialog
QPrintPreviewDialog preview(&printer); QPrintPreviewDialog preview(printer.data());
connect(&preview, &QPrintPreviewDialog::paintRequested, this, &MainWindowsNoGUI::PrintPages); connect(&preview, &QPrintPreviewDialog::paintRequested, this, &MainWindowsNoGUI::PrintPages);
preview.exec(); preview.exec();
} }
@ -839,7 +830,7 @@ void MainWindowsNoGUI::LayoutPrint()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer) void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, bool prepareForPrinting)
{ {
SCASSERT(printer != nullptr) SCASSERT(printer != nullptr)
printer->setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion()); printer->setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
@ -861,17 +852,34 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer)
if (not isTiled && papers.size() > 0) if (not isTiled && papers.size() > 0)
{ {
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(0)); const QSizeF size = QSizeF(FromPixel(paperSize.width(), Unit::Mm), FromPixel(paperSize.height(), Unit::Mm));
SCASSERT(paper != nullptr) const QPrinter::PageSize pSZ = FindTemplate(size);
printer->setPaperSize ( QSizeF(FromPixel(paper->rect().width(), Unit::Mm), if (pSZ == QPrinter::Custom)
FromPixel(paper->rect().height(), Unit::Mm)), QPrinter::Millimeter ); {
printer->setPaperSize (size, QPrinter::Millimeter );
}
else
{
printer->setPaperSize (pSZ);
}
} }
{
const qreal left = FromPixel(margins.left(), Unit::Mm);
const qreal top = FromPixel(margins.top(), Unit::Mm);
const qreal right = FromPixel(margins.right(), Unit::Mm);
const qreal bottom = FromPixel(margins.bottom(), Unit::Mm);
printer->setPageMargins(left, top, right, bottom, QPrinter::Millimeter);
}
if (prepareForPrinting)
{
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName()); printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName());
#else #else
printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName() + QLatin1Literal(".pdf")); printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName() + QLatin1Literal(".pdf"));
#endif #endif
}
printer->setDocName(FileName()); printer->setDocName(FileName());
IsLayoutGrayscale() ? printer->setColorMode(QPrinter::GrayScale) : printer->setColorMode(QPrinter::Color); IsLayoutGrayscale() ? printer->setColorMode(QPrinter::GrayScale) : printer->setColorMode(QPrinter::Color);
@ -893,6 +901,47 @@ bool MainWindowsNoGUI::IsLayoutGrayscale() const
return true; return true;
} }
//---------------------------------------------------------------------------------------------------------------------
QPrinter::PaperSize MainWindowsNoGUI::FindTemplate(const QSizeF &size) const
{
if (size == QSizeF(841, 1189))
{
return QPrinter::A0;
}
if (size == QSizeF(594, 841))
{
return QPrinter::A1;
}
if (size == QSizeF(420, 594))
{
return QPrinter::A2;
}
if (size == QSizeF(297, 420))
{
return QPrinter::A3;
}
if (size == QSizeF(210, 297))
{
return QPrinter::A4;
}
if (size == QSizeF(215.9, 355.6))
{
return QPrinter::Legal;
}
if (size == QSizeF(215.9, 279.4))
{
return QPrinter::Letter;
}
return QPrinter::Custom;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool MainWindowsNoGUI::isPagesUniform() const bool MainWindowsNoGUI::isPagesUniform() const
{ {

View File

@ -30,6 +30,7 @@
#define MAINWINDOWSNOGUI_H #define MAINWINDOWSNOGUI_H
#include <QMainWindow> #include <QMainWindow>
#include <QPrinter>
#include "../vpatterndb/vdetail.h" #include "../vpatterndb/vdetail.h"
#include "../vlayout/vlayoutdetail.h" #include "../vlayout/vlayoutdetail.h"
@ -87,6 +88,8 @@ protected:
QString curFile; QString curFile;
bool isLayoutStale; bool isLayoutStale;
QMarginsF margins;
QSizeF paperSize;
void PrepareDetailsForLayout(const QHash<quint32, VDetail> *details); void PrepareDetailsForLayout(const QHash<quint32, VDetail> *details);
void ExportLayout(const DialogSaveLayout &dialog); void ExportLayout(const DialogSaveLayout &dialog);
@ -119,8 +122,9 @@ private:
void PrintPreview(); void PrintPreview();
void LayoutPrint(); void LayoutPrint();
void SetPrinterSettings(QPrinter *printer); void SetPrinterSettings(QPrinter *printer, bool prepareForPrinting = true);
bool IsLayoutGrayscale() const; bool IsLayoutGrayscale() const;
QPrinter::PaperSize FindTemplate(const QSizeF &size) const;
bool isPagesUniform() const; bool isPagesUniform() const;
QString FileName() const; QString FileName() const;

View File

@ -38,7 +38,7 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VLayoutGenerator::VLayoutGenerator(QObject *parent) VLayoutGenerator::VLayoutGenerator(QObject *parent)
:QObject(parent), papers(QVector<VLayoutPaper>()), bank(new VBank()), paperHeight(0), paperWidth(0), :QObject(parent), papers(QVector<VLayoutPaper>()), bank(new VBank()), paperHeight(0), paperWidth(0), margins(),
stopGeneration(false), state(LayoutErrors::NoError), shift(0), rotate(true), rotationIncrease(180), stopGeneration(false), state(LayoutErrors::NoError), shift(0), rotate(true), rotationIncrease(180),
autoCrop(false), saveLength(false), unitePages(false) autoCrop(false), saveLength(false), unitePages(false)
{} {}
@ -99,7 +99,7 @@ void VLayoutGenerator::Generate()
break; break;
} }
VLayoutPaper paper(paperHeight, paperWidth); VLayoutPaper paper(PageHeight(), PageWidth());
paper.SetShift(shift); paper.SetShift(shift);
paper.SetLayoutWidth(bank->GetLayoutWidth()); paper.SetLayoutWidth(bank->GetLayoutWidth());
paper.SetPaperIndex(static_cast<quint32>(papers.count())); paper.SetPaperIndex(static_cast<quint32>(papers.count()));
@ -189,6 +189,18 @@ void VLayoutGenerator::Abort()
#endif #endif
} }
//---------------------------------------------------------------------------------------------------------------------
int VLayoutGenerator::PageHeight() const
{
return static_cast<int>(paperHeight - (margins.top() + margins.bottom()));
}
//---------------------------------------------------------------------------------------------------------------------
int VLayoutGenerator::PageWidth() const
{
return static_cast<int>(paperWidth - (margins.left() + margins.right()));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VLayoutGenerator::IsUnitePages() const bool VLayoutGenerator::IsUnitePages() const
{ {
@ -256,17 +268,29 @@ void VLayoutGenerator::SetRotate(bool value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VLayoutGenerator::GetPaperWidth() const qreal VLayoutGenerator::GetPaperWidth() const
{ {
return paperWidth; return paperWidth;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetPaperWidth(int value) void VLayoutGenerator::SetPaperWidth(qreal value)
{ {
paperWidth = value; paperWidth = value;
} }
//---------------------------------------------------------------------------------------------------------------------
QMarginsF VLayoutGenerator::GetFields() const
{
return margins;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetFields(const QMarginsF &value)
{
margins = value;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
quint32 VLayoutGenerator::GetShift() const quint32 VLayoutGenerator::GetShift() const
{ {
@ -280,13 +304,13 @@ void VLayoutGenerator::SetShift(quint32 shift)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VLayoutGenerator::GetPaperHeight() const qreal VLayoutGenerator::GetPaperHeight() const
{ {
return paperHeight; return paperHeight;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetPaperHeight(int value) void VLayoutGenerator::SetPaperHeight(qreal value)
{ {
paperHeight = value; paperHeight = value;
} }

View File

@ -34,6 +34,7 @@
#include "vlayoutdef.h" #include "vlayoutdef.h"
#include "vbank.h" #include "vbank.h"
#include "../vmisc/vmargins.h"
#include <memory> #include <memory>
class VLayoutPaper; class VLayoutPaper;
@ -52,11 +53,14 @@ public:
void SetCaseType(Cases caseType); void SetCaseType(Cases caseType);
int DetailsCount(); int DetailsCount();
int GetPaperHeight() const; qreal GetPaperHeight() const;
void SetPaperHeight(int value); void SetPaperHeight(qreal value);
int GetPaperWidth() const; qreal GetPaperWidth() const;
void SetPaperWidth(int value); void SetPaperWidth(qreal value);
QMarginsF GetFields() const;
void SetFields(const QMarginsF &value);
quint32 GetShift() const; quint32 GetShift() const;
void SetShift(quint32 shift); void SetShift(quint32 shift);
@ -96,8 +100,9 @@ private:
Q_DISABLE_COPY(VLayoutGenerator) Q_DISABLE_COPY(VLayoutGenerator)
QVector<VLayoutPaper> papers; QVector<VLayoutPaper> papers;
VBank *bank; VBank *bank;
int paperHeight; qreal paperHeight;
int paperWidth; qreal paperWidth;
QMarginsF margins;
volatile bool stopGeneration; volatile bool stopGeneration;
LayoutErrors state; LayoutErrors state;
quint32 shift; quint32 shift;
@ -106,6 +111,9 @@ private:
bool autoCrop; bool autoCrop;
bool saveLength; bool saveLength;
bool unitePages; bool unitePages;
int PageHeight() const;
int PageWidth() const;
}; };
typedef std::shared_ptr<VLayoutGenerator> VLayoutGeneratorPtr; typedef std::shared_ptr<VLayoutGenerator> VLayoutGeneratorPtr;

View File

@ -244,10 +244,10 @@ QImage VPoster::Borders(int rows, int colomns, int i, int j, QImage &image, int
QRect VPoster::PageRect() const QRect VPoster::PageRect() const
{ {
// Because the Point unit is defined to be 1/72th of an inch // Because the Point unit is defined to be 1/72th of an inch
// we can't use method pageRect(QPrinter::Point). Our dpi different can be different. // we can't use method pageRect(QPrinter::Point). Our dpi value can be different.
// We convert value yourself to pixels. // We convert value yourself to pixels.
const QRectF rect = printer->pageRect(QPrinter::Millimeter); const QRectF rect = printer->pageRect(QPrinter::Millimeter);
QRect pageRect(qFloor(ToPixel(rect.x())), qFloor(ToPixel(rect.y())), qFloor(ToPixel(rect.width())), const QRect pageRect(qFloor(ToPixel(rect.x())), qFloor(ToPixel(rect.y())), qFloor(ToPixel(rect.width())),
qFloor(ToPixel(rect.height()))); qFloor(ToPixel(rect.height())));
return pageRect; return pageRect;
} }

View File

@ -0,0 +1,374 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qmarginsf.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
#include <QDataStream>
#include <QDebug>
/*!
\class QMarginsF
\inmodule QtCore
\ingroup painting
\since 5.3
\brief The QMarginsF class defines the four margins of a rectangle.
QMarginsF defines a set of four margins; left, top, right and bottom,
that describe the size of the borders surrounding a rectangle.
The isNull() function returns \c true only if all margins are set to zero.
QMarginsF objects can be streamed as well as compared.
*/
/*****************************************************************************
QMarginsF member functions
*****************************************************************************/
/*!
\fn QMarginsF::QMarginsF()
Constructs a margins object with all margins set to 0.
\sa isNull()
*/
/*!
\fn QMarginsF::QMarginsF(qreal left, qreal top, qreal right, qreal bottom)
Constructs margins with the given \a left, \a top, \a right, \a bottom
\sa setLeft(), setRight(), setTop(), setBottom()
*/
/*!
\fn QMarginsF::QMarginsF(const QMargins &margins)
Constructs margins copied from the given \a margins
*/
/*!
\fn bool QMarginsF::isNull() const
Returns \c true if all margins are 0; otherwise returns
false.
*/
/*!
\fn qreal QMarginsF::left() const
Returns the left margin.
\sa setLeft()
*/
/*!
\fn qreal QMarginsF::top() const
Returns the top margin.
\sa setTop()
*/
/*!
\fn qreal QMarginsF::right() const
Returns the right margin.
*/
/*!
\fn qreal QMarginsF::bottom() const
Returns the bottom margin.
*/
/*!
\fn void QMarginsF::setLeft(qreal left)
Sets the left margin to \a left.
*/
/*!
\fn void QMarginsF::setTop(qreal Top)
Sets the Top margin to \a Top.
*/
/*!
\fn void QMarginsF::setRight(qreal right)
Sets the right margin to \a right.
*/
/*!
\fn void QMarginsF::setBottom(qreal bottom)
Sets the bottom margin to \a bottom.
*/
/*!
\fn bool operator==(const QMarginsF &lhs, const QMarginsF &rhs)
\relates QMarginsF
Returns \c true if \a lhs and \a rhs are equal; otherwise returns \c false.
*/
/*!
\fn bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs)
\relates QMarginsF
Returns \c true if \a lhs and \a rhs are different; otherwise returns \c false.
*/
/*!
\fn const QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs)
\relates QMarginsF
Returns a QMarginsF object that is the sum of the given margins, \a lhs
and \a rhs; each component is added separately.
\sa QMarginsF::operator+=(), QMarginsF::operator-=()
*/
/*!
\fn const QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs)
\relates QMarginsF
Returns a QMarginsF object that is formed by subtracting \a rhs from
\a lhs; each component is subtracted separately.
\sa QMarginsF::operator+=(), QMarginsF::operator-=()
*/
/*!
\fn const QMarginsF operator+(const QMarginsF &lhs, qreal rhs)
\relates QMarginsF
Returns a QMarginsF object that is formed by adding \a rhs to
\a lhs.
\sa QMarginsF::operator+=(), QMarginsF::operator-=()
*/
/*!
\fn const QMarginsF operator+(qreal lhs, const QMarginsF &rhs)
\relates QMarginsF
Returns a QMarginsF object that is formed by adding \a lhs to
\a rhs.
\sa QMarginsF::operator+=(), QMarginsF::operator-=()
*/
/*!
\fn const QMarginsF operator-(const QMarginsF &lhs, qreal rhs)
\relates QMarginsF
Returns a QMarginsF object that is formed by subtracting \a rhs from
\a lhs.
\sa QMarginsF::operator+=(), QMarginsF::operator-=()
*/
/*!
\fn const QMarginsF operator*(const QMarginsF &lhs, qreal rhs)
\relates QMarginsF
\overload
Returns a QMarginsF object that is formed by multiplying each component
of the given \a lhs margins by \a rhs factor.
\sa QMarginsF::operator*=(), QMarginsF::operator/=()
*/
/*!
\fn const QMarginsF operator*(qreal lhs, const QMarginsF &rhs)
\relates QMarginsF
\overload
Returns a QMarginsF object that is formed by multiplying each component
of the given \a lhs margins by \a rhs factor.
\sa QMarginsF::operator*=(), QMarginsF::operator/=()
*/
/*!
\fn const QMarginsF operator/(const QMarginsF &lhs, qreal rhs)
\relates QMarginsF
\overload
Returns a QMarginsF object that is formed by dividing the components of
the given \a lhs margins by the given \a rhs divisor.
\sa QMarginsF::operator*=(), QMarginsF::operator/=()
*/
/*!
\fn QMarginsF operator+(const QMarginsF &margins)
\relates QMarginsF
Returns a QMargin object that is formed from all components of \a margins.
*/
/*!
\fn QMarginsF operator-(const QMarginsF &margins)
\relates QMarginsF
Returns a QMargin object that is formed by negating all components of \a margins.
*/
/*!
\fn QMarginsF &QMarginsF::operator+=(const QMarginsF &margins)
Add each component of \a margins to the respective component of this object
and returns a reference to it.
\sa operator-=()
*/
/*!
\fn QMarginsF &QMarginsF::operator-=(const QMarginsF &margins)
Subtract each component of \a margins from the respective component of this object
and returns a reference to it.
\sa operator+=()
*/
/*!
\fn QMarginsF &QMarginsF::operator+=(qreal addend)
\overload
Adds the \a addend to each component of this object
and returns a reference to it.
\sa operator-=()
*/
/*!
\fn QMarginsF &QMarginsF::operator-=(qreal subtrahend)
\overload
Subtracts the \a subtrahend from each component of this object
and returns a reference to it.
\sa operator+=()
*/
/*!
\fn QMarginsF &QMarginsF::operator*=(qreal factor)
Multiplies each component of this object by \a factor
and returns a reference to it.
\sa operator/=()
*/
/*!
\fn QMarginsF &QMarginsF::operator/=(qreal divisor)
Divides each component of this object by \a divisor
and returns a reference to it.
\sa operator*=()
*/
/*!
\fn QMargins QMarginsF::toMargins() const
Returns an integer based copy of this margins object.
Note that the components in the returned margins will be rounded to
the nearest integer.
\sa QMarginsF()
*/
/*****************************************************************************
QMarginsF stream functions
*****************************************************************************/
#ifndef QT_NO_DATASTREAM
/*!
\fn QDataStream &operator<<(QDataStream &stream, const QMarginsF &m)
\relates QMarginsF
Writes margin \a m to the given \a stream and returns a
reference to the stream.
\sa {Serializing Qt Data Types}
*/
QDataStream &operator<<(QDataStream &s, const QMarginsF &m)
{
s << double(m.left()) << double(m.top()) << double(m.right()) << double(m.bottom());
return s;
}
/*!
\fn QDataStream &operator>>(QDataStream &stream, QMarginsF &m)
\relates QMarginsF
Reads a margin from the given \a stream into margin \a m
and returns a reference to the stream.
\sa {Serializing Qt Data Types}
*/
QDataStream &operator>>(QDataStream &s, QMarginsF &m)
{
double left, top, right, bottom;
s >> left;
s >> top;
s >> right;
s >> bottom;
m = QMarginsF(qreal(left), qreal(top), qreal(right), qreal(bottom));
return s;
}
#endif // QT_NO_DATASTREAM
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QMarginsF &m)
{
QDebugStateSaver saver(dbg);
dbg.nospace();
dbg << "QMarginsF" << '(';
dbg << m.left() << ", " << m.top() << ", " << m.right() << ", " << m.bottom();
dbg << ')';
return dbg;
}
#endif
#endif // QT_VERSION < QT_VERSION_CHECK(5, 3, 0)

View File

@ -0,0 +1,251 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QMARGINSF_H
#define QMARGINSF_H
#include <QtGlobal>
#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
#include <QMargins>
/*****************************************************************************
QMarginsF class
*****************************************************************************/
class QMarginsF
{
public:
Q_DECL_CONSTEXPR QMarginsF() Q_DECL_NOTHROW;
Q_DECL_CONSTEXPR QMarginsF(qreal left, qreal top, qreal right, qreal bottom) Q_DECL_NOTHROW;
Q_DECL_CONSTEXPR QMarginsF(const QMargins &margins) Q_DECL_NOTHROW;
Q_DECL_CONSTEXPR bool isNull() const Q_DECL_NOTHROW;
Q_DECL_CONSTEXPR qreal left() const Q_DECL_NOTHROW;
Q_DECL_CONSTEXPR qreal top() const Q_DECL_NOTHROW;
Q_DECL_CONSTEXPR qreal right() const Q_DECL_NOTHROW;
Q_DECL_CONSTEXPR qreal bottom() const Q_DECL_NOTHROW;
void setLeft(qreal left) Q_DECL_NOTHROW;
void setTop(qreal top) Q_DECL_NOTHROW;
void setRight(qreal right) Q_DECL_NOTHROW;
void setBottom(qreal bottom) Q_DECL_NOTHROW;
QMarginsF &operator+=(const QMarginsF &margins) Q_DECL_NOTHROW;
QMarginsF &operator-=(const QMarginsF &margins) Q_DECL_NOTHROW;
QMarginsF &operator+=(qreal addend) Q_DECL_NOTHROW;
QMarginsF &operator-=(qreal subtrahend) Q_DECL_NOTHROW;
QMarginsF &operator*=(qreal factor) Q_DECL_NOTHROW;
QMarginsF &operator/=(qreal divisor);
Q_DECL_CONSTEXPR inline QMargins toMargins() const Q_DECL_NOTHROW;
private:
qreal m_left;
qreal m_top;
qreal m_right;
qreal m_bottom;
};
Q_DECLARE_TYPEINFO(QMarginsF, Q_MOVABLE_TYPE);
/*****************************************************************************
QMarginsF stream functions
*****************************************************************************/
#ifndef QT_NO_DATASTREAM
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QMarginsF &);
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMarginsF &);
#endif
/*****************************************************************************
QMarginsF inline functions
*****************************************************************************/
Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF() Q_DECL_NOTHROW
: m_left(0), m_top(0), m_right(0), m_bottom(0) {}
Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(qreal aleft, qreal atop, qreal aright, qreal abottom) Q_DECL_NOTHROW
: m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {}
Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(const QMargins &margins) Q_DECL_NOTHROW
: m_left(margins.left()), m_top(margins.top()), m_right(margins.right()), m_bottom(margins.bottom()) {}
Q_DECL_CONSTEXPR inline bool QMarginsF::isNull() const Q_DECL_NOTHROW
{ return qFuzzyIsNull(m_left) && qFuzzyIsNull(m_top) && qFuzzyIsNull(m_right) && qFuzzyIsNull(m_bottom); }
Q_DECL_CONSTEXPR inline qreal QMarginsF::left() const Q_DECL_NOTHROW
{ return m_left; }
Q_DECL_CONSTEXPR inline qreal QMarginsF::top() const Q_DECL_NOTHROW
{ return m_top; }
Q_DECL_CONSTEXPR inline qreal QMarginsF::right() const Q_DECL_NOTHROW
{ return m_right; }
Q_DECL_CONSTEXPR inline qreal QMarginsF::bottom() const Q_DECL_NOTHROW
{ return m_bottom; }
inline void QMarginsF::setLeft(qreal aleft) Q_DECL_NOTHROW
{ m_left = aleft; }
inline void QMarginsF::setTop(qreal atop) Q_DECL_NOTHROW
{ m_top = atop; }
inline void QMarginsF::setRight(qreal aright) Q_DECL_NOTHROW
{ m_right = aright; }
inline void QMarginsF::setBottom(qreal abottom) Q_DECL_NOTHROW
{ m_bottom = abottom; }
Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return qFuzzyCompare(lhs.left(), rhs.left())
&& qFuzzyCompare(lhs.top(), rhs.top())
&& qFuzzyCompare(lhs.right(), rhs.right())
&& qFuzzyCompare(lhs.bottom(), rhs.bottom());
}
Q_DECL_CONSTEXPR inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return !operator==(lhs, rhs);
}
Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() + rhs.left(), lhs.top() + rhs.top(),
lhs.right() + rhs.right(), lhs.bottom() + rhs.bottom());
}
Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() - rhs.left(), lhs.top() - rhs.top(),
lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom());
}
Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() + rhs, lhs.top() + rhs,
lhs.right() + rhs, lhs.bottom() + rhs);
}
Q_DECL_CONSTEXPR inline QMarginsF operator+(qreal lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QMarginsF(rhs.left() + lhs, rhs.top() + lhs,
rhs.right() + lhs, rhs.bottom() + lhs);
}
Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() - rhs, lhs.top() - rhs,
lhs.right() - rhs, lhs.bottom() - rhs);
}
Q_DECL_CONSTEXPR inline QMarginsF operator*(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() * rhs, lhs.top() * rhs,
lhs.right() * rhs, lhs.bottom() * rhs);
}
Q_DECL_CONSTEXPR inline QMarginsF operator*(qreal lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QMarginsF(rhs.left() * lhs, rhs.top() * lhs,
rhs.right() * lhs, rhs.bottom() * lhs);
}
Q_DECL_CONSTEXPR inline QMarginsF operator/(const QMarginsF &lhs, qreal divisor)
{
return QMarginsF(lhs.left() / divisor, lhs.top() / divisor,
lhs.right() / divisor, lhs.bottom() / divisor);
}
inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins) Q_DECL_NOTHROW
{
return *this = *this + margins;
}
inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins) Q_DECL_NOTHROW
{
return *this = *this - margins;
}
inline QMarginsF &QMarginsF::operator+=(qreal addend) Q_DECL_NOTHROW
{
m_left += addend;
m_top += addend;
m_right += addend;
m_bottom += addend;
return *this;
}
inline QMarginsF &QMarginsF::operator-=(qreal subtrahend) Q_DECL_NOTHROW
{
m_left -= subtrahend;
m_top -= subtrahend;
m_right -= subtrahend;
m_bottom -= subtrahend;
return *this;
}
inline QMarginsF &QMarginsF::operator*=(qreal factor) Q_DECL_NOTHROW
{
return *this = *this * factor;
}
inline QMarginsF &QMarginsF::operator/=(qreal divisor)
{
return *this = *this / divisor;
}
Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &margins) Q_DECL_NOTHROW
{
return margins;
}
Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &margins) Q_DECL_NOTHROW
{
return QMarginsF(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
}
Q_DECL_CONSTEXPR inline QMargins QMarginsF::toMargins() const Q_DECL_NOTHROW
{
return QMargins(qRound(m_left), qRound(m_top), qRound(m_right), qRound(m_bottom));
}
#ifndef QT_NO_DEBUG_STREAM
Q_CORE_EXPORT QDebug operator<<(QDebug, const QMarginsF &);
#endif
#endif // QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
#endif // QMARGINSF_H

View File

@ -32,6 +32,7 @@
#include <QComboBox> #include <QComboBox>
#include <QDir> #include <QDir>
#include <QPrinterInfo>
// Keep synchronize all names with initialization in VTranslateVars class!!!!! // Keep synchronize all names with initialization in VTranslateVars class!!!!!
//measurements //measurements
@ -1719,3 +1720,26 @@ QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath)
return QString();// should never reach return QString();// should never reach
} }
//---------------------------------------------------------------------------------------------------------------------
QSharedPointer<QPrinter> DefaultPrinter()
{
QPrinterInfo def = QPrinterInfo::defaultPrinter();
//if there is no default printer set the print preview won't show
if(def.isNull() || def.printerName().isEmpty())
{
if(QPrinterInfo::availablePrinters().isEmpty())
{
return QSharedPointer<QPrinter>();
}
else
{
def = QPrinterInfo::availablePrinters().first();
}
}
QSharedPointer<QPrinter> printer = QSharedPointer<QPrinter>(new QPrinter(def, QPrinter::ScreenResolution));
printer->setResolution(static_cast<int>(PrintDPI));
return printer;
}

View File

@ -43,6 +43,7 @@
#endif /* Q_CC_MSVC */ #endif /* Q_CC_MSVC */
class QComboBox; class QComboBox;
class QPrinter;
#define SceneSize 50000 #define SceneSize 50000
#define DefPointRadius 1.5//mm #define DefPointRadius 1.5//mm
@ -591,4 +592,6 @@ QString StrippedName(const QString &fullFileName);
QString RelativeMPath(const QString &patternPath, const QString &absoluteMPath); QString RelativeMPath(const QString &patternPath, const QString &absoluteMPath);
QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath); QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath);
QSharedPointer<QPrinter> DefaultPrinter();
#endif // DEF_H #endif // DEF_H

43
src/libs/vmisc/vmargins.h Normal file
View File

@ -0,0 +1,43 @@
/************************************************************************
**
** @file vmargins.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 7 11, 2015
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2015 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VMARGINS_H
#define VMARGINS_H
#include <QtGlobal>
#include <QMetaType>
#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
# include "backport/qmarginsf.h"
#else
# include <QMargins>
#endif
Q_DECLARE_METATYPE(QMarginsF)
#endif // VMARGINS_H

View File

@ -10,7 +10,8 @@ SOURCES += \
$$PWD/vabstractapplication.cpp \ $$PWD/vabstractapplication.cpp \
$$PWD/projectversion.cpp \ $$PWD/projectversion.cpp \
$$PWD/vcommonsettings.cpp \ $$PWD/vcommonsettings.cpp \
$$PWD/vtapesettings.cpp $$PWD/vtapesettings.cpp \
$$PWD/backport/qmarginsf.cpp
win32-msvc*:SOURCES += $$PWD/stable.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp
@ -29,4 +30,6 @@ HEADERS += \
$$PWD/vtapesettings.h \ $$PWD/vtapesettings.h \
$$PWD/debugbreak.h \ $$PWD/debugbreak.h \
$$PWD/vlockguard.h \ $$PWD/vlockguard.h \
$$PWD/vsysexits.h $$PWD/vsysexits.h \
$$PWD/backport/qmarginsf.h \
$$PWD/vmargins.h

View File

@ -7,7 +7,7 @@
# File with common stuff for whole project # File with common stuff for whole project
include(../../../common.pri) include(../../../common.pri)
QT += widgets QT += widgets printsupport
# Name of library # Name of library
TARGET = vmisc TARGET = vmisc

View File

@ -32,6 +32,8 @@
#include <QDebug> #include <QDebug>
#include <QLocale> #include <QLocale>
#include <QApplication> #include <QApplication>
#include <QPrinter>
#include <QSharedPointer>
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
@ -69,12 +71,16 @@ const QString VSettings::SettingLayoutRotationIncrease = QStringLitera
const QString VSettings::SettingLayoutAutoCrop = QStringLiteral("layout/autoCrop"); const QString VSettings::SettingLayoutAutoCrop = QStringLiteral("layout/autoCrop");
const QString VSettings::SettingLayoutSaveLength = QStringLiteral("layout/saveLength"); const QString VSettings::SettingLayoutSaveLength = QStringLiteral("layout/saveLength");
const QString VSettings::SettingLayoutUnitePages = QStringLiteral("layout/unitePages"); const QString VSettings::SettingLayoutUnitePages = QStringLiteral("layout/unitePages");
const QString VSettings::SettingFields = QStringLiteral("layout/fields");
const QString VSettings::SettingIgnoreFields = QStringLiteral("layout/ignoreFields");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VSettings::VSettings(Format format, Scope scope, const QString &organization, const QString &application, VSettings::VSettings(Format format, Scope scope, const QString &organization, const QString &application,
QObject *parent) QObject *parent)
:VCommonSettings(format, scope, organization, application, parent) :VCommonSettings(format, scope, organization, application, parent)
{} {
qRegisterMetaTypeStreamOperators<QMarginsF>("QMarginsF");
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VSettings::GetLabelLanguage() const QString VSettings::GetLabelLanguage() const
@ -350,6 +356,49 @@ void VSettings::SetLayoutWidth(qreal value)
setValue(SettingLayoutWidth, value); setValue(SettingLayoutWidth, value);
} }
//---------------------------------------------------------------------------------------------------------------------
QMarginsF VSettings::GetFields() const
{
const QMarginsF def = GetDefFields();
const QVariant val = value(SettingFields, QVariant::fromValue(def));
if (val.canConvert<QMarginsF>())
{
return val.value<QMarginsF>();
}
return def;
}
//---------------------------------------------------------------------------------------------------------------------
QMarginsF VSettings::GetDefFields()
{
QSharedPointer<QPrinter> printer = DefaultPrinter();
if (printer.isNull())
{
return QMarginsF();
}
qreal left = 0;
qreal top = 0;
qreal right = 0;
qreal bottom = 0;
printer->getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
// We can't use Unit::Px because our dpi in most cases is different
QMarginsF def;
def.setLeft(UnitConvertor(left, Unit::Mm, Unit::Px));
def.setRight(UnitConvertor(right, Unit::Mm, Unit::Px));
def.setTop(UnitConvertor(top, Unit::Mm, Unit::Px));
def.setBottom(UnitConvertor(bottom, Unit::Mm, Unit::Px));
return def;
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetFields(const QMarginsF &value)
{
QVariant val = QVariant::fromValue(value);
QString str = val.toString();
setValue(SettingFields, val);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
Cases VSettings::GetLayoutGroup() const Cases VSettings::GetLayoutGroup() const
{ {
@ -441,7 +490,13 @@ void VSettings::SetLayoutRotationIncrease(int value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetLayoutAutoCrop() const bool VSettings::GetLayoutAutoCrop() const
{ {
return value(SettingLayoutAutoCrop, false).toBool(); return value(SettingLayoutAutoCrop, GetDefLayoutAutoCrop()).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetDefLayoutAutoCrop()
{
return false;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -453,7 +508,13 @@ void VSettings::SetLayoutAutoCrop(bool value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetLayoutSaveLength() const bool VSettings::GetLayoutSaveLength() const
{ {
return value(SettingLayoutSaveLength, false).toBool(); return value(SettingLayoutSaveLength, GetDefLayoutSaveLength()).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetDefLayoutSaveLength()
{
return false;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -465,7 +526,13 @@ void VSettings::SetLayoutSaveLength(bool value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetLayoutUnitePages() const bool VSettings::GetLayoutUnitePages() const
{ {
return value(SettingLayoutUnitePages, false).toBool(); return value(SettingLayoutUnitePages, GetDefLayoutUnitePages()).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetDefLayoutUnitePages()
{
return false;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -474,6 +541,24 @@ void VSettings::SetLayoutUnitePages(bool value)
setValue(SettingLayoutUnitePages, value); setValue(SettingLayoutUnitePages, value);
} }
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetIgnoreAllFields() const
{
return value(SettingIgnoreFields, GetDefIgnoreAllFields()).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetDefIgnoreAllFields()
{
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetIgnoreAllFields(bool value)
{
setValue(SettingIgnoreFields, value);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VSettings::StandardTablesPath() const QString VSettings::StandardTablesPath() const
{ {

View File

@ -32,6 +32,8 @@
#include "vcommonsettings.h" #include "vcommonsettings.h"
#include "../vlayout/vbank.h" #include "../vlayout/vbank.h"
#include "../vmisc/vmargins.h"
class VSettings : public VCommonSettings class VSettings : public VCommonSettings
{ {
Q_OBJECT Q_OBJECT
@ -83,6 +85,7 @@ public:
QString GetUserPassword() const; QString GetUserPassword() const;
void SetUserPassword(const QString &value); void SetUserPassword(const QString &value);
// Layout settings
qreal GetLayoutPaperHeight() const; qreal GetLayoutPaperHeight() const;
void SetLayoutPaperHeight(qreal value); void SetLayoutPaperHeight(qreal value);
@ -97,6 +100,10 @@ public:
static qreal GetDefLayoutWidth(); static qreal GetDefLayoutWidth();
void SetLayoutWidth(qreal value); void SetLayoutWidth(qreal value);
QMarginsF GetFields() const;
static QMarginsF GetDefFields();
void SetFields(const QMarginsF &value);
Cases GetLayoutGroup() const; Cases GetLayoutGroup() const;
static Cases GetDefLayoutGroup(); static Cases GetDefLayoutGroup();
void SetLayoutGroup(const Cases &value); void SetLayoutGroup(const Cases &value);
@ -110,14 +117,21 @@ public:
void SetLayoutRotationIncrease(int value); void SetLayoutRotationIncrease(int value);
bool GetLayoutAutoCrop() const; bool GetLayoutAutoCrop() const;
static bool GetDefLayoutAutoCrop();
void SetLayoutAutoCrop(bool value); void SetLayoutAutoCrop(bool value);
bool GetLayoutSaveLength() const; bool GetLayoutSaveLength() const;
static bool GetDefLayoutSaveLength();
void SetLayoutSaveLength(bool value); void SetLayoutSaveLength(bool value);
bool GetLayoutUnitePages() const; bool GetLayoutUnitePages() const;
static bool GetDefLayoutUnitePages();
void SetLayoutUnitePages(bool value); void SetLayoutUnitePages(bool value);
bool GetIgnoreAllFields() const;
static bool GetDefIgnoreAllFields();
void SetIgnoreAllFields(bool value);
private: private:
Q_DISABLE_COPY(VSettings) Q_DISABLE_COPY(VSettings)
static const QString SettingConfigurationLabelLanguage; static const QString SettingConfigurationLabelLanguage;
@ -148,6 +162,8 @@ private:
static const QString SettingLayoutAutoCrop; static const QString SettingLayoutAutoCrop;
static const QString SettingLayoutSaveLength; static const QString SettingLayoutSaveLength;
static const QString SettingLayoutUnitePages; static const QString SettingLayoutUnitePages;
static const QString SettingFields;
static const QString SettingIgnoreFields;
}; };
#endif // VSETTINGS_H #endif // VSETTINGS_H