author | ibotty <ibotty> | 2002-10-07 13:23:14 (UTC) |
---|---|---|
committer | ibotty <ibotty> | 2002-10-07 13:23:14 (UTC) |
commit | 68d98791b05217163f97d7c233952df8075416bb (patch) (unidiff) | |
tree | da2ad4d16d62053ca5b836cd08d37364ec12b635 | |
parent | a513a88322196c8caa21b00b83d454feae84200c (diff) | |
download | opie-68d98791b05217163f97d7c233952df8075416bb.zip opie-68d98791b05217163f97d7c233952df8075416bb.tar.gz opie-68d98791b05217163f97d7c233952df8075416bb.tar.bz2 |
changed WidgetLayer to a new (well partial) image storage
WidgetLayer is now to be considered stable.
there wont be any api removals.
newwidget.{h,cpp} will inherit WidgetLayer, soon.
i will try to be logic compatible with current widget.{h,cpp}, but will NOT
guarantee api compatibility.
-rw-r--r-- | noncore/apps/opie-console/widget_layer.cpp | 26 | ||||
-rw-r--r-- | noncore/apps/opie-console/widget_layer.h | 27 |
2 files changed, 36 insertions, 17 deletions
diff --git a/noncore/apps/opie-console/widget_layer.cpp b/noncore/apps/opie-console/widget_layer.cpp index 28227e4..f428ed4 100644 --- a/noncore/apps/opie-console/widget_layer.cpp +++ b/noncore/apps/opie-console/widget_layer.cpp | |||
@@ -1,155 +1,157 @@ | |||
1 | /* ------------------------------------------------------------------------- */ | 1 | /* ------------------------------------------------------------------------- */ |
2 | /* */ | 2 | /* */ |
3 | /* widget_layer.cpp Widget Layer */ | 3 | /* widget_layer.cpp Widget Layer */ |
4 | /* */ | 4 | /* */ |
5 | /* opie developers <opie@handhelds.org> */ | 5 | /* opie developers <opie@handhelds.org> */ |
6 | /* */ | 6 | /* */ |
7 | /* ------------------------------------------------------------------------- */ | 7 | /* ------------------------------------------------------------------------- */ |
8 | 8 | ||
9 | 9 | ||
10 | 10 | ||
11 | #include "widget_layer.h" | 11 | #include "widget_layer.h" |
12 | 12 | ||
13 | #include <qclipboard.h> | 13 | #include <qclipboard.h> |
14 | #include <qregexp.h> | 14 | #include <qregexp.h> |
15 | #include <qglobal.h> | 15 | #include <qglobal.h> |
16 | 16 | ||
17 | #include <string.h> | 17 | #include <string.h> |
18 | //#include < | 18 | //#include < |
19 | 19 | ||
20 | #include "common.h" | 20 | #include "common.h" |
21 | 21 | ||
22 | 22 | ||
23 | #define loc(X,Y) ((Y)*m_columns+(X)) | ||
24 | 23 | ||
25 | 24 | WidgetLayer::WidgetLayer( QWidget *parent, const char *name ) : QFrame( parent, name ) | |
26 | WidgetLayer::WidgetLayer( QObject *parent, const char *name ) : QObject( parent, name ) | ||
27 | { | 25 | { |
28 | // get the clipboard | 26 | // get the clipboard |
29 | m_clipboard = QApplication::clipboard(); | 27 | m_clipboard = QApplication::clipboard(); |
30 | 28 | ||
31 | // when data on clipboard changes, clear selection | 29 | // when data on clipboard changes, clear selection |
32 | QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), | 30 | QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), |
33 | (QObject*)this, SLOT( onClearSelection() ) ); | 31 | (QObject*)this, SLOT( onClearSelection() ) ); |
34 | 32 | ||
35 | // initialize vars: | 33 | // initialize vars: |
36 | m_lines = 1; | 34 | m_lines = 1; |
37 | m_columns = 1; | 35 | m_columns = 1; |
38 | m_resizing = false; | 36 | m_resizing = false; |
39 | 37 | ||
40 | m_image = QArray<Character>(); | 38 | // just for demonstrating |
39 | //m_image = QArray<Character>( m_lines * m_columns ); | ||
40 | m_image = QArray<Character>( 1 ); | ||
41 | |||
41 | } | 42 | } |
42 | 43 | ||
44 | |||
43 | WidgetLayer::~WidgetLayer() | 45 | WidgetLayer::~WidgetLayer() |
44 | { | 46 | { |
45 | // clean up! | 47 | // clean up |
48 | delete m_image; | ||
46 | } | 49 | } |
47 | 50 | ||
48 | /* --------------------------------- audio ---------------------------------- */ | 51 | /* --------------------------------- audio ---------------------------------- */ |
49 | 52 | ||
50 | void WidgetLayer::bell() | 53 | void WidgetLayer::bell() |
51 | { | 54 | { |
52 | QApplication::beep(); | 55 | QApplication::beep(); |
53 | } | 56 | } |
54 | 57 | ||
55 | 58 | ||
56 | /* --------------------------------- screen --------------------------------- */ | 59 | /* --------------------------------- screen --------------------------------- */ |
57 | 60 | ||
58 | 61 | ||
59 | void WidgetLayer::propagateSize() | 62 | void WidgetLayer::propagateSize() |
60 | { | 63 | { |
61 | QArray<Character> oldimage = m_image; | 64 | QArray<Character> oldimage = m_image.copy(); |
62 | int oldlines = m_lines; | 65 | int oldlines = m_lines; |
63 | int oldcolumns = m_columns; | 66 | int oldcolumns = m_columns; |
64 | 67 | ||
65 | makeImage(); | 68 | makeImage(); |
66 | 69 | ||
67 | // copy old image, to reduce flicker | 70 | // copy old image, to reduce flicker |
68 | if ( oldimage ) | 71 | if ( ! oldimage.isEmpty() ) |
69 | { | 72 | { |
70 | //FIXME: is it possible to do this with QArray.dublicate()? | ||
71 | |||
72 | int lins = QMIN( oldlines, m_lines ); | 73 | int lins = QMIN( oldlines, m_lines ); |
73 | int cols = QMIN( oldcolumns, m_columns ); | 74 | int cols = QMIN( oldcolumns, m_columns ); |
74 | for ( int lin = 0; lin < lins; ++lin ) | 75 | for ( int lin = 0; lin < lins; ++lin ) |
75 | { | 76 | { |
76 | memcpy( (void*) &m_image[m_columns*lin], | 77 | memcpy( (void*) &m_image[m_columns*lin], |
77 | (void*) &oldimage[oldcolumns*lin], | 78 | (void*) &oldimage[oldcolumns*lin], |
78 | cols*sizeof( Character ) ); | 79 | cols*sizeof( Character ) ); |
79 | } | 80 | } |
80 | //free( oldimage ); | ||
81 | } | 81 | } |
82 | else | 82 | else |
83 | clearImage(); | 83 | clearImage(); |
84 | 84 | ||
85 | delete oldimage; | ||
86 | |||
85 | m_resizing = true; | 87 | m_resizing = true; |
86 | emit imageSizeChanged( m_lines, m_columns ); | 88 | emit imageSizeChanged( m_lines, m_columns ); |
87 | m_resizing = false; | 89 | m_resizing = false; |
88 | } | 90 | } |
89 | 91 | ||
90 | void WidgetLayer::makeImage() | 92 | void WidgetLayer::makeImage() |
91 | { | 93 | { |
92 | calcGeometry(); | 94 | calcGeometry(); |
93 | m_image = QArray<Character>(); | 95 | m_image = QArray<Character>( m_columns * m_lines ); |
94 | clearImage(); | 96 | clearImage(); |
95 | } | 97 | } |
96 | 98 | ||
97 | void WidgetLayer::clearImage() | 99 | void WidgetLayer::clearImage() |
98 | { | 100 | { |
99 | //should this belong here?? | 101 | //should this belong here?? |
100 | for ( int y = 0; y < m_lines; y++ ) | 102 | for ( int y = 0; y < m_lines; y++ ) |
101 | for ( int x = 0; x < m_columns; x++ ) | 103 | for ( int x = 0; x < m_columns; x++ ) |
102 | { | 104 | { |
103 | m_image[loc(x,y)].c = 0xff; | 105 | m_image[loc(x,y)].c = 0xff; |
104 | m_image[loc(x,y)].f = 0xff; | 106 | m_image[loc(x,y)].f = 0xff; |
105 | m_image[loc(x,y)].b = 0xff; | 107 | m_image[loc(x,y)].b = 0xff; |
106 | m_image[loc(x,y)].r = 0xff; | 108 | m_image[loc(x,y)].r = 0xff; |
107 | } | 109 | } |
108 | } | 110 | } |
109 | 111 | ||
110 | /* --------------------------------- selection ------------------------------ */ | 112 | /* --------------------------------- selection ------------------------------ */ |
111 | 113 | ||
112 | void WidgetLayer::pasteClipboard() | 114 | void WidgetLayer::pasteClipboard() |
113 | { | 115 | { |
114 | insertSelection(); | 116 | insertSelection(); |
115 | } | 117 | } |
116 | 118 | ||
117 | 119 | ||
118 | void WidgetLayer::insertSelection() | 120 | void WidgetLayer::insertSelection() |
119 | { | 121 | { |
120 | QString text = QApplication::clipboard()->text(); | 122 | QString text = QApplication::clipboard()->text(); |
121 | if ( ! text.isNull() ) | 123 | if ( ! text.isNull() ) |
122 | { | 124 | { |
123 | text.replace( QRegExp( "\n" ), "\r" ); | 125 | text.replace( QRegExp( "\n" ), "\r" ); |
124 | insertText( text ); | 126 | insertText( text ); |
125 | // selection should be unselected | 127 | // selection should be unselected |
126 | emit selectionCleared(); | 128 | emit selectionCleared(); |
127 | } | 129 | } |
128 | } | 130 | } |
129 | 131 | ||
130 | void WidgetLayer::insertText( QString text ) | 132 | void WidgetLayer::insertText( QString text ) |
131 | { | 133 | { |
132 | // text is inserted as key event | 134 | // text is inserted as key event |
133 | QKeyEvent e( QEvent::KeyPress, 0, -1, 0, text); | 135 | QKeyEvent e( QEvent::KeyPress, 0, -1, 0, text); |
134 | emit keyPressed( &e ); | 136 | emit keyPressed( &e ); |
135 | } | 137 | } |
136 | 138 | ||
137 | void WidgetLayer::onClearSelection() | 139 | void WidgetLayer::onClearSelection() |
138 | { | 140 | { |
139 | emit selectionCleared(); | 141 | emit selectionCleared(); |
140 | } | 142 | } |
141 | 143 | ||
142 | void WidgetLayer::setSelection( const QString& text ) | 144 | void WidgetLayer::setSelection( const QString& text ) |
143 | { | 145 | { |
144 | // why get the clipboard, we have it as instance var... | 146 | // why get the clipboard, we have it as instance var... |
145 | QObject *m_clipboard = QApplication::clipboard(); | 147 | QObject *m_clipboard = QApplication::clipboard(); |
146 | 148 | ||
147 | // we know, that cliboard changes, when we change clipboard | 149 | // we know, that cliboard changes, when we change clipboard |
148 | QObject::disconnect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), | 150 | QObject::disconnect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), |
149 | (QObject*) this, SLOT( selectionCleared() ) ); | 151 | (QObject*) this, SLOT( selectionCleared() ) ); |
150 | 152 | ||
151 | QApplication::clipboard()->setText( text ); | 153 | QApplication::clipboard()->setText( text ); |
152 | 154 | ||
153 | QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), | 155 | QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), |
154 | (QObject*) this, SLOT( selectionCleared() ) ); | 156 | (QObject*) this, SLOT( selectionCleared() ) ); |
155 | } | 157 | } |
diff --git a/noncore/apps/opie-console/widget_layer.h b/noncore/apps/opie-console/widget_layer.h index 07ec12a..99d248e 100644 --- a/noncore/apps/opie-console/widget_layer.h +++ b/noncore/apps/opie-console/widget_layer.h | |||
@@ -1,200 +1,217 @@ | |||
1 | /* -------------------------------------------------------------------------- */ | 1 | /* -------------------------------------------------------------------------- */ |
2 | /* */ | 2 | /* */ |
3 | /* [widget_layer.h] Widget Layer */ | 3 | /* [widget_layer.h] Widget Layer */ |
4 | /* */ | 4 | /* */ |
5 | /* -------------------------------------------------------------------------- */ | 5 | /* -------------------------------------------------------------------------- */ |
6 | 6 | ||
7 | // proposal of a widget Layer in opie-console | 7 | // proposal of a widget Layer in opie-console |
8 | // | 8 | // |
9 | // fellow devels: | 9 | // fellow devels: |
10 | // just mail me (ibotty@web.de), what you additionally need from the main widget | 10 | // just mail me (ibotty@web.de), what you additionally need from the main widget |
11 | // (or say in chat) | 11 | // (or say in chat) |
12 | 12 | ||
13 | #ifndef WIDGET_LAYER_H | 13 | #ifndef WIDGET_LAYER_H |
14 | #define WIDGET_LAYER_H | 14 | #define WIDGET_LAYER_H |
15 | 15 | ||
16 | // qt includes | 16 | // qt includes |
17 | #include <qapplication.h> | 17 | #include <qapplication.h> |
18 | #include <qframe.h> | ||
19 | #include <qarray.h> | ||
18 | #include <qtimer.h> | 20 | #include <qtimer.h> |
19 | #include <qkeycode.h> | 21 | #include <qkeycode.h> |
20 | #include <qclipboard.h> | 22 | #include <qclipboard.h> |
21 | 23 | ||
22 | 24 | ||
23 | // opie-console includes | 25 | // opie-console includes |
24 | #include "session.h" | 26 | #include "session.h" |
25 | #include "common.h" | 27 | #include "common.h" |
26 | 28 | ||
27 | class WidgetLayer : public QObject | 29 | /* |
30 | * given a pseudo location ( column, line ), | ||
31 | * returns the actual index, in the QArray<Character> | ||
32 | */ | ||
33 | #define loc(X,Y) ((Y)*m_columns+(X)) | ||
34 | |||
35 | |||
36 | |||
37 | |||
38 | class WidgetLayer : public QFrame | ||
28 | { Q_OBJECT | 39 | { Q_OBJECT |
29 | 40 | ||
30 | public: | 41 | public: |
31 | 42 | ||
32 | /** | 43 | /** |
33 | * constructor | 44 | * constructor |
34 | */ | 45 | */ |
35 | WidgetLayer( QObject *parent=0, const char *name=0 ); | 46 | WidgetLayer( QWidget *parent=0, const char *name=0 ); |
36 | 47 | ||
37 | /** | 48 | /** |
38 | * destructor | 49 | * destructor |
39 | */ | 50 | */ |
40 | virtual ~WidgetLayer(); | 51 | virtual ~WidgetLayer(); |
41 | 52 | ||
42 | public: | 53 | public: |
43 | /** | 54 | /** |
44 | * sets the image | 55 | * sets the image |
45 | */ | 56 | */ |
46 | virtual void setImage( const Character* const newimg, int lines, int colums ) = 0; | 57 | virtual void setImage( QArray<Character> const newimg, int lines, int colums ); |
47 | 58 | ||
48 | /** | 59 | /** |
49 | * annoy the user | 60 | * annoy the user |
50 | */ | 61 | */ |
51 | void bell(); | 62 | void bell(); |
52 | 63 | ||
53 | /** | 64 | /** |
54 | * return the lines count | 65 | * return the lines count |
55 | */ | 66 | */ |
56 | int lines(){ return m_lines; } | 67 | int lines(){ return m_lines; } |
57 | 68 | ||
58 | /** | 69 | /** |
59 | * return the columns count | 70 | * return the columns count |
60 | */ | 71 | */ |
61 | int columns(){ return m_columns; } | 72 | int columns(){ return m_columns; } |
62 | 73 | ||
63 | /** | 74 | /** |
64 | * insert current selection (currently this is only the clipboard) | 75 | * insert current selection (currently this is only the clipboard) |
65 | */ | 76 | */ |
66 | void insertSelection(); | 77 | void insertSelection(); |
67 | 78 | ||
68 | /** | 79 | /** |
69 | * insert text | 80 | * insert text |
70 | */ | 81 | */ |
71 | void insertText( QString text ); | 82 | void insertText( QString text ); |
72 | /** | 83 | /** |
73 | * set selection (clipboard) to text | 84 | * set selection (clipboard) to text |
74 | */ | 85 | */ |
75 | void setSelection( const QString &text ); | 86 | void setSelection( const QString &text ); |
76 | 87 | ||
77 | /** | 88 | /** |
78 | * paste content of clipboard | 89 | * paste content of clipboard |
79 | */ | 90 | */ |
80 | void pasteClipboard(); | 91 | void pasteClipboard(); |
81 | 92 | ||
82 | 93 | ||
83 | signals: | 94 | signals: |
84 | 95 | ||
85 | /** | 96 | /** |
86 | * key was pressed | 97 | * key was pressed |
87 | */ | 98 | */ |
88 | void keyPressed( QKeyEvent *e ); | 99 | void keyPressed( QKeyEvent *e ); |
89 | 100 | ||
90 | /** | 101 | /** |
91 | * whenever Mouse selects something | 102 | * whenever Mouse selects something |
92 | * 0left Button | 103 | * 0left Button |
93 | * 3Button released | 104 | * 3Button released |
94 | * // numbering due to layout in old TEWidget | 105 | * // numbering due to layout in old TEWidget |
95 | */ | 106 | */ |
96 | void mousePressed( int button, int x, int y ); | 107 | void mousePressed( int button, int x, int y ); |
97 | 108 | ||
98 | /** | 109 | /** |
99 | * size of image changed | 110 | * size of image changed |
100 | */ | 111 | */ |
101 | void imageSizeChanged( int lines, int columns ); | 112 | void imageSizeChanged( int lines, int columns ); |
102 | 113 | ||
103 | /** | 114 | /** |
104 | * cursor in history changed | 115 | * cursor in history changed |
105 | */ | 116 | */ |
106 | void historyCursorChanged( int value ); | 117 | void historyCursorChanged( int value ); |
107 | 118 | ||
108 | /** | 119 | /** |
109 | * selection should be cleared | 120 | * selection should be cleared |
110 | */ | 121 | */ |
111 | void selectionCleared(); | 122 | void selectionCleared(); |
112 | 123 | ||
113 | /** | 124 | /** |
114 | * selection begin | 125 | * selection begin |
115 | */ | 126 | */ |
116 | void selectionBegin( const int x, const int y ); | 127 | void selectionBegin( const int x, const int y ); |
117 | 128 | ||
118 | /** | 129 | /** |
119 | * selection extended | 130 | * selection extended |
120 | * (from begin (s.a.) to x, y) | 131 | * (from begin (s.a.) to x, y) |
121 | */ | 132 | */ |
122 | void selectionExtended( const int x, const int y ); | 133 | void selectionExtended( const int x, const int y ); |
123 | 134 | ||
124 | /** | 135 | /** |
125 | * selection end | 136 | * selection end |
126 | * bool: preserve line breaks in selection | 137 | * bool: preserve line breaks in selection |
127 | */ | 138 | */ |
128 | void selectionEnd( const bool lineBreakPreserve ); | 139 | void selectionEnd( const bool lineBreakPreserve ); |
129 | 140 | ||
130 | 141 | ||
131 | 142 | ||
132 | // protected methods | 143 | // protected methods |
133 | protected: | 144 | protected: |
134 | 145 | ||
135 | // image operations | 146 | // image operations |
136 | 147 | ||
137 | /** | 148 | /** |
138 | * changes image, to suit new size | 149 | * changes image, to suit new size |
139 | * TODO: find meaningful name! | 150 | * TODO: find meaningful name! |
140 | */ | 151 | */ |
141 | void propagateSize(); | 152 | void propagateSize(); |
142 | 153 | ||
143 | /** | 154 | /** |
144 | * | 155 | *determines count of lines and columns |
145 | */ | 156 | */ |
146 | virtual void calcGeometry() = 0; | 157 | virtual void calcGeometry() = 0; |
147 | 158 | ||
148 | /** | 159 | /** |
149 | * makes an empty image | 160 | * makes an empty image |
150 | */ | 161 | */ |
151 | void makeImage(); | 162 | void makeImage(); |
152 | 163 | ||
153 | /** | 164 | /** |
154 | * clears the image | 165 | * clears the image |
155 | */ | 166 | */ |
156 | void clearImage(); | 167 | void clearImage(); |
157 | 168 | ||
158 | protected slots: | 169 | protected slots: |
159 | 170 | ||
160 | /** | 171 | /** |
161 | * clear selection | 172 | * clear selection |
162 | */ | 173 | */ |
163 | void onClearSelection(); | 174 | void onClearSelection(); |
164 | 175 | ||
165 | 176 | ||
166 | // protected vars | 177 | // protected vars |
167 | protected: | 178 | protected: |
168 | 179 | ||
169 | /** | 180 | /** |
170 | * current Session | 181 | * current Session |
171 | */ | 182 | */ |
172 | Session *m_session; | 183 | Session *m_session; |
173 | 184 | ||
174 | /** | 185 | /** |
175 | * current character image | 186 | * current character image |
187 | * | ||
188 | * a Character at loc( column, line ) | ||
189 | * has the actual index: | ||
190 | * ix = line * m_columns + column; | ||
191 | * | ||
192 | * use loc( x, y ) macro to access. | ||
176 | */ | 193 | */ |
177 | QArray<Character> m_image; | 194 | QArray<Character> m_image; |
178 | 195 | ||
179 | /** | 196 | /** |
180 | * lines count | 197 | * lines count |
181 | */ | 198 | */ |
182 | int m_lines; | 199 | int m_lines; |
183 | 200 | ||
184 | /** | 201 | /** |
185 | * columns count | 202 | * columns count |
186 | */ | 203 | */ |
187 | int m_columns; | 204 | int m_columns; |
188 | 205 | ||
189 | /** | 206 | /** |
190 | * clipboard | 207 | * clipboard |
191 | */ | 208 | */ |
192 | QClipboard* m_clipboard; | 209 | QClipboard* m_clipboard; |
193 | 210 | ||
194 | /** | 211 | /** |
195 | * whether widget was resized | 212 | * whether widget is resizing |
196 | */ | 213 | */ |
197 | bool m_resizing; | 214 | bool m_resizing; |
198 | }; | 215 | }; |
199 | 216 | ||
200 | #endif // WIDGET_LAYER_H | 217 | #endif // WIDGET_LAYER_H |