summaryrefslogtreecommitdiffstats
path: root/karbon/tools/vtexttool.h
blob: 6cf02c11d1ed0c0760752a59014f1ecb25219919 (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/* This file is part of the KDE project
   Copyright (C) 2001, 2002, 2003 The Karbon Developers

   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; either
   version 2 of the License, or (at your option) any later version.

   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 __VTEXTTOOL_H__
#define __VTEXTTOOL_H__


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <kdialogbase.h>

#include "tqframe.h"
#include "tqgroupbox.h"
#include "tqcombobox.h"

#include "vcommand.h"
#include "vtext.h"
#include "vtool.h"

class KFontCombo;
class KIntNumInput;
class TQCheckBox;
class TQLineEdit;
class TQPushButton;
class TQTabWidget;
class ShadowWidget;
class VTextTool;
class TQCursor;

class ShadowPreview : public TQWidget
{
	Q_OBJECT
  

public:
	ShadowPreview( ShadowWidget* parent );
	~ShadowPreview();

signals:
	void changed( int angle, int distance, bool );

protected:
	virtual void mouseReleaseEvent( TQMouseEvent* );
	virtual void paintEvent( TQPaintEvent* );

private:
	ShadowWidget* m_parent;
};


class ShadowWidget : public TQGroupBox
{
	Q_OBJECT
  

public:
	ShadowWidget( TQWidget* parent, const char* name, int angle, int distance, bool translucent );
	~ShadowWidget();

	void setUseShadow( bool use );
	bool useShadow();
	void setShadowAngle( int angle );
	int shadowAngle();
	void setShadowDistance( int distance );
	int shadowDistance();
	void setTranslucent( bool translucent );
	bool isTranslucent();

public slots:
	void setShadowValues( int angle, int distance, bool translucent );
	void updatePreview( int );
	void updatePreview();

protected:
	TQCheckBox* m_useShadow;
	KIntNumInput* m_angle;
	KIntNumInput* m_distance;
	TQCheckBox* m_translucent;
	ShadowPreview* m_preview;
};


class VTextOptionsWidget : public KDialogBase
{
	Q_OBJECT
  

public:
	VTextOptionsWidget( VTextTool* tool, TQWidget *parent );
	~VTextOptionsWidget();

	void setFont( const TQFont& font );
	TQFont font();
	void setText( const TQString& text );
	TQString text();
	void setPosition( VText::Position position );
	VText::Position position();
	void setAlignment( VText::Alignment alignment );
	VText::Alignment alignment();
	void setOffset( double offset );
	double offset();
	void setUseShadow( bool state );
	bool useShadow();
	void setShadow( int angle, int distance, bool translucent );
	bool translucentShadow();
	int shadowAngle();
	int shadowDistance();

public slots:
	void valueChanged( int );
	void valueChanged( double );
	void accept();
	void cancel();
	void textChanged( const TQString& );
	void editBasePath();
	void convertToShapes();
	void initialize( VObject &text );

protected:
	TQTabWidget* m_tabWidget;
	KFontCombo* m_fontCombo;
	TQCheckBox* m_boldCheck;
	TQCheckBox* m_italicCheck;
	KIntNumInput* m_fontSize;
	TQLineEdit* m_textEditor;
	ShadowWidget* m_shadow;
	TQComboBox* m_textAlignment;
	TQComboBox* m_textPosition;
	TQPushButton* m_editBasePath;
	TQPushButton* m_convertToShapes;
	KDoubleNumInput* m_textOffset;
	VTextTool* m_tool;
};


class VTextTool : public VTool, public VVisitor
{
public:
	VTextTool( KarbonView *view );
	~VTextTool();

	virtual void setup (KActionCollection *collection );
	virtual TQString uiname() { return i18n( "Text Tool" ); }

	virtual TQString contextHelp();
	virtual bool showDialog() const;

	virtual void activate();
	virtual void deactivate();

	virtual void mouseButtonPress();
	virtual void mouseButtonRelease();
	virtual void mouseDrag();
	virtual void mouseDragRelease();
	virtual void textChanged();
	virtual void accept();
	virtual void cancel();
	virtual void editBasePath();
	virtual void convertToShapes();

	virtual void visitVPath( VPath& composite );
	virtual void visitVDocument( VDocument& )
	{}

	virtual void visitVGroup( VGroup& )
	{}

	virtual void visitVLayer( VLayer& )
	{}

	virtual void visitVSubpath( VSubpath& path );
	virtual void visitVText( VText& text );

	virtual void draw( VPainter* painter );

protected:
	virtual void mouseDragShiftPressed();
	virtual void mouseDragShiftReleased();

private:
	class VTextCmd : public VCommand
	{
	public:
		VTextCmd( VDocument* doc, const TQString& name, VText* text );
		VTextCmd( VDocument* doc, const TQString& name, VText* text,
				  const TQFont &newFont, const VSubpath& newBasePath, VText::Position newPosition, VText::Alignment newAlignment, double newOffset, const TQString& newText,
				  bool newUseShadow, int newShadowAngle, int newShadowDistance, bool newTranslucentShadow );
		virtual ~VTextCmd();

		virtual void execute();
		virtual void unexecute();
		virtual bool isExecuted()
		{
			return m_executed;
		}
		virtual bool changesSelection() const { return true; }

	private:
		class VTextModifPrivate
		{
		public:
			VTextModifPrivate() : oldBasePath( 0L ), newBasePath( 0L )
			{}

			TQFont oldFont;
			TQFont newFont;
			VSubpath oldBasePath;
			VSubpath newBasePath;
			VText::Position oldPosition;
			VText::Position newPosition;
			VText::Alignment oldAlignment;
			VText::Alignment newAlignment;
			double oldOffset;
			double newOffset;
			TQString oldText;
			TQString newText;
			bool oldUseShadow;
			bool newUseShadow;
			int oldShadowAngle;
			int newShadowAngle;
			int oldShadowDistance;
			int newShadowDistance;
			bool oldTranslucentShadow;
			bool newTranslucentShadow;
		};

		VText* m_text;
		bool m_executed;
		VTextModifPrivate* m_textModifications;
	};

	class VTextToCompositeCmd : public VCommand
	{
	public:
		VTextToCompositeCmd( VDocument* doc, const TQString& name, VText* text );
		virtual ~VTextToCompositeCmd();

		virtual void execute();
		virtual void unexecute();
		virtual bool isExecuted()
		{
			return m_executed;
		}

	private:
		VText* m_text;
		VGroup* m_group;
		bool m_executed;
	};

	void drawPathCreation();
	void drawEditedText();
	
	/**
	* Creates new temporary text object along given path for displaying.
	*
	* @param path the path to create the text along
	*/
	bool createText( VSubpath &path );

	VTextOptionsWidget* m_optionsWidget;
	KoPoint m_last;
	VText* m_text;
	VText* m_editedText;
	bool m_creating;
	// are we dragging in 45 degree steps?
	bool m_stepwise;
	TQCursor* m_cursor;
};

#endif