Refactoring methods GetMinPrinterFields and GetPrinterFields.
--HG-- branch : develop
This commit is contained in:
parent
593bae3969
commit
9da0b5cab5
|
@ -583,7 +583,7 @@ void DialogLayoutSettings::DialogAccepted()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const QMarginsF minFields = RoundMargins(GetMinPrinterFields());
|
const QMarginsF minFields = RoundMargins(MinPrinterFields());
|
||||||
const QMarginsF fields = RoundMargins(GetFields());
|
const QMarginsF fields = RoundMargins(GetFields());
|
||||||
if (fields.left() < minFields.left() || fields.right() < minFields.right() ||
|
if (fields.left() < minFields.left() || fields.right() < minFields.right() ||
|
||||||
fields.top() < minFields.top() || fields.bottom() < minFields.bottom())
|
fields.top() < minFields.top() || fields.bottom() < minFields.bottom())
|
||||||
|
@ -959,28 +959,13 @@ QMarginsF DialogLayoutSettings::RoundMargins(const QMarginsF &margins) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QMarginsF DialogLayoutSettings::GetMinPrinterFields() const
|
QMarginsF DialogLayoutSettings::MinPrinterFields() const
|
||||||
{
|
{
|
||||||
QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText());
|
QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText());
|
||||||
if (not printer.isNull())
|
if (not printer.isNull())
|
||||||
{
|
{
|
||||||
QSharedPointer<QPrinter> pr = QSharedPointer<QPrinter>(new QPrinter(printer));
|
QSharedPointer<QPrinter> pr = QSharedPointer<QPrinter>(new QPrinter(printer));
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
|
return GetMinPrinterFields(pr);
|
||||||
QPageLayout layout = pr->pageLayout();
|
|
||||||
layout.setUnits(QPageLayout::Millimeter);
|
|
||||||
const QMarginsF minMargins = layout.minimumMargins();
|
|
||||||
|
|
||||||
QMarginsF min;
|
|
||||||
min.setLeft(UnitConvertor(minMargins.left(), Unit::Mm, Unit::Px));
|
|
||||||
min.setRight(UnitConvertor(minMargins.right(), Unit::Mm, Unit::Px));
|
|
||||||
min.setTop(UnitConvertor(minMargins.top(), Unit::Mm, Unit::Px));
|
|
||||||
min.setBottom(UnitConvertor(minMargins.bottom(), Unit::Mm, Unit::Px));
|
|
||||||
return min;
|
|
||||||
#else
|
|
||||||
pr->setFullPage(false);
|
|
||||||
pr->setPageMargins(0, 0, 0, 0, QPrinter::Millimeter);
|
|
||||||
return GetPrinterFields(QSharedPointer<QPrinter>(new QPrinter(printer)));
|
|
||||||
#endif //QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1158,25 +1143,3 @@ void DialogLayoutSettings::SetAdditionalOptions(bool value)
|
||||||
SetUnitePages(value);
|
SetUnitePages(value);
|
||||||
SetStripOptimization(value);
|
SetStripOptimization(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QMarginsF DialogLayoutSettings::GetPrinterFields(const QSharedPointer<QPrinter> &printer)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ private:
|
||||||
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;
|
QMarginsF RoundMargins(const QMarginsF &margins) const;
|
||||||
QMarginsF GetMinPrinterFields() const;
|
QMarginsF MinPrinterFields() const;
|
||||||
QMarginsF GetDefPrinterFields() const;
|
QMarginsF GetDefPrinterFields() const;
|
||||||
|
|
||||||
Unit PaperUnit() const;
|
Unit PaperUnit() const;
|
||||||
|
@ -176,8 +176,6 @@ private:
|
||||||
|
|
||||||
void SheetSize(const QSizeF &size);
|
void SheetSize(const QSizeF &size);
|
||||||
void SetAdditionalOptions(bool value);
|
void SetAdditionalOptions(bool value);
|
||||||
|
|
||||||
static QMarginsF GetPrinterFields(const QSharedPointer<QPrinter> &printer);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DIALOGLAYOUTSETTINGS_H
|
#endif // DIALOGLAYOUTSETTINGS_H
|
||||||
|
|
|
@ -1849,6 +1849,50 @@ QSharedPointer<QPrinter> PreparePrinter(const QPrinterInfo &info, QPrinter::Prin
|
||||||
return printer;
|
return printer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QMarginsF GetMinPrinterFields(const QSharedPointer<QPrinter> &printer)
|
||||||
|
{
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
|
||||||
|
QPageLayout layout = printer->pageLayout();
|
||||||
|
layout.setUnits(QPageLayout::Millimeter);
|
||||||
|
const QMarginsF minMargins = layout.minimumMargins();
|
||||||
|
|
||||||
|
QMarginsF min;
|
||||||
|
min.setLeft(UnitConvertor(minMargins.left(), Unit::Mm, Unit::Px));
|
||||||
|
min.setRight(UnitConvertor(minMargins.right(), Unit::Mm, Unit::Px));
|
||||||
|
min.setTop(UnitConvertor(minMargins.top(), Unit::Mm, Unit::Px));
|
||||||
|
min.setBottom(UnitConvertor(minMargins.bottom(), Unit::Mm, Unit::Px));
|
||||||
|
return min;
|
||||||
|
#else
|
||||||
|
auto tempPrinter = QSharedPointer<QPrinter>(new QPrinter(QPrinterInfo(* printer)));
|
||||||
|
tempPrinter->setFullPage(false);
|
||||||
|
tempPrinter->setPageMargins(0, 0, 0, 0, QPrinter::Millimeter);
|
||||||
|
return GetPrinterFields(tempPrinter);
|
||||||
|
#endif //QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QMarginsF GetPrinterFields(const QSharedPointer<QPrinter> &printer)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QPixmap darkenPixmap(const QPixmap &pixmap)
|
QPixmap darkenPixmap(const QPixmap &pixmap)
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,6 +50,7 @@ template <class T> class QSharedPointer;
|
||||||
#endif /* Q_CC_MSVC */
|
#endif /* Q_CC_MSVC */
|
||||||
|
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
|
class QMarginsF;
|
||||||
|
|
||||||
#define SceneSize 50000
|
#define SceneSize 50000
|
||||||
#define DefPointRadius 1.5//mm
|
#define DefPointRadius 1.5//mm
|
||||||
|
@ -634,6 +635,9 @@ QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath)
|
||||||
QSharedPointer<QPrinter> PreparePrinter(const QPrinterInfo &info,
|
QSharedPointer<QPrinter> PreparePrinter(const QPrinterInfo &info,
|
||||||
QPrinter::PrinterMode mode = QPrinter::ScreenResolution) Q_REQUIRED_RESULT;
|
QPrinter::PrinterMode mode = QPrinter::ScreenResolution) Q_REQUIRED_RESULT;
|
||||||
|
|
||||||
|
QMarginsF GetMinPrinterFields(const QSharedPointer<QPrinter> &printer);
|
||||||
|
QMarginsF GetPrinterFields(const QSharedPointer<QPrinter> &printer);
|
||||||
|
|
||||||
QPixmap darkenPixmap(const QPixmap &pixmap) Q_REQUIRED_RESULT;
|
QPixmap darkenPixmap(const QPixmap &pixmap) Q_REQUIRED_RESULT;
|
||||||
|
|
||||||
void ShowInGraphicalShell(const QString &filePath);
|
void ShowInGraphicalShell(const QString &filePath);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user