mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 22:00:35 +01:00
Elements static texts can now be either black or white.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1616 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -554,6 +554,7 @@ bool CustomElement::parseText(QDomElement &e, QPainter &qp) {
|
||||
// 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 @@ bool CustomElement::parseText(QDomElement &e, QPainter &qp) {
|
||||
|
||||
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();
|
||||
|
||||
@@ -40,6 +40,7 @@ PartText::PartText(QETElementEditor *editor, QGraphicsItem *parent, ElementScene
|
||||
#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 @@ void PartText::fromXml(const QDomElement &xml_element) {
|
||||
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 @@ const QDomElement PartText::toXml(QDomDocument &xml_document) const {
|
||||
if (rotationAngle()) {
|
||||
xml_element.setAttribute("rotation", QString("%1").arg(rotationAngle()));
|
||||
}
|
||||
if (!isBlack()) {
|
||||
xml_element.setAttribute("color", "white");
|
||||
}
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
@@ -107,6 +112,22 @@ void PartText::setRotationAngle(const qreal &angle) {
|
||||
setRotation(QET::correctAngle(angle));
|
||||
}
|
||||
|
||||
/**
|
||||
@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.
|
||||
*/
|
||||
@@ -195,6 +216,8 @@ void PartText::setProperty(const QString &property, const QVariant &value) {
|
||||
setPlainText(value.toString());
|
||||
} else if (property == "rotation angle") {
|
||||
setRotationAngle(value.toDouble());
|
||||
} else if (property == "color") {
|
||||
setBlack(value.toBool());
|
||||
}
|
||||
update();
|
||||
}
|
||||
@@ -220,6 +243,8 @@ QVariant PartText::property(const QString &property) {
|
||||
return(toPlainText());
|
||||
} else if (property == "rotation angle") {
|
||||
return(rotation());
|
||||
} else if (property == "color") {
|
||||
return(isBlack());
|
||||
}
|
||||
return(QVariant());
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ class PartText : public QGraphicsTextItem, public CustomElementPart {
|
||||
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;
|
||||
|
||||
@@ -35,6 +35,12 @@ TextEditor::TextEditor(QETElementEditor *editor, PartText *text, QWidget *parent
|
||||
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 @@ TextEditor::TextEditor(QETElementEditor *editor, PartText *text, QWidget *parent
|
||||
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::updateTextY() { addChangePartCommand(tr("ordonn\351e"), part, "
|
||||
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 @@ void TextEditor::updateForm() {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ class TextEditor : public ElementItemEditor {
|
||||
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 @@ class TextEditor : public ElementItemEditor {
|
||||
void updateTextY();
|
||||
void updateTextT();
|
||||
void updateTextS();
|
||||
void updateTextC();
|
||||
void updateTextRotationAngle();
|
||||
void updateForm();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user