home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoPageLayout.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  7.6 KB  |  261 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
  3.    Copyright 2002, 2003 David Faure <faure@kde.org>
  4.    Copyright 2003 Nicolas GOUTTE <goutte@kde.org>
  5.  
  6.    This library is free software; you can redistribute it and/or
  7.    modify it under the terms of the GNU Library General Public
  8.    License as published by the Free Software Foundation; either
  9.    version 2 of the License, or (at your option) any later version.
  10.  
  11.    This library is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.    Library General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU Library General Public License
  17.    along with this library; see the file COPYING.LIB.  If not, write to
  18.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.  * Boston, MA 02110-1301, USA.
  20. */
  21.  
  22. #ifndef KOPAGELAYOUT_H
  23. #define KOPAGELAYOUT_H
  24.  
  25. #include <KoGenStyles.h>
  26. #include <qstringlist.h>
  27. #include <koffice_export.h>
  28. class QDomElement;
  29.  
  30. /**
  31.  * @brief Represents the paper format a document shall be printed on.
  32.  *
  33.  * For compatibility reasons, and because of screen and custom,
  34.  * this enum doesn't map to QPrinter::PageSize but KoPageFormat::printerPageSize
  35.  * does the conversion.
  36.  *
  37.  * @todo convert DIN to ISO in the names
  38.  */
  39. enum KoFormat {
  40.     PG_DIN_A3 = 0,
  41.     PG_DIN_A4 = 1,
  42.     PG_DIN_A5 = 2,
  43.     PG_US_LETTER = 3,
  44.     PG_US_LEGAL = 4,
  45.     PG_SCREEN = 5,
  46.     PG_CUSTOM = 6,
  47.     PG_DIN_B5 = 7,
  48.     PG_US_EXECUTIVE = 8,
  49.     PG_DIN_A0 = 9,
  50.     PG_DIN_A1 = 10,
  51.     PG_DIN_A2 = 11,
  52.     PG_DIN_A6 = 12,
  53.     PG_DIN_A7 = 13,
  54.     PG_DIN_A8 = 14,
  55.     PG_DIN_A9 = 15,
  56.     PG_DIN_B0 = 16,
  57.     PG_DIN_B1 = 17,
  58.     PG_DIN_B10 = 18,
  59.     PG_DIN_B2 = 19,
  60.     PG_DIN_B3 = 20,
  61.     PG_DIN_B4 = 21,
  62.     PG_DIN_B6 = 22,
  63.     PG_ISO_C5 = 23,
  64.     PG_US_COMM10 = 24,
  65.     PG_ISO_DL = 25,
  66.     PG_US_FOLIO = 26,
  67.     PG_US_LEDGER = 27,
  68.     PG_US_TABLOID = 28,
  69.     // update the number below and the static arrays if you add more values to the enum
  70.     PG_LAST_FORMAT = PG_US_TABLOID // used by koPageLayout.cpp
  71. };
  72.  
  73. /**
  74.  *  Represents the orientation of a printed document.
  75.  */
  76. enum KoOrientation {
  77.     PG_PORTRAIT = 0,
  78.     PG_LANDSCAPE = 1
  79. };
  80.  
  81. namespace KoPageFormat
  82. {
  83.     /**
  84.      * @brief Convert a KoFormat into a KPrinter::PageSize.
  85.      *
  86.      * If format is 'screen' it will use A4 landscape.
  87.      * If format is 'custom' it will use A4 portrait.
  88.      * (you may want to take care of those cases separately).
  89.      * Usually passed to KPrinter::setPageSize().
  90.      *
  91.      * @note We return int instead of the enum to avoid including kprinter.h
  92.      */
  93.     KOFFICECORE_EXPORT int /*KPrinter::PageSize*/ printerPageSize( KoFormat format );
  94.  
  95.     /**
  96.      * Returns the width (in mm) for a given page format and orientation
  97.      * 'Custom' isn't supported by this function, obviously.
  98.      */
  99.     KOFFICECORE_EXPORT double width( KoFormat format, KoOrientation orientation );
  100.  
  101.     /**
  102.      * Returns the height (in mm) for a given page format and orientation
  103.      * 'Custom' isn't supported by this function, obviously.
  104.      */
  105.     KOFFICECORE_EXPORT double height( KoFormat format, KoOrientation orientation );
  106.  
  107.     /**
  108.      * Returns the internal name of the given page format.
  109.      * Use for saving.
  110.      */
  111.     KOFFICECORE_EXPORT QString formatString( KoFormat format );
  112.  
  113.     /**
  114.      * Convert a format string (internal name) to a page format value.
  115.      * Use for loading.
  116.      */
  117.     KOFFICECORE_EXPORT KoFormat formatFromString( const QString & string );
  118.  
  119.     /**
  120.      * Returns the default format (based on the KControl settings)
  121.      */
  122.     KOFFICECORE_EXPORT KoFormat defaultFormat();
  123.  
  124.     /**
  125.      * Returns the translated name of the given page format.
  126.      * Use for showing the user.
  127.      */
  128.     KOFFICECORE_EXPORT QString name( KoFormat format );
  129.  
  130.     /**
  131.      * Lists the translated names of all the available formats
  132.      */
  133.     KOFFICECORE_EXPORT QStringList allFormats();
  134.  
  135.     /**
  136.      * Try to find the paper format for the given width and height (in mm).
  137.      * Useful to some import filters.
  138.      */
  139.     KOFFICECORE_EXPORT KoFormat guessFormat( double width, double height );
  140. }
  141.  
  142.  
  143. /**
  144.  * @brief Header/Footer type.
  145.  *
  146.  * @note Yes, this should have been a bitfield, but there was only 0, 2, 3 in koffice-1.0. Don't ask why.
  147.  * In the long run this should be replaced with a more flexible repetition/section concept.
  148.  */
  149. enum KoHFType {
  150.     HF_SAME = 0,            ///< 0: Header/Footer is the same on all pages
  151.     HF_FIRST_EO_DIFF = 1,   ///< 1: Header/Footer is different on first, even and odd pages (2&3)
  152.     HF_FIRST_DIFF = 2,      ///< 2: Header/Footer for the first page differs
  153.     HF_EO_DIFF = 3          ///< 3: Header/Footer for even - odd pages are different
  154. };
  155.  
  156. /**
  157.  * This structure defines the page layout, including
  158.  * its size in pt, its format (e.g. A4), orientation, unit, margins etc.
  159.  */
  160. struct KoPageLayout
  161. {
  162.     /** Page format */
  163.     KoFormat format;
  164.     /** Page orientation */
  165.     KoOrientation orientation;
  166.  
  167.     /** Page width in pt */
  168.     double ptWidth;
  169.     /** Page height in pt */
  170.     double ptHeight;
  171.     /** Left margin in pt */
  172.     double ptLeft;
  173.     /** Right margin in pt */
  174.     double ptRight;
  175.     /** Top margin in pt */
  176.     double ptTop;
  177.     /** Bottom margin in pt */
  178.     double ptBottom;
  179.     double ptPageEdge;
  180.     double ptBindingSide;
  181.  
  182.     bool operator==( const KoPageLayout& l ) const {
  183.        return ( ptWidth == l.ptWidth &&
  184.                 ptHeight == l.ptHeight &&
  185.                 ptLeft == l.ptLeft &&
  186.                 ptRight == l.ptRight &&
  187.                 ptTop == l.ptTop &&
  188.                 ptBottom == l.ptBottom &&
  189.                 ptPageEdge == l.ptPageEdge &&
  190.                 ptBindingSide == l.ptBindingSide);
  191.     }
  192.     bool operator!=( const KoPageLayout& l ) const {
  193.         return !( (*this) == l );
  194.     }
  195.  
  196.     /**
  197.      * Save this page layout to OASIS.
  198.      */
  199.     KOFFICECORE_EXPORT KoGenStyle saveOasis() const;
  200.  
  201.     /**
  202.      * Load this page layout from OASIS
  203.      */
  204.     KOFFICECORE_EXPORT void loadOasis(const QDomElement &style);
  205.  
  206.     /**
  207.      * @return a page layout with the default page size depending on the locale settings,
  208.      * default margins (2 cm), and portrait orientation.
  209.      * @since 1.4
  210.      */
  211.     static KOFFICECORE_EXPORT KoPageLayout standardLayout();
  212. };
  213.  
  214. /** structure for header-footer */
  215. struct KoHeadFoot
  216. {
  217.     QString headLeft;
  218.     QString headMid;
  219.     QString headRight;
  220.     QString footLeft;
  221.     QString footMid;
  222.     QString footRight;
  223. };
  224.  
  225. /** structure for columns */
  226. struct KoColumns
  227. {
  228.     int columns;
  229.     double ptColumnSpacing;
  230.     bool operator==( const KoColumns& rhs ) const {
  231.         return columns == rhs.columns &&
  232.                QABS(ptColumnSpacing - rhs.ptColumnSpacing) <= 1E-10;
  233.     }
  234.     bool operator!=( const KoColumns& rhs ) const {
  235.         return columns != rhs.columns ||
  236.                QABS(ptColumnSpacing - rhs.ptColumnSpacing) > 1E-10;
  237.     }
  238. };
  239.  
  240. /** structure for KWord header-footer */
  241. struct KoKWHeaderFooter
  242. {
  243.     KoHFType header;
  244.     KoHFType footer;
  245.     double ptHeaderBodySpacing;
  246.     double ptFooterBodySpacing;
  247.     double ptFootNoteBodySpacing;
  248.     bool operator==( const KoKWHeaderFooter& rhs ) const {
  249.         return header == rhs.header && footer == rhs.footer &&
  250.                QABS(ptHeaderBodySpacing - rhs.ptHeaderBodySpacing) <= 1E-10 &&
  251.                QABS(ptFooterBodySpacing - rhs.ptFooterBodySpacing) <= 1E-10 &&
  252.                QABS(ptFootNoteBodySpacing - rhs.ptFootNoteBodySpacing) <= 1E-10;
  253.     }
  254.     bool operator!=( const KoKWHeaderFooter& rhs ) const {
  255.         return !( *this == rhs );
  256.     }
  257. };
  258.  
  259. #endif /* KOPAGELAYOUT_H */
  260.  
  261.