From ea20e6c0a8d9cf18e5546fceaf353ee08a65c4e1 Mon Sep 17 00:00:00 2001 From: Aleksei German Date: Mon, 17 Aug 2020 14:10:01 +0200 Subject: [PATCH] QmlDesigner: Fix for Rich Text Editor - Fixed tables style - Added border around color selector button Task: QDS-2634 Change-Id: I5a164fedaefa87f394c7815a5bb416ec7898417e Reviewed-by: Thomas Hartmann --- .../richtexteditor/richtexteditor.cpp | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/plugins/qmldesigner/components/richtexteditor/richtexteditor.cpp b/src/plugins/qmldesigner/components/richtexteditor/richtexteditor.cpp index af04bb676a4..f0cafc892d3 100644 --- a/src/plugins/qmldesigner/components/richtexteditor/richtexteditor.cpp +++ b/src/plugins/qmldesigner/components/richtexteditor/richtexteditor.cpp @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include @@ -85,6 +87,27 @@ static void cursorEditBlock(QTextCursor& cursor, std::function f) { cursor.endEditBlock(); } +static QPixmap drawColorBox(const QColor& color, const QSize& size, int borderWidth = 4) +{ + if (size.isEmpty()) { + return {}; + } + + QPixmap result(size); + + const QColor borderColor = QApplication::palette("QWidget").color(QPalette::Normal, + QPalette::Button); + + result.fill(color); + QPainter painter(&result); + QPen pen(borderColor); + pen.setWidth(borderWidth); + painter.setPen(pen); + painter.drawRect(QRect(QPoint(0,0), size)); + + return result; +} + RichTextEditor::RichTextEditor(QWidget *parent) : QWidget(parent) , ui(new Ui::RichTextEditor) @@ -214,8 +237,7 @@ void RichTextEditor::fontChanged(const QFont &f) void RichTextEditor::colorChanged(const QColor &c) { - QPixmap colorBox(ui->tableBar->iconSize()); - colorBox.fill(c); + QPixmap colorBox(drawColorBox(c, ui->tableBar->iconSize())); m_actionTextColor->setIcon(colorBox); } @@ -436,8 +458,7 @@ void RichTextEditor::setupListActions() void RichTextEditor::setupFontActions() { - QPixmap colorBox(ui->tableBar->iconSize()); - colorBox.fill(ui->textEdit->textColor()); + QPixmap colorBox(drawColorBox(ui->textEdit->textColor(), ui->tableBar->iconSize())); m_actionTextColor = ui->toolBar->addAction(colorBox, tr("&Color..."), [this]() { QColor col = QColorDialog::getColor(ui->textEdit->textColor(), this); @@ -507,7 +528,17 @@ void RichTextEditor::setupTableActions() m_actionCreateTable = ui->tableBar->addAction(createTableIcon, tr("Create Table"), [this]() { QTextCursor cursor = ui->textEdit->textCursor(); cursorEditBlock(cursor, [&] () { - cursor.insertTable(1,1); + //format table cells to look a bit better: + QTextTableFormat tableFormat; + tableFormat.setBorderCollapse(true); + tableFormat.setCellSpacing(2.0); + tableFormat.setCellPadding(2.0); + tableFormat.setBorder(1.0); + + cursor.insertTable(1, 1, tableFormat); + + //move cursor into the first cell of the table: + ui->textEdit->setTextCursor(cursor); }); }); m_actionCreateTable->setCheckable(false);