[rkward/work/optionset_experiments] rkward/plugin: Experimental variants of the optionset UI: Implement basic pop-up editor

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Fri Oct 23 19:08:26 UTC 2015


Git commit ed62943c3292ff50d2ffd52fcc3d044f958333f7 by Thomas Friedrichsmeier.
Committed on 12/06/2015 at 13:02.
Pushed by tfry into branch 'work/optionset_experiments'.

Experimental variants of the optionset UI: Implement basic pop-up editor

M  +32   -3    rkward/plugin/rkoptionset.cpp
M  +19   -0    rkward/plugin/rkoptionset.h

http://commits.kde.org/rkward/ed62943c3292ff50d2ffd52fcc3d044f958333f7

diff --git a/rkward/plugin/rkoptionset.cpp b/rkward/plugin/rkoptionset.cpp
index 86fe9bd..6a38df2 100644
--- a/rkward/plugin/rkoptionset.cpp
+++ b/rkward/plugin/rkoptionset.cpp
@@ -47,11 +47,12 @@ RKOptionSet::RKOptionSet (const QDomElement &element, RKComponent *parent_compon
 	min_rows = xml->getIntAttribute (element, "min_rows", 0, DL_INFO);
 	min_rows_if_any = xml->getIntAttribute (element, "min_rows_if_any", 1, DL_INFO);
 	max_rows = xml->getIntAttribute (element, "max_rows", INT_MAX, DL_INFO);
+	exp_mode = (ExperimentalMode) xml->getMultiChoiceAttribute (element, "exp_mode", "regular;detached;tabbed", 1, DL_INFO);
 
 	// build UI framework
 	QVBoxLayout *layout = new QVBoxLayout (this);
-	switcher = new QStackedWidget (this);
-	layout->addWidget (switcher);
+	switcher = new QStackedWidget (exp_mode == Detached ? 0 : this);
+	if (exp_mode != Detached) layout->addWidget (switcher);
 	user_area = new KVBox (this);
 	switcher->addWidget (user_area);
 	updating_notice = new QLabel (i18n ("Updating status, please wait"), this);
@@ -200,7 +201,7 @@ void RKOptionSet::fetchDefaults () {
 RKComponent *RKOptionSet::createDisplay (bool show_index, QWidget *parent) {
 	RK_TRACE (PLUGIN);
 
-	RKComponent* dummy = new RKComponent (this, parent);
+	RKComponent* dummy = new RKComponent (this, exp_mode == Regular ? parent : parentWidget ());
 	QVBoxLayout *layout = new QVBoxLayout (dummy);
 	layout->setContentsMargins (0, 0, 0, 0);
 	KHBox *box = new KHBox (dummy);
@@ -212,6 +213,7 @@ RKComponent *RKOptionSet::createDisplay (bool show_index, QWidget *parent) {
 		display = new QTreeView (box);
 		display_show_index = show_index;
 		model = new RKOptionSetDisplayModel (this);
+		if (exp_mode == Detached) display->setItemDelegate (new RKOptionSetDelegate (this));
 	}
 
 	display_buttons = new KHBox (dummy);
@@ -722,6 +724,8 @@ void RKOptionSet::setContentsForRow (int row) {
 		applyContentsFromExternalColumn (col, row);
 	}
 	contents_container->enablednessProperty ()->setBoolValue (row >= 0);
+
+	if (exp_mode == Detached) switcher->show ();
 }
 
 void RKOptionSet::storeRowSerialization (int row) {
@@ -878,5 +882,30 @@ void RKOptionSetDisplayModel::triggerReset() {
 	}
 }
 
+#include <QApplication>
+RKOptionSetDelegate::RKOptionSetDelegate (RKOptionSet* parent) : QItemDelegate (parent) {
+	set = parent;
+}
+
+void RKOptionSetDelegate::paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
+	if (index.column () == 0) {
+		QStyleOptionButton button;
+		button.rect = option.rect;
+		button.text = i18n ("Edit");
+		button.state = QStyle::State_Enabled;
+		QApplication::style()->drawControl( QStyle::CE_PushButton, &button, painter);
+	} else {
+		QItemDelegate::paint (painter, option, index);
+	}
+}
+
+bool RKOptionSetDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) {
+	if (event->type() == QEvent::MouseButtonRelease) {
+		set->setContentsForRow (index.row ());
+//		return true;
+	}
+	return QItemDelegate::editorEvent (event, model, option, index);
+}
+
 
 #include "rkoptionset.moc"
diff --git a/rkward/plugin/rkoptionset.h b/rkward/plugin/rkoptionset.h
index e9a1a81..fe6be90 100644
--- a/rkward/plugin/rkoptionset.h
+++ b/rkward/plugin/rkoptionset.h
@@ -59,6 +59,7 @@ private slots:
 /** When keys in the key column change, all other columns have to be updated, accordingly. */
 	void handleKeycolumnUpdate ();
 protected:
+friend class RKOptionSetDelegate;
 	void fetchPropertyValuesRecursive (PropertyValueMap *list, bool include_top_level=false, const QString &prefix=QString (), bool include_inactive_elements=false) const;
 friend class RKOptionSetDisplayModel;
 	int rowCount () const { return row_count->intValue (); };
@@ -126,6 +127,12 @@ friend class RKOptionSetDisplayModel;
 	int min_rows_if_any;
 	int max_rows;
 
+	enum ExperimentalMode {
+		Regular,
+		Detached,
+		Tabbed
+	} exp_mode;
+
 	bool updating;
 /** Sets the contents from the values in given row */
 	void setContentsForRow (int row);
@@ -153,4 +160,16 @@ private slots:
 	void doResetNow ();
 };
 
+#include <QItemDelegate>
+
+class RKOptionSetDelegate : public QItemDelegate {
+	Q_OBJECT
+public:
+	RKOptionSetDelegate (RKOptionSet *parent);
+	void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
+	bool editorEvent (QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
+private:
+	RKOptionSet *set;
+};
+
 #endif



More information about the rkward-tracker mailing list