[rkward-cvs] rkward/rkward/plugin rkstandardcomponent.cpp,1.21,1.22 rkstandardcomponent.h,1.12,1.13 rkstandardcomponentgui.cpp,1.3,1.4 rkstandardcomponentgui.h,1.1,1.2

Thomas Friedrichsmeier tfry at users.sourceforge.net
Mon Mar 20 20:31:00 UTC 2006


Update of /cvsroot/rkward/rkward/rkward/plugin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5769/rkward/plugin

Modified Files:
	rkstandardcomponent.cpp rkstandardcomponent.h 
	rkstandardcomponentgui.cpp rkstandardcomponentgui.h 
Log Message:
Add support for "enslaved" RKComponents: Those are technically embedded, but have a separate GUI that is shown via a push button

Index: rkstandardcomponentgui.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkstandardcomponentgui.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** rkstandardcomponentgui.cpp	20 Mar 2006 01:29:01 -0000	1.3
--- rkstandardcomponentgui.cpp	20 Mar 2006 20:30:58 -0000	1.4
***************
*** 36,40 ****
  /////////////////////////////////////// RKStandardComponentGUI ////////////////////////////////////////////////
  
! RKStandardComponentGUI::RKStandardComponentGUI (RKStandardComponent *component, RKComponentPropertyCode *code_property) {
  	RK_TRACE (PLUGIN);
  
--- 36,40 ----
  /////////////////////////////////////// RKStandardComponentGUI ////////////////////////////////////////////////
  
! RKStandardComponentGUI::RKStandardComponentGUI (RKStandardComponent *component, RKComponentPropertyCode *code_property, bool enslaved) {
  	RK_TRACE (PLUGIN);
  
***************
*** 43,46 ****
--- 43,48 ----
  	connect (code_property, SIGNAL (valueChanged (RKComponentPropertyBase *)), this, SLOT (codeChanged (RKComponentPropertyBase *)));
  
+ 	RKStandardComponentGUI::enslaved = enslaved;
+ 
  	// code update timer
  	code_update_timer = new QTimer (this);
***************
*** 76,94 ****
  	// buttons
  	vbox = new QVBoxLayout (hbox, RKGlobals::spacingHint ());
! 	ok_button = new QPushButton ("Submit", upper_widget);
  	connect (ok_button, SIGNAL (clicked ()), this, SLOT (ok ()));
  	vbox->addWidget (ok_button);
  	
! 	cancel_button = new QPushButton ("Close", upper_widget);
  	connect (cancel_button, SIGNAL (clicked ()), this, SLOT (cancel ()));
  	vbox->addWidget (cancel_button);
  	vbox->addStretch (1);
  	
! 	help_button = new QPushButton ("Help", upper_widget);
  	connect (help_button, SIGNAL (clicked ()), this, SLOT (help ()));
  	vbox->addWidget (help_button);
  	
! 	if (switchable) {
! 		switch_button = new QPushButton ("Use Wizard", upper_widget);
  		connect (switch_button, SIGNAL (clicked ()), this, SLOT (switchInterface ()));
  		vbox->addWidget (switch_button);
--- 78,97 ----
  	// buttons
  	vbox = new QVBoxLayout (hbox, RKGlobals::spacingHint ());
! 	ok_button = new QPushButton (i18n ("Submit"), upper_widget);
  	connect (ok_button, SIGNAL (clicked ()), this, SLOT (ok ()));
  	vbox->addWidget (ok_button);
+ 	if (enslaved) ok_button->hide ();
  	
! 	cancel_button = new QPushButton (i18n ("Close"), upper_widget);
  	connect (cancel_button, SIGNAL (clicked ()), this, SLOT (cancel ()));
  	vbox->addWidget (cancel_button);
  	vbox->addStretch (1);
  	
! 	help_button = new QPushButton (i18n ("Help"), upper_widget);
  	connect (help_button, SIGNAL (clicked ()), this, SLOT (help ()));
  	vbox->addWidget (help_button);
  	
! 	if (switchable && (!enslaved)) {
! 		switch_button = new QPushButton (i18n ("Use Wizard"), upper_widget);
  		connect (switch_button, SIGNAL (clicked ()), this, SLOT (switchInterface ()));
  		vbox->addWidget (switch_button);
***************
*** 96,107 ****
  	vbox->addStretch (2);
  	
! 	toggle_code_button = new QPushButton ("Code", upper_widget);
  	toggle_code_button->setToggleButton (true);
  	toggle_code_button->setOn (true);
  	connect (toggle_code_button, SIGNAL (clicked ()), this, SLOT (toggleCode ()));
  	vbox->addWidget (toggle_code_button);
  	
  	// code display
  	code_display = new RKCommandEditor (splitter, true);
  }
  
--- 99,112 ----
  	vbox->addStretch (2);
  	
! 	toggle_code_button = new QPushButton (i18n ("Code"), upper_widget);
  	toggle_code_button->setToggleButton (true);
  	toggle_code_button->setOn (true);
  	connect (toggle_code_button, SIGNAL (clicked ()), this, SLOT (toggleCode ()));
  	vbox->addWidget (toggle_code_button);
+ 	if (enslaved) toggle_code_button->hide ();
  	
  	// code display
  	code_display = new RKCommandEditor (splitter, true);
+ 	if (enslaved) code_display->hide ();
  }
  
***************
*** 123,127 ****
  
  	hide ();
! 	component->deleteLater ();
  }
  
--- 128,134 ----
  
  	hide ();
! 	if (!enslaved) {
! 		component->deleteLater ();
! 	}
  }
  
***************
*** 176,180 ****
  ///////////////////////////////// RKStandardComponentWizard /////////////////////////////////
  
! RKStandardComponentWizard::RKStandardComponentWizard (RKStandardComponent *component, RKComponentPropertyCode *code_property) : RKStandardComponentGUI (component, code_property) {
  	RK_TRACE (PLUGIN);
  
--- 183,187 ----
  ///////////////////////////////// RKStandardComponentWizard /////////////////////////////////
  
! RKStandardComponentWizard::RKStandardComponentWizard (RKStandardComponent *component, RKComponentPropertyCode *code_property, bool enslaved) : RKStandardComponentGUI (component, code_property, enslaved) {
  	RK_TRACE (PLUGIN);
  
***************
*** 211,216 ****
  
  	// buttons
! 	cancel_button = new QPushButton ("Cancel", this);
  	main_grid->addWidget (cancel_button, 2, 0, Qt::AlignLeft);
  	help_button = new QPushButton ("Help", this);
  	main_grid->addWidget (help_button, 2, 1, Qt::AlignLeft);
--- 218,224 ----
  
  	// buttons
! 	cancel_button = new QPushButton (i18n ("Cancel"), this);
  	main_grid->addWidget (cancel_button, 2, 0, Qt::AlignLeft);
+ 	if (enslaved) cancel_button->hide ();
  	help_button = new QPushButton ("Help", this);
  	main_grid->addWidget (help_button, 2, 1, Qt::AlignLeft);
***************
*** 229,240 ****
  	RK_TRACE (PLUGIN);
  
! 	// build the last page
! 	RKComponent *last_page = stack->addPage (component);
! 	QVBoxLayout *vbox = new QVBoxLayout (last_page, RKGlobals::spacingHint ());
! 	QLabel *label = new QLabel (i18n ("Below you can see the command(s) corresponding to the settings you made. Click 'Submit' to run the command(s)."), last_page);
! 	label->setAlignment (Qt::AlignAuto | Qt::AlignVCenter | Qt::ExpandTabs | Qt::WordBreak);
! 	code_display = new RKCommandEditor (last_page, true);
! 	vbox->addWidget (label);
! 	vbox->addWidget (code_display);
  
  	stack->goToFirstPage ();
--- 237,250 ----
  	RK_TRACE (PLUGIN);
  
! 	if (!enslaved) {
! 		// build the last page
! 		RKComponent *last_page = stack->addPage (component);
! 		QVBoxLayout *vbox = new QVBoxLayout (last_page, RKGlobals::spacingHint ());
! 		QLabel *label = new QLabel (i18n ("Below you can see the command(s) corresponding to the settings you made. Click 'Submit' to run the command(s)."), last_page);
! 		label->setAlignment (Qt::AlignAuto | Qt::AlignVCenter | Qt::ExpandTabs | Qt::WordBreak);
! 		code_display = new RKCommandEditor (last_page, true);
! 		vbox->addWidget (label);
! 		vbox->addWidget (code_display);
! 	}
  
  	stack->goToFirstPage ();
***************
*** 271,278 ****
  	RK_TRACE (PLUGIN);
  
! 	if (stack->havePage (true)) {		// not on last page
  		next_button->setText (i18n ("Next >"));
  		next_button->setEnabled (stack->currentPageSatisfied ());
! 		if (stack->havePage (false) || (!is_switchable)) {		// not on first page
  			prev_button->setText (i18n ("< Back"));
  			prev_button->setEnabled (stack->havePage (false));
--- 281,288 ----
  	RK_TRACE (PLUGIN);
  
! 	if (stack->havePage (true) || enslaved) {		// not on last page
  		next_button->setText (i18n ("Next >"));
  		next_button->setEnabled (stack->currentPageSatisfied ());
! 		if (stack->havePage (false) || (!is_switchable) || enslaved) {		// not on first page
  			prev_button->setText (i18n ("< Back"));
  			prev_button->setEnabled (stack->havePage (false));

Index: rkstandardcomponent.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkstandardcomponent.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** rkstandardcomponent.h	20 Mar 2006 19:33:55 -0000	1.12
--- rkstandardcomponent.h	20 Mar 2006 20:30:58 -0000	1.13
***************
*** 59,62 ****
--- 59,64 ----
  /** RTTI */
  	int type () { return ComponentStandard; };
+ /** set the GUI caption (if this is a top-level gui) */
+ 	void setCaption (const QString &caption);
  public slots:
  /** this gets called by the script-backend, when it's done. Might enable the
***************
*** 71,74 ****
--- 73,78 ----
  /** reimplemented from QWidget to hide the gui if applicable */
  	void hide ();
+ /** for enslaved components */
+ 	void showGUI ();
  private:
  /** The property holding the generated code. Note that this member is tightly controlled by the ScriptBackend */
***************
*** 81,86 ****
  /** Avoid updating code-display, etc. until the component is fully created */
  	bool created;
! 	bool createTopLevel (const QDomElement &doc_element, int force_mode=0);
! 	void buildAndInitialize (const QDomElement &doc_element, const QDomElement &gui_element, QWidget *parent_widget, bool build_wizard);
  /** used during switchInterfaces () to discard child components, and delete gui if applicable */
  	void discard ();
--- 85,90 ----
  /** Avoid updating code-display, etc. until the component is fully created */
  	bool created;
! 	bool createTopLevel (const QDomElement &doc_element, int force_mode=0, bool enslaved=false);
! 	void buildAndInitialize (const QDomElement &doc_element, const QDomElement &gui_element, QWidget *parent_widget, bool build_wizard, bool enslaved=false);
  /** used during switchInterfaces () to discard child components, and delete gui if applicable */
  	void discard ();

Index: rkstandardcomponent.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkstandardcomponent.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** rkstandardcomponent.cpp	20 Mar 2006 19:33:55 -0000	1.21
--- rkstandardcomponent.cpp	20 Mar 2006 20:30:58 -0000	1.22
***************
*** 98,101 ****
--- 98,107 ----
  			return;		// should never happen
  		}
+ 	} else if (!parent_widget) {				// we have a parent component, but should still have a separate GUI
+ 		if (!createTopLevel (doc_element, 0, true)) {
+ 			RK_ASSERT (false);
+ 			deleteLater ();
+ 			return;		// should never happen
+ 		}		
  	} else {
  		bool build_wizard = false;
***************
*** 134,138 ****
  }
  
! bool RKStandardComponent::createTopLevel (const QDomElement &doc_element, int force_mode) {
  	RK_TRACE (PLUGIN);
  
--- 140,162 ----
  }
  
! void RKStandardComponent::showGUI () {
! 	RK_TRACE (PLUGIN);
! 
! 	if (!gui) {
! 		RK_ASSERT (false);
! 		return;
! 	}
! 	gui->show ();
! 	gui->raise ();
! }
! 
! void RKStandardComponent::setCaption (const QString &caption) {
! 	RK_TRACE (PLUGIN);
! 
! 	if (!gui) return;
! 	gui->setCaption (caption);
! }
! 
! bool RKStandardComponent::createTopLevel (const QDomElement &doc_element, int force_mode, bool enslaved) {
  	RK_TRACE (PLUGIN);
  
***************
*** 171,183 ****
  
  	if (build_wizard) {
! 		gui = new RKStandardComponentWizard (this, code);
  		static_cast<RKStandardComponentWizard *> (gui)->createWizard (!dialog_element.isNull ());
  		wizard = static_cast<RKStandardComponentWizard *> (gui)->getStack ();
! 		buildAndInitialize (doc_element, wizard_element, gui->mainWidget (), true);
  		static_cast<RKStandardComponentWizard *> (gui)->addLastPage ();
  	} else {
! 		gui = new RKStandardComponentGUI (this, code);
  		gui->createDialog (!wizard_element.isNull ());
! 		buildAndInitialize (doc_element, dialog_element, gui->mainWidget (), false);
  	}
  
--- 195,207 ----
  
  	if (build_wizard) {
! 		gui = new RKStandardComponentWizard (this, code, enslaved);
  		static_cast<RKStandardComponentWizard *> (gui)->createWizard (!dialog_element.isNull ());
  		wizard = static_cast<RKStandardComponentWizard *> (gui)->getStack ();
! 		buildAndInitialize (doc_element, wizard_element, gui->mainWidget (), true, enslaved);
  		static_cast<RKStandardComponentWizard *> (gui)->addLastPage ();
  	} else {
! 		gui = new RKStandardComponentGUI (this, code, enslaved);
  		gui->createDialog (!wizard_element.isNull ());
! 		buildAndInitialize (doc_element, dialog_element, gui->mainWidget (), false, enslaved);
  	}
  
***************
*** 223,227 ****
  }
  
! void RKStandardComponent::buildAndInitialize (const QDomElement &doc_element, const QDomElement &gui_element, QWidget *parent_widget, bool build_wizard) {
  	RK_TRACE (PLUGIN);
  
--- 247,251 ----
  }
  
! void RKStandardComponent::buildAndInitialize (const QDomElement &doc_element, const QDomElement &gui_element, QWidget *parent_widget, bool build_wizard, bool enslaved) {
  	RK_TRACE (PLUGIN);
  
***************
*** 234,237 ****
--- 258,262 ----
  	builder->buildElement (gui_element, parent_widget, build_wizard);
  	builder->parseLogic (xml->getChildElement (doc_element, "logic", DL_INFO));
+ 	setCaption (xml->getStringAttribute (gui_element, "label", QString::null, DL_WARNING));
  
  	// initialize
***************
*** 241,245 ****
  	delete builder;
  	created = true;
! 	if (gui) gui->show ();
  	changed ();
  }
--- 266,272 ----
  	delete builder;
  	created = true;
! 	if (gui && (!enslaved)) {
! 		gui->show ();
! 	}
  	changed ();
  }
***************
*** 343,346 ****
--- 370,375 ----
  #include "rkcomponentmap.h"
  
+ #include <qpushbutton.h>
+ 
  RKComponentBuilder::RKComponentBuilder (RKStandardComponent *parent_component) {
  	RK_TRACE (PLUGIN);
***************
*** 429,433 ****
  			RKComponentHandle *handle = RKGlobals::componentMap ()->getComponentHandle (component_id);
  			if (handle) {
! 				widget = handle->invoke (component (), parent_widget);
  			} else {
  				xml->displayError (&e, QString ("Could not embed component '%1'. Not found").arg (component_id), DL_ERROR);
--- 458,470 ----
  			RKComponentHandle *handle = RKGlobals::componentMap ()->getComponentHandle (component_id);
  			if (handle) {
! 				if (xml->getBoolAttribute (e, "as_button", false, DL_INFO)) {
! 					widget = handle->invoke (component (), 0);
! 					QString dummy = xml->getStringAttribute (e, "label", "Options", DL_WARNING);
! 					widget->setCaption (dummy);
! 					QPushButton *button = new QPushButton (dummy, parent_widget);
! 					component ()->connect (button, SIGNAL (clicked ()), widget, SLOT (showGUI ()));
! 				} else {
! 					widget = handle->invoke (component (), parent_widget);
! 				}
  			} else {
  				xml->displayError (&e, QString ("Could not embed component '%1'. Not found").arg (component_id), DL_ERROR);

Index: rkstandardcomponentgui.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkstandardcomponentgui.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** rkstandardcomponentgui.h	20 Mar 2006 00:57:31 -0000	1.1
--- rkstandardcomponentgui.h	20 Mar 2006 20:30:58 -0000	1.2
***************
*** 76,80 ****
  	Q_OBJECT
  public:
! 	RKStandardComponentGUI (RKStandardComponent *component, RKComponentPropertyCode *code_property);
  	~RKStandardComponentGUI ();
  
--- 76,80 ----
  	Q_OBJECT
  public:
! 	RKStandardComponentGUI (RKStandardComponent *component, RKComponentPropertyCode *code_property, bool enslaved);
  	~RKStandardComponentGUI ();
  
***************
*** 110,113 ****
--- 110,115 ----
  	QPushButton *switch_button;
  	RKCommandEditor *code_display;
+ 
+ 	bool enslaved;
  };
  
***************
*** 118,122 ****
  	Q_OBJECT
  public:
! 	RKStandardComponentWizard (RKStandardComponent *component, RKComponentPropertyCode *code_property);
  	~RKStandardComponentWizard ();
  
--- 120,124 ----
  	Q_OBJECT
  public:
! 	RKStandardComponentWizard (RKStandardComponent *component, RKComponentPropertyCode *code_property, bool enslaved);
  	~RKStandardComponentWizard ();
  





More information about the rkward-tracker mailing list