33 #include "kselectaction_p.h"
35 #include <QActionEvent>
37 #include <QToolButton>
39 #include <QStandardItem>
58 , d_ptr(new KSelectActionPrivate())
66 , d_ptr(new KSelectActionPrivate())
75 , d_ptr(new KSelectActionPrivate())
98 QObject::connect(q_ptr->selectableActionGroup(), SIGNAL(triggered(
QAction*)), q_ptr, SLOT(actionTriggered(
QAction*)));
99 QObject::connect(q_ptr, SIGNAL(toggled(
bool)), q_ptr, SLOT(slotToggled(
bool)));
100 q_ptr->setMenu(
new KMenu());
101 q_ptr->setEnabled(
false );
107 return d->m_actionGroup;
137 if (
actions().contains(action)) {
138 if (action->isVisible() && action->isEnabled() && action->isCheckable()) {
139 action->setChecked(
true);
144 kWarning (129) <<
"Action does not have the correct properties to be current:" << action->text();
146 kWarning (129) <<
"Action does not belong to group:" << action->text();
173 if (cs == Qt::CaseSensitive)
176 compare = text.toLower();
180 if (cs == Qt::CaseSensitive) {
181 if (text == compare) {
185 }
else if (cs == Qt::CaseInsensitive) {
186 if (text.toLower() == compare) {
207 d->m_comboWidth = width;
209 foreach (
KComboBox* box, d->m_comboBoxes)
210 box->setMaximumWidth(d->m_comboWidth);
218 d->m_maxComboViewCount = n;
220 foreach (
KComboBox* box, d->m_comboBoxes)
221 if ( d->m_maxComboViewCount != -1 )
222 box->setMaxVisibleItems(d->m_maxComboViewCount);
225 box->setMaxVisibleItems(10);
242 button->setEnabled(
true);
243 button->addAction(action);
246 foreach (
KComboBox* comboBox, d->m_comboBoxes) {
247 comboBox->setEnabled(
true);
248 comboBox->addAction(action);
251 menu()->addAction(action);
258 newAction->setText(text);
259 newAction->setCheckable(
true );
262 if (!d->m_menuAccelsEnabled) {
263 newAction->setText(text);
274 newAction->setIcon(icon);
286 d->m_actionGroup->removeAction(action);
290 setEnabled( !hasActions );
293 button->setEnabled( !hasActions );
294 button->removeAction(action);
297 foreach (
KComboBox* comboBox, d->m_comboBoxes)
299 comboBox->setEnabled( !hasActions );
300 comboBox->removeAction(action);
303 menu()->removeAction(action);
340 if ( index < 0 || index >=
actions().count() )
342 kWarning() <<
"KSelectAction::changeItem Index out of scope";
346 actions()[index]->setText( d->makeMenuText( text ) );
356 foreach (
const QString&
string, lst) {
357 if ( !
string.isEmpty() ) {
361 action->setSeparator(
true);
367 setEnabled( lst.count() > 0 || d->m_edit );
373 return d->m_comboWidth;
383 const QList<QAction*>
actions = d->m_actionGroup->actions();
384 for (
int i = 0; i < actions.count(); ++i)
393 actions[i]->deleteLater();
400 while (d->m_actionGroup->actions().count())
409 foreach (
KComboBox* comboBox, d->m_comboBoxes)
431 return d->m_toolBarMode;
437 d->m_toolBarMode = mode;
443 return d->m_toolButtonPopupMode;
449 d->m_toolButtonPopupMode = mode;
452 void KSelectActionPrivate::_k_comboBoxDeleted(
QObject*
object)
454 foreach (
KComboBox* comboBox, m_comboBoxes)
455 if (
object == comboBox) {
456 m_comboBoxes.removeAll(static_cast<KComboBox*>(
object));
461 void KSelectActionPrivate::_k_comboBoxCurrentIndexChanged(
int index)
475 triggeringCombo && triggeringCombo->count () > 0 &&
476 index == triggeringCombo->count () - 1) {
479 const QString newItemText = triggeringCombo->currentText ();
483 bool blocked = triggeringCombo->blockSignals (
true);
484 triggeringCombo->removeItem (index);
485 triggeringCombo->blockSignals (blocked);
489 newAction->trigger();
501 d->m_menuAccelsEnabled = b;
507 return d->m_menuAccelsEnabled;
524 button->setToolTip(toolTip());
526 button->setStatusTip(statusTip());
527 button->setAutoRaise(
true);
528 button->setFocusPolicy(Qt::NoFocus);
529 button->setIconSize(toolBar->iconSize());
530 button->setToolButtonStyle(toolBar->toolButtonStyle());
531 QObject::connect(toolBar, SIGNAL(iconSizeChanged(
QSize)),
532 button, SLOT(setIconSize(
QSize)));
533 QObject::connect(toolBar, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
534 button, SLOT(setToolButtonStyle(Qt::ToolButtonStyle)));
535 button->setDefaultAction(
this);
542 d->m_buttons.append(button);
548 comboBox->installEventFilter (
this);
550 if ( d->m_maxComboViewCount != -1 )
551 comboBox->setMaxVisibleItems( d->m_maxComboViewCount );
553 if ( d->m_comboWidth > 0 )
554 comboBox->setMaximumWidth( d->m_comboWidth );
557 comboBox->setToolTip(toolTip());
559 comboBox->setStatusTip(statusTip());
562 comboBox->addAction(action);
565 comboBox->setEnabled(
false);
567 connect(comboBox, SIGNAL(destroyed(
QObject*)), SLOT(_k_comboBoxDeleted(
QObject*)));
568 connect(comboBox, SIGNAL(currentIndexChanged(
int)), SLOT(_k_comboBoxCurrentIndexChanged(
int)));
569 d->m_comboBoxes.append(comboBox);
581 if (
QToolButton *toolButton = qobject_cast<QToolButton *>(widget))
582 d->m_buttons.removeAll(toolButton);
583 else if (
KComboBox *comboBox = qobject_cast<KComboBox *>(widget))
584 d->m_comboBoxes.removeAll(comboBox);
591 if (event->type() == QEvent::ActionChanged) {
592 Q_FOREACH(
KComboBox* comboBox, d->m_comboBoxes) {
593 comboBox->setToolTip(toolTip());
595 comboBox->setStatusTip(statusTip());
598 toolButton->setToolTip(toolTip());
600 toolButton->setStatusTip(statusTip());
625 if (action->isChecked ())
630 if (action != curAction)
633 return sa->
actions ().indexOf (action);
640 return (curAction && curAction->isChecked ()) ? sa->
actions ().indexOf (curAction) : -1;
655 if (event->type () == QEvent::FocusOut) {
656 QFocusEvent *
const e = static_cast <QFocusEvent *> (event);
662 if (e->reason () != Qt::ActiveWindowFocusReason &&
663 e->reason () != Qt::PopupFocusReason &&
664 e->reason () != Qt::OtherFocusReason) {
667 comboBox->setEditText (comboBox->itemText (comboBox->currentIndex ()));
673 bool blocked = comboBox->blockSignals (
true);
675 if (event->type () == QEvent::ActionAdded)
677 QActionEvent *
const e = static_cast <QActionEvent *> (event);
679 const int index = e->before () ?
680 comboBox->findData (QVariant::fromValue (e->before ())) :
693 comboBox->insertItem (index,
696 QVariant::fromValue (e->action ()));
697 if (QStandardItemModel *model = qobject_cast<QStandardItemModel *>(comboBox->model())) {
698 QStandardItem *item = model->item(index);
699 item->setEnabled(e->action()->isEnabled());
704 comboBox->setCurrentIndex (newItem);
706 else if (event->type () == QEvent::ActionChanged)
708 QActionEvent *
const e = static_cast <QActionEvent *> (event);
710 const int index = comboBox->findData (QVariant::fromValue (e->action ()));
721 comboBox->setItemIcon (index, e->action ()->icon ());
722 comboBox->setItemText (index, ::
DropAmpersands (e->action ()->text ()));
723 if (QStandardItemModel *model = qobject_cast<QStandardItemModel *>(comboBox->model())) {
724 QStandardItem *item = model->item(index);
725 item->setEnabled(e->action()->isEnabled());
730 comboBox->setCurrentIndex (newItem);
732 else if (event->type () == QEvent::ActionRemoved)
734 QActionEvent *
const e = static_cast <QActionEvent *> (event);
736 const int index = comboBox->findData (QVariant::fromValue (e->action ()));
744 comboBox->removeItem (index);
748 comboBox->setCurrentIndex (newItem);
751 comboBox->blockSignals (blocked);
761 #include "kselectaction.moc"