summaryrefslogtreecommitdiffstats
path: root/kword/KWFrameStyleManager.h
blob: c44adb82be287ea1e7fec1dcdbafeabf4495e5e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* This file is part of the KDE project
   Copyright (C) 2002 Nash Hoogwater <[email protected]>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; using
   version 2 of the License.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef kwframestylemanager_h
#define kwframestylemanager_h

#include "KWFrameStyle.h"

#include <kdialogbase.h>
#include <tqptrlist.h>


class TQGroupBox;
class TQGridLayout;
class TQLineEdit;
class TQListBox;
class TQPushButton;
class TQTabWidget;
class TQWidget;
class KWDocument;
class KWFrameStyleManagerTab;
class KoParagLayoutWidget;
class KoParagLayout;
class KColorButton;
class KWBrushStylePreview;

/******************************************************************/
/* Class: KWFrameStylePreview                                     */
/******************************************************************/

class KWFrameStylePreview : public TQWidget
{
    Q_OBJECT
  TQ_OBJECT

public:
    KWFrameStylePreview( TQWidget *tqparent )
        : TQWidget( tqparent ), frameStyle( 0 ) {
            setBackgroundColor( white );
        }

    void setFrameStyle(KWFrameStyle *_frameStyle);

protected:
    void paintEvent( TQPaintEvent *e );

    void setTopBorder(KoBorder _bTop) { frameStyle->setTopBorder( _bTop ); tqrepaint( true ); }
    void setBottomBorder(KoBorder _bBottom) { frameStyle->setBottomBorder( _bBottom ); tqrepaint( true ); }
    void setRightBorder(KoBorder _bRight) { frameStyle->setRightBorder( _bRight ); tqrepaint( true ); }
    void setLeftBorder(KoBorder _bLeft) { frameStyle->setLeftBorder( _bLeft ); tqrepaint( true ); }
    void setBackground( const TQColor & col ) { frameStyle->setBackgroundColor( col ); tqrepaint( true ); }

    KWFrameStyle *frameStyle;
};


class KWFrameStyleListItem
{
  public:
    KWFrameStyleListItem() {}
    ~KWFrameStyleListItem();
    KWFrameStyleListItem(KWFrameStyle *orig, KWFrameStyle *changed) {
        m_origFrameStyle = orig;
        m_changedFrameStyle = changed;
    }

    KWFrameStyle *origFrameStyle()const { return m_origFrameStyle; }
    KWFrameStyle *changedFrameStyle()const { return m_changedFrameStyle; }
    void setOrigFrameStyle( KWFrameStyle *_orig ) { m_origFrameStyle = _orig; }
    void setChangedFrameStyle( KWFrameStyle *_changed ) { m_changedFrameStyle = _changed; }
    void deleteOrigFrameStyle() { delete m_changedFrameStyle; }
    void deleteChangedFrameStyle() { delete m_changedFrameStyle; }

    void switchStyle();
    void deleteStyle( KWFrameStyle *current );
    void apply();

  protected:
    KWFrameStyle *m_origFrameStyle;
    KWFrameStyle *m_changedFrameStyle;
};

/******************************************************************/
/* Class: KWFrameStyleManager                                     */
/******************************************************************/
class KWFrameStyleManager : public KDialogBase
{
    Q_OBJECT
  TQ_OBJECT

public:
    KWFrameStyleManager( TQWidget *_parent, KWDocument *_doc,
                         const TQString & activeStyleName );
    ~KWFrameStyleManager();

protected:
    void addStyles(const TQPtrList<KWFrameStyle> & style );
    void setupWidget();
    void addGeneralTab();
    void apply();
    void updateGUI();
    void updatePreview();
    void save();
    int frameStyleIndex( int pos );

    TQTabWidget *m_tabs;
    TQListBox *m_stylesList;
    TQLineEdit *m_nameString;
    TQPushButton *m_deleteButton;
    TQPushButton *m_newButton;
    TQPushButton *m_moveUpButton;
    TQPushButton *m_moveDownButton;

    TQGroupBox *previewBox;
    KWFrameStylePreview *preview;

    KWFrameStyle *m_currentFrameStyle;
    TQStringList m_styleOrder;
    TQPtrList<KWFrameStyleListItem> m_frameStyles;
    TQPtrList<KWFrameStyleManagerTab> m_tabsList;
    int numFrameStyles;
    bool noSignals;

    KWDocument *m_doc;

protected slots:
    virtual void slotOk();
    virtual void slotApply();
    void switchStyle();
    void switchTabs();
    void addStyle();
    void deleteStyle();
    void moveUpStyle();
    void moveDownStyle();
    void renameStyle(const TQString &);
    void importFromFile();
protected:
    void addTab( KWFrameStyleManagerTab * tab );
};

class KWFrameStyleManagerTab : public TQWidget {
    Q_OBJECT
  TQ_OBJECT
public:
    KWFrameStyleManagerTab(TQWidget *tqparent) : TQWidget(tqparent) {};

    /** the new style which is to be displayed */
    void setStyle(KWFrameStyle *style) { m_style = style; }
    /**  update the GUI from the current Style*/
    virtual void update() = 0;
    /**  return the (i18n-ed) name of the tab */
    virtual TQString tabName() = 0;
    /** save the GUI to the style */
    virtual void save() = 0;
protected:
    KWFrameStyle *m_style;
};

class KWFrameStyleBackgroundTab : public KWFrameStyleManagerTab
{
    Q_OBJECT
  TQ_OBJECT
public:
    KWFrameStyleBackgroundTab( TQWidget * tqparent );

    virtual void update();
    virtual void save();
    virtual TQString tabName();
protected slots:
    void updateBrushConfiguration( const TQColor & );
protected:
    TQBrush m_backgroundColor;
    TQWidget *bgwidget;
    TQGridLayout *grid;
    KColorButton *brushColor;
    KWBrushStylePreview *brushPreview;
};

class KWFrameStyleBordersTab : public KWFrameStyleManagerTab
{
    Q_OBJECT
  TQ_OBJECT
public:
    KWFrameStyleBordersTab( TQWidget * tqparent );
    ~KWFrameStyleBordersTab();
    void setWidget( KoParagLayoutWidget * widget );

    virtual void update();
    virtual void save();
    virtual TQString tabName();
protected:
    virtual void resizeEvent( TQResizeEvent *e );

    KoParagLayoutWidget * m_widget;
    KoParagLayout *m_borders; // Pity that I'm using such an overdosis for just borders :-(
};

#endif