Skip to content

Commit 7d6b7cc

Browse files
author
Sandro Santilli
committed
Show actually visible canvas area in overview (possibly rotated)
Fix #11862
1 parent 1ccf558 commit 7d6b7cc

File tree

1 file changed

+16
-72
lines changed

1 file changed

+16
-72
lines changed

src/gui/qgsmapoverviewcanvas.cpp

+16-72
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
//! widget that serves as rectangle showing current extent in overview
3434
class QgsPanningWidget : public QWidget
3535
{
36+
QPolygon mPoly;
37+
3638
public:
3739
QgsPanningWidget( QWidget* parent )
3840
: QWidget( parent )
@@ -42,26 +44,24 @@ class QgsPanningWidget : public QWidget
4244
setAttribute( Qt::WA_NoSystemBackground );
4345
}
4446

45-
void resizeEvent( QResizeEvent* r ) override
47+
void setPolygon( const QPolygon& p )
4648
{
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();
5253
}
5354

5455

5556
void paintEvent( QPaintEvent* pe ) override
5657
{
5758
Q_UNUSED( pe );
5859

59-
QRect r( QPoint( 0, 0 ), size() );
6060
QPainter p;
6161
p.begin( this );
6262
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 );
6565
p.end();
6666
}
6767

@@ -122,70 +122,14 @@ void QgsMapOverviewCanvas::drawExtentRect()
122122
return;
123123
}
124124

125+
const QPolygonF& vPoly = mMapCanvas->mapSettings().visiblePolygon();
125126
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) );
189133
mPanningWidget->show(); // show if hidden
190134
}
191135

0 commit comments

Comments
 (0)