18
18
#include < string>
19
19
#include < vector>
20
20
21
- #include " portability.h"
21
+ // #include "portability.h"
22
+ #include " shorthands.h"
22
23
23
24
24
25
// #include <qvbox.h>
25
26
// #include <qhbox.h>
26
27
// #define QHBOX QHBox
27
28
28
- #include < qpainter.h>
29
- #include < qpixmap.h>
30
- #include < qpicture.h>
31
- #include < qdialog.h>
32
- #include < qlineedit.h>
29
+ // #include <QPainter>
30
+ #include < QPixmap>
31
+ // #include <QPicture>
32
+ #include < QDialog>
33
+ #include < QLineEdit>
34
+ #include < QCheckBox>
35
+ #include < QGraphicsView>
36
+ #include < QGraphicsScene>
37
+ #include < QGraphicsPixmapItem>
38
+ #include < QMainWindow>
39
+ #include < QAction>
33
40
34
41
#include " ImageTransform.h"
35
42
#include " Language.h"
36
43
44
+ #include " BackgroundImageStationSet.h"
45
+
46
+ #define ZOOM_STEP 1.41
47
+
37
48
class BackgroundImage ;
38
49
39
- /* * sketch image display
40
- */
41
- class BackgroundImageShow : public QWidget
50
+ class BackgroundImageScene : public QGraphicsScene
42
51
{
43
- // Q_OBJECT
44
52
private:
45
- BackgroundImage * image; // !< main window
53
+ BackgroundImageStationSet stations;
54
+ BackgroundImage * image;
55
+ QGraphicsPixmapItem * pixmap;
46
56
QPixmap * orig_pix; // !< original pixmap (N.B. caller must manage it FIXME)
47
- QPixmap pix; // !< current pixmap
48
- int xs, ys; // !< temporary station coordinates
49
- int zoom; // !< zoom value
50
- int xpos; // !< X offset
51
- int ypos; // !< Y offset
52
-
57
+ bool do_add_station;
58
+ bool do_remove_station;
59
+ QString station_name;
60
+
53
61
public:
54
- /* * cstr
55
- * @param my_image image main window
56
- */
57
- BackgroundImageShow ( BackgroundImage * my_image );
62
+ BackgroundImageScene ( BackgroundImage * my_image );
58
63
59
- /* * dstr
60
- * @note the original pixmap is not destroyed
61
- * must be passed to the caller (or upper) before dstr
62
- * and the caller must manage it
63
- */
64
- ~BackgroundImageShow () { }
64
+ ~BackgroundImageScene ();
65
65
66
- /* * set the temporary station coordinates
67
- * @param x X
68
- * @param y Y
69
- */
70
- void setStation ( int x = -1 , int y = -1 )
71
- {
72
- xs = x;
73
- ys = y;
74
- if ( xs >= 0 ) showIt ();
75
- }
76
-
77
- /* * load a PNG image
78
- * @param name image filename
66
+ /* * accessor for the image
67
+ * @return the pointer to the background image
68
+ * FIXME
79
69
*/
80
- void LoadImage ( const char * name );
70
+ QPixmap * getImage () { return orig_pix; }
71
+ // const QPixmap & getPixmap() const { return pixmap->pixmap(); }
81
72
82
- /* * apply the zoom and display the sketch
83
- * @param in_out zoom variation (pos. increase; neg. decrease)
84
- */
85
- void doZoom ( int in_out );
86
73
87
- /* * mode the sketch
88
- * @param dx X displacement
89
- * @param dy Y displacement
90
- */
91
- void doMove ( int dx, int dy );
74
+ // callback for StationDialog
75
+ void setStationName ( QString & name )
76
+ {
77
+ do_add_station = ! name.isEmpty ();
78
+ station_name = name;
79
+ }
80
+
81
+ void setRemoveStation ( bool remove ) { do_remove_station = remove ; }
92
82
93
- /* * accessor for the zoom value
94
- * @return the value of the zoom
95
- */
96
- int Zoom () const { return zoom; }
83
+ const std::vector< BackgroundImageStation * > & getStations ()
84
+ {
85
+ return stations. getStations ();
86
+ }
97
87
98
- /* * accessor for the X position
99
- * @return the value of the X position
100
- */
101
- int Xpos () const { return xpos; }
88
+ void mouseReleaseEvent ( QGraphicsSceneMouseEvent * e0 );
89
+ void mousePressEvent ( QGraphicsSceneMouseEvent * e0 );
102
90
103
- /* * accessor for the Y position
104
- * @return the value of the Y position
91
+ /* * load a PNG image
92
+ * @param name image filename
105
93
*/
106
- int Ypos () const { return ypos; }
94
+ void loadImage ( const char * name );
107
95
108
- /* * accessor for the image
109
- * @return the pointer to the background image
110
- */
111
- QPixmap * GetImage () { return orig_pix; }
96
+ void changeStation ( BackgroundImageStation * st, QString name )
97
+ {
98
+ st->setName ( name );
99
+ }
100
+ };
112
101
102
+ /* * sketch image display
103
+ */
104
+ class BackgroundImageView : public QGraphicsView
105
+ {
106
+ // Q_OBJECT
113
107
private:
114
- /* * display
108
+ BackgroundImage * image; // !< main window
109
+ BackgroundImageScene * scene; // !< scene
110
+
111
+ public:
112
+ /* * cstr
113
+ * @param parent image main window
114
+ * @param scene image scene
115
115
*/
116
- void showIt ( );
116
+ BackgroundImageView ( BackgroundImage * parent, BackgroundImageScene * scene );
117
117
118
- /* * handle paint event
119
- * @param e paint event
118
+ /* * dstr
119
+ * @note the original pixmap is not destroyed
120
+ * must be passed to the caller (or upper) before dstr
121
+ * and the caller must manage it
120
122
*/
121
- void paintEvent ( QPaintEvent * e );
123
+ ~BackgroundImageView () { }
122
124
123
125
};
124
126
127
+
128
+
125
129
/* * sketch image main window
126
130
*/
127
- class BackgroundImage : public QMAINWINDOW
131
+ class BackgroundImage : public QMainWindow
128
132
{
129
133
Q_OBJECT
130
134
private:
131
135
QWidget * parent; // !< parent widget
132
136
Language & lexicon;
133
137
int offset_y; // !< Y offset of the image on the screen
134
138
BackgroundImageCallback * callback; // !<
135
- BackgroundImageShow * mis; // !< sketch image display
136
- std::vector< BackgroundImageStation > stations; // !< stations correspondences
139
+ BackgroundImageView * view; // !< sketch image display
140
+ BackgroundImageScene * scene;
141
+
142
+ QAction * actOk;
143
+ QAction * actQuit;
144
+ QAction * actZoomIn;
145
+ QAction * actZoomOut;
137
146
138
147
public:
139
148
/* * cstr
@@ -149,64 +158,6 @@ class BackgroundImage : public QMAINWINDOW
149
158
*/
150
159
virtual ~BackgroundImage ();
151
160
152
- /* * add a new station point (correspondence)
153
- * @param name station name
154
- * @param x X coord of the point on the pixmap
155
- * @param y Y coord of the point on the pixmap
156
- */
157
- void addStation ( const QString & name, int x, int y )
158
- {
159
- stations.push_back ( BackgroundImageStation ( name.latin1 (), x, y) );
160
- // update();
161
- }
162
-
163
- /* * get the station at a point (actually close to)
164
- * @param x x coord
165
- * @param y y coord
166
- * @return station or NULL
167
- */
168
- BackgroundImageStation * getStationAt ( int x, int y )
169
- {
170
- for ( std::vector< BackgroundImageStation >::iterator sit = stations.begin (),
171
- end = stations.end ();
172
- sit != end;
173
- ++sit ) {
174
- if ( abs (x - sit->x ) < 4 && abs (y - sit->y ) < 4 )
175
- return &(*sit);
176
- }
177
- return NULL ;
178
- }
179
-
180
- void removeStation ( BackgroundImageStation * st )
181
- {
182
- for ( std::vector< BackgroundImageStation >::iterator sit = stations.begin (),
183
- end = stations.end ();
184
- sit != end;
185
- ++sit ) {
186
- if ( &(*sit) == st ) {
187
- stations.erase ( sit );
188
- break ;
189
- }
190
- }
191
- // TODO update();
192
- }
193
-
194
- void changeStation ( BackgroundImageStation * st, const char * name )
195
- {
196
- st->name = name;
197
- // TODO update();
198
- }
199
-
200
-
201
-
202
- /* * get the vector of stations
203
- * @return a ref. to the vector of stations
204
- */
205
- const std::vector< BackgroundImageStation > & getStations () const { return stations; }
206
-
207
- private:
208
- void mousePressEvent ( QMouseEvent * e );
209
-
210
161
public slots:
211
162
/* * set the image as canvas background
212
163
*/
@@ -216,17 +167,14 @@ class BackgroundImage : public QMAINWINDOW
216
167
*/
217
168
void doQuit ();
218
169
219
- /* * zoom in and out
220
- */
221
- void doZoomIn () { mis->doZoom ( 1 ); }
222
- void doZoomOut () { mis->doZoom ( -1 ); }
170
+ void onZoomIn () { view->scale ( ZOOM_STEP, ZOOM_STEP ); }
223
171
224
- /* * move the image left/right and up/down
225
- */
226
- void doDown () { mis-> doMove ( 0 , - 1 ); }
227
- void doUp () { mis-> doMove ( 0 , 1 ); }
228
- void doRight () { mis-> doMove ( - 1 , 0 ); }
229
- void doLeft () { mis-> doMove ( 1 , 0 ); }
172
+ void onZoomOut () { view-> scale ( 1.0 /ZOOM_STEP, 1.0 /ZOOM_STEP ); }
173
+
174
+ private:
175
+ void createToolBar ();
176
+
177
+ void createActions ();
230
178
};
231
179
232
180
@@ -236,18 +184,22 @@ class BackgroundImageStationDialog : public QDialog
236
184
{
237
185
Q_OBJECT
238
186
private:
239
- BackgroundImage * parent ;
187
+ BackgroundImageScene * scene ;
240
188
QLineEdit * station;
241
- int x;
242
- int y;
243
189
244
190
public:
245
- BackgroundImageStationDialog ( BackgroundImage * my_parent, int x0, int y0 );
191
+ BackgroundImageStationDialog ( BackgroundImage * my_parent,
192
+ BackgroundImageScene * scene );
246
193
247
194
public slots:
248
195
void doOK ();
249
196
250
- void doCancel () { delete this ; }
197
+ void doCancel ()
198
+ {
199
+ hide ();
200
+ QString empty; // actually null
201
+ scene->setStationName ( empty );
202
+ }
251
203
};
252
204
253
205
/* * dialog to edit the station names
@@ -257,17 +209,23 @@ class BackgroundImageEditStationDialog : public QDialog
257
209
Q_OBJECT
258
210
private:
259
211
BackgroundImage * parent;
212
+ BackgroundImageScene * scene;
260
213
BackgroundImageStation * station;
261
214
QLineEdit * st_name;
262
215
QCheckBox * remove;
263
216
264
217
public:
265
- BackgroundImageEditStationDialog ( BackgroundImage * my_parent, BackgroundImageStation * st );
218
+ BackgroundImageEditStationDialog ( BackgroundImage * my_parent,
219
+ BackgroundImageScene * my_scene,
220
+ BackgroundImageStation * st );
266
221
267
222
public slots:
268
223
void doOK ();
269
224
270
- void doCancel () { delete this ; }
225
+ void doCancel ()
226
+ {
227
+ hide ();
228
+ }
271
229
};
272
230
273
231
#endif
0 commit comments