1 /* This file is part of the KDE project 2 * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) 3 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 #ifndef KREPORTRENDEROBJECTS_H 19 #define KREPORTRENDEROBJECTS_H 20 21 #include <QString> 22 #include <QList> 23 #include <QPointF> 24 #include <QSizeF> 25 #include <QFont> 26 #include <QImage> 27 #include <QPen> 28 #include <QBrush> 29 #include <QPicture> 30 #include <QPageLayout> 31 32 #include "KReportDataSource.h" 33 #include "KReportItemBase.h" 34 #include "KReportSectionData.h" 35 #include "KReportLineStyle.h" 36 37 class ORODocument; 38 class OROPage; 39 class OROPrimitive; 40 class OROTextBox; 41 class OROLine; 42 class OROImage; 43 class OROSection; 44 45 46 /*! 47 * @brief Represents a single document containing one or more OROPage elements 48 */ 49 class KREPORT_EXPORT ORODocument : public QObject 50 { 51 Q_OBJECT 52 53 public: 54 explicit ORODocument(const QString &title = QString()); 55 ~ORODocument() override; 56 57 QString title() const; 58 void setTitle(const QString &title); 59 60 61 /** 62 * @brief Return the total number of pages in the document 63 * 64 */ 65 int pageCount() const; 66 67 /** 68 * @brief Return a pointer to a given page 69 * 70 * @param index page number to find 71 * @return OROPage* 72 */ 73 OROPage* page(int index); 74 const OROPage* page(int index) const; 75 76 /** 77 * @brief Adds the supplied page to this document 78 * 79 * Ownership of the page is tranferred the document 80 * 81 * @param page an OROPage* to be added 82 */ 83 void addPage(OROPage* page); 84 85 /** 86 * @brief Returns the index of the supplied page in the document 87 * 88 * @param page OROPage* to find 89 * @return int page index 90 */ 91 int pageIndex(const OROPage* page) const; 92 93 /** 94 * @brief Removes the given page from the document 95 * 96 * The page is also deleted 97 * 98 * @param page OROPage* to delete 99 */ 100 void removePage(OROPage* page); 101 102 /** 103 * @brief Takes the page from the document but does not delete it 104 * 105 * @param page OROPage* to take from the document 106 */ 107 void takePage(OROPage *page); 108 109 /** 110 * @brief Return the total number of sections in the document 111 * 112 */ 113 int sectionCount() const; 114 115 /** 116 * @brief Return a pointer to a given section 117 * 118 * @param index section number to find 119 * @return OROSection* 120 */ 121 OROSection* section(int index); 122 const OROSection* section(int index) const; 123 124 /** 125 * @brief Adds the supplied sectin to the document 126 * 127 * Ownership of the section is transferred to the document 128 * 129 * @param section OROSection* to add to the document 130 */ 131 void addSection(OROSection* section); 132 133 /** 134 * @brief Removes the supplied section from the document 135 * 136 * The section will also be deleted 137 * 138 * @param section OROSection* to remove and delete 139 */ 140 void removeSection(OROSection *section); 141 142 /** 143 * @brief Takes the section from the document but does not delete it 144 * 145 * @param section OROSection* to take from the document 146 */ 147 void takeSection(OROSection *section); 148 149 void setPageLayout(const QPageLayout &layout); 150 QPageLayout pageLayout() const; 151 152 void notifyChange(int pageNo); 153 154 Q_SIGNALS: 155 void updated(int pageNo); 156 157 private: 158 class Private; 159 Private * const d; 160 }; 161 162 /*! 163 * @brief Represents a single page in a document and may contain zero or more 164 * OROPrimitive objects all of which represent some form of mark to be made on 165 * a page. 166 */ 167 class KREPORT_EXPORT OROPage 168 { 169 public: 170 explicit OROPage(ORODocument * doc = nullptr); 171 ~OROPage(); 172 173 ORODocument* document(); 174 const ORODocument* document() const; 175 void setDocument(ORODocument *doc); 176 177 int pageNumber() const; // returns this pages current page number 178 179 int primitiveCount() const; 180 181 OROPrimitive* primitive(int index); 182 const OROPrimitive* primitive(int index) const; 183 184 void insertPrimitive(OROPrimitive* primitive, int index = -1); 185 void removePrimitive(OROPrimitive *primitive); 186 void takePrimitive(OROPrimitive *primitive); 187 188 private: 189 class Private; 190 Private * const d; 191 }; 192 193 /*! 194 * @brief Represents a single a single row in a document and may contain zero or more 195 * OROPrimitives 196 */ 197 class KREPORT_EXPORT OROSection 198 { 199 public: 200 explicit OROSection(ORODocument* doc = nullptr); 201 ~OROSection(); 202 203 void setHeight(int); 204 int height() const; 205 206 void setBackgroundColor(const QColor& color); 207 QColor backgroundColor() const; 208 209 ORODocument* document(); 210 const ORODocument* document() const; 211 void setDocument(ORODocument *doc); 212 213 void setType(KReportSectionData::Type type); 214 KReportSectionData::Type type() const; 215 216 int primitiveCount() const; 217 OROPrimitive* primitive(int index); 218 const OROPrimitive* primitive(int index) const; 219 void addPrimitive(OROPrimitive* primitive); 220 void sortPrimitives(Qt::Orientation orientation); 221 222 private: 223 class Private; 224 Private * const d; 225 }; 226 227 228 /*! 229 * @brief Represents the basic primitive with a position and type. 230 * Other primitives are subclasses with a defined type and any additional 231 * information they require to define that primitive. 232 */ 233 class KREPORT_EXPORT OROPrimitive 234 { 235 public: 236 virtual ~OROPrimitive(); 237 238 OROPage* page(); 239 const OROPage* page() const; 240 void setPage(OROPage *page); 241 242 QPointF position() const; 243 void setPosition(const QPointF &pos); 244 245 QSizeF size() const; 246 void setSize(const QSizeF &s); 247 248 virtual OROPrimitive* clone() const = 0; 249 250 protected: 251 OROPrimitive(); 252 253 private: 254 class Private; 255 Private * const d; 256 }; 257 258 /*! 259 * @brief A text box primitive it defines a box region and text that will 260 * be rendered inside that region, it also contains information for font 261 * and positioning of the text. 262 */ 263 class KREPORT_EXPORT OROTextBox : public OROPrimitive 264 { 265 public: 266 OROTextBox(); 267 ~OROTextBox() override; 268 269 QString text() const; 270 void setText(const QString &text); 271 272 KReportTextStyleData textStyle() const; 273 void setTextStyle(const KReportTextStyleData&); 274 275 KReportLineStyle lineStyle() const; 276 void setLineStyle(const KReportLineStyle&); 277 278 void setFont(const QFont &font); 279 280 int flags() const; 281 void setFlags(int flags); 282 283 OROPrimitive* clone() const override; 284 285 bool requiresPostProcessing() const; 286 void setRequiresPostProcessing(bool pp); 287 288 bool wordWrap() const; 289 void setWordWrap(bool ww); 290 291 bool canGrow() const; 292 void setCanGrow(bool grow); 293 294 private: 295 class Private; 296 Private * const d; 297 }; 298 299 /*! 300 * @brief Defines a line with a width/weight. 301 */ 302 class KREPORT_EXPORT OROLine : public OROPrimitive 303 { 304 public: 305 OROLine(); 306 ~OROLine() override; 307 startPoint()308 QPointF startPoint() const { 309 return position(); 310 }; 311 void setStartPoint(const QPointF &start); 312 313 QPointF endPoint() const; 314 void setEndPoint(const QPointF &end); 315 316 KReportLineStyle lineStyle() const; 317 void setLineStyle(const KReportLineStyle& style); 318 319 OROPrimitive* clone() const override; 320 321 private: 322 class Private; 323 Private * const d; 324 }; 325 326 /*! 327 * @brief Defines an image. 328 * An image is a bitmap. 329 */ 330 class KREPORT_EXPORT OROImage: public OROPrimitive 331 { 332 public: 333 OROImage(); 334 ~OROImage() override; 335 336 QImage image() const; 337 void setImage(const QImage &img); 338 339 bool isScaled() const; 340 void setScaled(bool scaled); 341 342 Qt::TransformationMode transformationMode() const; 343 void setTransformationMode(Qt::TransformationMode transformation); 344 345 Qt::AspectRatioMode aspectRatioMode() const; 346 void setAspectRatioMode(Qt::AspectRatioMode aspect); 347 348 OROPrimitive* clone() const override; 349 350 private: 351 class Private; 352 Private * const d; 353 }; 354 355 /*! 356 * @brief Defines a picture. 357 * A picture is different to an image, in that it is drawn using commands. 358 */ 359 class KREPORT_EXPORT OROPicture: public OROPrimitive 360 { 361 public: 362 OROPicture(); 363 ~OROPicture() override; 364 365 void setPicture(const QPicture& pic); 366 QPicture* picture(); 367 368 OROPrimitive* clone() const override; 369 370 private: 371 class Private; 372 Private * const d; 373 374 }; 375 376 /*! 377 * @brief Defines a rectangle. 378 */ 379 class KREPORT_EXPORT ORORect: public OROPrimitive 380 { 381 public: 382 ORORect(); 383 ~ORORect() override; 384 385 QRectF rect() const; 386 void setRect(const QRectF &rectangle); 387 388 QPen pen() const; 389 void setPen(const QPen &pen); 390 391 QBrush brush() const; 392 void setBrush(const QBrush &brush); 393 394 OROPrimitive* clone() const override; 395 396 private: 397 class Private; 398 Private * const d; 399 }; 400 401 /*! 402 * @brief Defines an ellipse. 403 */ 404 class KREPORT_EXPORT OROEllipse: public OROPrimitive 405 { 406 public: 407 OROEllipse(); 408 ~OROEllipse() override; 409 410 QRectF rect() const; 411 void setRect(const QRectF &rectangle); 412 413 QPen pen() const; 414 void setPen(const QPen &pen); 415 416 QBrush brush() const; 417 void setBrush(const QBrush &brush); 418 419 OROPrimitive* clone() const override; 420 421 private: 422 class Private; 423 Private * const d; 424 }; 425 426 /*! 427 * @brief Defines checkbox. 428 */ 429 class KREPORT_EXPORT OROCheckBox : public OROPrimitive 430 { 431 public: 432 enum class Type { 433 Cross, 434 Tick, 435 Dot 436 }; 437 438 OROCheckBox(); 439 ~OROCheckBox() override; 440 OROPrimitive* clone() const override; 441 442 void setCheckType(Type type); 443 Type checkType() const; 444 445 void setValue(bool val); 446 bool value() const; 447 448 void setLineStyle(const KReportLineStyle& ls); 449 KReportLineStyle lineStyle() const; 450 451 void setForegroundColor(const QColor& fg); 452 QColor foregroundColor() const; 453 454 private: 455 class Private; 456 Private * const d; 457 458 }; 459 460 #endif // __RENDEROBJECTS_H__ 461