kword

KWFrameStyleManager.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 Nash Hoogwater <nrhoogwater@wanadoo.nl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; using
00007    version 2 of the License.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef kwframestylemanager_h
00021 #define kwframestylemanager_h
00022 
00023 #include "KWFrameStyle.h"
00024 
00025 #include <kdialogbase.h>
00026 #include <qptrlist.h>
00027 
00028 
00029 class QGroupBox;
00030 class QGridLayout;
00031 class QLineEdit;
00032 class QListBox;
00033 class QPushButton;
00034 class QTabWidget;
00035 class QWidget;
00036 class KWDocument;
00037 class KWFrameStyleManagerTab;
00038 class KoParagLayoutWidget;
00039 class KoParagLayout;
00040 class KColorButton;
00041 class KWBrushStylePreview;
00042 
00043 /******************************************************************/
00044 /* Class: KWFrameStylePreview                                     */
00045 /******************************************************************/
00046 
00047 class KWFrameStylePreview : public QWidget
00048 {
00049     Q_OBJECT
00050 
00051 public:
00052     KWFrameStylePreview( QWidget *parent )
00053         : QWidget( parent ), frameStyle( 0 ) {
00054             setBackgroundColor( white );
00055         }
00056 
00057     void setFrameStyle(KWFrameStyle *_frameStyle);
00058 
00059 protected:
00060     void paintEvent( QPaintEvent *e );
00061 
00062     void setTopBorder(KoBorder _bTop) { frameStyle->setTopBorder( _bTop ); repaint( true ); }
00063     void setBottomBorder(KoBorder _bBottom) { frameStyle->setBottomBorder( _bBottom ); repaint( true ); }
00064     void setRightBorder(KoBorder _bRight) { frameStyle->setRightBorder( _bRight ); repaint( true ); }
00065     void setLeftBorder(KoBorder _bLeft) { frameStyle->setLeftBorder( _bLeft ); repaint( true ); }
00066     void setBackground( const QColor & col ) { frameStyle->setBackgroundColor( col ); repaint( true ); }
00067 
00068     KWFrameStyle *frameStyle;
00069 };
00070 
00071 
00072 class KWFrameStyleListItem
00073 {
00074   public:
00075     KWFrameStyleListItem() {}
00076     ~KWFrameStyleListItem();
00077     KWFrameStyleListItem(KWFrameStyle *orig, KWFrameStyle *changed) {
00078         m_origFrameStyle = orig;
00079         m_changedFrameStyle = changed;
00080     }
00081 
00082     KWFrameStyle *origFrameStyle()const { return m_origFrameStyle; }
00083     KWFrameStyle *changedFrameStyle()const { return m_changedFrameStyle; }
00084     void setOrigFrameStyle( KWFrameStyle *_orig ) { m_origFrameStyle = _orig; }
00085     void setChangedFrameStyle( KWFrameStyle *_changed ) { m_changedFrameStyle = _changed; }
00086     void deleteOrigFrameStyle() { delete m_changedFrameStyle; }
00087     void deleteChangedFrameStyle() { delete m_changedFrameStyle; }
00088 
00089     void switchStyle();
00090     void deleteStyle( KWFrameStyle *current );
00091     void apply();
00092 
00093   protected:
00094     KWFrameStyle *m_origFrameStyle;
00095     KWFrameStyle *m_changedFrameStyle;
00096 };
00097 
00098 /******************************************************************/
00099 /* Class: KWFrameStyleManager                                     */
00100 /******************************************************************/
00101 class KWFrameStyleManager : public KDialogBase
00102 {
00103     Q_OBJECT
00104 
00105 public:
00106     KWFrameStyleManager( QWidget *_parent, KWDocument *_doc,
00107                          const QString & activeStyleName );
00108     ~KWFrameStyleManager();
00109 
00110 protected:
00111     void addStyles(const QPtrList<KWFrameStyle> & style );
00112     void setupWidget();
00113     void addGeneralTab();
00114     void apply();
00115     void updateGUI();
00116     void updatePreview();
00117     void save();
00118     int frameStyleIndex( int pos );
00119 
00120     QTabWidget *m_tabs;
00121     QListBox *m_stylesList;
00122     QLineEdit *m_nameString;
00123     QPushButton *m_deleteButton;
00124     QPushButton *m_newButton;
00125     QPushButton *m_moveUpButton;
00126     QPushButton *m_moveDownButton;
00127 
00128     QGroupBox *previewBox;
00129     KWFrameStylePreview *preview;
00130 
00131     KWFrameStyle *m_currentFrameStyle;
00132     QStringList m_styleOrder;
00133     QPtrList<KWFrameStyleListItem> m_frameStyles;
00134     QPtrList<KWFrameStyleManagerTab> m_tabsList;
00135     int numFrameStyles;
00136     bool noSignals;
00137 
00138     KWDocument *m_doc;
00139 
00140 protected slots:
00141     virtual void slotOk();
00142     virtual void slotApply();
00143     void switchStyle();
00144     void switchTabs();
00145     void addStyle();
00146     void deleteStyle();
00147     void moveUpStyle();
00148     void moveDownStyle();
00149     void renameStyle(const QString &);
00150     void importFromFile();
00151 protected:
00152     void addTab( KWFrameStyleManagerTab * tab );
00153 };
00154 
00155 class KWFrameStyleManagerTab : public QWidget {
00156     Q_OBJECT
00157 public:
00158     KWFrameStyleManagerTab(QWidget *parent) : QWidget(parent) {};
00159 
00161     void setStyle(KWFrameStyle *style) { m_style = style; }
00163     virtual void update() = 0;
00165     virtual QString tabName() = 0;
00167     virtual void save() = 0;
00168 protected:
00169     KWFrameStyle *m_style;
00170 };
00171 
00172 class KWFrameStyleBackgroundTab : public KWFrameStyleManagerTab
00173 {
00174     Q_OBJECT
00175 public:
00176     KWFrameStyleBackgroundTab( QWidget * parent );
00177 
00178     virtual void update();
00179     virtual void save();
00180     virtual QString tabName();
00181 protected slots:
00182     void updateBrushConfiguration( const QColor & );
00183 protected:
00184     QBrush m_backgroundColor;
00185     QWidget *bgwidget;
00186     QGridLayout *grid;
00187     KColorButton *brushColor;
00188     KWBrushStylePreview *brushPreview;
00189 };
00190 
00191 class KWFrameStyleBordersTab : public KWFrameStyleManagerTab
00192 {
00193     Q_OBJECT
00194 public:
00195     KWFrameStyleBordersTab( QWidget * parent );
00196     ~KWFrameStyleBordersTab();
00197     void setWidget( KoParagLayoutWidget * widget );
00198 
00199     virtual void update();
00200     virtual void save();
00201     virtual QString tabName();
00202 protected:
00203     virtual void resizeEvent( QResizeEvent *e );
00204 
00205     KoParagLayoutWidget * m_widget;
00206     KoParagLayout *m_borders; // Pity that I'm using such an overdosis for just borders :-(
00207 };
00208 
00209 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys