[qet] [1313] add a F2 shortcut for the widget " Edit the color of the given conductor"

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 1313
Author:   scorpio810
Date:     2011-08-22 13:17:10 +0200 (Mon, 22 Aug 2011)
Log Message:
-----------
add a F2 shortcut for the widget "Edit the color of the given conductor"

Modified Paths:
--------------
    branches/0.3/sources/diagramview.cpp
    branches/0.3/sources/diagramview.h

Modified: branches/0.3/sources/diagramview.cpp
===================================================================
--- branches/0.3/sources/diagramview.cpp	2011-08-17 18:58:07 UTC (rev 1312)
+++ branches/0.3/sources/diagramview.cpp	2011-08-22 11:17:10 UTC (rev 1313)
@@ -73,6 +73,8 @@
 	connect(&(scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(updateWindowTitle()));
 	
 	connect(this, SIGNAL(aboutToAddElement()), this, SLOT(addDroppedElement()), Qt::QueuedConnection);
+	QShortcut *edit_conductor_color_shortcut = new QShortcut(QKeySequence(Qt::Key_F2), this);
+	connect(edit_conductor_color_shortcut, SIGNAL(activated()), this, SLOT(editSelectedConductorColor()));
 }
 
 /**
@@ -737,6 +739,20 @@
 }
 
 /**
+	Edit the color of the selected conductor; does nothing if multiple conductors are selected
+*/
+void DiagramView::editSelectedConductorColor() {
+	// retrieve selected content
+	DiagramContent selection = scene -> selectedContent();
+	
+	// we'll focus on the selected conductor (we do not handle multiple conductors edition)
+	QList<Conductor *> selected_conductors = selection.conductors(DiagramContent::AnyConductor | DiagramContent::SelectedOnly);
+	if (selected_conductors.count() == 1) {
+		editConductorColor(selected_conductors.at(0));
+	}
+}
+
+/**
 	Affiche des informations sur un element
 	@param element Element a afficher
 */
@@ -858,6 +874,41 @@
 }
 
 /**
+	Edit the color of the given conductor
+	@param edited_conductor Conductor we want to change the color
+*/
+void DiagramView::editConductorColor(Conductor *edited_conductor) {
+	if (scene -> isReadOnly()) return;
+	if (!edited_conductor) return;
+	
+	// store the initial properties of the provided conductor
+	ConductorProperties initial_properties = edited_conductor -> properties();
+	
+	// prepare a color dialog showing the initial conductor color
+	QColorDialog *color_dialog = new QColorDialog(this);
+	color_dialog -> setWindowTitle(tr("Choisir la nouvelle couleur de ce conducteur"));
+#ifdef Q_WS_MAC
+	color_dialog.setWindowFlags(Qt::Sheet);
+#endif
+	color_dialog -> setCurrentColor(initial_properties.color);
+	
+	// asks the user what color he wishes to apply
+	if (color_dialog -> exec() == QDialog::Accepted) {
+		QColor new_color = color_dialog -> selectedColor();
+		if (new_color != initial_properties.color) {
+			// the user chose a different color
+			ConductorProperties new_properties = initial_properties;
+			new_properties.color = new_color;
+			
+			ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(edited_conductor);
+			ccpc -> setOldSettings(initial_properties);
+			ccpc -> setNewSettings(new_properties);
+			diagram() -> undoStack().push(ccpc);
+		}
+	}
+}
+
+/**
 	Reinitialise le profil des conducteurs selectionnes
 */
 void DiagramView::resetConductors() {

Modified: branches/0.3/sources/diagramview.h
===================================================================
--- branches/0.3/sources/diagramview.h	2011-08-17 18:58:07 UTC (rev 1312)
+++ branches/0.3/sources/diagramview.h	2011-08-22 11:17:10 UTC (rev 1313)
@@ -118,9 +118,11 @@
 	void adjustSceneRect();
 	void updateWindowTitle();
 	void editSelectionProperties();
+	void editSelectedConductorColor();
 	void editElement(Element *);
 	void editConductor();
 	void editConductor(Conductor *);
+	void editConductorColor(Conductor *);
 	void resetConductors();
 	
 	private slots:


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/