[qet] [2447] remove some bool by an enum, the code is more comprehensible

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


Revision: 2447
Author:   blacksun
Date:     2013-08-24 14:03:26 +0200 (Sat, 24 Aug 2013)
Log Message:
-----------
remove some bool by an enum, the code is more comprehensible

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

Modified: branches/0.4/sources/diagramview.cpp
===================================================================
--- branches/0.4/sources/diagramview.cpp	2013-08-23 23:09:06 UTC (rev 2446)
+++ branches/0.4/sources/diagramview.cpp	2013-08-24 12:03:26 UTC (rev 2447)
@@ -49,10 +49,11 @@
 	@param diagram Schema a afficher ; si diagram vaut 0, un nouveau Diagram est utilise
 	@param parent Le QWidget parent de cette vue de schema
 */
-DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QGraphicsView(parent), is_adding_text(false), is_moving_view_(false) {
+DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QGraphicsView(parent) {
 	setAttribute(Qt::WA_DeleteOnClose, true);
 	setInteractive(true);
-	
+	current_behavior = noAction;
+
 	QString whatsthis = tr(
 		"Ceci est la zone dans laquelle vous concevez vos sch\351mas en y ajoutant"
 		" des \351l\351ments et en posant des conducteurs entre leurs bornes. Il est"
@@ -425,15 +426,16 @@
 		switchToVisualisationModeIfNeeded(e);
 		fresh_focus_in_ = false;
 	}
-	if (isInteractive() && !scene -> isReadOnly()) {
-		if (is_adding_text && e -> buttons() == Qt::LeftButton) {
-			addDiagramTextAtPos(mapToScene(e -> pos()));
-			is_adding_text = false;
+	if (isInteractive() && !scene -> isReadOnly() && current_behavior > noAction && e -> buttons() == Qt::LeftButton) {
+		switch (current_behavior) {
+			case addingText:
+				addDiagramTextAtPos(mapToScene(e -> pos()));
+				break;
+			case addingImage:
+				addDiagramImageAtPos(mapToScene(e -> pos()));
+				break;
 		}
-		if (is_adding_image && e -> buttons() == Qt::LeftButton) {
-			addDiagramImageAtPos(mapToScene(e -> pos()));
-			is_adding_image = false;
-		}
+		current_behavior = noAction;
 	}
 	// workaround for drag view with hold wheel click and drag mouse
 	// see also mouseMoveEvent() and mouseReleaseEvent()
@@ -1157,7 +1159,7 @@
 bool DiagramView::switchToVisualisationModeIfNeeded(QInputEvent *e) {
 	if (isCtrlShifting(e) && !selectedItemHasFocus()) {
 		if (dragMode() != QGraphicsView::ScrollHandDrag) {
-			is_moving_view_ = true;
+			current_behavior = dragView;
 			setVisualisationMode();
 			return(true);
 		}
@@ -1171,9 +1173,9 @@
 	otherwise.
 */
 bool DiagramView::switchToSelectionModeIfNeeded(QInputEvent *e) {
-	if (is_moving_view_ && !selectedItemHasFocus() && !isCtrlShifting(e)) {
+	if (current_behavior == dragView && !selectedItemHasFocus() && !isCtrlShifting(e)) {
 		setSelectionMode();
-		is_moving_view_ = false;
+		current_behavior = noAction;
 		return(true);
 	}
 	return(false);
@@ -1215,9 +1217,7 @@
 */
 void DiagramView::addText() {
 	if (scene -> isReadOnly()) return;
-	is_adding_text = true;
-	//Debug CYRIL
-	is_adding_image = false;
+	current_behavior = addingText;
 }
 
 
@@ -1256,7 +1256,7 @@
 		QMessageBox::critical(this, tr("Erreur"), tr("Impossible de charger l'image...D\351soler :("));
 		return;
 	}
-	is_adding_image = true;
+	current_behavior = addingImage;
 }
 /**
 * @brief DiagramView::addDiagramImageAtPos

Modified: branches/0.4/sources/diagramview.h
===================================================================
--- branches/0.4/sources/diagramview.h	2013-08-23 23:09:06 UTC (rev 2446)
+++ branches/0.4/sources/diagramview.h	2013-08-24 12:03:26 UTC (rev 2447)
@@ -38,6 +38,8 @@
 	DiagramView(Diagram * = 0, QWidget * = 0);
 	virtual ~DiagramView();
 	
+	enum behavior {noAction, addingText, addingImage, dragView};
+
 	private:
 	DiagramView(const DiagramView &);
 	
@@ -48,9 +50,7 @@
 	QAction *paste_here;
 	QAction *find_element_;
 	QPoint paste_here_pos;
-	bool is_adding_text;
-	bool is_adding_image;
-	bool is_moving_view_;               ///< Indicate whether the visualisation mode has been enabled due to mouse/keyboard interactions
+	behavior current_behavior;
 	bool fresh_focus_in_;               ///< Indicate the focus was freshly gained
 	ElementsLocation next_location_;
 	QPoint next_position_;


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