CalendarSupport

printplugin.h
1/*
2 SPDX-FileCopyrightText: 2003 Reinhold Kainhofer <reinhold@kainhofer.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <KCalendarCore/Calendar>
10#include <KCalendarCore/Incidence>
11#include <KConfig>
12
13#include <QDate>
14#include <QPointer>
15#include <QPrinter>
16
17namespace CalendarSupport
18{
19/**
20 Base class of Calendar printer class.
21*/
23{
24public:
25 enum PrintType {
26 Incidence = 100,
27 Day = 200,
28 Week = 300,
29 Month = 400,
30 Year = 900,
31 Todolist = 1000,
32 Journallist = 2000,
33 WhatsNext = 2100,
34 ItemList = 2200
35 };
36};
37
38/**
39 Base class for Calendar printing classes. Each sub class represents one
40 calendar print format.
41*/
43{
44public:
46 : mConfigWidget(nullptr)
47 {
48 }
49
50 virtual ~PrintPlugin() = default;
51
53
54 virtual void setConfig(KConfig *cfg)
55 {
56 mConfig = cfg;
57 }
58
59 virtual void setCalendar(const KCalendarCore::Calendar::Ptr &cal)
60 {
61 mCalendar = cal;
62 }
63
64 virtual void setSelectedIncidences(const KCalendarCore::Incidence::List &inc)
65 {
66 mSelectedIncidences = inc;
67 }
68
69 [[nodiscard]] virtual KCalendarCore::Incidence::List selectedIncidences() const
70 {
71 return mSelectedIncidences;
72 }
73
74 /**
75 Returns KConfig group name where store settings
76 */
77 [[nodiscard]] virtual QString groupName() const = 0;
78 /**
79 Returns short description of print format.
80 */
81 [[nodiscard]] virtual QString description() const = 0;
82 /**
83 Returns long description of print format.
84 */
85 [[nodiscard]] virtual QString info() const = 0;
86
87 /**
88 Returns the sort ID of the plugin. This value will be used to identify
89 the config widget in the widget stack, and to sort the plugin name in the
90 print style selection list.
91 If another plugin uses the same ID or a value of -1 is returned, a unique
92 (negative) ID will be automatically generated and thus the position of
93 the plugin in the selection list is undefined.
94 */
95 virtual int sortID() const
96 {
97 return -1;
98 }
99
100 /**
101 Returns true if the plugin should be enabled; false otherwise.
102 */
103 [[nodiscard]] virtual bool enabled() const
104 {
105 return false;
106 }
107
108 QWidget *configWidget(QWidget *w)
109 {
110 if (!mConfigWidget) {
111 mConfigWidget = createConfigWidget(w);
113 }
114 return mConfigWidget;
115 }
116
117 /* Create the config widget. setSettingsWidget will be automatically
118 called on it */
119 virtual QWidget *createConfigWidget(QWidget *) = 0;
120
121 /**
122 Actually do the printing.
123 */
124 virtual void doPrint(QPrinter *printer) = 0;
125
126 /**
127 Orientation of printout. Default is Portrait. If your plugin wants
128 to use some other orientation as default (e.g. depending on some
129 config settings), implement this function in your subclass and
130 return the desired orientation.
131 */
136
137 /**
138 Load complete configuration. Each implementation calls its parent's
139 implementation to load parent configuration options, then loads its own.
140 */
141 virtual void doLoadConfig()
142 {
143 }
144
145 /**
146 Save complete configuration. Each implementation saves its own
147 configuration options, then calls its parent's implementation to save
148 parent options.
149 */
150 virtual void doSaveConfig()
151 {
152 }
153
154public:
155 /**
156 Read settings from configuration widget and apply them to current object.
157 */
158 virtual void readSettingsWidget()
159 {
160 }
161
162 /**
163 Set configuration widget to reflect settings of current object.
164 */
165 virtual void setSettingsWidget()
166 {
167 }
168
169 /**
170 Set date range which should be printed.
171 */
172 virtual void setDateRange(const QDate &from, const QDate &to)
173 {
174 mFromDate = from;
175 mToDate = to;
176 }
177
178protected:
179 QDate mFromDate;
180 QDate mToDate;
181
182protected:
183 QPointer<QWidget> mConfigWidget;
184 /** The printer object. This will only be available in the doPrint method
185 of the selected plugin */
186 QPrinter *mPrinter = nullptr;
188 KCalendarCore::Incidence::List mSelectedIncidences;
189 KConfig *mConfig = nullptr;
190};
191
192}
Base class of Calendar printer class.
Definition printplugin.h:23
Base class for Calendar printing classes.
Definition printplugin.h:43
virtual QString info() const =0
Returns long description of print format.
virtual void readSettingsWidget()
Read settings from configuration widget and apply them to current object.
virtual bool enabled() const
Returns true if the plugin should be enabled; false otherwise.
virtual void setSettingsWidget()
Set configuration widget to reflect settings of current object.
virtual QString description() const =0
Returns short description of print format.
virtual void setDateRange(const QDate &from, const QDate &to)
Set date range which should be printed.
virtual QString groupName() const =0
Returns KConfig group name where store settings.
virtual void doLoadConfig()
Load complete configuration.
QPrinter * mPrinter
The printer object.
virtual void doPrint(QPrinter *printer)=0
Actually do the printing.
virtual void doSaveConfig()
Save complete configuration.
virtual QPageLayout::Orientation defaultOrientation() const
Orientation of printout.
virtual int sortID() const
Returns the sort ID of the plugin.
Definition printplugin.h:95
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:28 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.