src/hbcore/gui/hbtoolbarextension.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
child 21 4633027730f5
child 34 ed14f46c0e55
--- a/src/hbcore/gui/hbtoolbarextension.cpp	Thu Jul 15 14:03:49 2010 +0100
+++ b/src/hbcore/gui/hbtoolbarextension.cpp	Thu Jul 22 16:36:53 2010 +0100
@@ -41,7 +41,6 @@
 #include <QDebug>
 #include <QGraphicsGridLayout>
 #include <QEventLoop>
-#include <QPainter>
 #include <QGraphicsLinearLayout> 
 
 /*!
@@ -69,6 +68,11 @@
     \fn int HbToolBarExtension::type() const
  */
 
+/*!
+  \primitives
+  \primitive{background} HbFrameItem representing the extension background.
+  */
+
 HbToolBarExtensionPrivate::HbToolBarExtensionPrivate() :
         HbDialogPrivate(),
         mToolButtons(),
@@ -107,9 +111,8 @@
 
 void HbToolBarExtensionPrivate::doLazyInit()
 {
-    Q_Q(HbToolBarExtension);
     if ( !lazyInitDone ) {
-        q->setBackgroundItem( HbStyle::P_ToolBarExtension_background );
+        setBackgroundItem(HbStyle::P_ToolBarExtension_background);
 #ifdef HB_EFFECTS
         if (!extensionEffectsLoaded){
             HbEffectInternal::add("HB_TBE", "tbe_button_click", "clicked");
@@ -152,7 +155,7 @@
         return;
 
     foreach (HbToolButton* button, mToolButtons) {
-        button->setVisible(button->action()->isVisible());
+        button->setVisible(HbToolButtonPrivate::d_ptr(button)->action->isVisible());
     }
 
     mLayout = new QGraphicsGridLayout();
@@ -160,7 +163,7 @@
     mLayout->setSpacing(0.0);  // if non zero spacing needed, add to css
     for ( int i(0), j(0), ie(mToolButtons.count()); i < ie; ++i ) {
         HbToolButton *button = mToolButtons.at(i);
-        if ( button->action()->isVisible() ) {
+        if ( HbToolButtonPrivate::d_ptr(button)->action->isVisible() ) {
             // Calculate the row and column indices
             column = ( j % columns );
             row = ( (j - column) / columns );
@@ -204,38 +207,46 @@
 {
     Q_Q(HbToolBarExtension);
 
-    HbAction *action = qobject_cast<HbAction *>( event->action() );
-
-    if (action) {
-        HbToolButton *button = new HbToolButton(action, q->contentWidget());
+    HbToolButton *button = 0;
 
-        if (!button->action()->icon().isNull()) {
-            if (button->action()->text().isEmpty()) {
-                button->setToolButtonStyle(HbToolButton::ToolButtonIcon);
-            } else {
-                button->setToolButtonStyle(HbToolButton::ToolButtonTextAndIcon);
-            }
-        } else {
-            button->setToolButtonStyle(HbToolButton::ToolButtonText);
-        }
+    HbAction *hbAction = qobject_cast<HbAction *>( event->action() );
 
-        button->setProperty("toolbutton_extension_layout", true);
-        button->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, 
-                                            QSizePolicy::Preferred) );
-
-        // Find out index where to insert button
-        int index = q->actions().indexOf( event->action() );
+    if (hbAction) {
+        if (!q->contentWidget()) {
+            initialiseContent(); // create now to prevent mem leak below
+        }
+        button = new HbToolButton(hbAction, q->contentWidget());
+    } else {
+        button = new HbToolButton(q->contentWidget());
+        HbToolButtonPrivate::d_ptr(button)->action = event->action();
+        QObject::connect(event->action(), SIGNAL(triggered()), button, SLOT(_q_actionTriggered()));
+        QObject::connect(event->action(), SIGNAL(changed()), button, SLOT(_q_actionChanged()));
+    }
 
-        mToolButtons.insert( index, button );
-        
-        q->connect(button, SIGNAL(clicked()), q, SLOT(_q_animateButtonClicked()));
-        q->connect(action, SIGNAL(triggered()), q, SLOT(close()));
-        
-        if (contentWidget){
-            doLayout();
+    if ((hbAction && !hbAction->icon().isNull()) || !event->action()->icon().isNull()) {
+        if (HbToolButtonPrivate::d_ptr(button)->action->text().isEmpty()) {
+            button->setToolButtonStyle(HbToolButton::ToolButtonIcon);
+        } else {
+            button->setToolButtonStyle(HbToolButton::ToolButtonTextAndIcon);
         }
     } else {
-        qWarning() << "Use HbAction instead of QAction!";
+        button->setToolButtonStyle(HbToolButton::ToolButtonText);
+    }
+
+    button->setProperty("toolbutton_extension_layout", true);
+    button->setSizePolicy( QSizePolicy( QSizePolicy::Preferred,
+                                        QSizePolicy::Preferred) );
+
+    // Find out index where to insert button
+    int index = q->actions().indexOf( event->action() );
+
+    mToolButtons.insert( index, button );
+
+    q->connect(button, SIGNAL(clicked()), q, SLOT(_q_animateButtonClicked()));
+    q->connect(event->action(), SIGNAL(triggered()), q, SLOT(close()));
+
+    if (contentWidget){
+        doLayout();
     }
 }
 
@@ -243,7 +254,7 @@
 {
     for ( int i(0); i < mToolButtons.count(); ++i ) {
         HbToolButton *button = mToolButtons.at(i);
-        if ( button->action() == event->action() ) {            
+        if ( HbToolButtonPrivate::d_ptr(button)->action == event->action() ) {
             mToolButtons.removeAt(i);                   
             if (contentWidget) {
                 mLayout->removeAt(i);
@@ -304,7 +315,7 @@
     Q_Q(HbToolBarExtension);
     HbToolButton *button = static_cast<HbToolButton *>(q->sender());
     if (button) {
-        HbEffect::start(button, "TBEButtonClicked", "clicked");
+        HbEffect::start(button, "HB_TBE", "clicked");
     }
 #endif
 }
@@ -328,7 +339,6 @@
  */
 HbToolBarExtension::~HbToolBarExtension()
 {
-    disconnect();
 }
 
 /*!
@@ -444,6 +454,9 @@
     return HbDialog::event(event);
 }
 
+/*!
+  \reimp
+  */
 void HbToolBarExtension::polish( HbStyleParameters &params )
 {    
     Q_D(HbToolBarExtension);  
@@ -460,9 +473,7 @@
     params.addParameter( ColsPortrait );
     params.addParameter( ColsLandscape );
     d->initialiseContent();
-    if (d->mDefaultContentWidget) {
-        QGraphicsWidget *tbeContentWidget = contentWidget();
-        style()->setItemName( tbeContentWidget, "HbToolBarExtension" );
+    if (d->mDefaultContentWidget) {       
         HbDialog::polish(params);
         if ( params.value( Margins ).isValid() 
              && params.value( RowsPortrait ).isValid()