-rw-r--r-- | examples/applet/config.in | 2 | ||||
-rw-r--r-- | examples/applet/example.pro | 2 | ||||
-rw-r--r-- | examples/applet/simpleimpl.cpp | 96 | ||||
-rw-r--r-- | examples/applet/simpleimpl.h | 23 |
4 files changed, 16 insertions, 107 deletions
diff --git a/examples/applet/config.in b/examples/applet/config.in index 177de27..c3fb6dd 100644 --- a/examples/applet/config.in +++ b/examples/applet/config.in | |||
@@ -1,4 +1,4 @@ | |||
1 | config APPLET_EXAMPLE | 1 | config APPLET_EXAMPLE |
2 | boolean "Taskbar Applet Example" | 2 | boolean "Taskbar Applet Example" |
3 | default "y" | 3 | default "y" |
4 | depends ( LIBQPE || LIBQPE-X11 ) && EXAMPLES | 4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIEUI2 &&EXAMPLES |
diff --git a/examples/applet/example.pro b/examples/applet/example.pro index 3efd31e..5ae540b 100644 --- a/examples/applet/example.pro +++ b/examples/applet/example.pro | |||
@@ -1,16 +1,16 @@ | |||
1 | CONFIG += warn_on qt | 1 | CONFIG += warn_on qt |
2 | 2 | ||
3 | TEMPLATE = lib | 3 | TEMPLATE = lib |
4 | DESTDIR = $(OPIEDIR)/plugins/applets | 4 | DESTDIR = $(OPIEDIR)/plugins/applets |
5 | TARGET = example | 5 | TARGET = example |
6 | 6 | ||
7 | SOURCES = simpleimpl.cpp | 7 | SOURCES = simpleimpl.cpp |
8 | HEADERS = simpleimpl.h | 8 | HEADERS = simpleimpl.h |
9 | 9 | ||
10 | INCLUDEPATH += $(OPIEDIR)/include | 10 | INCLUDEPATH += $(OPIEDIR)/include |
11 | DEPENDSPATH += $(OPIEDIR)/include | 11 | DEPENDSPATH += $(OPIEDIR)/include |
12 | 12 | ||
13 | LIBS += -lqpe | 13 | LIBS += -lqpe -lopieui2 |
14 | 14 | ||
15 | 15 | ||
16 | include ( $(OPIEDIR)/include.pro ) | 16 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/examples/applet/simpleimpl.cpp b/examples/applet/simpleimpl.cpp index 82fc6e5..62d9bf7 100644 --- a/examples/applet/simpleimpl.cpp +++ b/examples/applet/simpleimpl.cpp | |||
@@ -1,162 +1,90 @@ | |||
1 | |||
2 | #include "simpleimpl.h" | ||
3 | |||
4 | #include <opie2/otaskbarapplet.h> | ||
5 | |||
6 | #include <qpe/applnk.h> // for AppLnk | ||
7 | #include <qpe/resource.h> // for Resource loading | ||
8 | |||
1 | #include <qlabel.h> | 9 | #include <qlabel.h> |
2 | #include <qpainter.h> | 10 | #include <qpainter.h> |
3 | #include <qmessagebox.h> | 11 | #include <qmessagebox.h> |
4 | 12 | ||
5 | #include <qpe/applnk.h> // for AppLnk | ||
6 | #include <qpe/resource.h> // for Resource loading | ||
7 | 13 | ||
8 | #include "simpleimpl.h" | ||
9 | 14 | ||
10 | 15 | ||
11 | SimpleApplet::SimpleApplet(QWidget *parent) | 16 | SimpleApplet::SimpleApplet(QWidget *parent) |
12 | : QWidget( parent, "Simple Applet" ) { | 17 | : QWidget( parent, "Simple Applet" ) { |
13 | /* | 18 | /* |
14 | * we will load an Image, scale it for the right usage | 19 | * we will load an Image, scale it for the right usage |
15 | * remember your applet might be used by different | 20 | * remember your applet might be used by different |
16 | * resolutions. | 21 | * resolutions. |
17 | * Then we will convert the image back to an Pixmap | 22 | * Then we will convert the image back to an Pixmap |
18 | * and draw this Pimxap. We need to use Image because its | 23 | * and draw this Pimxap. We need to use Image because its |
19 | * the only class that allows scaling. | 24 | * the only class that allows scaling. |
20 | */ | 25 | */ |
21 | 26 | ||
22 | QImage image = Resource::loadImage("Tux"); | 27 | QImage image = Resource::loadImage("Tux"); |
23 | /* | 28 | /* |
24 | * smooth scale to AppLnk smallIconSize for applest | 29 | * smooth scale to AppLnk smallIconSize for applest |
25 | * smallIconSize gets adjusted to the resolution | 30 | * smallIconSize gets adjusted to the resolution |
26 | * so on some displays like SIMpad and a C-750 the smallIconSize | 31 | * so on some displays like SIMpad and a C-750 the smallIconSize |
27 | * is greater than on a iPAQ h3870 | 32 | * is greater than on a iPAQ h3870 |
28 | */ | 33 | */ |
29 | image = image.smoothScale(AppLnk::smallIconSize(), AppLnk::smallIconSize() ); | 34 | image = image.smoothScale(AppLnk::smallIconSize(), AppLnk::smallIconSize() ); |
30 | 35 | ||
31 | /* | 36 | /* |
32 | * now we need to convert the Image to a Pixmap cause these | 37 | * now we need to convert the Image to a Pixmap cause these |
33 | * can be drawn more easily | 38 | * can be drawn more easily |
34 | */ | 39 | */ |
35 | m_pix = new QPixmap(); | 40 | m_pix = new QPixmap(); |
36 | m_pix->convertFromImage( image ); | 41 | m_pix->convertFromImage( image ); |
37 | 42 | ||
38 | /* | 43 | /* |
39 | * Now we will say that we don't want to be bigger than our | 44 | * Now we will say that we don't want to be bigger than our |
40 | * Pixmap | 45 | * Pixmap |
41 | */ | 46 | */ |
42 | setFixedHeight(AppLnk::smallIconSize() ); | 47 | setFixedHeight(AppLnk::smallIconSize() ); |
43 | setFixedWidth( AppLnk::smallIconSize() ); | 48 | setFixedWidth( AppLnk::smallIconSize() ); |
44 | 49 | ||
45 | } | 50 | } |
46 | 51 | ||
47 | SimpleApplet::~SimpleApplet() { | 52 | SimpleApplet::~SimpleApplet() { |
48 | delete m_pix; | 53 | delete m_pix; |
49 | } | 54 | } |
50 | 55 | ||
51 | 56 | ||
52 | /* | 57 | /* |
53 | * here you would normal show or do something | 58 | * here you would normal show or do something |
54 | * useful. If you want to show a widget at the top left | 59 | * useful. If you want to show a widget at the top left |
55 | * of your icon you need to map your rect().topLeft() to | 60 | * of your icon you need to map your rect().topLeft() to |
56 | * global with mapToGlobal(). Then you might also need to | 61 | * global with mapToGlobal(). Then you might also need to |
57 | * move the widgets so it is visible | 62 | * move the widgets so it is visible |
58 | */ | 63 | */ |
59 | void SimpleApplet::mousePressEvent(QMouseEvent* ) { | 64 | void SimpleApplet::mousePressEvent(QMouseEvent* ) { |
60 | QMessageBox::information(this, tr("No action taken"), | 65 | QMessageBox::information(this, tr("No action taken"), |
61 | tr("<qt>This Plugin does not yet support anything usefule aye.</qt>"), | 66 | tr("<qt>This Plugin does not yet support anything usefule aye.</qt>"), |
62 | QMessageBox::Ok ); | 67 | QMessageBox::Ok ); |
63 | 68 | ||
64 | } | 69 | } |
65 | 70 | ||
66 | void SimpleApplet::paintEvent( QPaintEvent* ) { | 71 | void SimpleApplet::paintEvent( QPaintEvent* ) { |
67 | QPainter p(this); | 72 | QPainter p(this); |
68 | 73 | ||
69 | /* simpy draw the pixmap from the start of this widget */ | 74 | /* simpy draw the pixmap from the start of this widget */ |
70 | p.drawPixmap(0, 0, *m_pix ); | 75 | p.drawPixmap(0, 0, *m_pix ); |
71 | } | 76 | } |
72 | 77 | ||
73 | /* | 78 | /* |
74 | * Here comes the implementation of the interface | 79 | * We need to add this symbol for the plugin exporter! |
75 | */ | 80 | */ |
76 | SimpleAppletImpl::SimpleAppletImpl() { | 81 | int SimpleApplet::position(){ |
77 | } | ||
78 | /* needed cause until it is only pure virtual */ | ||
79 | SimpleAppletImpl::~SimpleAppletImpl() { | ||
80 | /* | ||
81 | * we will delete our applets as well | ||
82 | * setAUtoDelete makes the QList free | ||
83 | * the objects behind the pointers | ||
84 | */ | ||
85 | m_applets.setAutoDelete( true ); | ||
86 | m_applets.clear(); | ||
87 | } | ||
88 | |||
89 | /* | ||
90 | * For the taskbar interface return a Widget | ||
91 | */ | ||
92 | QWidget* SimpleAppletImpl::applet( QWidget* parent ) { | ||
93 | /* | ||
94 | * There are problems with ownership. So we add | ||
95 | * our ownlist and clear this; | ||
96 | */ | ||
97 | SimpleApplet* ap = new SimpleApplet( parent ); | ||
98 | m_applets.append( ap ); | ||
99 | |||
100 | return ap; | ||
101 | } | ||
102 | |||
103 | /* | ||
104 | * A small hint where the Applet Should be displayed | ||
105 | */ | ||
106 | int SimpleAppletImpl::position()const { | ||
107 | return 1; | 82 | return 1; |
108 | } | 83 | } |
109 | 84 | ||
110 | 85 | ||
111 | /* | ||
112 | * Now the important QUnkownInterface method without | ||
113 | * this one your applet won't load | ||
114 | * @param uuid The uuid of the interface | ||
115 | * @param iface The pointer to the interface ptr | ||
116 | */ | ||
117 | QRESULT SimpleAppletImpl::queryInterface( const QUuid& uuid, QUnknownInterface** iface) { | ||
118 | /* set the pointer to the interface to 0 */ | ||
119 | *iface = 0; | ||
120 | |||
121 | /* | ||
122 | * we check if we support the requested interface | ||
123 | * and then assign to the pointer. | ||
124 | * You may alos create another interface here so | ||
125 | * *iface = this is only in this simple case true you | ||
126 | * could also support more interfaces. | ||
127 | * But this example below is the most common use. | ||
128 | * Now the caller knows that the Interface Pointer | ||
129 | * is valid and the interface supported | ||
130 | */ | ||
131 | if ( uuid == IID_QUnknown ) | ||
132 | *iface = this; | ||
133 | else if ( uuid == IID_TaskbarApplet ) | ||
134 | *iface = this; | ||
135 | else | ||
136 | return QS_FALSE; | ||
137 | |||
138 | if ( *iface ) | ||
139 | (*iface)->addRef(); | ||
140 | |||
141 | return QS_OK; | ||
142 | } | ||
143 | |||
144 | 86 | ||
145 | /* | 87 | /* |
146 | * Finally we need to export the Interface. | 88 | * Here comes the implementation of the interface |
147 | * CREATE_INSTANCE creates a interface and calls | ||
148 | * queryInterface for the QUnknownInterface once | ||
149 | * With out this function the applet can't be loaded. | ||
150 | * | ||
151 | * NOTE: If your applet does not load it's likely you've an | ||
152 | * unresolved symbol. Change the .pro TEMPLATE = lib to TEMPLATE= app | ||
153 | * and recompile. If the linker only complains about a missing | ||
154 | * main method the problem is more complex. In most cases it'll say | ||
155 | * you which symbols are missing and you can implement them. | ||
156 | * The main(int argc, char* argv[] ) does not need to be | ||
157 | * included in a library so it's ok that the linker complains | ||
158 | */ | 89 | */ |
159 | Q_EXPORT_INTERFACE() { | 90 | EXPORT_OPIE_APPLET_v1( SimpleApplet ) \ No newline at end of file |
160 | Q_CREATE_INSTANCE( SimpleAppletImpl ) | ||
161 | } | ||
162 | |||
diff --git a/examples/applet/simpleimpl.h b/examples/applet/simpleimpl.h index f58e2af..90c632f 100644 --- a/examples/applet/simpleimpl.h +++ b/examples/applet/simpleimpl.h | |||
@@ -1,77 +1,58 @@ | |||
1 | /* | 1 | /* |
2 | * You may use, modify and distribute without any limitation | 2 | * You may use, modify and distribute without any limitation |
3 | */ | 3 | */ |
4 | 4 | ||
5 | /** | 5 | /** |
6 | * Opie and Qtopia uses a component system called QCOM | 6 | * Opie and Qtopia uses a component system called QCOM |
7 | * which was first part of the Qt 3.0 API but was made | 7 | * which was first part of the Qt 3.0 API but was made |
8 | * prviate during the betas. Opie and Qtopia still use it | 8 | * prviate during the betas. Opie and Qtopia still use it |
9 | * and we're happy with it. | 9 | * and we're happy with it. |
10 | * Every starts with the QUnknownInterface. It supports functions | 10 | * Every starts with the QUnknownInterface. It supports functions |
11 | * for reference counting and the most important one | 11 | * for reference counting and the most important one |
12 | * is for a query. Every QCOM interface got a global unique id ( GUID,UUID ) | 12 | * is for a query. Every QCOM interface got a global unique id ( GUID,UUID ) |
13 | * query is used to see if a interface is supported by | 13 | * query is used to see if a interface is supported by |
14 | * a dynamic shared object ( dso / plugin ) | 14 | * a dynamic shared object ( dso / plugin ) |
15 | * For tasks like loading Applications, InputMethods, Today, MenuButton, | 15 | * For tasks like loading Applications, InputMethods, Today, MenuButton, |
16 | * Taskbar, Style, Email Client there are specefic Interfaces you | 16 | * Taskbar, Style, Email Client there are specefic Interfaces you |
17 | * need to implement. The interfaces inherits from QUnknownInterface and | 17 | * need to implement. The interfaces inherits from QUnknownInterface and |
18 | * you'll need inherit from the interface. | 18 | * you'll need inherit from the interface. |
19 | * As example we will use the Taskbar interface | 19 | * As example we will use the Taskbar interface |
20 | * the OTaskBarAppletWrapper implements the factory for us | ||
20 | */ | 21 | */ |
21 | 22 | ||
22 | #ifndef SIMPLE_OPIE_EXAMPLE_APPLET_H | 23 | #ifndef SIMPLE_OPIE_EXAMPLE_APPLET_H |
23 | #define SIMPLE_OPIE_EXAMPLE_APPLET_H | 24 | #define SIMPLE_OPIE_EXAMPLE_APPLET_H |
24 | 25 | ||
25 | /* | 26 | /* |
26 | * The taskbar applet interfaces wants us to implement position() and applet() | 27 | * The taskbar applet interfaces wants us to implement position() and applet() |
27 | * additionally we need to implement add(), release() and queryInterface for QUnknownInterface | 28 | * additionally we need to implement add(), release() and queryInterface for QUnknownInterface |
28 | * luckiy there is a macro for the reference counting | 29 | * luckiy there is a macro for the reference counting |
29 | * We provide an Implementation of the interface. | 30 | * We provide an Implementation of the interface. |
30 | */ | 31 | */ |
31 | #include <qwidget.h> | 32 | #include <qwidget.h> |
32 | #include <qlist.h> | 33 | #include <qlist.h> |
33 | 34 | ||
34 | #include <qpe/taskbarappletinterface.h> | 35 | #include <qpe/taskbarappletinterface.h> |
35 | 36 | ||
36 | 37 | ||
37 | /* | 38 | /* |
38 | * Because we only draw an Icon in a fixed width and height | 39 | * Because we only draw an Icon in a fixed width and height |
39 | * we declare and define SimpleApplet here and you could use QLabel | 40 | * we declare and define SimpleApplet here and you could use QLabel |
40 | * setPixmap or use QWidget and draw yourself. | 41 | * setPixmap or use QWidget and draw yourself. |
41 | * You might also want to reimplement mouse*Event to use some simple actions | 42 | * You might also want to reimplement mouse*Event to use some simple actions |
42 | */ | 43 | */ |
43 | class SimpleApplet : public QWidget { | 44 | class SimpleApplet : public QWidget { |
44 | Q_OBJECT | 45 | Q_OBJECT |
45 | public: | 46 | public: |
46 | SimpleApplet(QWidget *parent); | 47 | SimpleApplet(QWidget *parent); |
47 | ~SimpleApplet(); | 48 | ~SimpleApplet(); |
49 | static int position(); | ||
48 | private: | 50 | private: |
49 | void mousePressEvent( QMouseEvent* ); | 51 | void mousePressEvent( QMouseEvent* ); |
50 | void paintEvent( QPaintEvent* ); | 52 | void paintEvent( QPaintEvent* ); |
51 | QPixmap *m_pix; | 53 | QPixmap *m_pix; |
52 | }; | 54 | }; |
53 | 55 | ||
54 | class SimpleAppletImpl : public TaskbarAppletInterface { | ||
55 | public: | ||
56 | |||
57 | SimpleAppletImpl(); | ||
58 | virtual ~SimpleAppletImpl(); | ||
59 | |||
60 | QRESULT queryInterface( const QUuid&, QUnknownInterface** ); | ||
61 | |||
62 | QWidget *applet( QWidget* parent ); | ||
63 | int position()const; | ||
64 | |||
65 | /* | ||
66 | * macro for reference countint | ||
67 | * if reference drops to zero | ||
68 | * delete this is called | ||
69 | */ | ||
70 | Q_REFCOUNT | ||
71 | |||
72 | private: | ||
73 | QList<SimpleApplet> m_applets; | ||
74 | }; | ||
75 | 56 | ||
76 | 57 | ||
77 | #endif | 58 | #endif |