| 1 |
/* This file is part of the KDE project |
| 2 |
* SPDX-FileCopyrightText: 2007, 2010 Thomas Zander <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
// clazy:excludeall=qstring-arg |
| 8 |
#include "KoPageLayoutDialog.h" |
| 9 |
|
| 10 |
#include "KoPageLayoutWidget.h" |
| 11 |
#include "KoPagePreviewWidget.h" |
| 12 |
|
| 13 |
#include <KLocalizedString> |
| 14 |
#include <WidgetsDebug.h> |
| 15 |
|
| 16 |
#include <QCheckBox> |
| 17 |
#include <QDialogButtonBox> |
| 18 |
#include <QHBoxLayout> |
| 19 |
#include <QTimer> |
| 20 |
|
| 21 |
class Q_DECL_HIDDEN KoPageLayoutDialog::Private |
| 22 |
{ |
| 23 |
public: |
| 24 |
Private() : pageLayoutWidget(nullptr), documentCheckBox(nullptr) {} |
| 25 |
KoPageLayoutWidget *pageLayoutWidget; |
| 26 |
QCheckBox *documentCheckBox; |
| 27 |
}; |
| 28 |
|
| 29 |
|
| 30 |
KoPageLayoutDialog::KoPageLayoutDialog(QWidget *parent, const KoPageLayout &layout) |
| 31 |
: KPageDialog(parent) |
| 32 |
, d(new Private) |
| 33 |
{ |
| 34 |
setWindowTitle(i18n("Page Layout")); |
| 35 |
setFaceType(KPageDialog::Tabbed); |
| 36 |
|
| 37 |
QWidget *widget = new QWidget(this); |
| 38 |
addPage(widget, i18n("Page")); |
| 39 |
|
| 40 |
QHBoxLayout *lay = new QHBoxLayout(widget); |
| 41 |
|
| 42 |
d->pageLayoutWidget = new KoPageLayoutWidget(widget, layout); |
| 43 |
d->pageLayoutWidget->showUnitchooser(false); |
| 44 |
lay->addWidget(d->pageLayoutWidget,1); |
| 45 |
|
| 46 |
KoPagePreviewWidget *prev = new KoPagePreviewWidget(widget); |
| 47 |
// use not original layout, but "fixed" one (e.g. with 0 values) as now hold by pageLayoutWidget |
| 48 |
prev->setPageLayout(d->pageLayoutWidget->pageLayout()); |
| 49 |
lay->addWidget(prev, 1); |
| 50 |
|
| 51 |
connect (d->pageLayoutWidget, &KoPageLayoutWidget::layoutChanged, |
| 52 |
prev, &KoPagePreviewWidget::setPageLayout); |
| 53 |
connect (d->pageLayoutWidget, &KoPageLayoutWidget::layoutChanged, |
| 54 |
this, &KoPageLayoutDialog::setPageLayout); |
| 55 |
connect (d->pageLayoutWidget, &KoPageLayoutWidget::unitChanged, |
| 56 |
this, &KoPageLayoutDialog::unitChanged); |
| 57 |
} |
| 58 |
|
| 59 |
KoPageLayoutDialog::~KoPageLayoutDialog() |
| 60 |
{ |
| 61 |
delete d; |
| 62 |
} |
| 63 |
|
| 64 |
KoPageLayout KoPageLayoutDialog::pageLayout() const |
| 65 |
{ |
| 66 |
return d->pageLayoutWidget->pageLayout(); |
| 67 |
} |
| 68 |
|
| 69 |
void KoPageLayoutDialog::setPageLayout(const KoPageLayout &layout) |
| 70 |
{ |
| 71 |
d->pageLayoutWidget->setPageLayout(layout); |
| 72 |
} |
| 73 |
|
| 74 |
void KoPageLayoutDialog::accept() |
| 75 |
{ |
| 76 |
KPageDialog::accept(); |
| 77 |
deleteLater(); |
| 78 |
} |
| 79 |
|
| 80 |
void KoPageLayoutDialog::reject() |
| 81 |
{ |
| 82 |
KPageDialog::reject(); |
| 83 |
deleteLater(); |
| 84 |
} |
| 85 |
|
| 86 |
bool KoPageLayoutDialog::applyToDocument() const |
| 87 |
{ |
| 88 |
return d->documentCheckBox && d->documentCheckBox->isChecked(); |
| 89 |
} |
| 90 |
|
| 91 |
void KoPageLayoutDialog::showApplyToDocument(bool on) |
| 92 |
{ |
| 93 |
if (on && d->documentCheckBox == nullptr) { |
| 94 |
for (int i = 0; i < children().count(); ++i) { |
| 95 |
if (QDialogButtonBox *buttonBox = qobject_cast<QDialogButtonBox*>(children()[i])) { |
| 96 |
d->documentCheckBox = new QCheckBox(i18n("Apply to document"), buttonBox); |
| 97 |
d->documentCheckBox->setChecked(true); |
| 98 |
buttonBox->addButton(d->documentCheckBox, QDialogButtonBox::ResetRole); |
| 99 |
break; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
Q_ASSERT(d->pageLayoutWidget); |
| 104 |
connect (d->documentCheckBox, &QAbstractButton::toggled, |
| 105 |
d->pageLayoutWidget, &KoPageLayoutWidget::setApplyToDocument); |
| 106 |
} else if (d->documentCheckBox) { |
| 107 |
d->documentCheckBox->setVisible(on); |
| 108 |
} |
| 109 |
} |
| 110 |
/* |
| 111 |
void KoPageLayoutDialog::showTextDirection(bool on) |
| 112 |
{ |
| 113 |
d->pageLayoutWidget->showTextDirection(on); |
| 114 |
} |
| 115 |
|
| 116 |
KoText::Direction KoPageLayoutDialog::textDirection() const |
| 117 |
{ |
| 118 |
return d->pageLayoutWidget->textDirection(); |
| 119 |
} |
| 120 |
|
| 121 |
void KoPageLayoutDialog::setTextDirection(KoText::Direction direction) |
| 122 |
{ |
| 123 |
d->pageLayoutWidget->setTextDirection(direction); |
| 124 |
} |
| 125 |
*/ |
| 126 |
void KoPageLayoutDialog::showPageSpread(bool on) |
| 127 |
{ |
| 128 |
d->pageLayoutWidget->showPageSpread(on); |
| 129 |
} |
| 130 |
|
| 131 |
void KoPageLayoutDialog::setPageSpread(bool pageSpread) |
| 132 |
{ |
| 133 |
d->pageLayoutWidget->setPageSpread(pageSpread); |
| 134 |
} |
| 135 |
|
| 136 |
void KoPageLayoutDialog::showUnitchooser(bool on) |
| 137 |
{ |
| 138 |
d->pageLayoutWidget->showUnitchooser(on); |
| 139 |
} |
| 140 |
/* |
| 141 |
void KoPageLayoutDialog::setUnit(const KoUnit &unit) |
| 142 |
{ |
| 143 |
d->pageLayoutWidget->setUnit(unit); |
| 144 |
} |
| 145 |
*/ |