QComboBox: Use platform theme hint to determine popup geometry.

Change-Id: I1f81be1394455715c5dfcd2d426758c4c7cd91fc
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
This commit is contained in:
Friedemann Kleint 2012-02-27 17:09:43 +01:00 committed by Qt by Nokia
parent 52dab54986
commit 838f828a1d
2 changed files with 18 additions and 25 deletions

View File

@ -43,6 +43,7 @@
#ifndef QT_NO_COMBOBOX #ifndef QT_NO_COMBOBOX
#include <qstylepainter.h> #include <qstylepainter.h>
#include <qplatformtheme_qpa.h>
#include <qlineedit.h> #include <qlineedit.h>
#include <qapplication.h> #include <qapplication.h>
#include <qdesktopwidget.h> #include <qdesktopwidget.h>
@ -57,15 +58,13 @@
#include <qtreeview.h> #include <qtreeview.h>
#include <qheaderview.h> #include <qheaderview.h>
#include <qmath.h> #include <qmath.h>
#include <private/qguiapplication_p.h>
#include <private/qapplication_p.h> #include <private/qapplication_p.h>
#include <private/qcombobox_p.h> #include <private/qcombobox_p.h>
#include <private/qabstractitemmodel_p.h> #include <private/qabstractitemmodel_p.h>
#include <private/qabstractscrollarea_p.h> #include <private/qabstractscrollarea_p.h>
#include <private/qsoftkeymanager_p.h> #include <private/qsoftkeymanager_p.h>
#include <qdebug.h> #include <qdebug.h>
#ifdef Q_WS_X11
#include <private/qt_x11_p.h>
#endif
#if defined(Q_WS_MAC) && !defined(QT_NO_EFFECTS) && !defined(QT_NO_STYLE_MAC) #if defined(Q_WS_MAC) && !defined(QT_NO_EFFECTS) && !defined(QT_NO_STYLE_MAC)
#include <private/qcore_mac_p.h> #include <private/qcore_mac_p.h>
#include <QMacStyle> #include <QMacStyle>
@ -219,16 +218,12 @@ void QComboBoxPrivate::_q_modelDestroyed()
//Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't //Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't
QRect QComboBoxPrivate::popupGeometry(int screen) const QRect QComboBoxPrivate::popupGeometry(int screen) const
{ {
#ifdef Q_WS_WIN bool useFullScreenForPopupMenu = false;
return QApplication::desktop()->screenGeometry(screen); if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
#elif defined Q_WS_X11 useFullScreenForPopupMenu = theme->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool();
if (X11->desktopEnvironment == DE_KDE) return useFullScreenForPopupMenu ?
return QApplication::desktop()->screenGeometry(screen); QApplication::desktop()->screenGeometry(screen) :
else QApplication::desktop()->availableGeometry(screen);
return QApplication::desktop()->availableGeometry(screen);
#else
return QApplication::desktop()->availableGeometry(screen);
#endif
} }
bool QComboBoxPrivate::updateHoverControl(const QPoint &pos) bool QComboBoxPrivate::updateHoverControl(const QPoint &pos)

View File

@ -43,6 +43,8 @@
#include "qcombobox.h" #include "qcombobox.h"
#include <private/qcombobox_p.h> #include <private/qcombobox_p.h>
#include <private/qguiapplication_p.h>
#include <qplatformtheme_qpa.h>
#include <qfontcombobox.h> #include <qfontcombobox.h>
#include <qdesktopwidget.h> #include <qdesktopwidget.h>
@ -1915,19 +1917,15 @@ void tst_QComboBox::itemListPosition()
QWidget topLevel; QWidget topLevel;
QFontComboBox combo(&topLevel); QFontComboBox combo(&topLevel);
//the code to get the avaialbe screen space is copied from QComboBox code //the code to get the available screen space is copied from QComboBox code
const int scrNumber = QApplication::desktop()->screenNumber(&combo); const int scrNumber = QApplication::desktop()->screenNumber(&combo);
QRect screen;
#ifdef Q_WS_WIN bool useFullScreenForPopupMenu = false;
screen = QApplication::desktop()->screenGeometry(scrNumber); if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
#elif defined Q_WS_X11 useFullScreenForPopupMenu = theme->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool();
if (X11->desktopEnvironment == DE_KDE) const QRect screen = useFullScreenForPopupMenu ?
screen = QApplication::desktop()->screenGeometry(scrNumber); QApplication::desktop()->screenGeometry(scrNumber) :
else QApplication::desktop()->availableGeometry(scrNumber);
screen = QApplication::desktop()->availableGeometry(scrNumber);
#else
screen = QApplication::desktop()->availableGeometry(scrNumber);
#endif
combo.move(screen.width()-combo.sizeHint().width(), 0); //puts the combo to the top-right corner combo.move(screen.width()-combo.sizeHint().width(), 0); //puts the combo to the top-right corner