summaryrefslogtreecommitdiff
authorsandman <sandman>2002-06-21 00:30:56 (UTC)
committer sandman <sandman>2002-06-21 00:30:56 (UTC)
commitb5951d300371cbe78fa94163aa882419e3d08d4b (patch) (unidiff)
treecc52dbcba8666a86f38585b6e5032c31324e60bf
parent56649b4725b2e98d786d06f83d4b3281ea1090fb (diff)
downloadopie-b5951d300371cbe78fa94163aa882419e3d08d4b.zip
opie-b5951d300371cbe78fa94163aa882419e3d08d4b.tar.gz
opie-b5951d300371cbe78fa94163aa882419e3d08d4b.tar.bz2
Fix for background drawing to make taskbar look nice with liquid style
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/inputmethods.cpp2
-rw-r--r--core/launcher/mrulist.cpp5
2 files changed, 5 insertions, 2 deletions
diff --git a/core/launcher/inputmethods.cpp b/core/launcher/inputmethods.cpp
index da98e07..ac72b02 100644
--- a/core/launcher/inputmethods.cpp
+++ b/core/launcher/inputmethods.cpp
@@ -1,319 +1,321 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_LANGLIST 21#define QTOPIA_INTERNAL_LANGLIST
22#include "inputmethods.h" 22#include "inputmethods.h"
23 23
24#include <qpe/config.h> 24#include <qpe/config.h>
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/inputmethodinterface.h> 26#include <qpe/inputmethodinterface.h>
27#include <qpe/qlibrary.h> 27#include <qpe/qlibrary.h>
28#include <qpe/global.h> 28#include <qpe/global.h>
29 29
30#include <qpopupmenu.h> 30#include <qpopupmenu.h>
31#include <qpushbutton.h> 31#include <qpushbutton.h>
32#include <qtoolbutton.h> 32#include <qtoolbutton.h>
33#include <qwidget.h> 33#include <qwidget.h>
34#include <qlayout.h> 34#include <qlayout.h>
35#include <qtimer.h> 35#include <qtimer.h>
36#include <qdir.h> 36#include <qdir.h>
37#include <stdlib.h> 37#include <stdlib.h>
38#include <qtranslator.h> 38#include <qtranslator.h>
39 39
40#ifdef Q_WS_QWS 40#ifdef Q_WS_QWS
41#include <qwindowsystem_qws.h> 41#include <qwindowsystem_qws.h>
42#include <qwsevent_qws.h> 42#include <qwsevent_qws.h>
43#endif 43#endif
44 44
45#ifdef SINGLE_APP 45#ifdef SINGLE_APP
46#include "handwritingimpl.h" 46#include "handwritingimpl.h"
47#include "keyboardimpl.h" 47#include "keyboardimpl.h"
48#include "pickboardimpl.h" 48#include "pickboardimpl.h"
49#endif 49#endif
50 50
51 51
52/* XPM */ 52/* XPM */
53static const char * tri_xpm[]={ 53static const char * tri_xpm[]={
54"9 9 2 1", 54"9 9 2 1",
55"a c #000000", 55"a c #000000",
56". c None", 56". c None",
57".........", 57".........",
58".........", 58".........",
59".........", 59".........",
60"....a....", 60"....a....",
61"...aaa...", 61"...aaa...",
62"..aaaaa..", 62"..aaaaa..",
63".aaaaaaa.", 63".aaaaaaa.",
64".........", 64".........",
65"........."}; 65"........."};
66 66
67static const int inputWidgetStyle = QWidget::WStyle_Customize | 67static const int inputWidgetStyle = QWidget::WStyle_Customize |
68 QWidget::WStyle_Tool | 68 QWidget::WStyle_Tool |
69 QWidget::WStyle_StaysOnTop | 69 QWidget::WStyle_StaysOnTop |
70 QWidget::WGroupLeader; 70 QWidget::WGroupLeader;
71 71
72InputMethods::InputMethods( QWidget *parent ) : 72InputMethods::InputMethods( QWidget *parent ) :
73 QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ) 73 QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize )
74{ 74{
75 method = NULL; 75 method = NULL;
76 76
77 setBackgroundMode ( PaletteBackground );
78
77 QHBoxLayout *hbox = new QHBoxLayout( this ); 79 QHBoxLayout *hbox = new QHBoxLayout( this );
78 80
79 kbdButton = new QToolButton( this ); 81 kbdButton = new QToolButton( this );
80 kbdButton->setFocusPolicy(NoFocus); 82 kbdButton->setFocusPolicy(NoFocus);
81 kbdButton->setToggleButton( TRUE ); 83 kbdButton->setToggleButton( TRUE );
82 kbdButton->setFixedHeight( 17 ); 84 kbdButton->setFixedHeight( 17 );
83 kbdButton->setFixedWidth( 32 ); 85 kbdButton->setFixedWidth( 32 );
84 kbdButton->setAutoRaise( TRUE ); 86 kbdButton->setAutoRaise( TRUE );
85 kbdButton->setUsesBigPixmap( TRUE ); 87 kbdButton->setUsesBigPixmap( TRUE );
86 hbox->addWidget( kbdButton ); 88 hbox->addWidget( kbdButton );
87 connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) ); 89 connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) );
88 90
89 kbdChoice = new QToolButton( this ); 91 kbdChoice = new QToolButton( this );
90 kbdChoice->setFocusPolicy(NoFocus); 92 kbdChoice->setFocusPolicy(NoFocus);
91 kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); 93 kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) );
92 kbdChoice->setFixedHeight( 17 ); 94 kbdChoice->setFixedHeight( 17 );
93 kbdChoice->setFixedWidth( 12 ); 95 kbdChoice->setFixedWidth( 12 );
94 kbdChoice->setAutoRaise( TRUE ); 96 kbdChoice->setAutoRaise( TRUE );
95 hbox->addWidget( kbdChoice ); 97 hbox->addWidget( kbdChoice );
96 connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) ); 98 connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) );
97 99
98 connect( (QPEApplication*)qApp, SIGNAL(clientMoused()), 100 connect( (QPEApplication*)qApp, SIGNAL(clientMoused()),
99 this, SLOT(resetStates()) ); 101 this, SLOT(resetStates()) );
100 102
101 loadInputMethods(); 103 loadInputMethods();
102} 104}
103 105
104InputMethods::~InputMethods() 106InputMethods::~InputMethods()
105{ 107{
106#ifndef SINGLE_APP 108#ifndef SINGLE_APP
107 QValueList<InputMethod>::Iterator mit; 109 QValueList<InputMethod>::Iterator mit;
108 for ( mit = inputMethodList.begin(); mit != inputMethodList.end(); ++mit ) { 110 for ( mit = inputMethodList.begin(); mit != inputMethodList.end(); ++mit ) {
109 int i = (*mit).interface->release(); 111 int i = (*mit).interface->release();
110 (*mit).library->unload(); 112 (*mit).library->unload();
111 delete (*mit).library; 113 delete (*mit).library;
112 } 114 }
113#endif 115#endif
114} 116}
115 117
116void InputMethods::hideInputMethod() 118void InputMethods::hideInputMethod()
117{ 119{
118 kbdButton->setOn( FALSE ); 120 kbdButton->setOn( FALSE );
119} 121}
120 122
121void InputMethods::showInputMethod() 123void InputMethods::showInputMethod()
122{ 124{
123 kbdButton->setOn( TRUE ); 125 kbdButton->setOn( TRUE );
124} 126}
125 127
126void InputMethods::showInputMethod(const QString& name) 128void InputMethods::showInputMethod(const QString& name)
127{ 129{
128 int i = 0; 130 int i = 0;
129 QValueList<InputMethod>::Iterator it; 131 QValueList<InputMethod>::Iterator it;
130 InputMethod *im = 0; 132 InputMethod *im = 0;
131 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { 133 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) {
132 if ( (*it).interface->name() == name ) { 134 if ( (*it).interface->name() == name ) {
133 im = &(*it); 135 im = &(*it);
134 break; 136 break;
135 } 137 }
136 } 138 }
137 if ( im ) 139 if ( im )
138 chooseMethod(im); 140 chooseMethod(im);
139} 141}
140 142
141void InputMethods::resetStates() 143void InputMethods::resetStates()
142{ 144{
143 if ( method ) 145 if ( method )
144 method->interface->resetState(); 146 method->interface->resetState();
145} 147}
146 148
147QRect InputMethods::inputRect() const 149QRect InputMethods::inputRect() const
148{ 150{
149 if ( !method || !method->widget->isVisible() ) 151 if ( !method || !method->widget->isVisible() )
150 return QRect(); 152 return QRect();
151 else 153 else
152 return method->widget->geometry(); 154 return method->widget->geometry();
153} 155}
154 156
155void InputMethods::loadInputMethods() 157void InputMethods::loadInputMethods()
156{ 158{
157#ifndef SINGLE_APP 159#ifndef SINGLE_APP
158 hideInputMethod(); 160 hideInputMethod();
159 method = 0; 161 method = 0;
160 162
161 QValueList<InputMethod>::Iterator mit; 163 QValueList<InputMethod>::Iterator mit;
162 for ( mit = inputMethodList.begin(); mit != inputMethodList.end(); ++mit ) { 164 for ( mit = inputMethodList.begin(); mit != inputMethodList.end(); ++mit ) {
163 (*mit).interface->release(); 165 (*mit).interface->release();
164 (*mit).library->unload(); 166 (*mit).library->unload();
165 delete (*mit).library; 167 delete (*mit).library;
166 } 168 }
167 inputMethodList.clear(); 169 inputMethodList.clear();
168 170
169 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods"; 171 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods";
170 QDir dir( path, "lib*.so" ); 172 QDir dir( path, "lib*.so" );
171 QStringList list = dir.entryList(); 173 QStringList list = dir.entryList();
172 QStringList::Iterator it; 174 QStringList::Iterator it;
173 for ( it = list.begin(); it != list.end(); ++it ) { 175 for ( it = list.begin(); it != list.end(); ++it ) {
174 InputMethodInterface *iface = 0; 176 InputMethodInterface *iface = 0;
175 QLibrary *lib = new QLibrary( path + "/" + *it ); 177 QLibrary *lib = new QLibrary( path + "/" + *it );
176 if ( lib->queryInterface( IID_InputMethod, (QUnknownInterface**)&iface ) == QS_OK ) { 178 if ( lib->queryInterface( IID_InputMethod, (QUnknownInterface**)&iface ) == QS_OK ) {
177 InputMethod input; 179 InputMethod input;
178 input.library = lib; 180 input.library = lib;
179 input.interface = iface; 181 input.interface = iface;
180 input.widget = input.interface->inputMethod( 0, inputWidgetStyle ); 182 input.widget = input.interface->inputMethod( 0, inputWidgetStyle );
181 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) ); 183 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) );
182 inputMethodList.append( input ); 184 inputMethodList.append( input );
183 185
184 QString type = (*it).left( (*it).find(".") ); 186 QString type = (*it).left( (*it).find(".") );
185 QStringList langs = Global::languageList(); 187 QStringList langs = Global::languageList();
186 for (QStringList::ConstIterator lit = langs.begin(); lit!=langs.end(); ++lit) { 188 for (QStringList::ConstIterator lit = langs.begin(); lit!=langs.end(); ++lit) {
187 QString lang = *lit; 189 QString lang = *lit;
188 QTranslator * trans = new QTranslator(qApp); 190 QTranslator * trans = new QTranslator(qApp);
189 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 191 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm";
190 if ( trans->load( tfn )) 192 if ( trans->load( tfn ))
191 qApp->installTranslator( trans ); 193 qApp->installTranslator( trans );
192 else 194 else
193 delete trans; 195 delete trans;
194 } 196 }
195 } else { 197 } else {
196 delete lib; 198 delete lib;
197 } 199 }
198 } 200 }
199#else 201#else
200 InputMethod input; 202 InputMethod input;
201 input.interface = new HandwritingImpl(); 203 input.interface = new HandwritingImpl();
202 input.widget = input.interface->inputMethod( 0, inputWidgetStyle ); 204 input.widget = input.interface->inputMethod( 0, inputWidgetStyle );
203 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) ); 205 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) );
204 inputMethodList.append( input ); 206 inputMethodList.append( input );
205 input.interface = new KeyboardImpl(); 207 input.interface = new KeyboardImpl();
206 input.widget = input.interface->inputMethod( 0, inputWidgetStyle ); 208 input.widget = input.interface->inputMethod( 0, inputWidgetStyle );
207 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) ); 209 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) );
208 inputMethodList.append( input ); 210 inputMethodList.append( input );
209 input.interface = new PickboardImpl(); 211 input.interface = new PickboardImpl();
210 input.widget = input.interface->inputMethod( 0, inputWidgetStyle ); 212 input.widget = input.interface->inputMethod( 0, inputWidgetStyle );
211 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) ); 213 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) );
212 inputMethodList.append( input ); 214 inputMethodList.append( input );
213#endif 215#endif
214 if ( !inputMethodList.isEmpty() ) { 216 if ( !inputMethodList.isEmpty() ) {
215 Config cfg("qpe"); 217 Config cfg("qpe");
216 cfg.setGroup("InputMethod"); 218 cfg.setGroup("InputMethod");
217 QString curMethod = cfg.readEntry("current",""); 219 QString curMethod = cfg.readEntry("current","");
218 if(curMethod.isEmpty()) { 220 if(curMethod.isEmpty()) {
219 method = &inputMethodList[0]; 221 method = &inputMethodList[0];
220 } else { 222 } else {
221 int i = 0; 223 int i = 0;
222 QValueList<InputMethod>::Iterator it; 224 QValueList<InputMethod>::Iterator it;
223 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { 225 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) {
224 if((*it).interface->name() == curMethod) { 226 if((*it).interface->name() == curMethod) {
225 method = &inputMethodList[i]; 227 method = &inputMethodList[i];
226// qDebug(curMethod); 228// qDebug(curMethod);
227 } 229 }
228 } 230 }
229 } 231 }
230 kbdButton->setPixmap( *method->interface->icon() ); 232 kbdButton->setPixmap( *method->interface->icon() );
231 } 233 }
232 if ( !inputMethodList.isEmpty() ) 234 if ( !inputMethodList.isEmpty() )
233 kbdButton->show(); 235 kbdButton->show();
234 else 236 else
235 kbdButton->hide(); 237 kbdButton->hide();
236 if ( inputMethodList.count() > 1 ) 238 if ( inputMethodList.count() > 1 )
237 kbdChoice->show(); 239 kbdChoice->show();
238 else 240 else
239 kbdChoice->hide(); 241 kbdChoice->hide();
240} 242}
241 243
242void InputMethods::chooseKbd() 244void InputMethods::chooseKbd()
243{ 245{
244 QPopupMenu pop( this ); 246 QPopupMenu pop( this );
245 247
246 int i = 0; 248 int i = 0;
247 QValueList<InputMethod>::Iterator it; 249 QValueList<InputMethod>::Iterator it;
248 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { 250 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) {
249 pop.insertItem( (*it).interface->name(), i ); 251 pop.insertItem( (*it).interface->name(), i );
250 if ( method == &(*it) ) 252 if ( method == &(*it) )
251 pop.setItemChecked( i, TRUE ); 253 pop.setItemChecked( i, TRUE );
252 } 254 }
253 255
254 QPoint pt = mapToGlobal(kbdChoice->geometry().topRight()); 256 QPoint pt = mapToGlobal(kbdChoice->geometry().topRight());
255 QSize s = pop.sizeHint(); 257 QSize s = pop.sizeHint();
256 pt.ry() -= s.height(); 258 pt.ry() -= s.height();
257 pt.rx() -= s.width(); 259 pt.rx() -= s.width();
258 i = pop.exec( pt ); 260 i = pop.exec( pt );
259 if ( i == -1 ) 261 if ( i == -1 )
260 return; 262 return;
261 InputMethod *im = &inputMethodList[i]; 263 InputMethod *im = &inputMethodList[i];
262 chooseMethod(im); 264 chooseMethod(im);
263} 265}
264 266
265void InputMethods::chooseMethod(InputMethod* im) 267void InputMethods::chooseMethod(InputMethod* im)
266{ 268{
267 if ( im != method ) { 269 if ( im != method ) {
268 if ( method && method->widget->isVisible() ) 270 if ( method && method->widget->isVisible() )
269 method->widget->hide(); 271 method->widget->hide();
270 method = im; 272 method = im;
271 Config cfg("qpe"); 273 Config cfg("qpe");
272 cfg.setGroup("InputMethod"); 274 cfg.setGroup("InputMethod");
273 cfg.writeEntry("current", method->interface->name()); 275 cfg.writeEntry("current", method->interface->name());
274 kbdButton->setPixmap( *method->interface->icon() ); 276 kbdButton->setPixmap( *method->interface->icon() );
275 } 277 }
276 if ( !kbdButton->isOn() ) 278 if ( !kbdButton->isOn() )
277 kbdButton->setOn( TRUE ); 279 kbdButton->setOn( TRUE );
278 else 280 else
279 showKbd( TRUE ); 281 showKbd( TRUE );
280} 282}
281 283
282 284
283void InputMethods::showKbd( bool on ) 285void InputMethods::showKbd( bool on )
284{ 286{
285 if ( !method ) 287 if ( !method )
286 return; 288 return;
287 289
288 if ( on ) { 290 if ( on ) {
289 method->interface->resetState(); 291 method->interface->resetState();
290 // HACK... Make the texteditor fit with all input methods 292 // HACK... Make the texteditor fit with all input methods
291 // Input methods should also never use more than about 40% of the screen 293 // Input methods should also never use more than about 40% of the screen
292 int height = QMIN( method->widget->sizeHint().height(), 134 ); 294 int height = QMIN( method->widget->sizeHint().height(), 134 );
293 method->widget->resize( qApp->desktop()->width(), height ); 295 method->widget->resize( qApp->desktop()->width(), height );
294 method->widget->move( 0, mapToGlobal( QPoint() ).y() - height ); 296 method->widget->move( 0, mapToGlobal( QPoint() ).y() - height );
295 method->widget->show(); 297 method->widget->show();
296 } else { 298 } else {
297 method->widget->hide(); 299 method->widget->hide();
298 } 300 }
299 301
300 emit inputToggled( on ); 302 emit inputToggled( on );
301} 303}
302 304
303bool InputMethods::shown() const 305bool InputMethods::shown() const
304{ 306{
305 return method && method->widget->isVisible(); 307 return method && method->widget->isVisible();
306} 308}
307 309
308QString InputMethods::currentShown() const 310QString InputMethods::currentShown() const
309{ 311{
310 return method && method->widget->isVisible() 312 return method && method->widget->isVisible()
311 ? method->interface->name() : QString::null; 313 ? method->interface->name() : QString::null;
312} 314}
313 315
314void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat ) 316void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat )
315{ 317{
316#if defined(Q_WS_QWS) 318#if defined(Q_WS_QWS)
317 QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat ); 319 QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat );
318#endif 320#endif
319} 321}
diff --git a/core/launcher/mrulist.cpp b/core/launcher/mrulist.cpp
index 5590d38..0530fd6 100644
--- a/core/launcher/mrulist.cpp
+++ b/core/launcher/mrulist.cpp
@@ -1,223 +1,224 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 Holger 'zecke' Freyther 2** Copyright (C) 2002 Holger 'zecke' Freyther
3** Copyright (C) 2000 Trolltech AS. All rights reserved. 3** Copyright (C) 2000 Trolltech AS. All rights reserved.
4** 4**
5** This file is part of Qtopia Environment. 5** This file is part of Qtopia Environment.
6** 6**
7** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14** 14**
15** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
16** 16**
17** Contact info@trolltech.com if any conditions of this licensing are 17** Contact info@trolltech.com if any conditions of this licensing are
18** not clear to you. 18** not clear to you.
19** 19**
20**********************************************************************/ 20**********************************************************************/
21 21
22#include "mrulist.h" 22#include "mrulist.h"
23 23
24#include <qpe/global.h> 24#include <qpe/global.h>
25#include <qpe/applnk.h> 25#include <qpe/applnk.h>
26#include <qpe/resource.h> 26#include <qpe/resource.h>
27 27
28#include <qframe.h> 28#include <qframe.h>
29#include <qpushbutton.h> 29#include <qpushbutton.h>
30#include <qtoolbutton.h> 30#include <qtoolbutton.h>
31#include <qpopupmenu.h> 31#include <qpopupmenu.h>
32#include <qpainter.h> 32#include <qpainter.h>
33#include <qwindowsystem_qws.h> 33#include <qwindowsystem_qws.h>
34 34
35 35
36 QList<MRUList>*MRUList::MRUListWidgets = NULL; 36 QList<MRUList>*MRUList::MRUListWidgets = NULL;
37 QList<AppLnk>*MRUList::task = NULL; 37 QList<AppLnk>*MRUList::task = NULL;
38 38
39 39
40MRUList::MRUList( QWidget *parent ) 40MRUList::MRUList( QWidget *parent )
41 : QFrame( parent ), selected(-1), oldsel(-1) 41 : QFrame( parent ), selected(-1), oldsel(-1)
42{ 42{
43 setBackgroundMode( PaletteButton ); 43 setBackgroundMode( PaletteBackground );
44 if (!MRUListWidgets) 44 if (!MRUListWidgets)
45 MRUListWidgets = new QList<MRUList>; 45 MRUListWidgets = new QList<MRUList>;
46 if (!task) 46 if (!task)
47 task = new QList<AppLnk>; 47 task = new QList<AppLnk>;
48 MRUListWidgets->append( this ); 48 MRUListWidgets->append( this );
49} 49}
50 50
51 51
52MRUList::~MRUList() 52MRUList::~MRUList()
53{ 53{
54 if (MRUListWidgets) 54 if (MRUListWidgets)
55 MRUListWidgets->remove( this ); 55 MRUListWidgets->remove( this );
56 if (task) 56 if (task)
57 task->setAutoDelete( TRUE ); 57 task->setAutoDelete( TRUE );
58} 58}
59 59
60 60
61QSize MRUList::sizeHint() const 61QSize MRUList::sizeHint() const
62{ 62{
63 return QSize( frameWidth(), 16 ); 63 return QSize( frameWidth(), 16 );
64} 64}
65 65
66// thanks to John from Trolltech 66// thanks to John from Trolltech
67void MRUList::removeTask(const QString &appName ) 67void MRUList::removeTask(const QString &appName )
68{ 68{
69 qWarning("MRULList::removeTask( %s)", appName.latin1() ); 69 qWarning("MRULList::removeTask( %s)", appName.latin1() );
70 if(appName.isEmpty() ) 70 if(appName.isEmpty() )
71 return; 71 return;
72 72
73 if(!task ) // at least it should be called once before 73 if(!task ) // at least it should be called once before
74 return; 74 return;
75 unsigned int i= 0; 75 unsigned int i= 0;
76 for ( ; i < task->count(); i++ ) { 76 for ( ; i < task->count(); i++ ) {
77 AppLnk *t = task->at(i); 77 AppLnk *t = task->at(i);
78 if ( t->exec() == appName ) 78 if ( t->exec() == appName )
79 task->remove(); 79 task->remove();
80 } 80 }
81 for (unsigned i = 0; i < MRUListWidgets->count(); i++ ) 81 for (unsigned i = 0; i < MRUListWidgets->count(); i++ )
82 MRUListWidgets->at(i)->update(); 82 MRUListWidgets->at(i)->update();
83} 83}
84 84
85void MRUList::addTask( const AppLnk *appLnk ) 85void MRUList::addTask( const AppLnk *appLnk )
86{ 86{
87 qWarning("Add Task" ); 87 qWarning("Add Task" );
88 if ( !appLnk ) 88 if ( !appLnk )
89 return; 89 return;
90 unsigned int i = 0; 90 unsigned int i = 0;
91 91
92 if ( !task ) 92 if ( !task )
93 return; 93 return;
94 94
95 i = 0; 95 i = 0;
96 for ( ; i < task->count(); i++ ) { 96 for ( ; i < task->count(); i++ ) {
97 AppLnk *t = task->at(i); 97 AppLnk *t = task->at(i);
98 if ( t->exec() == appLnk->exec() ) { 98 if ( t->exec() == appLnk->exec() ) {
99 if (i != 0) { 99 if (i != 0) {
100 task->remove(); 100 task->remove();
101 task->prepend( t ); 101 task->prepend( t );
102 } 102 }
103 for (unsigned i = 0; i < MRUListWidgets->count(); i++ ) 103 for (unsigned i = 0; i < MRUListWidgets->count(); i++ )
104 MRUListWidgets->at(i)->update(); 104 MRUListWidgets->at(i)->update();
105 return; 105 return;
106 } 106 }
107 } 107 }
108 // check which tasks are running and delete them from the list 108 // check which tasks are running and delete them from the list
109 AppLnk *t = new AppLnk( *appLnk ); 109 AppLnk *t = new AppLnk( *appLnk );
110 // DocLnks have an overloaded virtual function exec() 110 // DocLnks have an overloaded virtual function exec()
111 t->setExec( appLnk->exec() ); 111 t->setExec( appLnk->exec() );
112 task->prepend( t ); 112 task->prepend( t );
113 113
114 if ( task->count() > 6 ) { 114 if ( task->count() > 6 ) {
115 t = task->last(); 115 t = task->last();
116 task->remove(); 116 task->remove();
117 Global::terminate(t); 117 Global::terminate(t);
118 delete t; 118 delete t;
119 } 119 }
120 120
121 for (unsigned i = 0; i < MRUListWidgets->count(); i++ ) 121 for (unsigned i = 0; i < MRUListWidgets->count(); i++ )
122 MRUListWidgets->at(i)->update(); 122 MRUListWidgets->at(i)->update();
123} 123}
124 124
125bool MRUList::quitOldApps() 125bool MRUList::quitOldApps()
126{ 126{
127 QStringList appsstarted; 127 QStringList appsstarted;
128 QStringList appsrunning; 128 QStringList appsrunning;
129 for ( int i=task->count()-1; i>=0; --i ) { 129 for ( int i=task->count()-1; i>=0; --i ) {
130 AppLnk *t = task->at(i); 130 AppLnk *t = task->at(i);
131 appsstarted.append(t->exec()); 131 appsstarted.append(t->exec());
132 } 132 }
133 133
134 const QList<QWSWindow> &list = qwsServer->clientWindows(); 134 const QList<QWSWindow> &list = qwsServer->clientWindows();
135 QWSWindow* w; 135 QWSWindow* w;
136 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 136 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
137 QString app = w->client()->identity(); 137 QString app = w->client()->identity();
138 if ( appsstarted.contains(app) && !appsrunning.contains(app) ) 138 if ( appsstarted.contains(app) && !appsrunning.contains(app) )
139 appsrunning.append(app); 139 appsrunning.append(app);
140 } 140 }
141 141
142 if ( appsrunning.count() > 1 ) { 142 if ( appsrunning.count() > 1 ) {
143 QStringList::ConstIterator it = appsrunning.begin(); 143 QStringList::ConstIterator it = appsrunning.begin();
144 ++it; // top stays running! 144 ++it; // top stays running!
145 for (; it != appsrunning.end(); it++) { 145 for (; it != appsrunning.end(); it++) {
146 for ( int i=task->count()-1; i>=0; --i ) { 146 for ( int i=task->count()-1; i>=0; --i ) {
147 AppLnk *t = task->at(i); 147 AppLnk *t = task->at(i);
148 if ( t->exec() == *it ){ 148 if ( t->exec() == *it ){
149 task->remove(i ); 149 task->remove(i );
150 delete t; 150 delete t;
151 Global::terminate(t); 151 Global::terminate(t);
152 } 152 }
153 } 153 }
154 } 154 }
155 return TRUE; 155 return TRUE;
156 } else { 156 } else {
157 return FALSE; 157 return FALSE;
158 } 158 }
159} 159}
160 160
161 161
162void MRUList::mousePressEvent(QMouseEvent *e) 162void MRUList::mousePressEvent(QMouseEvent *e)
163{ 163{
164 selected = 0; 164 selected = 0;
165 int x=0; 165 int x=0;
166 QListIterator<AppLnk> it( *task ); 166 QListIterator<AppLnk> it( *task );
167 for ( ; it.current(); ++it,++selected,x+=15 ) { 167 for ( ; it.current(); ++it,++selected,x+=15 ) {
168 if ( x + 15 <= width() ) { 168 if ( x + 15 <= width() ) {
169 if ( e->x() >= x && e->x() < x+15 ) { 169 if ( e->x() >= x && e->x() < x+15 ) {
170 if ( selected < (int)task->count() ) { 170 if ( selected < (int)task->count() ) {
171 repaint(FALSE); 171 repaint(FALSE);
172 return; 172 return;
173 } 173 }
174 } 174 }
175 } else { 175 } else {
176 break; 176 break;
177 } 177 }
178 } 178 }
179 selected = -1; 179 selected = -1;
180 repaint( FALSE ); 180 repaint( FALSE );
181} 181}
182 182
183 183
184void MRUList::mouseReleaseEvent(QMouseEvent *) 184void MRUList::mouseReleaseEvent(QMouseEvent *)
185{ 185{
186 if ( selected >= 0 ) { 186 if ( selected >= 0 ) {
187 if ( parentWidget() ) 187 if ( parentWidget() )
188 if ( parentWidget()->isA( "QPopupMenu" ) ) 188 if ( parentWidget()->isA( "QPopupMenu" ) )
189 parentWidget()->hide(); 189 parentWidget()->hide();
190 Global::execute( task->at(selected)->exec() ); 190 Global::execute( task->at(selected)->exec() );
191 selected = -1; 191 selected = -1;
192 oldsel = -1; 192 oldsel = -1;
193 update(); 193 update();
194 } 194 }
195} 195}
196 196
197 197
198void MRUList::paintEvent( QPaintEvent * ) 198void MRUList::paintEvent( QPaintEvent * )
199{ 199{
200 QPainter p( this ); 200 QPainter p( this );
201 AppLnk *t; 201 AppLnk *t;
202 int x = 0; 202 int x = 0;
203 int y = (height() - 14) / 2; 203 int y = (height() - 14) / 2;
204 int i = 0; 204 int i = 0;
205 205
206 p.fillRect( 0, 0, width(), height(), colorGroup().background() ); 206// p.fillRect( 0, 0, width(), height(), colorGroup().background() );
207 erase ( );
207 208
208 if ( task ) { 209 if ( task ) {
209 QListIterator<AppLnk> it( *task ); 210 QListIterator<AppLnk> it( *task );
210 for ( ; it.current(); i++, ++it ) { 211 for ( ; it.current(); i++, ++it ) {
211 if ( x + 15 <= width() ) { 212 if ( x + 15 <= width() ) {
212 t = it.current(); 213 t = it.current();
213 if ( (int)i == selected ) 214 if ( (int)i == selected )
214 p.fillRect( x, y, 15, t->pixmap().height()+1, colorGroup().highlight() ); 215 p.fillRect( x, y, 15, t->pixmap().height()+1, colorGroup().highlight() );
215 else if ( (int)i == oldsel ) 216 else if ( (int)i == oldsel )
216 p.eraseRect( x, y, 15, t->pixmap().height()+1 ); 217 p.eraseRect( x, y, 15, t->pixmap().height()+1 );
217 p.drawPixmap( x, y, t->pixmap() ); 218 p.drawPixmap( x, y, t->pixmap() );
218 x += 15; 219 x += 15;
219 } 220 }
220 } 221 }
221 } 222 }
222} 223}
223 224