diff --git a/src/archivedialog.cpp b/src/archivedialog.cpp index ecc68bb..939ab99 100644 --- a/src/archivedialog.cpp +++ b/src/archivedialog.cpp @@ -1,342 +1,342 @@ /* Copyright (c) 2000,2001 Cornelius Schumacher Copyright (C) 2003-2004 Reinhold Kainhofer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ // ArchiveDialog -- archive/delete past events. #include "archivedialog.h" #include "eventarchiver.h" #include "kcalprefs.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace CalendarSupport; ArchiveDialog::ArchiveDialog(const Akonadi::ETMCalendar::Ptr &cal, Akonadi::IncidenceChanger *changer, QWidget *parent) : QDialog(parent) { setWindowTitle(i18nc("@title:window", "Archive/Delete Past Events and To-dos")); QVBoxLayout *mainLayout = new QVBoxLayout(this); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel, this); mUser1Button = new QPushButton; buttonBox->addButton(mUser1Button, QDialogButtonBox::ActionRole); connect(buttonBox, &QDialogButtonBox::rejected, this, &ArchiveDialog::reject); mUser1Button->setDefault(true); setModal(false); mUser1Button->setText(i18nc("@action:button", "&Archive")); mCalendar = cal; mChanger = changer; QFrame *topFrame = new QFrame(this); mainLayout->addWidget(topFrame); mainLayout->addWidget(buttonBox); QVBoxLayout *topLayout = new QVBoxLayout(topFrame); - topLayout->setMargin(0); + topLayout->setContentsMargins(0, 0, 0, 0); QLabel *descLabel = new QLabel(topFrame); descLabel->setText( xi18nc("@info:whatsthis", "Archiving saves old items into the given file and " "then deletes them in the current calendar. If the archive file " "already exists they will be added. " "(How to restore)")); descLabel->setWhatsThis( i18nc("@info:whatsthis", "In order to add an archive to your calendar, use the Merge Calendar " "function. You can view an archive by opening it like you would any " "other calendar. It is not saved in a special format, but as " "vCalendar.")); descLabel->setTextInteractionFlags( Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard |Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard); descLabel->setWordWrap(true); descLabel->setContextMenuPolicy(Qt::NoContextMenu); topLayout->addWidget(descLabel); connect(descLabel, &QLabel::linkActivated, this, &ArchiveDialog::showWhatsThis); QButtonGroup *radioBG = new QButtonGroup(this); connect(radioBG, QOverload::of( &QButtonGroup::buttonClicked), this, &ArchiveDialog::slotActionChanged); QHBoxLayout *dateLayout = new QHBoxLayout(); - dateLayout->setMargin(0); + dateLayout->setContentsMargins(0, 0, 0, 0); mArchiveOnceRB = new QRadioButton(i18nc("@option:radio", "Archive now items older than:"), topFrame); mArchiveOnceRB->setToolTip( i18nc("@info:tooltip", "Enable one time archiving or purging of older items")); mArchiveOnceRB->setWhatsThis( i18nc("@info:whatsthis", "If you check this box, events and to-dos older than the specified age " "will be archived or purged. The items will be archived unless the " "\"Delete only\" option is enabled; else the items will be purged " "and not saved.")); dateLayout->addWidget(mArchiveOnceRB); radioBG->addButton(mArchiveOnceRB); mDateEdit = new KDateComboBox(topFrame); mDateEdit->setToolTip( i18nc("@info:tooltip", "Set the one time archiving cut-off date")); mDateEdit->setWhatsThis( i18nc("@info:whatsthis", "The date before which items should be archived. All older events " "and to-dos will be saved and deleted, the newer (and events " "exactly on that date) will be kept.")); dateLayout->addWidget(mDateEdit); topLayout->addLayout(dateLayout); // Checkbox, numinput and combo for auto-archiving (similar to kmail's // mExpireFolderCheckBox/mReadExpiryTimeNumInput in kmfolderdia.cpp) QWidget *autoArchiveHBox = new QWidget(topFrame); QHBoxLayout *autoArchiveHBoxHBoxLayout = new QHBoxLayout(autoArchiveHBox); - autoArchiveHBoxHBoxLayout->setMargin(0); + autoArchiveHBoxHBoxLayout->setContentsMargins(0, 0, 0, 0); topLayout->addWidget(autoArchiveHBox); mAutoArchiveRB = new QRadioButton(i18nc("@option:radio", "Automaticall&y archive items older than:"), autoArchiveHBox); mAutoArchiveRB->setToolTip( i18nc("@info:tooltip", "Enable automatic archiving or purging of older items")); mAutoArchiveRB->setWhatsThis( i18nc("@info:whatsthis", "If this feature is enabled, the application will regularly check if " "events and to-dos have to be archived; this means you will not " "need to use this dialog box again, except to change the settings.")); radioBG->addButton(mAutoArchiveRB); autoArchiveHBoxHBoxLayout->addWidget(mAutoArchiveRB); mExpiryTimeNumInput = new QSpinBox(autoArchiveHBox); autoArchiveHBoxHBoxLayout->addWidget(mExpiryTimeNumInput); mExpiryTimeNumInput->setRange(1, 500); mExpiryTimeNumInput->setSingleStep(1); mExpiryTimeNumInput->setEnabled(false); mExpiryTimeNumInput->setValue(7); mExpiryTimeNumInput->setToolTip( i18nc("@info:tooltip", "Set the archival age in days, weeks or months")); mExpiryTimeNumInput->setWhatsThis( i18nc("@info:whatsthis", "The age of the events and to-dos to archive. All older items " "will be saved and deleted, the newer will be kept.")); mExpiryUnitsComboBox = new KComboBox(autoArchiveHBox); autoArchiveHBoxHBoxLayout->addWidget(mExpiryUnitsComboBox); mExpiryUnitsComboBox->setToolTip( i18nc("@info:tooltip", "Set the units for the automatic archive age")); mExpiryUnitsComboBox->setWhatsThis( i18nc("@info:whatsthis", "Select the time units (days, weeks or months) for automatic archiving.")); // Those items must match the "Expiry Unit" enum in the kcfg file! mExpiryUnitsComboBox->addItem( i18nc("@item:inlistbox expires in daily units", "Day(s)")); mExpiryUnitsComboBox->addItem( i18nc("@item:inlistbox expiration in weekly units", "Week(s)")); mExpiryUnitsComboBox->addItem( i18nc("@item:inlistbox expiration in monthly units", "Month(s)")); mExpiryUnitsComboBox->setEnabled(false); QHBoxLayout *fileLayout = new QHBoxLayout(); - fileLayout->setMargin(0); + fileLayout->setContentsMargins(0, 0, 0, 0); QLabel *l = new QLabel(i18nc("@label", "Archive &file:"), topFrame); fileLayout->addWidget(l); mArchiveFile = new KUrlRequester(QUrl::fromLocalFile( KCalPrefs::instance()->mArchiveFile), topFrame); mArchiveFile->setMode(KFile::File); mArchiveFile->setFilter(i18nc("@label filter for KUrlRequester", "*.ics|iCalendar Files")); mArchiveFile->setToolTip( i18nc("@info:tooltip", "Set the location of the archive")); mArchiveFile->setWhatsThis( i18nc("@info:whatsthis", "The path of the archive file. The events and to-dos will be appended " "to the specified file, so any events that are already in the file " "will not be modified or deleted. You can later load or merge the " "file like any other calendar. It is not saved in a special " "format, it uses the iCalendar format.")); l->setBuddy(mArchiveFile->lineEdit()); fileLayout->addWidget(mArchiveFile); topLayout->addLayout(fileLayout); QGroupBox *typeBox = new QGroupBox(i18nc("@title:group", "Type of Items to Archive")); typeBox->setWhatsThis( i18nc("@info:whatsthis", "Here you can select which items " "should be archived. Events are archived if they " "ended before the date given above; to-dos are archived if " "they were finished before the date.")); topLayout->addWidget(typeBox); QBoxLayout *typeLayout = new QVBoxLayout(typeBox); mEvents = new QCheckBox(i18nc("@option:check", "Archive &Events")); mEvents->setToolTip( i18nc("@option:check", "Archive or purge events")); mEvents->setWhatsThis( i18nc("@info:whatsthis", "Select this option to archive events if they ended before the date given above.")); typeLayout->addWidget(mEvents); mTodos = new QCheckBox(i18nc("@option:check", "Archive Completed &To-dos")); mTodos->setToolTip( i18nc("@option:check", "Archive or purge completed to-dos")); mTodos->setWhatsThis( i18nc("@info:whatsthis", "Select this option to archive to-dos if they were completed " "before the date given above.")); typeLayout->addWidget(mTodos); mDeleteCb = new QCheckBox(i18nc("@option:check", "&Delete only, do not save"), topFrame); mDeleteCb->setToolTip( i18nc("@info:tooltip", "Purge the old items without saving them")); mDeleteCb->setWhatsThis( i18nc("@info:whatsthis", "Select this option to delete old events and to-dos without saving " "them. It is not possible to recover the events later.")); topLayout->addWidget(mDeleteCb); connect(mDeleteCb, &QCheckBox::toggled, mArchiveFile, &KUrlRequester::setDisabled); connect(mDeleteCb, &QCheckBox::toggled, this, &ArchiveDialog::slotEnableUser1); connect(mArchiveFile->lineEdit(), &QLineEdit::textChanged, this, &ArchiveDialog::slotEnableUser1); // Load settings from KCalPrefs mExpiryTimeNumInput->setValue(KCalPrefs::instance()->mExpiryTime); mExpiryUnitsComboBox->setCurrentIndex(KCalPrefs::instance()->mExpiryUnit); mDeleteCb->setChecked(KCalPrefs::instance()->mArchiveAction == KCalPrefs::actionDelete); mEvents->setChecked(KCalPrefs::instance()->mArchiveEvents); mTodos->setChecked(KCalPrefs::instance()->mArchiveTodos); slotEnableUser1(); // The focus should go to a useful field by default, not to the top richtext-label if (KCalPrefs::instance()->mAutoArchive) { mAutoArchiveRB->setChecked(true); mAutoArchiveRB->setFocus(); } else { mArchiveOnceRB->setChecked(true); mArchiveOnceRB->setFocus(); } slotActionChanged(); connect(mUser1Button, &QPushButton::clicked, this, &ArchiveDialog::slotUser1); } ArchiveDialog::~ArchiveDialog() { } void ArchiveDialog::slotEnableUser1() { const bool state = (mDeleteCb->isChecked() || !mArchiveFile->lineEdit()->text().trimmed().isEmpty()); mUser1Button->setEnabled(state); } void ArchiveDialog::slotActionChanged() { mDateEdit->setEnabled(mArchiveOnceRB->isChecked()); mExpiryTimeNumInput->setEnabled(mAutoArchiveRB->isChecked()); mExpiryUnitsComboBox->setEnabled(mAutoArchiveRB->isChecked()); } // Archive old events void ArchiveDialog::slotUser1() { EventArchiver archiver; connect(&archiver, &EventArchiver::eventsDeleted, this, &ArchiveDialog::slotEventsDeleted); KCalPrefs::instance()->mAutoArchive = mAutoArchiveRB->isChecked(); KCalPrefs::instance()->mExpiryTime = mExpiryTimeNumInput->value(); KCalPrefs::instance()->mExpiryUnit = mExpiryUnitsComboBox->currentIndex(); if (mDeleteCb->isChecked()) { KCalPrefs::instance()->mArchiveAction = KCalPrefs::actionDelete; } else { KCalPrefs::instance()->mArchiveAction = KCalPrefs::actionArchive; // Get destination URL QUrl destUrl(mArchiveFile->url()); if (!destUrl.isValid()) { KMessageBox::sorry(this, i18nc("@info", "The archive file name is not valid.")); return; } // Force filename to be ending with vCalendar extension QString filename = destUrl.fileName(); if (!filename.endsWith(QLatin1String(".vcs")) && !filename.endsWith(QLatin1String(".ics"))) { filename.append(QLatin1String(".ics")); destUrl = destUrl.adjusted(QUrl::RemoveFilename); destUrl.setPath(destUrl.path() + filename); } KCalPrefs::instance()->mArchiveFile = destUrl.url(); } if (KCalPrefs::instance()->mAutoArchive) { archiver.runAuto(mCalendar, mChanger, this, true /*with gui*/); Q_EMIT autoArchivingSettingsModified(); accept(); } else { archiver.runOnce(mCalendar, mChanger, mDateEdit->date(), this); accept(); } } void ArchiveDialog::slotEventsDeleted() { Q_EMIT eventsDeleted(); if (!KCalPrefs::instance()->mAutoArchive) { accept(); } } void ArchiveDialog::showWhatsThis() { QWidget *widget = qobject_cast< QWidget * >(sender()); if (widget && !widget->whatsThis().isEmpty()) { QWhatsThis::showText(QCursor::pos(), widget->whatsThis()); } } diff --git a/src/next/incidenceviewer.cpp b/src/next/incidenceviewer.cpp index 5203c54..e523794 100644 --- a/src/next/incidenceviewer.cpp +++ b/src/next/incidenceviewer.cpp @@ -1,257 +1,257 @@ /* Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company Author: Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "incidenceviewer.h" #include "incidenceviewer_p.h" #include "attachmenthandler.h" #include "utils.h" #include "KdepimDBusInterfaces/UriHandler" #include "incidenceattachmentmodel.h" #include #include #include #include #include #include #include using namespace CalendarSupport; TextBrowser::TextBrowser(QWidget *parent) : QTextBrowser(parent) { setFrameStyle(QFrame::NoFrame); } void TextBrowser::setSource(const QUrl &name) { QString uri = name.toString(); // QTextBrowser for some reason insists on putting // or / in links, // this is a crude workaround if (uri.startsWith(QLatin1String("uid:")) || uri.startsWith(QLatin1String("kmail:")) || uri.startsWith(QStringLiteral("urn:x-ical").section(QLatin1Char(':'), 0, 0)) || uri.startsWith(QLatin1String("news:")) || uri.startsWith(QLatin1String("mailto:"))) { uri.replace(QRegExp(QLatin1String("^([^:]+:)/+")), QStringLiteral("\\1")); } if (uri.startsWith(QStringLiteral("ATTACH:"))) { Q_EMIT attachmentUrlClicked(uri); } else { UriHandler::process(uri); } } class Q_DECL_HIDDEN IncidenceViewer::Private { public: Private(IncidenceViewer *parent) : mCalendar(nullptr) , mParent(parent) , mParentCollectionFetchJob(nullptr) , mAttachmentModel(nullptr) , mDelayedClear(false) { mAttachmentHandler = new AttachmentHandler(parent); mBrowser = new TextBrowser; parent->connect(mBrowser, &TextBrowser::attachmentUrlClicked, parent, [this](const QString &str) { slotAttachmentUrlClicked(str); }); } void updateView() { QString text; if (mCurrentItem.isValid()) { text = KCalUtils::IncidenceFormatter::extensiveDisplayStr( CalendarSupport::displayName(mCalendar, mParentCollection), CalendarSupport::incidence(mCurrentItem), mDate); text.prepend(mHeaderText); mBrowser->setHtml(text); } else { text = mDefaultText; if (!mDelayedClear) { mBrowser->setHtml(text); } } } void slotParentCollectionFetched(KJob *job) { mParentCollectionFetchJob = nullptr; mParentCollection = Akonadi::Collection(); if (!job->error()) { Akonadi::CollectionFetchJob *fetchJob = qobject_cast(job); if (!fetchJob->collections().isEmpty()) { mParentCollection = fetchJob->collections().at(0); } } updateView(); } void slotAttachmentUrlClicked(const QString &uri) { const QString attachmentName = QString::fromUtf8(QByteArray::fromBase64(uri.mid(7).toUtf8())); mAttachmentHandler->view(attachmentName, CalendarSupport::incidence(mCurrentItem)); } Akonadi::ETMCalendar *mCalendar = nullptr; IncidenceViewer *mParent = nullptr; TextBrowser *mBrowser = nullptr; Akonadi::Item mCurrentItem; QString mHeaderText; QString mDefaultText; Akonadi::Collection mParentCollection; Akonadi::CollectionFetchJob *mParentCollectionFetchJob = nullptr; IncidenceAttachmentModel *mAttachmentModel = nullptr; AttachmentHandler *mAttachmentHandler = nullptr; QDate mDate; bool mDelayedClear = false; }; IncidenceViewer::IncidenceViewer(Akonadi::ETMCalendar *calendar, QWidget *parent) : QWidget(parent) , d(new Private(this)) { d->mCalendar = calendar; init(); } IncidenceViewer::IncidenceViewer(QWidget *parent) : QWidget(parent) , d(new Private(this)) { d->mCalendar = nullptr; init(); } void IncidenceViewer::init() { QVBoxLayout *layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); d->mBrowser->setOpenLinks(true); d->mBrowser->setMinimumHeight(1); layout->addWidget(d->mBrowser); // always fetch full payload for incidences fetchScope().fetchFullPayload(); fetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent); d->updateView(); } IncidenceViewer::~IncidenceViewer() { delete d; } void IncidenceViewer::setCalendar(Akonadi::ETMCalendar *calendar) { d->mCalendar = calendar; } Akonadi::Item IncidenceViewer::incidence() const { return ItemMonitor::item(); } QDate IncidenceViewer::activeDate() const { return d->mDate; } QAbstractItemModel *IncidenceViewer::attachmentModel() const { if (!d->mAttachmentModel) { d->mAttachmentModel = new IncidenceAttachmentModel(const_cast(this)); } return d->mAttachmentModel; } void IncidenceViewer::setDelayedClear(bool delayed) { d->mDelayedClear = delayed; } void IncidenceViewer::setDefaultMessage(const QString &message) { d->mDefaultText = message; } void IncidenceViewer::setHeaderText(const QString &text) { d->mHeaderText = text; } void IncidenceViewer::setIncidence(const Akonadi::Item &incidence, const QDate &date) { d->mDate = date; ItemMonitor::setItem(incidence); d->updateView(); } void IncidenceViewer::itemChanged(const Akonadi::Item &item) { if (!item.hasPayload()) { d->mBrowser->clear(); return; } d->mCurrentItem = item; if (d->mAttachmentModel) { d->mAttachmentModel->setItem(d->mCurrentItem); } if (d->mParentCollectionFetchJob) { disconnect(d->mParentCollectionFetchJob, SIGNAL(result(KJob*)), this, SLOT(slotParentCollectionFetched(KJob*))); delete d->mParentCollectionFetchJob; } d->mParentCollectionFetchJob = new Akonadi::CollectionFetchJob(d->mCurrentItem.parentCollection(), Akonadi::CollectionFetchJob::Base, this); connect(d->mParentCollectionFetchJob, SIGNAL(result(KJob*)), this, SLOT(slotParentCollectionFetched(KJob*))); } void IncidenceViewer::itemRemoved() { d->mCurrentItem = Akonadi::Item(); d->mBrowser->clear(); } #include "moc_incidenceviewer.cpp" #include "moc_incidenceviewer_p.cpp" diff --git a/src/printing/calprinter.cpp b/src/printing/calprinter.cpp index feac09f..5fce8b1 100644 --- a/src/printing/calprinter.cpp +++ b/src/printing/calprinter.cpp @@ -1,342 +1,342 @@ /* Copyright (c) 1998 Preston Brown Copyright (C) 2003-2004 Reinhold Kainhofer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include "calprinter.h" #include "calprintdefaultplugins.h" #include "journalprint.h" #include "yearprint.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace CalendarSupport; CalPrinter::CalPrinter(QWidget *parent, const Akonadi::ETMCalendar::Ptr &calendar, bool uniqItem) : QObject(parent) , mUniqItem(uniqItem) { mParent = parent; mConfig = new KConfig(QStringLiteral("calendar_printing.rc"), KConfig::SimpleConfig); init(calendar); } CalPrinter::~CalPrinter() { mPrintPlugins.clear(); delete mConfig; } void CalPrinter::init(const Akonadi::ETMCalendar::Ptr &calendar) { mCalendar = calendar; mPrintPlugins.clear(); if (!mUniqItem) { mPrintPlugins.prepend(new CalPrintYear()); mPrintPlugins.prepend(new CalPrintJournal()); mPrintPlugins.prepend(new CalPrintTodos()); mPrintPlugins.prepend(new CalPrintMonth()); mPrintPlugins.prepend(new CalPrintWeek()); mPrintPlugins.prepend(new CalPrintDay()); } mPrintPlugins.prepend(new CalPrintIncidence()); PrintPlugin::List::Iterator it = mPrintPlugins.begin(); PrintPlugin::List::Iterator end = mPrintPlugins.end(); for (; it != end; ++it) { if (*it) { (*it)->setConfig(mConfig); (*it)->setCalendar(mCalendar); (*it)->doLoadConfig(); } } } void CalPrinter::setDateRange(const QDate &fd, const QDate &td) { PrintPlugin::List::Iterator it = mPrintPlugins.begin(); const PrintPlugin::List::Iterator end = mPrintPlugins.end(); for (; it != end; ++it) { (*it)->setDateRange(fd, td); } } void CalPrinter::print(int type, const QDate &fd, const QDate &td, const KCalCore::Incidence::List &selectedIncidences, bool preview) { PrintPlugin::List::Iterator it; const PrintPlugin::List::Iterator end = mPrintPlugins.end(); for (it = mPrintPlugins.begin(); it != end; ++it) { (*it)->setSelectedIncidences(selectedIncidences); } QPointer printDialog = new CalPrintDialog(type, mPrintPlugins, mParent, mUniqItem); KConfigGroup grp(mConfig, ""); //orientation setting isn't in a group printDialog->setOrientation(CalPrinter::ePrintOrientation(grp.readEntry("Orientation", 1))); printDialog->setPreview(preview); setDateRange(fd, td); if (printDialog->exec() == QDialog::Accepted) { grp.writeEntry("Orientation", static_cast(printDialog->orientation())); // Save all changes in the dialog for (it = mPrintPlugins.begin(); it != mPrintPlugins.end(); ++it) { (*it)->doSaveConfig(); } doPrint(printDialog->selectedPlugin(), printDialog->orientation(), preview); } delete printDialog; for (it = mPrintPlugins.begin(); it != mPrintPlugins.end(); ++it) { (*it)->setSelectedIncidences(KCalCore::Incidence::List()); } } void CalPrinter::doPrint(PrintPlugin *selectedStyle, CalPrinter::ePrintOrientation dlgorientation, bool preview) { if (!selectedStyle) { KMessageBox::error( mParent, i18nc("@info", "Unable to print, an invalid print style was specified."), i18nc("@title:window", "Printing error")); return; } QPrinter printer; switch (dlgorientation) { case eOrientPlugin: printer.setOrientation(selectedStyle->defaultOrientation()); break; case eOrientPortrait: printer.setOrientation(QPrinter::Portrait); break; case eOrientLandscape: printer.setOrientation(QPrinter::Landscape); break; case eOrientPrinter: break; } if (preview) { QPointer printPreview = new PimCommon::KPimPrintPreviewDialog(&printer); connect(printPreview.data(), &QPrintPreviewDialog::paintRequested, this, [selectedStyle, &printer]() { selectedStyle->doPrint(&printer); }); printPreview->exec(); delete printPreview; } else { QPointer printDialog = new QPrintDialog(&printer, mParent); if (printDialog->exec() == QDialog::Accepted) { selectedStyle->doPrint(&printer); } delete printDialog; } } void CalPrinter::updateConfig() { } CalPrintDialog::CalPrintDialog(int initialPrintType, const PrintPlugin::List &plugins, QWidget *parent, bool uniqItem) : QDialog(parent) { setWindowTitle(i18nc("@title:window", "Print")); QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); QVBoxLayout *mainLayout = new QVBoxLayout(this); mOkButton = buttonBox->button(QDialogButtonBox::Ok); mOkButton->setDefault(true); mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, &QDialogButtonBox::accepted, this, &CalPrintDialog::slotOk); connect(buttonBox, &QDialogButtonBox::rejected, this, &CalPrintDialog::reject); setModal(true); QWidget *page = new QWidget(this); QVBoxLayout *pageVBoxLayout = new QVBoxLayout(page); - pageVBoxLayout->setMargin(0); + pageVBoxLayout->setContentsMargins(0, 0, 0, 0); mainLayout->addWidget(page); mainLayout->addWidget(buttonBox); QSplitter *splitter = new QSplitter(page); pageVBoxLayout->addWidget(splitter); splitter->setOrientation(Qt::Horizontal); splitter->setChildrenCollapsible(false); QGroupBox *typeBox = new QGroupBox(i18nc("@title:group", "Print Style"), splitter); QBoxLayout *typeLayout = new QVBoxLayout(typeBox); mTypeGroup = new QButtonGroup(typeBox); QWidget *splitterRight = new QWidget(splitter); QGridLayout *splitterRightLayout = new QGridLayout(splitterRight); - splitterRightLayout->setMargin(0); + splitterRightLayout->setContentsMargins(0, 0, 0, 0); //splitterRightLayout->setMargin( marginHint() ); //splitterRightLayout->setSpacing( spacingHint() ); mConfigArea = new QStackedWidget(splitterRight); splitterRightLayout->addWidget(mConfigArea, 0, 0, 1, 2); QLabel *orientationLabel = new QLabel(i18nc("@label", "Page &orientation:"), splitterRight); orientationLabel->setAlignment(Qt::AlignRight); splitterRightLayout->addWidget(orientationLabel, 1, 0); mOrientationSelection = new KComboBox(splitterRight); mOrientationSelection->setToolTip( i18nc("@info:tooltip", "Set the print orientation")); mOrientationSelection->setWhatsThis( i18nc("@info:whatsthis", "Choose if you want your output to be printed in \"portrait\" or " "\"landscape\". You can also default to the orientation best suited to " "the selected style or to your printer's default setting.")); mOrientationSelection->addItem(i18nc("@item:inlistbox", "Use Default Orientation of Selected Style")); mOrientationSelection->addItem(i18nc("@item:inlistbox", "Use Printer Default")); mOrientationSelection->addItem(i18nc("@item:inlistbox", "Portrait")); mOrientationSelection->addItem(i18nc("@item:inlistbox", "Landscape")); splitterRightLayout->addWidget(mOrientationSelection, 1, 1); // signals and slots connections connect(mTypeGroup, QOverload::of( &QButtonGroup::buttonClicked), this, &CalPrintDialog::setPrintType); orientationLabel->setBuddy(mOrientationSelection); // First insert the config widgets into the widget stack. This possibly assigns // proper ids (when two plugins have the same sortID), so store them in a map // and use these new IDs to later sort the plugins for the type selection. for (PrintPlugin::List::ConstIterator it = plugins.constBegin(), total = plugins.constEnd(); it != total; ++it) { int newid = mConfigArea->insertWidget((*it)->sortID(), (*it)->configWidget(mConfigArea)); mPluginIDs[newid] = (*it); } // Insert all plugins in sorted order; plugins with clashing IDs will be first QMap::ConstIterator mapit; bool firstButton = true; int id = 0; for (mapit = mPluginIDs.constBegin(); mapit != mPluginIDs.constEnd(); ++mapit) { PrintPlugin *p = mapit.value(); QRadioButton *radioButton = new QRadioButton(p->description()); radioButton->setEnabled(p->enabled()); radioButton->setToolTip( i18nc("@info:tooltip", "Select the type of print")); radioButton->setWhatsThis( i18nc("@info:whatsthis", "Select one of the following types of prints you want to make. " "You may want to print an individual item, or all the items for a " "specific time range (like a day, week or month), or you may want " "to print your to-do list.")); // Check the first available button (to ensure one is selected initially) and then // the button matching the desired print type -- if such is available! if ((firstButton || p->sortID() == initialPrintType) && p->enabled()) { firstButton = false; radioButton->setChecked(true); setPrintType(id); } mTypeGroup->addButton(radioButton, mapit.key()); typeLayout->addWidget(radioButton); id++; } if (uniqItem) { typeBox->hide(); } typeLayout->insertStretch(-1, 100); setMinimumSize(minimumSizeHint()); resize(minimumSizeHint()); } CalPrintDialog::~CalPrintDialog() { } void CalPrintDialog::setPreview(bool preview) { if (preview) { mOkButton->setText(i18nc("@action:button", "&Preview")); } else { mOkButton->setText(KStandardGuiItem::print().text()); } } void CalPrintDialog::setPrintType(int i) { mConfigArea->setCurrentIndex(i); mConfigArea->currentWidget()->raise(); QAbstractButton *btn = mTypeGroup->button(i); if (btn) { btn->setChecked(true); } } void CalPrintDialog::setOrientation(CalPrinter::ePrintOrientation orientation) { mOrientation = orientation; mOrientationSelection->setCurrentIndex(mOrientation); } CalPrinter::ePrintOrientation CalPrintDialog::orientation() const { return mOrientation; } PrintPlugin *CalPrintDialog::selectedPlugin() { int id = mConfigArea->currentIndex(); if (mPluginIDs.contains(id)) { return mPluginIDs[id]; } else { return nullptr; } } void CalPrintDialog::slotOk() { mOrientation = static_cast(mOrientationSelection->currentIndex()); QMap::ConstIterator it = mPluginIDs.constBegin(); for (; it != mPluginIDs.constEnd(); ++it) { if (it.value()) { it.value()->readSettingsWidget(); } } accept(); }