aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksei German <aleksei.german@qt.io>2020-08-17 14:10:01 +0200
committerThomas Hartmann <thomas.hartmann@qt.io>2020-08-27 10:04:41 +0000
commitea20e6c0a8d9cf18e5546fceaf353ee08a65c4e1 (patch)
treeaa508592004f309cbfece38c98f86c4bbef5aacd
parentaa055e74dc30c2f34edaf3e03f47710ac7244ddb (diff)
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 <thomas.hartmann@qt.io>
-rw-r--r--src/plugins/qmldesigner/components/richtexteditor/richtexteditor.cpp41
1 files changed, 36 insertions, 5 deletions
diff --git a/src/plugins/qmldesigner/components/richtexteditor/richtexteditor.cpp b/src/plugins/qmldesigner/components/richtexteditor/richtexteditor.cpp
index af04bb676a..f0cafc892d 100644
--- a/src/plugins/qmldesigner/components/richtexteditor/richtexteditor.cpp
+++ b/src/plugins/qmldesigner/components/richtexteditor/richtexteditor.cpp
@@ -38,6 +38,8 @@
#include <QTextTable>
#include <QScopeGuard>
#include <QPointer>
+#include <QTextTableFormat>
+#include <QPainter>
#include <utils/stylehelper.h>
@@ -85,6 +87,27 @@ static void cursorEditBlock(QTextCursor& cursor, std::function<void()> 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);