File indexing completed on 2024-05-19 05:14:36
0001 /* 0002 This file is part of KAddressBook. 0003 SPDX-FileCopyrightText: 1996-2002 Mirko Boehm <mirko@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0006 */ 0007 0008 #pragma once 0009 0010 #include "importexport/contactfields.h" 0011 0012 #include <KContacts/Addressee> 0013 0014 #include <QHash> 0015 #include <QPixmap> 0016 #include <QStringList> 0017 #include <QWidget> 0018 0019 class KPageWidgetItem; 0020 0021 namespace KABPrinting 0022 { 0023 class PrintingWizard; 0024 class PrintProgress; 0025 0026 /** 0027 * @short The abstract interface to the PrintingWizards style objects. 0028 * 0029 * To implement a print style, derive from this class and read 0030 * the information in printingwizard.h to see how this two pieces 0031 * work together. Basically, the print style gets the contacts it 0032 * is supposed to print from the PrintingWizard is will not 0033 * change this set - neither its content nor its order. 0034 * 0035 * To register your new style in the printing wizard, you need to 0036 * define a PrintStyleFactory that handles how your objects are 0037 * created and deleted. See the existing print styles for 0038 * examples. 0039 * 0040 * A print style should have a preview image that gives the user 0041 * a basic impression on how it will look. Add this image to the 0042 * printing folder and edit CMakeLists.txt to have 0043 * it installed along with kaddressbook. 0044 * Load it using setPreview( const QString& ). 0045 * 0046 * Your print style is supposed to add its options as pages to 0047 * the printing wizard. The method wizard() gives you a pointer 0048 * to the wizard object. 0049 */ 0050 class PrintStyle : public QObject 0051 { 0052 Q_OBJECT 0053 0054 public: 0055 /** 0056 * Creates a new print style. 0057 * 0058 * @param wizard The wizard the style belongs to. 0059 */ 0060 explicit PrintStyle(PrintingWizard *wizard); 0061 0062 /** 0063 * Destroys the print style. 0064 */ 0065 ~PrintStyle() override; 0066 0067 /** 0068 * This method must be reimplemented to actually print something. 0069 * 0070 * @param contacts The filtered and sorted list of contacts. 0071 * @param progress The object to inform the user about the progress of printing. 0072 */ 0073 virtual void print(const KContacts::Addressee::List &contacts, PrintProgress *progress) = 0; 0074 0075 /** 0076 * This method should be reimplemented to provide a preview of what 0077 * the printed page will look like. 0078 * 0079 * An invalid pixmap is returned by default, which means no preview 0080 * is available. 0081 */ 0082 const QPixmap &preview() const; 0083 0084 /** 0085 * Hides all style specific pages in the printing wizard. 0086 */ 0087 void hidePages(); 0088 0089 /** 0090 * Show all style specific pages in the printing wizard. 0091 */ 0092 void showPages(); 0093 0094 /** 0095 * Returns the preferred contact field that shall be used for sorting. 0096 */ 0097 KAddressBookImportExport::ContactFields::Field preferredSortField() const; 0098 0099 /** 0100 * Returns the preferred order that shall be used for sorting. 0101 */ 0102 Qt::SortOrder preferredSortOrder() const; 0103 0104 protected: 0105 /** 0106 * Loads the preview image from the kaddressbook data directory. 0107 * 0108 * @param fileName The name of the preview image in the "printing" subdirectory 0109 * without any prefix. 0110 * @returns Whether the image was loaded successfully. 0111 */ 0112 bool setPreview(const QString &fileName); 0113 0114 /** 0115 * Sets the preview @p image. 0116 */ 0117 void setPreview(const QPixmap &image); 0118 0119 /** 0120 * Sets the preferred sort options for this printing style. 0121 */ 0122 void setPreferredSortOptions(KAddressBookImportExport::ContactFields::Field, Qt::SortOrder sortOrder = Qt::AscendingOrder); 0123 0124 /** 0125 * Returns the printing wizard that is responsible for this style. 0126 */ 0127 PrintingWizard *wizard() const; 0128 0129 /** 0130 * Adds an additional page to the printing wizard, e.g. a configuration 0131 * page for the style. 0132 * 0133 * @param page The page widget. 0134 * @param title The page title. 0135 */ 0136 void addPage(QWidget *page, const QString &title); 0137 0138 private: 0139 PrintingWizard *mWizard = nullptr; 0140 QPixmap mPreview; 0141 QList<QWidget *> mPageList; 0142 QHash<QWidget *, KPageWidgetItem *> mPageItems; 0143 QStringList mPageTitles; 0144 0145 KAddressBookImportExport::ContactFields::Field mSortField; 0146 Qt::SortOrder mSortOrder; 0147 }; 0148 0149 /** 0150 * The factories are used to have all object of the respective 0151 * print style created in one place. 0152 */ 0153 class PrintStyleFactory 0154 { 0155 public: 0156 explicit PrintStyleFactory(PrintingWizard *parent); 0157 virtual ~PrintStyleFactory(); 0158 0159 virtual PrintStyle *create() const = 0; 0160 0161 /** 0162 * Overload this method to provide a one-liner description 0163 * for your print style. 0164 */ 0165 virtual QString description() const = 0; 0166 0167 protected: 0168 PrintingWizard *mParent = nullptr; 0169 }; 0170 }