reuse last used color for newer text boxes (only if applied globally) + recolor text boxes on background changes (white text becomes black and black text becomes white (like for polygons))

preferencesAboutTextFull
Clément Fauconnier 5 years ago
parent a8fa4b0caa
commit 40c334c144
  1. 2
      src/board/UBBoardController.cpp
  2. 6
      src/domain/UBGraphicsScene.cpp
  3. 9
      src/domain/UBGraphicsTextItem.cpp
  4. 1
      src/domain/UBGraphicsTextItem.h
  5. 107
      src/domain/UBGraphicsTextItemDelegate.cpp
  6. 1
      src/domain/UBGraphicsTextItemDelegate.h

@ -1589,7 +1589,7 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
if(documentChange) if(documentChange)
{ {
UBGraphicsTextItem::lastUsedTextColor = QColor(); UBGraphicsTextItem::lastUsedTextColor = QColor(Qt::black);
} }
if (sceneChange) if (sceneChange)

@ -1179,6 +1179,12 @@ void UBGraphicsScene::recolorAllItems()
curGroup->setColor(newColor); curGroup->setColor(newColor);
} }
} }
if (item->type() == UBGraphicsTextItem::Type)
{
UBGraphicsTextItem *textItem = static_cast<UBGraphicsTextItem*>(item);
textItem->recolor();
}
} }
foreach(QGraphicsView* view, views()) foreach(QGraphicsView* view, views())

@ -41,7 +41,7 @@
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "core/memcheck.h" #include "core/memcheck.h"
QColor UBGraphicsTextItem::lastUsedTextColor; QColor UBGraphicsTextItem::lastUsedTextColor = QColor(Qt::black);
UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent)
: QGraphicsTextItem(parent) : QGraphicsTextItem(parent)
@ -81,6 +81,13 @@ UBGraphicsTextItem::~UBGraphicsTextItem()
{ {
} }
void UBGraphicsTextItem::recolor()
{
UBGraphicsTextItemDelegate * del = dynamic_cast<UBGraphicsTextItemDelegate*>(Delegate());
if (del)
del->recolor();
}
void UBGraphicsTextItem::setSelected(bool selected) void UBGraphicsTextItem::setSelected(bool selected)
{ {
if(selected){ if(selected){

@ -99,6 +99,7 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes
virtual void setUuid(const QUuid &pUuid); virtual void setUuid(const QUuid &pUuid);
void activateTextEditor(bool activate); void activateTextEditor(bool activate);
void setSelected(bool selected); void setSelected(bool selected);
void recolor();
QString mTypeTextHereLabel; QString mTypeTextHereLabel;

@ -115,9 +115,21 @@ UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDele
QTextCursor curCursor = delegated()->textCursor(); QTextCursor curCursor = delegated()->textCursor();
QTextCharFormat format; QTextCharFormat format;
QFont font(createDefaultFont()); QFont font(createDefaultFont());
font.setPointSize(UBSettings::settings()->fontPointSize());
font.setPointSize(UBSettings::settings()->fontPointSize());
format.setFont(font); 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); curCursor.mergeCharFormat(format);
delegated()->setTextCursor(curCursor); delegated()->setTextCursor(curCursor);
delegated()->setFont(font); delegated()->setFont(font);
@ -368,12 +380,14 @@ void UBGraphicsTextItemDelegate::pickColor()
QColor selectedColor = colorDialog.selectedColor(); QColor selectedColor = colorDialog.selectedColor();
delegated()->setDefaultTextColor(selectedColor); delegated()->setDefaultTextColor(selectedColor);
QTextCursor curCursor = delegated()->textCursor(); QTextCursor curCursor = delegated()->textCursor();
QTextCharFormat format; QTextCharFormat format;
format.setForeground(QBrush(selectedColor)); format.setForeground(QBrush(selectedColor));
curCursor.mergeCharFormat(format); curCursor.mergeCharFormat(format);
delegated()->setTextCursor(curCursor); delegated()->setTextCursor(curCursor);
UBGraphicsTextItem::lastUsedTextColor = selectedColor; if (!curCursor.hasComplexSelection())
UBGraphicsTextItem::lastUsedTextColor = selectedColor;
delegated()->setSelected(true); delegated()->setSelected(true);
delegated()->document()->adjustSize(); delegated()->document()->adjustSize();
@ -673,6 +687,95 @@ void UBGraphicsTextItemDelegate::ChangeTextSize(qreal factor, textChangeMode cha
delegated()->setTextCursor(cursor); delegated()->setTextCursor(cursor);
} }
void UBGraphicsTextItemDelegate::recolor()
{
QTextCursor cursor = delegated()->textCursor();
QTextCharFormat textFormat;
int anchorPos = cursor.anchor();
int cursorPos = cursor.position();
if (0 == anchorPos-cursorPos)
{
// If nothing is selected, then we select all the text
cursor.setPosition (0, QTextCursor::MoveAnchor);
cursor.setPosition (cursor.document()->characterCount()-1, QTextCursor::KeepAnchor);
}
int startPos = qMin(cursor.anchor(), cursor.position());
int endPos = qMax(cursor.anchor(), cursor.position());
QFont curFont;
QFont nextCharFont;
bool bEndofTheSameBlock;
int iBlockLen;
int iCursorPos = startPos;
QBrush curBrush;
QBrush nextCharBrush;
cursor.setPosition (startPos, QTextCursor::MoveAnchor);
while(iCursorPos < endPos)
{
bEndofTheSameBlock = false;
iBlockLen = 0;
// Here we get the point size of the first character
cursor.setPosition (iCursorPos+1, QTextCursor::KeepAnchor);
curBrush = cursor.charFormat().foreground();
// Then we position the end cursor to the start cursor position
cursor.setPosition (iCursorPos, QTextCursor::KeepAnchor);
do
{
cursor.setPosition (iCursorPos+iBlockLen+1, QTextCursor::KeepAnchor);
nextCharBrush = cursor.charFormat().foreground();
if (curBrush != nextCharBrush || (iCursorPos+iBlockLen >= endPos))
{
bEndofTheSameBlock = true;
break;
}
iBlockLen++;
}while(!bEndofTheSameBlock);
//setting new parameters
if (UBSettings::settings()->isDarkBackground())
{
if (curBrush.color() == Qt::black)
{
curBrush = QBrush(Qt::white);
}
}
else
{
if (curBrush.color() == Qt::white)
{
curBrush = QBrush(Qt::black);
}
}
cursor.setPosition (iCursorPos+iBlockLen, QTextCursor::KeepAnchor);
textFormat.setForeground(curBrush);
cursor.mergeCharFormat(textFormat);
iCursorPos += iBlockLen;
cursor.setPosition (iCursorPos, QTextCursor::MoveAnchor);
curFont = nextCharFont;
}
delegated()->setFont(curFont);
//returning initial selection
cursor.setPosition (anchorPos, QTextCursor::MoveAnchor);
cursor.setPosition (cursorPos, QTextCursor::KeepAnchor);
delegated()->setTextCursor(cursor);
}
void UBGraphicsTextItemDelegate::updateAlighButtonState() void UBGraphicsTextItemDelegate::updateAlighButtonState()
{ {
if (!mAlignButton) { if (!mAlignButton) {

@ -112,6 +112,7 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
virtual ~UBGraphicsTextItemDelegate(); virtual ~UBGraphicsTextItemDelegate();
bool isEditable(); bool isEditable();
void scaleTextSize(qreal multiplyer); void scaleTextSize(qreal multiplyer);
void recolor();
virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
virtual void createControls(); virtual void createControls();
qreal titleBarWidth(); qreal titleBarWidth();

Loading…
Cancel
Save