Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fb2code.hpp « source - github.com/lintest/fb2edit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2aeb730969578dee3b75cca0578073a28d6ea468 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef FB2CODE_H
#define FB2CODE_H

#include <QByteArray>
#include <QObject>
#include <QPlainTextEdit>
#include <QTextCharFormat>
#include <QColor>
#include <QTextEdit>
#include <QToolBar>

#include "fb2mode.h"

QT_BEGIN_NAMESPACE
class QPaintEvent;
class QResizeEvent;
class QSize;
class QWidget;
QT_END_NAMESPACE

class FbCodeEdit : public QPlainTextEdit
{
    Q_OBJECT

public:
    FbCodeEdit(QWidget *parent = 0);

    QAction * act(Fb::Actions index) const;
    void setAction(Fb::Actions index, QAction *action);
    void connectActions(QToolBar *tool);
    void disconnectActions();

    QString text() const { return toPlainText(); }

    bool read(QIODevice *device);

    void load(const QByteArray data)
        { setPlainText(QString::fromUtf8(data.data())); }

    bool findText(const QString &exp, QTextDocument::FindFlags options = {});

    bool isModified() const { return document()->isModified(); }

    void setCursor(int line, int column);

signals:
    void status(const QString &text);

protected:
    void resizeEvent(QResizeEvent *event);

private slots:
    void clipboardDataChanged();
    void updateLineNumberAreaWidth(int newBlockCount);
    void highlightCurrentLine();
    void updateLineNumberArea(const QRect &, int);
    void find();
    void validate();
    void zoomIn();
    void zoomOut();
    void zoomReset();

private:
    class LineNumberArea : public QWidget
    {
    public:
        LineNumberArea(FbCodeEdit *parent) : QWidget(parent) { editor = parent; }
        QSize sizeHint() const { return QSize(editor->lineNumberAreaWidth(), 0); }
    protected:
        void paintEvent(QPaintEvent *event) { editor->lineNumberAreaPaintEvent(event); }
    private:
        FbCodeEdit *editor;
    };

private:
    void lineNumberAreaPaintEvent(QPaintEvent *event);
    int lineNumberAreaWidth();
    void setZoomRatio(qreal ratio);

private:
    QWidget *lineNumberArea;
    FbActionMap m_actions;
    qreal zoomRatio;
    static qreal baseFontSize;
    static qreal zoomRatioMin;
    static qreal zoomRatioMax;
    friend class FbCodeEdit::LineNumberArea;
};

#endif // FB2CODE_H