Conditionally remove use of QApplication::desktop in ComboBox.cpp (#7179)
Prepare the application for Qt6 by conditionally removing the use of `QApplication::desktop` in `ComboBox.cpp`. The method was already deprecated in Qt5 and is removed in Qt6. Instead the method `QWidget::screen` is used now if the Qt version is equal to or newer than 5.14 (because the method was only introduced with that version). Fall back to `QApplication::desktop` if an older version is detected during the build. This is for example the case for the CI builds which are based on Ubuntu 18.04. Generalize the check if the menu can be shown in the screen. The code now also does handles the case where the menu would go out of screen along the X axis. Also remove the unused include `embed.h`.
This commit is contained in:
committed by
GitHub
parent
a98c700911
commit
b622fa2206
@@ -26,16 +26,20 @@
|
||||
|
||||
#include "ComboBox.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionFrame>
|
||||
#include <QScreen>
|
||||
|
||||
#include "CaptionMenu.h"
|
||||
#include "embed.h"
|
||||
#include "gui_templates.h"
|
||||
|
||||
#define QT_SUPPORTS_WIDGET_SCREEN (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
||||
#if !QT_SUPPORTS_WIDGET_SCREEN
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#endif
|
||||
|
||||
namespace lmms::gui
|
||||
{
|
||||
const int CB_ARROW_BTN_WIDTH = 18;
|
||||
@@ -116,15 +120,23 @@ void ComboBox::mousePressEvent( QMouseEvent* event )
|
||||
a->setData( i );
|
||||
}
|
||||
|
||||
QPoint gpos = mapToGlobal( QPoint( 0, height() ) );
|
||||
if( gpos.y() + m_menu.sizeHint().height() < qApp->desktop()->height() )
|
||||
QPoint gpos = mapToGlobal(QPoint(0, height()));
|
||||
|
||||
#if (QT_SUPPORTS_WIDGET_SCREEN)
|
||||
bool const menuCanBeFullyShown = screen()->geometry().contains(QRect(gpos, m_menu.sizeHint()));
|
||||
#else
|
||||
bool const menuCanBeFullyShown = gpos.y() + m_menu.sizeHint().height() < qApp->desktop()->height();
|
||||
#endif
|
||||
|
||||
if (menuCanBeFullyShown)
|
||||
{
|
||||
m_menu.exec( gpos );
|
||||
m_menu.exec(gpos);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_menu.exec( mapToGlobal( QPoint( width(), 0 ) ) );
|
||||
m_menu.exec(mapToGlobal(QPoint(width(), 0)));
|
||||
}
|
||||
|
||||
m_pressed = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user