~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Gui/MouseModel.h

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
Import upstream version 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2005 Werner Mayer <werner.wm.mayer@gmx.de>              *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
6
 *   This library is free software; you can redistribute it and/or         *
 
7
 *   modify it under the terms of the GNU Library General Public           *
 
8
 *   License as published by the Free Software Foundation; either          *
 
9
 *   version 2 of the License, or (at your option) any later version.      *
 
10
 *                                                                         *
 
11
 *   This library  is distributed in the hope that it will be useful,      *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU Library General Public License for more details.                  *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU Library General Public     *
 
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
 
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#ifndef MOUSEMODEL_H
 
25
#define MOUSEMODEL_H
 
26
 
 
27
#ifndef __Qt4All__
 
28
# include "Qt4All.h"
 
29
#endif
 
30
 
 
31
#include <vector>
 
32
#include <Inventor/SbLinear.h>
 
33
#include <Inventor/SbVec2f.h>
 
34
 
 
35
// forwards
 
36
class QMouseEvent;
 
37
class QWheelEvent;
 
38
class QKeyEvent;
 
39
class QPaintEvent;
 
40
class QResizeEvent;
 
41
class SoEvent;
 
42
class SbViewportRegion;
 
43
class SoMouseButtonEvent;
 
44
class SoLocation2Event;
 
45
class SoKeyboardEvent;
 
46
 
 
47
namespace Gui {
 
48
class View3DInventorViewer;
 
49
 
 
50
/**
 
51
 * The mouse model base class
 
52
 * In derived classes you must implement the methods @ref initialize() and @ref terminate()
 
53
 * For all drawing stuff you just have to reimplement the @ref draw() method. 
 
54
 * In general you need not to do anything else.
 
55
 * \author Werner Mayer and J�rgen Riegel
 
56
 */
 
57
class GuiExport AbstractMouseModel
 
58
{
 
59
public:
 
60
    enum { Continue=0, Restart=1, Finish=2, Cancel=3 };
 
61
 
 
62
    AbstractMouseModel();
 
63
    virtual ~AbstractMouseModel(void){}
 
64
    /// implement this in derived classes
 
65
    virtual void initialize() = 0;
 
66
    /// implement this in derived classes
 
67
    virtual void terminate () = 0;
 
68
    void grabMouseModel(Gui::View3DInventorViewer*);
 
69
    void releaseMouseModel(void);
 
70
    const std::vector<SbVec2f>& getPolygon() const { return _clPoly; }
 
71
    SbBool isInner() const { return m_bInner; }
 
72
 
 
73
    void redraw();
 
74
 
 
75
    /** @name Mouse events*/
 
76
    //@{
 
77
    int handleEvent(const SoEvent * const ev, const SbViewportRegion& vp);
 
78
    //@}
 
79
 
 
80
protected:
 
81
    virtual int mouseButtonEvent( const SoMouseButtonEvent * const e, const QPoint& pos ){ return 0; };
 
82
    virtual int locationEvent   ( const SoLocation2Event   * const e, const QPoint& pos ){ return 0; };
 
83
    virtual int keyboardEvent   ( const SoKeyboardEvent    * const e )                   { return 0; };
 
84
 
 
85
    /// drawing stuff
 
86
    virtual void draw (){};
 
87
 
 
88
protected:
 
89
    Gui::View3DInventorViewer*_pcView3D;
 
90
    QCursor m_cPrevCursor;
 
91
    int  m_iXold, m_iYold;
 
92
    int  m_iXnew, m_iYnew;
 
93
    SbBool m_bInner;
 
94
    SbBool mustRedraw;
 
95
 
 
96
private:
 
97
    std::vector<SbVec2f> _clPoly;
 
98
};
 
99
 
 
100
// -----------------------------------------------------------------------------------
 
101
 
 
102
/**
 
103
 * The standard model class
 
104
 * \author J�rgen Riegel
 
105
 */
 
106
class GuiExport BaseMouseModel : public AbstractMouseModel
 
107
{
 
108
public:
 
109
    BaseMouseModel();
 
110
    virtual ~BaseMouseModel(){}
 
111
};
 
112
 
 
113
// -----------------------------------------------------------------------------------
 
114
 
 
115
/**
 
116
 * The poly picker mouse model class
 
117
 * Create a polygon
 
118
 * \author Werner Mayer
 
119
 */
 
120
class GuiExport PolyPickerMouseModel : public BaseMouseModel
 
121
{
 
122
public:
 
123
    PolyPickerMouseModel();
 
124
    virtual ~PolyPickerMouseModel();
 
125
 
 
126
    /// set the new mouse cursor
 
127
    virtual void initialize();
 
128
    /// do nothing
 
129
    virtual void terminate();
 
130
 
 
131
protected:
 
132
    virtual int mouseButtonEvent( const SoMouseButtonEvent * const e, const QPoint& pos );
 
133
    virtual int locationEvent   ( const SoLocation2Event   * const e, const QPoint& pos );
 
134
    virtual int keyboardEvent   ( const SoKeyboardEvent    * const e );
 
135
 
 
136
    /// draw the polygon
 
137
    virtual void draw ();
 
138
    virtual int popupMenu();
 
139
 
 
140
protected:
 
141
    std::vector<QPoint> _cNodeVector;
 
142
    int  m_iRadius, m_iNodes;
 
143
    bool m_bWorking;
 
144
};
 
145
 
 
146
// -----------------------------------------------------------------------------------
 
147
 
 
148
/**
 
149
 * The poly clip mouse model class
 
150
 * Create a polygon
 
151
 * \author Werner Mayer
 
152
 */
 
153
class GuiExport PolyClipMouseModel : public PolyPickerMouseModel
 
154
{
 
155
public:
 
156
    PolyClipMouseModel();
 
157
    virtual ~PolyClipMouseModel();
 
158
 
 
159
protected:
 
160
    virtual int popupMenu();
 
161
};
 
162
 
 
163
// -----------------------------------------------------------------------------------
 
164
 
 
165
/**
 
166
 * The selection mouse model class
 
167
 * Draws a rectangle for selection
 
168
 * \author Werner Mayer
 
169
 */
 
170
class GuiExport SelectionMouseModel : public BaseMouseModel 
 
171
{
 
172
public:
 
173
    SelectionMouseModel();
 
174
    virtual ~SelectionMouseModel();
 
175
 
 
176
    /// do nothing
 
177
    virtual void initialize();
 
178
    /// do nothing
 
179
    virtual void terminate();
 
180
 
 
181
protected:
 
182
    virtual int mouseButtonEvent( const SoMouseButtonEvent * const e, const QPoint& pos );
 
183
    virtual int locationEvent   ( const SoLocation2Event   * const e, const QPoint& pos );
 
184
    virtual int keyboardEvent   ( const SoKeyboardEvent    * const e );
 
185
 
 
186
    /// draw the rectangle
 
187
    virtual void draw ();
 
188
 
 
189
private:
 
190
    bool m_bWorking;
 
191
};
 
192
 
 
193
// -----------------------------------------------------------------------------------
 
194
 
 
195
/**
 
196
 * The box zoom mouse model class
 
197
 * Draws a rectangle for box zooming
 
198
 * \author Werner Mayer
 
199
 */
 
200
class GuiExport BoxZoomMouseModel : public SelectionMouseModel 
 
201
{
 
202
public:
 
203
    BoxZoomMouseModel();
 
204
    ~BoxZoomMouseModel();
 
205
    void terminate();
 
206
};
 
207
 
 
208
} // namespace Gui
 
209
 
 
210
#endif // MOUSEMODEL_H