Skip to content

Commit db6e924

Browse files
authored
choreL Rewrite code which used QDesktopWidget Class #867
QDesktopWidget is deprecated
2 parents 14e76c4 + 2f96e09 commit db6e924

8 files changed

+13
-45
lines changed

src/applaunchhelper.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "joybuttontypes/joybutton.h"
2525

2626
#include <QDebug>
27-
#include <QDesktopWidget>
2827
#include <QMapIterator>
2928
#include <QThread>
3029

src/event.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <QApplication>
2121
#include <QCursor>
2222
#include <QDebug>
23-
#include <QDesktopWidget>
2423
#include <QFileInfo>
2524
#include <QMessageBox>
2625
#include <QProcess>
@@ -316,7 +315,8 @@ void sendSpringEvent(PadderCommon::springModeInfo *fullSpring, PadderCommon::spr
316315
fullSpring->screen = -1;
317316
}
318317

319-
QRect deskRect = QGuiApplication::screens().at(fullSpring->screen)->geometry();
318+
QRect deskRect = fullSpring->screen == -1 ? QGuiApplication::primaryScreen()->geometry()
319+
: QGuiApplication::screens().at(fullSpring->screen)->geometry();
320320

321321
width = deskRect.width();
322322
height = deskRect.height();

src/gui/mainsettingsdialog.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include <QApplication>
4040
#include <QComboBox>
4141
#include <QDebug>
42-
#include <QDesktopWidget>
4342
#include <QDir>
4443
#include <QFileDialog>
4544
#include <QLabel>

src/main.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ int main(int argc, char *argv[])
548548
PadderCommon::log_system_config(); // workaround for missing windows logs
549549
#endif
550550

551-
PadderCommon::mouseHelperObj.initDeskWid();
552551
QPointer<InputDaemon> joypad_worker = new InputDaemon(joysticks, &settings);
553552
inputEventThread = new QThread();
554553
inputEventThread->setObjectName("inputEventThread");
@@ -570,8 +569,6 @@ int main(int argc, char *argv[])
570569
QObject::connect(&antimicrox, &QApplication::aboutToQuit, &mainAppHelper, &AppLaunchHelper::revertMouseThread);
571570
QObject::connect(&antimicrox, &QApplication::aboutToQuit, joypad_worker.data(), &InputDaemon::quit);
572571
QObject::connect(&antimicrox, &QApplication::aboutToQuit, joypad_worker.data(), &InputDaemon::deleteLater);
573-
QObject::connect(&antimicrox, &QApplication::aboutToQuit, &PadderCommon::mouseHelperObj, &MouseHelper::deleteDeskWid,
574-
Qt::DirectConnection);
575572

576573
QObject::connect(localServer, &LocalAntiMicroServer::showHiddenWindow, mainWindow, &MainWindow::show);
577574
QObject::connect(localServer, &LocalAntiMicroServer::clientdisconnect, mainWindow,

src/mousedialog/springmoderegionpreview.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
#include <QApplication>
2222
#include <QDebug>
23-
#include <QDesktopWidget>
2423
#include <QPaintEvent>
2524
#include <QPainter>
25+
#include <QScreen>
2626

2727
SpringModeRegionPreview::SpringModeRegionPreview(int width, int height, QWidget *parent)
2828
:
@@ -43,8 +43,9 @@ SpringModeRegionPreview::SpringModeRegionPreview(int width, int height, QWidget
4343

4444
if ((tempwidth >= 2) && (tempheight >= 2))
4545
{
46-
int cw = (qApp->desktop()->width() / 2) - (tempwidth / 2);
47-
int ch = (qApp->desktop()->height() / 2) - (tempheight / 2);
46+
// TODO create a simple class representing display fopr calculating cursor locations
47+
int cw = (QGuiApplication::primaryScreen()->virtualGeometry().width() / 2) - (tempwidth / 2);
48+
int ch = (QGuiApplication::primaryScreen()->virtualGeometry().height() / 2) - (tempheight / 2);
4849

4950
setGeometry(cw, ch, tempwidth, tempheight);
5051
show();
@@ -108,8 +109,8 @@ void SpringModeRegionPreview::setSpringWidth(int width)
108109

109110
if ((tempwidth >= 2) && (height >= 2))
110111
{
111-
int cw = (qApp->desktop()->width() / 2) - (tempwidth / 2);
112-
int ch = (qApp->desktop()->height() / 2) - (height / 2);
112+
int cw = (QGuiApplication::primaryScreen()->virtualGeometry().width() / 2) - (tempwidth / 2);
113+
int ch = (QGuiApplication::primaryScreen()->virtualGeometry().height() / 2) - (height / 2);
113114

114115
setGeometry(cw, ch, tempwidth, height);
115116
if (!isVisible())
@@ -133,8 +134,8 @@ void SpringModeRegionPreview::setSpringHeight(int height)
133134

134135
if ((width >= 2) && (tempheight >= 2))
135136
{
136-
int cw = (qApp->desktop()->width() / 2) - (width / 2);
137-
int ch = (qApp->desktop()->height() / 2) - (tempheight / 2);
137+
int cw = (QGuiApplication::primaryScreen()->virtualGeometry().width() / 2) - (width / 2);
138+
int ch = (QGuiApplication::primaryScreen()->virtualGeometry().height() / 2) - (tempheight / 2);
138139

139140
setGeometry(cw, ch, width, tempheight);
140141
if (!isVisible())
@@ -153,8 +154,8 @@ void SpringModeRegionPreview::setSpringSize(int width, int height)
153154
int tempwidth = adjustSpringSizeWidth(width);
154155
int tempheight = adjustSpringSizeHeight(height);
155156

156-
int cw = (qApp->desktop()->width() / 2) - (tempwidth / 2);
157-
int ch = (qApp->desktop()->height() / 2) - (height / 2);
157+
int cw = (QGuiApplication::primaryScreen()->virtualGeometry().width() / 2) - (tempwidth / 2);
158+
int ch = (QGuiApplication::primaryScreen()->virtualGeometry().height() / 2) - (height / 2);
158159

159160
resize(tempwidth, tempheight);
160161
move(cw, ch);

src/mousehelper.cpp

-18
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "mousehelper.h"
2020

2121
#include <QDebug>
22-
#include <QDesktopWidget>
2322

2423
MouseHelper::MouseHelper(QObject *parent)
2524
: QObject(parent)
@@ -35,20 +34,3 @@ MouseHelper::MouseHelper(QObject *parent)
3534
}
3635

3736
void MouseHelper::resetSpringMouseMoving() { springMouseMoving = false; }
38-
39-
void MouseHelper::initDeskWid()
40-
{
41-
if (deskWid == nullptr)
42-
deskWid = new QDesktopWidget;
43-
}
44-
45-
void MouseHelper::deleteDeskWid()
46-
{
47-
if (deskWid != nullptr)
48-
{
49-
delete deskWid;
50-
deskWid = nullptr;
51-
}
52-
}
53-
54-
QDesktopWidget *MouseHelper::getDesktopWidget() const { return deskWid; }

src/mousehelper.h

-10
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,19 @@
2222
#include <QObject>
2323
#include <QTimer>
2424

25-
class QDesktopWidget;
26-
2725
class MouseHelper : public QObject
2826
{
2927
Q_OBJECT
3028

3129
public:
3230
explicit MouseHelper(QObject *parent = nullptr);
33-
QDesktopWidget *getDesktopWidget() const;
3431
bool springMouseMoving;
3532
int previousCursorLocation[2];
3633
int pivotPoint[2];
3734
QTimer mouseTimer;
3835

39-
public slots:
40-
void deleteDeskWid();
41-
void initDeskWid();
42-
4336
private slots:
4437
void resetSpringMouseMoving();
45-
46-
private:
47-
QDesktopWidget *deskWid;
4838
};
4939

5040
#endif // MOUSEHELPER_H

src/springmousemoveinfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef struct _springModeInfo
3333
// Should the cursor not move around the center
3434
// of the screen.
3535
bool relative;
36-
int screen;
36+
int screen; //-1 for default screen
3737
double springDeadX;
3838
double springDeadY;
3939

0 commit comments

Comments
 (0)