File indexing completed on 2025-01-05 04:47:43
0001 /* 0002 SPDX-FileCopyrightText: 2003 Reinhold Kainhofer <reinhold@kainhofer.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <KCalendarCore/Calendar> 0010 #include <KCalendarCore/Incidence> 0011 #include <KConfig> 0012 0013 #include <QDate> 0014 #include <QPointer> 0015 #include <QPrinter> 0016 0017 namespace CalendarSupport 0018 { 0019 /** 0020 Base class of Calendar printer class. 0021 */ 0022 class CalPrinterBase 0023 { 0024 public: 0025 enum PrintType { Incidence = 100, Day = 200, Week = 300, Month = 400, Year = 900, Todolist = 1000, Journallist = 2000, WhatsNext = 2100, ItemList = 2200 }; 0026 }; 0027 0028 /** 0029 Base class for Calendar printing classes. Each sub class represents one 0030 calendar print format. 0031 */ 0032 class PrintPlugin 0033 { 0034 public: 0035 PrintPlugin() 0036 : mConfigWidget(nullptr) 0037 { 0038 } 0039 0040 virtual ~PrintPlugin() = default; 0041 0042 using List = QList<PrintPlugin *>; 0043 0044 virtual void setConfig(KConfig *cfg) 0045 { 0046 mConfig = cfg; 0047 } 0048 0049 virtual void setCalendar(const KCalendarCore::Calendar::Ptr &cal) 0050 { 0051 mCalendar = cal; 0052 } 0053 0054 virtual void setSelectedIncidences(const KCalendarCore::Incidence::List &inc) 0055 { 0056 mSelectedIncidences = inc; 0057 } 0058 0059 virtual KCalendarCore::Incidence::List selectedIncidences() const 0060 { 0061 return mSelectedIncidences; 0062 } 0063 0064 /** 0065 Returns KConfig group name where store settings 0066 */ 0067 virtual QString groupName() const = 0; 0068 /** 0069 Returns short description of print format. 0070 */ 0071 virtual QString description() const = 0; 0072 /** 0073 Returns long description of print format. 0074 */ 0075 virtual QString info() const = 0; 0076 0077 /** 0078 Returns the sort ID of the plugin. This value will be used to identify 0079 the config widget in the widget stack, and to sort the plugin name in the 0080 print style selection list. 0081 If another plugin uses the same ID or a value of -1 is returned, a unique 0082 (negative) ID will be automatically generated and thus the position of 0083 the plugin in the selection list is undefined. 0084 */ 0085 virtual int sortID() const 0086 { 0087 return -1; 0088 } 0089 0090 /** 0091 Returns true if the plugin should be enabled; false otherwise. 0092 */ 0093 virtual bool enabled() const 0094 { 0095 return false; 0096 } 0097 0098 QWidget *configWidget(QWidget *w) 0099 { 0100 if (!mConfigWidget) { 0101 mConfigWidget = createConfigWidget(w); 0102 setSettingsWidget(); 0103 } 0104 return mConfigWidget; 0105 } 0106 0107 /* Create the config widget. setSettingsWidget will be automatically 0108 called on it */ 0109 virtual QWidget *createConfigWidget(QWidget *) = 0; 0110 0111 /** 0112 Actually do the printing. 0113 */ 0114 virtual void doPrint(QPrinter *printer) = 0; 0115 0116 /** 0117 Orientation of printout. Default is Portrait. If your plugin wants 0118 to use some other orientation as default (e.g. depending on some 0119 config settings), implement this function in your subclass and 0120 return the desired orientation. 0121 */ 0122 virtual QPageLayout::Orientation defaultOrientation() const 0123 { 0124 return QPageLayout::Portrait; 0125 } 0126 0127 /** 0128 Load complete configuration. Each implementation calls its parent's 0129 implementation to load parent configuration options, then loads its own. 0130 */ 0131 virtual void doLoadConfig() 0132 { 0133 } 0134 0135 /** 0136 Save complete configuration. Each implementation saves its own 0137 configuration options, then calls its parent's implementation to save 0138 parent options. 0139 */ 0140 virtual void doSaveConfig() 0141 { 0142 } 0143 0144 public: 0145 /** 0146 Read settings from configuration widget and apply them to current object. 0147 */ 0148 virtual void readSettingsWidget() 0149 { 0150 } 0151 0152 /** 0153 Set configuration widget to reflect settings of current object. 0154 */ 0155 virtual void setSettingsWidget() 0156 { 0157 } 0158 0159 /** 0160 Set date range which should be printed. 0161 */ 0162 virtual void setDateRange(const QDate &from, const QDate &to) 0163 { 0164 mFromDate = from; 0165 mToDate = to; 0166 } 0167 0168 protected: 0169 QDate mFromDate; 0170 QDate mToDate; 0171 0172 protected: 0173 QPointer<QWidget> mConfigWidget; 0174 /** The printer object. This will only be available in the doPrint method 0175 of the selected plugin */ 0176 QPrinter *mPrinter = nullptr; 0177 KCalendarCore::Calendar::Ptr mCalendar; 0178 KCalendarCore::Incidence::List mSelectedIncidences; 0179 KConfig *mConfig = nullptr; 0180 }; 0181 0182 }