Commit 1de97322 authored by Albert Astals Cid's avatar Albert Astals Cid

Bring QPageSize from Qt5

Allows us to not use a dummy printer for knowing page size
Which is nice since it won't block because Qt4 QPrinter is a bit weird sometimes

BUGS: 334708
FIXED-IN: KDE Applications 15.08
parent 1da3c424
......@@ -45,6 +45,7 @@ endif(NOT WIN32)
# okularcore
set(okularcore_SRCS
core/qpagesize.cpp # REMOVE On Qt5 port
core/action.cpp
core/annotations.cpp
core/area.cpp
......
......@@ -86,6 +86,7 @@
#include "view_p.h"
#include "form.h"
#include "utils.h"
#include "qpagesize.h" // TODO Convert to <> in Qt5
#include <memory>
......@@ -170,88 +171,87 @@ QString DocumentPrivate::namePaperSize(double inchesWidth, double inchesHeight)
if (inchesWidth > inchesHeight)
qSwap(inchesWidth, inchesHeight);
// Use QPrinter to find which of the predefined paper sizes
// Use QPageSize to find which of the predefined paper sizes
// matches best the given paper width and height
QPrinter dummyPrinter;
QPrinter::PaperSize paperSize = QPrinter::Custom;
for (int i = 0; i < (int)QPrinter::NPaperSize; ++i)
QPageSize::PageSizeId paperSize = QPageSize::Custom;
for (int i = 0; i < (int)QPageSize::NPaperSize; ++i)
{
const QPrinter::PaperSize ps = (QPrinter::PaperSize)i;
dummyPrinter.setPaperSize(ps);
const QSizeF definedPaperSize = dummyPrinter.paperSize(QPrinter::Inch);
const QPageSize size((QPageSize::PageSizeId)i);
const QSizeF definedPaperSize = size.size(QPageSize::Inch);
if (inchesWidth > definedPaperSize.width() * lowerBoundFactor && inchesWidth < definedPaperSize.width() * upperBoundFactor
&& inchesHeight > definedPaperSize.height() * lowerBoundFactor && inchesHeight < definedPaperSize.height() * upperBoundFactor)
{
paperSize = ps;
paperSize = (QPageSize::PageSizeId)i;
break;
}
}
// Handle all paper sizes defined in QPrinter,
// Handle all paper sizes defined in QPageSize,
// return string depending if paper's orientation is landscape or portrait
switch (paperSize) {
case QPrinter::A0:
case QPageSize::A0:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO A0") : i18nc("paper size", "portrait DIN/ISO A0");
case QPrinter::A1:
case QPageSize::A1:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO A1") : i18nc("paper size", "portrait DIN/ISO A1");
case QPrinter::A2:
case QPageSize::A2:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO A2") : i18nc("paper size", "portrait DIN/ISO A2");
case QPrinter::A3:
case QPageSize::A3:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO A3") : i18nc("paper size", "portrait DIN/ISO A3");
case QPrinter::A4:
case QPageSize::A4:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO A4") : i18nc("paper size", "portrait DIN/ISO A4");
case QPrinter::A5:
case QPageSize::A5:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO A5") : i18nc("paper size", "portrait DIN/ISO A5");
case QPrinter::A6:
case QPageSize::A6:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO A6") : i18nc("paper size", "portrait DIN/ISO A6");
case QPrinter::A7:
case QPageSize::A7:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO A7") : i18nc("paper size", "portrait DIN/ISO A7");
case QPrinter::A8:
case QPageSize::A8:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO A8") : i18nc("paper size", "portrait DIN/ISO A8");
case QPrinter::A9:
case QPageSize::A9:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO A9") : i18nc("paper size", "portrait DIN/ISO A9");
case QPrinter::B0:
case QPageSize::B0:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO B0") : i18nc("paper size", "portrait DIN/ISO B0");
case QPrinter::B1:
case QPageSize::B1:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO B1") : i18nc("paper size", "portrait DIN/ISO B1");
case QPrinter::B2:
case QPageSize::B2:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO B2") : i18nc("paper size", "portrait DIN/ISO B2");
case QPrinter::B3:
case QPageSize::B3:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO B3") : i18nc("paper size", "portrait DIN/ISO B3");
case QPrinter::B4:
case QPageSize::B4:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO B4") : i18nc("paper size", "portrait DIN/ISO B4");
case QPrinter::B5:
case QPageSize::B5:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO B5") : i18nc("paper size", "portrait DIN/ISO B5");
case QPrinter::B6:
case QPageSize::B6:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO B6") : i18nc("paper size", "portrait DIN/ISO B6");
case QPrinter::B7:
case QPageSize::B7:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO B7") : i18nc("paper size", "portrait DIN/ISO B7");
case QPrinter::B8:
case QPageSize::B8:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO B8") : i18nc("paper size", "portrait DIN/ISO B8");
case QPrinter::B9:
case QPageSize::B9:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO B9") : i18nc("paper size", "portrait DIN/ISO B9");
case QPrinter::B10:
case QPageSize::B10:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DIN/ISO B10") : i18nc("paper size", "portrait DIN/ISO B10");
case QPrinter::Letter:
case QPageSize::Letter:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape letter") : i18nc("paper size", "portrait letter");
case QPrinter::Legal:
case QPageSize::Legal:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape legal") : i18nc("paper size", "portrait legal");
case QPrinter::Executive:
case QPageSize::Executive:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape executive") : i18nc("paper size", "portrait executive");
case QPrinter::C5E:
case QPageSize::C5E:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape C5E") : i18nc("paper size", "portrait C5E");
case QPrinter::Comm10E:
case QPageSize::Comm10E:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape Comm10E") : i18nc("paper size", "portrait Comm10E");
case QPrinter::DLE:
case QPageSize::DLE:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape DLE") : i18nc("paper size", "portrait DLE");
case QPrinter::Folio:
case QPageSize::Folio:
return orientation == QPrinter::Landscape ? i18nc("paper size", "landscape folio") : i18nc("paper size", "portrait folio");
case QPrinter::Tabloid:
case QPrinter::Ledger:
case QPageSize::Tabloid:
case QPageSize::Ledger:
/// Ledger and Tabloid are the same, just rotated by 90 degrees
return orientation == QPrinter::Landscape ? i18nc("paper size", "ledger") : i18nc("paper size", "tabloid");
case QPrinter::Custom:
default: // TODO add new strings on master
case QPageSize::Custom:
return orientation == QPrinter::Landscape ? i18nc("paper size", "unknown landscape paper size") : i18nc("paper size", "unknown portrait paper size");
}
......
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2014 John Layt <jlayt@kde.org>
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtGui 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 QPAGESIZE_H
#define QPAGESIZE_H
#include <QtCore/qsharedpointer.h>
QT_BEGIN_NAMESPACE
#if defined(B0)
#undef B0 // Terminal hang-up. We assume that you do not want that.
#endif
class QPageSizePrivate;
class QString;
class QSize;
class QSizeF;
class QRectF;
class QRect;
class QPageSize
{
public:
// ### Qt6 Re-order and remove duplicates
// NOTE: Must keep in sync with QPagedPrintEngine and QPrinter
enum PageSizeId {
// Existing Qt sizes
A4,
B5,
Letter,
Legal,
Executive,
A0,
A1,
A2,
A3,
A5,
A6,
A7,
A8,
A9,
B0,
B1,
B10,
B2,
B3,
B4,
B6,
B7,
B8,
B9,
C5E,
Comm10E,
DLE,
Folio,
Ledger,
Tabloid,
Custom,
// New values derived from PPD standard
A10,
A3Extra,
A4Extra,
A4Plus,
A4Small,
A5Extra,
B5Extra,
JisB0,
JisB1,
JisB2,
JisB3,
JisB4,
JisB5,
JisB6,
JisB7,
JisB8,
JisB9,
JisB10,
// AnsiA = Letter,
// AnsiB = Ledger,
AnsiC,
AnsiD,
AnsiE,
LegalExtra,
LetterExtra,
LetterPlus,
LetterSmall,
TabloidExtra,
ArchA,
ArchB,
ArchC,
ArchD,
ArchE,
Imperial7x9,
Imperial8x10,
Imperial9x11,
Imperial9x12,
Imperial10x11,
Imperial10x13,
Imperial10x14,
Imperial12x11,
Imperial15x11,
ExecutiveStandard,
Note,
Quarto,
Statement,
SuperA,
SuperB,
Postcard,
DoublePostcard,
Prc16K,
Prc32K,
Prc32KBig,
FanFoldUS,
FanFoldGerman,
FanFoldGermanLegal,
EnvelopeB4,
EnvelopeB5,
EnvelopeB6,
EnvelopeC0,
EnvelopeC1,
EnvelopeC2,
EnvelopeC3,
EnvelopeC4,
// EnvelopeC5 = C5E,
EnvelopeC6,
EnvelopeC65,
EnvelopeC7,
// EnvelopeDL = DLE,
Envelope9,
// Envelope10 = Comm10E,
Envelope11,
Envelope12,
Envelope14,
EnvelopeMonarch,
EnvelopePersonal,
EnvelopeChou3,
EnvelopeChou4,
EnvelopeInvite,
EnvelopeItalian,
EnvelopeKaku2,
EnvelopeKaku3,
EnvelopePrc1,
EnvelopePrc2,
EnvelopePrc3,
EnvelopePrc4,
EnvelopePrc5,
EnvelopePrc6,
EnvelopePrc7,
EnvelopePrc8,
EnvelopePrc9,
EnvelopePrc10,
EnvelopeYou4,
// Last item, with commonly used synynoms from QPagedPrintEngine / QPrinter
LastPageSize = EnvelopeYou4,
NPageSize = LastPageSize,
NPaperSize = LastPageSize,
// Convenience overloads for naming consistency
AnsiA = Letter,
AnsiB = Ledger,
EnvelopeC5 = C5E,
EnvelopeDL = DLE,
Envelope10 = Comm10E
};
// NOTE: Must keep in sync with QPageLayout::Unit and QPrinter::Unit
enum Unit {
Millimeter,
Point,
Inch,
Pica,
Didot,
Cicero
};
enum SizeMatchPolicy {
FuzzyMatch,
FuzzyOrientationMatch,
ExactMatch
};
explicit QPageSize(PageSizeId pageSizeId);
~QPageSize();
bool isValid() const;
QSizeF size(Unit units) const;
private:
friend class QPageSizePrivate;
friend class QPlatformPrintDevice;
QSharedDataPointer<QPageSizePrivate> d;
};
QT_END_NAMESPACE
#endif // QPAGESIZE_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment