Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

appicons.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
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"

Generated on Sat Nov 5 16:15:29 2005 for OPIE by  doxygen 1.4.2