Added wrap mode attribute to text box.
This commit is contained in:
@@ -594,6 +594,26 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Text Wrap Mode Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
QTextOption::WrapMode ModelObject::textWrapMode() const
|
||||
{
|
||||
return QTextOption::WordWrap;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Text Wrap Mode Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void ModelObject::setTextWrapMode( QTextOption::WrapMode value )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Text Line Spacing Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
|
||||
@@ -251,6 +251,13 @@ namespace glabels
|
||||
virtual void setTextVAlign( Qt::Alignment value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textWrapMode
|
||||
//
|
||||
virtual QTextOption::WrapMode textWrapMode() const;
|
||||
virtual void setTextWrapMode( QTextOption::WrapMode value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textLineSpacing
|
||||
//
|
||||
|
||||
+63
-24
@@ -69,6 +69,7 @@ namespace glabels
|
||||
mTextColorNode = ColorNode( QColor( 0, 0, 0 ) );
|
||||
mTextHAlign = Qt::AlignLeft;
|
||||
mTextVAlign = Qt::AlignTop;
|
||||
mTextWrapMode = QTextOption::WordWrap;
|
||||
mTextLineSpacing = 1;
|
||||
}
|
||||
|
||||
@@ -76,26 +77,27 @@ namespace glabels
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ModelTextObject::ModelTextObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const QString& text,
|
||||
const QString& fontFamily,
|
||||
double fontSize,
|
||||
QFont::Weight fontWeight,
|
||||
bool fontItalicFlag,
|
||||
bool fontUnderlineFlag,
|
||||
ColorNode textColorNode,
|
||||
Qt::Alignment textHAlign,
|
||||
Qt::Alignment textVAlign,
|
||||
double textLineSpacing,
|
||||
const QMatrix& matrix,
|
||||
bool shadowState,
|
||||
const Distance& shadowX,
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
ModelTextObject::ModelTextObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const QString& text,
|
||||
const QString& fontFamily,
|
||||
double fontSize,
|
||||
QFont::Weight fontWeight,
|
||||
bool fontItalicFlag,
|
||||
bool fontUnderlineFlag,
|
||||
ColorNode textColorNode,
|
||||
Qt::Alignment textHAlign,
|
||||
Qt::Alignment textVAlign,
|
||||
QTextOption::WrapMode textWrapMode,
|
||||
double textLineSpacing,
|
||||
const QMatrix& matrix,
|
||||
bool shadowState,
|
||||
const Distance& shadowX,
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelObject( x0, y0, w, h,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
@@ -120,6 +122,7 @@ namespace glabels
|
||||
mTextColorNode = textColorNode;
|
||||
mTextHAlign = textHAlign;
|
||||
mTextVAlign = textVAlign;
|
||||
mTextWrapMode = textWrapMode;
|
||||
mTextLineSpacing = textLineSpacing;
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
@@ -141,6 +144,7 @@ namespace glabels
|
||||
mTextColorNode = object->mTextColorNode;
|
||||
mTextHAlign = object->mTextHAlign;
|
||||
mTextVAlign = object->mTextVAlign;
|
||||
mTextWrapMode = object->mTextWrapMode;
|
||||
mTextLineSpacing = object->mTextLineSpacing;
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
@@ -378,6 +382,29 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Text Wrap Mode Property Getter
|
||||
///
|
||||
QTextOption::WrapMode ModelTextObject::textWrapMode() const
|
||||
{
|
||||
return mTextWrapMode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Text Wrap Mode Property Setter
|
||||
///
|
||||
void ModelTextObject::setTextWrapMode( QTextOption::WrapMode value )
|
||||
{
|
||||
if ( mTextWrapMode != value )
|
||||
{
|
||||
mTextWrapMode = value;
|
||||
update();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// TextLineSpacing Property Getter
|
||||
///
|
||||
@@ -415,7 +442,7 @@ namespace glabels
|
||||
|
||||
QTextOption textOption;
|
||||
textOption.setAlignment( mTextHAlign );
|
||||
textOption.setWrapMode( QTextOption::WordWrap );
|
||||
textOption.setWrapMode( mTextWrapMode );
|
||||
|
||||
QFontMetricsF fontMetrics( font );
|
||||
double dy = fontMetrics.lineSpacing() * mTextLineSpacing;
|
||||
@@ -537,7 +564,7 @@ namespace glabels
|
||||
|
||||
QTextOption textOption;
|
||||
textOption.setAlignment( mTextHAlign );
|
||||
textOption.setWrapMode( QTextOption::WordWrap );
|
||||
textOption.setWrapMode( mTextWrapMode );
|
||||
|
||||
QFontMetricsF fontMetrics( font );
|
||||
double dy = fontMetrics.lineSpacing() * mTextLineSpacing;
|
||||
@@ -612,6 +639,10 @@ namespace glabels
|
||||
///
|
||||
void ModelTextObject::drawTextInEditor( QPainter* painter, const QColor& color ) const
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->setClipRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
|
||||
if ( mText.isEmpty() )
|
||||
{
|
||||
QColor mutedColor = color;
|
||||
@@ -627,6 +658,8 @@ namespace glabels
|
||||
{
|
||||
layout->draw( painter, QPointF( 0, 0 ) );
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
@@ -638,6 +671,10 @@ namespace glabels
|
||||
const QColor& color,
|
||||
merge::Record* record ) const
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->setClipRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
|
||||
QFont font;
|
||||
font.setFamily( mFontFamily );
|
||||
font.setPointSizeF( mFontSize );
|
||||
@@ -647,7 +684,7 @@ namespace glabels
|
||||
|
||||
QTextOption textOption;
|
||||
textOption.setAlignment( mTextHAlign );
|
||||
textOption.setWrapMode( QTextOption::WordWrap );
|
||||
textOption.setWrapMode( mTextWrapMode );
|
||||
|
||||
QFontMetricsF fontMetrics( font );
|
||||
double dy = fontMetrics.lineSpacing() * mTextLineSpacing;
|
||||
@@ -684,7 +721,7 @@ namespace glabels
|
||||
double h = boundingRect.height();
|
||||
|
||||
|
||||
// Pass #2 -- adjust layout positions for vertical alignment and create hover path
|
||||
// Pass #2 -- adjust layout positions for vertical alignment
|
||||
x = marginPts;
|
||||
switch ( mTextVAlign )
|
||||
{
|
||||
@@ -717,6 +754,8 @@ namespace glabels
|
||||
|
||||
// Cleanup
|
||||
qDeleteAll( layouts );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+41
-32
@@ -46,26 +46,27 @@ namespace glabels
|
||||
public:
|
||||
ModelTextObject();
|
||||
|
||||
ModelTextObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const QString& text,
|
||||
const QString& fontFamily,
|
||||
double fontSize,
|
||||
QFont::Weight fontWeight,
|
||||
bool fontItalicFlag,
|
||||
bool fontUnderlineFlag,
|
||||
ColorNode textColorNode,
|
||||
Qt::Alignment textHAlign,
|
||||
Qt::Alignment textVAlign,
|
||||
double textLineSpacing,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
bool shadowState = false,
|
||||
const Distance& shadowX = 0,
|
||||
const Distance& shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
ModelTextObject( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const QString& text,
|
||||
const QString& fontFamily,
|
||||
double fontSize,
|
||||
QFont::Weight fontWeight,
|
||||
bool fontItalicFlag,
|
||||
bool fontUnderlineFlag,
|
||||
ColorNode textColorNode,
|
||||
Qt::Alignment textHAlign,
|
||||
Qt::Alignment textVAlign,
|
||||
QTextOption::WrapMode textWrapMode,
|
||||
double textLineSpacing,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
bool shadowState = false,
|
||||
const Distance& shadowX = 0,
|
||||
const Distance& shadowY = 0,
|
||||
double shadowOpacity = 1.0,
|
||||
const ColorNode& shadowColorNode = ColorNode() );
|
||||
|
||||
ModelTextObject( const ModelTextObject* object );
|
||||
|
||||
@@ -145,6 +146,13 @@ namespace glabels
|
||||
void setTextVAlign( Qt::Alignment value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textWrapMode
|
||||
//
|
||||
QTextOption::WrapMode textWrapMode() const override;
|
||||
void setTextWrapMode( QTextOption::WrapMode value ) override;
|
||||
|
||||
|
||||
//
|
||||
// Text Property: textLineSpacing
|
||||
//
|
||||
@@ -189,19 +197,20 @@ namespace glabels
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
RawText mText;
|
||||
QString mFontFamily;
|
||||
double mFontSize;
|
||||
QFont::Weight mFontWeight;
|
||||
bool mFontItalicFlag;
|
||||
bool mFontUnderlineFlag;
|
||||
ColorNode mTextColorNode;
|
||||
Qt::Alignment mTextHAlign;
|
||||
Qt::Alignment mTextVAlign;
|
||||
double mTextLineSpacing;
|
||||
RawText mText;
|
||||
QString mFontFamily;
|
||||
double mFontSize;
|
||||
QFont::Weight mFontWeight;
|
||||
bool mFontItalicFlag;
|
||||
bool mFontUnderlineFlag;
|
||||
ColorNode mTextColorNode;
|
||||
Qt::Alignment mTextHAlign;
|
||||
Qt::Alignment mTextVAlign;
|
||||
QTextOption::WrapMode mTextWrapMode;
|
||||
double mTextLineSpacing;
|
||||
|
||||
QList<QTextLayout*> mEditorLayouts;
|
||||
QPainterPath mHoverPath;
|
||||
QList<QTextLayout*> mEditorLayouts;
|
||||
QPainterPath mHoverPath;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -341,6 +341,7 @@ namespace glabels
|
||||
XmlUtil::setDoubleAttr( node, "line_spacing", object->textLineSpacing() );
|
||||
XmlUtil::setAlignmentAttr( node, "align", object->textHAlign() );
|
||||
XmlUtil::setAlignmentAttr( node, "valign", object->textVAlign() );
|
||||
XmlUtil::setWrapModeAttr( node, "wrap", object->textWrapMode() );
|
||||
|
||||
/* affine attrs */
|
||||
createAffineAttrs( node, object );
|
||||
|
||||
@@ -629,9 +629,10 @@ namespace glabels
|
||||
bool fontUnderlineFlag = XmlUtil::getBoolAttr( node, "font_underline", false );
|
||||
|
||||
/* text attrs */
|
||||
double textLineSpacing = XmlUtil::getDoubleAttr( node, "line_spacing", 1 );
|
||||
Qt::Alignment textHAlign = XmlUtil::getAlignmentAttr( node, "align", Qt::AlignLeft );
|
||||
Qt::Alignment textVAlign = XmlUtil::getAlignmentAttr( node, "valign", Qt::AlignTop );
|
||||
double textLineSpacing = XmlUtil::getDoubleAttr( node, "line_spacing", 1 );
|
||||
Qt::Alignment textHAlign = XmlUtil::getAlignmentAttr( node, "align", Qt::AlignLeft );
|
||||
Qt::Alignment textVAlign = XmlUtil::getAlignmentAttr( node, "valign", Qt::AlignTop );
|
||||
QTextOption::WrapMode textWrapMode = XmlUtil::getWrapModeAttr( node, "wrap", QTextOption::WordWrap );
|
||||
|
||||
/* affine attrs */
|
||||
double a[6];
|
||||
@@ -680,7 +681,7 @@ namespace glabels
|
||||
return new ModelTextObject( x0, y0, w, h,
|
||||
text,
|
||||
fontFamily, fontSize, fontWeight, fontItalicFlag, fontUnderlineFlag,
|
||||
textColorNode, textHAlign, textVAlign, textLineSpacing,
|
||||
textColorNode, textHAlign, textVAlign, textWrapMode, textLineSpacing,
|
||||
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
|
||||
}
|
||||
|
||||
@@ -298,6 +298,33 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
QTextOption::WrapMode XmlUtil::getWrapModeAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
QTextOption::WrapMode default_value )
|
||||
{
|
||||
init();
|
||||
|
||||
QString valueString = node.attribute( name, "" );
|
||||
if ( valueString != "" )
|
||||
{
|
||||
if ( valueString == "word" )
|
||||
{
|
||||
return QTextOption::WordWrap;
|
||||
}
|
||||
else if ( valueString == "anywhere" )
|
||||
{
|
||||
return QTextOption::WrapAnywhere;
|
||||
}
|
||||
else if ( valueString == "none" )
|
||||
{
|
||||
return QTextOption::NoWrap;
|
||||
}
|
||||
}
|
||||
|
||||
return default_value;
|
||||
}
|
||||
|
||||
|
||||
void XmlUtil::setStringAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
const QString& value )
|
||||
@@ -406,5 +433,28 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
void XmlUtil::setWrapModeAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
QTextOption::WrapMode value )
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case QTextOption::WordWrap:
|
||||
node.setAttribute( name, "word" );
|
||||
break;
|
||||
case QTextOption::WrapAnywhere:
|
||||
node.setAttribute( name, "anywhere" );
|
||||
break;
|
||||
case QTextOption::NoWrap:
|
||||
case QTextOption::ManualWrap:
|
||||
node.setAttribute( name, "none" );
|
||||
break;
|
||||
default:
|
||||
node.setAttribute( name, "word" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <QFont>
|
||||
#include <QString>
|
||||
#include <Qt>
|
||||
#include <QTextOption>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -86,6 +87,10 @@ namespace glabels
|
||||
const QString& name,
|
||||
Qt::Alignment default_value );
|
||||
|
||||
static QTextOption::WrapMode getWrapModeAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
QTextOption::WrapMode default_value );
|
||||
|
||||
|
||||
static void setStringAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
@@ -119,6 +124,10 @@ namespace glabels
|
||||
const QString& name,
|
||||
Qt::Alignment value );
|
||||
|
||||
static void setWrapModeAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
QTextOption::WrapMode value );
|
||||
|
||||
|
||||
private:
|
||||
Units mUnits;
|
||||
|
||||
Reference in New Issue
Block a user