[rkward/work/generalized_preview] rkward/plugin: Re-style preview captions, and add close buttons.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Sat Jan 9 20:33:13 UTC 2016


Git commit 87bdc227ff9fdfbb7409e27a2f99f4aab59a9335 by Thomas Friedrichsmeier.
Committed on 09/01/2016 at 20:32.
Pushed by tfry into branch 'work/generalized_preview'.

Re-style preview captions, and add close buttons.

M  +41   -5    rkward/plugin/rkstandardcomponentgui.cpp
M  +2    -0    rkward/plugin/rkstandardcomponentgui.h

http://commits.kde.org/rkward/87bdc227ff9fdfbb7409e27a2f99f4aab59a9335

diff --git a/rkward/plugin/rkstandardcomponentgui.cpp b/rkward/plugin/rkstandardcomponentgui.cpp
index 33ad4b7..6678f40 100644
--- a/rkward/plugin/rkstandardcomponentgui.cpp
+++ b/rkward/plugin/rkstandardcomponentgui.cpp
@@ -22,18 +22,19 @@
 #include <kactioncollection.h>
 #include <kurl.h>
 #include <kvbox.h>
-#include <khbox.h>
 
 #include <qtimer.h>
-#include <qlayout.h>
 #include <qpushbutton.h>
 #include <qlabel.h>
 #include <QCloseEvent>
 #include <QCheckBox>
 #include <QSplitter>
+#include <QHBoxLayout>
+#include <QToolButton>
 
 #include "rkcomponentmap.h"
 #include "../misc/rkcommonfunctions.h"
+#include "../misc/rkstandardicons.h"
 #include "../windows/rkworkplace.h"
 #include "../windows/rkcommandeditorwindow.h"
 #include "../rbackend/rinterface.h"
@@ -166,11 +167,29 @@ void RKStandardComponentGUI::finalize () {
 	RK_TRACE (PLUGIN);
 
 	for (int i = 0; i < previews.size (); ++i) {
-		KVBox *dummy = new KVBox ();
+		// Add preview to splitter. Also add a title bar to each preview.
+		QWidget *dummy = new QWidget ();
+		QVBoxLayout *vl = new QVBoxLayout (dummy);
+		vl->setContentsMargins (0, 0, 0, 0);
+		QFrame *line = new QFrame (dummy);
+		line->setFrameShape (QFrame::HLine);
+		vl->addWidget (line);
+		QHBoxLayout *hl = new QHBoxLayout ();
+		vl->addLayout (hl);
 		QLabel *lab = new QLabel (i18n ("<b>%1</b>", previews[i].label), dummy);
-		lab->setStyleSheet ("background-color: rgb(100, 100, 255);");
+		lab->setAlignment (Qt::AlignCenter);
+		QToolButton *tb = new QToolButton (dummy);
+		tb->setAutoRaise (true);
+		tb->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionDelete));
+		tb->setProperty ("preview_area", QVariant::fromValue (dummy));
+		connect (tb, SIGNAL (clicked()), this, SLOT (previewCloseButtonClicked()));
+		hl->addStretch ();
+		hl->addWidget (lab);
+		hl->addWidget (tb);
+		hl->addStretch ();
+
+		vl->addWidget (previews[i].area);
 		previews[i].area->show ();
-		previews[i].area->setParent (dummy);
 		previews[i].area = dummy;
 		if (!(previews[i].controller->boolValue ())) dummy->hide ();
 		splitter->insertWidget (i+1, previews[i].area);
@@ -254,6 +273,23 @@ void RKStandardComponentGUI::toggleCode () {
 	updateCode ();
 }
 
+void RKStandardComponentGUI::previewCloseButtonClicked () {
+	RK_TRACE (PLUGIN);
+
+	RK_ASSERT (splitter);  // is a dialog
+	QWidget *area = qvariant_cast<QWidget*> (sender ()->property ("preview_area"));
+
+	for (int i = 0; i < previews.size (); ++i) {
+		if (area == previews[i].area) {
+			previews[i].controller->setBoolValue (false);
+			if (i == previews.size () - 1) toggle_code_box->setChecked (false);
+			return;
+		}
+	}
+
+	RK_ASSERT (false);
+}
+
 void RKStandardComponentGUI::previewVisibilityChanged (RKComponentPropertyBase* prop) {
 	RK_TRACE (PLUGIN);
 
diff --git a/rkward/plugin/rkstandardcomponentgui.h b/rkward/plugin/rkstandardcomponentgui.h
index cea337b..9d1ad9f 100644
--- a/rkward/plugin/rkstandardcomponentgui.h
+++ b/rkward/plugin/rkstandardcomponentgui.h
@@ -95,7 +95,9 @@ public slots:
 	void updateCodeNow ();
 	void switchInterface () { component->switchInterface (); };
 	void copyCode ();
+private slots:
 	void previewVisibilityChanged (RKComponentPropertyBase*);
+	void previewCloseButtonClicked ();
 private:
 	RKComponentPropertyCode *code_property;
 	RKComponentPropertyBool code_display_visibility;



More information about the rkward-tracker mailing list