[qet] [1616] Elements static texts can now be either black or white.

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


Revision: 1616
Author:   xavier
Date:     2012-04-01 00:48:40 +0200 (Sun, 01 Apr 2012)
Log Message:
-----------
Elements static texts can now be either black or white.

Modified Paths:
--------------
    branches/0.3/sources/customelement.cpp
    branches/0.3/sources/editor/parttext.cpp
    branches/0.3/sources/editor/parttext.h
    branches/0.3/sources/editor/texteditor.cpp
    branches/0.3/sources/editor/texteditor.h

Modified: branches/0.3/sources/customelement.cpp
===================================================================
--- branches/0.3/sources/customelement.cpp	2012-03-31 22:08:57 UTC (rev 1615)
+++ branches/0.3/sources/customelement.cpp	2012-03-31 22:48:40 UTC (rev 1616)
@@ -554,6 +554,7 @@
 	// determine la police a utiliser et en recupere les metriques associees
 	QFont used_font = QETApp::diagramTextsFont(size);
 	QFontMetrics qfm(used_font);
+	QColor text_color = (e.attribute("color") != "white"? Qt::black : Qt::white);
 	
 	// instancie un QTextDocument (comme la classe QGraphicsTextItem) pour
 	// generer le rendu graphique du texte
@@ -591,12 +592,9 @@
 	
 	qp.translate(qpainter_offset);
 	
-	/*
-		effectue le rendu du QTextDocument en forcant la palette utilisee
-		afin de rendre le texte en noir systematiquement
-	*/
+	// force the palette used to render the QTextDocument
 	QAbstractTextDocumentLayout::PaintContext ctx;
-	ctx.palette.setColor(QPalette::Text, QColor(Qt::black));
+	ctx.palette.setColor(QPalette::Text, text_color);
 	text_document.documentLayout() -> draw(&qp, ctx);
 	
 	qp.restore();

Modified: branches/0.3/sources/editor/parttext.cpp
===================================================================
--- branches/0.3/sources/editor/parttext.cpp	2012-03-31 22:08:57 UTC (rev 1615)
+++ branches/0.3/sources/editor/parttext.cpp	2012-03-31 22:48:40 UTC (rev 1616)
@@ -40,6 +40,7 @@
 #if QT_VERSION >= 0x040600
 	setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
 #endif
+	setDefaultTextColor(Qt::black);
 	setPlainText(QObject::tr("T", "default text when adding a text in the element editor"));
 	
 	adjustItemPosition(1);
@@ -61,6 +62,7 @@
 	int font_size = xml_element.attribute("size").toInt(&ok);
 	if (!ok || font_size < 1) font_size = 20;
 	
+	setBlack(xml_element.attribute("color") != "white");
 	setFont(QETApp::diagramTextsFont(font_size));
 	setPlainText(xml_element.attribute("text"));
 	
@@ -90,6 +92,9 @@
 	if (rotationAngle()) {
 		xml_element.setAttribute("rotation", QString("%1").arg(rotationAngle()));
 	}
+	if (!isBlack()) {
+		xml_element.setAttribute("color", "white");
+	}
 	return(xml_element);
 }
 
@@ -108,6 +113,22 @@
 }
 
 /**
+	@return true or false if this static text is rendered black or white,
+	respectively.
+*/
+bool PartText::isBlack() const {
+	return(defaultTextColor() == Qt::black);
+}
+
+/**
+	@param color whether this static text should be rendered black (true) or white
+	(false).
+*/
+void PartText::setBlack(bool color) {
+	setDefaultTextColor(color ? Qt::black : Qt::white);
+}
+
+/**
 	@return Les coordonnees du point situe en bas a gauche du texte.
 */
 QPointF PartText::margin() const {
@@ -195,6 +216,8 @@
 		setPlainText(value.toString());
 	} else if (property == "rotation angle") {
 		setRotationAngle(value.toDouble());
+	} else if (property == "color") {
+		setBlack(value.toBool());
 	}
 	update();
 }
@@ -220,6 +243,8 @@
 		return(toPlainText());
 	} else if (property == "rotation angle") {
 		return(rotation());
+	} else if (property == "color") {
+		return(isBlack());
 	}
 	return(QVariant());
 }

Modified: branches/0.3/sources/editor/parttext.h
===================================================================
--- branches/0.3/sources/editor/parttext.h	2012-03-31 22:08:57 UTC (rev 1615)
+++ branches/0.3/sources/editor/parttext.h	2012-03-31 22:48:40 UTC (rev 1616)
@@ -49,6 +49,8 @@
 	const QDomElement toXml(QDomDocument &) const;
 	qreal rotationAngle() const;
 	void setRotationAngle(const qreal &);
+	bool isBlack() const;
+	void setBlack(bool);
 	virtual void setProperty(const QString &, const QVariant &);
 	virtual QVariant property(const QString &);
 	virtual bool isUseless() const;

Modified: branches/0.3/sources/editor/texteditor.cpp
===================================================================
--- branches/0.3/sources/editor/texteditor.cpp	2012-03-31 22:08:57 UTC (rev 1615)
+++ branches/0.3/sources/editor/texteditor.cpp	2012-03-31 22:48:40 UTC (rev 1616)
@@ -35,6 +35,12 @@
 	qle_text  = new QLineEdit();
 	font_size = new QSpinBox();
 	font_size -> setRange(0, 144);
+	black_color_ = new QRadioButton(tr("Noir", "element text part color"));
+	white_color_ = new QRadioButton(tr("Blanc", "element text part color"));
+	color_ = new QButtonGroup(this);
+	color_ -> addButton(black_color_, true);
+	color_ -> addButton(white_color_, false);
+	connect(color_, SIGNAL(buttonClicked(int)), this, SLOT(updateTextC()));
 	QLabel *rotation_angle_label = new QLabel(tr("Angle de rotation : "));
 	rotation_angle_label -> setWordWrap(true);
 	rotation_angle_ = QETApp::createTextOrientationSpinBoxWidget();
@@ -57,6 +63,13 @@
 	fs -> addWidget(font_size);
 	main_layout -> addLayout(fs);
 	
+	QHBoxLayout *color_layout = new QHBoxLayout();
+	color_layout -> addWidget(new QLabel(tr("Couleur : ")));
+	color_layout -> addWidget(black_color_);
+	color_layout -> addWidget(white_color_);
+	color_layout -> addStretch();
+	main_layout -> addLayout(color_layout);
+	
 	QHBoxLayout *t = new QHBoxLayout();
 	t -> addWidget(new QLabel(tr("Texte : ")));
 	t -> addWidget(qle_text);
@@ -126,6 +139,8 @@
 void TextEditor::updateTextT() { addChangePartCommand(tr("contenu"),     part, "text", qle_text -> text());         }
 /// Met a jour la taille du texte et cree un objet d'annulation
 void TextEditor::updateTextS() { addChangePartCommand(tr("taille"),      part, "size", font_size -> value());       }
+/// Update the text color and create an undo object
+void TextEditor::updateTextC() { addChangePartCommand(tr("couleur", "undo caption"), part, "color", color_ -> checkedId()); }
 /// Met a jour l'angle de rotation du champ de texte et cree un objet d'annulation
 void TextEditor::updateTextRotationAngle() { addChangePartCommand(tr("angle de rotation"), part, "rotation angle", rotation_angle_ -> value()); }
 
@@ -139,6 +154,9 @@
 	qle_y     -> setText(part -> property("y").toString());
 	qle_text  -> setText(part -> property("text").toString());
 	font_size -> setValue(part -> property("size").toInt());
+	if (QAbstractButton *button = color_ -> button(part -> property("color").toBool())) {
+		button -> setChecked(true);
+	}
 	rotation_angle_ -> setValue(part -> property("rotation angle").toDouble());
 	activeConnections(true);
 }

Modified: branches/0.3/sources/editor/texteditor.h
===================================================================
--- branches/0.3/sources/editor/texteditor.h	2012-03-31 22:08:57 UTC (rev 1615)
+++ branches/0.3/sources/editor/texteditor.h	2012-03-31 22:48:40 UTC (rev 1616)
@@ -40,6 +40,8 @@
 	PartText *part;
 	QLineEdit *qle_x, *qle_y, *qle_text;
 	QSpinBox *font_size;
+	QButtonGroup *color_;
+	QRadioButton *black_color_, *white_color_;
 	QTextOrientationSpinBoxWidget *rotation_angle_;
 	
 	// methodes
@@ -53,6 +55,7 @@
 	void updateTextY();
 	void updateTextT();
 	void updateTextS();
+	void updateTextC();
 	void updateTextRotationAngle();
 	void updateForm();
 	


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