Diffstat (limited to 'inputmethods/dasher/QtDasherScreen.cc') (more/less context) (ignore whitespace changes)
-rw-r--r-- | inputmethods/dasher/QtDasherScreen.cc | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/inputmethods/dasher/QtDasherScreen.cc b/inputmethods/dasher/QtDasherScreen.cc index 747b705..2179cfb 100644 --- a/inputmethods/dasher/QtDasherScreen.cc +++ b/inputmethods/dasher/QtDasherScreen.cc | |||
@@ -1,177 +1,182 @@ | |||
1 | // QtDasherScreen.cc | 1 | // QtDasherScreen.cc |
2 | // (c) 2003 Yann Dirson | 2 | // (c) 2003 Yann Dirson |
3 | // Derived from GtkDasherCanvas.cc | 3 | // Derived from GtkDasherCanvas.cc |
4 | // (c) 2002 Philip Cowans | 4 | // (c) 2002 Philip Cowans |
5 | 5 | ||
6 | #include <iostream> | 6 | #include <iostream> |
7 | #include <string> | 7 | #include <string> |
8 | 8 | ||
9 | #include <qpointarray.h> | 9 | #include <qpointarray.h> |
10 | #include <qpoint.h> | 10 | #include <qpoint.h> |
11 | 11 | ||
12 | #include "QtDasherScreen.h" | 12 | #include "QtDasherScreen.h" |
13 | #include "DasherScreen.h" | 13 | #include "DasherScreen.h" |
14 | #include "SettingsStore.h" | 14 | #include "SettingsStore.h" |
15 | 15 | ||
16 | #define MAXFONTSIZE 25 | 16 | #define MAXFONTSIZE 25 |
17 | #define MINFONTSIZE 8 | 17 | #define MINFONTSIZE 8 |
18 | 18 | ||
19 | QtDasherScreen::QtDasherScreen (int _width, int _height, | 19 | QtDasherScreen::QtDasherScreen (int _width, int _height, |
20 | CDasherInterface *_interface, | 20 | CDasherInterface *_interface, |
21 | QWidget * _parent, Dasher::CDashEditbox *edit): | 21 | QWidget * _parent, |
22 | QWidget(_parent), interface( _interface ), | 22 | Dasher::CDashEditbox *_edit): |
23 | fontname( "fixed" ), fontsize(12), | 23 | QWidget(_parent), |
24 | Dasher::CDasherScreen(_width, _height) | 24 | Dasher::CDasherScreen(_width, _height), |
25 | fontsize(12), | ||
26 | interface( _interface ), | ||
27 | fontname( "fixed" ) | ||
25 | { | 28 | { |
26 | font = QFont (fontname.c_str(), fontsize); | 29 | font = QFont (fontname.c_str(), fontsize); |
27 | painter = new QPainter (); | 30 | painter = new QPainter (); |
28 | 31 | ||
29 | pixmap = new QPixmap (_width, _height); | 32 | pixmap = new QPixmap (_width, _height); |
30 | pixmap->setOptimization(QPixmap::BestOptim); | 33 | pixmap->setOptimization(QPixmap::BestOptim); |
31 | interface->SetSettingsStore(new CSettingsStore); | 34 | interface->SetSettingsStore(new CSettingsStore); |
32 | 35 | ||
33 | interface->ChangeLanguageModel(0); | 36 | interface->ChangeLanguageModel(0); |
34 | interface->ChangeView(0); | 37 | interface->ChangeView(0); |
35 | interface->ChangeEdit(edit); | 38 | interface->ChangeEdit(_edit); |
39 | edit = _edit; | ||
40 | |||
36 | 41 | ||
37 | /* interface->GetFontSizes(&FontSizes); | 42 | /* interface->GetFontSizes(&FontSizes); |
38 | 43 | ||
39 | for (int i=0; i<FontSizes.size(); i++) { | 44 | for (int i=0; i<FontSizes.size(); i++) { |
40 | if (FontSizes[i]>Fonts.size()) | 45 | if (FontSizes[i]>Fonts.size()) |
41 | Fonts.resize((FontSizes[i])+1); | 46 | Fonts.resize((FontSizes[i])+1); |
42 | Fonts[FontSizes[i]]= QFont (fontname.c_str(), FontSizes[i]); | 47 | Fonts[FontSizes[i]]= QFont (fontname.c_str(), FontSizes[i]); |
43 | // Fonts[FontSizes[i]].setPixelSize(FontSizes[i]); | 48 | // Fonts[FontSizes[i]].setPixelSize(FontSizes[i]); |
44 | } | 49 | } |
45 | */ | 50 | */ |
46 | interface->ChangeScreen(this); | 51 | interface->ChangeScreen(this); |
47 | 52 | ||
48 | paused=true; | 53 | paused=true; |
49 | 54 | ||
50 | QTimer *tmr = new QTimer(this); | 55 | QTimer *tmr = new QTimer(this); |
51 | connect (tmr, SIGNAL(timeout()), SLOT(timer())); | 56 | connect (tmr, SIGNAL(timeout()), SLOT(timer())); |
52 | tmr->start(200); | 57 | tmr->start(200); |
53 | 58 | ||
54 | } | 59 | } |
55 | 60 | ||
56 | long QtDasherScreen::get_time() | 61 | long QtDasherScreen::get_time() |
57 | { | 62 | { |
58 | long s_now; | 63 | long s_now; |
59 | long ms_now; | 64 | long ms_now; |
60 | 65 | ||
61 | struct timeval tv; | 66 | struct timeval tv; |
62 | struct timezone tz; | 67 | struct timezone tz; |
63 | 68 | ||
64 | gettimeofday( &tv, &tz ); | 69 | gettimeofday( &tv, &tz ); |
65 | 70 | ||
66 | s_now = tv.tv_sec-1054487600; | 71 | s_now = tv.tv_sec-1054487600; |
67 | 72 | ||
68 | ms_now = tv.tv_usec / 1000; | 73 | ms_now = tv.tv_usec / 1000; |
69 | 74 | ||
70 | return( long(s_now*1000 + ms_now) ); | 75 | return( long(s_now*1000 + ms_now) ); |
71 | 76 | ||
72 | } | 77 | } |
73 | 78 | ||
74 | QtDasherScreen::~QtDasherScreen() | 79 | QtDasherScreen::~QtDasherScreen() |
75 | { | 80 | { |
76 | delete painter; | 81 | delete painter; |
77 | delete interface; | 82 | delete interface; |
78 | delete edit; | 83 | delete edit; |
79 | } | 84 | } |
80 | 85 | ||
81 | QColor QtDasherScreen::getColor(int Color, const Opts::ColorSchemes ColorScheme) const | 86 | QColor QtDasherScreen::getColor(int Color, const Opts::ColorSchemes ColorScheme) const |
82 | { | 87 | { |
83 | switch (ColorScheme) { | 88 | switch (ColorScheme) { |
84 | case Dasher::Opts::Nodes1: | 89 | case Dasher::Opts::Nodes1: |
85 | switch (Color) { | 90 | switch (Color) { |
86 | case 0: return QColor (180, 245, 180); | 91 | case 0: return QColor (180, 245, 180); |
87 | case 1: return QColor (160, 200, 160); | 92 | case 1: return QColor (160, 200, 160); |
88 | case 2: return QColor (0, 255, 255); | 93 | case 2: return QColor (0, 255, 255); |
89 | default: abort (); | 94 | default: abort (); |
90 | } | 95 | } |
91 | case Dasher::Opts::Nodes2: | 96 | case Dasher::Opts::Nodes2: |
92 | switch (Color) { | 97 | switch (Color) { |
93 | case 0: return QColor (255, 185, 255); | 98 | case 0: return QColor (255, 185, 255); |
94 | case 1: return QColor (140, 200, 255); | 99 | case 1: return QColor (140, 200, 255); |
95 | case 2: return QColor (255, 175, 175); | 100 | case 2: return QColor (255, 175, 175); |
96 | default: abort (); | 101 | default: abort (); |
97 | } | 102 | } |
98 | case Dasher::Opts::Special1: return QColor (240, 240, 240); | 103 | case Dasher::Opts::Special1: return QColor (240, 240, 240); |
99 | case Dasher::Opts::Special2: return QColor (255, 255, 255); | 104 | case Dasher::Opts::Special2: return QColor (255, 255, 255); |
100 | case Dasher::Opts::Groups: | 105 | case Dasher::Opts::Groups: |
101 | switch (Color) { | 106 | switch (Color) { |
102 | case 0: return QColor (255, 255, 0); | 107 | case 0: return QColor (255, 255, 0); |
103 | case 1: return QColor (255, 100, 100); | 108 | case 1: return QColor (255, 100, 100); |
104 | case 2: return QColor (0, 255, 0); | 109 | case 2: return QColor (0, 255, 0); |
105 | default: abort (); | 110 | default: abort (); |
106 | } | 111 | } |
107 | case Dasher::Opts::Objects: return QColor (0, 0, 0); | 112 | case Dasher::Opts::Objects: return QColor (0, 0, 0); |
108 | default: abort(); | 113 | default: abort(); |
109 | } | 114 | } |
110 | } | 115 | } |
111 | 116 | ||
112 | void QtDasherScreen::DrawRectangle(int x1, int y1, int x2, int y2, | 117 | void QtDasherScreen::DrawRectangle(int x1, int y1, int x2, int y2, |
113 | int Color, Opts::ColorSchemes ColorScheme) const | 118 | int Color, Opts::ColorSchemes ColorScheme) const |
114 | { | 119 | { |
115 | painter->setBrush (getColor (Color, ColorScheme)); | 120 | painter->setBrush (getColor (Color, ColorScheme)); |
116 | painter->drawRect (x1, y1, x2-x1, y2-y1); | 121 | painter->drawRect (x1, y1, x2-x1, y2-y1); |
117 | } | 122 | } |
118 | 123 | ||
119 | static void Points_to_QPointArray(const Dasher::CDasherScreen::point* const points, | 124 | static void Points_to_QPointArray(const Dasher::CDasherScreen::point* const points, |
120 | int number, | 125 | int number, |
121 | QPointArray &qpa) | 126 | QPointArray &qpa) |
122 | { | 127 | { |
123 | for (int i = 0; i < number; i++) { | 128 | for (int i = 0; i < number; i++) { |
124 | qpa.setPoint (i, points[i].x, points[i].y); | 129 | qpa.setPoint (i, points[i].x, points[i].y); |
125 | } | 130 | } |
126 | } | 131 | } |
127 | 132 | ||
128 | void QtDasherScreen::Polyline(point* Points, int Number) const | 133 | void QtDasherScreen::Polyline(point* Points, int Number) const |
129 | { | 134 | { |
130 | QPointArray qpa(Number); | 135 | QPointArray qpa(Number); |
131 | Points_to_QPointArray (Points, Number, qpa); | 136 | Points_to_QPointArray (Points, Number, qpa); |
132 | painter->setPen (SolidLine); | 137 | painter->setPen (SolidLine); |
133 | painter->drawPolyline (qpa); | 138 | painter->drawPolyline (qpa); |
134 | painter->setPen (NoPen); | 139 | painter->setPen (NoPen); |
135 | } | 140 | } |
136 | 141 | ||
137 | void QtDasherScreen::DrawPolygon(point* Points, int Number, int Color, | 142 | void QtDasherScreen::DrawPolygon(point* Points, int Number, int Color, |
138 | Opts::ColorSchemes ColorScheme) const | 143 | Opts::ColorSchemes ColorScheme) const |
139 | { | 144 | { |
140 | painter->setBrush (getColor (Color, ColorScheme)); | 145 | painter->setBrush (getColor (Color, ColorScheme)); |
141 | QPointArray qpa(Number); | 146 | QPointArray qpa(Number); |
142 | Points_to_QPointArray (Points, Number, qpa); | 147 | Points_to_QPointArray (Points, Number, qpa); |
143 | painter->drawPolygon (qpa); | 148 | painter->drawPolygon (qpa); |
144 | } | 149 | } |
145 | 150 | ||
146 | void QtDasherScreen::mousePressEvent (QMouseEvent *e) | 151 | void QtDasherScreen::mousePressEvent (QMouseEvent *) |
147 | { | 152 | { |
148 | paused=false; | 153 | paused=false; |
149 | interface->Unpause(get_time()); | 154 | interface->Unpause(get_time()); |
150 | } | 155 | } |
151 | 156 | ||
152 | void QtDasherScreen::mouseReleaseEvent(QMouseEvent *e) | 157 | void QtDasherScreen::mouseReleaseEvent(QMouseEvent *e) |
153 | { | 158 | { |
154 | QPoint p = e->pos(); | 159 | QPoint p = e->pos(); |
155 | interface->PauseAt(p.x(), p.y()); | 160 | interface->PauseAt(p.x(), p.y()); |
156 | paused=true; | 161 | paused=true; |
157 | } | 162 | } |
158 | 163 | ||
159 | void QtDasherScreen::timer() | 164 | void QtDasherScreen::timer() |
160 | { | 165 | { |
161 | if (paused==false) { | 166 | if (paused==false) { |
162 | QPoint cursorpos; | 167 | QPoint cursorpos; |
163 | cursorpos=this->cursor().pos(); | 168 | cursorpos=this->cursor().pos(); |
164 | cursorpos=mapFromGlobal(cursorpos); | 169 | cursorpos=mapFromGlobal(cursorpos); |
165 | 170 | ||
166 | interface->TapOn(cursorpos.x(), cursorpos.y(), get_time()); | 171 | interface->TapOn(cursorpos.x(), cursorpos.y(), get_time()); |
167 | } | 172 | } |
168 | } | 173 | } |
169 | 174 | ||
170 | 175 | ||
171 | 176 | ||
172 | 177 | ||
173 | 178 | ||
174 | 179 | ||
175 | 180 | ||
176 | 181 | ||
177 | 182 | ||