#ifndef NOTEWINDOW_H
#define NOTEWINDOW_H
#include <QWidget>
#include <QTextEdit>
#include <QPushButton>
#include <QJSEngine>
#include <QCloseEvent>
#include <QSyntaxHighlighter>
#include <QTextCharFormat>
#include <QRegularExpression>
#include "ConfigManager.h"
class WedgeHighlighter : public QSyntaxHighlighter {
public:
WedgeHighlighter(QTextDocument *parent, const QColor &focusColor)
: QSyntaxHighlighter(parent), m_focusColor(focusColor) {}
void setFocusColor(const QColor &color) { m_focusColor = color; rehighlight(); }
protected:
void highlightBlock(const QString &text) override {
static QRegularExpression boldRegex("^.*!$");
if (boldRegex.match(text).hasMatch()) {
QTextCharFormat format;
format.setFontWeight(QFont::Bold);
format.setForeground(m_focusColor);
setFormat(0, text.length(), format);
}
static QRegularExpression italicRegex("^.*\\?$");
if (italicRegex.match(text).hasMatch()) {
QTextCharFormat format;
format.setFontItalic(true);
setFormat(0, text.length(), format);
}
static QRegularExpression underlineRegex("^\\s*([^\\s].*\\*)$");
QRegularExpressionMatch uMatch = underlineRegex.match(text);
if (uMatch.hasMatch()) {
QTextCharFormat uFormat;
uFormat.setFontUnderline(true);
int startPos = uMatch.capturedStart(1);
int length = uMatch.capturedLength(1);
setFormat(startPos, length, uFormat);
}
static QRegularExpression strikethruRegex("^\\s*([^\\s].*~)$");
QRegularExpressionMatch sMatch = strikethruRegex.match(text);
if (sMatch.hasMatch()) {
QTextCharFormat sFormat;
sFormat.setFontStrikeOut(true);
int startPos = sMatch.capturedStart(1);
int length = sMatch.capturedLength(1);
setFormat(startPos, length, sFormat);
}
}
private:
QColor m_focusColor;
};
class NoteWindow : public QWidget {
Q_OBJECT
public:
explicit NoteWindow(QWidget *parent = nullptr);
protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void closeEvent(QCloseEvent *event) override;
bool eventFilter(QObject *obj, QEvent *event) override;
private slots:
void openSettings();
void updateAppearance();
private:
void setupUi();
void loadData();
bool handleCalculation(int key);
void refreshDates();
QString getOtcDateResult(int day, QString mon);
QTextEdit *editor;
WedgeHighlighter *highlighter;
QPushButton *settingsBtn;
QJSEngine mathEngine;
NoteData currentData;
QPoint dragPosition;
bool isInitialized = false;
};
#endif