summaryrefslogtreecommitdiff
path: root/noncore
authordrw <drw>2005-03-08 21:50:02 (UTC)
committer drw <drw>2005-03-08 21:50:02 (UTC)
commit2b32d3e15f5774ee8f73977d606675e819498614 (patch) (unidiff)
treee30982f7bfdf36bb8bfc2e3762c2d9234b809607 /noncore
parentd32769dbeedb21fd7bdafb1c762e4e501cb02961 (diff)
downloadopie-2b32d3e15f5774ee8f73977d606675e819498614.zip
opie-2b32d3e15f5774ee8f73977d606675e819498614.tar.gz
opie-2b32d3e15f5774ee8f73977d606675e819498614.tar.bz2
Better version of icon
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/notesapplet/notes.cpp76
1 files changed, 23 insertions, 53 deletions
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp
index b3e72a7..d06672a 100644
--- a/noncore/applets/notesapplet/notes.cpp
+++ b/noncore/applets/notesapplet/notes.cpp
@@ -21,12 +21,13 @@
21#include <qpe/filemanager.h> 21#include <qpe/filemanager.h>
22#include <qpe/qpeapplication.h> 22#include <qpe/qpeapplication.h>
23#include <qpe/timestring.h> 23#include <qpe/timestring.h>
24#include <qpe/applnk.h> 24#include <qpe/applnk.h>
25#include <qpe/ir.h> 25#include <qpe/ir.h>
26#include <qpe/config.h> 26#include <qpe/config.h>
27#include <qpe/resource.h>
27using namespace Opie::Core; 28using namespace Opie::Core;
28using namespace Opie::Ui; 29using namespace Opie::Ui;
29 30
30/* QT */ 31/* QT */
31#include <qmultilineedit.h> 32#include <qmultilineedit.h>
32#include <qlistbox.h> 33#include <qlistbox.h>
@@ -45,53 +46,21 @@ using namespace Opie::Ui;
45#include <qstringlist.h> 46#include <qstringlist.h>
46#include <qtimer.h> 47#include <qtimer.h>
47 48
48/* STD */ 49/* STD */
49#include <stdlib.h> 50#include <stdlib.h>
50 51
51/* XPM */
52static char * notes_xpm[] = {
53"16 16 11 1",
54" c None",
55". c #000000",
56"+ c #7F7F7F",
57"@ c #BFBFBF",
58"# c #BFC1FF",
59"$ c #FF0000",
60"% c #FFFFFF",
61"& c #00037F",
62"* c #0006FF",
63"= c #0005BF",
64"- c #7F0000",
65" .. ",
66" .. ",
67" ... ",
68" .+ ",
69" .@. ",
70" . .+ ",
71" ..#.@. ",
72" ..###.+.. ",
73" ..###$...##.. ",
74"..###$$$%+$$##&.",
75".*=####$-###&=&.",
76".=**=###==&=&=..",
77" ..=**=#&=&=.. ",
78" ..=*=&=.. ",
79" ..=.. ",
80" . "};
81
82
83NotesControl::NotesControl( QWidget *, const char * ) 52NotesControl::NotesControl( QWidget *, const char * )
84 : QVBox( 0, "NotesControl",/* WDestructiveClose | */WStyle_StaysOnTop ) 53 : QVBox( 0, "NotesControl",/* WDestructiveClose | */WStyle_StaysOnTop )
85// : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) 54// : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
86{ 55{
87 QDir d( QDir::homeDirPath()+"/notes"); 56 QDir d( QDir::homeDirPath()+"/notes");
88 if( !d.exists()) { 57 if( !d.exists()) {
89 odebug << "make dir" << oendl; 58 odebug << "make dir" << oendl;
90 if(!d.mkdir( QDir::homeDirPath()+"/notes", true)) 59 if(!d.mkdir( QDir::homeDirPath()+"/notes", true))
91 odebug << "<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed" << oendl; 60 odebug << "<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed" << oendl;
92 } 61 }
93 Config cfg("Notes"); 62 Config cfg("Notes");
94 cfg.setGroup("Options"); 63 cfg.setGroup("Options");
95 showMax = cfg.readBoolEntry("ShowMax", false); 64 showMax = cfg.readBoolEntry("ShowMax", false);
96 65
97 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 66 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
@@ -164,43 +133,43 @@ void NotesControl::slotDeleteButtonClicked() {
164 }; 133 };
165} 134}
166 135
167void NotesControl::slotDeleteButton() { 136void NotesControl::slotDeleteButton() {
168 137
169 QString selectedText = box->currentText(); 138 QString selectedText = box->currentText();
170 odebug << "deleting "+selectedText << oendl; 139 odebug << "deleting "+selectedText << oendl;
171 140
172 if( !selectedText.isEmpty()) { 141 if( !selectedText.isEmpty()) {
173 142
174 Config cfg("Notes"); 143 Config cfg("Notes");
175 cfg.setGroup("Docs"); 144 cfg.setGroup("Docs");
176 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 145 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
177 QString entryName, entryName2;; 146 QString entryName, entryName2;;
178 for ( int i = 0; i < noOfFiles; i++ ) { 147 for ( int i = 0; i < noOfFiles; i++ ) {
179 entryName.sprintf( "File%i", i + 1 ); 148 entryName.sprintf( "File%i", i + 1 );
180 if(selectedText == cfg.readEntry( entryName )) { 149 if(selectedText == cfg.readEntry( entryName )) {
181 odebug << "removing " << selectedText.latin1() << ", " << i << "" << oendl; 150 odebug << "removing " << selectedText.latin1() << ", " << i << "" << oendl;
182 for ( int j = i; j < noOfFiles; j++ ) { 151 for ( int j = i; j < noOfFiles; j++ ) {
183 entryName.sprintf( "File%i", i + 1 ); 152 entryName.sprintf( "File%i", i + 1 );
184 entryName2.sprintf( "File%i", i + 2 ); 153 entryName2.sprintf( "File%i", i + 2 );
185 QString temp = cfg.readEntry(entryName2); 154 QString temp = cfg.readEntry(entryName2);
186 odebug << "move "+temp << oendl; 155 odebug << "move "+temp << oendl;
187 cfg.writeEntry(entryName, temp); 156 cfg.writeEntry(entryName, temp);
188 i++; 157 i++;
189 } 158 }
190 cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); 159 cfg.writeEntry("NumberOfFiles", noOfFiles-1 );
191 entryName.sprintf( "File%i", noOfFiles ); 160 entryName.sprintf( "File%i", noOfFiles );
192 cfg.removeEntry(entryName); 161 cfg.removeEntry(entryName);
193 cfg.write(); 162 cfg.write();
194 DocLnk nf(selectedText); 163 DocLnk nf(selectedText);
195 nf.removeFiles(); 164 nf.removeFiles();
196 QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop"; 165 QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop";
197 odebug << fi << oendl; 166 odebug << fi << oendl;
198 167
199 QFile f( fi); 168 QFile f( fi);
200 if( !f.remove()) odebug << ".desktop file not removed" << oendl; 169 if( !f.remove()) odebug << ".desktop file not removed" << oendl;
201 170
202 } 171 }
203 } 172 }
204 view->clear(); 173 view->clear();
205 174
206 populateBox(); 175 populateBox();
@@ -282,13 +251,13 @@ void NotesControl::focusOutEvent ( QFocusEvent * e) {
282} 251}
283 252
284void NotesControl::save() { 253void NotesControl::save() {
285 Config cfg("Notes"); 254 Config cfg("Notes");
286 cfg.setGroup("Docs"); 255 cfg.setGroup("Docs");
287 if( edited) { 256 if( edited) {
288// odebug << "is edited" << oendl; 257// odebug << "is edited" << oendl;
289 QString rt = view->text(); 258 QString rt = view->text();
290 if( rt.length()>1) { 259 if( rt.length()>1) {
291 QString pt = rt.simplifyWhiteSpace(); 260 QString pt = rt.simplifyWhiteSpace();
292 int i = pt.find( ' ', pt.find( ' ' )+2 ); 261 int i = pt.find( ' ', pt.find( ' ' )+2 );
293 QString docname = pt; 262 QString docname = pt;
294 if ( i > 0 ) 263 if ( i > 0 )
@@ -300,51 +269,51 @@ void NotesControl::save() {
300 // cut the length. filenames longer than that don't make sense 269 // cut the length. filenames longer than that don't make sense
301 // and something goes wrong when they get too long. 270 // and something goes wrong when they get too long.
302 if ( docname.length() > 40 ) 271 if ( docname.length() > 40 )
303 docname = docname.left(40); 272 docname = docname.left(40);
304 if ( docname.isEmpty() ) 273 if ( docname.isEmpty() )
305 docname = "Empty Text"; 274 docname = "Empty Text";
306// odebug << docname << oendl; 275// odebug << docname << oendl;
307 276
308 if( oldDocName != docname) { 277 if( oldDocName != docname) {
309 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 278 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
310 QString entryName; 279 QString entryName;
311 entryName.sprintf( "File%i", noOfFiles + 1 ); 280 entryName.sprintf( "File%i", noOfFiles + 1 );
312 cfg.writeEntry( entryName,docname ); 281 cfg.writeEntry( entryName,docname );
313 cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); 282 cfg.writeEntry("NumberOfFiles", noOfFiles+1 );
314 cfg.write(); 283 cfg.write();
315 } 284 }
316// else 285// else
317// odebug << "oldname equals docname" << oendl; 286// odebug << "oldname equals docname" << oendl;
318 287
319 doc = new DocLnk(docname); 288 doc = new DocLnk(docname);
320 if(QFile(doc->linkFile()).exists()) 289 if(QFile(doc->linkFile()).exists())
321 odebug << "puppie" << oendl; 290 odebug << "puppie" << oendl;
322 doc->setType("text/plain"); 291 doc->setType("text/plain");
323 doc->setName(docname); 292 doc->setName(docname);
324 QString temp = docname.replace( QRegExp(" "), "_" ); 293 QString temp = docname.replace( QRegExp(" "), "_" );
325 doc->setFile( QDir::homeDirPath()+"/notes/"+temp); 294 doc->setFile( QDir::homeDirPath()+"/notes/"+temp);
326 FileManager fm; 295 FileManager fm;
327 if ( !fm.saveFile( *doc, rt ) ) { 296 if ( !fm.saveFile( *doc, rt ) ) {
328 } 297 }
329 298
330 oldDocName=docname; 299 oldDocName=docname;
331 edited=false; 300 edited=false;
332// odebug << "save" << oendl; 301// odebug << "save" << oendl;
333 if (doPopulate) 302 if (doPopulate)
334 populateBox(); 303 populateBox();
335 } 304 }
336 cfg.writeEntry( "LastDoc",oldDocName ); 305 cfg.writeEntry( "LastDoc",oldDocName );
337 cfg.write(); 306 cfg.write();
338 307
339 } 308 }
340} 309}
341 310
342void NotesControl::populateBox() { 311void NotesControl::populateBox() {
343 box->clear(); 312 box->clear();
344// odebug << "populate" << oendl; 313// odebug << "populate" << oendl;
345 Config cfg("Notes"); 314 Config cfg("Notes");
346 cfg.setGroup("Docs"); 315 cfg.setGroup("Docs");
347 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 316 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
348 QStringList list; 317 QStringList list;
349 QString entryName; 318 QString entryName;
350 for ( int i = 0; i < noOfFiles; i++ ) { 319 for ( int i = 0; i < noOfFiles; i++ ) {
@@ -373,13 +342,13 @@ void NotesControl::load() {
373 cfg.writeEntry( "LastDoc",oldDocName ); 342 cfg.writeEntry( "LastDoc",oldDocName );
374 cfg.write(); 343 cfg.write();
375 } 344 }
376} 345}
377 346
378void NotesControl::load(const QString & file) { 347void NotesControl::load(const QString & file) {
379 odebug << "loading "+file << oendl; 348 odebug << "loading "+file << oendl;
380 QString name = file; 349 QString name = file;
381 QString temp; 350 QString temp;
382 if( !QFile( QDir::homeDirPath()+"/"+file).exists() ) 351 if( !QFile( QDir::homeDirPath()+"/"+file).exists() )
383 temp = QDir::homeDirPath()+"/notes/"+ name.replace( QRegExp(" "), "_" ); 352 temp = QDir::homeDirPath()+"/notes/"+ name.replace( QRegExp(" "), "_" );
384 else 353 else
385 temp = name; 354 temp = name;
@@ -400,13 +369,13 @@ void NotesControl::load(const QString & file) {
400} 369}
401 370
402void NotesControl::loadDoc( const DocLnk &f) { 371void NotesControl::loadDoc( const DocLnk &f) {
403 FileManager fm; 372 FileManager fm;
404 QString txt; 373 QString txt;
405 if ( !fm.loadFile( f, txt ) ) { 374 if ( !fm.loadFile( f, txt ) ) {
406 odebug << "could not load file "+f.file() << oendl; 375 odebug << "could not load file "+f.file() << oendl;
407 return; 376 return;
408 } 377 }
409 view->setText(txt); 378 view->setText(txt);
410} 379}
411 380
412void NotesControl::slotViewEdited() { 381void NotesControl::slotViewEdited() {
@@ -434,13 +403,13 @@ void NotesControl::slotSearch() {
434 403
435// void NotesControl::keyReleaseEvent( QKeyEvent *e) { 404// void NotesControl::keyReleaseEvent( QKeyEvent *e) {
436 405
437// switch ( e->state() ) { 406// switch ( e->state() ) {
438// case ControlButton: 407// case ControlButton:
439// if(e->key() == Key_C) { //copy 408// if(e->key() == Key_C) { //copy
440// odebug << "copy" << oendl; 409// odebug << "copy" << oendl;
441// QClipboard *cb = QApplication::clipboard(); 410// QClipboard *cb = QApplication::clipboard();
442// QString text; 411// QString text;
443 412
444// // Copy text from the clipboard (paste) 413// // Copy text from the clipboard (paste)
445// text = cb->text(); 414// text = cb->text();
446// } 415// }
@@ -458,14 +427,15 @@ void NotesControl::slotSearch() {
458// } 427// }
459 428
460//=========================================================================== 429//===========================================================================
461 430
462NotesApplet::NotesApplet( QWidget *parent, const char *name ) 431NotesApplet::NotesApplet( QWidget *parent, const char *name )
463 : QWidget( parent, name ) { 432 : QWidget( parent, name ) {
464 setFixedHeight( 18 ); 433 setFixedHeight( AppLnk::smallIconSize() );
465 setFixedWidth( 14 ); 434 setFixedWidth( AppLnk::smallIconSize() );
435 notesPixmap.convertFromImage( Resource::loadImage( "edit" ).smoothScale( height(), width() ) );
466 vc = new NotesControl; 436 vc = new NotesControl;
467} 437}
468 438
469NotesApplet::~NotesApplet() { 439NotesApplet::~NotesApplet() {
470 delete vc; 440 delete vc;
471} 441}
@@ -481,16 +451,16 @@ void NotesApplet::mousePressEvent( QMouseEvent *) {
481 vc->save(); 451 vc->save();
482 vc->close(); 452 vc->close();
483 } else { 453 } else {
484// vc = new NotesControl; 454// vc = new NotesControl;
485// QPoint curPos = mapToGlobal( rect().topLeft() ); 455// QPoint curPos = mapToGlobal( rect().topLeft() );
486 if(vc->showMax) { 456 if(vc->showMax) {
487 odebug << "show max" << oendl; 457 odebug << "show max" << oendl;
488 vc->showMaximized(); 458 vc->showMaximized();
489 } else { 459 } else {
490 odebug << "no show max" << oendl; 460 odebug << "no show max" << oendl;
491 QWidget *wid = QPEApplication::desktop(); 461 QWidget *wid = QPEApplication::desktop();
492 QRect rect = QApplication::desktop()->geometry(); 462 QRect rect = QApplication::desktop()->geometry();
493 vc->setGeometry( ( wid->width() / 2) - ( vc->width() / 2 ) , 28 , wid->width() -10 , 180); 463 vc->setGeometry( ( wid->width() / 2) - ( vc->width() / 2 ) , 28 , wid->width() -10 , 180);
494 vc->move ( (rect.center()/2) - (vc->rect().center()/2)); 464 vc->move ( (rect.center()/2) - (vc->rect().center()/2));
495// vc->move( (( wid->width() / 2) - ( vc->width() / 2 ))-4, 28); 465// vc->move( (( wid->width() / 2) - ( vc->width() / 2 ))-4, 28);
496 } 466 }
@@ -505,12 +475,12 @@ void NotesApplet::mousePressEvent( QMouseEvent *) {
505 vc->view->setFocus(); 475 vc->view->setFocus();
506 } 476 }
507} 477}
508 478
509void NotesApplet::paintEvent( QPaintEvent* ) { 479void NotesApplet::paintEvent( QPaintEvent* ) {
510 QPainter p(this); 480 QPainter p(this);
511 p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); 481 p.drawPixmap( 0, 2, notesPixmap );
512} 482}
513 483
514 484
515EXPORT_OPIE_APPLET_v1( NotesApplet ) 485EXPORT_OPIE_APPLET_v1( NotesApplet )
516 486