F:/KPlato/koffice/libs/kotext/KoParagDia.h

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003    Copyright (C) 2005 Martin Ellis <martin.ellis@kdemail.net>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef paragdia_h
00022 #define paragdia_h
00023 
00024 #include <kpagedialog.h>
00025 #include <QStringList>
00026 #include <q3ptrlist.h>
00027 #include <q3stylesheet.h>
00028 #include <QKeyEvent>
00029 #include <QLabel>
00030 #include <QMouseEvent>
00031 #include <KoRuler.h>
00032 #include <KoUnit.h>
00033 #include <KoUnitWidgets.h>
00034 #include <q3dict.h>
00035 #include <QLineEdit>
00036 #include "KoParagLayout.h"
00037 #include "KoParagCounter.h"
00038 #include <knuminput.h>
00039 #include <q3groupbox.h>
00040 #include <koffice_export.h>
00041 #include <QStackedWidget>
00042 #include "ui_KoParagDecorationTab.h"
00043 class QListWidget;
00044 class KoTextZoomHandler;
00045 class KButtonBox;
00046 class KPushButton;
00047 class KColorButton;
00048 class KoTextDocument;
00049 class KoBorderPreview;
00050 class KoStylePreview;
00051 class KPagePreview2;
00052 class KPagePreview;
00053 class KoSpinBox;
00054 class Q3ButtonGroup;
00055 class QCheckBox;
00056 class QComboBox;
00057 class Q3GroupBox;
00058 class QLabel;
00059 class Q3ListBox;
00060 class QPushButton;
00061 class QRadioButton;
00062 class QWidget;
00063 class KIntNumInput;
00064 class KDoubleNumInput;
00065 class KComboBox;
00066 class Q3VBoxLayout;
00067 class KoUnitDoubleSpinBox;
00068 
00069 class KoParagDecorationTab : public QWidget, public Ui::KoParagDecorationTab
00070 {
00071 public:
00072   KoParagDecorationTab( QWidget *parent ) : QWidget( parent ) {
00073     setupUi( this );
00074   }
00075 };
00076 
00077 
00083 class KOTEXT_EXPORT KoParagLayoutWidget : public QWidget
00084 {
00085     Q_OBJECT
00086 public:
00087     // Constructor: flag (PD_SOMETHING) and parent widget
00088     KoParagLayoutWidget( int flag, QWidget * parent )
00089         : QWidget( parent ), m_flag( flag )
00090     {
00091     }
00092     virtual ~KoParagLayoutWidget() {}
00093 
00094     // Display settings, from the paragLayout
00095     virtual void display( const KoParagLayout & lay ) = 0;
00096 
00097     // Save the settings, into the paragLayout
00098     // This is only used by the stylist, not by paragdia (which needs undo/redo, applying partially etc.)
00099     virtual void save( KoParagLayout & lay ) = 0;
00100 
00101     // Return true if the settings where modified
00102     // ## maybe too global, but how to do it differently? We'll see if we need this.
00103     //virtual bool isModified() = 0;
00104 
00106     virtual QString tabName() = 0;
00107 
00108     // Return the part of the paraglayout that this widget cares about
00109     int flag() const { return m_flag; }
00110 
00111 private:
00112     int m_flag;
00113 };
00114 
00118 class KOTEXT_EXPORT KoIndentSpacingWidget : public KoParagLayoutWidget
00119 {
00120     Q_OBJECT
00121 public:
00122     KoIndentSpacingWidget( KoUnit::Unit unit, double _frameWidth, QWidget * parent );
00123     virtual ~KoIndentSpacingWidget() {}
00124 
00125     virtual void display( const KoParagLayout & lay );
00126     virtual void save( KoParagLayout & lay );
00127     //virtual bool isModified();
00128     virtual QString tabName();
00129 
00130     double leftIndent() const;
00131     double rightIndent() const;
00132     double firstLineIndent() const;
00133     double spaceBeforeParag() const;
00134     double spaceAfterParag() const;
00135     double lineSpacing() const;
00136     KoParagLayout::SpacingType lineSpacingType() const;
00137 private slots:
00138     void leftChanged( double );
00139     void rightChanged( double );
00140     void firstChanged( double );
00141     void spacingActivated( int );
00142     void spacingChanged( double );
00143     void spacingChanged( int );
00144     void beforeChanged( double );
00145     void afterChanged( double );
00146 private:
00147     void updateLineSpacing( KoParagLayout::SpacingType _type );
00148 
00149     QStackedWidget *sSpacingStack;
00150     KIntNumInput *eSpacingPercent;
00151     KoUnitDoubleSpinBox *eBefore, *eAfter, *eSpacing;
00152     KoUnitDoubleSpinBox *eLeft, *eRight, *eFirstLine;
00153     QComboBox *cSpacing;
00154     KPagePreview *prev1;
00155     KoUnit::Unit m_unit;
00156 };
00157 
00161 class KOTEXT_EXPORT KoParagAlignWidget : public KoParagLayoutWidget
00162 {
00163     Q_OBJECT
00164 public:
00165     KoParagAlignWidget( bool breakLine, QWidget * parent );
00166     virtual ~KoParagAlignWidget() {}
00167 
00168     virtual void display( const KoParagLayout & lay );
00169     virtual void save( KoParagLayout & lay );
00170     //virtual bool isModified();
00171     virtual QString tabName();
00172 
00173     int pageBreaking() const;
00174     int align() const;
00175 
00176 protected slots:
00177     void alignLeft();
00178     void alignCenter();
00179     void alignRight();
00180     void alignJustify();
00181 
00182 protected:
00183     void clearAligns();
00184 
00185 private:
00186     QRadioButton *rLeft, *rCenter, *rRight, *rJustify;
00187     QCheckBox *cKeepLinesTogether, *cHardBreakBefore, *cHardBreakAfter;
00188     KPagePreview2 *prev2;
00189 };
00190 
00194 class KOTEXT_EXPORT KoParagDecorationWidget : public KoParagLayoutWidget
00195 {
00196     Q_OBJECT
00197 public:
00198     KoParagDecorationWidget( QWidget * parent );
00199     virtual ~KoParagDecorationWidget() {}
00200 
00201     virtual void display( const KoParagLayout & lay );
00202     virtual void save( KoParagLayout & lay );
00203     //virtual bool isModified();
00204     virtual QString tabName();
00205 
00206     // Borders
00207     KoBorder leftBorder() const { return m_leftBorder; }
00208     KoBorder rightBorder() const { return m_rightBorder; }
00209     KoBorder topBorder() const { return m_topBorder; }
00210     KoBorder bottomBorder() const { return m_bottomBorder; }
00211     bool joinBorder() const { return m_joinBorder; }
00212 
00213     // Background color
00214     QColor backgroundColor() const;
00215 
00216 protected slots:
00217     void brdLeftToggled( bool );
00218     void brdRightToggled( bool );
00219     void brdTopToggled( bool );
00220     void brdBottomToggled( bool );
00221     void brdJoinToggled( bool );
00222     void slotPressEvent(QMouseEvent *_ev);
00223 
00224 protected:
00225     void updateBorders();
00226 
00227 private:
00228     // GUI
00229     KoBorderPreview *wPreview;
00231     KoParagDecorationTab *wDeco;
00233     KoBorder::BorderStyle curBorderStyle() const;
00235     unsigned int curBorderWidth() const;
00237     QColor curBorderColor() const;
00238 
00239     // Borders
00240     KoBorder m_leftBorder, m_rightBorder, m_topBorder, m_bottomBorder;
00241     bool m_joinBorder;
00242 
00259     void clickedBorderPreview( KoBorder& border, KoBorder::BorderType position,
00260                                KPushButton *corresponding );
00261 
00263     void updateBorder( KoBorder& border );
00265     bool borderChanged( const KoBorder& border );
00266 
00267 };
00268 
00269 
00270 class KOTEXT_EXPORT KoCounterStyleWidget : public QWidget
00271 {
00272     Q_OBJECT
00273 public:
00274     KoCounterStyleWidget( bool displayDepth= true, bool onlyStyleTypeLetter = false, bool disableAll=false, QWidget* parent = 0 );
00275 
00276     class StyleRepresenter {
00277         public:
00278             StyleRepresenter (const QString name, KoParagCounter::Style style, bool bullet=false) {
00279                 m_name=name;
00280                 m_style=style;
00281                 m_bullet=bullet;
00282             }
00283             QString name() const { return m_name; }
00284             KoParagCounter::Style style() const { return m_style; }
00285             bool isBullet() const { return m_bullet; }
00286 
00287         private:
00288             QString m_name;
00289             KoParagCounter::Style m_style;
00290             bool m_bullet;
00291     };
00292 
00293     static void makeCounterRepresenterList( Q3PtrList<StyleRepresenter>& stylesList , bool onlyStyleTypeLetter = false );
00294     void fillStyleCombo(KoParagCounter::Numbering type = KoParagCounter::NUM_LIST);
00295     void display( const KoParagLayout & lay );
00296     void changeKWSpinboxType(KoParagCounter::Style st);
00297     const KoParagCounter & counter() const { return m_counter; }
00298     void setCounter( const KoParagCounter& counter );
00299 
00300 public slots:
00301     void numTypeChanged( int nType );
00302 
00303 signals:
00304     void sig_startChanged( int );
00305     void sig_restartChanged(bool);
00306     void sig_depthChanged(int);
00307     void sig_displayLevelsChanged(int);
00308     void sig_suffixChanged(const QString &);
00309     void sig_prefixChanged(const QString &);
00310     void sig_numTypeChanged( int );
00311     void sig_alignmentChanged( int );
00312     void changeCustomBullet( const QString & , QChar );
00313     void changeStyle( KoParagCounter::Style );
00314 protected slots:
00315     void startChanged(int i) {m_counter.setStartNumber(i);emit sig_startChanged(i);}
00316     void restartChanged(bool b) {m_counter.setRestartCounter(b);emit sig_restartChanged(b);}
00317     void depthChanged(int i) {m_counter.setDepth(i);emit sig_depthChanged(i);}
00318     void displayLevelsChanged(int i) {m_counter.setDisplayLevels(i);emit sig_displayLevelsChanged(i);}
00319     void alignmentChanged(const QString& s);
00320     void suffixChanged(const QString & txt) {m_counter.setSuffix(txt);emit sig_suffixChanged(txt); }
00321     void prefixChanged(const QString & txt) {m_counter.setPrefix(txt);emit sig_prefixChanged(txt); }
00322 
00323     void numStyleChanged();
00324     void selectCustomBullet();
00325 
00326 protected:
00327     void displayStyle( KoParagCounter::Style style );
00328 
00329 private:
00330     Q3GroupBox *gStyle;
00331     Q3PtrList <StyleRepresenter> stylesList;
00332     QListWidget *lstStyle;
00333     KoParagCounter m_counter;
00334     QLineEdit *sSuffix, *sPrefix;
00335     QPushButton *bCustom;
00336     KoSpinBox *spnStart;
00337     QSpinBox *spnDepth;
00338     QSpinBox *spnDisplayLevels;
00339     QLabel *lStart;
00340     QLabel *lCustom;
00341     QCheckBox *cbRestart;
00342     KComboBox *cbAlignment;
00343     QLabel *lAlignment;
00344     unsigned int styleBuffer;
00345     bool noSignals;
00346 };
00347 
00351 class KOTEXT_EXPORT KoParagCounterWidget : public KoParagLayoutWidget
00352 {
00353     Q_OBJECT
00354 public:
00355 
00356     KoParagCounterWidget( bool disableAll=false, QWidget * parent = 0 );
00357     virtual ~KoParagCounterWidget() {}
00358 
00359     virtual void display( const KoParagLayout & lay );
00360     virtual void save( KoParagLayout & lay );
00361     //virtual bool isModified();
00362     virtual QString tabName();
00363 
00364     const KoParagCounter & counter() const { return m_counter; }
00365 
00366 protected slots:
00367     //void selectCustomBullet();
00368     //void numStyleChanged(); // selected another style from the combobox
00369     void numTypeChanged( int );  // selected another type radiobutton.
00370 
00371     void suffixChanged(const QString & txt) {m_counter.setSuffix(txt); updatePreview(); }
00372     void prefixChanged(const QString & txt) {m_counter.setPrefix(txt); updatePreview();}
00373     void startChanged(int i) {m_counter.setStartNumber(i); updatePreview();}
00374     void restartChanged(bool b) {m_counter.setRestartCounter(b); }
00375     void depthChanged(int i) {m_counter.setDepth(i); updatePreview();}
00376     void displayLevelsChanged(int i) {m_counter.setDisplayLevels(i); updatePreview();}
00377     void alignmentChanged(int i) {m_counter.setAlignment(i); updatePreview();}
00378     void slotChangeCustomBullet( const QString & f, QChar c);
00379     void styleChanged (KoParagCounter::Style st );
00380 
00381 private:
00382     void updatePreview();
00383 
00384     Q3ButtonGroup *gNumbering;
00385     KoParagCounter m_counter;
00386     KoStylePreview *preview;
00387     KoCounterStyleWidget *m_styleWidget;
00388     unsigned int styleBuffer;
00389     bool noSignals;
00390 };
00391 
00395 class KoTabulatorsLineEdit : public KoUnitDoubleSpinBox
00396 {
00397     Q_OBJECT
00398 public:
00399     KoTabulatorsLineEdit( QWidget *parent, double lower, double upper, double step, double value = 0.0,
00400                          KoUnit::Unit unit = KoUnit::U_PT, unsigned int precision = 2 );
00401 
00402 protected:
00403     virtual void keyPressEvent ( QKeyEvent * );
00404  signals:
00405     void keyReturnPressed();
00406 };
00407 
00411 class KOTEXT_EXPORT KoParagTabulatorsWidget : public KoParagLayoutWidget
00412 {
00413     Q_OBJECT
00414 public:
00415     KoParagTabulatorsWidget( KoUnit::Unit unit, double _frameWidth, QWidget * parent );
00416     virtual ~KoParagTabulatorsWidget() {}
00417 
00418     virtual void display( const KoParagLayout & lay );
00419     virtual void save( KoParagLayout & lay );
00420     virtual QString tabName();
00421 
00422     KoTabulatorList tabList() const { return m_tabList; }
00423 
00424     void setCurrentTab( double tabPos );
00425 
00426 protected slots:
00427     void slotTabValueChanged( double );
00428     void slotAlignCharChanged( const QString &_text );
00429     void newClicked();
00430     void deleteClicked();
00431     void deleteAllClicked();
00432     void setActiveItem(int selected);
00433     void updateAlign(int selected);
00434     void updateFilling(int selected);
00435     void updateWidth();
00436 
00437 private:
00438 
00439     void sortLists();
00440     QString tabToString(const KoTabulator &tab);
00441 
00442     Q3VBoxLayout* editLayout;
00443 
00444     Q3ListBox* lstTabs;
00445     Q3GroupBox* gPosition;
00446     KoTabulatorsLineEdit* sTabPos;
00447     Q3ButtonGroup* bgAlign;
00448     QRadioButton* rAlignLeft;
00449     QRadioButton* rAlignCenter;
00450     QRadioButton* rAlignRight;
00451     QRadioButton* rAlignVar;
00452     QLineEdit* sAlignChar;
00453     Q3GroupBox* gTabLeader;
00454     QComboBox* cFilling;
00455     KoUnitDoubleSpinBox* eWidth;
00456     QPushButton* bNew;
00457     QPushButton* bDelete;
00458     QPushButton* bDeleteAll;
00459 
00460     KoTabulatorList m_tabList;
00461     KoUnit::Unit m_unit;
00462     double m_toplimit;
00463     bool noSignals;
00464 };
00465 
00471 class KoStylePreview : public Q3GroupBox
00472 {
00473     Q_OBJECT
00474 
00475 public:
00476     KoStylePreview( const QString &title, const QString &text, QWidget *parent );
00477     virtual ~KoStylePreview();
00478 
00481     void setStyle( KoParagStyle *style );
00482 
00484     void setCounter( const KoParagCounter & counter );
00485 
00486 protected:
00487     void drawContents( QPainter *painter );
00488 
00489     KoTextDocument *m_textdoc;
00490     KoTextZoomHandler *m_zoomHandler;
00491 };
00492 
00493 
00500 class KOTEXT_EXPORT KoParagDia : public KPageDialog
00501 {
00502     Q_OBJECT
00503 
00504 public:
00505     enum { PD_SPACING = 1, PD_ALIGN = 2, PD_DECORATION = 4, PD_NUMBERING = 8,
00506            PD_TABS = 16 };
00507 
00511     KoParagDia( QWidget*, int flags, KoUnit::Unit unit, double _frameWidth=-1,bool breakLine=true, bool disableAll = false);
00512     ~KoParagDia();
00513 
00515     int getFlags()const { return m_flags; }
00516 
00518     void setCurrentPage( int page );
00519 
00521     void setParagLayout( const KoParagLayout & lay );
00522 
00523     // Get values (in pt) - tab 1
00524     double leftIndent() const { return m_indentSpacingWidget->leftIndent(); }
00525     double rightIndent() const { return m_indentSpacingWidget->rightIndent(); }
00526     double firstLineIndent() const { return m_indentSpacingWidget->firstLineIndent(); }
00527     double spaceBeforeParag() const { return m_indentSpacingWidget->spaceBeforeParag(); }
00528     double spaceAfterParag() const { return m_indentSpacingWidget->spaceAfterParag(); }
00529     double lineSpacing() const { return m_indentSpacingWidget->lineSpacing(); }
00530     KoParagLayout::SpacingType lineSpacingType() const{ return m_indentSpacingWidget->lineSpacingType(); }
00531 
00532     // tab 2
00533     int align() const { return m_alignWidget->align(); }
00534     int pageBreaking() const { return m_alignWidget->pageBreaking(); }
00535 
00536     // tab 3
00537     KoBorder leftBorder() const { return m_decorationsWidget->leftBorder(); }
00538     KoBorder rightBorder() const { return m_decorationsWidget->rightBorder(); }
00539     KoBorder topBorder() const { return m_decorationsWidget->topBorder(); }
00540     KoBorder bottomBorder() const { return m_decorationsWidget->bottomBorder(); }
00541     bool joinBorder() const { return m_decorationsWidget->joinBorder(); }
00542 
00543     // tab 4
00544     const KoParagCounter & counter() const { return m_counterWidget->counter(); }
00545 
00546     // tab 5
00547     KoTabulatorList tabListTabulator() const { return m_tabulatorsWidget->tabList(); }
00548     KoParagTabulatorsWidget * tabulatorsWidget() const { return m_tabulatorsWidget; }
00549 
00550     QColor backgroundColor() const { return m_decorationsWidget->backgroundColor(); }
00551 
00552     // Support for "what has changed?"
00553     bool isAlignChanged() const {return oldLayout.alignment!=align();}
00554     bool isLineSpacingChanged() const {
00555         return (oldLayout.lineSpacingValue() !=lineSpacing() ||
00556                 oldLayout.lineSpacingType != lineSpacingType());
00557     }
00558     bool isLeftMarginChanged() const {
00559         return oldLayout.margins[Q3StyleSheetItem::MarginLeft]!=leftIndent();
00560     }
00561     bool isRightMarginChanged() const {
00562         return oldLayout.margins[Q3StyleSheetItem::MarginRight]!=rightIndent();
00563     }
00564     bool isFirstLineChanged() const {
00565         return oldLayout.margins[ Q3StyleSheetItem::MarginFirstLine]!=firstLineIndent();
00566     }
00567     bool isSpaceBeforeChanged() const {
00568         return oldLayout.margins[Q3StyleSheetItem::MarginTop]!=spaceBeforeParag();
00569     }
00570     bool isSpaceAfterChanged() const {
00571         return oldLayout.margins[Q3StyleSheetItem::MarginBottom]!=spaceAfterParag();
00572     }
00573     bool isPageBreakingChanged() const {
00574         return oldLayout.pageBreaking!=pageBreaking();
00575     }
00576     bool isCounterChanged() const;
00577     bool isBorderChanged() const {
00578         return (oldLayout.leftBorder!=leftBorder() ||
00579                 oldLayout.rightBorder!=rightBorder() ||
00580                 oldLayout.topBorder!=topBorder() ||
00581                 oldLayout.bottomBorder!=bottomBorder() );
00582     }
00583     bool isJoinBorderChanged() const { return oldLayout.joinBorder!=joinBorder(); }
00584     bool listTabulatorChanged() const {return oldLayout.tabList()!=tabListTabulator();}
00585     bool isBackgroundColorChanged() const { return oldLayout.backgroundColor != backgroundColor(); }
00586 
00587     KoParagLayout paragLayout() const;
00589     int changedFlags() const;
00590 
00591 protected slots:
00592     void slotReset();
00593     virtual void slotOk();
00594     virtual void slotApply();
00595 signals:
00596      void applyParagStyle();
00597 
00598 private:
00599     KoIndentSpacingWidget * m_indentSpacingWidget;
00600     KoParagAlignWidget * m_alignWidget;
00601     KoParagDecorationWidget * m_decorationsWidget;
00602     KoParagCounterWidget * m_counterWidget;
00603     KoParagTabulatorsWidget * m_tabulatorsWidget;
00604     KPageWidgetItem *m_p1, *m_p2, *m_p3, *m_p4, *m_p5;
00605     int m_flags;
00606     KoParagLayout oldLayout;
00607 };
00608 
00609 #endif

Généré le Wed Nov 22 23:41:08 2006 pour KPlato par  doxygen 1.5.1-p1