1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
--- src/widgets/qpopupmenu.cpp.sav
+++ src/widgets/qpopupmenu.cpp
@@ -457,6 +457,15 @@
menuContentsChanged();
}
+QRect QPopupMenu::screenRect( const QPoint& pos )
+{
+ int screen_num = QApplication::desktop()->screenNumber( pos );
+#ifdef Q_WS_MAC
+ return QApplication::desktop()->availableGeometry( screen_num );
+#else
+ return QApplication::desktop()->screenGeometry( screen_num );
+#endif
+}
/*!
Displays the popup menu so that the item number \a indexAtPoint
will be at the specified \e global position \a pos. To translate a
@@ -501,6 +510,15 @@
// point.
#endif
+ QRect screen = screenRect( geometry().center());
+ QRect screen2 = screenRect( QApplication::reverseLayout()
+ ? pos+QPoint(width(),0) : pos );
+ // if the widget is not in the screen given by the position, move it
+ // there, so that updateSize() uses the right size of the screen
+ if( screen != screen2 ) {
+ screen = screen2;
+ move( screen.x(), screen.y());
+ }
if(d->scroll.scrollable) {
d->scroll.scrollable = QPopupMenuPrivate::Scroll::ScrollNone;
d->scroll.topScrollableIndex = d->scroll.scrollableSize = 0;
@@ -520,18 +538,6 @@
updateSize(TRUE);
}
- int screen_num;
- if (QApplication::desktop()->isVirtualDesktop())
- screen_num =
- QApplication::desktop()->screenNumber( QApplication::reverseLayout() ?
- pos+QPoint(width(),0) : pos );
- else
- screen_num = QApplication::desktop()->screenNumber( this );
-#ifdef Q_WS_MAC
- QRect screen = QApplication::desktop()->availableGeometry( screen_num );
-#else
- QRect screen = QApplication::desktop()->screenGeometry( screen_num );
-#endif
int sw = screen.width(); // screen width
int sh = screen.height(); // screen height
int sx = screen.x(); // screen pos
@@ -1059,7 +1065,7 @@
mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 4 );
}
- int dh = QApplication::desktop()->height();
+ int dh = screenRect( geometry().center()).height();
ncols = 1;
for ( QMenuItemListIt it2( *mitems ); it2.current(); ++it2 ) {
@@ -2313,9 +2319,9 @@
bool right = FALSE;
if ( ( parentMenu && parentMenu->isPopupMenu &&
((QPopupMenu*)parentMenu)->geometry().x() < geometry().x() ) ||
- p.x() < 0 )
+ p.x() < screenRect( p ).left())
right = TRUE;
- if ( right && (ps.width() > QApplication::desktop()->width() - mapToGlobal( r.topRight() ).x() ) )
+ if ( right && (ps.width() > screenRect( p ).right() - mapToGlobal( r.topRight() ).x() ) )
right = FALSE;
if ( right )
p.setX( mapToGlobal( r.topRight() ).x() );
@@ -2326,7 +2332,7 @@
bool left = FALSE;
if ( ( parentMenu && parentMenu->isPopupMenu &&
((QPopupMenu*)parentMenu)->geometry().x() > geometry().x() ) ||
- p.x() + ps.width() > QApplication::desktop()->width() )
+ p.x() + ps.width() > screenRect( p ).right() )
left = TRUE;
if ( left && (ps.width() > mapToGlobal( r.topLeft() ).x() ) )
left = FALSE;
@@ -2334,8 +2340,8 @@
p.setX( mapToGlobal( r.topLeft() ).x() - ps.width() );
}
QRect pr = popup->itemGeometry(popup->count() - 1);
- if (p.y() + ps.height() > QApplication::desktop()->height() &&
- p.y() - ps.height() + (QCOORD) pr.height() >= 0)
+ if (p.y() + ps.height() > screenRect( p ).bottom() &&
+ p.y() - ps.height() + (QCOORD) pr.height() >= screenRect( p ).top())
p.setY( p.y() - ps.height() + (QCOORD) pr.height());
if ( style().styleHint(QStyle::SH_PopupMenu_SloppySubMenus, this )) {
--- src/widgets/qpopupmenu.h.sav
+++ src/widgets/qpopupmenu.h
@@ -152,6 +152,7 @@
QSize updateSize(bool force_recalc=FALSE, bool do_resize=TRUE);
void updateRow( int row );
+ QRect screenRect(const QPoint& pos);
#ifndef QT_NO_ACCEL
void updateAccel( QWidget * );
void enableAccel( bool );
|