File indexing completed on 2024-04-21 04:41:51
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) 0003 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Lesser General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2.1 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Lesser General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Lesser General Public 0016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 #ifndef KREPORTRENDEROBJECTS_H 0019 #define KREPORTRENDEROBJECTS_H 0020 0021 #include <QString> 0022 #include <QList> 0023 #include <QPointF> 0024 #include <QSizeF> 0025 #include <QFont> 0026 #include <QImage> 0027 #include <QPen> 0028 #include <QBrush> 0029 #include <QPicture> 0030 #include <QPageLayout> 0031 0032 #include "KReportDataSource.h" 0033 #include "KReportItemBase.h" 0034 #include "KReportSectionData.h" 0035 #include "KReportLineStyle.h" 0036 0037 class ORODocument; 0038 class OROPage; 0039 class OROPrimitive; 0040 class OROTextBox; 0041 class OROLine; 0042 class OROImage; 0043 class OROSection; 0044 0045 0046 /*! 0047 * @brief Represents a single document containing one or more OROPage elements 0048 */ 0049 class KREPORT_EXPORT ORODocument : public QObject 0050 { 0051 Q_OBJECT 0052 0053 public: 0054 explicit ORODocument(const QString &title = QString()); 0055 ~ORODocument() override; 0056 0057 QString title() const; 0058 void setTitle(const QString &title); 0059 0060 0061 /** 0062 * @brief Return the total number of pages in the document 0063 * 0064 */ 0065 int pageCount() const; 0066 0067 /** 0068 * @brief Return a pointer to a given page 0069 * 0070 * @param index page number to find 0071 * @return OROPage* 0072 */ 0073 OROPage* page(int index); 0074 const OROPage* page(int index) const; 0075 0076 /** 0077 * @brief Adds the supplied page to this document 0078 * 0079 * Ownership of the page is tranferred the document 0080 * 0081 * @param page an OROPage* to be added 0082 */ 0083 void addPage(OROPage* page); 0084 0085 /** 0086 * @brief Returns the index of the supplied page in the document 0087 * 0088 * @param page OROPage* to find 0089 * @return int page index 0090 */ 0091 int pageIndex(const OROPage* page) const; 0092 0093 /** 0094 * @brief Removes the given page from the document 0095 * 0096 * The page is also deleted 0097 * 0098 * @param page OROPage* to delete 0099 */ 0100 void removePage(OROPage* page); 0101 0102 /** 0103 * @brief Takes the page from the document but does not delete it 0104 * 0105 * @param page OROPage* to take from the document 0106 */ 0107 void takePage(OROPage *page); 0108 0109 /** 0110 * @brief Return the total number of sections in the document 0111 * 0112 */ 0113 int sectionCount() const; 0114 0115 /** 0116 * @brief Return a pointer to a given section 0117 * 0118 * @param index section number to find 0119 * @return OROSection* 0120 */ 0121 OROSection* section(int index); 0122 const OROSection* section(int index) const; 0123 0124 /** 0125 * @brief Adds the supplied sectin to the document 0126 * 0127 * Ownership of the section is transferred to the document 0128 * 0129 * @param section OROSection* to add to the document 0130 */ 0131 void addSection(OROSection* section); 0132 0133 /** 0134 * @brief Removes the supplied section from the document 0135 * 0136 * The section will also be deleted 0137 * 0138 * @param section OROSection* to remove and delete 0139 */ 0140 void removeSection(OROSection *section); 0141 0142 /** 0143 * @brief Takes the section from the document but does not delete it 0144 * 0145 * @param section OROSection* to take from the document 0146 */ 0147 void takeSection(OROSection *section); 0148 0149 void setPageLayout(const QPageLayout &layout); 0150 QPageLayout pageLayout() const; 0151 0152 void notifyChange(int pageNo); 0153 0154 Q_SIGNALS: 0155 void updated(int pageNo); 0156 0157 private: 0158 class Private; 0159 Private * const d; 0160 }; 0161 0162 /*! 0163 * @brief Represents a single page in a document and may contain zero or more 0164 * OROPrimitive objects all of which represent some form of mark to be made on 0165 * a page. 0166 */ 0167 class KREPORT_EXPORT OROPage 0168 { 0169 public: 0170 explicit OROPage(ORODocument * doc = nullptr); 0171 ~OROPage(); 0172 0173 ORODocument* document(); 0174 const ORODocument* document() const; 0175 void setDocument(ORODocument *doc); 0176 0177 int pageNumber() const; // returns this pages current page number 0178 0179 int primitiveCount() const; 0180 0181 OROPrimitive* primitive(int index); 0182 const OROPrimitive* primitive(int index) const; 0183 0184 void insertPrimitive(OROPrimitive* primitive, int index = -1); 0185 void removePrimitive(OROPrimitive *primitive); 0186 void takePrimitive(OROPrimitive *primitive); 0187 0188 private: 0189 class Private; 0190 Private * const d; 0191 }; 0192 0193 /*! 0194 * @brief Represents a single a single row in a document and may contain zero or more 0195 * OROPrimitives 0196 */ 0197 class KREPORT_EXPORT OROSection 0198 { 0199 public: 0200 explicit OROSection(ORODocument* doc = nullptr); 0201 ~OROSection(); 0202 0203 void setHeight(int); 0204 int height() const; 0205 0206 void setBackgroundColor(const QColor& color); 0207 QColor backgroundColor() const; 0208 0209 ORODocument* document(); 0210 const ORODocument* document() const; 0211 void setDocument(ORODocument *doc); 0212 0213 void setType(KReportSectionData::Type type); 0214 KReportSectionData::Type type() const; 0215 0216 int primitiveCount() const; 0217 OROPrimitive* primitive(int index); 0218 const OROPrimitive* primitive(int index) const; 0219 void addPrimitive(OROPrimitive* primitive); 0220 void sortPrimitives(Qt::Orientation orientation); 0221 0222 private: 0223 class Private; 0224 Private * const d; 0225 }; 0226 0227 0228 /*! 0229 * @brief Represents the basic primitive with a position and type. 0230 * Other primitives are subclasses with a defined type and any additional 0231 * information they require to define that primitive. 0232 */ 0233 class KREPORT_EXPORT OROPrimitive 0234 { 0235 public: 0236 virtual ~OROPrimitive(); 0237 0238 OROPage* page(); 0239 const OROPage* page() const; 0240 void setPage(OROPage *page); 0241 0242 QPointF position() const; 0243 void setPosition(const QPointF &pos); 0244 0245 QSizeF size() const; 0246 void setSize(const QSizeF &s); 0247 0248 virtual OROPrimitive* clone() const = 0; 0249 0250 protected: 0251 OROPrimitive(); 0252 0253 private: 0254 class Private; 0255 Private * const d; 0256 }; 0257 0258 /*! 0259 * @brief A text box primitive it defines a box region and text that will 0260 * be rendered inside that region, it also contains information for font 0261 * and positioning of the text. 0262 */ 0263 class KREPORT_EXPORT OROTextBox : public OROPrimitive 0264 { 0265 public: 0266 OROTextBox(); 0267 ~OROTextBox() override; 0268 0269 QString text() const; 0270 void setText(const QString &text); 0271 0272 KReportTextStyleData textStyle() const; 0273 void setTextStyle(const KReportTextStyleData&); 0274 0275 KReportLineStyle lineStyle() const; 0276 void setLineStyle(const KReportLineStyle&); 0277 0278 void setFont(const QFont &font); 0279 0280 int flags() const; 0281 void setFlags(int flags); 0282 0283 OROPrimitive* clone() const override; 0284 0285 bool requiresPostProcessing() const; 0286 void setRequiresPostProcessing(bool pp); 0287 0288 bool wordWrap() const; 0289 void setWordWrap(bool ww); 0290 0291 bool canGrow() const; 0292 void setCanGrow(bool grow); 0293 0294 private: 0295 class Private; 0296 Private * const d; 0297 }; 0298 0299 /*! 0300 * @brief Defines a line with a width/weight. 0301 */ 0302 class KREPORT_EXPORT OROLine : public OROPrimitive 0303 { 0304 public: 0305 OROLine(); 0306 ~OROLine() override; 0307 0308 QPointF startPoint() const { 0309 return position(); 0310 }; 0311 void setStartPoint(const QPointF &start); 0312 0313 QPointF endPoint() const; 0314 void setEndPoint(const QPointF &end); 0315 0316 KReportLineStyle lineStyle() const; 0317 void setLineStyle(const KReportLineStyle& style); 0318 0319 OROPrimitive* clone() const override; 0320 0321 private: 0322 class Private; 0323 Private * const d; 0324 }; 0325 0326 /*! 0327 * @brief Defines an image. 0328 * An image is a bitmap. 0329 */ 0330 class KREPORT_EXPORT OROImage: public OROPrimitive 0331 { 0332 public: 0333 OROImage(); 0334 ~OROImage() override; 0335 0336 QImage image() const; 0337 void setImage(const QImage &img); 0338 0339 bool isScaled() const; 0340 void setScaled(bool scaled); 0341 0342 Qt::TransformationMode transformationMode() const; 0343 void setTransformationMode(Qt::TransformationMode transformation); 0344 0345 Qt::AspectRatioMode aspectRatioMode() const; 0346 void setAspectRatioMode(Qt::AspectRatioMode aspect); 0347 0348 OROPrimitive* clone() const override; 0349 0350 private: 0351 class Private; 0352 Private * const d; 0353 }; 0354 0355 /*! 0356 * @brief Defines a picture. 0357 * A picture is different to an image, in that it is drawn using commands. 0358 */ 0359 class KREPORT_EXPORT OROPicture: public OROPrimitive 0360 { 0361 public: 0362 OROPicture(); 0363 ~OROPicture() override; 0364 0365 void setPicture(const QPicture& pic); 0366 QPicture* picture(); 0367 0368 OROPrimitive* clone() const override; 0369 0370 private: 0371 class Private; 0372 Private * const d; 0373 0374 }; 0375 0376 /*! 0377 * @brief Defines a rectangle. 0378 */ 0379 class KREPORT_EXPORT ORORect: public OROPrimitive 0380 { 0381 public: 0382 ORORect(); 0383 ~ORORect() override; 0384 0385 QRectF rect() const; 0386 void setRect(const QRectF &rectangle); 0387 0388 QPen pen() const; 0389 void setPen(const QPen &pen); 0390 0391 QBrush brush() const; 0392 void setBrush(const QBrush &brush); 0393 0394 OROPrimitive* clone() const override; 0395 0396 private: 0397 class Private; 0398 Private * const d; 0399 }; 0400 0401 /*! 0402 * @brief Defines an ellipse. 0403 */ 0404 class KREPORT_EXPORT OROEllipse: public OROPrimitive 0405 { 0406 public: 0407 OROEllipse(); 0408 ~OROEllipse() override; 0409 0410 QRectF rect() const; 0411 void setRect(const QRectF &rectangle); 0412 0413 QPen pen() const; 0414 void setPen(const QPen &pen); 0415 0416 QBrush brush() const; 0417 void setBrush(const QBrush &brush); 0418 0419 OROPrimitive* clone() const override; 0420 0421 private: 0422 class Private; 0423 Private * const d; 0424 }; 0425 0426 /*! 0427 * @brief Defines checkbox. 0428 */ 0429 class KREPORT_EXPORT OROCheckBox : public OROPrimitive 0430 { 0431 public: 0432 enum class Type { 0433 Cross, 0434 Tick, 0435 Dot 0436 }; 0437 0438 OROCheckBox(); 0439 ~OROCheckBox() override; 0440 OROPrimitive* clone() const override; 0441 0442 void setCheckType(Type type); 0443 Type checkType() const; 0444 0445 void setValue(bool val); 0446 bool value() const; 0447 0448 void setLineStyle(const KReportLineStyle& ls); 0449 KReportLineStyle lineStyle() const; 0450 0451 void setForegroundColor(const QColor& fg); 0452 QColor foregroundColor() const; 0453 0454 private: 0455 class Private; 0456 Private * const d; 0457 0458 }; 0459 0460 #endif // __RENDEROBJECTS_H__