forked from qt-creator/qt-creator
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>
This commit is contained in:
committed by
Thomas Hartmann
parent
aa055e74dc
commit
ea20e6c0a8
@@ -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);
|
||||
|
Reference in New Issue
Block a user