[education/rkward] /: Port away from deprecated QDesktopWidget
Thomas Friedrichsmeier
null at kde.org
Sat Apr 2 12:47:32 BST 2022
Git commit 8d4ef015ad838981f7ed52102f51b8644d0203e5 by Thomas Friedrichsmeier.
Committed on 02/04/2022 at 11:47.
Pushed by tfry into branch 'master'.
Port away from deprecated QDesktopWidget
M +1 -1 ChangeLog
M +1 -3 rkward/dialogs/rkreadlinedialog.cpp
M +17 -2 rkward/misc/rkcommonfunctions.cpp
M +5 -1 rkward/misc/rkcommonfunctions.h
M +1 -3 rkward/plugin/rkstandardcomponentgui.cpp
M +5 -0 rkward/rbackend/rkstructuregetter.cpp
M +6 -6 rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
M +1 -2 rkward/rkward.cpp
M +0 -1 rkward/windows/rkcodecompletion.cpp
M +5 -5 rkward/windows/rkwindowcatcher.cpp
https://invent.kde.org/education/rkward/commit/8d4ef015ad838981f7ed52102f51b8644d0203e5
diff --git a/ChangeLog b/ChangeLog
index 950030fa..bace3374 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,7 +3,7 @@ TODOS for autotests:
- Use options(warn=1), in order to get warnings into the test?
- Fix compilation with the upcoming R 4.2.0
-- Support for switching color themes, including basic support for dark theme
+- Support for switching color schemes, including basic support for dark mode
- Fix crash in dev.capture()
- Fix plot window not showing when created attached
- Space-saving placement of main window status bar, and display more tips in it
diff --git a/rkward/dialogs/rkreadlinedialog.cpp b/rkward/dialogs/rkreadlinedialog.cpp
index 89178766..8d1c628c 100644
--- a/rkward/dialogs/rkreadlinedialog.cpp
+++ b/rkward/dialogs/rkreadlinedialog.cpp
@@ -20,8 +20,6 @@
#include <qlineedit.h>
#include <QTextEdit>
#include <qlabel.h>
-#include <qapplication.h>
-#include <qdesktopwidget.h>
#include <QScrollBar>
#include <QTimer>
#include <QVBoxLayout>
@@ -47,7 +45,7 @@ RKReadLineDialog::RKReadLineDialog (QWidget *parent, const QString &caption, con
layout->addWidget (new QLabel (caption, this));
- int screen_width = qApp->desktop ()->availableGeometry (this).width ();
+ int screen_width = RKCommonFunctions::availableGeometry(this).width();
QString context = command->fullOutput ();
if (!context.isEmpty ()) {
diff --git a/rkward/misc/rkcommonfunctions.cpp b/rkward/misc/rkcommonfunctions.cpp
index ed5fc4ad..214f0149 100644
--- a/rkward/misc/rkcommonfunctions.cpp
+++ b/rkward/misc/rkcommonfunctions.cpp
@@ -2,7 +2,7 @@
rkcommonfunctions - description
-------------------
begin : Mon Oct 17 2005
- copyright : (C) 2005-2020 by Thomas Friedrichsmeier
+ copyright : (C) 2005-2022 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -21,7 +21,12 @@
#include <qregexp.h>
#include <QDir>
#include <QStandardPaths>
-#include <QCoreApplication>
+#include <QApplication>
+#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
+# include <QDesktopWidget>
+#else
+# include <QScreen>
+#endif
#include <QLabel>
#include <KLocalizedString>
@@ -282,4 +287,14 @@ namespace RKCommonFunctions {
return ret;
}
+ QRect availableGeometry(QWidget* for_widget) {
+#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
+ auto screen = for_widget->screen();
+ if (screen) return screen->availableGeometry();
+ return QApplication::primaryScreen()->availableGeometry();
+#else
+ return ::QApplication::desktop()->availableGeometry(for_widget);
+#endif
+ }
+
} // namespace
diff --git a/rkward/misc/rkcommonfunctions.h b/rkward/misc/rkcommonfunctions.h
index f934f20f..05ebcc31 100644
--- a/rkward/misc/rkcommonfunctions.h
+++ b/rkward/misc/rkcommonfunctions.h
@@ -2,7 +2,7 @@
rkcommonfunctions - description
-------------------
begin : Mon Oct 17 2005
- copyright : (C) 2005-2020 by Thomas Friedrichsmeier
+ copyright : (C) 2005-2022 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -18,6 +18,7 @@
#define RKCOMMONFUNCTIONS_H
#include <QChar>
+#include <QRect>
class QStringList;
class QString;
@@ -65,6 +66,9 @@ namespace RKCommonFunctions {
QLabel* wordWrappedLabel (const QString &text);
/** create a QLabel that has wordwarp enabled, *and* clickable links (opened inside RKWard), in a single line of code. */
QLabel* linkedWrappedLabel (const QString &text);
+
+/** Small wrapper around QScreen::availableGeometry(), mostly to ease porting */
+ QRect availableGeometry(QWidget *for_widget);
};
#endif
diff --git a/rkward/plugin/rkstandardcomponentgui.cpp b/rkward/plugin/rkstandardcomponentgui.cpp
index 3e5a8a3c..f217155b 100644
--- a/rkward/plugin/rkstandardcomponentgui.cpp
+++ b/rkward/plugin/rkstandardcomponentgui.cpp
@@ -28,10 +28,8 @@
#include <QSplitter>
#include <QHBoxLayout>
#include <QToolButton>
-#include <QDesktopWidget>
#include <QAction>
#include <QUrl>
-#include <QApplication>
#include "rkcomponentmap.h"
#include "../misc/rkcommonfunctions.h"
@@ -86,7 +84,7 @@ public:
setSizes (sizes);
if (QSplitter::window ()->isVisible ()) {
- QRect boundary = QApplication::desktop ()->availableGeometry (this);
+ QRect boundary = RKCommonFunctions::availableGeometry(this);
int new_width = window->width ();
int new_height = window->height ();
int new_x = window->x ();
diff --git a/rkward/rbackend/rkstructuregetter.cpp b/rkward/rbackend/rkstructuregetter.cpp
index da917a38..51239a45 100644
--- a/rkward/rbackend/rkstructuregetter.cpp
+++ b/rkward/rbackend/rkstructuregetter.cpp
@@ -137,6 +137,11 @@ void RKStructureGetter::getStructureWrapper (GetStructureWorkerArgs *data) {
data->getter->getStructureWorker (data->toplevel, data->name, data->add_type_flags, data->storage, data->nesting_depth);
}
+/** Temporarily resolve a promise, usually without keeping its value (unless keep_evalled_promises is set, which it never is, at the time of this writing).
+ * This is useful for peeking into large objects while building the object tree, without permanently using lots of RAM.
+ *
+ * @note This is is not quite perfect, however. E.g. if we have two promises a and b, where b takes a slice out of a, then
+ * evaluating b will force a, permanently. */
SEXP RKStructureGetter::resolvePromise (SEXP from) {
RK_TRACE (RBACKEND);
diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
index 9b76d8ef..65e20212 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
@@ -25,8 +25,8 @@
#include <KLocalizedString>
// for screen resolution
-#include <QApplication>
-#include <QDesktopWidget>
+#include <QGuiApplication>
+#include <QScreen>
#include "../rkfrontendtransmitter.h"
#include "../../windows/rkworkplace.h"
@@ -260,12 +260,12 @@ void RKGraphicsDeviceFrontendTransmitter::newData () {
RK_DEBUG (GRAPHICS_DEVICE, DL_WARNING, "Graphics operation canceled");
emit stopInteraction();
} else if (opcode == RKDQueryResolution) {
- QDesktopWidget *desktop = QApplication::desktop ();
- streamer.outstream << (qint32) desktop->physicalDpiX () << (qint32) desktop->physicalDpiY ();
- RK_DEBUG (GRAPHICS_DEVICE, DL_INFO, "DPI for device %d: %d by %d", devnum+1, desktop->physicalDpiX (), desktop->physicalDpiY ());
+ auto screen = QGuiApplication::primaryScreen();
+ streamer.outstream << (qint32) screen->logicalDotsPerInchX() << (qint32) screen->logicalDotsPerInchY();
+ RK_DEBUG (GRAPHICS_DEVICE, DL_INFO, "DPI for device %d: %d by %d", devnum+1, screen->logicalDotsPerInchX(), screen->logicalDotsPerInchY());
streamer.writeOutBuffer ();
// Actually, this is only needed once, but where to put it...
- RKGraphicsDeviceFrontendTransmitter::lwdscale = ((double) desktop->physicalDpiX()) / 96; // taken from devX11.c
+ RKGraphicsDeviceFrontendTransmitter::lwdscale = ((double) screen->logicalDotsPerInchX()) / 96; // taken from devX11.c
} else {
if (devnum) RK_DEBUG (GRAPHICS_DEVICE, DL_ERROR, "Received transmission of type %d for unknown device number %d. Skipping.", opcode, devnum+1);
sendDummyReply (opcode);
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 51355fc5..c15aa81a 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -19,7 +19,6 @@
// include files for QT
#include <qtimer.h>
-#include <QDesktopWidget>
#include <QCloseEvent>
#include <QPointer>
#include <QApplication>
@@ -795,7 +794,7 @@ void RKWardMainWindow::readOptions () {
KConfigGroup cg = config->group ("General Options");
QSize size = cg.readEntry ("Geometry", QSize ());
if (size.isEmpty ()) {
- size = QApplication::desktop ()->availableGeometry ().size ();
+ size = RKCommonFunctions::availableGeometry(this).size();
}
resize (size);
diff --git a/rkward/windows/rkcodecompletion.cpp b/rkward/windows/rkcodecompletion.cpp
index 2c00b7d8..1410d66b 100644
--- a/rkward/windows/rkcodecompletion.cpp
+++ b/rkward/windows/rkcodecompletion.cpp
@@ -651,7 +651,6 @@ RKCallHintModel::RKCallHintModel (RKCompletionManager* manager) : RKCompletionMo
function = 0;
}
-#include <QDesktopWidget>
// TODO: There could be more than one function by a certain name, and we could support this!
void RKCallHintModel::setFunction(RObject* _function) {
RK_TRACE (COMMANDEDITOR);
diff --git a/rkward/windows/rkwindowcatcher.cpp b/rkward/windows/rkwindowcatcher.cpp
index cda54025..19e7eb11 100644
--- a/rkward/windows/rkwindowcatcher.cpp
+++ b/rkward/windows/rkwindowcatcher.cpp
@@ -19,15 +19,14 @@
#ifndef DISABLE_RKWINDOWCATCHER
-#include <qlayout.h>
-#include <qapplication.h>
-#include <QDesktopWidget>
+#include <QLayout>
+#include <QApplication>
#include <QPushButton>
#include <QDialogButtonBox>
#include <QDialog>
#include <QWindow>
-#include <kmessagebox.h>
+#include <KMessageBox>
#include <KLocalizedString>
#include <KWindowSystem>
#include <KWindowInfo>
@@ -36,6 +35,7 @@
#include "../dialogs/rkerrordialog.h"
#include "rkworkplace.h"
#include "../misc/rkstandardicons.h"
+#include "../misc/rkcommonfunctions.h"
#include "../debug.h"
RKWindowCatcher *RKWindowCatcher::_instance = 0;
@@ -355,7 +355,7 @@ void RKCaughtX11Window::doEmbed () {
// try to be helpful when the window is too large to fit on screen
QRect dims = window ()->frameGeometry ();
- QRect avail = QApplication::desktop ()->availableGeometry (window ());
+ QRect avail = RKCommonFunctions::availableGeometry(window());
if ((dims.width () > avail.width ()) || (dims.height () > avail.height ())) {
KMessageBox::information (this, i18n ("The current window appears too large to fit on the screen. If this happens regularly, you may want to adjust the default graphics window size in Settings->Configure RKWard->Onscreen Graphics."), i18n ("Large window"), "dont_ask_again_large_x11_window");
}
More information about the rkward-tracker
mailing list