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

KDE's Doxygen guidelines are available online.