author | mickeyl <mickeyl> | 2004-03-01 21:10:13 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-03-01 21:10:13 (UTC) |
commit | 77af6f58d59011e123309c82b684695508a46787 (patch) (unidiff) | |
tree | 1eeb3b323bc14581af7da9fe5b58c4c611b00575 /noncore/applets/notesapplet | |
parent | 7b0bdb05e4ae29b2643d73e3b8f20a86a86dcccc (diff) | |
download | opie-77af6f58d59011e123309c82b684695508a46787.zip opie-77af6f58d59011e123309c82b684695508a46787.tar.gz opie-77af6f58d59011e123309c82b684695508a46787.tar.bz2 |
remove boiler plate code in favour of a template
-rw-r--r-- | noncore/applets/notesapplet/notes.cpp | 10 | ||||
-rw-r--r-- | noncore/applets/notesapplet/notes.h | 1 | ||||
-rw-r--r-- | noncore/applets/notesapplet/notesapplet.pro | 8 | ||||
-rw-r--r-- | noncore/applets/notesapplet/notesappletimpl.cpp | 53 | ||||
-rw-r--r-- | noncore/applets/notesapplet/notesappletimpl.h | 35 |
5 files changed, 13 insertions, 94 deletions
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp index 7b8bdd9..1142028 100644 --- a/noncore/applets/notesapplet/notes.cpp +++ b/noncore/applets/notesapplet/notes.cpp | |||
@@ -1,69 +1,70 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org> | 2 | ** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org> |
3 | 3 | ||
4 | ** All rights reserved. | 4 | ** All rights reserved. |
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 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #include "notes.h" | 16 | #include "notes.h" |
17 | 17 | ||
18 | #include <qapplication.h> | 18 | #include <qapplication.h> |
19 | #include <stdlib.h> | 19 | #include <stdlib.h> |
20 | #include <qstringlist.h> | 20 | #include <qstringlist.h> |
21 | 21 | ||
22 | #include <opie2/otaskbarapplet.h> | ||
22 | #include <qpe/filemanager.h> | 23 | #include <qpe/filemanager.h> |
23 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
24 | #include <qpe/timestring.h> | 25 | #include <qpe/timestring.h> |
25 | #include <qpe/applnk.h> | 26 | #include <qpe/applnk.h> |
26 | #include <qpe/ir.h> | 27 | #include <qpe/ir.h> |
27 | #include <qpe/config.h> | 28 | #include <qpe/config.h> |
28 | 29 | ||
29 | // #include <qsocket.h> | 30 | // #include <qsocket.h> |
30 | // #include <qclipboard.h> | 31 | // #include <qclipboard.h> |
31 | #include <qmultilineedit.h> | 32 | #include <qmultilineedit.h> |
32 | #include <qlistbox.h> | 33 | #include <qlistbox.h> |
33 | #include <qpopupmenu.h> | 34 | #include <qpopupmenu.h> |
34 | #include <qmessagebox.h> | 35 | #include <qmessagebox.h> |
35 | 36 | ||
36 | #include <qdir.h> | 37 | #include <qdir.h> |
37 | #include <qfile.h> | 38 | #include <qfile.h> |
38 | #include <qpoint.h> | 39 | #include <qpoint.h> |
39 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
40 | #include <qpainter.h> | 41 | #include <qpainter.h> |
41 | #include <qlayout.h> | 42 | #include <qlayout.h> |
42 | #include <qframe.h> | 43 | #include <qframe.h> |
43 | #include <qpixmap.h> | 44 | #include <qpixmap.h> |
44 | #include <qstring.h> | 45 | #include <qstring.h> |
45 | #include <qtimer.h> | 46 | #include <qtimer.h> |
46 | 47 | ||
47 | /* XPM */ | 48 | /* XPM */ |
48 | static char * notes_xpm[] = { | 49 | static char * notes_xpm[] = { |
49 | "16 16 11 1", | 50 | "16 16 11 1", |
50 | " c None", | 51 | " c None", |
51 | ". c #000000", | 52 | ". c #000000", |
52 | "+ c #7F7F7F", | 53 | "+ c #7F7F7F", |
53 | "@ c #BFBFBF", | 54 | "@ c #BFBFBF", |
54 | "# c #BFC1FF", | 55 | "# c #BFC1FF", |
55 | "$ c #FF0000", | 56 | "$ c #FF0000", |
56 | "% c #FFFFFF", | 57 | "% c #FFFFFF", |
57 | "& c #00037F", | 58 | "& c #00037F", |
58 | "* c #0006FF", | 59 | "* c #0006FF", |
59 | "= c #0005BF", | 60 | "= c #0005BF", |
60 | "- c #7F0000", | 61 | "- c #7F0000", |
61 | " .. ", | 62 | " .. ", |
62 | " .. ", | 63 | " .. ", |
63 | " ... ", | 64 | " ... ", |
64 | " .+ ", | 65 | " .+ ", |
65 | " .@. ", | 66 | " .@. ", |
66 | " . .+ ", | 67 | " . .+ ", |
67 | " ..#.@. ", | 68 | " ..#.@. ", |
68 | " ..###.+.. ", | 69 | " ..###.+.. ", |
69 | " ..###$...##.. ", | 70 | " ..###$...##.. ", |
@@ -421,84 +422,93 @@ void NotesControl::slotShowMax() { | |||
421 | hide(); | 422 | hide(); |
422 | } | 423 | } |
423 | 424 | ||
424 | void NotesControl::slotSearch() { | 425 | void NotesControl::slotSearch() { |
425 | int boxCount = box->count(); | 426 | int boxCount = box->count(); |
426 | for(int i=0;i< boxCount;i++) { | 427 | for(int i=0;i< boxCount;i++) { |
427 | 428 | ||
428 | } | 429 | } |
429 | } | 430 | } |
430 | 431 | ||
431 | // void NotesControl::keyReleaseEvent( QKeyEvent *e) { | 432 | // void NotesControl::keyReleaseEvent( QKeyEvent *e) { |
432 | 433 | ||
433 | // switch ( e->state() ) { | 434 | // switch ( e->state() ) { |
434 | // case ControlButton: | 435 | // case ControlButton: |
435 | // if(e->key() == Key_C) { //copy | 436 | // if(e->key() == Key_C) { //copy |
436 | // qDebug("copy"); | 437 | // qDebug("copy"); |
437 | // QClipboard *cb = QApplication::clipboard(); | 438 | // QClipboard *cb = QApplication::clipboard(); |
438 | // QString text; | 439 | // QString text; |
439 | 440 | ||
440 | // // Copy text from the clipboard (paste) | 441 | // // Copy text from the clipboard (paste) |
441 | // text = cb->text(); | 442 | // text = cb->text(); |
442 | // } | 443 | // } |
443 | // if(e->key() == Key_X) { //cut | 444 | // if(e->key() == Key_X) { //cut |
444 | // } | 445 | // } |
445 | // if(e->key() == Key_V) { //paste | 446 | // if(e->key() == Key_V) { //paste |
446 | // QClipboard *cb = QApplication::clipboard(); | 447 | // QClipboard *cb = QApplication::clipboard(); |
447 | // QString text; | 448 | // QString text; |
448 | // //view | 449 | // //view |
449 | // cb->setText(); | 450 | // cb->setText(); |
450 | // } | 451 | // } |
451 | // break; | 452 | // break; |
452 | // }; | 453 | // }; |
453 | // QWidget::keyReleaseEvent(e); | 454 | // QWidget::keyReleaseEvent(e); |
454 | // } | 455 | // } |
455 | 456 | ||
456 | //=========================================================================== | 457 | //=========================================================================== |
457 | 458 | ||
458 | NotesApplet::NotesApplet( QWidget *parent, const char *name ) | 459 | NotesApplet::NotesApplet( QWidget *parent, const char *name ) |
459 | : QWidget( parent, name ) { | 460 | : QWidget( parent, name ) { |
460 | setFixedHeight( 18 ); | 461 | setFixedHeight( 18 ); |
461 | setFixedWidth( 14 ); | 462 | setFixedWidth( 14 ); |
462 | vc = new NotesControl; | 463 | vc = new NotesControl; |
463 | } | 464 | } |
464 | 465 | ||
465 | NotesApplet::~NotesApplet() { | 466 | NotesApplet::~NotesApplet() { |
466 | delete vc; | 467 | delete vc; |
467 | } | 468 | } |
468 | 469 | ||
470 | int NotesApplet::position() | ||
471 | { | ||
472 | return 6; | ||
473 | } | ||
474 | |||
469 | void NotesApplet::mousePressEvent( QMouseEvent *) { | 475 | void NotesApplet::mousePressEvent( QMouseEvent *) { |
470 | if( !vc->isHidden()) { | 476 | if( !vc->isHidden()) { |
471 | vc->doPopulate=false; | 477 | vc->doPopulate=false; |
472 | vc->save(); | 478 | vc->save(); |
473 | vc->close(); | 479 | vc->close(); |
474 | } else { | 480 | } else { |
475 | // vc = new NotesControl; | 481 | // vc = new NotesControl; |
476 | // QPoint curPos = mapToGlobal( rect().topLeft() ); | 482 | // QPoint curPos = mapToGlobal( rect().topLeft() ); |
477 | if(vc->showMax) { | 483 | if(vc->showMax) { |
478 | qDebug("show max"); | 484 | qDebug("show max"); |
479 | vc->showMaximized(); | 485 | vc->showMaximized(); |
480 | } else { | 486 | } else { |
481 | qDebug("no show max"); | 487 | qDebug("no show max"); |
482 | QWidget *wid = QPEApplication::desktop(); | 488 | QWidget *wid = QPEApplication::desktop(); |
483 | QRect rect = QApplication::desktop()->geometry(); | 489 | QRect rect = QApplication::desktop()->geometry(); |
484 | vc->setGeometry( ( wid->width() / 2) - ( vc->width() / 2 ) , 28 , wid->width() -10 , 180); | 490 | vc->setGeometry( ( wid->width() / 2) - ( vc->width() / 2 ) , 28 , wid->width() -10 , 180); |
485 | vc->move ( (rect.center()/2) - (vc->rect().center()/2)); | 491 | vc->move ( (rect.center()/2) - (vc->rect().center()/2)); |
486 | // vc->move( (( wid->width() / 2) - ( vc->width() / 2 ))-4, 28); | 492 | // vc->move( (( wid->width() / 2) - ( vc->width() / 2 ))-4, 28); |
487 | } | 493 | } |
488 | vc->show(); | 494 | vc->show(); |
489 | vc->doPopulate=true; | 495 | vc->doPopulate=true; |
490 | vc->populateBox(); | 496 | vc->populateBox(); |
491 | vc->doPopulate=false; | 497 | vc->doPopulate=false; |
492 | vc->loaded=false; | 498 | vc->loaded=false; |
493 | 499 | ||
494 | vc->load(); | 500 | vc->load(); |
495 | // this->setFocus(); | 501 | // this->setFocus(); |
496 | vc->view->setFocus(); | 502 | vc->view->setFocus(); |
497 | } | 503 | } |
498 | } | 504 | } |
499 | 505 | ||
500 | void NotesApplet::paintEvent( QPaintEvent* ) { | 506 | void NotesApplet::paintEvent( QPaintEvent* ) { |
501 | QPainter p(this); | 507 | QPainter p(this); |
502 | p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); | 508 | p.drawPixmap( 0, 1, ( const char** ) notes_xpm ); |
503 | } | 509 | } |
504 | 510 | ||
511 | Q_EXPORT_INTERFACE() | ||
512 | { | ||
513 | Q_CREATE_INSTANCE( OTaskbarAppletWrapper<NotesApplet> ); | ||
514 | } | ||
diff --git a/noncore/applets/notesapplet/notes.h b/noncore/applets/notesapplet/notes.h index 08253cb..ed1f98c 100644 --- a/noncore/applets/notesapplet/notes.h +++ b/noncore/applets/notesapplet/notes.h | |||
@@ -31,63 +31,64 @@ class QPushButton; | |||
31 | class QMultiLineEdit; | 31 | class QMultiLineEdit; |
32 | class QListBox; | 32 | class QListBox; |
33 | class QListBoxItem; | 33 | class QListBoxItem; |
34 | class NotesControl : public QVBox { | 34 | class NotesControl : public QVBox { |
35 | Q_OBJECT | 35 | Q_OBJECT |
36 | public: | 36 | public: |
37 | NotesControl( QWidget *parent=0, const char *name=0 ); | 37 | NotesControl( QWidget *parent=0, const char *name=0 ); |
38 | 38 | ||
39 | QPixmap notes; | 39 | QPixmap notes; |
40 | QMultiLineEdit *view; | 40 | QMultiLineEdit *view; |
41 | QListBox *box; | 41 | QListBox *box; |
42 | QPushButton *saveButton, *deleteButton, *newButton; | 42 | QPushButton *saveButton, *deleteButton, *newButton; |
43 | QString FileNamePath; | 43 | QString FileNamePath; |
44 | bool loaded, edited, doPopulate, isNew; | 44 | bool loaded, edited, doPopulate, isNew; |
45 | bool showMax; | 45 | bool showMax; |
46 | void save(); | 46 | void save(); |
47 | void populateBox(); | 47 | void populateBox(); |
48 | void load(); | 48 | void load(); |
49 | 49 | ||
50 | private: | 50 | private: |
51 | QTimer menuTimer; | 51 | QTimer menuTimer; |
52 | DocLnk *doc; | 52 | DocLnk *doc; |
53 | QString oldDocName; | 53 | QString oldDocName; |
54 | void focusOutEvent( QFocusEvent * ); | 54 | void focusOutEvent( QFocusEvent * ); |
55 | void load(const QString&); | 55 | void load(const QString&); |
56 | private slots: | 56 | private slots: |
57 | void slotSearch(); | 57 | void slotSearch(); |
58 | void slotShowMax(); | 58 | void slotShowMax(); |
59 | void slotBeamButton(); | 59 | void slotBeamButton(); |
60 | void slotBeamFinished( Ir*); | 60 | void slotBeamFinished( Ir*); |
61 | void slotDeleteButton(); | 61 | void slotDeleteButton(); |
62 | void slotSaveButton(); | 62 | void slotSaveButton(); |
63 | void slotDeleteButtonClicked(); | 63 | void slotDeleteButtonClicked(); |
64 | void slotNewButton(); | 64 | void slotNewButton(); |
65 | void boxPressed(int, QListBoxItem *, const QPoint&); | 65 | void boxPressed(int, QListBoxItem *, const QPoint&); |
66 | void showMenu(); | 66 | void showMenu(); |
67 | void loadDoc( const DocLnk &); | 67 | void loadDoc( const DocLnk &); |
68 | void slotViewEdited(); | 68 | void slotViewEdited(); |
69 | void slotBoxSelected(const QString &); | 69 | void slotBoxSelected(const QString &); |
70 | // void keyReleaseEvent( QKeyEvent *); | 70 | // void keyReleaseEvent( QKeyEvent *); |
71 | 71 | ||
72 | }; | 72 | }; |
73 | 73 | ||
74 | class NotesApplet : public QWidget { | 74 | class NotesApplet : public QWidget { |
75 | Q_OBJECT | 75 | Q_OBJECT |
76 | public: | 76 | public: |
77 | NotesApplet( QWidget *parent = 0, const char *name=0 ); | 77 | NotesApplet( QWidget *parent = 0, const char *name=0 ); |
78 | ~NotesApplet(); | 78 | ~NotesApplet(); |
79 | static int position(); | ||
79 | NotesControl *vc; | 80 | NotesControl *vc; |
80 | public slots: | 81 | public slots: |
81 | private: | 82 | private: |
82 | void mousePressEvent( QMouseEvent * ); | 83 | void mousePressEvent( QMouseEvent * ); |
83 | void paintEvent( QPaintEvent* ); | 84 | void paintEvent( QPaintEvent* ); |
84 | 85 | ||
85 | private: | 86 | private: |
86 | QPixmap notesPixmap; | 87 | QPixmap notesPixmap; |
87 | private slots: | 88 | private slots: |
88 | 89 | ||
89 | 90 | ||
90 | }; | 91 | }; |
91 | 92 | ||
92 | #endif // __NOTES_APPLET_H__ | 93 | #endif // __NOTES_APPLET_H__ |
93 | 94 | ||
diff --git a/noncore/applets/notesapplet/notesapplet.pro b/noncore/applets/notesapplet/notesapplet.pro index 3075948..38ba184 100644 --- a/noncore/applets/notesapplet/notesapplet.pro +++ b/noncore/applets/notesapplet/notesapplet.pro | |||
@@ -1,16 +1,12 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt plugin warn_on release | 2 | CONFIG += qt plugin warn_on release |
3 | HEADERS = notes.h notesappletimpl.h | 3 | HEADERS = notes.h |
4 | SOURCES = notes.cpp notesappletimpl.cpp | 4 | SOURCES = notes.cpp |
5 | TARGET = notesapplet | 5 | TARGET = notesapplet |
6 | DESTDIR = $(OPIEDIR)/plugins/applets | 6 | DESTDIR = $(OPIEDIR)/plugins/applets |
7 | INCLUDEPATH += $(OPIEDIR)/include | 7 | INCLUDEPATH += $(OPIEDIR)/include |
8 | DEPENDPATH += $(OPIEDIR)/include | 8 | DEPENDPATH += $(OPIEDIR)/include |
9 | LIBS += -lqpe | 9 | LIBS += -lqpe |
10 | VERSION = 1.0.0 | 10 | VERSION = 1.0.0 |
11 | MOC_DIR=opieobj | ||
12 | OBJECTS_DIR=opieobj | ||
13 | |||
14 | |||
15 | 11 | ||
16 | include ( $(OPIEDIR)/include.pro ) | 12 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/applets/notesapplet/notesappletimpl.cpp b/noncore/applets/notesapplet/notesappletimpl.cpp deleted file mode 100644 index 8a9da7f..0000000 --- a/noncore/applets/notesapplet/notesappletimpl.cpp +++ b/dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org> | ||
3 | ** | ||
4 | ** | ||
5 | ** This file may be distributed and/or modified under the terms of the | ||
6 | ** GNU General Public License version 2 as published by the Free Software | ||
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
8 | ** packaging of this file. | ||
9 | ** | ||
10 | ** | ||
11 | **********************************************************************/ | ||
12 | #include "notes.h" | ||
13 | #include "notesappletimpl.h" | ||
14 | |||
15 | |||
16 | NotesAppletImpl::NotesAppletImpl() | ||
17 | : notes(0){ | ||
18 | } | ||
19 | |||
20 | NotesAppletImpl::~NotesAppletImpl() { | ||
21 | // not needed though cause we should have a valid parent | ||
22 | delete notes; | ||
23 | } | ||
24 | |||
25 | QWidget *NotesAppletImpl::applet( QWidget *parent ) { | ||
26 | if ( !notes ) | ||
27 | notes = new NotesApplet( parent ); | ||
28 | return notes; | ||
29 | } | ||
30 | |||
31 | int NotesAppletImpl::position() const { | ||
32 | return 6; | ||
33 | } | ||
34 | |||
35 | QRESULT NotesAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { | ||
36 | *iface = 0; | ||
37 | if ( uuid == IID_QUnknown ) | ||
38 | *iface = this; | ||
39 | else if ( uuid == IID_TaskbarApplet ) | ||
40 | *iface = this; | ||
41 | else | ||
42 | return QS_FALSE; | ||
43 | |||
44 | if ( *iface ) | ||
45 | (*iface)->addRef(); | ||
46 | return QS_OK; | ||
47 | } | ||
48 | |||
49 | Q_EXPORT_INTERFACE() { | ||
50 | Q_CREATE_INSTANCE( NotesAppletImpl ) | ||
51 | } | ||
52 | |||
53 | |||
diff --git a/noncore/applets/notesapplet/notesappletimpl.h b/noncore/applets/notesapplet/notesappletimpl.h deleted file mode 100644 index a87118c..0000000 --- a/noncore/applets/notesapplet/notesappletimpl.h +++ b/dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org> | ||
3 | ** | ||
4 | ** | ||
5 | ** This file may be distributed and/or modified under the terms of the | ||
6 | ** GNU General Public License version 2 as published by the Free Software | ||
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
8 | ** packaging of this file. | ||
9 | ** | ||
10 | ** | ||
11 | **********************************************************************/ | ||
12 | #ifndef NOTESAPPLETIMPL_H | ||
13 | #define NOTESAPPLETIMPL_H | ||
14 | |||
15 | #include <qpe/taskbarappletinterface.h> | ||
16 | |||
17 | class NotesApplet; | ||
18 | |||
19 | class NotesAppletImpl : public TaskbarAppletInterface | ||
20 | { | ||
21 | public: | ||
22 | NotesAppletImpl(); | ||
23 | virtual ~NotesAppletImpl(); | ||
24 | |||
25 | QRESULT queryInterface( const QUuid&, QUnknownInterface** ); | ||
26 | Q_REFCOUNT | ||
27 | |||
28 | virtual QWidget *applet( QWidget *parent ); | ||
29 | virtual int position() const; | ||
30 | |||
31 | private: | ||
32 | NotesApplet *notes; | ||
33 | }; | ||
34 | |||
35 | #endif | ||