mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
Dynamic element text item : The font of the dynamic texts can be individually be setted.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5764 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -165,6 +165,20 @@ int DiagramTextItem::fontSize() const
|
|||||||
return font().pointSize();
|
return font().pointSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiagramTextItem::setFont(const QFont &font)
|
||||||
|
{
|
||||||
|
if (this->font() == font) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
prepareAlignment();
|
||||||
|
QGraphicsTextItem::setFont(font);
|
||||||
|
finishAlignment();
|
||||||
|
emit fontChanged(font);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DiagramTextItem::setColor(const QColor& color)
|
void DiagramTextItem::setColor(const QColor& color)
|
||||||
{
|
{
|
||||||
setDefaultTextColor(color);
|
setDefaultTextColor(color);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#define DIAGRAM_TEXT_ITEM_H
|
#define DIAGRAM_TEXT_ITEM_H
|
||||||
|
|
||||||
#include <QGraphicsTextItem>
|
#include <QGraphicsTextItem>
|
||||||
|
#include <QFont>
|
||||||
|
|
||||||
class Diagram;
|
class Diagram;
|
||||||
class QDomElement;
|
class QDomElement;
|
||||||
@@ -37,6 +38,7 @@ class DiagramTextItem : public QGraphicsTextItem
|
|||||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
||||||
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
||||||
Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText)
|
Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText)
|
||||||
|
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@@ -44,6 +46,7 @@ class DiagramTextItem : public QGraphicsTextItem
|
|||||||
void colorChanged(QColor color);
|
void colorChanged(QColor color);
|
||||||
void alignmentChanged(Qt::Alignment alignment);
|
void alignmentChanged(Qt::Alignment alignment);
|
||||||
void textEdited(const QString &old_str, const QString &new_str);
|
void textEdited(const QString &old_str, const QString &new_str);
|
||||||
|
void fontChanged(QFont font);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DiagramTextItem(QGraphicsItem * = nullptr);
|
DiagramTextItem(QGraphicsItem * = nullptr);
|
||||||
@@ -69,6 +72,8 @@ class DiagramTextItem : public QGraphicsTextItem
|
|||||||
void setFontSize(int s);
|
void setFontSize(int s);
|
||||||
int fontSize()const;
|
int fontSize()const;
|
||||||
|
|
||||||
|
void setFont(const QFont &font);
|
||||||
|
|
||||||
void setColor(const QColor& color);
|
void setColor(const QColor& color);
|
||||||
QColor color() const;
|
QColor color() const;
|
||||||
|
|
||||||
|
|||||||
@@ -92,12 +92,10 @@ QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const
|
|||||||
root_element.setAttribute("x", QString::number(pos().x()));
|
root_element.setAttribute("x", QString::number(pos().x()));
|
||||||
root_element.setAttribute("y", QString::number(pos().y()));
|
root_element.setAttribute("y", QString::number(pos().y()));
|
||||||
root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
|
root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
|
||||||
root_element.setAttribute("font_size", font().pointSize());
|
|
||||||
root_element.setAttribute("uuid", m_uuid.toString());
|
root_element.setAttribute("uuid", m_uuid.toString());
|
||||||
root_element.setAttribute("font_family", font().family());
|
|
||||||
root_element.setAttribute("dynamicitemstyle", font().styleName());
|
|
||||||
root_element.setAttribute("frame", m_frame? "true" : "false");
|
root_element.setAttribute("frame", m_frame? "true" : "false");
|
||||||
root_element.setAttribute("text_width", QString::number(m_text_width));
|
root_element.setAttribute("text_width", QString::number(m_text_width));
|
||||||
|
root_element.setAttribute("font", font().toString());
|
||||||
|
|
||||||
QMetaEnum me = textFromMetaEnum();
|
QMetaEnum me = textFromMetaEnum();
|
||||||
root_element.setAttribute("text_from", me.valueToKey(m_text_from));
|
root_element.setAttribute("text_from", me.valueToKey(m_text_from));
|
||||||
@@ -162,10 +160,21 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsTextItem::setRotation(dom_elmt.attribute("rotation", QString::number(0)).toDouble());
|
QGraphicsTextItem::setRotation(dom_elmt.attribute("rotation", QString::number(0)).toDouble());
|
||||||
|
|
||||||
|
if (dom_elmt.hasAttribute("font"))
|
||||||
|
{
|
||||||
|
QFont font;
|
||||||
|
font.fromString(dom_elmt.attribute("font"));
|
||||||
|
setFont(font);
|
||||||
|
}
|
||||||
|
else //Retrocompatibility during the 0.7 dev because the font property was added lately. TODO remove this part in futur
|
||||||
|
{
|
||||||
QFont font_(dom_elmt.attribute("font_family", font().family()),
|
QFont font_(dom_elmt.attribute("font_family", font().family()),
|
||||||
dom_elmt.attribute("font_size", QString::number(9)).toInt());
|
dom_elmt.attribute("font_size", QString::number(9)).toInt());
|
||||||
font_.setStyleName(dom_elmt.attribute("dynamicitemstyle", font().styleName()));
|
font_.setStyleName(dom_elmt.attribute("dynamicitemstyle", font().styleName()));
|
||||||
setFont(font_);
|
setFont(font_);
|
||||||
|
}
|
||||||
|
|
||||||
m_uuid = QUuid(dom_elmt.attribute("uuid", QUuid::createUuid().toString()));
|
m_uuid = QUuid(dom_elmt.attribute("uuid", QUuid::createUuid().toString()));
|
||||||
setFrame(dom_elmt.attribute("frame", "false") == "true"? true : false);
|
setFrame(dom_elmt.attribute("frame", "false") == "true"? true : false);
|
||||||
setTextWidth(dom_elmt.attribute("text_width", QString::number(-1)).toDouble());
|
setTextWidth(dom_elmt.attribute("text_width", QString::number(-1)).toDouble());
|
||||||
@@ -643,13 +652,13 @@ void DynamicElementTextItem::paint(QPainter *painter, const QStyleOptionGraphics
|
|||||||
if (m_frame)
|
if (m_frame)
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setFont(QETApp::dynamicTextsItemFont(fontSize()));
|
painter->setFont(QETApp::dynamicTextsItemFont(font().pointSize()));
|
||||||
|
|
||||||
//Adjust the thickness according to the font size,
|
//Adjust the thickness according to the font size,
|
||||||
qreal w=0.3;
|
qreal w=0.3;
|
||||||
if(fontSize() >= 5)
|
if(font().pointSize() >= 5)
|
||||||
{
|
{
|
||||||
w = (qreal)fontSize()*0.1;
|
w = font().pointSizeF()*0.1;
|
||||||
if(w > 2.5)
|
if(w > 2.5)
|
||||||
w = 2.5;
|
w = 2.5;
|
||||||
}
|
}
|
||||||
@@ -661,7 +670,7 @@ void DynamicElementTextItem::paint(QPainter *painter, const QStyleOptionGraphics
|
|||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
//Adjust the rounding of the rectangle according to the size of the font
|
//Adjust the rounding of the rectangle according to the size of the font
|
||||||
qreal ro = (qreal)fontSize()/3;
|
qreal ro = font().pointSizeF()/3;
|
||||||
painter->drawRoundedRect(frameRect(), ro, ro);
|
painter->drawRoundedRect(frameRect(), ro, ro);
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|||||||
@@ -35,26 +35,27 @@
|
|||||||
#include "addelementtextcommand.h"
|
#include "addelementtextcommand.h"
|
||||||
#include "alignmenttextdialog.h"
|
#include "alignmenttextdialog.h"
|
||||||
|
|
||||||
int src_txt_row = 0;
|
static int src_txt_row = 0;
|
||||||
int usr_txt_row = 1;
|
static int usr_txt_row = 1;
|
||||||
int info_txt_row = 2;
|
static int info_txt_row = 2;
|
||||||
int compo_txt_row = 3;
|
static int compo_txt_row = 3;
|
||||||
int size_txt_row = 4;
|
static int size_txt_row = 4;
|
||||||
int color_txt_row = 5;
|
static int font_txt_row = 5;
|
||||||
int frame_txt_row = 6;
|
static int color_txt_row = 6;
|
||||||
int width_txt_row = 7;
|
static int frame_txt_row = 7;
|
||||||
int x_txt_row = 8;
|
static int width_txt_row = 8;
|
||||||
int y_txt_row = 9;
|
static int x_txt_row = 9;
|
||||||
int rot_txt_row = 10;
|
static int y_txt_row = 10;
|
||||||
int align_txt_row = 11;
|
static int rot_txt_row = 11;
|
||||||
|
static int align_txt_row = 12;
|
||||||
|
|
||||||
int align_grp_row = 0;
|
static int align_grp_row = 0;
|
||||||
int x_grp_row = 1;
|
static int x_grp_row = 1;
|
||||||
int y_grp_row = 2;
|
static int y_grp_row = 2;
|
||||||
int rot_grp_row = 3;
|
static int rot_grp_row = 3;
|
||||||
int adjust_grp_row = 4;
|
static int adjust_grp_row = 4;
|
||||||
int frame_grp_row = 5;
|
static int frame_grp_row = 5;
|
||||||
int hold_to_bottom_grp_row = 6;
|
static int hold_to_bottom_grp_row = 6;
|
||||||
|
|
||||||
DynamicElementTextModel::DynamicElementTextModel(Element *element, QObject *parent) :
|
DynamicElementTextModel::DynamicElementTextModel(Element *element, QObject *parent) :
|
||||||
QStandardItemModel(parent),
|
QStandardItemModel(parent),
|
||||||
@@ -193,12 +194,27 @@ QList<QStandardItem *> DynamicElementTextModel::itemsForText(DynamicElementTextI
|
|||||||
size->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
size->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||||
|
|
||||||
QStandardItem *siza = new QStandardItem();
|
QStandardItem *siza = new QStandardItem();
|
||||||
siza->setData(deti->fontSize(), Qt::EditRole);
|
siza->setData(deti->font().pointSize(), Qt::EditRole);
|
||||||
siza->setData(DynamicElementTextModel::size, Qt::UserRole+1);
|
siza->setData(DynamicElementTextModel::size, Qt::UserRole+1);
|
||||||
siza->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
|
siza->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
|
||||||
|
|
||||||
qsi_list.clear();
|
qsi_list.clear();
|
||||||
qsi_list << size << siza;
|
qsi_list << size << siza;
|
||||||
|
qsi->appendRow(qsi_list);
|
||||||
|
|
||||||
|
//Font
|
||||||
|
QStandardItem *font = new QStandardItem(tr("Police"));
|
||||||
|
font->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||||
|
|
||||||
|
QStandardItem *fonta = new QStandardItem();
|
||||||
|
fonta->setFont(deti->font());
|
||||||
|
fonta->setData(deti->font().family(), Qt::EditRole);
|
||||||
|
fonta->setData(DynamicElementTextModel::font, Qt::UserRole+1);
|
||||||
|
fonta->setData(deti->font(), Qt::UserRole+2);
|
||||||
|
fonta->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
|
||||||
|
|
||||||
|
qsi_list.clear();
|
||||||
|
qsi_list << font << fonta;
|
||||||
qsi->appendRow(qsi_list);
|
qsi->appendRow(qsi_list);
|
||||||
|
|
||||||
//Color
|
//Color
|
||||||
@@ -470,13 +486,20 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem
|
|||||||
}
|
}
|
||||||
|
|
||||||
int fs = text_qsi->child(size_txt_row,1)->data(Qt::EditRole).toInt();
|
int fs = text_qsi->child(size_txt_row,1)->data(Qt::EditRole).toInt();
|
||||||
if (fs != deti->fontSize())
|
if (fs != deti->font().pointSize())
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "fontSize", QVariant(deti->fontSize()), QVariant(fs), undo);
|
QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "fontSize", QVariant(deti->font().pointSize()), QVariant(fs), undo);
|
||||||
quc->setAnimated(true, false);
|
quc->setAnimated(true, false);
|
||||||
quc->setText(tr("Modifier la taille d'un texte d'élément"));
|
quc->setText(tr("Modifier la taille d'un texte d'élément"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QFont font = text_qsi->child(font_txt_row, 1)->data(Qt::UserRole+2).value<QFont>();
|
||||||
|
if (font != deti->font())
|
||||||
|
{
|
||||||
|
QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "font", QVariant(deti->font()), QVariant(font), undo);
|
||||||
|
quc->setText(tr("Modifier la police d'un texte d'élément"));
|
||||||
|
}
|
||||||
|
|
||||||
QColor color = text_qsi->child(color_txt_row,1)->data(Qt::EditRole).value<QColor>();
|
QColor color = text_qsi->child(color_txt_row,1)->data(Qt::EditRole).value<QColor>();
|
||||||
if(color != deti->color())
|
if(color != deti->color())
|
||||||
{
|
{
|
||||||
@@ -1209,7 +1232,7 @@ void DynamicElementTextModel::setConnection(DynamicElementTextItem *deti, bool s
|
|||||||
|
|
||||||
QList<QMetaObject::Connection> connection_list;
|
QList<QMetaObject::Connection> connection_list;
|
||||||
connection_list << connect(deti, &DynamicElementTextItem::colorChanged, [deti,this](){this->updateDataFromText(deti, color);});
|
connection_list << connect(deti, &DynamicElementTextItem::colorChanged, [deti,this](){this->updateDataFromText(deti, color);});
|
||||||
connection_list << connect(deti, &DynamicElementTextItem::fontSizeChanged, [deti,this](){this->updateDataFromText(deti, size);});
|
connection_list << connect(deti, &DynamicElementTextItem::fontChanged, [deti,this](){this->updateDataFromText(deti, font);});
|
||||||
connection_list << connect(deti, &DynamicElementTextItem::textFromChanged, [deti,this](){this->updateDataFromText(deti, textFrom);});
|
connection_list << connect(deti, &DynamicElementTextItem::textFromChanged, [deti,this](){this->updateDataFromText(deti, textFrom);});
|
||||||
connection_list << connect(deti, &DynamicElementTextItem::textChanged, [deti,this](){this->updateDataFromText(deti, userText);});
|
connection_list << connect(deti, &DynamicElementTextItem::textChanged, [deti,this](){this->updateDataFromText(deti, userText);});
|
||||||
connection_list << connect(deti, &DynamicElementTextItem::infoNameChanged, [deti,this](){this->updateDataFromText(deti, infoText);});
|
connection_list << connect(deti, &DynamicElementTextItem::infoNameChanged, [deti,this](){this->updateDataFromText(deti, infoText);});
|
||||||
@@ -1317,8 +1340,17 @@ void DynamicElementTextModel::updateDataFromText(DynamicElementTextItem *deti, V
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case size:
|
case size:
|
||||||
qsi->child(size_txt_row,1)->setData(deti->fontSize(), Qt::EditRole);
|
//qsi->child(size_txt_row,1)->setData(deti->fontSize(), Qt::EditRole);
|
||||||
break;
|
break;
|
||||||
|
case font:
|
||||||
|
{
|
||||||
|
QFont f(deti->font());
|
||||||
|
qsi->child(font_txt_row,1)->setFont(f);
|
||||||
|
qsi->child(font_txt_row,1)->setData(f.family(), Qt::EditRole);
|
||||||
|
qsi->child(font_txt_row,1)->setData(f, Qt::UserRole+2);
|
||||||
|
qsi->child(size_txt_row,1)->setData(f.pointSize(), Qt::EditRole);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case color:
|
case color:
|
||||||
{
|
{
|
||||||
qsi->child(color_txt_row,1)->setData(deti->color(), Qt::EditRole);
|
qsi->child(color_txt_row,1)->setData(deti->color(), Qt::EditRole);
|
||||||
@@ -1380,6 +1412,7 @@ void DynamicElementTextModel::updateDataFromGroup(ElementTextItemGroup *group, D
|
|||||||
{
|
{
|
||||||
qsi->child(x_grp_row,1)->setData(group->pos().x(), Qt::EditRole);
|
qsi->child(x_grp_row,1)->setData(group->pos().x(), Qt::EditRole);
|
||||||
qsi->child(y_grp_row,1)->setData(group->pos().y(), Qt::EditRole);
|
qsi->child(y_grp_row,1)->setData(group->pos().y(), Qt::EditRole);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case grpRotation:
|
case grpRotation:
|
||||||
qsi->child(rot_grp_row,1)->setData(group->rotation(), Qt::EditRole);
|
qsi->child(rot_grp_row,1)->setData(group->rotation(), Qt::EditRole);
|
||||||
@@ -1493,9 +1526,15 @@ QWidget *DynamicTextItemDelegate::createEditor(QWidget *parent, const QStyleOpti
|
|||||||
sb->setFrame(false);
|
sb->setFrame(false);
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
case DynamicElementTextModel::font:
|
||||||
|
{
|
||||||
|
QFontDialog *fd = new QFontDialog(index.data(Qt::UserRole+2).value<QFont>(), parent);
|
||||||
|
fd->setObjectName("font_dialog");
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
case DynamicElementTextModel::color:
|
case DynamicElementTextModel::color:
|
||||||
{
|
{
|
||||||
QColorDialog *cd = new QColorDialog(index.data(Qt::EditRole).value<QColor>());
|
QColorDialog *cd = new QColorDialog(index.data(Qt::EditRole).value<QColor>(), parent);
|
||||||
cd->setObjectName("color_dialog");
|
cd->setObjectName("color_dialog");
|
||||||
return cd;
|
return cd;
|
||||||
}
|
}
|
||||||
@@ -1573,15 +1612,41 @@ void DynamicTextItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *
|
|||||||
{
|
{
|
||||||
if (index.isValid())
|
if (index.isValid())
|
||||||
{
|
{
|
||||||
if(editor->objectName() == "color_dialog")
|
if (editor->objectName() == "font_dialog")
|
||||||
|
{
|
||||||
|
if (QStandardItemModel *qsim = dynamic_cast<QStandardItemModel *>(model))
|
||||||
|
{
|
||||||
|
if(QStandardItem *qsi = qsim->itemFromIndex(index))
|
||||||
|
{
|
||||||
|
QFontDialog *fd = static_cast<QFontDialog *>(editor);
|
||||||
|
if (fd->result() == QDialog::Accepted)
|
||||||
|
{
|
||||||
|
//qsi->setData(fd->selectedFont().family(), Qt::EditRole);
|
||||||
|
//qsi->setData(fd->selectedFont(), Qt::UserRole+2);
|
||||||
|
/**For unknow reason, call selectedFont doesn't work,
|
||||||
|
* (always return the same font, no matter what you select)
|
||||||
|
* Instead we use curentFont
|
||||||
|
**/
|
||||||
|
qsi->setData(fd->currentFont().family(), Qt::EditRole);
|
||||||
|
qsi->setData(fd->currentFont(), Qt::UserRole+2);
|
||||||
|
qsi->setFont(fd->currentFont());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(editor->objectName() == "color_dialog")
|
||||||
{
|
{
|
||||||
if (QStandardItemModel *qsim = dynamic_cast<QStandardItemModel *>(model))
|
if (QStandardItemModel *qsim = dynamic_cast<QStandardItemModel *>(model))
|
||||||
{
|
{
|
||||||
if(QStandardItem *qsi = qsim->itemFromIndex(index))
|
if(QStandardItem *qsi = qsim->itemFromIndex(index))
|
||||||
{
|
{
|
||||||
QColorDialog *cd = static_cast<QColorDialog *> (editor);
|
QColorDialog *cd = static_cast<QColorDialog *> (editor);
|
||||||
|
if (cd->result() == QDialog::Accepted)
|
||||||
|
{
|
||||||
qsi->setData(cd->selectedColor(), Qt::EditRole);
|
qsi->setData(cd->selectedColor(), Qt::EditRole);
|
||||||
qsi->setData(cd->selectedColor(), Qt::ForegroundRole);
|
qsi->setData(cd->selectedColor(), Qt::ForegroundRole);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class DynamicElementTextModel : public QStandardItemModel
|
|||||||
compositeText,
|
compositeText,
|
||||||
txtAlignment,
|
txtAlignment,
|
||||||
size,
|
size,
|
||||||
|
font,
|
||||||
color,
|
color,
|
||||||
pos,
|
pos,
|
||||||
frame,
|
frame,
|
||||||
|
|||||||
Reference in New Issue
Block a user