summaryrefslogtreecommitdiffstats
path: root/kbarcode/mycanvasview.h
blob: ec917e70dcc81b574d1e037be626a7f5465fb53e (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
/***************************************************************************
                          mycanvasview.h  -  description
                             -------------------
    begin                : Die Apr 23 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 MYCANVASVIEW_H
#define MYCANVASVIEW_H

#include <tqcanvas.h>
#include <tqvaluelist.h>
#include "documentitem.h"

class TCanvasItem;

typedef TQValueList<TCanvasItem*> TCanvasItemList;


class TQRect;
class TQPainter;
class MyCanvas : public TQCanvas {
    Q_OBJECT
  

    public:
        MyCanvas( TQObject* parent, const char* name = 0 );
        ~MyCanvas();

        void setRect( TQRect r ) {
            m_rect = r;
        }

        TQRect rect() const {
            return m_rect;
        }

        void setGrid( bool enabled ) {
                m_grid = enabled;
        }

        bool grid() const { return m_grid; }

    protected:
        void drawBackground( TQPainter & painter, const TQRect & clip );

    private:
        TQRect m_rect;
        bool m_grid;
};

class Definition;
class TQColor;
class TQLabel;
class TQPoint;
class KCommandHistory;
class KMacroCommand;
class KRuler;
class KStatusBar;
class MyCanvasView : public TQCanvasView
{
    Q_OBJECT
  

    enum edges {
        TopLeft,
        TopMiddle,
        TopRight,
        RightMiddle,
        LeftMiddle,
        BottomLeft,
        BottomMiddle,
        BottomRight,
        Inside,
        Outside,
        Barcode
    };
    
    public:
        MyCanvasView( Definition* d, MyCanvas *c, TQWidget* parent=0, const char* name=0, WFlags f=0);
        ~MyCanvasView();

	/** return a list of all DocumentItems on the canvas
	 */
	DocumentItemList getAllItems();

        TCanvasItemList getSelected();

        TCanvasItem* getActive();
        void setActive( TQCanvasItem* item = 0, bool control = false );

        void setCurrent( TQCanvasItem* item );

        void setHistory( KCommandHistory* hist ) {
            history = hist;
        }

        TQPoint getTranslation() const {
            return translation;
        }

        void setDefinition( Definition* d );
        void setPosLabel( KStatusBar* s, int id ) {
            mouseid = id;
            statusbar = s;
        }

        static int getLowestZ( TQCanvasItemList list );
        static int getHighestZ( TQCanvasItemList list );
        
        void snapPoint(TQPoint* point, TCanvasItem* item) ;
        
    public slots:
        void selectAll();
        void deSelectAll();
        
        void deleteCurrent();

        void updateGUI() {
            canvas()->update();
            repaintContents();
        }

    protected:
        void contentsMousePressEvent(TQMouseEvent*);
        void contentsMouseMoveEvent(TQMouseEvent*);
        void contentsMouseReleaseEvent(TQMouseEvent *);
        void contentsMouseDoubleClickEvent(TQMouseEvent*);
        void resizeEvent( TQResizeEvent * r );
        
    signals:
        void selectionChanged();
        void movedSomething();
        void doubleClickedItem( TCanvasItem* );
        void showContextMenu( TQPoint );
        
    private:
        void setSelected( TQCanvasItem* item = 0, bool control = false );
        KMacroCommand* getMoveCommand();
        
        Definition* def;

        KRuler* rulerv;
        KRuler* rulerh;

        KCommandHistory* history;
        KMacroCommand* m_commov;
        MyCanvas* canv;

        int mouseid;
        KStatusBar* statusbar;

        TQPoint moving_start;
        TQPoint translation;

        TQRect old;

        bool isInside( TQPoint p, TQCanvasItem* item );
        int isEdge(  TQPoint p, TQCanvasItem* item  );
        void reposition();
        void updateRuler();
        int updateCursor( TQPoint pos, bool pressed = false );
        int m_mode;
        TQPoint delta_pt ;
};

#endif