Skip to content

Commit 50de7f8

Browse files
committed
remove Qt5 compatibility for QWidget::screen()
1 parent 8c11267 commit 50de7f8

File tree

7 files changed

+11
-41
lines changed

7 files changed

+11
-41
lines changed

src/errordialoghandler.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#include <QGuiApplication>
55
#include <QScopedPointer>
66
#include <QScreen>
7+
#include <QStyle>
78
#include <QThread>
89
#include <QtDebug>
910

1011
#include "moc_errordialoghandler.cpp"
1112
#include "util/assert.h"
1213
#include "util/compatibility/qmutex.h"
1314
#include "util/versionstore.h"
14-
#include "util/widgethelper.h"
1515

1616
namespace {
1717
// Gross estimated dimensions for the size of the error dialog,
@@ -164,8 +164,7 @@ void ErrorDialogHandler::errorDialog(ErrorDialogProperties* pProps) {
164164
if (props->m_detailsUseMonospaceFont) {
165165
// There is no event to respond on the Show Details button of QMessagBox.
166166
// Therefore we must consider the expanded size for positioning the dialog initially.
167-
auto* pScreen =
168-
mixxx::widgethelper::getScreen(*pMsgBox);
167+
auto* pScreen = pMsgBox->screen();
169168
if (!pScreen) {
170169
// Fallback to obtain the primary screen when mixxx::widgethelper::getScreen can't
171170
// determine the screen. This happens always with Qt <5.14

src/library/dlgcoverartfullsize.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "mixer/basetrackplayer.h"
1111
#include "moc_dlgcoverartfullsize.cpp"
1212
#include "track/track.h"
13-
#include "util/widgethelper.h"
1413
#include "widget/wcoverartmenu.h"
1514

1615
DlgCoverArtFullSize::DlgCoverArtFullSize(
@@ -191,7 +190,7 @@ void DlgCoverArtFullSize::adjustImageAndDialogSize() {
191190
centerOverWidget = this;
192191
}
193192

194-
const QScreen* const pScreen = mixxx::widgethelper::getScreen(*centerOverWidget);
193+
const auto* const pScreen = centerOverWidget->screen();
195194
QRect screenGeometry;
196195
VERIFY_OR_DEBUG_ASSERT(pScreen) {
197196
qWarning() << "Assuming screen size of 800x600px.";

src/preferences/dialog/dlgpreferences.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "preferences/dialog/dlgprefsound.h"
1717
#include "util/color/color.h"
1818
#include "util/desktophelper.h"
19-
#include "util/widgethelper.h"
2019

2120
#ifdef __VINYLCONTROL__
2221
#include "preferences/dialog/dlgprefvinyl.h"
@@ -352,7 +351,7 @@ void DlgPreferences::onShow() {
352351
int newWidth = m_geometry[2].toInt();
353352
int newHeight = m_geometry[3].toInt();
354353

355-
const QScreen* const pScreen = mixxx::widgethelper::getScreen(*this);
354+
const auto* const pScreen = screen();
356355
QRect screenAvailableGeometry;
357356
VERIFY_OR_DEBUG_ASSERT(pScreen) {
358357
qWarning() << "Assuming screen size of 800x600px.";
@@ -554,7 +553,7 @@ void DlgPreferences::resizeEvent(QResizeEvent* e) {
554553

555554
QRect DlgPreferences::getDefaultGeometry() {
556555
adjustSize();
557-
const auto* const pScreen = mixxx::widgethelper::getScreen(*this);
556+
const auto* const pScreen = screen();
558557
VERIFY_OR_DEBUG_ASSERT(pScreen) {
559558
return QRect();
560559
}

src/preferences/dialog/dlgprefinterface.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "util/cmdlineargs.h"
2020
#include "util/screensaver.h"
2121
#include "util/screensavermanager.h"
22-
#include "util/widgethelper.h"
2322

2423
using mixxx::skin::SkinManifest;
2524
using mixxx::skin::SkinPointer;
@@ -236,8 +235,7 @@ DlgPrefInterface::DlgPrefInterface(
236235
}
237236

238237
QScreen* DlgPrefInterface::getScreen() const {
239-
auto* pScreen =
240-
mixxx::widgethelper::getScreen(*this);
238+
auto* pScreen = screen();
241239
if (!pScreen) {
242240
// Obtain the primary screen. This is necessary if no window is
243241
// available before the widget is displayed.

src/util/widgethelper.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ QPoint mapPopupToScreen(
1313
const QWidget& widget,
1414
const QPoint& popupUpperLeft,
1515
const QSize& popupSize) {
16-
const auto* const pScreen = getScreen(widget);
16+
const auto* const pScreen = widget.screen();
1717
VERIFY_OR_DEBUG_ASSERT(pScreen) {
1818
// This should never fail
1919
return popupUpperLeft;
@@ -37,8 +37,7 @@ QPoint mapPopupToScreen(
3737
return QPoint(adjustedX, adjustedY);
3838
}
3939

40-
QWindow* getWindow(
41-
const QWidget& widget) {
40+
QWindow* getWindow(const QWidget& widget) {
4241
if (auto* window = widget.windowHandle()) {
4342
return window;
4443
}
@@ -52,7 +51,7 @@ void growListWidget(QListWidget& listWidget, const QWidget& parent) {
5251
// Try to display all files and the complete file locations to avoid
5352
// horizontal scrolling.
5453
// Get the screen dimensions
55-
QScreen* const pScreen = getScreen(parent);
54+
const auto* const pScreen = parent.screen();
5655
QSize screenSpace;
5756
VERIFY_OR_DEBUG_ASSERT(pScreen) {
5857
qWarning() << "Screen not detected. Assuming screen size of 800x600px.";
@@ -67,7 +66,7 @@ void growListWidget(QListWidget& listWidget, const QWidget& parent) {
6766
int minW = listWidget.sizeHintForColumn(0) + margin;
6867
int minH = listWidget.sizeHintForRow(0) * listWidget.count() + margin;
6968
// The file list should fit into the window, but clamp to 75% of screen size
70-
// so (hoepfully) the entire containing dialog is visible even if there are
69+
// so (hopefully) the entire containing dialog is visible even if there are
7170
// toolbars at the screen edges
7271
int newW = std::min(minW, static_cast<int>(screenSpace.width() * 0.75));
7372
int newH = std::min(minH, static_cast<int>(screenSpace.height() * 0.75));

src/util/widgethelper.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,6 @@ QPoint mapPopupToScreen(
2828
QWindow* getWindow(
2929
const QWidget& widget);
3030

31-
/// Obtains the corresponding screen for the given widget.
32-
///
33-
/// Might return nullptr if no screen could be determined.
34-
inline QScreen* getScreen(
35-
const QWidget& widget) {
36-
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
37-
return widget.screen();
38-
#else
39-
const auto* pWindow = getWindow(widget);
40-
if (!pWindow && widget.parent()) {
41-
// The window might still be hidden and invisible. Then we
42-
// try to obtain the screen from its parent recursively.
43-
return getScreen(*qobject_cast<QWidget*>(widget.parent()));
44-
}
45-
if (!pWindow) {
46-
// This might happen if the widget is not yet displayed
47-
return nullptr;
48-
}
49-
return pWindow->screen();
50-
#endif
51-
}
52-
5331
/// QSize for stretching a list widget attempting to show entire column
5432
void growListWidget(QListWidget& listWidget, const QWidget& parent);
5533

src/widget/wsearchrelatedtracksmenu.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "util/math.h"
1515
#include "util/parented_ptr.h"
1616
#include "util/qt.h"
17-
#include "util/widgethelper.h"
1817

1918
namespace {
2019

@@ -110,8 +109,7 @@ QString WSearchRelatedTracksMenu::elideActionText(
110109
if (elidableTextSuffix.isEmpty()) {
111110
return actionTextPrefix;
112111
}
113-
const auto* const pScreen =
114-
mixxx::widgethelper::getScreen(*this);
112+
const auto* const pScreen = screen();
115113
VERIFY_OR_DEBUG_ASSERT(pScreen) {
116114
// This should never fail
117115
return actionTextPrefix;

0 commit comments

Comments
 (0)