src/hbinput/inputwidgets/hbinputbuttongroup.cpp
changeset 30 80e4d18b72f5
parent 23 e6ad4ef83b23
--- a/src/hbinput/inputwidgets/hbinputbuttongroup.cpp	Fri Sep 17 08:32:10 2010 +0300
+++ b/src/hbinput/inputwidgets/hbinputbuttongroup.cpp	Mon Oct 04 00:38:12 2010 +0300
@@ -37,7 +37,7 @@
 #include <hbaction.h>
 #include <hbevent.h>
 #include <hbcolorscheme.h>
-#include <hbdialog.h>
+#include <hbinputpopupbase.h>
 #include <hbframeitem.h>
 #include <hbwidgetfeedback.h>
 #include <hbdeviceprofile.h>
@@ -47,6 +47,18 @@
 
 #include "hbinputbutton.h"
 
+/*!
+@stable
+@hbinput
+\class HbInputButtonGroup
+\brief A widget presenting group of buttons for virtual keyboards.
+
+HbInputButtonGroup is a widget displaying a mat of buttons, performance-optimized
+as a single widget instead of multiple separate button widgets.
+
+\sa HbInputButton
+*/
+
 /// @cond
 
 const QString HbNormalBackground("qtg_fr_input_btn_keypad_normal");
@@ -98,7 +110,8 @@
 HbInputButtonGroupPrivate::HbInputButtonGroupPrivate()
     : mUnitValue(0), mGridSize(1, 1), mButtonBorderSize(1.0), mEnabled(true),
       mButtonPreviewEnabled(false), mCharacterSelectionPreviewEnabled(false),
-      mMultiTouchEnabled(true), mCharacterSelectionPreview(0), mBackground(0)
+      mMultiTouchEnabled(true), mCharacterSelectionPreview(0), mBackground(0),
+      mHasMouseGrab(false)
 {
     for (int i = 0; i < HbTextLayoutCount; ++i) {
         mTextLayouts.append(0);
@@ -421,14 +434,12 @@
 
         // Create and initialize character preview
         if (!mCharacterSelectionPreview) {
-            mCharacterSelectionPreview = new HbDialog();
+            mCharacterSelectionPreview = new HbInputPopupBase();
             HbInputRegionCollector::instance()->attach(mCharacterSelectionPreview);
             mCharacterSelectionPreview->setModal(true);
             mCharacterSelectionPreview->setBackgroundFaded(false);
             mCharacterSelectionPreview->setTimeout(HbPopup::NoTimeout);
             mCharacterSelectionPreview->setDismissPolicy(HbPopup::TapAnywhere);
-            mCharacterSelectionPreview->setFlag(QGraphicsItem::ItemIsPanel, true);
-            mCharacterSelectionPreview->setActive(false);
             qreal margin = HbPreviewMarginInUnits * mUnitValue * 0.5;
             mCharacterSelectionPreview->setContentsMargins(margin, 0, margin, 0);
         }
@@ -1823,6 +1834,14 @@
         break;
     }
 
+    case QEvent::GrabMouse:
+        d->mHasMouseGrab = true;
+        break;
+
+    case QEvent::UngrabMouse:
+        d->mHasMouseGrab = false;
+        break;
+
     default:
         return HbWidget::event(event);
     }
@@ -1895,6 +1914,10 @@
 
     setAcceptTouchEvents(d->mMultiTouchEnabled);
 
+    if (qApp) {
+        qApp->installEventFilter(this);
+    }
+
     HbWidget::showEvent(event);
 }
 
@@ -1907,10 +1930,27 @@
 {
     cancelButtonPress();
 
+    if (qApp) {
+        qApp->removeEventFilter(this);
+    }
+
     HbWidget::hideEvent(event);
 }
 
 /*!
+Releases all pressed buttons when deactivated.
+*/
+bool HbInputButtonGroup::eventFilter(QObject *obj, QEvent *event)
+{
+    Q_UNUSED(obj);
+
+    if (event->type() == QEvent::ApplicationDeactivate) {
+        cancelButtonPress();
+    }
+    return false;
+}
+
+/*!
 Emits buttonPressed signal.
 */
 void HbInputButtonGroup::emitButtonPressed(const QKeyEvent &event)
@@ -1963,7 +2003,9 @@
 {
     Q_D(HbInputButtonGroup);
 
-    ungrabMouse();
+    if (d->mHasMouseGrab) {
+        ungrabMouse();
+    }
 
     d->mActiveButtons.clear();