Commit fa4acc48 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix various titler bugs (pasting breaks color & font, incorrect selection)

BUG: 374614
parent c27117f0
......@@ -98,6 +98,12 @@ void MyTextItem::updateShadow(bool enabled, int blur, int xoffset, int yoffset,
update();
}
void MyTextItem::setTextColor(const QColor &col)
{
setDefaultTextColor(col);
refreshFormat();
}
QStringList MyTextItem::shadowInfo() const
{
QStringList info;
......@@ -125,24 +131,39 @@ void MyTextItem::setAlignment(Qt::Alignment alignment)
setTextCursor(cursor);
}
void MyTextItem::updateGeometry(int, int, int)
void MyTextItem::refreshFormat()
{
updateGeometry();
// update gradient if necessary
QString gradientData = data(TitleDocument::Gradient).toString();
QTextCursor cursor = textCursor();
QTextCharFormat cformat;
cursor.select(QTextCursor::Document);
int position = textCursor().position();
// Formatting can be lost on paste, since our QTextCursor gets overwritten, so re-apply all formatting here
QColor fgColor = defaultTextColor();
cformat.setForeground(fgColor);
cformat.setFont(font());
if (!gradientData.isEmpty()) {
QTextCursor cursor = textCursor();
QTextCharFormat cformat;
QRectF rect = boundingRect();
int position = textCursor().position();
QLinearGradient gr = GradientWidget::gradientFromString(gradientData, rect.width(), rect.height());
cursor.select(QTextCursor::Document);
cformat.setForeground(QBrush(gr));
cursor.mergeCharFormat(cformat);
cursor.clearSelection();
cursor.setPosition(position); // restore cursor position
setTextCursor(cursor);
}
//Apply
cursor.mergeCharFormat(cformat);
// restore cursor position
cursor.clearSelection();
cursor.setPosition(position);
setTextCursor(cursor);
}
void MyTextItem::updateGeometry(int, int, int)
{
updateGeometry();
// update gradient if necessary
refreshFormat();
QString text = toPlainText();
m_path = QPainterPath();
if (text.isEmpty()) {
......@@ -700,10 +721,12 @@ void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e)
}
QGraphicsScene::mousePressEvent(e);
} else if (m_tool == TITLE_RECTANGLE) {
clearTextSelection();
m_sceneClickPoint = QPointF(xPos, yPos);
m_selectedItem = NULL;
e->ignore();
} else if (m_tool == TITLE_TEXT) {
clearTextSelection();
MyTextItem *textItem = new MyTextItem(i18n("Text"), NULL);
yPos = (((int) e->scenePos().y() - (int)(m_fontSize / 2)) / m_gridSize) * m_gridSize;
textItem->setPos(xPos, yPos);
......
......@@ -59,6 +59,7 @@ public:
QStringList shadowInfo() const;
void loadShadow(QStringList info);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *evt);
void setTextColor(const QColor &col);
protected:
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
......@@ -73,6 +74,7 @@ private:
MyQGraphicsEffect *m_shadowEffect;
void updateShadow();
void blurShadow(QImage &image, int radius);
void refreshFormat();
public slots:
void updateGeometry(int, int, int);
......
......@@ -440,6 +440,7 @@ int TitleDocument::loadFromXml(const QDomDocument& doc, QGraphicsRectItem* start
cursor.setBlockFormat(format);
txt->setData(TitleDocument::LineSpacing, lineSpacing);
}
txt->setTextColor(col);
cformat.setForeground(QBrush(col));
cursor.setCharFormat(cformat);
if (txtProperties.namedItem(QStringLiteral("gradient")).isNull() == false) {
......
......@@ -966,7 +966,7 @@ void TitleWidget::slotNewText(MyTextItem *tt)
tt->setFont(font);
QColor color = fontColorButton->color();
QColor outlineColor = textOutlineColor->color();
tt->setDefaultTextColor(color);
tt->setTextColor(color);
tt->document()->setDocumentMargin(0);
QTextCursor cur(tt->document());
......@@ -1652,7 +1652,7 @@ void TitleWidget::slotUpdateText()
// item->setTextCursor(cur);
cur.clearSelection();
item->setTextCursor(cur);
item->setDefaultTextColor(color);
item->setTextColor(color);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment