mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-03-17 23:59:58 +01:00
Test font size in pixel for DynamicElementTextItem
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "../diagramcommands.h"
|
||||
#include "../qetapp.h"
|
||||
#include "../richtext/richtexteditor_p.h"
|
||||
#include "../utils/qetutils.h"
|
||||
|
||||
/**
|
||||
@brief DiagramTextItem::DiagramTextItem
|
||||
@@ -157,6 +158,14 @@ QPointF DiagramTextItem::mapMovementFromParent(const QPointF &movement) const
|
||||
return(local_movement_point - local_origin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DiagramTextItem::setFont
|
||||
* Reimplemented from QGraphicsTextItem.
|
||||
* This function ensure alignment is unchanged after @a font was set.
|
||||
* If not set, the font size is set in pixel instead of point
|
||||
* and emit fontChanged.
|
||||
* @param font
|
||||
*/
|
||||
void DiagramTextItem::setFont(const QFont &font)
|
||||
{
|
||||
if (this->font() == font) {
|
||||
@@ -165,7 +174,8 @@ void DiagramTextItem::setFont(const QFont &font)
|
||||
else
|
||||
{
|
||||
prepareAlignment();
|
||||
QGraphicsTextItem::setFont(font);
|
||||
//Make sure font size is in pixel
|
||||
QGraphicsTextItem::setFont(QETUtils::pointSizeToPixelSize(font));
|
||||
finishAlignment();
|
||||
emit fontChanged(font);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "crossrefitem.h"
|
||||
#include "element.h"
|
||||
#include "elementtextitemgroup.h"
|
||||
#include "../utils/qetutils.h"
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QDomElement>
|
||||
@@ -168,6 +169,7 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
|
||||
{
|
||||
QFont font;
|
||||
font.fromString(dom_elmt.attribute("font"));
|
||||
font = QETUtils::pointSizeToPixelSize(font); //In case of font was previously saved in point size
|
||||
setFont(font);
|
||||
}
|
||||
else //Retrocompatibility during the 0.7 dev because the font property was added lately. TODO remove this part in futur
|
||||
@@ -175,6 +177,7 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
|
||||
QFont font_(dom_elmt.attribute("font_family", font().family()),
|
||||
dom_elmt.attribute("font_size", QString::number(9)).toInt());
|
||||
font_.setStyleName(dom_elmt.attribute("dynamicitemstyle", font().styleName()));
|
||||
font_ = QETUtils::pointSizeToPixelSize(font_);
|
||||
setFont(font_);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user