Index: trunk/src/gui/widgets/qpushbutton.cpp
===================================================================
--- trunk/src/gui/widgets/qpushbutton.cpp	(revision 306)
+++ trunk/src/gui/widgets/qpushbutton.cpp	(revision 561)
@@ -2,5 +2,6 @@
 **
 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
 **
 ** This file is part of the QtGui module of the Qt Toolkit.
@@ -21,8 +22,7 @@
 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 **
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 **
 ** GNU General Public License Usage
@@ -34,6 +34,6 @@
 ** met: http://www.gnu.org/copyleft/gpl.html.
 **
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
 ** $QT_END_LICENSE$
 **
@@ -64,4 +64,5 @@
 #endif
 
+#include "private/qmenu_p.h"
 #include "private/qpushbutton_p.h"
 
@@ -74,5 +75,5 @@
 
     \ingroup basicwidgets
-    \mainclass
+
 
     The push button, or command button, is perhaps the most commonly
@@ -388,6 +389,7 @@
 {
     Q_D(const QPushButton);
-    if (d->sizeHint.isValid())
+    if (d->sizeHint.isValid() && d->lastAutoDefault == autoDefault())
         return d->sizeHint;
+    d->lastAutoDefault = autoDefault();
     ensurePolished();
 
@@ -528,6 +530,5 @@
 
     if (menu && !d->menu) {
-        disconnect(this, SIGNAL(pressed()), this, SLOT(_q_popupPressed()));
-        connect(this, SIGNAL(pressed()), this, SLOT(_q_popupPressed()));
+        connect(this, SIGNAL(pressed()), this, SLOT(_q_popupPressed()), Qt::UniqueConnection);
     }
     if (d->menu)
@@ -576,10 +577,31 @@
 
     menu->setNoReplayFor(q);
+
+    QPoint menuPos = adjustedMenuPosition();
+
+    QPointer<QPushButton> guard(q);
+    QMenuPrivate::get(menu)->causedPopup.widget = guard;
+
+    //Because of a delay in menu effects, we must keep track of the
+    //menu visibility to avoid flicker on button release
+    menuOpen = true;
+    menu->exec(menuPos);
+    if (guard) {
+        menuOpen = false;
+        q->setDown(false);
+    }
+}
+
+QPoint QPushButtonPrivate::adjustedMenuPosition()
+{
+    Q_Q(QPushButton);
+
     bool horizontal = true;
 #if !defined(QT_NO_TOOLBAR)
-    QToolBar *tb = qobject_cast<QToolBar*>(q->parentWidget());
+    QToolBar *tb = qobject_cast<QToolBar*>(parent);
     if (tb && tb->orientation() == Qt::Vertical)
         horizontal = false;
 #endif
+
     QWidgetItem item(q);
     QRect rect = item.geometry();
@@ -591,5 +613,5 @@
     int y = globalPos.y();
     if (horizontal) {
-        if (globalPos.y() + rect.height() + menuSize.height() <= qApp->desktop()->height()) {
+        if (globalPos.y() + rect.height() + menuSize.height() <= QApplication::desktop()->availableGeometry(q).height()) {
             y += rect.height();
         } else {
@@ -599,29 +621,13 @@
             x += rect.width() - menuSize.width();
     } else {
-        if (globalPos.x() + rect.width() + menu->sizeHint().width() <= qApp->desktop()->width())
+        if (globalPos.x() + rect.width() + menu->sizeHint().width() <= QApplication::desktop()->availableGeometry(q).width())
             x += rect.width();
         else
             x -= menuSize.width();
     }
-    QPointer<QPushButton> guard(q);
-
-    //Because of a delay in menu effects, we must keep track of the
-    //menu visibility to avoid flicker on button release
-    menuOpen = true;
-    menu->exec(QPoint(x, y));
-    if (guard) {
-        menuOpen = false;
-        // on some platforms (e.g. OS/2) QPushButton::focusOutEvent() may be called
-        // before we return from exec() above (for example, as a result of window
-        // deactivation). It will set down to false but since menuOpen won't be
-        // false yet, the button will be redrawn as sunken still. Simple setDown(false)
-        // won't do anything in this case so we need to call update() instead to make
-        // sure the button is redrawn as unsunken.
-        if (down)
-            q->setDown(false);
-        else
-            q->update();
-    }
-}
+
+    return QPoint(x,y);
+}
+
 #endif // QT_NO_MENU
 
@@ -668,4 +674,6 @@
 		d->resetLayoutItemMargins();
 		updateGeometry();
+    } else if (e->type() == QEvent::PolishRequest) {
+        updateGeometry();
     }
     return QAbstractButton::event(e);
