src/hbcore/inputfw/hbinputregioncollector.cpp
changeset 6 c3690ec91ef8
parent 5 627c4a0fd0e7
child 30 80e4d18b72f5
child 34 ed14f46c0e55
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    20 **
    20 **
    21 ** If you have questions regarding the use of this file, please contact
    21 ** If you have questions regarding the use of this file, please contact
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
       
    25 #include "hbinputregioncollector_p.h"
    25 
    26 
    26 #include <QRegion>
    27 #include <QRegion>
    27 #include <QTransform>
    28 #include <QTransform>
    28 #include <QPointer>
    29 #include <QPointer>
    29 
    30 
    30 #include "hbinputregioncollector_p.h"
       
    31 #include "hbwidget.h"
    31 #include "hbwidget.h"
    32 #include "hbmainwindow.h"
    32 #include "hbmainwindow.h"
    33 #include "hbpopup.h"
    33 #include "hbpopup.h"
    34 #include "hbdeviceprofile.h"
    34 #include "hbdeviceprofile.h"
    35 
    35 
    49 
    49 
    50 class HbWidgetFilterList
    50 class HbWidgetFilterList
    51 {
    51 {
    52 public:
    52 public:
    53     HbWidgetFilterList(HbWidget *w)
    53     HbWidgetFilterList(HbWidget *w)
    54         :mWidget (w), mIsVisible (false)
    54         : mWidget(w), mIsVisible(false) {
    55     {
    55     }
    56     }
    56     bool operator ==(const HbWidgetFilterList &other) const {
    57     bool operator ==(const HbWidgetFilterList &other) const {return mWidget == other.mWidget;}
    57         return mWidget == other.mWidget;
       
    58     }
    58     QPointer <HbWidget> mWidget;
    59     QPointer <HbWidget> mWidget;
    59     // visibility is needed as the time when we get show event inside eventFilter
    60     // visibility is needed as the time when we get show event inside eventFilter
    60     // widget is not visible.
    61     // widget is not visible.
    61     bool mIsVisible;
    62     bool mIsVisible;
    62 };
    63 };
    63 
    64 
    64 class HbInputRegionCollectorPrivate
    65 class HbInputRegionCollectorPrivate
    65 {
    66 {
    66 public:
    67 public:
    67     HbInputRegionCollectorPrivate()
    68     HbInputRegionCollectorPrivate()
    68         :mEnabled(false), mModalDialogs(0){}
    69         : mEnabled(false), mModalDialogs(0) {}
    69     QList < HbWidgetFilterList > mInputWidgets;
    70     QList < HbWidgetFilterList > mInputWidgets;
    70     bool mEnabled;
    71     bool mEnabled;
    71     int mModalDialogs;
    72     int mModalDialogs;
    72 };
    73 };
    73 
    74 
    83 
    84 
    84 /*!
    85 /*!
    85 Constructor.
    86 Constructor.
    86 */
    87 */
    87 HbInputRegionCollector::HbInputRegionCollector()
    88 HbInputRegionCollector::HbInputRegionCollector()
    88     :d_ptr(new HbInputRegionCollectorPrivate())
    89     : d_ptr(new HbInputRegionCollectorPrivate())
    89 {
    90 {
    90 }
    91 }
    91 
    92 
    92 /*!
    93 /*!
    93 Destructor.
    94 Destructor.
    98 }
    99 }
    99 
   100 
   100 /*!
   101 /*!
   101 Installs a even filter on the passed widget.
   102 Installs a even filter on the passed widget.
   102 */
   103 */
   103 void HbInputRegionCollector::attach (HbWidget *widget)
   104 void HbInputRegionCollector::attach(HbWidget *widget)
   104 {
   105 {
   105     if (widget && !d_ptr->mInputWidgets.contains(widget)) {
   106     if (widget && !d_ptr->mInputWidgets.contains(widget)) {
   106         if (d_ptr->mEnabled) {
   107         if (d_ptr->mEnabled) {
   107             widget->installEventFilter(this);
   108             widget->installEventFilter(this);
   108         }
   109         }
   111 }
   112 }
   112 
   113 
   113 /*!
   114 /*!
   114 Detaches widget from region collection and updates current region if region collection is enabled.
   115 Detaches widget from region collection and updates current region if region collection is enabled.
   115 */
   116 */
   116 void HbInputRegionCollector::detach (HbWidget *widget)
   117 void HbInputRegionCollector::detach(HbWidget *widget)
   117 {
   118 {
   118     if (widget && d_ptr->mInputWidgets.contains(widget)) {
   119     if (widget && d_ptr->mInputWidgets.contains(widget)) {
   119         widget->removeEventFilter(this);
   120         widget->removeEventFilter(this);
   120         d_ptr->mInputWidgets.removeOne(widget);
   121         d_ptr->mInputWidgets.removeOne(widget);
   121         if (d_ptr->mEnabled) {
   122         if (d_ptr->mEnabled) {
   125 }
   126 }
   126 
   127 
   127 /*!
   128 /*!
   128 Observes size, position and move events of all attached widgets and calls update().
   129 Observes size, position and move events of all attached widgets and calls update().
   129 */
   130 */
   130 bool HbInputRegionCollector::eventFilter (QObject *obj, QEvent *event)
   131 bool HbInputRegionCollector::eventFilter(QObject *obj, QEvent *event)
   131 {
   132 {
   132     HbWidget *widget = qobject_cast<HbWidget *>(obj);
   133     HbWidget *widget = qobject_cast<HbWidget *>(obj);
   133     if (widget) {
   134     if (widget) {
   134         switch (event->type()) {
   135         switch (event->type()) {
   135         case QEvent::GraphicsSceneResize:
   136         case QEvent::GraphicsSceneResize:
   136         case QEvent::GraphicsSceneMove:
   137         case QEvent::GraphicsSceneMove:
   137             update();
   138             update();
   138             break;
   139             break;
   139         case QEvent::Show:
   140         case QEvent::Show: {
   140             {
   141             // We can not query for HbWidget visiblility at this point
   141                 // We can not query for HbWidget visiblility at this point
   142             // so have to set it inside the strcuture variable.
   142                 // so have to set it inside the strcuture variable.
   143             int pos = d_ptr->mInputWidgets.indexOf(widget);
   143                 int pos = d_ptr->mInputWidgets.indexOf(widget);
   144             if (pos != -1) {
   144                 if (pos != -1) {
   145                 // Temporary TODO ++
   145                     // Temporary TODO ++
   146                 // TODO write a HbInputWidgetStore class which will hold all the
   146                     // TODO write a HbInputWidgetStore class which will hold all the 
   147                 // active widgets and will emit signals for example sceneBlocked()
   147                     // active widgets and will emit signals for example sceneBlocked() 
   148                 // sceneUnBlocked(). And then connect to region collector.
   148                     // sceneUnBlocked(). And then connect to region collector.
   149                 HbPopup *popup = qobject_cast<HbPopup *>(obj);
   149                     HbPopup *popup = qobject_cast<HbPopup *>(obj);
   150                 // since there is a bug in Qt that QGraphicsItem geenrates two show events
   150                     // since there is a bug in Qt that QGraphicsItem geenrates two show events
   151                 // once when you do a show() and once when you added it to the scene(),
   151                     // once when you do a show() and once when you added it to the scene(), 
   152                 // so need a check on visibility.
   152                     // so need a check on visibility.
   153                 if (popup && popup->isModal() && !d_ptr->mInputWidgets[pos].mIsVisible) {
   153                     if (popup && popup->isModal() && !d_ptr->mInputWidgets[pos].mIsVisible) {
   154                     d_ptr->mModalDialogs++;
   154                         d_ptr->mModalDialogs++;
       
   155                     }
       
   156                     // Temporary TODO --                
       
   157                     d_ptr->mInputWidgets[pos].mIsVisible = true;
       
   158                     update();
       
   159                 }
   155                 }
   160                 break;
   156                 // Temporary TODO --
   161             }
   157                 d_ptr->mInputWidgets[pos].mIsVisible = true;
   162         case QEvent::Hide:
   158                 update();
   163             {
   159             }
   164                 int pos = d_ptr->mInputWidgets.indexOf(widget);
   160             break;
   165                 if (pos != -1) {
   161         }
   166                     // Temporary TODO ++
   162         case QEvent::Hide: {
   167                     HbPopup *popup = qobject_cast<HbPopup *>(obj);
   163             int pos = d_ptr->mInputWidgets.indexOf(widget);
   168                     if (popup && popup->isModal()) {
   164             if (pos != -1) {
   169                         d_ptr->mModalDialogs--;
   165                 // Temporary TODO ++
   170                     }
   166                 HbPopup *popup = qobject_cast<HbPopup *>(obj);
   171                     // Temporary TODO --
   167                 if (popup && popup->isModal()) {
   172                     d_ptr->mInputWidgets[pos].mIsVisible = false;
   168                     d_ptr->mModalDialogs--;
   173                     update();
       
   174                 }
   169                 }
   175                 break;
   170                 // Temporary TODO --
   176             }
   171                 d_ptr->mInputWidgets[pos].mIsVisible = false;
       
   172                 update();
       
   173             }
       
   174             break;
       
   175         }
   177         default:
   176         default:
   178             break;
   177             break;
   179         };
   178         };
   180     }
   179     }
   181     return false;
   180     return false;
   208                     // we need to check transformation of the QGraphicsView.
   207                     // we need to check transformation of the QGraphicsView.
   209                     // for example when there is a orientation switch transformation
   208                     // for example when there is a orientation switch transformation
   210                     // is 270 degree. We should map it to get transformed rectangle.
   209                     // is 270 degree. We should map it to get transformed rectangle.
   211                     QTransform t = window->viewportTransform();
   210                     QTransform t = window->viewportTransform();
   212                     QRectF tRect = t.mapRect(rect);
   211                     QRectF tRect = t.mapRect(rect);
   213                     region += tRect.toRect();
       
   214                     QRectF intersection = QRectF(window->geometry()).intersected(tRect);
   212                     QRectF intersection = QRectF(window->geometry()).intersected(tRect);
   215                     region += intersection.toRect();
   213                     region += intersection.toRect();
   216                 }
   214                 }
   217             }
   215             }
   218         }
   216         }
   219      }
   217     }
   220     emit updateRegion(region);
   218     emit updateRegion(region);
   221 }
   219 }
   222 
   220 
   223 /*!
   221 /*!
   224 Enables region collection, this function is called by input framework.
   222 Enables region collection, this function is called by input framework.