11#include "calprintdefaultplugins.h"
12#include "journalprint.h"
15#include <KConfigGroup>
17#include <KStandardGuiItem>
18#include <KWindowStateSaver>
20#include <QButtonGroup>
21#include <QDialogButtonBox>
24#include <QPrintDialog>
25#include <QPrintPreviewDialog>
27#include <QStackedWidget>
30using namespace CalendarSupport;
35 , mConfig(new
KConfig(QStringLiteral(
"calendar_printing.rc"),
KConfig::SimpleConfig))
41CalPrinter::~CalPrinter()
43 qDeleteAll(mPrintPlugins);
51 qDeleteAll(mPrintPlugins);
52 mPrintPlugins.
clear();
55 mPrintPlugins.
prepend(
new CalPrintYear());
56 mPrintPlugins.
prepend(
new CalPrintJournal());
57 mPrintPlugins.
prepend(
new CalPrintTodos());
58 mPrintPlugins.
prepend(
new CalPrintMonth());
59 mPrintPlugins.
prepend(
new CalPrintWeek());
60 mPrintPlugins.
prepend(
new CalPrintDay());
62 mPrintPlugins.prepend(
new CalPrintIncidence());
66 for (; it !=
end; ++it) {
68 (*it)->setConfig(mConfig);
69 (*it)->setCalendar(mCalendar);
70 (*it)->doLoadConfig();
77 for (
const auto plugin : std::as_const(mPrintPlugins)) {
78 plugin->setDateRange(fd, td);
86 for (it = mPrintPlugins.
begin(); it != end; ++it) {
87 (*it)->setSelectedIncidences(selectedIncidences);
92 printDialog->setOrientation(CalPrinter::ePrintOrientation(grp.readEntry(
"Orientation", 1)));
93 printDialog->setPreview(preview);
97 grp.writeEntry(
"Orientation",
static_cast<int>(printDialog->orientation()));
100 for (it = mPrintPlugins.
begin(); it != mPrintPlugins.
end(); ++it) {
101 (*it)->doSaveConfig();
103 doPrint(printDialog->selectedPlugin(), printDialog->orientation(), preview);
107 for (it = mPrintPlugins.begin(); it != mPrintPlugins.end(); ++it) {
112void CalPrinter::doPrint(
PrintPlugin *selectedStyle, CalPrinter::ePrintOrientation dlgorientation,
bool preview)
114 if (!selectedStyle) {
115 KMessageBox::error(mParent,
i18nc(
"@info",
"Unable to print, an invalid print style was specified."),
i18nc(
"@title:window",
"Printing error"));
120 switch (dlgorientation) {
124 case eOrientPortrait:
127 case eOrientLandscape:
135 QPointer<QPrintPreviewDialog>
printPreview =
new QPrintPreviewDialog(&printer);
136 new KWindowStateSaver(
printPreview.
data(),
"CalendarPrintPreviewDialog"_L1);
138 selectedStyle->doPrint(&printer);
143 QPointer<QPrintDialog> printDialog =
new QPrintDialog(&printer, mParent);
145 selectedStyle->
doPrint(&printer);
151void CalPrinter::updateConfig()
155CalPrintDialog::CalPrintDialog(
int initialPrintType,
const PrintPlugin::List &plugins, QWidget *parent,
bool uniqItem)
158 setWindowTitle(
i18nc(
"@title:window",
"Print"));
160 auto mainLayout =
new QVBoxLayout(
this);
162 mOkButton->setDefault(
true);
167 auto page =
new QWidget(
this);
168 auto pageVBoxLayout =
new QVBoxLayout(page);
169 pageVBoxLayout->setContentsMargins(0, 0, 0, 0);
170 mainLayout->addWidget(page);
171 mainLayout->addWidget(buttonBox);
173 auto splitter =
new QSplitter(page);
174 pageVBoxLayout->addWidget(splitter);
176 splitter->setChildrenCollapsible(
false);
177 auto typeBox =
new QGroupBox(
i18nc(
"@title:group",
"Print Style"), splitter);
178 QBoxLayout *typeLayout =
new QVBoxLayout(typeBox);
179 mTypeGroup =
new QButtonGroup(typeBox);
181 auto splitterRight =
new QWidget(splitter);
182 auto splitterRightLayout =
new QGridLayout(splitterRight);
183 splitterRightLayout->setContentsMargins(0, 0, 0, 0);
187 mConfigArea =
new QStackedWidget(splitterRight);
188 splitterRightLayout->addWidget(mConfigArea, 0, 0, 1, 2);
189 auto orientationLabel =
new QLabel(
i18nc(
"@label",
"Page &orientation:"), splitterRight);
191 splitterRightLayout->addWidget(orientationLabel, 1, 0);
193 mOrientationSelection =
new QComboBox(splitterRight);
194 mOrientationSelection->setToolTip(
i18nc(
"@info:tooltip",
"Set the print orientation"));
195 mOrientationSelection->setWhatsThis(
i18nc(
"@info:whatsthis",
196 "Choose if you want your output to be printed in \"portrait\" or "
197 "\"landscape\". You can also default to the orientation best suited to "
198 "the selected style or to your printer's default setting."));
199 mOrientationSelection->addItem(
i18nc(
"@item:inlistbox",
"Use Default Orientation of Selected Style"));
200 mOrientationSelection->addItem(
i18nc(
"@item:inlistbox",
"Use Printer Default"));
201 mOrientationSelection->addItem(
i18nc(
"@item:inlistbox",
"Portrait"));
202 mOrientationSelection->addItem(
i18nc(
"@item:inlistbox",
"Landscape"));
203 splitterRightLayout->addWidget(mOrientationSelection, 1, 1);
207 orientationLabel->setBuddy(mOrientationSelection);
213 int newid = mConfigArea->insertWidget((*it)->sortID(), (*it)->configWidget(mConfigArea));
214 mPluginIDs[newid] = (*it);
218 bool firstButton =
true;
220 for (mapit = mPluginIDs.constBegin(); mapit != mPluginIDs.constEnd(); ++mapit) {
221 PrintPlugin *p = mapit.
value();
222 auto radioButton =
new QRadioButton(p->
description());
223 radioButton->setEnabled(p->
enabled());
224 radioButton->setToolTip(
i18nc(
"@info:tooltip",
"Select the type of print"));
225 radioButton->setWhatsThis(
i18nc(
"@info:whatsthis",
226 "Select one of the following types of prints you want to make. "
227 "You may want to print an individual item, or all the items for a "
228 "specific time range (like a day, week or month), or you may want "
229 "to print your to-do list."));
232 if ((firstButton || p->
sortID() == initialPrintType) && p->
enabled()) {
234 radioButton->setChecked(
true);
237 mTypeGroup->addButton(radioButton, mapit.
key());
245 setMinimumSize(minimumSizeHint());
246 resize(minimumSizeHint());
249CalPrintDialog::~CalPrintDialog() =
default;
251void CalPrintDialog::setPreview(
bool preview)
254 mOkButton->setText(
i18nc(
"@action:button",
"&Preview"));
260void CalPrintDialog::changePrintType(
int i)
262 mConfigArea->setCurrentIndex(i);
263 mConfigArea->currentWidget()->raise();
264 QAbstractButton *btn = mTypeGroup->button(i);
270void CalPrintDialog::setPrintType(QAbstractButton *button)
273 const int i = mTypeGroup->id(button);
274 mConfigArea->setCurrentIndex(i);
275 mConfigArea->currentWidget()->raise();
280void CalPrintDialog::setOrientation(CalPrinter::ePrintOrientation orientation)
282 mOrientation = orientation;
283 mOrientationSelection->setCurrentIndex(mOrientation);
286CalPrinter::ePrintOrientation CalPrintDialog::orientation()
const
293 int id = mConfigArea->currentIndex();
294 if (mPluginIDs.contains(
id)) {
295 return mPluginIDs[id];
301void CalPrintDialog::slotOk()
303 mOrientation =
static_cast<CalPrinter::ePrintOrientation
>(mOrientationSelection->currentIndex());
306 for (; it != mPluginIDs.
constEnd(); ++it) {
308 it.
value()->readSettingsWidget();
314#include "moc_calprinter.cpp"
void setDateRange(QDate start, QDate end)
Set date range to be printed.
CalPrinter(QWidget *par, const KCalendarCore::Calendar::Ptr &calendar, bool uniqItem=false)
Base class for Calendar printing classes.
virtual bool enabled() const
Returns true if the plugin should be enabled; false otherwise.
virtual QString description() const =0
Returns short description of print format.
virtual void doPrint(QPrinter *printer)=0
Actually do the printing.
virtual QPageLayout::Orientation defaultOrientation() const
Orientation of printout.
virtual int sortID() const
Returns the sort ID of the plugin.
QSharedPointer< Calendar > Ptr
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
QAction * printPreview(const QObject *recvr, const char *slot, QObject *parent)
const QList< QKeySequence > & end()
QVariant data() const const
void insertStretch(int index, int stretch)
const_iterator constBegin() const const
const_iterator constEnd() const const
void prepend(parameter_type value)
const_iterator constEnd() const const
Key key(const T &value, const Key &defaultKey) const const
T value(const Key &key, const T &defaultValue) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
virtual bool setPageOrientation(QPageLayout::Orientation orientation)
void paintRequested(QPrinter *printer)