[education/rkward] rkward/windows: Add activateWidget() and widgets() implementations.

Thomas Friedrichsmeier null at kde.org
Thu Apr 11 20:57:07 BST 2024


Git commit 5bb5075dd5f7a66463395ea750c8d42df4f46c8b by Thomas Friedrichsmeier.
Committed on 11/04/2024 at 19:56.
Pushed by tfry into branch 'master'.

Add activateWidget() and widgets() implementations.

(See https://invent.kde.org/utilities/kate/-/merge_requests/1225)

M  +38   -0    rkward/windows/katepluginintegration.cpp
M  +3    -0    rkward/windows/katepluginintegration.h

https://invent.kde.org/education/rkward/-/commit/5bb5075dd5f7a66463395ea750c8d42df4f46c8b

diff --git a/rkward/windows/katepluginintegration.cpp b/rkward/windows/katepluginintegration.cpp
index 89d64a336..9534a0880 100644
--- a/rkward/windows/katepluginintegration.cpp
+++ b/rkward/windows/katepluginintegration.cpp
@@ -75,8 +75,13 @@ public:
 		}
 		RKMDIWindow::childEvent(ev);
 	}
+	QWidget* internalWidget() const {
+		return internal_widget;
+	}
 Q_SIGNALS:
 	void toolVisibleChanged(bool);
+private:
+	QWidget* internal_widget;
 };
 
 ///  END  Helper class for tool windows
@@ -428,6 +433,39 @@ bool KatePluginIntegrationWindow::addWidget(QWidget *widget) {
 	return true;
 }
 
+void KatePluginIntegrationWindow::activateWidget(QWidget *widget) {
+	RK_TRACE(APP);
+
+	QWidget *w = widget;
+	while (w) {
+		RKMDIWindow *rkw = qobject_cast<RKMDIWindow*>(w);
+		if (rkw) {
+			rkw->activate();
+			return;
+		}
+		w = w->parentWidget();
+	}
+	RK_DEBUG(APP, DL_WARNING, "no such widget found in activateWidget %p: %s", widget, widget ? qPrintable(widget->windowTitle()) : "[null]");
+}
+
+QWidgetList KatePluginIntegrationWindow::widgets() {
+	RK_TRACE(APP);
+
+	QWidgetList ret;
+	auto list = RKWorkplace::mainWorkplace()->getObjectList();
+	for (const auto win : list) {
+		if (win->isType(RKMDIWindow::KatePluginWindow) && win->isType(RKMDIWindow::DocumentWindow)) {
+			auto w = qobject_cast<KatePluginWindow*>(win)->internalWidget();
+			if (w) {
+				ret.append(w);
+			} else {
+				RK_DEBUG(APP, DL_WARNING, "found empty kate plugin mdi wrapper");
+			}
+		}
+	}
+	return ret;
+}
+
 #include "../rbackend/rcommand.h"
 #include "rkcommandlog.h"
 bool KatePluginIntegrationWindow::showMessage(const QVariantMap &map) {
diff --git a/rkward/windows/katepluginintegration.h b/rkward/windows/katepluginintegration.h
index d5a3630aa..81873854d 100644
--- a/rkward/windows/katepluginintegration.h
+++ b/rkward/windows/katepluginintegration.h
@@ -14,6 +14,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include <KXMLGUIClient>
 
 #include <QMap>
+#include <QWidget>
 
 class KatePluginIntegrationWindow;
 class RKMDIWindow;
@@ -108,6 +109,8 @@ private Q_SLOTS:
 	QWidget *toolviewForName(const QString &toolviewName);
 	bool showMessage(const QVariantMap &map);
 	bool addWidget(QWidget *widget);
+	void activateWidget(QWidget *widget);
+	QWidgetList widgets();
 	void insertWidgetInStatusbar(QWidget *widget);
 private:
 friend class KatePluginIntegrationApp;


More information about the rkward-tracker mailing list