summaryrefslogtreecommitdiff
authordrw <drw>2002-05-18 20:59:09 (UTC)
committer drw <drw>2002-05-18 20:59:09 (UTC)
commit1d935738d89d038e05013d8d099bcf4da14073ea (patch) (unidiff)
tree449b1a9185ede01d2fe7f90249603bc3a2f4f473
parentdd86981ce4191e7916dc97c114267763c9a07018 (diff)
downloadopie-1d935738d89d038e05013d8d099bcf4da14073ea.zip
opie-1d935738d89d038e05013d8d099bcf4da14073ea.tar.gz
opie-1d935738d89d038e05013d8d099bcf4da14073ea.tar.bz2
Added Launcher icon text and background color options
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcherview.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index 6354bb7..1598d13 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -1,198 +1,207 @@
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#include "launcherview.h" 21#include "launcherview.h"
22 22
23#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
24#include <qpe/applnk.h> 24#include <qpe/applnk.h>
25#include <qpe/qpedebug.h> 25#include <qpe/qpedebug.h>
26#include <qpe/config.h> 26#include <qpe/config.h>
27#include <qpe/categories.h> 27#include <qpe/categories.h>
28#include <qpe/categoryselect.h> 28#include <qpe/categoryselect.h>
29#include <qpe/menubutton.h> 29#include <qpe/menubutton.h>
30#include <qpe/resource.h> 30#include <qpe/resource.h>
31#include <qpe/qpetoolbar.h> 31#include <qpe/qpetoolbar.h>
32 32
33#include <qtimer.h> 33#include <qtimer.h>
34#include <qdict.h> 34#include <qdict.h>
35#include <qfile.h> 35#include <qfile.h>
36#include <qfileinfo.h> 36#include <qfileinfo.h>
37#include <qhbox.h> 37#include <qhbox.h>
38#include <qiconview.h> 38#include <qiconview.h>
39#include <qpainter.h> 39#include <qpainter.h>
40#include <qregexp.h> 40#include <qregexp.h>
41#include <qtoolbutton.h> 41#include <qtoolbutton.h>
42 42
43class LauncherIconView : public QIconView { 43class LauncherIconView : public QIconView {
44public: 44public:
45 QColor iconText;
46 QColor background;
47
45 LauncherIconView( QWidget* parent, const char* name=0 ) : 48 LauncherIconView( QWidget* parent, const char* name=0 ) :
46 QIconView(parent,name), 49 QIconView(parent,name),
47 tf(""), 50 tf(""),
48 cf(0), 51 cf(0),
49 bsy(0) 52 bsy(0)
50 { 53 {
51 sortmeth = Name; 54 sortmeth = Name;
52 hidden.setAutoDelete(TRUE); 55 hidden.setAutoDelete(TRUE);
53 ike = FALSE; 56 ike = FALSE;
57
58 Config config( "qpe" );
59 config.setGroup( "Appearance" );
60 iconText = QColor( config.readEntry( "LauncherIconText", "#000000" ) );
61 background = QColor( config.readEntry( "LauncherBackground", "#FFFFFF" ) );
54 } 62 }
55 63
56 ~LauncherIconView() 64 ~LauncherIconView()
57 { 65 {
58#if 0 // debuggery 66#if 0 // debuggery
59 QListIterator<AppLnk> it(hidden); 67 QListIterator<AppLnk> it(hidden);
60 AppLnk* l; 68 AppLnk* l;
61 while ((l=it.current())) { 69 while ((l=it.current())) {
62 ++it; 70 ++it;
63 //qDebug("%p: hidden (should remove)",l); 71 //qDebug("%p: hidden (should remove)",l);
64 } 72 }
65#endif 73#endif
66 } 74 }
67 75
68 QIconViewItem* busyItem() const { return bsy; } 76 QIconViewItem* busyItem() const { return bsy; }
69 77
70 void updateCategoriesAndMimeTypes(); 78 void updateCategoriesAndMimeTypes();
71 79
72 void doAutoScroll() 80 void doAutoScroll()
73 { 81 {
74 // We don't want rubberbanding (yet) 82 // We don't want rubberbanding (yet)
75 } 83 }
76 84
77 void setBusy(bool on) 85 void setBusy(bool on)
78 { 86 {
79 QIconViewItem *c = on ? currentItem() : 0; 87 QIconViewItem *c = on ? currentItem() : 0;
80 if ( bsy != c ) { 88 if ( bsy != c ) {
81 QIconViewItem* o = bsy; 89 QIconViewItem* o = bsy;
82 bsy = c; 90 bsy = c;
83 if ( o ) o->repaint(); 91 if ( o ) o->repaint();
84 if ( c ) c->repaint(); 92 if ( c ) c->repaint();
85 } 93 }
86 } 94 }
87 95
88 bool inKeyEvent() const { return ike; } 96 bool inKeyEvent() const { return ike; }
89 void keyPressEvent(QKeyEvent* e) 97 void keyPressEvent(QKeyEvent* e)
90 { 98 {
91 ike = TRUE; 99 ike = TRUE;
92 if ( e->key() == Key_F33 ) { 100 if ( e->key() == Key_F33 ) {
93 // "OK" button 101 // "OK" button
94 returnPressed(currentItem()); 102 returnPressed(currentItem());
95 } 103 }
96 QIconView::keyPressEvent(e); 104 QIconView::keyPressEvent(e);
97 ike = FALSE; 105 ike = FALSE;
98 } 106 }
99 107
100 void addItem(AppLnk* app, bool resort=TRUE); 108 void addItem(AppLnk* app, bool resort=TRUE);
101 bool removeLink(const QString& linkfile); 109 bool removeLink(const QString& linkfile);
102 110
103 QStringList mimeTypes() const; 111 QStringList mimeTypes() const;
104 QStringList categories() const; 112 QStringList categories() const;
105 113
106 void clear() 114 void clear()
107 { 115 {
108 mimes.clear(); 116 mimes.clear();
109 cats.clear(); 117 cats.clear();
110 QIconView::clear(); 118 QIconView::clear();
111 hidden.clear(); 119 hidden.clear();
112 } 120 }
113 121
114 void addCatsAndMimes(AppLnk* app) 122 void addCatsAndMimes(AppLnk* app)
115 { 123 {
116 // QStringList c = app->categories(); 124 // QStringList c = app->categories();
117 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { 125 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) {
118 // cats.replace(*cit,(void*)1); 126 // cats.replace(*cit,(void*)1);
119 // } 127 // }
120 QString maj=app->type(); 128 QString maj=app->type();
121 int sl=maj.find('/'); 129 int sl=maj.find('/');
122 if (sl>=0) { 130 if (sl>=0) {
123 QString k = maj.left(sl); 131 QString k = maj.left(sl);
124 mimes.replace(k,(void*)1); 132 mimes.replace(k,(void*)1);
125 } 133 }
126 } 134 }
127 135
128 void drawBackground( QPainter *p, const QRect &r ) 136 void drawBackground( QPainter *p, const QRect &r )
129 { 137 {
130 Config config("qpe"); 138 Config config("qpe");
131 config.setGroup("Appearance"); 139 config.setGroup("Appearance");
132 QString backgroundImage = config.readEntry("BackgroundImage","launcher/opie-background"); 140 QString backgroundImage = config.readEntry("BackgroundImage","launcher/opie-background");
133 // if (backgroundImage.isNull()) backgroundImage="launcher/opie-background"; 141 // if (backgroundImage.isNull()) backgroundImage="launcher/opie-background";
134 int backgroundMode = QPixmap::defaultDepth() >= 12 ? 1 : 0; 142 int backgroundMode = QPixmap::defaultDepth() >= 12 ? 1 : 0;
135 //int backgroundMode = 2; 143 //int backgroundMode = 2;
136 144
137 if ( backgroundMode == 1 ) { 145 if ( backgroundMode == 1 ) {
138 146
139 // Double buffer the background 147 // Double buffer the background
140 static QPixmap *bg = NULL; 148 static QPixmap *bg = NULL;
141 static QColor bgColor; 149 static QColor bgColor;
142 150
143 if ( (bg == NULL) || (bgColor != colorGroup().button()) ) { 151 if ( (bg == NULL) || (bgColor != colorGroup().button()) ) {
144 // Create a new background double buffer 152 // Create a new background double buffer
145 if (bg == NULL) 153 if (bg == NULL)
146 bg = new QPixmap( width(), height() ); 154 bg = new QPixmap( width(), height() );
147 bgColor = colorGroup().button(); 155 bgColor = colorGroup().button();
148 QPainter painter( bg ); 156 QPainter painter( bg );
149 157
150 painter.fillRect( QRect( 0, 0, width(), height() ), colorGroup().background().light(110)); 158// painter.fillRect( QRect( 0, 0, width(), height() ), colorGroup().background().light(110));
159 painter.fillRect( QRect( 0, 0, width(), height() ), background);
151 // Overlay the Qtopia logo in the center 160 // Overlay the Qtopia logo in the center
152 QImage logo; 161 QImage logo;
153 if (QFile::exists(backgroundImage)) { 162 if (QFile::exists(backgroundImage)) {
154 logo = QImage(backgroundImage); 163 logo = QImage(backgroundImage);
155 } else { 164 } else {
156 logo = Resource::loadImage(backgroundImage ); 165 logo = Resource::loadImage(backgroundImage );
157 } 166 }
158 if ( !logo.isNull() ) 167 if ( !logo.isNull() )
159 painter.drawImage( (width() - logo.width()) / 2, 168 painter.drawImage( (width() - logo.width()) / 2,
160 (height() - logo.height()) / 2, logo ); 169 (height() - logo.height()) / 2, logo );
161 } 170 }
162 171
163 // Draw the double buffer to the widget (it is tiled for when the icon view is large) 172 // Draw the double buffer to the widget (it is tiled for when the icon view is large)
164 p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(), 173 p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(),
165 (r.y() + contentsY()) % bg->height() ) ); 174 (r.y() + contentsY()) % bg->height() ) );
166 } else if ( backgroundMode == 2 ) { 175 } else if ( backgroundMode == 2 ) {
167 static QPixmap *bg = 0; 176 static QPixmap *bg = 0;
168 static QColor bgColor; 177 static QColor bgColor;
169 if ( !bg || (bgColor != colorGroup().background()) ) { 178 if ( !bg || (bgColor != colorGroup().background()) ) {
170 bgColor = colorGroup().background(); 179 bgColor = colorGroup().background();
171 bg = new QPixmap( width(), 9 ); 180 bg = new QPixmap( width(), 9 );
172 QPainter painter( bg ); 181 QPainter painter( bg );
173 for ( int i = 0; i < 3; i++ ) { 182 for ( int i = 0; i < 3; i++ ) {
174 painter.setPen( colorGroup().background().light(130) ); 183 painter.setPen( colorGroup().background().light(130) );
175 painter.drawLine( 0, i*3, width()-1, i*3 ); 184 painter.drawLine( 0, i*3, width()-1, i*3 );
176 painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); 185 painter.drawLine( 0, i*3+1, width()-1, i*3+1 );
177 painter.setPen( colorGroup().background().light(105) ); 186 painter.setPen( colorGroup().background().light(105) );
178 painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); 187 painter.drawLine( 0, i*3+2, width()-1, i*3+2 );
179 } 188 }
180 } 189 }
181 p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(), 190 p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(),
182 (r.y() + contentsY()) % bg->height() ) ); 191 (r.y() + contentsY()) % bg->height() ) );
183 } else { 192 } else {
184 p->fillRect( r, QBrush( colorGroup().background().light(110) ) ); 193 p->fillRect( r, QBrush( colorGroup().background().light(110) ) );
185 } 194 }
186 } 195 }
187 196
188 void hideOrShowItems(bool resort); 197 void hideOrShowItems(bool resort);
189 198
190 void setTypeFilter(const QString& typefilter, bool resort) 199 void setTypeFilter(const QString& typefilter, bool resort)
191 { 200 {
192 tf = QRegExp(typefilter,FALSE,TRUE); 201 tf = QRegExp(typefilter,FALSE,TRUE);
193 hideOrShowItems(resort); 202 hideOrShowItems(resort);
194 } 203 }
195 204
196 void setCategoryFilter( int catfilter, bool resort ) 205 void setCategoryFilter( int catfilter, bool resort )
197 { 206 {
198 Categories cat; 207 Categories cat;
@@ -242,96 +251,100 @@ protected:
242 } 251 }
243 252
244private: 253private:
245 QList<AppLnk> hidden; 254 QList<AppLnk> hidden;
246 QDict<void> mimes; 255 QDict<void> mimes;
247 QDict<void> cats; 256 QDict<void> cats;
248 SortMethod sortmeth; 257 SortMethod sortmeth;
249 QRegExp tf; 258 QRegExp tf;
250 int cf; 259 int cf;
251 QIconViewItem* bsy; 260 QIconViewItem* bsy;
252 bool ike; 261 bool ike;
253 262
254}; 263};
255 264
256 265
257bool LauncherView::bsy=FALSE; 266bool LauncherView::bsy=FALSE;
258 267
259void LauncherView::setBusy(bool on) 268void LauncherView::setBusy(bool on)
260{ 269{
261 icons->setBusy(on); 270 icons->setBusy(on);
262} 271}
263 272
264class LauncherItem : public QIconViewItem 273class LauncherItem : public QIconViewItem
265{ 274{
266public: 275public:
267 LauncherItem( QIconView *parent, AppLnk* applnk ); 276 LauncherItem( QIconView *parent, AppLnk* applnk );
268 ~LauncherItem() 277 ~LauncherItem()
269 { 278 {
270 LauncherIconView* liv = (LauncherIconView*)iconView(); 279 LauncherIconView* liv = (LauncherIconView*)iconView();
271 if ( liv->busyItem() == this ) 280 if ( liv->busyItem() == this )
272 liv->setBusy(FALSE); 281 liv->setBusy(FALSE);
273 delete app; 282 delete app;
274 } 283 }
275 284
276 AppLnk* appLnk() const { return app; } 285 AppLnk* appLnk() const { return app; }
277 AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; } 286 AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; }
278 287
279 virtual int compare ( QIconViewItem * i ) const; 288 virtual int compare ( QIconViewItem * i ) const;
280 289
281 void paintItem( QPainter *p, const QColorGroup &cg ) 290 void paintItem( QPainter *p, const QColorGroup &cg )
282 { 291 {
283 LauncherIconView* liv = (LauncherIconView*)iconView(); 292 LauncherIconView* liv = (LauncherIconView*)iconView();
284 QBrush oldBrush( liv->itemTextBackground() ); 293 QBrush oldBrush( liv->itemTextBackground() );
285 QColorGroup mycg( cg ); 294 QColorGroup mycg( cg );
286 if ( liv->currentItem() == this ) { 295 if ( liv->currentItem() == this ) {
287 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); 296 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) );
288 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); 297 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) );
289 } 298 }
299 else {
300 mycg.setColor( QColorGroup::Text, liv->iconText );
301 }
302
290 QIconViewItem::paintItem(p,mycg); 303 QIconViewItem::paintItem(p,mycg);
291 if ( liv->currentItem() == this ) 304 if ( liv->currentItem() == this )
292 liv->setItemTextBackground( oldBrush ); 305 liv->setItemTextBackground( oldBrush );
293 if ( liv->busyItem() == this ) { 306 if ( liv->busyItem() == this ) {
294 static QPixmap* busypm=0; 307 static QPixmap* busypm=0;
295 if ( !busypm ) 308 if ( !busypm )
296 busypm = new QPixmap(Resource::loadPixmap("launching")); 309 busypm = new QPixmap(Resource::loadPixmap("launching"));
297 p->drawPixmap(x()+(width()-busypm->width())/2, y(),*busypm); 310 p->drawPixmap(x()+(width()-busypm->width())/2, y(),*busypm);
298 } 311 }
299 } 312 }
300 313
301protected: 314protected:
302 AppLnk* app; 315 AppLnk* app;
303}; 316};
304 317
305 318
306LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk ) 319LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk )
307 : QIconViewItem( parent, applnk->name(), applnk->bigPixmap() ), 320 : QIconViewItem( parent, applnk->name(), applnk->bigPixmap() ),
308 app(applnk) // Takes ownership 321 app(applnk) // Takes ownership
309{ 322{
310} 323}
311 324
312int LauncherItem::compare ( QIconViewItem * i ) const 325int LauncherItem::compare ( QIconViewItem * i ) const
313{ 326{
314 LauncherIconView* view = (LauncherIconView*)iconView(); 327 LauncherIconView* view = (LauncherIconView*)iconView();
315 return view->compare(app,((LauncherItem *)i)->appLnk()); 328 return view->compare(app,((LauncherItem *)i)->appLnk());
316} 329}
317 330
318QStringList LauncherIconView::mimeTypes() const 331QStringList LauncherIconView::mimeTypes() const
319{ 332{
320 QStringList r; 333 QStringList r;
321 QDictIterator<void> it(mimes); 334 QDictIterator<void> it(mimes);
322 while (it.current()) { 335 while (it.current()) {
323 r.append(it.currentKey()); 336 r.append(it.currentKey());
324 ++it; 337 ++it;
325 } 338 }
326 r.sort(); 339 r.sort();
327 return r; 340 return r;
328} 341}
329 342
330void LauncherIconView::addItem(AppLnk* app, bool resort) 343void LauncherIconView::addItem(AppLnk* app, bool resort)
331{ 344{
332 addCatsAndMimes(app); 345 addCatsAndMimes(app);
333 346
334 if ( (tf.isEmpty() || tf.match(app->type()) >= 0) 347 if ( (tf.isEmpty() || tf.match(app->type()) >= 0)
335 && (cf == 0 || app->categories().contains(cf) 348 && (cf == 0 || app->categories().contains(cf)
336 || cf == -1 && app->categories().count() == 0 ) ) 349 || cf == -1 && app->categories().count() == 0 ) )
337 (void) new LauncherItem( this, app ); 350 (void) new LauncherItem( this, app );