Skip to content

Commit 250d7ad

Browse files
committed
1 parent a4d242e commit 250d7ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5879
-4577
lines changed

QTshot/BackgroundImage.cpp

+293-227
Large diffs are not rendered by default.

QTshot/BackgroundImage.h

+106-148
Original file line numberDiff line numberDiff line change
@@ -18,122 +18,131 @@
1818
#include <string>
1919
#include <vector>
2020

21-
#include "portability.h"
21+
// #include "portability.h"
22+
#include "shorthands.h"
2223

2324

2425
// #include <qvbox.h>
2526
// #include <qhbox.h>
2627
// #define QHBOX QHBox
2728

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>
3340

3441
#include "ImageTransform.h"
3542
#include "Language.h"
3643

44+
#include "BackgroundImageStationSet.h"
45+
46+
#define ZOOM_STEP 1.41
47+
3748
class BackgroundImage;
3849

39-
/** sketch image display
40-
*/
41-
class BackgroundImageShow : public QWidget
50+
class BackgroundImageScene: public QGraphicsScene
4251
{
43-
// Q_OBJECT
4452
private:
45-
BackgroundImage * image; //!< main window
53+
BackgroundImageStationSet stations;
54+
BackgroundImage * image;
55+
QGraphicsPixmapItem * pixmap;
4656
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+
5361
public:
54-
/** cstr
55-
* @param my_image image main window
56-
*/
57-
BackgroundImageShow( BackgroundImage * my_image );
62+
BackgroundImageScene( BackgroundImage * my_image );
5863

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();
6565

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
7969
*/
80-
void LoadImage( const char * name );
70+
QPixmap * getImage() { return orig_pix; }
71+
// const QPixmap & getPixmap() const { return pixmap->pixmap(); }
8172

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 );
8673

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; }
9282

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+
}
9787

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 );
10290

103-
/** accessor for the Y position
104-
* @return the value of the Y position
91+
/** load a PNG image
92+
* @param name image filename
10593
*/
106-
int Ypos() const { return ypos; }
94+
void loadImage( const char * name );
10795

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+
};
112101

102+
/** sketch image display
103+
*/
104+
class BackgroundImageView : public QGraphicsView
105+
{
106+
// Q_OBJECT
113107
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
115115
*/
116-
void showIt();
116+
BackgroundImageView( BackgroundImage * parent, BackgroundImageScene * scene );
117117

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
120122
*/
121-
void paintEvent( QPaintEvent * e );
123+
~BackgroundImageView() { }
122124

123125
};
124126

127+
128+
125129
/** sketch image main window
126130
*/
127-
class BackgroundImage : public QMAINWINDOW
131+
class BackgroundImage : public QMainWindow
128132
{
129133
Q_OBJECT
130134
private:
131135
QWidget * parent; //!< parent widget
132136
Language & lexicon;
133137
int offset_y; //!< Y offset of the image on the screen
134138
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;
137146

138147
public:
139148
/** cstr
@@ -149,64 +158,6 @@ class BackgroundImage : public QMAINWINDOW
149158
*/
150159
virtual ~BackgroundImage();
151160

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-
210161
public slots:
211162
/** set the image as canvas background
212163
*/
@@ -216,17 +167,14 @@ class BackgroundImage : public QMAINWINDOW
216167
*/
217168
void doQuit();
218169

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 ); }
223171

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();
230178
};
231179

232180

@@ -236,18 +184,22 @@ class BackgroundImageStationDialog : public QDialog
236184
{
237185
Q_OBJECT
238186
private:
239-
BackgroundImage * parent;
187+
BackgroundImageScene * scene;
240188
QLineEdit * station;
241-
int x;
242-
int y;
243189

244190
public:
245-
BackgroundImageStationDialog( BackgroundImage * my_parent, int x0, int y0 );
191+
BackgroundImageStationDialog( BackgroundImage * my_parent,
192+
BackgroundImageScene * scene );
246193

247194
public slots:
248195
void doOK();
249196

250-
void doCancel() { delete this; }
197+
void doCancel()
198+
{
199+
hide();
200+
QString empty; // actually null
201+
scene->setStationName( empty );
202+
}
251203
};
252204

253205
/** dialog to edit the station names
@@ -257,17 +209,23 @@ class BackgroundImageEditStationDialog : public QDialog
257209
Q_OBJECT
258210
private:
259211
BackgroundImage * parent;
212+
BackgroundImageScene * scene;
260213
BackgroundImageStation * station;
261214
QLineEdit * st_name;
262215
QCheckBox * remove;
263216

264217
public:
265-
BackgroundImageEditStationDialog( BackgroundImage * my_parent, BackgroundImageStation * st );
218+
BackgroundImageEditStationDialog( BackgroundImage * my_parent,
219+
BackgroundImageScene * my_scene,
220+
BackgroundImageStation * st );
266221

267222
public slots:
268223
void doOK();
269224

270-
void doCancel() { delete this; }
225+
void doCancel()
226+
{
227+
hide();
228+
}
271229
};
272230

273231
#endif

QTshot/CanvasMode.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
enum InputMode {
2323
INPUT_COMMAND,
2424
INPUT_POINT,
25-
INPUT_LINE
25+
INPUT_LINE,
26+
INPUT_AREA
2627
};
2728

2829
#endif

0 commit comments

Comments
 (0)