Fixed the color issue on text item when modifying the text size

preferencesAboutTextFull
Didier Clerc 11 years ago committed by Claudio Valerio
parent 552de9966b
commit e9f745b113
  1. 1
      src/domain/UBGraphicsTextItem.cpp
  2. 11
      src/domain/UBGraphicsTextItemDelegate.cpp

@ -61,7 +61,6 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) :
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);

@ -367,8 +367,6 @@ void UBGraphicsTextItemDelegate::ChangeTextSize(qreal factor, textChangeMode cha
int startPos = qMin(cursor.anchor(), cursor.position()); int startPos = qMin(cursor.anchor(), cursor.position());
int endPos = qMax(cursor.anchor(), cursor.position()); int endPos = qMax(cursor.anchor(), cursor.position());
qDebug() << "start: " << startPos << ", stop: " << endPos;
QFont curFont; QFont curFont;
QFont nextCharFont; QFont nextCharFont;
bool bEndofTheSameBlock; bool bEndofTheSameBlock;
@ -376,6 +374,8 @@ void UBGraphicsTextItemDelegate::ChangeTextSize(qreal factor, textChangeMode cha
int iPointSize; int iPointSize;
int iNextPointSize; int iNextPointSize;
int iCursorPos = startPos; int iCursorPos = startPos;
QBrush curBrush;
QBrush nextCharBrush;
// we search continuous blocks of the text with the same PointSize and allpy new settings for them. // we search continuous blocks of the text with the same PointSize and allpy new settings for them.
cursor.setPosition (startPos, QTextCursor::MoveAnchor); cursor.setPosition (startPos, QTextCursor::MoveAnchor);
@ -387,6 +387,7 @@ void UBGraphicsTextItemDelegate::ChangeTextSize(qreal factor, textChangeMode cha
// Here we get the point size of the first character // Here we get the point size of the first character
cursor.setPosition (iCursorPos+1, QTextCursor::KeepAnchor); cursor.setPosition (iCursorPos+1, QTextCursor::KeepAnchor);
curFont = cursor.charFormat().font(); curFont = cursor.charFormat().font();
curBrush = cursor.charFormat().foreground();
iPointSize = curFont.pointSize(); iPointSize = curFont.pointSize();
// Then we position the end cursor to the start cursor position // Then we position the end cursor to the start cursor position
@ -397,9 +398,10 @@ void UBGraphicsTextItemDelegate::ChangeTextSize(qreal factor, textChangeMode cha
// Get the next character font size // Get the next character font size
cursor.setPosition (iCursorPos+iBlockLen+1, QTextCursor::KeepAnchor); cursor.setPosition (iCursorPos+iBlockLen+1, QTextCursor::KeepAnchor);
nextCharFont = cursor.charFormat().font(); nextCharFont = cursor.charFormat().font();
nextCharBrush = cursor.charFormat().foreground();
iNextPointSize = nextCharFont.pointSize(); iNextPointSize = nextCharFont.pointSize();
if ((iPointSize != iNextPointSize)||(iCursorPos+iBlockLen >= endPos)||(0 != curFont.family().compare(nextCharFont.family()))){ if ((iPointSize != iNextPointSize)||(iCursorPos+iBlockLen >= endPos)||(0 != curFont.family().compare(nextCharFont.family()))||(curBrush != nextCharBrush)){
bEndofTheSameBlock = true; bEndofTheSameBlock = true;
break; break;
} }
@ -409,11 +411,12 @@ void UBGraphicsTextItemDelegate::ChangeTextSize(qreal factor, textChangeMode cha
}while(!bEndofTheSameBlock); }while(!bEndofTheSameBlock);
//setting new parameners //setting new parameters
QFont tmpFont = curFont; QFont tmpFont = curFont;
int iNewPointSize = (changeSize == changeMode) ? (iPointSize + factor) : (iPointSize * factor); int iNewPointSize = (changeSize == changeMode) ? (iPointSize + factor) : (iPointSize * factor);
tmpFont.setPointSize( (iNewPointSize > 0)?iNewPointSize:1); tmpFont.setPointSize( (iNewPointSize > 0)?iNewPointSize:1);
textFormat.setFont(tmpFont); textFormat.setFont(tmpFont);
textFormat.setForeground(curBrush);
cursor.setPosition (iCursorPos+iBlockLen, QTextCursor::KeepAnchor); cursor.setPosition (iCursorPos+iBlockLen, QTextCursor::KeepAnchor);
cursor.setCharFormat(textFormat); cursor.setCharFormat(textFormat);

Loading…
Cancel
Save