ginebra2/Charms/ObjectCharm.h
changeset 9 b39122337a00
equal deleted inserted replaced
7:a1f515018ac1 9:b39122337a00
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 *
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
       
    19 */
       
    20 
       
    21 #ifndef OBJECTCHARM_H_
       
    22 #define OBJECTCHARM_H_
       
    23 
       
    24 #include <QtGui>
       
    25 
       
    26 namespace GVA {
       
    27 
       
    28 // -------------------------------
       
    29 
       
    30 /*!
       
    31  * Base class for object "charms".  Charms set an event filter on a particular
       
    32  * object and perform some action in response to the events sent to the object.
       
    33  * ObjectCharms automatically destroy themselves when the target object is
       
    34  * destroyed.
       
    35  */
       
    36 class ObjectCharm : public QObject {
       
    37     Q_OBJECT
       
    38   public:
       
    39     ObjectCharm(QObject *object);
       
    40 
       
    41   private slots:
       
    42     virtual void onObjectDestroyed();
       
    43 
       
    44   protected:
       
    45     QObject *m_object;  // not owned
       
    46 };
       
    47 
       
    48 // -------------------------------
       
    49 
       
    50 /*!
       
    51  * This class draws a circle in response to mouse click events on the given object.  Intended
       
    52  * for testing purposes only.
       
    53  */
       
    54 class TouchCircleCharm : public ObjectCharm {
       
    55     Q_OBJECT
       
    56   public:
       
    57     TouchCircleCharm(QObject *object, QGraphicsItem *parent = 0);
       
    58     ~TouchCircleCharm();
       
    59 
       
    60   private slots:
       
    61     void onTimer();
       
    62 
       
    63   private:
       
    64     bool eventFilter(QObject *object, QEvent *event);
       
    65 
       
    66     class QGraphicsEllipseItem * m_item;
       
    67     class QTimer * m_timer;
       
    68 };
       
    69 
       
    70 }
       
    71 
       
    72 #endif /* OBJECTCHARM_H_ */