karbon

vtexttool.h
1/* This file is part of the KDE project
2 Copyright (C) 2001, 2002, 2003 The Karbon Developers
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef __VTEXTTOOL_H__
21#define __VTEXTTOOL_H__
22
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <kdialogbase.h>
29
30#include "tqframe.h"
31#include "tqgroupbox.h"
32#include "tqcombobox.h"
33
34#include "vcommand.h"
35#include "vtext.h"
36#include "vtool.h"
37
38class TDEFontCombo;
39class KIntNumInput;
40class TQCheckBox;
41class TQLineEdit;
42class TQPushButton;
43class TQTabWidget;
44class ShadowWidget;
45class VTextTool;
46class TQCursor;
47
48class ShadowPreview : public TQWidget
49{
50 TQ_OBJECT
51
52
53public:
54 ShadowPreview( ShadowWidget* parent );
55 ~ShadowPreview();
56
57signals:
58 void changed( int angle, int distance, bool );
59
60protected:
61 virtual void mouseReleaseEvent( TQMouseEvent* );
62 virtual void paintEvent( TQPaintEvent* );
63
64private:
65 ShadowWidget* m_parent;
66};
67
68
69class ShadowWidget : public TQGroupBox
70{
71 TQ_OBJECT
72
73
74public:
75 ShadowWidget( TQWidget* parent, const char* name, int angle, int distance, bool translucent );
76 ~ShadowWidget();
77
78 void setUseShadow( bool use );
79 bool useShadow();
80 void setShadowAngle( int angle );
81 int shadowAngle();
82 void setShadowDistance( int distance );
83 int shadowDistance();
84 void setTranslucent( bool translucent );
85 bool isTranslucent();
86
87public slots:
88 void setShadowValues( int angle, int distance, bool translucent );
89 void updatePreview( int );
90 void updatePreview();
91
92protected:
93 TQCheckBox* m_useShadow;
94 KIntNumInput* m_angle;
95 KIntNumInput* m_distance;
96 TQCheckBox* m_translucent;
97 ShadowPreview* m_preview;
98};
99
100
101class VTextOptionsWidget : public KDialogBase
102{
103 TQ_OBJECT
104
105
106public:
107 VTextOptionsWidget( VTextTool* tool, TQWidget *parent );
108 ~VTextOptionsWidget();
109
110 void setFont( const TQFont& font );
111 TQFont font();
112 void setText( const TQString& text );
113 TQString text();
114 void setPosition( VText::Position position );
115 VText::Position position();
116 void setAlignment( VText::Alignment alignment );
117 VText::Alignment alignment();
118 void setOffset( double offset );
119 double offset();
120 void setUseShadow( bool state );
121 bool useShadow();
122 void setShadow( int angle, int distance, bool translucent );
123 bool translucentShadow();
124 int shadowAngle();
125 int shadowDistance();
126
127public slots:
128 void valueChanged( int );
129 void valueChanged( double );
130 void accept();
131 void cancel();
132 void textChanged( const TQString& );
133 void editBasePath();
134 void convertToShapes();
135 void initialize( VObject &text );
136
137protected:
138 TQTabWidget* m_tabWidget;
139 TDEFontCombo* m_fontCombo;
140 TQCheckBox* m_boldCheck;
141 TQCheckBox* m_italicCheck;
142 KIntNumInput* m_fontSize;
143 TQLineEdit* m_textEditor;
144 ShadowWidget* m_shadow;
145 TQComboBox* m_textAlignment;
146 TQComboBox* m_textPosition;
147 TQPushButton* m_editBasePath;
148 TQPushButton* m_convertToShapes;
149 KDoubleNumInput* m_textOffset;
150 VTextTool* m_tool;
151};
152
153
154class VTextTool : public VTool, public VVisitor
155{
156public:
157 VTextTool( KarbonView *view );
158 ~VTextTool();
159
160 virtual void setup (TDEActionCollection *collection );
161 virtual TQString uiname() { return i18n( "Text Tool" ); }
162
163 virtual TQString contextHelp();
164 virtual bool showDialog() const;
165
166 virtual void activate();
167 virtual void deactivate();
168
169 virtual void mouseButtonPress();
170 virtual void mouseButtonRelease();
171 virtual void mouseDrag();
172 virtual void mouseDragRelease();
173 virtual void textChanged();
174 virtual void accept();
175 virtual void cancel();
176 virtual void editBasePath();
177 virtual void convertToShapes();
178
179 virtual void visitVPath( VPath& composite );
180 virtual void visitVDocument( VDocument& )
181 {}
182
183 virtual void visitVGroup( VGroup& )
184 {}
185
186 virtual void visitVLayer( VLayer& )
187 {}
188
189 virtual void visitVSubpath( VSubpath& path );
190 virtual void visitVText( VText& text );
191
192 virtual void draw( VPainter* painter );
193
194protected:
195 virtual void mouseDragShiftPressed();
196 virtual void mouseDragShiftReleased();
197
198private:
199 class VTextCmd : public VCommand
200 {
201 public:
202 VTextCmd( VDocument* doc, const TQString& name, VText* text );
203 VTextCmd( VDocument* doc, const TQString& name, VText* text,
204 const TQFont &newFont, const VSubpath& newBasePath, VText::Position newPosition, VText::Alignment newAlignment, double newOffset, const TQString& newText,
205 bool newUseShadow, int newShadowAngle, int newShadowDistance, bool newTranslucentShadow );
206 virtual ~VTextCmd();
207
208 virtual void execute();
209 virtual void unexecute();
210 virtual bool isExecuted()
211 {
212 return m_executed;
213 }
214 virtual bool changesSelection() const { return true; }
215
216 private:
217 class VTextModifPrivate
218 {
219 public:
220 VTextModifPrivate() : oldBasePath( 0L ), newBasePath( 0L )
221 {}
222
223 TQFont oldFont;
224 TQFont newFont;
225 VSubpath oldBasePath;
226 VSubpath newBasePath;
227 VText::Position oldPosition;
228 VText::Position newPosition;
229 VText::Alignment oldAlignment;
230 VText::Alignment newAlignment;
231 double oldOffset;
232 double newOffset;
233 TQString oldText;
234 TQString newText;
235 bool oldUseShadow;
236 bool newUseShadow;
237 int oldShadowAngle;
238 int newShadowAngle;
239 int oldShadowDistance;
240 int newShadowDistance;
241 bool oldTranslucentShadow;
242 bool newTranslucentShadow;
243 };
244
245 VText* m_text;
246 bool m_executed;
247 VTextModifPrivate* m_textModifications;
248 };
249
250 class VTextToCompositeCmd : public VCommand
251 {
252 public:
253 VTextToCompositeCmd( VDocument* doc, const TQString& name, VText* text );
254 virtual ~VTextToCompositeCmd();
255
256 virtual void execute();
257 virtual void unexecute();
258 virtual bool isExecuted()
259 {
260 return m_executed;
261 }
262
263 private:
264 VText* m_text;
265 VGroup* m_group;
266 bool m_executed;
267 };
268
269 void drawPathCreation();
270 void drawEditedText();
271
277 bool createText( VSubpath &path );
278
279 VTextOptionsWidget* m_optionsWidget;
280 KoPoint m_last;
281 VText* m_text;
282 VText* m_editedText;
283 bool m_creating;
284 // are we dragging in 45 degree steps?
285 bool m_stepwise;
286 TQCursor* m_cursor;
287};
288
289#endif
290
virtual void unexecute()
Unexecutes the command.
Definition vcommand.h:75
TQString name() const
Returns the name of the command.
Definition vcommand.h:91
virtual bool changesSelection() const
Returns if the command changes the actual document selection.
Definition vcommand.h:84
virtual void execute()=0
Executes the command.
The base class for all karbon tools.
Definition vtool.h:52
virtual void mouseDragRelease()
Mouse button release.
Definition vtool.h:220
virtual void mouseButtonPress()
Left mouse button press.
Definition vtool.h:185
virtual void mouseButtonRelease()
Left mouse button release.
Definition vtool.h:195
virtual TQString uiname()
The name of the tool.
Definition vtool.h:93
virtual void accept()
Terminates the current tool drawing (if any).
Definition vtool.h:265
virtual void cancel()
Cancels all tool operations.
Definition vtool.h:255
virtual void deactivate()
Deactivates the tool.
Definition vtool.h:83
virtual void activate()
Called during the tool activation.
Definition vtool.cpp:252
virtual void mouseDragShiftPressed()
Mouse drag with "Shift" key pressed at the same time.
Definition vtool.h:225
virtual void mouseDragShiftReleased()
"Shift" key released while mouse drag.
Definition vtool.h:235
virtual TQString contextHelp()
The context help of the tool.
Definition vtool.h:98
virtual void mouseDrag()
Mouse drag.
Definition vtool.h:215
KarbonView * view() const
Returns the connected karbon part.
Definition vtool.cpp:66
virtual bool showDialog() const
Shows the tools option dialog.
Definition vtool.h:88
The abstract visitor class.
Definition vvisitor.h:51