summaryrefslogtreecommitdiffstats
path: root/kbarcode/commands.h
blob: 7322360db2dcd0393f1a4e16094cae2a63b56aae (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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
/***************************************************************************
                          commands.h  -  description
                             -------------------
    begin                : Don Dez 19 2002
    copyright            : (C) 2002 by Dominik Seichter
    email                : domseichter@web.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef COMMANDS_H
#define COMMANDS_H

#include "mycanvasitem.h"

#include <tqobject.h>

#include <kcommand.h>
#include <tdelocale.h>

#include "barcodeitem.h"
#include "tcanvasitem.h"
#include "imageitem.h"

struct barcodeData;
class RectItem;
class MyCanvasLine;
class MyCanvasRectangle;
class MyCanvasView;
class CanvasBarcode;
class PictureRectangle;
class TQCanvasItem;
class TQColor;
class TQFont;
class TQImage;
class TQPen;
class TQPixmap;
class TQPoint;
class TQString;
class TextItem;
//NY29
class TextLineItem;
//NY29
class TokenProvider;

// Stuff for undo redo

class CommandUtils : public TQObject {
    TQ_OBJECT
  
    public:
        CommandUtils(TCanvasItem* item);
        ~CommandUtils();

        bool canvasHasItem();

    private slots:
        void documentItemDeleted();
        
    protected:
        TQCanvas* c;
        TCanvasItem* m_canvas_item;
};

/**
  * NewItemCommand is the base class for all classes
  * that create a new item in the label editor (e.g. a
  * barcode or a text element).
  * You have to implement void create() which creates
  * a TQCanvasItem in item.
  * NewItemCommand takes care about possitioning and
  * undo/redo (because of KCommand).
  *
  * @author Dominik Seichter
  */
class NewItemCommand : public TQObject, public KCommand {
    TQ_OBJECT
  
    public:
        NewItemCommand( MyCanvasView* view, const TQString & name );
        virtual ~NewItemCommand();

        void execute();
        void unexecute();
        TQString name() const {
            return m_name;
        };

        /** @returns a pointer to the TCanvasItem created by this class 
	  */
        inline TCanvasItem* createdItem() const { return m_item; }
    
    private slots:
        void documentItemDeleted();
        
    protected:
        /** This function has to be reimplemented in all subclasses
          * and has to create a TQCanvasItem and store a pointer to it
          * in item. Otherwise KBarcode is going to crash.
          *
          * Example:
          *
          * <pre>
          * void create() {
          *     DrawingRect* r = new DrawingRect( 0 ); // Drawing rect is a subclass of TQCanvasItem
          *     r->setCircle( m_circle );   // Do something with r
          *     item = r;   // save r into item, so that NewItemCommand knows about it
          * }
          * </pre>
          */
        virtual void create() = 0;
        
        MyCanvasView* cv;
        TCanvasItem* m_item;
        DocumentItem* m_object;
        TQPoint m_point;
        TQString m_name;    
};

class ResizeCommand : public KCommand, CommandUtils {
    public:
        ResizeCommand( TCanvasItem* it, bool shift = false ) 
            : CommandUtils( it )
        {
	    orect = rect = m_canvas_item->item()->rectMM();
	    m_shift = shift;
        }
        ~ResizeCommand() {}

        void setRect( int cx, int cy, int cw, int ch );
        
        void execute();
        void unexecute();
        TQString name() const {
            return i18n("Resized Item");
        }

    protected:
        TQRect orect;
        TQRect rect;
        bool m_shift;
};

/** Move a TCanvasItem on the canvas
 */
class MoveCommand : public KCommand, CommandUtils {
    public:
        /**
         * @param cx move in x direction cx mm
         * @param cy move in y direction cy mm
         */
        MoveCommand( int cx, int cy, TCanvasItem* it )
            : CommandUtils( it )
        {
            x = cx;
            y = cy;
        }
        ~MoveCommand() {}

        void execute();
        void unexecute();
        TQString name() const {
            return i18n("Moved Item");
        }

    protected:
        int x;
        int y;
};

class ChangeZCommand : public KCommand, CommandUtils {
    public:
        ChangeZCommand( int z, TCanvasItem* it );
        
        void execute();
        void unexecute();
        TQString name() const {
            return i18n("Raised or lowered an item");
        }

    protected:
        int m_z, m_oldz;
};

class LockCommand : public KCommand, CommandUtils {
    public:
        LockCommand( bool lock, TCanvasItem* it )
            : CommandUtils( it )
        {
            m_locked = lock;
        }
        
        void execute();
        void unexecute();
        TQString name() const {
            return i18n("Protected Item");
        }

    protected:
        bool m_locked;
};

class PictureCommand : public KCommand, CommandUtils {
    public:
        PictureCommand( double r, bool mirrorh, bool mirrorv, EImageScaling s, ImageItem* it );
        ~PictureCommand() {}

	void setExpression( const TQString & expr );
	void setPixmap( const TQPixmap & pix );

        void execute();
        void unexecute();
        TQString name() const {
            return i18n("Changed Settings");
        }
    protected:
        double rotate, orotate;
        bool mirrorv, omirrorv;
        bool mirrorh, omirrorh;
	TQString expression, oexpression;
        EImageScaling scaling, oscaling;
	TQPixmap pixmap, opixmap;
	TQSize oldsize;
	int pixserial, opixserial;
        
        ImageItem* m_item;
};

class TextChangeCommand : public KCommand, CommandUtils {
    public:
        TextChangeCommand( TextItem* it, TQString t );
        ~TextChangeCommand() { }

        void execute();
        void unexecute();
        TQString name() const {
            return i18n("Changed Text");
        }
    protected:
        TQString oldtext, text;
        TextItem* m_item;
};

class TextRotationCommand : public KCommand, protected CommandUtils {
    public:
        TextRotationCommand( double rot, TextItem* t  );

        void execute();
        void unexecute();
        TQString name() const {
            return i18n("Rotated Text");
        }

    protected:
        double rot1, rot2;
        TextItem* m_item;
};


//NY28
class TextLineChangeCommand : public KCommand, CommandUtils {
    public:
        TextLineChangeCommand( TextLineItem* it, TQString t, int font, int magvert, int maghor );
        ~TextLineChangeCommand() { }

        void execute();
        void unexecute();
        TQString name() const {
            return i18n("Changed Text");
        }
    protected:
        TQString oldtext, text;
        TextLineItem* m_item;
        int m_font;
        int m_mag_vert;
        int m_mag_hor;
};
//NY28

class BarcodeCommand : public KCommand, CommandUtils {
    public:
        BarcodeCommand( BarcodeItem* bcode, Barkode* d );
        ~BarcodeCommand() {
            delete data;
        }

        void execute();
        void unexecute();
        TQString name() const {
            return i18n("Changed Barcode");
        }
    protected:
        Barkode olddata;
        Barkode* data;
        BarcodeItem* m_item;
};

class NewPictureCommand : public NewItemCommand {
    public:
        NewPictureCommand( MyCanvasView* v )
	    : NewItemCommand( v, i18n("New Picture") )
	    {
	    }

    protected:
        void create();
};

class NewTextCommand : public NewItemCommand {
    public:
        NewTextCommand( TQString t, MyCanvasView* v, TokenProvider* token );

    protected:
        void create();
        TQString text;
        TokenProvider* m_token;
};

//NY27
class NewTextLineCommand : public NewItemCommand {
    public:
        NewTextLineCommand( TQString t, MyCanvasView* v, TokenProvider* token );

    protected:
        void create();
        TQString text;
	TokenProvider* m_token;
};
//NY27

class NewRectCommand : public NewItemCommand {
    public:
        NewRectCommand( MyCanvasView* v, bool circle = false );

    protected:
        void create();
        bool m_circle;
};

class NewLineCommand : public NewItemCommand {
    public:
        NewLineCommand( MyCanvasView* v );

    protected:
        void create();
};

class NewBarcodeCommand : public NewItemCommand {
    public:
        NewBarcodeCommand( MyCanvasView* v, TokenProvider* token );

    protected:
        void create();

    private:
	TokenProvider* m_token;
};

class DeleteCommand : public KCommand, CommandUtils {
    public:
        DeleteCommand( TCanvasItem* it ) 
            : CommandUtils( it )
        {
        }
        ~DeleteCommand();
        
        void execute();
        void unexecute();
        TQString name() const {
            return i18n("Delete Item");
        }
};

class BorderCommand : public KCommand, protected CommandUtils {
    public:
        BorderCommand( bool border, const TQPen & pen, DocumentItem* item );
        
        void execute();
        void unexecute();
        TQString name() const {
            return i18n("Modified Border");
        }
    
    protected:
        bool m_new_border;
        bool m_old_border;
        TQPen m_new_pen;
        TQPen m_old_pen;
        
        DocumentItem* m_item;
};

class FillCommand : public KCommand, protected CommandUtils {
    public:
        FillCommand(  TQColor c, RectItem* r  );

        void execute();
        void unexecute();
        TQString name() const {
            return i18n("Modified Rectangle or Ellipse");
        }

    protected:
        TQColor fill, fill2;
        RectItem* m_item;
};

class ScriptCommand : public KCommand, CommandUtils {
    public:
        ScriptCommand( const TQString & script, TCanvasItem* it )
            : CommandUtils( it )
        {
            m_script = script;
        }
        ~ScriptCommand() {}
        
        void execute();
        void unexecute();
        TQString name() const {
            return i18n("Changed visibility JavaScript");
        }

    protected:
        TQString m_script;
	TQString m_old_script;
};

#endif