File indexing completed on 2025-01-05 04:47:41

0001 /*
0002   SPDX-FileCopyrightText: 1998 Preston Brown <pbrown@kde.org>
0003   SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
0004 
0005   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0006 */
0007 #pragma once
0008 
0009 #include "calendarsupport_export.h"
0010 #include "printplugin.h"
0011 
0012 #include <QComboBox>
0013 #include <QDialog>
0014 #include <QPushButton>
0015 class QButtonGroup;
0016 class QStackedWidget;
0017 
0018 namespace CalendarSupport
0019 {
0020 /**
0021   CalPrinter is a class for printing Calendars.  It can print in several
0022   different formats (day, week, month).  It also provides a way for setting
0023   up the printer and remembering these preferences.
0024 */
0025 class CALENDARSUPPORT_EXPORT CalPrinter : public QObject, public CalPrinterBase
0026 {
0027     Q_OBJECT
0028 public:
0029     enum ePrintOrientation { eOrientPlugin = 0, eOrientPrinter, eOrientPortrait, eOrientLandscape };
0030 
0031 public:
0032     /**
0033       \param par parent widget for dialogs
0034       \param cal calendar to be printed
0035       \param uniqItem if true, indicates the calendar print dialog will only
0036       provide the option to print an single incidence; else, all possible types
0037       of print types will be shown
0038     */
0039     CalPrinter(QWidget *par, const KCalendarCore::Calendar::Ptr &calendar, bool uniqItem = false);
0040 
0041     ~CalPrinter() override;
0042 
0043     void init(const KCalendarCore::Calendar::Ptr &calendar);
0044 
0045     /**
0046       Set date range to be printed.
0047 
0048       \param start Start date
0049       \param end   End date
0050     */
0051     void setDateRange(QDate start, QDate end);
0052 
0053 public Q_SLOTS:
0054     void updateConfig();
0055 
0056 private Q_SLOTS:
0057     void doPrint(CalendarSupport::PrintPlugin *selectedStyle, CalendarSupport::CalPrinter::ePrintOrientation dlgorientation, bool preview = false);
0058 
0059 public:
0060     void print(int type, QDate fd, QDate td, const KCalendarCore::Incidence::List &selectedIncidences = KCalendarCore::Incidence::List(), bool preview = false);
0061     KCalendarCore::Calendar::Ptr calendar() const;
0062     KConfig *config() const;
0063 
0064 protected:
0065     PrintPlugin::List mPrintPlugins;
0066 
0067 private:
0068     KCalendarCore::Calendar::Ptr mCalendar;
0069     QWidget *const mParent;
0070     KConfig *const mConfig;
0071     const bool mUniqItem;
0072 };
0073 
0074 class CalPrintDialog : public QDialog
0075 {
0076     Q_OBJECT
0077 public:
0078     explicit CalPrintDialog(int initialPrintType, const PrintPlugin::List &plugins, QWidget *parent = nullptr, bool mUniqItem = false);
0079 
0080     ~CalPrintDialog() override;
0081 
0082     PrintPlugin *selectedPlugin();
0083     void setOrientation(CalPrinter::ePrintOrientation orientation);
0084     CalPrinter::ePrintOrientation orientation() const;
0085 
0086 public Q_SLOTS:
0087     void setPrintType(QAbstractButton *button);
0088     void setPreview(bool);
0089 
0090 private:
0091     void slotOk();
0092     void changePrintType(int id);
0093     QButtonGroup *mTypeGroup = nullptr;
0094     QStackedWidget *mConfigArea = nullptr;
0095     QMap<int, PrintPlugin *> mPluginIDs;
0096     QString mPreviewText;
0097     QComboBox *mOrientationSelection = nullptr;
0098     QPushButton *mOkButton = nullptr;
0099     CalPrinter::ePrintOrientation mOrientation;
0100 };
0101 }