Improve the style picker

This commit is contained in:
James Graham
2025-10-27 18:10:13 +00:00
parent c128450cf5
commit 11bf741554
11 changed files with 369 additions and 98 deletions

View File

@@ -33,6 +33,7 @@ target_sources(LibNeoChat PRIVATE
enums/pushrule.h
enums/roomsortparameter.cpp
enums/roomsortorder.h
enums/textstyle.h
enums/timelinemarkreadcondition.h
events/imagepackevent.cpp
events/pollevent.cpp

View File

@@ -29,6 +29,7 @@
#include "chatbartype.h"
#include "chatdocumenthandler_logging.h"
#include "eventhandler.h"
#include "textstyle.h"
using namespace Qt::StringLiterals;
@@ -1027,12 +1028,12 @@ int ChatDocumentHandler::currentListStyle() const
return -textCursor().currentList()->format().style();
}
ChatDocumentHandler::Style ChatDocumentHandler::style() const
TextStyle::Style ChatDocumentHandler::style() const
{
return static_cast<Style>(textCursor().blockFormat().headingLevel());
return static_cast<TextStyle::Style>(textCursor().blockFormat().headingLevel());
}
void ChatDocumentHandler::setStyle(ChatDocumentHandler::Style style)
void ChatDocumentHandler::setStyle(TextStyle::Style style)
{
const int headingLevel = style <= 6 ? style : 0;
// Apparently, 5 is maximum for FontSizeAdjustment; otherwise level=1 and

View File

@@ -12,6 +12,7 @@
#include "chatbarcache.h"
#include "enums/chatbartype.h"
#include "enums/textstyle.h"
#include "models/completionmodel.h"
#include "neochatroom.h"
#include "nestedlisthelper_p.h"
@@ -110,7 +111,7 @@ class ChatDocumentHandler : public QObject
Q_PROPERTY(bool underline READ underline WRITE setUnderline NOTIFY formatChanged)
Q_PROPERTY(bool strikethrough READ strikethrough WRITE setStrikethrough NOTIFY formatChanged)
Q_PROPERTY(ChatDocumentHandler::Style style READ style WRITE setStyle NOTIFY styleChanged)
Q_PROPERTY(TextStyle::Style style READ style WRITE setStyle NOTIFY styleChanged)
// Q_PROPERTY(bool canIndentList READ canIndentList NOTIFY cursorPositionChanged)
// Q_PROPERTY(bool canDedentList READ canDedentList NOTIFY cursorPositionChanged)
@@ -132,25 +133,6 @@ public:
End,
};
/**
* @brief Enum to define available styles.
*
* @note The Paragraph and Heading values are intentially fixed to match heading
* level values returned by QTextBlockFormat::headingLevel().
*
* @sa QTextBlockFormat::headingLevel()
*/
enum Style {
Paragraph = 0,
Heading1 = 1,
Heading2 = 2,
Heading3 = 3,
Heading4 = 4,
Heading5 = 5,
Heading6 = 6,
};
Q_ENUM(Style);
explicit ChatDocumentHandler(QObject *parent = nullptr);
ChatBarType::Type type() const;
@@ -218,8 +200,8 @@ public:
bool canDedentList() const;
int currentListStyle() const;
Style style() const;
void setStyle(Style style);
TextStyle::Style style() const;
void setStyle(TextStyle::Style style);
// bool list() const;
// void setList(bool list);

View File

@@ -0,0 +1,74 @@
// SPDX-FileCopyrightText: 2025 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#pragma once
#include <QObject>
#include <QQmlEngine>
using namespace Qt::StringLiterals;
/**
* @class TextStyle
*
* A class with the Style enum for available text styles.
*/
class TextStyle : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("")
public:
/**
* @brief Enum to define available styles.
*
* @note The Paragraph and Heading values are intentially fixed to match heading
* level values returned by QTextBlockFormat::headingLevel().
*
* @sa QTextBlockFormat::headingLevel()
*/
enum Style {
Paragraph = 0,
Heading1 = 1,
Heading2 = 2,
Heading3 = 3,
Heading4 = 4,
Heading5 = 5,
Heading6 = 6,
Code = 7,
Quote = 8,
};
Q_ENUM(Style);
/**
* @brief Translate the Kind enum value to a human readable string.
*
* @sa Kind
*/
static QString styleString(Style style)
{
switch (style) {
case Style::Paragraph:
return u"Paragraph"_s;
case Style::Heading1:
return u"Heading 1"_s;
case Style::Heading2:
return u"Heading 2"_s;
case Style::Heading3:
return u"Heading 3"_s;
case Style::Heading4:
return u"Heading 4"_s;
case Style::Heading5:
return u"Heading 5"_s;
case Style::Heading6:
return u"Heading 6"_s;
case Style::Code:
return u"Code"_s;
case Style::Quote:
return u"\"Quote\""_s;
default:
return {};
}
};
};