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 } |
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() |