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