[rkward/work/generalized_preview] rkward: Move status-message-popup functionality from rkwindowcatcher to base class, to allow it for all types of windows.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Tue Jan 5 21:03:45 UTC 2016


Git commit 62bdfe81c7371b64eeef4891a02e9c1afdbe9f5d by Thomas Friedrichsmeier.
Committed on 05/01/2016 at 21:02.
Pushed by tfry into branch 'work/generalized_preview'.

Move status-message-popup functionality from rkwindowcatcher to base class, to allow it for all types of windows.

Modernize it a bit, on the way.

M  +1    -5    rkward/plugin/rkpreviewbox.cpp
M  +28   -0    rkward/windows/rkmdiwindow.cpp
M  +9    -0    rkward/windows/rkmdiwindow.h
M  +0    -39   rkward/windows/rkwindowcatcher.cpp
M  +0    -12   rkward/windows/rkwindowcatcher.h

http://commits.kde.org/rkward/62bdfe81c7371b64eeef4891a02e9c1afdbe9f5d

diff --git a/rkward/plugin/rkpreviewbox.cpp b/rkward/plugin/rkpreviewbox.cpp
index 908fc55..3b4aa16 100644
--- a/rkward/plugin/rkpreviewbox.cpp
+++ b/rkward/plugin/rkpreviewbox.cpp
@@ -188,11 +188,7 @@ void RKPreviewBox::setStatusMessage(const QString& status) {
 
 	RKMDIWindow *window = RKWorkplace::mainWorkplace ()->getNamedWindow (idprop);
 	if (!window) return;
-	if (preview_mode == PlotPreview) {
-		static_cast<RKCaughtX11Window*> (window)->setStatusMessage (status);
-	} else {
-#warning TODO
-	}
+	window->setStatusMessage (status);
 }
 
 void RKPreviewBox::killPreview () {
diff --git a/rkward/windows/rkmdiwindow.cpp b/rkward/windows/rkmdiwindow.cpp
index 0535cf7..05bdf17 100644
--- a/rkward/windows/rkmdiwindow.cpp
+++ b/rkward/windows/rkmdiwindow.cpp
@@ -28,6 +28,7 @@
 #include <kactioncollection.h>
 #include <klocale.h>
 #include <kaction.h>
+#include <kpassivepopup.h>
 
 #include "rkworkplace.h"
 #include "rkworkplaceview.h"
@@ -36,6 +37,7 @@
 #include "../settings/rksettingsmodulegeneral.h"
 #include "../misc/rkstandardicons.h"
 #include "../misc/rkxmlguisyncer.h"
+#include "../rbackend/rcommand.h"
 
 #include "../debug.h"
 
@@ -66,6 +68,7 @@ RKMDIWindow::RKMDIWindow (QWidget *parent, int type, bool tool_window, const cha
 	part = 0;
 	active = false;
 	standard_client = 0;
+	status_popup = 0;
 
 	setWindowIcon (RKStandardIcons::iconForWindow (this));
 }
@@ -75,6 +78,7 @@ RKMDIWindow::~RKMDIWindow () {
 
 	if (isToolWindow ()) RKToolWindowList::unregisterToolWindow (this);
 	delete standard_client;
+	delete status_popup;
 }
 
 KActionCollection *RKMDIWindow::standardActionCollection () {
@@ -285,6 +289,30 @@ void RKMDIWindow::enterEvent (QEvent *event) {
 	QFrame::enterEvent (event);
 }
 
+void RKMDIWindow::setStatusMessage (const QString& message, RCommand *command) {
+	RK_TRACE (MISC);
+
+	if (!status_popup) {
+		status_popup = new KPassivePopup (this);
+		status_popup->setTimeout (0);
+		disconnect (status_popup, SIGNAL (clicked()), status_popup, SLOT (hide()));   // no auto-hiding, please
+	}
+
+	if (command) connect (command->notifier (), SIGNAL (commandFinished (RCommand*)), this, SLOT (clearStatusMessage()));
+	if (!message.isEmpty ()) {
+		status_popup->setView (QString (), message);
+		status_popup->show (this->mapToGlobal (QPoint (20, 20)));
+	} else {
+		status_popup->hide ();
+	}
+}
+
+void RKMDIWindow::clearStatusMessage () {
+	RK_TRACE (APP);
+
+	setStatusMessage (QString ());
+}
+
 void RKMDIWindow::setMetaInfo (const QString& _generic_window_name, const QString& _help_url, RKSettings::SettingsPage _settings_page) {
 	RK_TRACE (APP);
 
diff --git a/rkward/windows/rkmdiwindow.h b/rkward/windows/rkmdiwindow.h
index 54c7154..bdbb1e9 100644
--- a/rkward/windows/rkmdiwindow.h
+++ b/rkward/windows/rkmdiwindow.h
@@ -29,6 +29,8 @@ class QEvent;
 class QPaintEvent;
 class RKWorkplace;
 class RKToolWindowBar;
+class KPassivePopup;
+class RCommand;
 
 class RKMDIStandardActionClient : public KXMLGUIClient {
 public:
@@ -101,6 +103,10 @@ public:
 	virtual void prepareToBeDetached ();
 /** Tool windows will only hide themselves, and ignore the also_delete flag */
 	virtual bool close (bool also_delete);
+/** Set a status message to be shown in a popup inside the window. The message persists until the given R command has finished, or until this function is called with an empty string.
+This should be used, when the information shown is currently out-of-date (e.g. when refreshing a preview / loading a plot from history), _not_ when the window
+is simply busy (e.g. when saving the current plot to history). */
+	void setStatusMessage (const QString& message, RCommand* command=0);
 
 	bool eventFilter (QObject *watched, QEvent *e);
 	bool acceptsEventsFor (QObject *object);
@@ -119,6 +125,7 @@ signals:
 protected slots:
 	void showWindowHelp ();
 	void showWindowSettings ();
+	void clearStatusMessage ();
 protected:
 	void setPart (KParts::Part *p) { part = p; };
 	void setMetaInfo (const QString& generic_window_name, const QString& help_url, RKSettings::SettingsPage settings_page=RKSettings::NoPage);
@@ -148,6 +155,8 @@ friend class RKToolWindowBar;
 	QString generic_window_name;
 	QString help_url;
 	RKSettings::SettingsPage settings_page;
+
+	KPassivePopup* status_popup;
 };
 
 #endif
diff --git a/rkward/windows/rkwindowcatcher.cpp b/rkward/windows/rkwindowcatcher.cpp
index c3fdf64..8f45e19 100644
--- a/rkward/windows/rkwindowcatcher.cpp
+++ b/rkward/windows/rkwindowcatcher.cpp
@@ -128,7 +128,6 @@ void RKWindowCatcher::killDevice (int device_number) {
 #include <knuminput.h>
 #include <kvbox.h>
 #include <kactioncollection.h>
-#include <kpassivepopup.h>
 
 #include "../rkglobals.h"
 #include "../rbackend/rinterface.h"
@@ -210,10 +209,6 @@ void RKCaughtX11Window::commonInit (int device_number) {
 	setFocusPolicy (Qt::ClickFocus);
 	updateHistoryActions (0, 0, QStringList ());
 
-	status_popup = new KPassivePopup (this);
-	status_popup->setTimeout (0);
-	disconnect (status_popup, SIGNAL (clicked()), status_popup, SLOT (hide()));	// no auto-hiding, please
-
 	QVBoxLayout *layout = new QVBoxLayout (this);
 	layout->setContentsMargins (0, 0, 0, 0);
 	box_widget = new KVBox (this);
@@ -274,7 +269,6 @@ RKCaughtX11Window::~RKCaughtX11Window () {
 	if (embedded) RKWardApplication::getApp ()->unregisterNameWatcher (embedded);
 #endif
 	error_dialog->autoDeleteWhenDone ();
-	delete status_popup;
 }
 
 void RKCaughtX11Window::forceClose () {
@@ -590,39 +584,6 @@ void RKCaughtX11Window::updateHistoryActions (int history_length, int position,
 	plot_properties_action->setEnabled (RKSettingsModuleGraphics::plotHistoryEnabled ());
 }
 
-void RKCaughtX11Window::setStatusMessage (const QString& message, RCommand *command) {
-	RK_TRACE (MISC);
-
-	status_change_command = command;
-	if (command) command->addReceiver (this);
-	if (!message.isEmpty ()) {
-		status_popup->setView (QString (), message);
-		status_popup->show (xembed_container->mapToGlobal (QPoint (20, 20)));
-	} else {
-		status_popup->hide ();
-	}
-}
-
-// static
-void RKCaughtX11Window::setStatusMessage(int dev_num, const QString& message, RCommand* command) {
-	RK_TRACE (MISC);
-
-	RKCaughtX11Window *window = getWindow (dev_num);
-	if (!window) return;
-	window->setStatusMessage (message, command);
-}
-
-void RKCaughtX11Window::rCommandDone (RCommand *command) {
-	RK_TRACE (MISC);
-
-	if (command == status_change_command) {
-		setStatusMessage (QString ());
-		status_popup->hide();
-	}
-	RCommandReceiver::rCommandDone (command);
-}
-
-
 ///////////////////////////////// END RKCaughtX11Window ///////////////////////////////
 /**************************************************************************************/
 //////////////////////////////// BEGIN RKCaughtX11WindowPart //////////////////////////
diff --git a/rkward/windows/rkwindowcatcher.h b/rkward/windows/rkwindowcatcher.h
index af2cb92..e244263 100644
--- a/rkward/windows/rkwindowcatcher.h
+++ b/rkward/windows/rkwindowcatcher.h
@@ -94,7 +94,6 @@ class KVBox;
 class RKProgressControl;
 class QX11EmbedContainer;
 class QWinHost;
-class KPassivePopup;
 class RKGraphicsDevice;
 
 /** An R onscreen graphics device window managed by rkward. Currently, this can be X11 devices (on X11), Windows devices (on Windows), and
@@ -119,13 +118,6 @@ public:
 /** returns the window corresponding the to given R device number (or 0 if no such window exists) */
 	static RKCaughtX11Window* getWindow (int device_number) { return device_windows.value (device_number); };
 	void updateHistoryActions (int history_length, int position, const QStringList &labels);
-/** Set a status message to be shown in a popup inside the window. The message persists until the given R command has finished, or until this function is called with an empty string.
-This should be used, when the plot is currently out-of-date (e.g. when loading a plot from history), _not_ when the window
-is simply busy (e.g. when saving the current plot to history). */
-	void setStatusMessage (const QString& message, RCommand* command=0);
-/** static convencience wrapper around setStatusMessage (). Sets the message on the window corresponding to the given device number.
- * NOTE: If no device exists (or isn't known to the system), this function does nothing */
-	static void setStatusMessage (int dev_num, const QString &message, RCommand *command=0);
 public slots:
 	void deviceInteractive (bool interactive, const QString &prompt);
 	
@@ -167,7 +159,6 @@ private:
 	void forceClose ();
 	void commonInit (int device_number);
 	void reEmbed ();
-	void rCommandDone (RCommand *command);
 	friend class RKCaughtX11WindowPart;	// needs access to the actions
 	int device_number;
 	bool killed_in_r;
@@ -202,9 +193,6 @@ private:
 	KSelectAction *plot_list_action;
 	KAction *stop_interaction;
 
-	KPassivePopup* status_popup;
-	RCommand* status_change_command;
-
 	int history_length;
 	int history_position;
 };



More information about the rkward-tracker mailing list