src/hbcore/gui/hbtoolbarextension.cpp
changeset 6 c3690ec91ef8
parent 1 f7ac710697a9
child 7 923ff622b8b9
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    67 /*!
    67 /*!
    68     \reimp
    68     \reimp
    69     \fn int HbToolBarExtension::type() const
    69     \fn int HbToolBarExtension::type() const
    70  */
    70  */
    71 
    71 
       
    72 /*!
       
    73   \primitives
       
    74   \primitive{background} HbFrameItem representing the extension background.
       
    75   */
       
    76 
    72 HbToolBarExtensionPrivate::HbToolBarExtensionPrivate() :
    77 HbToolBarExtensionPrivate::HbToolBarExtensionPrivate() :
    73         HbDialogPrivate(),
    78         HbDialogPrivate(),
    74         mToolButtons(),
    79         mToolButtons(),
    75         mLayout(0),
    80         mLayout(0),
    76         extensionAction(0),
    81         extensionAction(0),
   150     initialiseContent();
   155     initialiseContent();
   151     if (!mDefaultContentWidget)
   156     if (!mDefaultContentWidget)
   152         return;
   157         return;
   153 
   158 
   154     foreach (HbToolButton* button, mToolButtons) {
   159     foreach (HbToolButton* button, mToolButtons) {
   155         button->setVisible(button->action()->isVisible());
   160         button->setVisible(HbToolButtonPrivate::d_ptr(button)->action->isVisible());
   156     }
   161     }
   157 
   162 
   158     mLayout = new QGraphicsGridLayout();
   163     mLayout = new QGraphicsGridLayout();
   159     mLayout->setContentsMargins( mMargins, mMargins, mMargins, mMargins );
   164     mLayout->setContentsMargins( mMargins, mMargins, mMargins, mMargins );
   160     mLayout->setSpacing(0.0);  // if non zero spacing needed, add to css
   165     mLayout->setSpacing(0.0);  // if non zero spacing needed, add to css
   161     for ( int i(0), j(0), ie(mToolButtons.count()); i < ie; ++i ) {
   166     for ( int i(0), j(0), ie(mToolButtons.count()); i < ie; ++i ) {
   162         HbToolButton *button = mToolButtons.at(i);
   167         HbToolButton *button = mToolButtons.at(i);
   163         if ( button->action()->isVisible() ) {
   168         if ( HbToolButtonPrivate::d_ptr(button)->action->isVisible() ) {
   164             // Calculate the row and column indices
   169             // Calculate the row and column indices
   165             column = ( j % columns );
   170             column = ( j % columns );
   166             row = ( (j - column) / columns );
   171             row = ( (j - column) / columns );
   167             if ( row >= maxRow ) {
   172             if ( row >= maxRow ) {
   168                 qWarning() << "Too many items in extension!";
   173                 qWarning() << "Too many items in extension!";
   202 
   207 
   203 void HbToolBarExtensionPrivate::actionAdded( QActionEvent *event )
   208 void HbToolBarExtensionPrivate::actionAdded( QActionEvent *event )
   204 {
   209 {
   205     Q_Q(HbToolBarExtension);
   210     Q_Q(HbToolBarExtension);
   206 
   211 
   207     HbAction *action = qobject_cast<HbAction *>( event->action() );
   212     HbToolButton *button = 0;
   208 
   213 
   209     if (action) {
   214     HbAction *hbAction = qobject_cast<HbAction *>( event->action() );
   210         HbToolButton *button = new HbToolButton(action, q->contentWidget());
   215 
   211 
   216     if (hbAction) {
   212         if (!button->action()->icon().isNull()) {
   217         button = new HbToolButton(hbAction, q->contentWidget());
   213             if (button->action()->text().isEmpty()) {
   218     } else {
   214                 button->setToolButtonStyle(HbToolButton::ToolButtonIcon);
   219         button = new HbToolButton(q->contentWidget());
   215             } else {
   220         HbToolButtonPrivate::d_ptr(button)->action = event->action();
   216                 button->setToolButtonStyle(HbToolButton::ToolButtonTextAndIcon);
   221         QObject::connect(event->action(), SIGNAL(triggered()), button, SLOT(_q_actionTriggered()));
   217             }
   222         QObject::connect(event->action(), SIGNAL(changed()), button, SLOT(_q_actionChanged()));
       
   223     }
       
   224 
       
   225     if ((hbAction && !hbAction->icon().isNull()) || !event->action()->icon().isNull()) {
       
   226         if (HbToolButtonPrivate::d_ptr(button)->action->text().isEmpty()) {
       
   227             button->setToolButtonStyle(HbToolButton::ToolButtonIcon);
   218         } else {
   228         } else {
   219             button->setToolButtonStyle(HbToolButton::ToolButtonText);
   229             button->setToolButtonStyle(HbToolButton::ToolButtonTextAndIcon);
   220         }
       
   221 
       
   222         button->setProperty("toolbutton_extension_layout", true);
       
   223         button->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, 
       
   224                                             QSizePolicy::Preferred) );
       
   225 
       
   226         // Find out index where to insert button
       
   227         int index = q->actions().indexOf( event->action() );
       
   228 
       
   229         mToolButtons.insert( index, button );
       
   230         
       
   231         q->connect(button, SIGNAL(clicked()), q, SLOT(_q_animateButtonClicked()));
       
   232         q->connect(action, SIGNAL(triggered()), q, SLOT(close()));
       
   233         
       
   234         if (contentWidget){
       
   235             doLayout();
       
   236         }
   230         }
   237     } else {
   231     } else {
   238         qWarning() << "Use HbAction instead of QAction!";
   232         button->setToolButtonStyle(HbToolButton::ToolButtonText);
       
   233     }
       
   234 
       
   235     button->setProperty("toolbutton_extension_layout", true);
       
   236     button->setSizePolicy( QSizePolicy( QSizePolicy::Preferred,
       
   237                                         QSizePolicy::Preferred) );
       
   238 
       
   239     // Find out index where to insert button
       
   240     int index = q->actions().indexOf( event->action() );
       
   241 
       
   242     mToolButtons.insert( index, button );
       
   243 
       
   244     q->connect(button, SIGNAL(clicked()), q, SLOT(_q_animateButtonClicked()));
       
   245     q->connect(event->action(), SIGNAL(triggered()), q, SLOT(close()));
       
   246 
       
   247     if (contentWidget){
       
   248         doLayout();
   239     }
   249     }
   240 }
   250 }
   241 
   251 
   242 void HbToolBarExtensionPrivate::actionRemoved( QActionEvent *event )
   252 void HbToolBarExtensionPrivate::actionRemoved( QActionEvent *event )
   243 {
   253 {
   244     for ( int i(0); i < mToolButtons.count(); ++i ) {
   254     for ( int i(0); i < mToolButtons.count(); ++i ) {
   245         HbToolButton *button = mToolButtons.at(i);
   255         HbToolButton *button = mToolButtons.at(i);
   246         if ( button->action() == event->action() ) {            
   256         if ( HbToolButtonPrivate::d_ptr(button)->action == event->action() ) {
   247             mToolButtons.removeAt(i);                   
   257             mToolButtons.removeAt(i);                   
   248             if (contentWidget) {
   258             if (contentWidget) {
   249                 mLayout->removeAt(i);
   259                 mLayout->removeAt(i);
   250                 doLayout();
   260                 doLayout();
   251             }
   261             }
   302 {
   312 {
   303 #ifdef HB_EFFECTS
   313 #ifdef HB_EFFECTS
   304     Q_Q(HbToolBarExtension);
   314     Q_Q(HbToolBarExtension);
   305     HbToolButton *button = static_cast<HbToolButton *>(q->sender());
   315     HbToolButton *button = static_cast<HbToolButton *>(q->sender());
   306     if (button) {
   316     if (button) {
   307         HbEffect::start(button, "TBEButtonClicked", "clicked");
   317         HbEffect::start(button, "HB_TBE", "clicked");
   308     }
   318     }
   309 #endif
   319 #endif
   310 }
   320 }
   311 
   321 
   312 // ======== MEMBER FUNCTIONS ========
   322 // ======== MEMBER FUNCTIONS ========
   442         // fall trough
   452         // fall trough
   443     }
   453     }
   444     return HbDialog::event(event);
   454     return HbDialog::event(event);
   445 }
   455 }
   446 
   456 
       
   457 /*!
       
   458   \reimp
       
   459   */
   447 void HbToolBarExtension::polish( HbStyleParameters &params )
   460 void HbToolBarExtension::polish( HbStyleParameters &params )
   448 {    
   461 {    
   449     Q_D(HbToolBarExtension);  
   462     Q_D(HbToolBarExtension);  
   450     d->doLazyInit();
   463     d->doLazyInit();
   451     const QString Margins       = "content-margins";
   464     const QString Margins       = "content-margins";
   458     params.addParameter( RowsPortrait );
   471     params.addParameter( RowsPortrait );
   459     params.addParameter( RowsLandscape );
   472     params.addParameter( RowsLandscape );
   460     params.addParameter( ColsPortrait );
   473     params.addParameter( ColsPortrait );
   461     params.addParameter( ColsLandscape );
   474     params.addParameter( ColsLandscape );
   462     d->initialiseContent();
   475     d->initialiseContent();
   463     if (d->mDefaultContentWidget) {
   476     if (d->mDefaultContentWidget) {       
   464         QGraphicsWidget *tbeContentWidget = contentWidget();
       
   465         style()->setItemName( tbeContentWidget, "HbToolBarExtension" );
       
   466         HbDialog::polish(params);
   477         HbDialog::polish(params);
   467         if ( params.value( Margins ).isValid() 
   478         if ( params.value( Margins ).isValid() 
   468              && params.value( RowsPortrait ).isValid() 
   479              && params.value( RowsPortrait ).isValid() 
   469              && params.value( RowsLandscape ).isValid() 
   480              && params.value( RowsLandscape ).isValid() 
   470              && params.value( ColsPortrait ).isValid() 
   481              && params.value( ColsPortrait ).isValid()