Revert to Paragraph format after a heading
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "chattextitemhelper.h"
|
||||
#include "clipboard.h"
|
||||
#include "neochatroom.h"
|
||||
#include "richformat.h"
|
||||
|
||||
ChatKeyHelper::ChatKeyHelper(QObject *parent)
|
||||
: QObject(parent)
|
||||
@@ -184,7 +185,12 @@ bool ChatKeyHelper::insertReturn(Qt::KeyboardModifiers modifiers)
|
||||
if (cursor.isNull()) {
|
||||
return false;
|
||||
}
|
||||
cursor.insertBlock();
|
||||
|
||||
// If there was a heading we always want to revert to Paragraph format.
|
||||
auto newBlockFormat = RichFormat::blockFormatForFormat(RichFormat::Paragraph);
|
||||
auto newCharFormat = cursor.charFormat();
|
||||
newCharFormat.merge(RichFormat::charFormatForFormat(static_cast<RichFormat::Format>(cursor.blockFormat().headingLevel()), true));
|
||||
cursor.insertBlock(newBlockFormat, newCharFormat);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,11 @@ QTextCharFormat RichFormat::charFormatForFormat(Format format, bool invert, cons
|
||||
if (headingLevelForFormat(format) > 0) {
|
||||
// Apparently, 4 is maximum for FontSizeAdjustment; otherwise level=1 and
|
||||
// level=2 look the same
|
||||
charFormat.setProperty(QTextFormat::FontSizeAdjustment, 5 - headingLevelForFormat(format));
|
||||
int fontSizeAdjustment = 0;
|
||||
if (!invert) {
|
||||
fontSizeAdjustment = 5 - headingLevelForFormat(format);
|
||||
}
|
||||
charFormat.setProperty(QTextFormat::FontSizeAdjustment, fontSizeAdjustment);
|
||||
}
|
||||
if (format == Paragraph) {
|
||||
charFormat.setFontWeight(QFont::Normal);
|
||||
|
||||
@@ -39,8 +39,8 @@ public:
|
||||
Heading4 = 4,
|
||||
Heading5 = 5,
|
||||
Heading6 = 6,
|
||||
Quote = 7,
|
||||
Code = 8,
|
||||
Quote,
|
||||
Code,
|
||||
InlineCode,
|
||||
Bold,
|
||||
Italic,
|
||||
|
||||
Reference in New Issue
Block a user