src/hbcore/gui/hbabstractbutton.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    34 #include <QGraphicsScene>
    34 #include <QGraphicsScene>
    35 #include <QPointer>
    35 #include <QPointer>
    36 #include <QStyle>
    36 #include <QStyle>
    37 
    37 
    38 #include <hbwidgetfeedback.h>
    38 #include <hbwidgetfeedback.h>
       
    39 #include <hbstyleprimitivedata.h>
    39 
    40 
    40 #ifdef HB_GESTURE_FW
    41 #ifdef HB_GESTURE_FW
    41 #include <hbtapgesture.h>
    42 #include <hbtapgesture.h>
    42 #include <hbpangesture.h>
    43 #include <hbpangesture.h>
    43 #endif
    44 #endif
   291 
   292 
   292 void HbAbstractButtonPrivate::init()
   293 void HbAbstractButtonPrivate::init()
   293 {
   294 {
   294     Q_Q( HbAbstractButton );
   295     Q_Q( HbAbstractButton );
   295 
   296 
   296 	q->setFocusPolicy(Qt::FocusPolicy(qApp->style()->styleHint(QStyle::SH_Button_FocusPolicy)));
   297     q->setFocusPolicy(Qt::FocusPolicy(qApp->style()->styleHint(QStyle::SH_Button_FocusPolicy)));
   297 
   298 
   298 #ifdef HB_GESTURE_FW
   299 #ifdef HB_GESTURE_FW
   299     q->grabGesture(Qt::TapGesture);
   300     q->grabGesture(Qt::TapGesture);
   300 #endif
   301 #endif
       
   302     q->setFlag(QGraphicsItem::ItemHasNoContents, true);
   301 
   303 
   302     // FIXME: size policy is commented out b/c of a bug in Qt #236689, also in our bugtracker.
   304     // FIXME: size policy is commented out b/c of a bug in Qt #236689, also in our bugtracker.
   303     //q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum, controlType));
   305     //q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum, controlType));
   304 
   306 
   305     //q->setForegroundRole(QPalette::ButtonText); TODO: check
   307     //q->setForegroundRole(QPalette::ButtonText); TODO: check
   516 {
   518 {
   517     Q_D( const HbAbstractButton );
   519     Q_D( const HbAbstractButton );
   518 
   520 
   519     return d->down;
   521     return d->down;
   520 }
   522 }
       
   523 
   521 
   524 
   522 /*!
   525 /*!
   523     @beta
   526     @beta
   524     Sets whether the button is pressed down.
   527     Sets whether the button is pressed down.
   525 
   528 
   793     HbWidget::initStyleOption(option);
   796     HbWidget::initStyleOption(option);
   794     Q_ASSERT(option);
   797     Q_ASSERT(option);
   795     option->state |= (isChecked() | isDown() ? QStyle::State_On : QStyle::State_Off);
   798     option->state |= (isChecked() | isDown() ? QStyle::State_On : QStyle::State_Off);
   796 }
   799 }
   797 
   800 
       
   801 void HbAbstractButton::initPrimitiveData(HbStylePrimitiveData *primitiveData, const QGraphicsObject *primitive)
       
   802 {
       
   803     HbWidgetBase::initPrimitiveData(primitiveData, primitive);
       
   804     Q_ASSERT(primitiveData);
       
   805     primitiveData->state |= (isChecked() | isDown() ? QStyle::State_On : QStyle::State_Off);
       
   806 
       
   807 }
       
   808 
   798 /*!
   809 /*!
   799     \reimp
   810     \reimp
   800  */
   811  */
   801 bool HbAbstractButton::event(QEvent *event)
   812 bool HbAbstractButton::event(QEvent *event)
   802 {
   813 {
   803     // as opposed to other widgets, disabled buttons accept mouse
   814     // as opposed to other widgets, disabled buttons accept mouse
   804     // events. This avoids surprising click-through scenarios	
   815     // events. This avoids surprising click-through scenarios   
   805     Q_D( HbAbstractButton );
   816     Q_D( HbAbstractButton );
   806     if (!isEnabled()) {
   817     if (!isEnabled()) {
   807         switch(event->type()) {
   818         switch(event->type()) {
   808         case QEvent::TabletPress:
   819         case QEvent::TabletPress:
   809         case QEvent::TabletRelease:
   820         case QEvent::TabletRelease:
   952 {
   963 {
   953     Q_D(HbAbstractButton);
   964     Q_D(HbAbstractButton);
   954     
   965     
   955     if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   966     if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   956         switch(tap->state()) {
   967         switch(tap->state()) {
   957 	        case Qt::GestureStarted:
   968             case Qt::GestureStarted:
   958                 scene()->setProperty(HbPrivate::OverridingGesture.latin1(),Qt::TapGesture);
   969                 scene()->setProperty(HbPrivate::OverridingGesture.latin1(),Qt::TapGesture);
   959                 if (!tap->property(HbPrivate::ThresholdRect.latin1()).toRect().isValid()) {
   970                 if (!tap->property(HbPrivate::ThresholdRect.latin1()).toRect().isValid()) {
   960                     tap->setProperty(HbPrivate::ThresholdRect.latin1(), mapRectToScene(boundingRect()).toRect());
   971                     tap->setProperty(HbPrivate::ThresholdRect.latin1(), mapRectToScene(boundingRect()).toRect());
   961                 }                
   972                 }                
   962                 setDown(true);
   973                 setDown(true);
  1074                 if (d->down && !d->longPress) {
  1085                 if (d->down && !d->longPress) {
  1075                     HbWidgetFeedback::triggered(this, Hb::InstantClicked);
  1086                     HbWidgetFeedback::triggered(this, Hb::InstantClicked);
  1076                 }
  1087                 }
  1077                 d->click();
  1088                 d->click();
  1078             }
  1089             }
  1079 	    break;
  1090         break;
  1080         }
  1091         }
  1081         default:
  1092         default:
  1082             event->ignore();
  1093             event->ignore();
  1083     }
  1094     }
  1084 }
  1095 }
  1165 {
  1176 {
  1166     Q_D(const HbAbstractButton);
  1177     Q_D(const HbAbstractButton);
  1167     if (d->mRepolishRequested && isVisible()) {
  1178     if (d->mRepolishRequested && isVisible()) {
  1168         d->mRepolishRequested = false;
  1179         d->mRepolishRequested = false;
  1169         // force the polish event in order to get the real size
  1180         // force the polish event in order to get the real size
  1170         QEvent polishEvent(QEvent::Polish);
  1181         if (!d->polished) {
  1171         QCoreApplication::sendEvent(const_cast<HbAbstractButton *>(this), &polishEvent);
  1182             QEvent polishEvent(QEvent::Polish);
  1172         d->mSizeHintPolish = true;
  1183             QCoreApplication::sendEvent(const_cast<HbAbstractButton *>(this), &polishEvent);
       
  1184             d->mSizeHintPolish = true;
       
  1185         } else if (d->repolishOutstanding) {
       
  1186             QCoreApplication::sendPostedEvents(const_cast<HbAbstractButton *>(this), QEvent::Polish);
       
  1187         }
       
  1188         QCoreApplication::sendPostedEvents(const_cast<HbAbstractButton *>(this), QEvent::LayoutRequest);
  1173     }
  1189     }
  1174     return HbWidget::sizeHint(which, constraint);
  1190     return HbWidget::sizeHint(which, constraint);
  1175 }
  1191 }
  1176 
  1192 
  1177 /*!
  1193 /*!