KoPageLayoutDia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2005 Thomas Zander <zander@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21// Description: Page Layout Dialog (sources)
22
23/******************************************************************/
24
25#include <KoPageLayoutDia.h>
26#include <KoPageLayoutColumns.h>
27#include <KoPageLayoutSize.h>
28#include <KoPageLayoutHeader.h>
29#include <KoUnit.h>
30#include <KoUnitWidgets.h>
31
32#include <tdelocale.h>
33#include <kiconloader.h>
34#include <tdemessagebox.h>
35
36#include <tqlabel.h>
37#include <tqlayout.h>
38#include <tqpainter.h>
39#include <tqlineedit.h>
40#include <tqbuttongroup.h>
41#include <tqradiobutton.h>
42#include <tqcheckbox.h>
43#include <tqhbox.h>
44#include <tqvgroupbox.h>
45#include <tqhbuttongroup.h>
46
47/******************************************************************/
48/* class KoPagePreview */
49/******************************************************************/
50
51/*===================== constrcutor ==============================*/
52KoPagePreview::KoPagePreview( TQWidget* parent, const char *name, const KoPageLayout& layout )
53 : TQGroupBox( i18n( "Page Preview" ), parent, name )
54{
55 setPageLayout( layout );
56 columns = 1;
57 setMinimumSize( 150, 150 );
58}
59
60/*====================== destructor ==============================*/
64
65/*=================== set layout =================================*/
67{
68 // resolution[XY] is in pixel per pt
69 double resolutionX = POINT_TO_INCH( static_cast<double>(KoGlobal::dpiX()) );
70 double resolutionY = POINT_TO_INCH( static_cast<double>(KoGlobal::dpiY()) );
71
72 m_pageWidth = layout.ptWidth * resolutionX;
73 m_pageHeight = layout.ptHeight * resolutionY;
74
75 double zh = 110.0 / m_pageHeight;
76 double zw = 110.0 / m_pageWidth;
77 double z = TQMIN( zw, zh );
78
79 m_pageWidth *= z;
80 m_pageHeight *= z;
81
82 m_textFrameX = layout.ptLeft * resolutionX * z;
83 m_textFrameY = layout.ptTop * resolutionY * z;
84 m_textFrameWidth = m_pageWidth - ( layout.ptLeft + layout.ptRight ) * resolutionX * z;
85 m_textFrameHeight = m_pageHeight - ( layout.ptTop + layout.ptBottom ) * resolutionY * z;
86
87 repaint( true );
88}
89
90/*=================== set layout =================================*/
91void KoPagePreview::setPageColumns( const KoColumns &_columns )
92{
93 columns = _columns.columns;
94 repaint( true );
95}
96
97/*======================== draw contents =========================*/
98void KoPagePreview::drawContents( TQPainter *painter )
99{
100 double cw = m_textFrameWidth;
101 if(columns!=1)
102 cw/=static_cast<double>(columns);
103
104 painter->setBrush( white );
105 painter->setPen( TQPen( black ) );
106
107 int x=static_cast<int>( ( width() - m_pageWidth ) * 0.5 );
108 int y=static_cast<int>( ( height() - m_pageHeight ) * 0.5 );
109 int w=static_cast<int>(m_pageWidth);
110 int h=static_cast<int>(m_pageHeight);
111 //painter->drawRect( x + 1, y + 1, w, h);
112 painter->drawRect( x, y, w, h );
113
114 painter->setBrush( TQBrush( black, HorPattern ) );
115 if ( m_textFrameWidth == m_pageWidth || m_textFrameHeight == m_pageHeight )
116 painter->setPen( NoPen );
117 else
118 painter->setPen( lightGray );
119
120 for ( int i = 0; i < columns; ++i )
121 painter->drawRect( x + static_cast<int>(m_textFrameX) + static_cast<int>(i * cw),
122 y + static_cast<int>(m_textFrameY), static_cast<int>(cw),
123 static_cast<int>(m_textFrameHeight) );
124}
125
126/******************************************************************/
127/* class KoPageLayoutDia */
128/******************************************************************/
129
130/*==================== constructor ===============================*/
131KoPageLayoutDia::KoPageLayoutDia( TQWidget* parent, const char* name,
132 const KoPageLayout& layout,
133 const KoHeadFoot& hf, int tabs,
134 KoUnit::Unit unit, bool modal )
135 : KDialogBase( KDialogBase::Tabbed, i18n("Page Layout"), KDialogBase::Ok | KDialogBase::Cancel,
136 KDialogBase::Ok, parent, name, modal)
137{
138
139 flags = tabs;
140 m_layout = layout;
141 m_unit = unit;
142 m_pageSizeTab = 0;
143 m_columnsTab = 0;
144 m_headerTab = 0;
145
146 m_column.columns = 1;
147
148 if ( tabs & FORMAT_AND_BORDERS ) setupTab1( true );
149 if ( tabs & HEADER_AND_FOOTER ) setupTab2( hf );
150
151 setFocusPolicy( TQWidget::StrongFocus );
152 setFocus();
153}
154
155/*==================== constructor ===============================*/
156KoPageLayoutDia::KoPageLayoutDia( TQWidget* parent, const char* name,
157 const KoPageLayout& layout,
158 const KoHeadFoot& hf,
159 const KoColumns& columns,
160 const KoKWHeaderFooter& kwhf,
161 int tabs, KoUnit::Unit unit )
162 : KDialogBase( KDialogBase::Tabbed, i18n("Page Layout"), KDialogBase::Ok | KDialogBase::Cancel,
163 KDialogBase::Ok, parent, name, true)
164{
165 flags = tabs;
166
167 m_layout = layout;
168 m_column = columns;
169 m_unit = unit;
170 m_pageSizeTab = 0;
171 m_columnsTab = 0;
172 m_headerTab = 0;
173
174 if ( tabs & FORMAT_AND_BORDERS ) setupTab1( !( tabs & DISABLE_BORDERS ) );
175 if ( tabs & HEADER_AND_FOOTER ) setupTab2( hf );
176 if ( tabs & COLUMNS ) setupTab3();
177 if ( tabs & KW_HEADER_AND_FOOTER ) setupTab4(kwhf);
178
179 setFocusPolicy( TQWidget::StrongFocus );
180 setFocus();
181}
182
183/*===================== destructor ===============================*/
187
188/*======================= show dialog ============================*/
189bool KoPageLayoutDia::pageLayout( KoPageLayout& layout, KoHeadFoot& hf, int tabs, KoUnit::Unit& unit, TQWidget* parent )
190{
191 bool res = false;
192 KoPageLayoutDia *dlg = new KoPageLayoutDia( parent, "PageLayout", layout, hf, tabs, unit );
193
194 if ( dlg->exec() == TQDialog::Accepted ) {
195 res = true;
196 if ( tabs & FORMAT_AND_BORDERS ) layout = dlg->layout();
197 if ( tabs & HEADER_AND_FOOTER ) hf = dlg->headFoot();
198 unit = dlg->unit();
199 }
200
201 delete dlg;
202
203 return res;
204}
205
206/*======================= show dialog ============================*/
208 KoKWHeaderFooter &_kwhf, int tabs, KoUnit::Unit& unit, TQWidget* parent )
209{
210 bool res = false;
211 KoPageLayoutDia *dlg = new KoPageLayoutDia( parent, "PageLayout", layout, hf, columns, _kwhf, tabs, unit );
212
213 if ( dlg->exec() == TQDialog::Accepted ) {
214 res = true;
215 if ( tabs & FORMAT_AND_BORDERS ) layout = dlg->layout();
216 if ( tabs & HEADER_AND_FOOTER ) hf = dlg->headFoot();
217 if ( tabs & COLUMNS ) columns = dlg->columns();
218 if ( tabs & KW_HEADER_AND_FOOTER ) _kwhf = dlg->headerFooter();
219 unit = dlg->unit();
220 }
221
222 delete dlg;
223
224 return res;
225}
226
227/*===================== get a standard page layout ===============*/
232
233/*====================== get header - footer =====================*/
235{
236 KoHeadFoot hf;
237 hf.headLeft = eHeadLeft->text();
238 hf.headMid = eHeadMid->text();
239 hf.headRight = eHeadRight->text();
240 hf.footLeft = eFootLeft->text();
241 hf.footMid = eFootMid->text();
242 hf.footRight = eFootRight->text();
243 return hf;
244}
245
246/*================================================================*/
247const KoKWHeaderFooter& KoPageLayoutDia::headerFooter()
248{
249 return m_headerTab->headerFooter();
250}
251
252/*================ setup page size & margins tab ==================*/
253void KoPageLayoutDia::setupTab1( bool enableBorders )
254{
255 TQWidget *tab1 = addPage(i18n( "Page Size && &Margins" ));
256 TQHBoxLayout *lay = new TQHBoxLayout(tab1);
257 m_pageSizeTab = new KoPageLayoutSize(tab1, m_layout, m_unit, m_column, !(flags & DISABLE_UNIT), enableBorders );
258 lay->addWidget(m_pageSizeTab);
259 m_pageSizeTab->show();
260 connect (m_pageSizeTab, TQ_SIGNAL( propertyChange(KoPageLayout&)),
261 this, TQ_SLOT (sizeUpdated( KoPageLayout&)));
262}
263
264void KoPageLayoutDia::sizeUpdated(KoPageLayout &layout) {
265 m_layout.ptWidth = layout.ptWidth;
266 m_layout.ptHeight = layout.ptHeight;
267 m_layout.ptLeft = layout.ptLeft;
268 m_layout.ptRight = layout.ptRight;
269 m_layout.ptTop = layout.ptTop;
270 m_layout.ptBottom = layout.ptBottom;
271 m_layout.format = layout.format;
272 m_layout.orientation = layout.orientation;
273 if(m_columnsTab)
274 m_columnsTab->setLayout(layout);
275}
276
277/*================ setup header and footer tab ===================*/
278void KoPageLayoutDia::setupTab2( const KoHeadFoot& hf )
279{
280 TQWidget *tab2 = addPage(i18n( "H&eader && Footer" ));
281 TQGridLayout *grid2 = new TQGridLayout( tab2, 7, 2, 0, KDialog::spacingHint() );
282
283 // ------------- header ---------------
284 TQGroupBox *gHead = new TQGroupBox( 0, TQt::Vertical, i18n( "Head Line" ), tab2 );
285 gHead->layout()->setSpacing(KDialog::spacingHint());
286 gHead->layout()->setMargin(KDialog::marginHint());
287 TQGridLayout *headGrid = new TQGridLayout( gHead->layout(), 2, 3 );
288
289 TQLabel *lHeadLeft = new TQLabel( i18n( "Left:" ), gHead );
290 headGrid->addWidget( lHeadLeft, 0, 0 );
291
292 eHeadLeft = new TQLineEdit( gHead );
293 headGrid->addWidget( eHeadLeft, 1, 0 );
294 eHeadLeft->setText( hf.headLeft );
295
296 TQLabel *lHeadMid = new TQLabel( i18n( "Mid:" ), gHead );
297 headGrid->addWidget( lHeadMid, 0, 1 );
298
299 eHeadMid = new TQLineEdit( gHead );
300 headGrid->addWidget( eHeadMid, 1, 1 );
301 eHeadMid->setText( hf.headMid );
302
303 TQLabel *lHeadRight = new TQLabel( i18n( "Right:" ), gHead );
304 headGrid->addWidget( lHeadRight, 0, 2 );
305
306 eHeadRight = new TQLineEdit( gHead );
307 headGrid->addWidget( eHeadRight, 1, 2 );
308 eHeadRight->setText( hf.headRight );
309
310 grid2->addMultiCellWidget( gHead, 0, 1, 0, 1 );
311
312 // ------------- footer ---------------
313 TQGroupBox *gFoot = new TQGroupBox( 0, TQt::Vertical, i18n( "Foot Line" ), tab2 );
314 gFoot->layout()->setSpacing(KDialog::spacingHint());
315 gFoot->layout()->setMargin(KDialog::marginHint());
316 TQGridLayout *footGrid = new TQGridLayout( gFoot->layout(), 2, 3 );
317
318 TQLabel *lFootLeft = new TQLabel( i18n( "Left:" ), gFoot );
319 footGrid->addWidget( lFootLeft, 0, 0 );
320
321 eFootLeft = new TQLineEdit( gFoot );
322 footGrid->addWidget( eFootLeft, 1, 0 );
323 eFootLeft->setText( hf.footLeft );
324
325 TQLabel *lFootMid = new TQLabel( i18n( "Mid:" ), gFoot );
326 footGrid->addWidget( lFootMid, 0, 1 );
327
328 eFootMid = new TQLineEdit( gFoot );
329 footGrid->addWidget( eFootMid, 1, 1 );
330 eFootMid->setText( hf.footMid );
331
332 TQLabel *lFootRight = new TQLabel( i18n( "Right:" ), gFoot );
333 footGrid->addWidget( lFootRight, 0, 2 );
334
335 eFootRight = new TQLineEdit( gFoot );
336 footGrid->addWidget( eFootRight, 1, 2 );
337 eFootRight->setText( hf.footRight );
338
339 grid2->addMultiCellWidget( gFoot, 2, 3, 0, 1 );
340
341 TQLabel *lMacros2 = new TQLabel( i18n( "You can insert several tags in the text:" ), tab2 );
342 grid2->addMultiCellWidget( lMacros2, 4, 4, 0, 1 );
343
344 TQLabel *lMacros3 = new TQLabel( i18n("<qt><ul><li>&lt;sheet&gt; The sheet name</li>"
345 "<li>&lt;page&gt; The current page</li>"
346 "<li>&lt;pages&gt; The total number of pages</li>"
347 "<li>&lt;name&gt; The filename or URL</li>"
348 "<li>&lt;file&gt; The filename with complete path or the URL</li></ul></qt>"), tab2 );
349 grid2->addMultiCellWidget( lMacros3, 5, 6, 0, 0, TQt::AlignTop );
350
351 TQLabel *lMacros4 = new TQLabel( i18n("<qt><ul><li>&lt;time&gt; The current time</li>"
352 "<li>&lt;date&gt; The current date</li>"
353 "<li>&lt;author&gt; Your full name</li>"
354 "<li>&lt;org&gt; Your organization</li>"
355 "<li>&lt;email&gt; Your email address</li></ul></qt>"), tab2 );
356 grid2->addMultiCellWidget( lMacros4, 5, 6, 1, 1, TQt::AlignTop );
357}
358
359/*================================================================*/
360void KoPageLayoutDia::setupTab3()
361{
362 TQWidget *tab3 = addPage(i18n( "Col&umns" ));
363 TQHBoxLayout *lay = new TQHBoxLayout(tab3);
364 m_columnsTab = new KoPageLayoutColumns(tab3, m_column, m_unit, m_layout);
365 m_columnsTab->layout()->setMargin(0);
366 lay->addWidget(m_columnsTab);
367 m_columnsTab->show();
368 connect (m_columnsTab, TQ_SIGNAL( propertyChange(KoColumns&)),
369 this, TQ_SLOT (columnsUpdated( KoColumns&)));
370}
371
372void KoPageLayoutDia::columnsUpdated(KoColumns &columns) {
373 m_column.columns = columns.columns;
374 m_column.ptColumnSpacing = columns.ptColumnSpacing;
375 if(m_pageSizeTab)
376 m_pageSizeTab->setColumns(columns);
377}
378
379/*================================================================*/
380void KoPageLayoutDia::setupTab4(const KoKWHeaderFooter kwhf )
381{
382 TQWidget *tab4 = addPage(i18n( "H&eader && Footer" ));
383 TQHBoxLayout *lay = new TQHBoxLayout(tab4);
384 m_headerTab = new KoPageLayoutHeader(tab4, m_unit, kwhf);
385 m_headerTab->layout()->setMargin(0);
386 lay->addWidget(m_headerTab);
387 m_headerTab->show();
388
389}
390
391
392/* Validation when closing. Error messages are never liked, but
393 better let the users enter all values in any order, and have one
394 final validation, than preventing them from entering values. */
395void KoPageLayoutDia::slotOk()
396{
397 if( m_pageSizeTab )
398 m_pageSizeTab->queryClose();
399 KDialogBase::slotOk(); // accept
400}
401
402#include <KoPageLayoutDia.moc>
TQFrame * addPage(const TQString &itemName, const TQString &header=TQString::null, const TQPixmap &pixmap=TQPixmap())
virtual void slotOk()
static int marginHint()
static int spacingHint()
This class is a widget that shows the KoColumns data structure and allows the user to change it.
void setLayout(KoPageLayout &layout)
Update the page preview widget with the param layout.
With this dialog the user can specify the layout of the paper during printing.
static bool pageLayout(KoPageLayout &, KoHeadFoot &, int tabs, KoUnit::Unit &unit, TQWidget *parent=0)
Show page layout dialog.
KoPageLayoutDia(TQWidget *parent, const char *name, const KoPageLayout &layout, const KoHeadFoot &headfoot, int flags, KoUnit::Unit unit, bool modal=true)
Constructor.
KoUnit::Unit unit() const
Returns the unit.
const KoPageLayout & layout() const
Returns the layout.
~KoPageLayoutDia()
Destructor.
KoHeadFoot headFoot() const
Returns the header and footer information.
static TDE_DEPRECATED KoPageLayout standardLayout()
Retrieves a standard page layout.
This class is a widget that shows the KoKWHeaderFooter data structure and allows the user to change i...
const KoKWHeaderFooter & headerFooter()
This class is a widget that shows the KoPageLayout data structure and allows the user to change it.
void setColumns(KoColumns &columns)
Update the page preview widget with the param columns.
~KoPagePreview()
destructor
KoPagePreview(TQWidget *, const char *, const KoPageLayout &)
constructor
void setPageLayout(const KoPageLayout &)
set page layout
Unit
Length units supported by KOffice.
Definition KoUnit.h:63
structure for columns
structure for header-footer
structure for KWord header-footer
This structure defines the page layout, including its size in pt, its format (e.g.
KoFormat format
Page format.
double ptRight
Right margin in pt.
double ptHeight
Page height in pt.
KoOrientation orientation
Page orientation.
double ptLeft
Left margin in pt.
double ptBottom
Bottom margin in pt.
double ptWidth
Page width in pt.
static KOFFICECORE_EXPORT KoPageLayout standardLayout()
double ptTop
Top margin in pt.