9#include "calendarsupport_debug.h"
10#include <KConfigGroup>
11#include <KLocalizedString>
12using namespace CalendarSupport;
20 return new CalPrintYearConfig(w);
23void CalPrintYear::readSettingsWidget()
25 auto cfg =
dynamic_cast<CalPrintYearConfig *
>((
QWidget *)mConfigWidget);
28 mYear = cfg->mYear->value();
29 mPages = cfg->mPages->currentText().toInt();
30 mSubDaysEvents = (cfg->mSubDays->currentIndex() == 0) ? Text : TimeBoxes;
31 mHolidaysEvents = (cfg->mHolidays->currentIndex() == 0) ? Text : TimeBoxes;
37void CalPrintYear::setSettingsWidget()
39 auto cfg =
dynamic_cast<CalPrintYearConfig *
>((
QWidget *)mConfigWidget);
42 const int months = 12;
44 for (
int i = 1; i <= months; ++i) {
45 const int pages = (months - 1) / i + 1;
46 if (pages != prevPages) {
53 cfg->mYear->setValue(mYear);
54 cfg->mPages->setCurrentIndex(cfg->mPages->findData(mPages));
56 cfg->mSubDays->setCurrentIndex((mSubDaysEvents == Text) ? 0 : 1);
57 cfg->mHolidays->setCurrentIndex((mHolidaysEvents == Text) ? 0 : 1);
63void CalPrintYear::doLoadConfig()
67 KConfigGroup config(mConfig, QStringLiteral(
"Yearprint"));
69 mPages = config.readEntry(
"Pages", 1);
70 mSubDaysEvents = config.readEntry(
"ShowSubDayEventsAs",
static_cast<int>(TimeBoxes));
71 mHolidaysEvents = config.readEntry(
"ShowHolidaysAs",
static_cast<int>(Text));
76void CalPrintYear::doSaveConfig()
78 qCDebug(CALENDARSUPPORT_LOG);
82 KConfigGroup config(mConfig, QStringLiteral(
"Yearprint"));
83 config.writeEntry(
"Year", mYear);
84 config.writeEntry(
"Pages", mPages);
85 config.writeEntry(
"Pages", mPages);
86 config.writeEntry(
"ShowSubDayEventsAs", mSubDaysEvents);
87 config.writeEntry(
"ShowHolidaysAs", mHolidaysEvents);
97void CalPrintYear::setDateRange(
const QDate &from,
const QDate &to)
100 auto cfg =
dynamic_cast<CalPrintYearConfig *
>((
QWidget *)mConfigWidget);
102 cfg->mYear->setValue(from.
year());
106void CalPrintYear::print(
QPainter &p,
int width,
int height)
119 const int months = 12;
121 for (
int i = 1; i < months; ++i) {
122 maxdays = qMax(maxdays, temp.daysInMonth());
123 temp = temp.addMonths(1);
128 int monthsPerPage = (months - 1) / mPages + 1;
129 int pages = (months - 1) / monthsPerPage + 1;
132 for (
int page = 0; page < pages; ++page) {
140 QString title =
i18nc(
"date from-to",
"%1\u2013%2", stdate, endate);
143 QRect monthesBox(headerBox);
144 monthesBox.setTop(monthesBox.bottom() + padding());
145 monthesBox.setBottom(height);
147 drawBox(p, BOX_BORDER_WIDTH, monthesBox);
148 float monthwidth = float(monthesBox.width()) / float(monthsPerPage);
150 for (
int j = 0; j < monthsPerPage; ++j) {
151 if (++thismonth > months) {
154 int xstart =
static_cast<int>(j * monthwidth + 0.5);
155 int xend =
static_cast<int>((j + 1) * monthwidth + 0.5);
156 QRect monthBox(xstart, monthesBox.top(), xend - xstart, monthesBox.height());
157 drawMonth(p, temp, monthBox, maxdays, mSubDaysEvents, mHolidaysEvents);
159 temp = temp.addMonths(1);
int drawHeader(QPainter &p, const QString &title, QDate month1, QDate month2, QRect box, bool expand=false, QColor backColor=QColor())
Draw the gray header bar of the printout to the QPainter.
int footerHeight() const
Returns the height of the page footer.
bool mExcludePrivate
Whether or not to print incidences with secrecy "private".
static void drawBox(QPainter &p, int linewidth, QRect rect)
Draw a box with given width at the given coordinates.
int headerHeight() const
Returns the height of the page header.
void drawMonth(QPainter &p, QDate dt, QRect box, int maxdays=-1, int subDailyFlags=TimeBoxes, int holidaysFlags=Text)
Draw a vertical representation of the month containing the date dt.
int drawFooter(QPainter &p, QRect box)
Draw a page footer containing the printing date and possibly other things, like a page number.
bool mExcludeConfidential
Whether or not to print incidences with secrecy "confidential".
void doSaveConfig() override
Save complete configuration.
void doLoadConfig() override
Load complete configuration.
bool mPrintFooter
Whether or not to print a footer at the bottoms of pages.
virtual void setDateRange(const QDate &from, const QDate &to)
Set date range which should be printed.
QPrinter * mPrinter
The printer object.
Q_SCRIPTABLE Q_NOREPLY void start()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
const QList< QKeySequence > & end()
virtual bool newPage() override
QString number(double n, char format, int precision)