lib

KoParagDia.h
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2005 Martin Ellis <martin.ellis@kdemail.net>
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#ifndef paragdia_h
22#define paragdia_h
23
24#include <kdialogbase.h>
25#include <tqstringlist.h>
26#include <tqptrlist.h>
27#include <tqstylesheet.h>
28#include <KoRuler.h>
29#include <KoUnit.h>
30#include <KoUnitWidgets.h>
31#include <tqdict.h>
32#include <tqlineedit.h>
33#include "KoParagLayout.h"
34#include "KoParagCounter.h"
35#include <knuminput.h>
36#include <tqgroupbox.h>
37#include <tqvgroupbox.h>
38#include <koffice_export.h>
40class KButtonBox;
41class KPushButton;
42class KColorButton;
43class KoTextDocument;
44class KoBorderPreview;
45class KoStylePreview;
46class KPagePreview2;
47class KPagePreview;
48class KoSpinBox;
49class TQButtonGroup;
50class TQCheckBox;
51class TQComboBox;
52class TQGridLayout;
53class TQGroupBox;
54class TQLabel;
55class TQListBox;
56class TQPushButton;
57class TQRadioButton;
58class TQWidget;
59class TQWidgetStack;
60class KIntNumInput;
61class KDoubleNumInput;
62class KComboBox;
63class TQVBoxLayout;
65class KoParagDecorationTab; // From KoParagDecorationTab.ui
66
72class KOTEXT_EXPORT KoParagLayoutWidget : public TQWidget
73{
74 TQ_OBJECT
75
76public:
77 // Constructor: parent widget, flag (PD_SOMETHING) and name
78 KoParagLayoutWidget( int flag, TQWidget * parent, const char * name = 0 )
79 : TQWidget( parent, name ), m_flag( flag )
80 {
81 }
82 virtual ~KoParagLayoutWidget() {}
83
84 // Display settings, from the paragLayout
85 virtual void display( const KoParagLayout & lay ) = 0;
86
87 // Save the settings, into the paragLayout
88 // This is only used by the stylist, not by paragdia (which needs undo/redo, applying partially etc.)
89 virtual void save( KoParagLayout & lay ) = 0;
90
91 // Return true if the settings where modified
92 // ## maybe too global, but how to do it differently? We'll see if we need this.
93 //virtual bool isModified() = 0;
94
96 virtual TQString tabName() = 0;
97
98 // Return the part of the paraglayout that this widget cares about
99 int flag() const { return m_flag; }
100
101private:
102 int m_flag;
103};
104
108class KOTEXT_EXPORT KoIndentSpacingWidget : public KoParagLayoutWidget
109{
110 TQ_OBJECT
111
112public:
113 KoIndentSpacingWidget( KoUnit::Unit unit, double _frameWidth, TQWidget * parent,const char * name = 0 );
114 virtual ~KoIndentSpacingWidget() {}
115
116 virtual void display( const KoParagLayout & lay );
117 virtual void save( KoParagLayout & lay );
118 //virtual bool isModified();
119 virtual TQString tabName();
120
121 double leftIndent() const;
122 double rightIndent() const;
123 double firstLineIndent() const;
124 double spaceBeforeParag() const;
125 double spaceAfterParag() const;
126 double lineSpacing() const;
127 KoParagLayout::SpacingType lineSpacingType() const;
128private slots:
129 void leftChanged( double );
130 void rightChanged( double );
131 void firstChanged( double );
132 void spacingActivated( int );
133 void spacingChanged( double );
134 void spacingChanged( int );
135 void beforeChanged( double );
136 void afterChanged( double );
137private:
138 void updateLineSpacing( KoParagLayout::SpacingType _type );
139
140 TQWidgetStack *sSpacingStack;
141 KIntNumInput *eSpacingPercent;
142 KoUnitDoubleSpinBox *eBefore, *eAfter, *eSpacing;
143 KoUnitDoubleSpinBox *eLeft, *eRight, *eFirstLine;
144 TQComboBox *cSpacing;
145 KPagePreview *prev1;
146 KoUnit::Unit m_unit;
147};
148
152class KOTEXT_EXPORT KoParagAlignWidget : public KoParagLayoutWidget
153{
154 TQ_OBJECT
155
156public:
157 KoParagAlignWidget(bool breakLine, TQWidget * parent, const char * name = 0 );
158 virtual ~KoParagAlignWidget() {}
159
160 virtual void display( const KoParagLayout & lay );
161 virtual void save( KoParagLayout & lay );
162 //virtual bool isModified();
163 virtual TQString tabName();
164
165 int pageBreaking() const;
166 int align() const;
167
168protected slots:
169 void alignLeft();
170 void alignCenter();
171 void alignRight();
172 void alignJustify();
173
174protected:
175 void clearAligns();
176
177private:
178 TQRadioButton *rLeft, *rCenter, *rRight, *rJustify;
179 TQCheckBox *cKeepLinesTogether, *cHardBreakBefore, *cHardBreakAfter;
180 KPagePreview2 *prev2;
181};
182
186class KOTEXT_EXPORT KoParagDecorationWidget : public KoParagLayoutWidget
187{
188 TQ_OBJECT
189
190public:
191 KoParagDecorationWidget( TQWidget * parent, const char * name = 0 );
192 virtual ~KoParagDecorationWidget() {}
193
194 virtual void display( const KoParagLayout & lay );
195 virtual void save( KoParagLayout & lay );
196 //virtual bool isModified();
197 virtual TQString tabName();
198
199 // Borders
200 KoBorder leftBorder() const { return m_leftBorder; }
201 KoBorder rightBorder() const { return m_rightBorder; }
202 KoBorder topBorder() const { return m_topBorder; }
203 KoBorder bottomBorder() const { return m_bottomBorder; }
204 bool joinBorder() const { return m_joinBorder; }
205
206 // Background color
207 TQColor backgroundColor() const;
208
209protected slots:
210 void brdLeftToggled( bool );
211 void brdRightToggled( bool );
212 void brdTopToggled( bool );
213 void brdBottomToggled( bool );
214 void brdJoinToggled( bool );
215 void slotPressEvent(TQMouseEvent *_ev);
216
217protected:
218 void updateBorders();
219
220private:
221 // GUI
222 KoBorderPreview *wPreview;
224 KoParagDecorationTab *wDeco;
226 KoBorder::BorderStyle curBorderStyle() const;
228 unsigned int curBorderWidth() const;
230 TQColor curBorderColor() const;
231
232 // Borders
233 KoBorder m_leftBorder, m_rightBorder, m_topBorder, m_bottomBorder;
234 bool m_joinBorder;
235
252 void clickedBorderPreview( KoBorder& border, KoBorder::BorderType position,
253 KPushButton *corresponding );
254
256 void updateBorder( KoBorder& border );
258 bool borderChanged( const KoBorder& border );
259
260};
261
262
263class KOTEXT_EXPORT KoCounterStyleWidget : public TQWidget
264{
265 TQ_OBJECT
266
267public:
268 KoCounterStyleWidget( bool displayDepth= true, bool onlyStyleTypeLetter = false, bool disableAll=false, TQWidget* parent = 0, const char* name = 0 );
269
270 class StyleRepresenter {
271 public:
272 StyleRepresenter (const TQString name, KoParagCounter::Style style, bool bullet=false) {
273 m_name=name;
274 m_style=style;
275 m_bullet=bullet;
276 }
277 TQString name() const { return m_name; }
278 KoParagCounter::Style style() const { return m_style; }
279 bool isBullet() const { return m_bullet; }
280
281 private:
282 TQString m_name;
283 KoParagCounter::Style m_style;
284 bool m_bullet;
285 };
286
287 static void makeCounterRepresenterList( TQPtrList<StyleRepresenter>& stylesList , bool onlyStyleTypeLetter = false );
288 void fillStyleCombo(KoParagCounter::Numbering type = KoParagCounter::NUM_LIST);
289 void display( const KoParagLayout & lay );
290 void changeKWSpinboxType(KoParagCounter::Style st);
291 const KoParagCounter & counter() const { return m_counter; }
292 void setCounter( const KoParagCounter& counter );
293
294public slots:
295 void numTypeChanged( int nType );
296
297signals:
298 void sig_startChanged( int );
299 void sig_restartChanged(bool);
300 void sig_depthChanged(int);
301 void sig_displayLevelsChanged(int);
302 void sig_suffixChanged(const TQString &);
303 void sig_prefixChanged(const TQString &);
304 void sig_numTypeChanged( int );
305 void sig_alignmentChanged( int );
306 void changeCustomBullet( const TQString & , TQChar );
307 void changeStyle( KoParagCounter::Style );
308protected slots:
309 void startChanged(int i) {m_counter.setStartNumber(i);emit sig_startChanged(i);}
310 void restartChanged(bool b) {m_counter.setRestartCounter(b);emit sig_restartChanged(b);}
311 void depthChanged(int i) {m_counter.setDepth(i);emit sig_depthChanged(i);}
312 void displayLevelsChanged(int i) {m_counter.setDisplayLevels(i);emit sig_displayLevelsChanged(i);}
313 void alignmentChanged(const TQString& s);
314 void suffixChanged(const TQString & txt) {m_counter.setSuffix(txt);emit sig_suffixChanged(txt); }
315 void prefixChanged(const TQString & txt) {m_counter.setPrefix(txt);emit sig_prefixChanged(txt); }
316
317 void numStyleChanged();
318 void selectCustomBullet();
319
320protected:
321 void displayStyle( KoParagCounter::Style style );
322
323private:
324 TQGroupBox *gStyle;
325 TQPtrList <StyleRepresenter> stylesList;
326 TQListBox *lstStyle;
327 KoParagCounter m_counter;
328 TQLineEdit *sSuffix, *sPrefix;
329 TQPushButton *bCustom;
330 KoSpinBox *spnStart;
331 TQSpinBox *spnDepth;
332 TQSpinBox *spnDisplayLevels;
333 TQLabel *lStart;
334 TQLabel *lCustom;
335 TQCheckBox *cbRestart;
336 KComboBox *cbAlignment;
337 TQLabel *lAlignment;
338 unsigned int styleBuffer;
339 bool noSignals;
340};
341
345class KOTEXT_EXPORT KoParagCounterWidget : public KoParagLayoutWidget
346{
347 TQ_OBJECT
348
349public:
350
351 KoParagCounterWidget( bool disableAll=false ,TQWidget * parent=0L, const char * name = 0 );
352 virtual ~KoParagCounterWidget() {}
353
354 virtual void display( const KoParagLayout & lay );
355 virtual void save( KoParagLayout & lay );
356 //virtual bool isModified();
357 virtual TQString tabName();
358
359 const KoParagCounter & counter() const { return m_counter; }
360
361protected slots:
362 //void selectCustomBullet();
363 //void numStyleChanged(); // selected another style from the combobox
364 void numTypeChanged( int ); // selected another type radiobutton.
365
366 void suffixChanged(const TQString & txt) {m_counter.setSuffix(txt); updatePreview(); }
367 void prefixChanged(const TQString & txt) {m_counter.setPrefix(txt); updatePreview();}
368 void startChanged(int i) {m_counter.setStartNumber(i); updatePreview();}
369 void restartChanged(bool b) {m_counter.setRestartCounter(b); }
370 void depthChanged(int i) {m_counter.setDepth(i); updatePreview();}
371 void displayLevelsChanged(int i) {m_counter.setDisplayLevels(i); updatePreview();}
372 void alignmentChanged(int i) {m_counter.setAlignment(i); updatePreview();}
373 void slotChangeCustomBullet( const TQString & f, TQChar c);
374 void styleChanged (KoParagCounter::Style st );
375
376private:
377 void updatePreview();
378
379 TQButtonGroup *gNumbering;
380 KoParagCounter m_counter;
381 KoStylePreview *preview;
382 KoCounterStyleWidget *m_styleWidget;
383 unsigned int styleBuffer;
384 bool noSignals;
385};
386
390class KoTabulatorsLineEdit : public KoUnitDoubleSpinBox
391{
392 TQ_OBJECT
393
394public:
395 KoTabulatorsLineEdit( TQWidget *parent, double lower, double upper, double step, double value = 0.0,
396 KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2, const char *name = 0 );
397
398protected:
399 virtual void keyPressEvent ( TQKeyEvent * );
400 signals:
401 void keyReturnPressed();
402};
403
407class KOTEXT_EXPORT KoParagTabulatorsWidget : public KoParagLayoutWidget
408{
409 TQ_OBJECT
410
411public:
412 KoParagTabulatorsWidget( KoUnit::Unit unit, double _frameWidth, TQWidget * parent, const char * name = 0 );
413 virtual ~KoParagTabulatorsWidget() {}
414
415 virtual void display( const KoParagLayout & lay );
416 virtual void save( KoParagLayout & lay );
417 virtual TQString tabName();
418
419 KoTabulatorList tabList() const { return m_tabList; }
420
421 void setCurrentTab( double tabPos );
422
423protected slots:
424 void slotTabValueChanged( double );
425 void slotAlignCharChanged( const TQString &_text );
426 void newClicked();
427 void deleteClicked();
428 void deleteAllClicked();
429 void setActiveItem(int selected);
430 void updateAlign(int selected);
431 void updateFilling(int selected);
432 void updateWidth();
433
434private:
435
436 void sortLists();
437 TQString tabToString(const KoTabulator &tab);
438
439 TQVBoxLayout* editLayout;
440
441 TQListBox* lstTabs;
442 TQGroupBox* gPosition;
443 KoTabulatorsLineEdit* sTabPos;
444 TQButtonGroup* bgAlign;
445 TQRadioButton* rAlignLeft;
446 TQRadioButton* rAlignCentre;
447 TQRadioButton* rAlignRight;
448 TQRadioButton* rAlignVar;
449 TQLineEdit* sAlignChar;
450 TQGroupBox* gTabLeader;
451 TQComboBox* cFilling;
452 KoUnitDoubleSpinBox* eWidth;
453 TQPushButton* bNew;
454 TQPushButton* bDelete;
455 TQPushButton* bDeleteAll;
456
457 KoTabulatorList m_tabList;
458 KoUnit::Unit m_unit;
459 double m_toplimit;
460 bool noSignals;
461};
462
468class KoStylePreview : public TQGroupBox
469{
470 TQ_OBJECT
471
472
473public:
474 KoStylePreview( const TQString &title, const TQString &text, TQWidget *parent, const char* name = 0 );
475 virtual ~KoStylePreview();
476
479 void setStyle( KoParagStyle *style );
480
482 void setCounter( const KoParagCounter & counter );
483
484protected:
485 void drawContents( TQPainter *painter );
486
487 KoTextDocument *m_textdoc;
488 KoTextZoomHandler *m_zoomHandler;
489};
490
491
498class KOTEXT_EXPORT KoParagDia : public KDialogBase
499{
500 TQ_OBJECT
501
502
503public:
504 enum { PD_SPACING = 1, PD_ALIGN = 2, PD_DECORATION = 4, PD_NUMBERING = 8,
505 PD_TABS = 16 };
506
510 KoParagDia( TQWidget*, const char*, int flags, KoUnit::Unit unit, double _frameWidth=-1,bool breakLine=true, bool disableAll = false);
511 ~KoParagDia();
512
514 int getFlags()const { return m_flags; }
515
517 void setCurrentPage( int page );
518
520 void setParagLayout( const KoParagLayout & lay );
521
522 // Get values (in pt) - tab 1
523 double leftIndent() const { return m_indentSpacingWidget->leftIndent(); }
524 double rightIndent() const { return m_indentSpacingWidget->rightIndent(); }
525 double firstLineIndent() const { return m_indentSpacingWidget->firstLineIndent(); }
526 double spaceBeforeParag() const { return m_indentSpacingWidget->spaceBeforeParag(); }
527 double spaceAfterParag() const { return m_indentSpacingWidget->spaceAfterParag(); }
528 double lineSpacing() const { return m_indentSpacingWidget->lineSpacing(); }
529 KoParagLayout::SpacingType lineSpacingType() const{ return m_indentSpacingWidget->lineSpacingType(); }
530
531 // tab 2
532 int align() const { return m_alignWidget->align(); }
533 int pageBreaking() const { return m_alignWidget->pageBreaking(); }
534
535 // tab 3
536 KoBorder leftBorder() const { return m_decorationsWidget->leftBorder(); }
537 KoBorder rightBorder() const { return m_decorationsWidget->rightBorder(); }
538 KoBorder topBorder() const { return m_decorationsWidget->topBorder(); }
539 KoBorder bottomBorder() const { return m_decorationsWidget->bottomBorder(); }
540 bool joinBorder() const { return m_decorationsWidget->joinBorder(); }
541
542 // tab 4
543 const KoParagCounter & counter() const { return m_counterWidget->counter(); }
544
545 // tab 5
546 KoTabulatorList tabListTabulator() const { return m_tabulatorsWidget->tabList(); }
547 KoParagTabulatorsWidget * tabulatorsWidget() const { return m_tabulatorsWidget; }
548
549 TQColor backgroundColor() const { return m_decorationsWidget->backgroundColor(); }
550
551 // Support for "what has changed?"
552 bool isAlignChanged() const {return oldLayout.alignment!=align();}
553 bool isLineSpacingChanged() const {
554 return (oldLayout.lineSpacingValue() !=lineSpacing() ||
555 oldLayout.lineSpacingType != lineSpacingType());
556 }
557 bool isLeftMarginChanged() const {
558 return oldLayout.margins[TQStyleSheetItem::MarginLeft]!=leftIndent();
559 }
560 bool isRightMarginChanged() const {
561 return oldLayout.margins[TQStyleSheetItem::MarginRight]!=rightIndent();
562 }
563 bool isFirstLineChanged() const {
564 return oldLayout.margins[ TQStyleSheetItem::MarginFirstLine]!=firstLineIndent();
565 }
566 bool isSpaceBeforeChanged() const {
567 return oldLayout.margins[TQStyleSheetItem::MarginTop]!=spaceBeforeParag();
568 }
569 bool isSpaceAfterChanged() const {
570 return oldLayout.margins[TQStyleSheetItem::MarginBottom]!=spaceAfterParag();
571 }
572 bool isPageBreakingChanged() const {
573 return oldLayout.pageBreaking!=pageBreaking();
574 }
575 bool isCounterChanged() const;
576 bool isBorderChanged() const {
577 return (oldLayout.leftBorder!=leftBorder() ||
578 oldLayout.rightBorder!=rightBorder() ||
579 oldLayout.topBorder!=topBorder() ||
580 oldLayout.bottomBorder!=bottomBorder() );
581 }
582 bool isJoinBorderChanged() const { return oldLayout.joinBorder!=joinBorder(); }
583 bool listTabulatorChanged() const {return oldLayout.tabList()!=tabListTabulator();}
584 bool isBackgroundColorChanged() const { return oldLayout.backgroundColor != backgroundColor(); }
585
586 KoParagLayout paragLayout() const;
588 int changedFlags() const;
589
590protected slots:
591 void slotReset();
592 virtual void slotOk();
593 virtual void slotApply();
594signals:
595 void applyParagStyle();
596
597private:
598 KoIndentSpacingWidget * m_indentSpacingWidget;
599 KoParagAlignWidget * m_alignWidget;
600 KoParagDecorationWidget * m_decorationsWidget;
601 KoParagCounterWidget * m_counterWidget;
602 KoParagTabulatorsWidget * m_tabulatorsWidget;
603 int m_flags;
604 KoParagLayout oldLayout;
605};
606
607#endif
KDialogBase(TQWidget *parent=0, const char *name=0, bool modal=true, const TQString &caption=TQString::null, int buttonMask=Ok|Apply|Cancel, ButtonCode defaultButton=Ok, bool separator=false, const KGuiItem &user1=KGuiItem(), const KGuiItem &user2=KGuiItem(), const KGuiItem &user3=KGuiItem())
int precision() const
This class represents a border - for anything, like paragraph, or frame.
Definition KoBorder.h:34
virtual TQString tabName()
return the (i18n-ed) name of the tab
virtual TQString tabName()
return the (i18n-ed) name of the tab
virtual TQString tabName()
return the (i18n-ed) name of the tab
This is the structure associated with a paragraph (KoTextParag), to define the bullet or numbering of...
virtual TQString tabName()
return the (i18n-ed) name of the tab
int getFlags() const
Flags passed to constructor.
Definition KoParagDia.h:514
KoParagDia(TQWidget *, const char *, int flags, KoUnit::Unit unit, double _frameWidth=-1, bool breakLine=true, bool disableAll=false)
breakLine : kpresenter didn't used this attibute, kword use it.
virtual TQString tabName()=0
return the (i18n-ed) name of the tab
This class holds the paragraph-specific formatting information It's separated from KoTextParag so tha...
SpacingType
Line spacing values Assuming h is the height of the biggest char in the line, and v is the linespacin...
A paragraph style is a combination of a character style and paragraph-layout attributes,...
virtual TQString tabName()
return the (i18n-ed) name of the tab
KoStylePreview.
Definition KoParagDia.h:469
void setCounter(const KoParagCounter &counter)
Set the given counter to the preview.
void setStyle(KoParagStyle *style)
Apply the given style to the preview.
This class extends KoZoomHandler to add support for WYSIWYG text layouting.
Spin box for double precision numbers with unit display.
double value(void) const
Unit
Length units supported by KOffice.
Definition KoUnit.h:63
const char * name(StdAction id)
Struct: KoTabulator Defines the position of a tabulation (in pt), and its type.
Definition KoRuler.h:46