source: projects/punch-card/punch-card-editor/src/text/editor.h @ 53

Last change on this file since 53 was 53, checked in by sven, 10 years ago

Punch Card Editor, ongoing development

  • Extended new Deck interface, expanding the undo framework
  • Implemented editor changes via undo framework
  • revised the menu and toolbar actions and structure (now dynamic construction at deck load time), implemented undo viewer
  • Started implementation of device driver framework in menu
  • Embedded the Qextserialport library (http://qextserialport.sourceforge.net/)
  • Started the Documation M200 Client device driver (well, just created the directory structure and qmake project file infrastructure)
  • At the current state, the complete project compiles :-)

Statistics: About 3500 Lines of code (without libqextserialport)

-- sven @ workstation

File size: 3.5 KB
Line 
1#ifndef DECKTEXTEDITOR_H
2#define DECKTEXTEDITOR_H
3
4#include <QPlainTextEdit>
5#include <QSharedPointer>
6
7namespace QPunchCard {
8namespace Text {
9        class Editor;
10        class CharUndoCommand;
11        class StringUndoCommand;
12};
13};
14
15#include "app/mainwindow.h"
16#include "deckviewer/cardeditor.h"
17#include "qpunchcard/card.h"
18#include "qpunchcard/deck.h"
19#include "text/editordock.h"
20#include "text/codec.h"
21
22namespace QPunchCard {
23namespace Text {
24
25class Editor : public QPlainTextEdit {
26        Q_OBJECT
27
28        QPointer<App::MainWindow> main;
29        QSharedPointer<const Codec> codec;
30        QList<QTextEdit::ExtraSelection> invalid_characters;
31        friend class Text::EditorDock;
32
33public:
34        // nested inner class
35        class NumberArea : public QWidget {
36                Text::Editor* editor;
37        public:
38                NumberArea(Text::Editor* e) : QWidget(e), editor(e) { }
39                QSize sizeHint() const {
40                        return editor->numberAreaSize(this);
41                }
42        protected:
43                void paintEvent(QPaintEvent* event) {
44                        editor->numberAreaPaintEvent(this, event);
45                }
46        };
47
48        Editor(App::MainWindow* main);
49
50        void numberAreaPaintEvent(NumberArea* area, QPaintEvent* event);
51        QSize numberAreaSize(const NumberArea* area) const;
52        bool translateBlock(const QTextBlock& block);
53        bool checkValidity(int pos);
54        /// returns # of invalid chars
55        int containsInvalidCharacters() { return invalid_characters.count(); }
56
57public slots:
58        // wird Markierung entfernen, wenn ausser gueltigem Blockbereich
59        void highlightRow(DeckIndex i);
60        void contentsChanged(DeckIndex lower_card_index, DeckIndex upper_card_index);
61
62signals:
63        // die aktive Karte des Benutzers
64        void cursorRowChanged(DeckIndex row);
65        void invalidCharactersCountChanged(int new_number);
66
67private:
68        NumberArea* row_area;
69        NumberArea* col_area;
70        int highlighted_row;
71
72protected:
73        void resizeEvent(QResizeEvent* event);
74        void paintEvent(QPaintEvent* e);
75
76private slots:
77        void updateLineNumberAreaWidth(int newBlockCount);
78        void highlightCurrentCursorPos();
79        void paintHighlights();
80        void updateLineNumberArea(const QRect&, int);
81        void translateChanges(int position, int charsRemoved, int charsAdded);
82
83}; // class Editor
84
85/*
86class CharUndoCommand : public DeckUndoCommand {
87        CharUndoCommand(Deck* editor, DeckIndex& position, CardIndex column, Card old_content,
88                        const Codec* codec, char new_char, QUndoCommand *parent = 0) :
89                DeckUndoCommand(deck, parent), column(column), old_content(old_content),
90                codec(codec), new_char(new_char) {
91        }
92
93                old_content = *position.getCard();
94                setText(position.getDeck()->tr("Changed contents of card").arg(position));
95        }
96        void undo() { position.getDeck()->cards[position] = old_content; }
97        void redo() { position.getDeck()->cards[position] = new_content; }
98private:
99        DeckIndex position;
100        Card old_content;
101        CardIndex column;
102        const Codec* codec;
103        char new_char;
104}; // class CharUndoCommand
105*/
106
107/*
108class ModifyLine : public DeckModifyCard {
109public:
110        ModifyLine(Deck* deck, const QString& new_text, const Codec* codec,
111                   DeckIndex& position, QUndoCommand* parent=0) : DeckModifyCard(deck, position, Card, parent) {
112                codec->fromAscii(codec, &new_content);
113                position.assertDeck(deck);
114                Q_ASSERT(this->deck);
115
116                // alten Inhalt irgendwie sichern
117                old_content = *position.getCard();
118                setText(position.getDeck()->tr("Changed contents of card").arg(position));
119        }
120        void undo() { position.getDeck()->cards[position] = old_content; }
121        void redo() { position.getDeck()->cards[position] = new_content; }
122private:
123
124        DeckIndex position;
125        Card new_content;
126        Card old_content;
127};
128*/
129
130
131}; // namespace Text
132}; // namespace QPunchCard
133
134#endif // DECKTEXTEDITOR_H
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License