author | ibotty <ibotty> | 2002-10-06 19:17:57 (UTC) |
---|---|---|
committer | ibotty <ibotty> | 2002-10-06 19:17:57 (UTC) |
commit | e99c8b4ed69d844bfab7cb1f1f5a514fdad3118f (patch) (unidiff) | |
tree | 88b9d305f7b12f1c7a9be01a027c1db73ee13dd0 /noncore | |
parent | aa8332baeebf7056d81fc245399477c7feaa1235 (diff) | |
download | opie-e99c8b4ed69d844bfab7cb1f1f5a514fdad3118f.zip opie-e99c8b4ed69d844bfab7cb1f1f5a514fdad3118f.tar.gz opie-e99c8b4ed69d844bfab7cb1f1f5a514fdad3118f.tar.bz2 |
wrote first incarnation of widget_layer.cpp.
edited widget_layer.h accordingly.
-rw-r--r-- | noncore/apps/opie-console/opie-console.pro | 6 | ||||
-rw-r--r-- | noncore/apps/opie-console/widget_layer.cpp | 155 | ||||
-rw-r--r-- | noncore/apps/opie-console/widget_layer.h | 104 |
3 files changed, 246 insertions, 19 deletions
diff --git a/noncore/apps/opie-console/opie-console.pro b/noncore/apps/opie-console/opie-console.pro index 831ca34..5c2d04e 100644 --- a/noncore/apps/opie-console/opie-console.pro +++ b/noncore/apps/opie-console/opie-console.pro | |||
@@ -21,7 +21,8 @@ HEADERS = io_layer.h io_serial.h \ | |||
21 | common.h \ | 21 | common.h \ |
22 | history.h \ | 22 | history.h \ |
23 | screen.h \ | 23 | screen.h \ |
24 | keytrans.h | 24 | keytrans.h \ |
25 | widget_layer.h | ||
25 | 26 | ||
26 | SOURCES = io_layer.cpp io_serial.cpp \ | 27 | SOURCES = io_layer.cpp io_serial.cpp \ |
27 | file_layer.cpp main.cpp \ | 28 | file_layer.cpp main.cpp \ |
@@ -40,7 +41,8 @@ SOURCES = io_layer.cpp io_serial.cpp \ | |||
40 | vt102emulation.cpp \ | 41 | vt102emulation.cpp \ |
41 | history.cpp \ | 42 | history.cpp \ |
42 | screen.cpp \ | 43 | screen.cpp \ |
43 | keytrans.cpp | 44 | keytrans.cpp \ |
45 | widget_layer.cpp | ||
44 | 46 | ||
45 | INTERFACES = configurebase.ui editbase.ui | 47 | INTERFACES = configurebase.ui editbase.ui |
46 | INCLUDEPATH += $(OPIEDIR)/include | 48 | INCLUDEPATH += $(OPIEDIR)/include |
diff --git a/noncore/apps/opie-console/widget_layer.cpp b/noncore/apps/opie-console/widget_layer.cpp new file mode 100644 index 0000000..28227e4 --- a/dev/null +++ b/noncore/apps/opie-console/widget_layer.cpp | |||
@@ -0,0 +1,155 @@ | |||
1 | /* ------------------------------------------------------------------------- */ | ||
2 | /* */ | ||
3 | /* widget_layer.cpp Widget Layer */ | ||
4 | /* */ | ||
5 | /* opie developers <opie@handhelds.org> */ | ||
6 | /* */ | ||
7 | /* ------------------------------------------------------------------------- */ | ||
8 | |||
9 | |||
10 | |||
11 | #include "widget_layer.h" | ||
12 | |||
13 | #include <qclipboard.h> | ||
14 | #include <qregexp.h> | ||
15 | #include <qglobal.h> | ||
16 | |||
17 | #include <string.h> | ||
18 | //#include < | ||
19 | |||
20 | #include "common.h" | ||
21 | |||
22 | |||
23 | #define loc(X,Y) ((Y)*m_columns+(X)) | ||
24 | |||
25 | |||
26 | WidgetLayer::WidgetLayer( QObject *parent, const char *name ) : QObject( parent, name ) | ||
27 | { | ||
28 | // get the clipboard | ||
29 | m_clipboard = QApplication::clipboard(); | ||
30 | |||
31 | // when data on clipboard changes, clear selection | ||
32 | QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), | ||
33 | (QObject*)this, SLOT( onClearSelection() ) ); | ||
34 | |||
35 | // initialize vars: | ||
36 | m_lines = 1; | ||
37 | m_columns = 1; | ||
38 | m_resizing = false; | ||
39 | |||
40 | m_image = QArray<Character>(); | ||
41 | } | ||
42 | |||
43 | WidgetLayer::~WidgetLayer() | ||
44 | { | ||
45 | // clean up! | ||
46 | } | ||
47 | |||
48 | /* --------------------------------- audio ---------------------------------- */ | ||
49 | |||
50 | void WidgetLayer::bell() | ||
51 | { | ||
52 | QApplication::beep(); | ||
53 | } | ||
54 | |||
55 | |||
56 | /* --------------------------------- screen --------------------------------- */ | ||
57 | |||
58 | |||
59 | void WidgetLayer::propagateSize() | ||
60 | { | ||
61 | QArray<Character> oldimage = m_image; | ||
62 | int oldlines = m_lines; | ||
63 | int oldcolumns = m_columns; | ||
64 | |||
65 | makeImage(); | ||
66 | |||
67 | // copy old image, to reduce flicker | ||
68 | if ( oldimage ) | ||
69 | { | ||
70 | //FIXME: is it possible to do this with QArray.dublicate()? | ||
71 | |||
72 | int lins = QMIN( oldlines, m_lines ); | ||
73 | int cols = QMIN( oldcolumns, m_columns ); | ||
74 | for ( int lin = 0; lin < lins; ++lin ) | ||
75 | { | ||
76 | memcpy( (void*) &m_image[m_columns*lin], | ||
77 | (void*) &oldimage[oldcolumns*lin], | ||
78 | cols*sizeof( Character ) ); | ||
79 | } | ||
80 | //free( oldimage ); | ||
81 | } | ||
82 | else | ||
83 | clearImage(); | ||
84 | |||
85 | m_resizing = true; | ||
86 | emit imageSizeChanged( m_lines, m_columns ); | ||
87 | m_resizing = false; | ||
88 | } | ||
89 | |||
90 | void WidgetLayer::makeImage() | ||
91 | { | ||
92 | calcGeometry(); | ||
93 | m_image = QArray<Character>(); | ||
94 | clearImage(); | ||
95 | } | ||
96 | |||
97 | void WidgetLayer::clearImage() | ||
98 | { | ||
99 | //should this belong here?? | ||
100 | for ( int y = 0; y < m_lines; y++ ) | ||
101 | for ( int x = 0; x < m_columns; x++ ) | ||
102 | { | ||
103 | m_image[loc(x,y)].c = 0xff; | ||
104 | m_image[loc(x,y)].f = 0xff; | ||
105 | m_image[loc(x,y)].b = 0xff; | ||
106 | m_image[loc(x,y)].r = 0xff; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | /* --------------------------------- selection ------------------------------ */ | ||
111 | |||
112 | void WidgetLayer::pasteClipboard() | ||
113 | { | ||
114 | insertSelection(); | ||
115 | } | ||
116 | |||
117 | |||
118 | void WidgetLayer::insertSelection() | ||
119 | { | ||
120 | QString text = QApplication::clipboard()->text(); | ||
121 | if ( ! text.isNull() ) | ||
122 | { | ||
123 | text.replace( QRegExp( "\n" ), "\r" ); | ||
124 | insertText( text ); | ||
125 | // selection should be unselected | ||
126 | emit selectionCleared(); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | void WidgetLayer::insertText( QString text ) | ||
131 | { | ||
132 | // text is inserted as key event | ||
133 | QKeyEvent e( QEvent::KeyPress, 0, -1, 0, text); | ||
134 | emit keyPressed( &e ); | ||
135 | } | ||
136 | |||
137 | void WidgetLayer::onClearSelection() | ||
138 | { | ||
139 | emit selectionCleared(); | ||
140 | } | ||
141 | |||
142 | void WidgetLayer::setSelection( const QString& text ) | ||
143 | { | ||
144 | // why get the clipboard, we have it as instance var... | ||
145 | QObject *m_clipboard = QApplication::clipboard(); | ||
146 | |||
147 | // we know, that cliboard changes, when we change clipboard | ||
148 | QObject::disconnect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), | ||
149 | (QObject*) this, SLOT( selectionCleared() ) ); | ||
150 | |||
151 | QApplication::clipboard()->setText( text ); | ||
152 | |||
153 | QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), | ||
154 | (QObject*) this, SLOT( selectionCleared() ) ); | ||
155 | } | ||
diff --git a/noncore/apps/opie-console/widget_layer.h b/noncore/apps/opie-console/widget_layer.h index cf2a1e5..3cdd6aa 100644 --- a/noncore/apps/opie-console/widget_layer.h +++ b/noncore/apps/opie-console/widget_layer.h | |||
@@ -1,4 +1,4 @@ | |||
1 | 1 | /* -------------------------------------------------------------------------- */ | |
2 | /* */ | 2 | /* */ |
3 | /* [widget_layer.h] Widget Layer */ | 3 | /* [widget_layer.h] Widget Layer */ |
4 | /* */ | 4 | /* */ |
@@ -10,21 +10,36 @@ | |||
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 | ||
14 | #define WIDGET_LAYER_H | ||
15 | |||
16 | // qt includes | ||
17 | #include <qapplication.h> | ||
18 | #include <qtimer.h> | ||
19 | #include <qkeycode.h> | ||
20 | #include <qclipboard.h> | ||
21 | |||
22 | |||
23 | // opie-console includes | ||
24 | #include "session.h" | ||
25 | #include "common.h" | ||
13 | 26 | ||
14 | class WidgetLayer : public QObject | 27 | class WidgetLayer : public QObject |
15 | { QObject | 28 | { Q_OBJECT |
16 | 29 | ||
17 | public: | 30 | public: |
31 | |||
18 | /** | 32 | /** |
19 | * constructor | 33 | * constructor |
20 | */ | 34 | */ |
21 | WidgetLayer(); | 35 | WidgetLayer( QObject *parent=0, const char *name=0 ); |
22 | 36 | ||
23 | /** | 37 | /** |
24 | * destructor | 38 | * destructor |
25 | */ | 39 | */ |
26 | virtual ~WidgetLayer(); | 40 | virtual ~WidgetLayer(); |
27 | 41 | ||
42 | public: | ||
28 | /** | 43 | /** |
29 | * sets the image | 44 | * sets the image |
30 | */ | 45 | */ |
@@ -43,17 +58,21 @@ public: | |||
43 | /** | 58 | /** |
44 | * return the columns count | 59 | * return the columns count |
45 | */ | 60 | */ |
46 | int columns(){ return m_columns } | 61 | int columns(){ return m_columns; } |
47 | 62 | ||
48 | /** | 63 | /** |
49 | * copy selection into clipboard, etc | 64 | * insert current selection (currently this is only the clipboard) |
50 | */ | 65 | */ |
51 | void emitSelection(); | 66 | void insertSelection(); |
52 | 67 | ||
53 | /** | 68 | /** |
69 | * insert text | ||
70 | */ | ||
71 | void insertText( QString text ); | ||
72 | /** | ||
54 | * set selection (clipboard) to text | 73 | * set selection (clipboard) to text |
55 | */ | 74 | */ |
56 | void setSelection( QString &text ) | 75 | void setSelection( const QString &text ); |
57 | 76 | ||
58 | /** | 77 | /** |
59 | * paste content of clipboard | 78 | * paste content of clipboard |
@@ -66,7 +85,7 @@ signals: | |||
66 | /** | 85 | /** |
67 | * key was pressed | 86 | * key was pressed |
68 | */ | 87 | */ |
69 | keyPressed( QKeyEvent *e ); | 88 | void keyPressed( QKeyEvent *e ); |
70 | 89 | ||
71 | /** | 90 | /** |
72 | * whenever Mouse selects something | 91 | * whenever Mouse selects something |
@@ -74,17 +93,17 @@ signals: | |||
74 | * 3Button released | 93 | * 3Button released |
75 | * // numbering due to layout in old TEWidget | 94 | * // numbering due to layout in old TEWidget |
76 | */ | 95 | */ |
77 | mousePressed( int button, int x, int y ); | 96 | void mousePressed( int button, int x, int y ); |
78 | 97 | ||
79 | /** | 98 | /** |
80 | * size of image changed | 99 | * size of image changed |
81 | */ | 100 | */ |
82 | imageSizeChanged( int lines, int columns ); | 101 | void imageSizeChanged( int lines, int columns ); |
83 | 102 | ||
84 | /** | 103 | /** |
85 | * cursor in history changed | 104 | * cursor in history changed |
86 | */ | 105 | */ |
87 | historyCursorChanged( int value ); | 106 | void historyCursorChanged( int value ); |
88 | 107 | ||
89 | /** | 108 | /** |
90 | * selection should be cleared | 109 | * selection should be cleared |
@@ -94,11 +113,11 @@ signals: | |||
94 | /** | 113 | /** |
95 | * selection begin | 114 | * selection begin |
96 | */ | 115 | */ |
97 | void selectionBegin( const int x, const int y ) | 116 | void selectionBegin( const int x, const int y ); |
98 | 117 | ||
99 | /** | 118 | /** |
100 | * selection extended | 119 | * selection extended |
101 | * (from begin s.a. to x, y) | 120 | * (from begin (s.a.) to x, y) |
102 | */ | 121 | */ |
103 | void selectionExtended( const int x, const int y ); | 122 | void selectionExtended( const int x, const int y ); |
104 | 123 | ||
@@ -108,12 +127,41 @@ signals: | |||
108 | */ | 127 | */ |
109 | void selectionEnd( const bool lineBreakPreserve ); | 128 | void selectionEnd( const bool lineBreakPreserve ); |
110 | 129 | ||
111 | slots: | 130 | |
131 | |||
132 | // protected methods | ||
133 | protected: | ||
134 | |||
135 | // image operations | ||
136 | |||
137 | /** | ||
138 | * changes image, to suit new size | ||
139 | * TODO: find meaningful name! | ||
140 | */ | ||
141 | void propagateSize(); | ||
142 | |||
143 | /** | ||
144 | * | ||
145 | */ | ||
146 | virtual void calcGeometry(); | ||
147 | |||
148 | /** | ||
149 | * makes an empty image | ||
150 | */ | ||
151 | void makeImage(); | ||
152 | |||
153 | /** | ||
154 | * clears the image | ||
155 | */ | ||
156 | void clearImage(); | ||
157 | |||
158 | protected slots: | ||
112 | 159 | ||
113 | /** | 160 | /** |
114 | * clear selection | 161 | * clear selection |
115 | */ | 162 | */ |
116 | onClearSelection(); | 163 | void onClearSelection(); |
164 | |||
117 | 165 | ||
118 | // protected vars | 166 | // protected vars |
119 | protected: | 167 | protected: |
@@ -121,10 +169,32 @@ protected: | |||
121 | /** | 169 | /** |
122 | * current Session | 170 | * current Session |
123 | */ | 171 | */ |
124 | Session m_session; | 172 | Session *m_session; |
173 | |||
174 | /** | ||
175 | * current character image | ||
176 | */ | ||
177 | QArray<Character> m_image; | ||
125 | 178 | ||
126 | /** | 179 | /** |
127 | * other misc vars | 180 | * lines count |
128 | */ | 181 | */ |
182 | int m_lines; | ||
129 | 183 | ||
184 | /** | ||
185 | * columns count | ||
186 | */ | ||
187 | int m_columns; | ||
188 | |||
189 | /** | ||
190 | * clipboard | ||
191 | */ | ||
192 | QClipboard* m_clipboard; | ||
193 | |||
194 | /** | ||
195 | * whether widget was resized | ||
196 | */ | ||
197 | bool m_resizing; | ||
130 | }; | 198 | }; |
199 | |||
200 | #endif // WIDGET_LAYER_H | ||