Pith - wedge_linux
wedge_linux/NoteWindow.h [2.8 kb]
Modified: 19:02:33 69 026 (27 May 026)
3 Days Ago
#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
Updates
Shim - Android 70.026.1
Wedge - Linux 68.026.1
Wedge - Android 68.026.1
Taper - Linux 64.026.1
Ayh Extension - Chrome 63.026.1
Dev
TVShow (227) 'CSA'
TVShow (228) 'APT'
TVProgram (83) 'BXT'
Miter Update(s)
Shim (Dictation)

Menu
Calendar
Project Tin (024/029)
Miter
RSS Feed
User Avatar
@vgmlr
=SUM(parts)