Warning, file /office/calligra/libs/widgets/KoPageLayoutDialog.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2007,2010 Thomas Zander <zander@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoPageLayoutDialog.h" 0021 0022 #include "KoPageLayoutWidget.h" 0023 #include "KoPagePreviewWidget.h" 0024 0025 #include <klocalizedstring.h> 0026 #include <WidgetsDebug.h> 0027 0028 #include <QCheckBox> 0029 #include <QDialogButtonBox> 0030 #include <QHBoxLayout> 0031 #include <QTimer> 0032 0033 class Q_DECL_HIDDEN KoPageLayoutDialog::Private 0034 { 0035 public: 0036 Private() : pageLayoutWidget(0), documentCheckBox(0) {} 0037 KoPageLayoutWidget *pageLayoutWidget; 0038 QCheckBox *documentCheckBox; 0039 }; 0040 0041 0042 KoPageLayoutDialog::KoPageLayoutDialog(QWidget *parent, const KoPageLayout &layout) 0043 : KPageDialog(parent) 0044 , d(new Private) 0045 { 0046 setWindowTitle(i18n("Page Layout")); 0047 setFaceType(KPageDialog::Tabbed); 0048 0049 QWidget *widget = new QWidget(this); 0050 addPage(widget, i18n("Page")); 0051 0052 QHBoxLayout *lay = new QHBoxLayout(widget); 0053 0054 d->pageLayoutWidget = new KoPageLayoutWidget(widget, layout); 0055 d->pageLayoutWidget->showUnitchooser(false); 0056 lay->addWidget(d->pageLayoutWidget,1); 0057 0058 KoPagePreviewWidget *prev = new KoPagePreviewWidget(widget); 0059 // use not original layout, but "fixed" one (e.g. with 0 values) as now hold by pageLayoutWidget 0060 prev->setPageLayout(d->pageLayoutWidget->pageLayout()); 0061 lay->addWidget(prev, 1); 0062 0063 connect (d->pageLayoutWidget, SIGNAL(layoutChanged(KoPageLayout)), 0064 prev, SLOT(setPageLayout(KoPageLayout))); 0065 connect (d->pageLayoutWidget, SIGNAL(layoutChanged(KoPageLayout)), 0066 this, SLOT(setPageLayout(KoPageLayout))); 0067 connect (d->pageLayoutWidget, SIGNAL(unitChanged(KoUnit)), 0068 this, SIGNAL(unitChanged(KoUnit))); 0069 } 0070 0071 KoPageLayoutDialog::~KoPageLayoutDialog() 0072 { 0073 delete d; 0074 } 0075 0076 KoPageLayout KoPageLayoutDialog::pageLayout() const 0077 { 0078 return d->pageLayoutWidget->pageLayout(); 0079 } 0080 0081 void KoPageLayoutDialog::setPageLayout(const KoPageLayout &layout) 0082 { 0083 d->pageLayoutWidget->setPageLayout(layout); 0084 } 0085 0086 void KoPageLayoutDialog::accept() 0087 { 0088 KPageDialog::accept(); 0089 deleteLater(); 0090 } 0091 0092 void KoPageLayoutDialog::reject() 0093 { 0094 KPageDialog::reject(); 0095 deleteLater(); 0096 } 0097 0098 bool KoPageLayoutDialog::applyToDocument() const 0099 { 0100 return d->documentCheckBox && d->documentCheckBox->isChecked(); 0101 } 0102 0103 void KoPageLayoutDialog::showApplyToDocument(bool on) 0104 { 0105 if (on && d->documentCheckBox == 0) { 0106 for (int i = 0; i < children().count(); ++i) { 0107 if (QDialogButtonBox *buttonBox = qobject_cast<QDialogButtonBox*>(children()[i])) { 0108 d->documentCheckBox = new QCheckBox(i18n("Apply to document"), buttonBox); 0109 d->documentCheckBox->setChecked(true); 0110 buttonBox->addButton(d->documentCheckBox, QDialogButtonBox::ResetRole); 0111 break; 0112 } 0113 } 0114 0115 Q_ASSERT(d->pageLayoutWidget); 0116 connect (d->documentCheckBox, SIGNAL(toggled(bool)), 0117 d->pageLayoutWidget, SLOT(setApplyToDocument(bool))); 0118 } else if (d->documentCheckBox) { 0119 d->documentCheckBox->setVisible(on); 0120 } 0121 } 0122 0123 void KoPageLayoutDialog::showTextDirection(bool on) 0124 { 0125 d->pageLayoutWidget->showTextDirection(on); 0126 } 0127 0128 KoText::Direction KoPageLayoutDialog::textDirection() const 0129 { 0130 return d->pageLayoutWidget->textDirection(); 0131 } 0132 0133 void KoPageLayoutDialog::setTextDirection(KoText::Direction direction) 0134 { 0135 d->pageLayoutWidget->setTextDirection(direction); 0136 } 0137 0138 void KoPageLayoutDialog::showPageSpread(bool on) 0139 { 0140 d->pageLayoutWidget->showPageSpread(on); 0141 } 0142 0143 void KoPageLayoutDialog::setPageSpread(bool pageSpread) 0144 { 0145 d->pageLayoutWidget->setPageSpread(pageSpread); 0146 } 0147 0148 void KoPageLayoutDialog::showUnitchooser(bool on) 0149 { 0150 d->pageLayoutWidget->showUnitchooser(on); 0151 } 0152 0153 void KoPageLayoutDialog::setUnit(const KoUnit &unit) 0154 { 0155 d->pageLayoutWidget->setUnit(unit); 0156 } 0157