[rkward/frameworks] rkward/windows: Allow preview status messages to be closed (by using KMessageWidget instead of KPassivePopup).

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Sep 15 18:57:41 UTC 2016


Git commit 11143202db5d4cf099834811f77252b83397150c by Thomas Friedrichsmeier.
Committed on 15/09/2016 at 18:56.
Pushed by tfry into branch 'frameworks'.

Allow preview status messages to be closed (by using KMessageWidget instead of KPassivePopup).

Status messaages are still shown as an overlay, in order to avoid resizing of the preview.

M  +26   -18   rkward/windows/rkmdiwindow.cpp
M  +4    -4    rkward/windows/rkmdiwindow.h

http://commits.kde.org/rkward/11143202db5d4cf099834811f77252b83397150c

diff --git a/rkward/windows/rkmdiwindow.cpp b/rkward/windows/rkmdiwindow.cpp
index 94d8e48..fe34128 100644
--- a/rkward/windows/rkmdiwindow.cpp
+++ b/rkward/windows/rkmdiwindow.cpp
@@ -23,12 +23,13 @@
 #include <QEvent>
 #include <QPaintEvent>
 #include <QAction>
+#include <QVBoxLayout>
 
 #include <kparts/partactivateevent.h>
 #include <kxmlguifactory.h>
 #include <kactioncollection.h>
 #include <KLocalizedString>
-#include <kpassivepopup.h>
+#include <kmessagewidget.h>
 
 #include "rkworkplace.h"
 #include "rkworkplaceview.h"
@@ -70,6 +71,7 @@ RKMDIWindow::RKMDIWindow (QWidget *parent, int type, bool tool_window, const cha
 	no_border_when_active = false;
 	standard_client = 0;
 	status_popup = 0;
+	status_popup_container = 0;
 
 	setWindowIcon (RKStandardIcons::iconForWindow (this));
 }
@@ -79,7 +81,6 @@ RKMDIWindow::~RKMDIWindow () {
 
 	if (isToolWindow ()) RKToolWindowList::unregisterToolWindow (this);
 	delete standard_client;
-	delete status_popup;
 }
 
 KActionCollection *RKMDIWindow::standardActionCollection () {
@@ -329,19 +330,32 @@ void RKMDIWindow::setStatusMessage (const QString& message, RCommand *command) {
 	RK_TRACE (MISC);
 
 	if (!status_popup) {
-		status_popup = new KPassivePopup (this);
-		disconnect (status_popup, SIGNAL (clicked()), status_popup, SLOT (hide()));   // no auto-hiding, please, either SIGNAL / SLOT mechanism
-		disconnect (status_popup, static_cast<void (KPassivePopup::*)()>(&KPassivePopup::clicked), status_popup, &QWidget::hide);
+		status_popup_container = new QWidget (this);
+		status_popup_container->resize (size ());
+		QVBoxLayout *layout = new QVBoxLayout (status_popup_container);
+		layout->setContentsMargins (10, 10, 10, 10);
+		status_popup = new KMessageWidget (status_popup_container);
+		status_popup->setCloseButtonVisible (true);
+		status_popup->setMessageType (KMessageWidget::Warning);
+		layout->addWidget (status_popup);
+		layout->addStretch ();
 	}
 
 	if (command) connect (command->notifier (), &RCommandNotifier::commandFinished, this, &RKMDIWindow::clearStatusMessage);
 	if (!message.isEmpty ()) {
-		status_popup->setView (QString (), message);
-		status_popup->show (this->mapToGlobal (QPoint (20, 20)));
-		status_popup->setTimeout (0);
+		status_popup_container->show ();
+		if (status_popup->text () == message) {
+			if (!status_popup->isVisible ()) status_popup->animatedShow ();  // it might have been close by user. And no, simply show() is _not_ good enough. KF5 (5.15.0)
+		}
+		if (status_popup->text () != message) {
+			if (status_popup->isVisible ()) status_popup->hide (); // otherwise, the KMessageWidget does not update geometry (KF5, 5.15.0)
+			status_popup->setText (message);
+			status_popup->animatedShow ();
+		}
 	} else {
+		status_popup_container->hide ();
 		status_popup->hide ();
-		status_popup->setTimeout (10);  // this is a lame way to keep track of whether the popup is empty. See showEvent()
+		status_popup->setText (QString ());  // this is a lame way to keep track of whether the popup is empty. See resizeEvent()
 	}
 }
 
@@ -351,16 +365,10 @@ void RKMDIWindow::clearStatusMessage () {
 	setStatusMessage (QString ());
 }
 
-void RKMDIWindow::hideEvent (QHideEvent* ev) {
-	if (status_popup) {
-		status_popup->hide ();
+void RKMDIWindow::resizeEvent (QResizeEvent*) {
+	if (status_popup_container && !status_popup->text ().isEmpty ()) {
+		status_popup_container->resize (size ());
 	}
-	QWidget::hideEvent (ev);
-}
-
-void RKMDIWindow::showEvent (QShowEvent* ev) {
-	if (status_popup && (status_popup->timeout () == 0)) status_popup->show (this->mapToGlobal (QPoint (20, 20)));
-	QWidget::showEvent (ev);
 }
 
 
diff --git a/rkward/windows/rkmdiwindow.h b/rkward/windows/rkmdiwindow.h
index 049b5bc..8e36e6f 100644
--- a/rkward/windows/rkmdiwindow.h
+++ b/rkward/windows/rkmdiwindow.h
@@ -30,7 +30,7 @@ class QEvent;
 class QPaintEvent;
 class RKWorkplace;
 class RKToolWindowBar;
-class KPassivePopup;
+class KMessageWidget;
 class RCommand;
 
 class RKMDIStandardActionClient : public KXMLGUIClient {
@@ -141,9 +141,9 @@ protected:
 /** @see globalContextProperty() */
 	void setGlobalContextProperty (const QString& property, const QString& value) { global_context_properties.insert (property, value); };
 
-	KPassivePopup* status_popup;
-	void hideEvent (QHideEvent *ev);
-	void showEvent (QShowEvent *ev);
+	KMessageWidget* status_popup;
+	QWidget* status_popup_container;
+	void resizeEvent (QResizeEvent *ev) override;
 
 friend class RKWorkplace;
 /** type of this window */



More information about the rkward-tracker mailing list