initial upload

This commit is contained in:
2023-11-15 20:54:49 +01:00
parent b90a34c4b4
commit 99dad98ce0
29 changed files with 1277 additions and 0 deletions

27
include/addlinkdialog.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef ADDLINKDIALOG_H
#define ADDLINKDIALOG_H
#include "ui_addlinkdialog.h"
#include "richtexteditor.h"
#include <QDialog>
class AddLinkDialog : public QDialog
{
Q_OBJECT
public:
AddLinkDialog(RichTextEditor *editor, QWidget *parent = nullptr);
~AddLinkDialog() override;
int showDialog();
public Q_SLOTS:
void accept() override;
private:
RichTextEditor *m_editor;
QT_PREPEND_NAMESPACE(Ui)::AddLinkDialog *m_ui;
};
#endif // ADDLINKDIALOG_H

26
include/coloraction.h Normal file
View File

@@ -0,0 +1,26 @@
#ifndef COLORACTION_H
#define COLORACTION_H
#include <QAction>
#include <QColor>
class ColorAction : public QAction
{
Q_OBJECT
public:
ColorAction(QObject *parent);
const QColor& color() const { return m_color; }
void setColor(const QColor &color);
Q_SIGNALS:
void colorChanged(const QColor &color);
private Q_SLOTS:
void chooseColor();
private:
QColor m_color;
};
#endif // COLORACTION_H

43
include/htmlhighlighter.h Normal file
View File

@@ -0,0 +1,43 @@
#ifndef HTMLHIGHLIGHTER_H
#define HTMLHIGHLIGHTER_H
#include <QSyntaxHighlighter>
#include <QTextCharFormat>
#include <QTextEdit>
/* HTML syntax highlighter based on Qt Quarterly example */
class HtmlHighlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
enum Construct {
Entity,
Tag,
Comment,
Attribute,
Value,
LastConstruct = Value
};
HtmlHighlighter(QTextEdit *textEdit);
void setFormatFor(Construct construct, const QTextCharFormat &format);
QTextCharFormat formatFor(Construct construct) const
{ return m_formats[construct]; }
protected:
enum State {
NormalState = -1,
InComment,
InTag
};
void highlightBlock(const QString &text) override;
private:
QTextCharFormat m_formats[LastConstruct + 1];
};
#endif // HTMLHIGHLIGHTER_H

23
include/htmltextedit.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef HTMLTEXTEDIT_H
#define HTMLTEXTEDIT_H
#include <QTextEdit>
#include <QAction>
#include <QContextMenuEvent>
class HtmlTextEdit : public QTextEdit
{
Q_OBJECT
public:
HtmlTextEdit(QWidget *parent = nullptr)
: QTextEdit(parent)
{}
void contextMenuEvent(QContextMenuEvent *event) override;
private slots:
void actionTriggered(QAction *action);
};
#endif // HTMLTEXTEDIT_H

34
include/richtexteditor.h Normal file
View File

@@ -0,0 +1,34 @@
#ifndef RICHTEXTEDITOR_H
#define RICHTEXTEDITOR_H
#include <QTextEdit>
#include <QToolBar>
class RichTextEditor : public QTextEdit
{
Q_OBJECT
public:
explicit RichTextEditor(QWidget *parent = nullptr);
void setDefaultFont(QFont font);
QToolBar *createToolBar(QWidget *parent = nullptr);
QString text(Qt::TextFormat format) const;
bool simplifyRichText() const { return m_simplifyRichText; }
public Q_SLOTS:
void setFontBold(bool b);
void setFontPointSize(double);
void setText(const QString &text);
void setSimplifyRichText(bool v);
Q_SIGNALS:
void stateChanged();
void simplifyRichTextChanged(bool);
private:
bool m_simplifyRichText;
};
#endif // RICHTEXTEDITOR_H

View File

@@ -0,0 +1,37 @@
#ifndef RICHTEXTEDITORDIALOG_H
#define RICHTEXTEDITORDIALOG_H
#include "richtexteditor.h"
#include <QDialog>
#include <QTextEdit>
#include <QTabWidget>
class RichTextEditorDialog : public QDialog
{
Q_OBJECT
public:
explicit RichTextEditorDialog(QWidget *parent = nullptr);
~RichTextEditorDialog();
int showDialog();
void setDefaultFont(const QFont &font);
void setText(const QString &text);
QString text(Qt::TextFormat format = Qt::AutoText) const;
private Q_SLOTS:
void tabIndexChanged(int newIndex);
void richTextChanged();
void sourceChanged();
private:
enum TabIndex { RichTextIndex, SourceIndex };
enum State { Clean, RichTextChanged, SourceChanged };
RichTextEditor *m_editor;
QTextEdit *m_text_edit;
QTabWidget *m_tab_widget;
State m_state;
int m_initialTab;
};
#endif // RICHTEXTEDITORDIALOG_H

View File

@@ -0,0 +1,57 @@
#ifndef RICHTEXTEDITORTOOLBAR_H
#define RICHTEXTEDITORTOOLBAR_H
#include "richtexteditor.h"
#include "coloraction.h"
#include <QToolBar>
#include <QComboBox>
#include <QFontComboBox>
#include <QPointer>
#include <QAction>
QIcon createIconSet(const QString &name);
class RichTextEditorToolBar : public QToolBar
{
Q_OBJECT
public:
RichTextEditorToolBar(RichTextEditor *editor,
QWidget *parent = nullptr);
public Q_SLOTS:
void updateActions();
private Q_SLOTS:
void alignmentActionTriggered(QAction *action);
void sizeInputActivated(const QString &size);
void fontFamilyActivated(const QString &font);
void colorChanged(const QColor &color);
void setVAlignSuper(bool super);
void setVAlignSub(bool sub);
void insertLink();
void insertImage();
void layoutDirectionChanged();
private:
QAction *m_bold_action;
QAction *m_italic_action;
QAction *m_underline_action;
QAction *m_valign_sup_action;
QAction *m_valign_sub_action;
QAction *m_align_left_action;
QAction *m_align_center_action;
QAction *m_align_right_action;
QAction *m_align_justify_action;
QAction *m_layoutDirectionAction;
QAction *m_link_action;
QAction *m_image_action;
QAction *m_simplify_richtext_action;
ColorAction *m_color_action;
QComboBox *m_font_size_input;
QFontComboBox *m_font_family_input;
QPointer<RichTextEditor> m_editor;
};
#endif // RICHTEXTEDITORTOOLBAR_H