File indexing completed on 2024-05-19 15:27:50

0001 /* This file is part of KGraphViewer.
0002    Copyright (C) 2005-2006 Gaël de Chalendar <kleag@free.fr>
0003 
0004    KGraphViewer is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License as published by the Free Software Foundation, version 2.
0007 
0008    This program is distributed in the hope that it will be useful,
0009    but WITHOUT ANY WARRANTY; without even the implied warranty of
0010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0011    General Public License for more details.
0012 
0013    You should have received a copy of the GNU General Public License
0014    along with this program; if not, write to the Free Software
0015    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0016    02110-1301, USA
0017 */
0018 
0019 /* This file was part of the KDE project
0020    Copyright (C) 2005 Jarosław Staniek <staniek@kde.org>
0021 
0022    This program is free software; you can redistribute it and/or
0023    modify it under the terms of the GNU Library General Public
0024    License as published by the Free Software Foundation; either
0025    version 2 of the License, or (at your option) any later version.
0026  */
0027 
0028 #ifndef KGVPAGELAYOUT_H
0029 #define KGVPAGELAYOUT_H
0030 
0031 // #include <KgvGenStyles.h>
0032 #include <QStringList>
0033 
0034 /**
0035  * @brief Represents the paper format a document shall be printed on.
0036  *
0037  * For compatibility reasons, and because of screen and custom,
0038  * this enum doesn't map to QPageSize::PageSizeId but KgvPageFormat::printerPageSize
0039  * does the conversion.
0040  *
0041  * @todo convert DIN to ISO in the names
0042  */
0043 enum KgvFormat {
0044     PG_DIN_A3 = 0,
0045     PG_DIN_A4 = 1,
0046     PG_DIN_A5 = 2,
0047     PG_US_LETTER = 3,
0048     PG_US_LEGAL = 4,
0049     PG_SCREEN = 5,
0050     PG_CUSTOM = 6,
0051     PG_DIN_B5 = 7,
0052     PG_US_EXECUTIVE = 8,
0053     PG_DIN_A0 = 9,
0054     PG_DIN_A1 = 10,
0055     PG_DIN_A2 = 11,
0056     PG_DIN_A6 = 12,
0057     PG_DIN_A7 = 13,
0058     PG_DIN_A8 = 14,
0059     PG_DIN_A9 = 15,
0060     PG_DIN_B0 = 16,
0061     PG_DIN_B1 = 17,
0062     PG_DIN_B10 = 18,
0063     PG_DIN_B2 = 19,
0064     PG_DIN_B3 = 20,
0065     PG_DIN_B4 = 21,
0066     PG_DIN_B6 = 22,
0067     PG_ISO_C5 = 23,
0068     PG_US_COMM10 = 24,
0069     PG_ISO_DL = 25,
0070     PG_US_FOLIO = 26,
0071     PG_US_LEDGER = 27,
0072     PG_US_TABLOID = 28,
0073     // update the number below and the static arrays if you add more values to the enum
0074     PG_LAST_FORMAT = PG_US_TABLOID // used by koPageLayout.cpp
0075 };
0076 
0077 /**
0078  *  Represents the orientation of a printed document.
0079  */
0080 enum KgvOrientation { PG_PORTRAIT = 0, PG_LANDSCAPE = 1 };
0081 
0082 namespace KgvPageFormat
0083 {
0084 /**
0085  * @brief Convert a KgvFormat into a QPageSize::PageSizeId.
0086  *
0087  * If format is 'screen' it will use A4 landscape.
0088  * If format is 'custom' it will use A4 portrait.
0089  * (you may want to take care of those cases separately).
0090  * Usually passed to QPrinter::setPageSize().
0091  *
0092  * @note We return int instead of the enum to avoid including QPageSize
0093  */
0094 int /*QPageSize::PageSizeId*/ printerPageSize(KgvFormat format);
0095 
0096 /**
0097  * Returns the width (in mm) for a given page format and orientation
0098  * 'Custom' isn't supported by this function, obviously.
0099  */
0100 double width(KgvFormat format, KgvOrientation orientation);
0101 
0102 /**
0103  * Returns the height (in mm) for a given page format and orientation
0104  * 'Custom' isn't supported by this function, obviously.
0105  */
0106 double height(KgvFormat format, KgvOrientation orientation);
0107 
0108 /**
0109  * Returns the internal name of the given page format.
0110  * Use for saving.
0111  */
0112 QString formatString(KgvFormat format);
0113 
0114 /**
0115  * Convert a format string (internal name) to a page format value.
0116  * Use for loading.
0117  */
0118 KgvFormat formatFromString(const QString &string);
0119 
0120 /**
0121  * Returns the default format (based on the KControl settings)
0122  */
0123 KgvFormat defaultFormat();
0124 
0125 /**
0126  * Returns the translated name of the given page format.
0127  * Use for showing the user.
0128  */
0129 QString name(KgvFormat format);
0130 
0131 /**
0132  * Lists the translated names of all the available formats
0133  */
0134 QStringList allFormats();
0135 
0136 /**
0137  * Try to find the paper format for the given width and height (in mm).
0138  * Useful to some import filters.
0139  */
0140 KgvFormat guessFormat(double width, double height);
0141 }
0142 
0143 /**
0144  * @brief Header/Footer type.
0145  *
0146  * @note Yes, this should have been a bitfield, but there was only 0, 2, 3 in koffice-1.0. Don't ask why.
0147  * In the long run this should be replaced with a more flexible repetition/section concept.
0148  */
0149 enum KgvHFType {
0150     HF_SAME = 0,          ///< 0: Header/Footer is the same on all pages
0151     HF_FIRST_EO_DIFF = 1, ///< 1: Header/Footer is different on first, even and odd pages (2&3)
0152     HF_FIRST_DIFF = 2,    ///< 2: Header/Footer for the first page differs
0153     HF_EO_DIFF = 3        ///< 3: Header/Footer for even - odd pages are different
0154 };
0155 
0156 /**
0157  * This structure defines the page layout, including
0158  * its size in pt, its format (e.g. A4), orientation, unit, margins etc.
0159  */
0160 struct KgvPageLayout {
0161     /** Page format */
0162     KgvFormat format;
0163     /** Page orientation */
0164     KgvOrientation orientation;
0165 
0166     /** Page width in pt */
0167     double ptWidth;
0168     /** Page height in pt */
0169     double ptHeight;
0170     /** Left margin in pt */
0171     double ptLeft;
0172     /** Right margin in pt */
0173     double ptRight;
0174     /** Top margin in pt */
0175     double ptTop;
0176     /** Bottom margin in pt */
0177     double ptBottom;
0178     double ptPageEdge;
0179     double ptBindingSide;
0180 
0181     bool operator==(const KgvPageLayout &l) const
0182     {
0183         return (ptWidth == l.ptWidth && ptHeight == l.ptHeight && ptLeft == l.ptLeft && ptRight == l.ptRight && ptTop == l.ptTop && ptBottom == l.ptBottom && ptPageEdge == l.ptPageEdge && ptBindingSide == l.ptBindingSide);
0184     }
0185     bool operator!=(const KgvPageLayout &l) const
0186     {
0187         return !((*this) == l);
0188     }
0189 
0190     /**
0191      * @return a page layout with the default page size depending on the locale settings,
0192      * default margins (2 cm), and portrait orientation.
0193      * @since 1.4
0194      */
0195     static KgvPageLayout standardLayout();
0196 };
0197 
0198 /** structure for header-footer */
0199 struct KgvHeadFoot {
0200     QString headLeft;
0201     QString headMid;
0202     QString headRight;
0203     QString footLeft;
0204     QString footMid;
0205     QString footRight;
0206 };
0207 
0208 /** structure for columns */
0209 struct KgvColumns {
0210     int columns;
0211     double ptColumnSpacing;
0212     bool operator==(const KgvColumns &rhs) const
0213     {
0214         return columns == rhs.columns && qAbs(ptColumnSpacing - rhs.ptColumnSpacing) <= 1E-10;
0215     }
0216     bool operator!=(const KgvColumns &rhs) const
0217     {
0218         return columns != rhs.columns || qAbs(ptColumnSpacing - rhs.ptColumnSpacing) > 1E-10;
0219     }
0220 };
0221 
0222 /** structure for KWord header-footer */
0223 struct KgvKWHeaderFooter {
0224     KgvHFType header;
0225     KgvHFType footer;
0226     double ptHeaderBodySpacing;
0227     double ptFooterBodySpacing;
0228     double ptFootNoteBodySpacing;
0229     bool operator==(const KgvKWHeaderFooter &rhs) const
0230     {
0231         return header == rhs.header && footer == rhs.footer && qAbs(ptHeaderBodySpacing - rhs.ptHeaderBodySpacing) <= 1E-10 && qAbs(ptFooterBodySpacing - rhs.ptFooterBodySpacing) <= 1E-10 &&
0232             qAbs(ptFootNoteBodySpacing - rhs.ptFootNoteBodySpacing) <= 1E-10;
0233     }
0234     bool operator!=(const KgvKWHeaderFooter &rhs) const
0235     {
0236         return !(*this == rhs);
0237     }
0238 };
0239 
0240 #endif /* KOPAGELAYOUT_H */