33
33
// ! widget that serves as rectangle showing current extent in overview
34
34
class QgsPanningWidget : public QWidget
35
35
{
36
+ QPolygon mPoly ;
37
+
36
38
public:
37
39
QgsPanningWidget ( QWidget* parent )
38
40
: QWidget( parent )
@@ -42,26 +44,24 @@ class QgsPanningWidget : public QWidget
42
44
setAttribute ( Qt::WA_NoSystemBackground );
43
45
}
44
46
45
- void resizeEvent ( QResizeEvent* r ) override
47
+ void setPolygon ( const QPolygon& p )
46
48
{
47
- QSize s = r->size ();
48
- QRegion reg ( 0 , 0 , s.width (), s.height () );
49
- QRegion reg2 ( 2 , 2 , s.width () - 4 , s.height () - 4 );
50
- QRegion reg3 = reg.subtracted ( reg2 );
51
- setMask ( reg3 );
49
+ if ( p == mPoly ) return ;
50
+ mPoly = p;
51
+ setGeometry ( p.boundingRect () );
52
+ repaint ();
52
53
}
53
54
54
55
55
56
void paintEvent ( QPaintEvent* pe ) override
56
57
{
57
58
Q_UNUSED ( pe );
58
59
59
- QRect r ( QPoint ( 0 , 0 ), size () );
60
60
QPainter p;
61
61
p.begin ( this );
62
62
p.setPen ( Qt::red );
63
- p. setBrush ( Qt::red );
64
- p.drawRect ( r );
63
+ QPolygonF t = mPoly . translated ( - mPoly . boundingRect (). left (), - mPoly . boundingRect (). top () );
64
+ p.drawConvexPolygon ( t );
65
65
p.end ();
66
66
}
67
67
@@ -122,70 +122,14 @@ void QgsMapOverviewCanvas::drawExtentRect()
122
122
return ;
123
123
}
124
124
125
+ const QPolygonF& vPoly = mMapCanvas ->mapSettings ().visiblePolygon ();
125
126
const QgsMapToPixel& cXf = mSettings .mapToPixel ();
126
- QgsPoint ll ( extent.xMinimum (), extent.yMinimum () );
127
- QgsPoint ur ( extent.xMaximum (), extent.yMaximum () );
128
-
129
- // transform the points before drawing
130
- cXf.transform ( &ll );
131
- cXf.transform ( &ur );
132
-
133
- #if 0
134
- // test whether panning widget should be drawn
135
- bool show = false;
136
- if ( ur.x() >= 0 && ur.x() < width() )
137
- show = true;
138
- if ( ll.x() >= 0 && ll.x() < width() )
139
- show = true;
140
- if ( ur.y() >= 0 && ur.y() < height() )
141
- show = true;
142
- if ( ll.y() >= 0 && ll.y() < height() )
143
- show = true;
144
- if ( !show )
145
- {
146
- QgsDebugMsg( "panning: extent out of overview area" );
147
- mPanningWidget->hide();
148
- return;
149
- }
150
- #endif
151
-
152
- // round values
153
- int x1 = static_cast <int >( ur.x () + 0.5 ), x2 = static_cast <int >( ll.x () + 0.5 );
154
- int y1 = static_cast <int >( ur.y () + 0.5 ), y2 = static_cast <int >( ll.y () + 0.5 );
155
-
156
- if ( x1 > x2 )
157
- std::swap ( x1, x2 );
158
- if ( y1 > y2 )
159
- std::swap ( y1 , y2 );
160
-
161
- #ifdef Q_OS_MAC
162
- // setGeometry (Qt 4.2) is causing Mac window corruption (decorations
163
- // are drawn at odd locations) if both coords are at limit. This may
164
- // have something to do with Qt calculating dimensions as x2 - x1 + 1.
165
- // (INT_MAX - INT_MIN + 1 is UINT_MAX + 1)
166
- if ( x1 == INT_MIN && x2 == INT_MAX )
167
- x1 += 1 ; // x2 -= 1 works too
168
- if ( y1 == INT_MIN && y2 == INT_MAX )
169
- y1 += 1 ;
170
- #endif
171
-
172
- QRect r ( x1, y1 , x2 - x1 + 1 , y2 - y1 + 1 );
173
-
174
- // allow for 5 pixel minimum widget size
175
- if ( r.width () < 5 && x1 > INT_MIN + 2 ) // make sure no underflow occurs (2 is largest adjustment)
176
- {
177
- r.setX ( r.x () - (( 5 - r.width () ) / 2 ) ); // adjust x by 1/2 the difference of calculated and min. width
178
- r.setWidth ( 5 );
179
- }
180
- if ( r.height () < 5 && y1 > INT_MIN + 2 )
181
- {
182
- r.setY ( r.y () - (( 5 - r.height () ) / 2 ) ); // adjust y
183
- r.setHeight ( 5 );
184
- }
185
-
186
- QgsDebugMsg ( QString ( " panning: extent to widget: [%1,%2] [%3x%4]" ).arg ( x1 ).arg ( y1 ).arg ( r.width () ).arg ( r.height () ) );
187
-
188
- mPanningWidget ->setGeometry ( r );
127
+ QVector< QPoint > pts;
128
+ pts.push_back ( cXf.transform ( QgsPoint (vPoly[0 ]) ).toQPointF ().toPoint () );
129
+ pts.push_back ( cXf.transform ( QgsPoint (vPoly[1 ]) ).toQPointF ().toPoint () );
130
+ pts.push_back ( cXf.transform ( QgsPoint (vPoly[2 ]) ).toQPointF ().toPoint () );
131
+ pts.push_back ( cXf.transform ( QgsPoint (vPoly[3 ]) ).toQPointF ().toPoint () );
132
+ mPanningWidget ->setPolygon ( QPolygon (pts) );
189
133
mPanningWidget ->show (); // show if hidden
190
134
}
191
135
0 commit comments