fixed a bug where by calling createDefaultFont at every UBGraphicsTextItem instanciation, some fonts styles could be overridden

preferencesAboutTextFull
Clément Fauconnier 3 years ago
parent 8216d2e9c6
commit 22acd9888a
  1. 3
      src/domain/UBGraphicsScene.cpp
  2. 58
      src/domain/UBGraphicsTextItem.cpp
  3. 2
      src/domain/UBGraphicsTextItem.h
  4. 55
      src/domain/UBGraphicsTextItemDelegate.cpp
  5. 1
      src/domain/UBGraphicsTextItemDelegate.h

@ -1934,9 +1934,12 @@ UBGraphicsTextItem* UBGraphicsScene::addTextWithFont(const QString& pString, con
UBGraphicsTextItem *UBGraphicsScene::addTextHtml(const QString &pString, const QPointF& pTopLeft)
{
UBGraphicsTextItem *textItem = new UBGraphicsTextItem();
textItem->setPlainText("");
textItem->setHtml(UBTextTools::cleanHtml(pString));
textItem->initFontProperties();
addItem(textItem);
textItem->show();

@ -81,6 +81,64 @@ UBGraphicsTextItem::~UBGraphicsTextItem()
{
}
void UBGraphicsTextItem::initFontProperties()
{
QTextCursor curCursor = textCursor();
QTextCharFormat format;
QFont font(createDefaultFont());
font.setPointSize(UBSettings::settings()->fontPointSize());
format.setFont(font);
if (UBSettings::settings()->isDarkBackground())
{
if (UBGraphicsTextItem::lastUsedTextColor == Qt::black)
UBGraphicsTextItem::lastUsedTextColor = Qt::white;
}
else
{
if (UBGraphicsTextItem::lastUsedTextColor == Qt::white)
UBGraphicsTextItem::lastUsedTextColor = Qt::black;
}
setDefaultTextColor(UBGraphicsTextItem::lastUsedTextColor);
format.setForeground(QBrush(UBGraphicsTextItem::lastUsedTextColor));
curCursor.mergeCharFormat(format);
setTextCursor(curCursor);
setFont(font);
adjustSize();
contentsChanged();
}
QFont UBGraphicsTextItem::createDefaultFont()
{
QFont font;
QString fFamily = UBSettings::settings()->fontFamily();
if (!fFamily.isEmpty())
font.setFamily(fFamily);
QString fStyleName = UBSettings::settings()->fontStyleName();
if (!fStyleName .isEmpty())
font.setStyleName(fStyleName);
bool bold = UBSettings::settings()->isBoldFont();
if (bold)
font.setWeight(QFont::Bold);
bool italic = UBSettings::settings()->isItalicFont();
if (italic)
font.setItalic(true);
int pointSize = UBSettings::settings()->fontPointSize();
if (pointSize > 0) {
font.setPointSize(pointSize);
}
return font;
}
void UBGraphicsTextItem::recolor()
{
UBGraphicsTextItemDelegate * del = dynamic_cast<UBGraphicsTextItemDelegate*>(Delegate());

@ -100,6 +100,8 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes
void activateTextEditor(bool activate);
void setSelected(bool selected);
void recolor();
void initFontProperties();
QFont createDefaultFont();
QString mTypeTextHereLabel;

@ -110,32 +110,6 @@ UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDele
, delta(5)
{
delegated()->setData(UBGraphicsItemData::ItemEditable, QVariant(true));
delegated()->setPlainText("");
QTextCursor curCursor = delegated()->textCursor();
QTextCharFormat format;
QFont font(createDefaultFont());
font.setPointSize(UBSettings::settings()->fontPointSize());
format.setFont(font);
if (UBSettings::settings()->isDarkBackground())
{
if (UBGraphicsTextItem::lastUsedTextColor == Qt::black)
UBGraphicsTextItem::lastUsedTextColor = Qt::white;
}
else
{
if (UBGraphicsTextItem::lastUsedTextColor == Qt::white)
UBGraphicsTextItem::lastUsedTextColor = Qt::black;
}
delegated()->setDefaultTextColor(UBGraphicsTextItem::lastUsedTextColor);
format.setForeground(QBrush(UBGraphicsTextItem::lastUsedTextColor));
curCursor.mergeCharFormat(format);
delegated()->setTextCursor(curCursor);
delegated()->setFont(font);
delegated()->adjustSize();
delegated()->contentsChanged();
connect(delegated()->document(), SIGNAL(cursorPositionChanged(QTextCursor)), this, SLOT(onCursorPositionChanged(QTextCursor)));
connect(delegated()->document(), SIGNAL(modificationChanged(bool)), this, SLOT(onModificationChanged(bool)));
@ -146,35 +120,6 @@ UBGraphicsTextItemDelegate::~UBGraphicsTextItemDelegate()
// NOOP
}
QFont UBGraphicsTextItemDelegate::createDefaultFont()
{
QFont font;
QString fFamily = UBSettings::settings()->fontFamily();
if (!fFamily.isEmpty())
font.setFamily(fFamily);
QString fStyleName = UBSettings::settings()->fontStyleName();
if (!fStyleName .isEmpty())
font.setStyleName(fStyleName);
bool bold = UBSettings::settings()->isBoldFont();
if (bold)
font.setWeight(QFont::Bold);
bool italic = UBSettings::settings()->isItalicFont();
if (italic)
font.setItalic(true);
int pointSize = UBSettings::settings()->fontPointSize();
if (pointSize > 0) {
font.setPointSize(pointSize);
}
return font;
}
void UBGraphicsTextItemDelegate::createControls()
{
UBGraphicsItemDelegate::createControls();

@ -158,7 +158,6 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
void restoreTextCursorFormats();
QFont createDefaultFont();
QAction *mEditableAction;
struct selectionData_t {
selectionData_t()

Loading…
Cancel
Save