[44] | 1 | #ifndef DECKTEXTEDITOR_H |
---|
| 2 | #define DECKTEXTEDITOR_H |
---|
| 3 | |
---|
| 4 | #include <QPlainTextEdit> |
---|
| 5 | #include <QDockWidget> |
---|
[48] | 6 | #include <QSharedPointer> |
---|
[44] | 7 | |
---|
| 8 | class TextEditorDock; |
---|
| 9 | class DeckTextEditor; |
---|
| 10 | |
---|
| 11 | #include "cardeditor.h" |
---|
| 12 | #include "qpunchcard/card.h" |
---|
| 13 | #include "qpunchcard/codec.h" |
---|
| 14 | |
---|
| 15 | class TextEditorDock : public QDockWidget { |
---|
| 16 | Q_OBJECT |
---|
| 17 | |
---|
| 18 | EditorWindow* main; |
---|
[47] | 19 | DeckTextEditor* editor; |
---|
[48] | 20 | QWidget* code_bar; |
---|
| 21 | QWidget* color_bar; |
---|
[44] | 22 | public: |
---|
| 23 | TextEditorDock(EditorWindow* parent); |
---|
| 24 | |
---|
[48] | 25 | private: |
---|
| 26 | void create_code_bar(); |
---|
| 27 | void create_color_bar(); |
---|
| 28 | |
---|
[47] | 29 | public slots: |
---|
| 30 | void setCard(DeckIndex i); |
---|
[48] | 31 | void setCodec(QString by_name); |
---|
| 32 | void showTextConverterDialog(); |
---|
[44] | 33 | |
---|
| 34 | signals: |
---|
[47] | 35 | void cardSelected(DeckIndex i); |
---|
[44] | 36 | }; |
---|
| 37 | |
---|
| 38 | /// The QPlainTextEditor extension |
---|
| 39 | class DeckTextEditor : public QPlainTextEdit { |
---|
| 40 | Q_OBJECT |
---|
| 41 | |
---|
[48] | 42 | QPointer<EditorWindow> main; |
---|
| 43 | QSharedPointer<const Codec> codec; |
---|
| 44 | friend class TextEditorDock; |
---|
[47] | 45 | |
---|
[44] | 46 | public: |
---|
| 47 | // nested inner class |
---|
| 48 | class NumberArea : public QWidget { |
---|
| 49 | DeckTextEditor* editor; |
---|
| 50 | public: |
---|
| 51 | NumberArea(DeckTextEditor* e) : QWidget(e), editor(e) { } |
---|
| 52 | QSize sizeHint() const { |
---|
| 53 | return editor->numberAreaSize(this); |
---|
| 54 | } |
---|
| 55 | protected: |
---|
| 56 | void paintEvent(QPaintEvent* event) { |
---|
| 57 | editor->numberAreaPaintEvent(this, event); |
---|
| 58 | } |
---|
| 59 | }; |
---|
| 60 | |
---|
[47] | 61 | DeckTextEditor(EditorWindow* main); |
---|
[44] | 62 | |
---|
| 63 | void numberAreaPaintEvent(NumberArea* area, QPaintEvent* event); |
---|
| 64 | QSize numberAreaSize(const NumberArea* area) const; |
---|
[48] | 65 | bool translateBlock(const QTextBlock& block); |
---|
[44] | 66 | |
---|
| 67 | public slots: |
---|
| 68 | // wird Markierung entfernen, wenn ausser gueltigem Blockbereich |
---|
[47] | 69 | void highlightRow(DeckIndex i); |
---|
| 70 | void contentsChanged(DeckIndex lower_card_index, DeckIndex upper_card_index); |
---|
[44] | 71 | |
---|
| 72 | signals: |
---|
| 73 | // die aktive Karte des Benutzers |
---|
[47] | 74 | void cursorRowChanged(DeckIndex row); |
---|
[44] | 75 | |
---|
| 76 | private: |
---|
| 77 | NumberArea* row_area; |
---|
| 78 | NumberArea* col_area; |
---|
| 79 | int highlighted_row; |
---|
| 80 | |
---|
| 81 | protected: |
---|
| 82 | void resizeEvent(QResizeEvent* event); |
---|
| 83 | |
---|
| 84 | private slots: |
---|
| 85 | void updateLineNumberAreaWidth(int newBlockCount); |
---|
| 86 | void highlightCurrentCursorPos(); |
---|
| 87 | void paintHighlights(); |
---|
| 88 | void updateLineNumberArea(const QRect&, int); |
---|
| 89 | void translateChanges(int position, int charsRemoved, int charsAdded); |
---|
| 90 | |
---|
| 91 | }; // class |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | #endif // DECKTEXTEDITOR_H |
---|