00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "appicons.h"
00023
00024 #ifdef QWS
00025 #include <qtopia/qcopenvelope_qws.h>
00026 #endif
00027
00028 #include <qtooltip.h>
00029 #include <qpixmap.h>
00030
00031
00032 AppIcons::AppIcons( QWidget *parent ) :
00033 QHBox(parent)
00034 {
00035 buttons.setAutoDelete(TRUE);
00036
00037 #ifndef QT_NO_COP
00038 QCopChannel* channel = new QCopChannel("Qt/Tray", this);
00039 connect(channel, SIGNAL(received(const QCString&,const QByteArray&)),
00040 this, SLOT(receive(const QCString&,const QByteArray&)));
00041 #endif
00042 }
00043
00044 void AppIcons::setIcon(int id, const QPixmap& pm)
00045 {
00046 button(id)->setPixmap(pm);
00047 }
00048
00049 class FlatButton : public QLabel {
00050 Q_OBJECT
00051 public:
00052 FlatButton(QWidget* parent) : QLabel(parent) { }
00053
00054 void mouseDoubleClickEvent(QMouseEvent* e)
00055 {
00056 emit clicked(e->pos(),e->button(),TRUE);
00057 }
00058 void mouseReleaseEvent(QMouseEvent* e)
00059 {
00060 if ( rect().contains(e->pos()) )
00061 emit clicked(e->pos(),e->button(),FALSE);
00062 }
00063
00064 signals:
00065 void clicked(const QPoint&, int, bool);
00066 };
00067
00068 QLabel* AppIcons::button(int id)
00069 {
00070 QLabel* f = buttons.find(id);
00071 if ( !f ) {
00072 buttons.insert(id,f=new FlatButton(this));
00073 connect(f,SIGNAL(clicked(const QPoint&,int,bool)),this,SLOT(clicked(const QPoint&,int,bool)));
00074 f->show();
00075 }
00076 return f;
00077 }
00078
00079 int AppIcons::findId(QLabel* b)
00080 {
00081 QIntDictIterator<QLabel> it(buttons);
00082 for ( ; ; ++it )
00083 if ( it.current() == b ) return it.currentKey();
00084 }
00085
00086 void AppIcons::clicked(const QPoint& relpos, int button, bool dbl)
00087 {
00088 #ifndef QT_NO_COP
00089 QLabel* s = (QLabel*)sender();
00090 if ( button == RightButton ) {
00091 QCopEnvelope("Qt/Tray","popup(int,QPoint)")
00092 << findId(s) << s->mapToGlobal(QPoint(0,0));
00093 } else {
00094 QCopEnvelope("Qt/Tray",
00095 dbl ? "doubleClicked(int,QPoint)" : "clicked(int,QPoint)")
00096 << findId(s) << relpos;
00097 }
00098 #endif
00099 }
00100
00101 void AppIcons::setToolTip(int id, const QString& tip)
00102 {
00103 QToolTip::add(button(id),tip);
00104 }
00105
00106 void AppIcons::remove(int id)
00107 {
00108 buttons.remove(id);
00109 }
00110
00111 void AppIcons::receive( const QCString &msg, const QByteArray &data )
00112 {
00113 QDataStream stream( data, IO_ReadOnly );
00114 if ( msg == "remove(int)" ) {
00115 int id;
00116 stream >> id;
00117 remove(id);
00118 } else if ( msg == "setIcon(int,QPixmap)" ) {
00119 int id;
00120 QPixmap pm;
00121 stream >> id >> pm;
00122 setIcon(id,pm);
00123 } else if ( msg == "setToolTip(int,QString)" ) {
00124 int id;
00125 QString s;
00126 stream >> id >> s;
00127 setToolTip(id,s);
00128 }
00129 }
00130
00131 #include "appicons.moc"