31 #include <QtCore/QPointer>
32 #include <QtGui/QDesktopWidget>
33 #include <QtGui/QFrame>
34 #include <QtGui/QLayout>
35 #include <QtGui/QMouseEvent>
36 #include <QtGui/QToolButton>
37 #include <QtXml/QDomElement>
89 class KToolBar::Private
98 unlockedMovable(true),
102 contextButtonTitle(0),
104 contextButtonAction(0),
113 contextLockAction(0),
114 dropIndicatorAction(0),
120 void slotAppearanceChanged();
121 void slotContextAboutToShow();
122 void slotContextAboutToHide();
123 void slotContextLeft();
124 void slotContextRight();
125 void slotContextShowText();
126 void slotContextTop();
127 void slotContextBottom();
128 void slotContextIcons();
129 void slotContextText();
130 void slotContextTextRight();
131 void slotContextTextUnder();
132 void slotContextIconSize();
133 void slotLockToolBars(
bool lock);
135 void init(
bool readConfig =
true,
bool isMainToolBar =
false);
136 QString getPositionAsString()
const;
138 void setLocked(
bool locked);
139 void adjustSeparatorVisibility();
140 void loadKDESettings();
141 void applyCurrentSettings();
145 static Qt::ToolButtonStyle toolButtonStyleFromString(
const QString& style);
146 static QString toolButtonStyleToString(Qt::ToolButtonStyle);
147 static Qt::ToolBarArea positionFromString(
const QString& position);
150 bool isMainToolBar : 1;
151 #ifndef KDE_NO_DEPRECATED
152 bool enableContext : 1;
154 bool unlockedMovable : 1;
155 static bool s_editable;
156 static bool s_locked;
158 QSet<KXMLGUIClient *> xmlguiClients;
160 QMenu* contextOrient;
183 values[level] =
Unset;
186 int currentValue()
const {
189 if (values[level] !=
Unset)
199 if (values[level] !=
Unset)
207 str += QString::number(values[level]) +
' ';
211 int& operator[](
int index) {
return values[index]; }
215 IntSetting iconSizeSettings;
216 IntSetting toolButtonStyleSettings;
218 QList<QAction*> actionsBeingDragged;
226 bool KToolBar::Private::s_editable =
false;
227 bool KToolBar::Private::s_locked =
true;
229 void KToolBar::Private::init(
bool readConfig,
bool _isMainToolBar)
231 isMainToolBar = _isMainToolBar;
238 q->applySettings(cg);
241 if (q->mainWindow()) {
243 connect(q, SIGNAL(allowedAreasChanged(Qt::ToolBarAreas)),
244 q->mainWindow(), SLOT(setSettingsDirty()));
245 connect(q, SIGNAL(iconSizeChanged(
QSize)),
246 q->mainWindow(), SLOT(setSettingsDirty()));
247 connect(q, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
248 q->mainWindow(), SLOT(setSettingsDirty()));
249 connect(q, SIGNAL(movableChanged(
bool)),
250 q->mainWindow(), SLOT(setSettingsDirty()));
251 connect(q, SIGNAL(orientationChanged(Qt::Orientation)),
252 q->mainWindow(), SLOT(setSettingsDirty()));
256 q->setMovable(
false);
260 connect(q, SIGNAL(movableChanged(
bool)),
261 q, SLOT(slotMovableChanged(
bool)));
263 q->setAcceptDrops(
true);
266 q, SLOT(slotAppearanceChanged()));
268 q, SLOT(slotAppearanceChanged()));
271 QString KToolBar::Private::getPositionAsString()
const
274 switch (q->mainWindow()->toolBarArea(const_cast<KToolBar*>(q))) {
275 case Qt::BottomToolBarArea:
277 case Qt::LeftToolBarArea:
279 case Qt::RightToolBarArea:
281 case Qt::TopToolBarArea:
287 KMenu *KToolBar::Private::contextMenu(
const QPoint &globalPos)
290 context =
new KMenu(q);
292 contextButtonTitle = context->addTitle(
i18nc(
"@title:menu",
"Show Text"));
293 contextShowText = context->addAction(
QString(), q, SLOT(slotContextShowText()));
295 context->addTitle(
i18nc(
"@title:menu",
"Toolbar Settings"));
297 contextOrient =
new KMenu(
i18n(
"Orientation"), context);
299 contextTop = contextOrient->addAction(
i18nc(
"toolbar position string",
"Top"), q, SLOT(slotContextTop()));
300 contextTop->setChecked(
true);
301 contextLeft = contextOrient->addAction(
i18nc(
"toolbar position string",
"Left"), q, SLOT(slotContextLeft()));
302 contextRight = contextOrient->addAction(
i18nc(
"toolbar position string",
"Right"), q, SLOT(slotContextRight()));
303 contextBottom = contextOrient->addAction(
i18nc(
"toolbar position string",
"Bottom"), q, SLOT(slotContextBottom()));
305 QActionGroup* positionGroup =
new QActionGroup(contextOrient);
306 foreach (
QAction* action, contextOrient->actions()) {
307 action->setActionGroup(positionGroup);
308 action->setCheckable(
true);
311 contextMode =
new KMenu(
i18n(
"Text Position"), context);
313 contextIcons = contextMode->addAction(
i18n(
"Icons Only"), q, SLOT(slotContextIcons()));
314 contextText = contextMode->addAction(
i18n(
"Text Only"), q, SLOT(slotContextText()));
315 contextTextRight = contextMode->addAction(
i18n(
"Text Alongside Icons"), q, SLOT(slotContextTextRight()));
316 contextTextUnder = contextMode->addAction(
i18n(
"Text Under Icons"), q, SLOT(slotContextTextUnder()));
318 QActionGroup* textGroup =
new QActionGroup(contextMode);
319 foreach (
QAction* action, contextMode->actions()) {
320 action->setActionGroup(textGroup);
321 action->setCheckable(
true);
324 contextSize =
new KMenu(
i18n(
"Icon Size"), context);
326 contextIconSizes.insert(contextSize->addAction(
i18nc(
"@item:inmenu Icon size",
"Default"), q, SLOT(slotContextIconSize())),
327 iconSizeSettings.defaultValue());
338 if (avSizes.count() < 10) {
340 foreach (
int it, avSizes) {
343 text =
i18n(
"Small (%1x%2)", it, it);
345 text =
i18n(
"Medium (%1x%2)", it, it);
347 text =
i18n(
"Large (%1x%2)", it, it);
349 text =
i18n(
"Huge (%1x%2)", it, it);
352 contextIconSizes.insert(contextSize->addAction(text, q, SLOT(slotContextIconSize())), it);
356 const int progression[] = { 16, 22, 32, 48, 64, 96, 128, 192, 256 };
358 for (uint i = 0; i < 9; i++) {
359 foreach (
int it, avSizes) {
360 if (it >= progression[ i ]) {
363 text =
i18n(
"Small (%1x%2)", it, it);
365 text =
i18n(
"Medium (%1x%2)", it, it);
367 text =
i18n(
"Large (%1x%2)", it, it);
369 text =
i18n(
"Huge (%1x%2)", it, it);
372 contextIconSizes.insert(contextSize->addAction(text, q, SLOT(slotContextIconSize())), it);
379 QActionGroup* sizeGroup =
new QActionGroup(contextSize);
380 foreach (
QAction* action, contextSize->actions()) {
381 action->setActionGroup(sizeGroup);
382 action->setCheckable(
true);
385 if (!q->toolBarsLocked() && !q->isMovable())
386 unlockedMovable =
false;
388 delete contextLockAction;
390 contextLockAction->setChecked(q->toolBarsLocked());
391 connect(contextLockAction, SIGNAL(toggled(
bool)), q, SLOT(slotLockToolBars(
bool)));
394 context->addMenu(contextMode);
395 context->addMenu(contextSize);
396 context->addMenu(contextOrient);
397 context->addSeparator();
399 connect(context, SIGNAL(aboutToShow()), q, SLOT(slotContextAboutToShow()));
402 contextButtonAction = q->actionAt(q->mapFromGlobal(globalPos));
403 if (contextButtonAction) {
404 contextShowText->setText(contextButtonAction->text());
405 contextShowText->setIcon(contextButtonAction->icon());
406 contextShowText->setCheckable(
true);
409 contextOrient->menuAction()->setVisible(!q->toolBarsLocked());
417 void KToolBar::Private::setLocked(
bool locked)
420 q->setMovable(!locked);
423 void KToolBar::Private::adjustSeparatorVisibility()
425 bool visibleNonSeparator =
false;
426 int separatorToShow = -1;
428 for (
int index = 0; index < q->actions().count(); ++index) {
429 QAction* action = q->actions()[ index ];
430 if (action->isSeparator()) {
431 if (visibleNonSeparator) {
432 separatorToShow = index;
433 visibleNonSeparator =
false;
435 action->setVisible(
false);
437 }
else if (!visibleNonSeparator) {
438 if (action->isVisible()) {
439 visibleNonSeparator =
true;
440 if (separatorToShow != -1) {
441 q->actions()[ separatorToShow ]->setVisible(
true);
442 separatorToShow = -1;
448 if (separatorToShow != -1)
449 q->actions()[ separatorToShow ]->setVisible(
false);
452 Qt::ToolButtonStyle KToolBar::Private::toolButtonStyleFromString(
const QString & _style)
454 QString style = _style.toLower();
455 if (style ==
"textbesideicon" || style ==
"icontextright")
456 return Qt::ToolButtonTextBesideIcon;
457 else if (style ==
"textundericon" || style ==
"icontextbottom")
458 return Qt::ToolButtonTextUnderIcon;
459 else if (style ==
"textonly")
460 return Qt::ToolButtonTextOnly;
462 return Qt::ToolButtonIconOnly;
465 QString KToolBar::Private::toolButtonStyleToString(Qt::ToolButtonStyle style)
469 case Qt::ToolButtonIconOnly:
472 case Qt::ToolButtonTextBesideIcon:
473 return "TextBesideIcon";
474 case Qt::ToolButtonTextOnly:
476 case Qt::ToolButtonTextUnderIcon:
477 return "TextUnderIcon";
481 Qt::ToolBarArea KToolBar::Private::positionFromString(
const QString& position)
483 Qt::ToolBarArea newposition = Qt::TopToolBarArea;
484 if (position == QLatin1String(
"left")) {
485 newposition = Qt::LeftToolBarArea;
486 }
else if (position == QLatin1String(
"bottom")) {
487 newposition = Qt::BottomToolBarArea;
488 }
else if (position == QLatin1String(
"right")) {
489 newposition = Qt::RightToolBarArea;
495 void KToolBar::Private::slotAppearanceChanged()
498 applyCurrentSettings();
501 void KToolBar::Private::loadKDESettings()
508 const QString fallBack = toolButtonStyleToString(Qt::ToolButtonTextBesideIcon);
525 const QString value =
group.readEntry(
"ToolButtonStyleOtherToolbars", fallBack);
526 toolButtonStyleSettings[
Level_KDEDefault] = KToolBar::Private::toolButtonStyleFromString(value);
531 void KToolBar::Private::applyCurrentSettings()
534 const int currentIconSize = iconSizeSettings.currentValue();
535 q->setIconSize(
QSize(currentIconSize, currentIconSize));
537 q->setToolButtonStyle(static_cast<Qt::ToolButtonStyle>(toolButtonStyleSettings.currentValue()));
559 void KToolBar::Private::slotContextAboutToShow()
574 configureAction = findAction(actionName);
576 if (!configureAction && kmw) {
580 if (configureAction) {
581 context->addAction(configureAction);
584 context->addAction(contextLockAction);
590 if (!q->toolBarsLocked() && tbAction && tbAction->associatedWidgets().count() > 0)
591 context->addAction(tbAction);
597 switch (q->toolButtonStyle()) {
598 case Qt::ToolButtonIconOnly:
600 contextIcons->setChecked(
true);
602 case Qt::ToolButtonTextBesideIcon:
603 contextTextRight->setChecked(
true);
605 case Qt::ToolButtonTextOnly:
606 contextText->setChecked(
true);
608 case Qt::ToolButtonTextUnderIcon:
609 contextTextUnder->setChecked(
true);
613 QMapIterator< QAction*, int > it = contextIconSizes;
614 while (it.hasNext()) {
616 if (it.value() == q->iconSize().width()) {
617 it.key()->setChecked(
true);
622 switch (q->mainWindow()->toolBarArea(q)) {
623 case Qt::BottomToolBarArea:
624 contextBottom->setChecked(
true);
626 case Qt::LeftToolBarArea:
627 contextLeft->setChecked(
true);
629 case Qt::RightToolBarArea:
630 contextRight->setChecked(
true);
633 case Qt::TopToolBarArea:
634 contextTop->setChecked(
true);
638 const bool showButtonSettings = contextButtonAction
639 && !contextShowText->text().isEmpty()
640 && contextTextRight->isChecked();
641 contextButtonTitle->setVisible(showButtonSettings);
642 contextShowText->setVisible(showButtonSettings);
643 if (showButtonSettings) {
644 contextShowText->setChecked(contextButtonAction->priority() >= QAction::NormalPriority);
648 void KToolBar::Private::slotContextAboutToHide()
662 configureAction = findAction(actionName);
664 if (!configureAction && kmw) {
668 if (configureAction) {
669 context->removeAction(configureAction);
672 context->removeAction(contextLockAction);
675 void KToolBar::Private::slotContextLeft()
677 q->mainWindow()->addToolBar(Qt::LeftToolBarArea, q);
680 void KToolBar::Private::slotContextRight()
682 q->mainWindow()->addToolBar(Qt::RightToolBarArea, q);
685 void KToolBar::Private::slotContextShowText()
687 Q_ASSERT(contextButtonAction);
688 const QAction::Priority priority = contextShowText->isChecked()
689 ? QAction::NormalPriority : QAction::LowPriority;
690 contextButtonAction->setPriority(priority);
696 if (findAction(contextButtonAction->objectName(), &client)) {
700 if (filename.isEmpty()) {
708 QDomDocument document;
709 document.setContent(configFile);
712 actionElem.setAttribute(
"priority", priority);
716 void KToolBar::Private::slotContextTop()
718 q->mainWindow()->addToolBar(Qt::TopToolBarArea, q);
721 void KToolBar::Private::slotContextBottom()
723 q->mainWindow()->addToolBar(Qt::BottomToolBarArea, q);
726 void KToolBar::Private::slotContextIcons()
728 q->setToolButtonStyle(Qt::ToolButtonIconOnly);
732 void KToolBar::Private::slotContextText()
734 q->setToolButtonStyle(Qt::ToolButtonTextOnly);
738 void KToolBar::Private::slotContextTextUnder()
740 q->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
744 void KToolBar::Private::slotContextTextRight()
746 q->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
750 void KToolBar::Private::slotContextIconSize()
753 if (action && contextIconSizes.contains(action)) {
754 const int iconSize = contextIconSizes.value(action);
755 q->setIconDimensions(iconSize);
759 void KToolBar::Private::slotLockToolBars(
bool lock)
761 q->setToolBarsLocked(lock);
770 d->init(readConfig, isMainToolBar);
773 if (
QMainWindow* mw = qobject_cast<QMainWindow*>(parent))
774 mw->addToolBar(
this);
781 setObjectName(objectName);
784 d->init(readConfig, objectName ==
"mainToolBar");
787 if (
QMainWindow* mw = qobject_cast<QMainWindow*>(parent))
788 mw->addToolBar(
this);
792 bool newLine,
bool isMainToolBar,
bool readConfig)
796 setObjectName(objectName);
797 d->init(readConfig, isMainToolBar);
810 delete d->contextLockAction;
814 #ifndef KDE_NO_DEPRECATED
817 d->enableContext = enable;
821 #ifndef KDE_NO_DEPRECATED
824 return d->enableContext;
830 Q_ASSERT(!cg.
name().isEmpty());
834 const int currentIconSize = iconSize().width();
836 if (!cg.
hasDefault(
"IconSize") && currentIconSize == d->iconSizeSettings.defaultValue()) {
844 const Qt::ToolButtonStyle currentToolButtonStyle = toolButtonStyle();
845 if (!cg.
hasDefault(
"ToolButtonStyle") && currentToolButtonStyle == d->toolButtonStyleSettings.defaultValue()) {
849 cg.
writeEntry(
"ToolButtonStyle", d->toolButtonStyleToString(currentToolButtonStyle));
854 #ifndef KDE_NO_DEPRECATED
857 d->xmlguiClients.clear();
858 d->xmlguiClients << client;
864 d->xmlguiClients << client;
869 #ifndef KDE_NO_DEPRECATED
871 QPointer<KToolBar> guard(
this);
872 const QPoint globalPos =
event->globalPos();
873 d->contextMenu(globalPos)->exec(globalPos);
877 d->slotContextAboutToHide();
889 const QString fallback = Private::toolButtonStyleToString(Qt::ToolButtonTextBesideIcon);
890 return KToolBar::Private::toolButtonStyleFromString(group.
readEntry(
"ToolButtonStyle", fallback));
900 QDomNode textNode = element.namedItem(
"text");
903 if (textNode.isElement())
905 QDomElement textElement = textNode.toElement();
906 text = textElement.text().toUtf8();
907 context = textElement.attribute(
"context").toUtf8();
911 textNode = element.namedItem(
"Text");
912 if (textNode.isElement())
914 QDomElement textElement = textNode.toElement();
915 text = textElement.text().toUtf8();
916 context = textElement.attribute(
"context").toUtf8();
921 if (!text.isEmpty() && !context.isEmpty())
922 i18nText =
i18nc(context, text);
923 else if (!text.isEmpty())
924 i18nText =
i18n(text);
926 if (!i18nText.isEmpty())
927 setWindowTitle(i18nText);
942 bool loadingAppDefaults =
true;
943 if (element.hasAttribute(
"tempXml")) {
945 loadingAppDefaults =
false;
947 if (!iconSizeDefault.isEmpty()) {
948 d->iconSizeSettings[
Level_AppXML] = iconSizeDefault.toInt();
950 const QString toolButtonStyleDefault = element.attribute(
"toolButtonStyleDefault");
951 if (!toolButtonStyleDefault.isEmpty()) {
952 d->toolButtonStyleSettings[
Level_AppXML] = d->toolButtonStyleFromString(toolButtonStyleDefault);
956 bool newLine =
false;
957 QString attrNewLine = element.attribute(
"newline").toLower();
958 if (!attrNewLine.isEmpty())
959 newLine = attrNewLine ==
"true";
961 mw->insertToolBarBreak(
this);
964 int newIconSize = -1;
965 if (element.hasAttribute(
"iconSize")) {
967 newIconSize = element.attribute(
"iconSize").trimmed().toInt(&ok);
971 if (newIconSize != -1)
974 const QString newToolButtonStyle = element.attribute(
"iconText");
975 if (!newToolButtonStyle.isEmpty())
980 QString attrHidden = element.attribute(
"hidden").toLower();
981 if (!attrHidden.isEmpty())
982 hidden = attrHidden ==
"true";
985 Qt::ToolBarArea pos = Qt::NoToolBarArea;
987 QString attrPosition = element.attribute(
"position").toLower();
988 if (!attrPosition.isEmpty())
989 pos = KToolBar::Private::positionFromString(attrPosition);
991 if (pos != Qt::NoToolBarArea)
992 mw->addToolBar(pos,
this);
996 d->applyCurrentSettings();
1003 Q_ASSERT(!current.isNull());
1005 current.setAttribute(
"tempXml",
"true");
1007 current.setAttribute(
"noMerge",
"1");
1008 current.setAttribute(
"position", d->getPositionAsString().toLower());
1009 current.setAttribute(
"hidden", isHidden() ?
"true" :
"false");
1011 const int currentIconSize = iconSize().width();
1012 if (currentIconSize == d->iconSizeSettings.defaultValue())
1013 current.removeAttribute(
"iconSize");
1015 current.setAttribute(
"iconSize", iconSize().width());
1017 if (toolButtonStyle() == d->toolButtonStyleSettings.defaultValue())
1018 current.removeAttribute(
"iconText");
1020 current.setAttribute(
"iconText", d->toolButtonStyleToString(toolButtonStyle()));
1025 current.setAttribute(
"iconSizeDefault", d->iconSizeSettings[
Level_AppXML]);
1028 const Qt::ToolButtonStyle bs =
static_cast<Qt::ToolButtonStyle
>(d->toolButtonStyleSettings[
Level_AppXML]);
1029 current.setAttribute(
"toolButtonStyleDefault", d->toolButtonStyleToString(bs));
1036 Q_ASSERT(!cg.
name().isEmpty());
1037 Q_UNUSED(forceGlobal);
1042 if (cg.
hasKey(
"Hidden")) {
1043 const bool hidden = cg.
readEntry(
"Hidden",
false);
1051 if (cg.
hasKey(
"IconSize")) {
1054 if (cg.
hasKey(
"ToolButtonStyle")) {
1058 d->applyCurrentSettings();
1068 QToolBar::setIconSize(
QSize(size, size));
1085 if (
toolBarsEditable() && event->proposedAction() & (Qt::CopyAction | Qt::MoveAction) &&
1086 event->mimeData()->hasFormat(
"application/x-kde-action-list")) {
1087 QByteArray data =
event->mimeData()->data(
"application/x-kde-action-list");
1089 QDataStream stream(data);
1093 stream >> actionNames;
1095 foreach (
const QString& actionName, actionNames) {
1097 QAction* newAction = ac->
action(actionName.toAscii().constData());
1099 d->actionsBeingDragged.append(newAction);
1105 if (d->actionsBeingDragged.count()) {
1106 QAction* overAction = actionAt(event->pos());
1109 dropIndicatorWidget->resize(8, height() - 4);
1110 dropIndicatorWidget->setFrameShape(QFrame::VLine);
1111 dropIndicatorWidget->setLineWidth(3);
1113 d->dropIndicatorAction = insertWidget(overAction, dropIndicatorWidget);
1115 insertAction(overAction, d->dropIndicatorAction);
1117 event->acceptProposedAction();
1129 if (d->dropIndicatorAction) {
1131 foreach (
QAction* action, actions()) {
1133 QWidget* widget = widgetForAction(action);
1134 if (event->pos().x() < widget->pos().x() + (widget->width() / 2)) {
1135 overAction = action;
1140 if (overAction != d->dropIndicatorAction) {
1142 int dropIndicatorIndex = actions().indexOf(d->dropIndicatorAction);
1143 if (dropIndicatorIndex + 1 < actions().count()) {
1144 if (actions()[ dropIndicatorIndex + 1 ] == overAction)
1146 }
else if (!overAction) {
1150 insertAction(overAction, d->dropIndicatorAction);
1165 delete d->dropIndicatorAction;
1166 d->dropIndicatorAction = 0L;
1167 d->actionsBeingDragged.clear();
1180 foreach (
QAction* action, d->actionsBeingDragged) {
1181 if (actions().contains(action))
1182 removeAction(action);
1183 insertAction(d->dropIndicatorAction, action);
1188 delete d->dropIndicatorAction;
1189 d->dropIndicatorAction = 0L;
1190 d->actionsBeingDragged.clear();
1203 if (
KAction* action = qobject_cast<KAction*>(actionAt(event->pos()))) {
1204 d->dragAction = action;
1205 d->dragStartPosition =
event->pos();
1219 if ((event->pos() - d->dragStartPosition).manhattanLength() < QApplication::startDragDistance()) {
1224 QDrag *drag =
new QDrag(
this);
1225 QMimeData *mimeData =
new QMimeData;
1229 QDataStream stream(&data, QIODevice::WriteOnly);
1232 actionNames << d->dragAction->objectName();
1234 stream << actionNames;
1237 mimeData->setData(
"application/x-kde-action-list", data);
1239 drag->setMimeData(mimeData);
1241 Qt::DropAction dropAction = drag->start(Qt::MoveAction);
1243 if (dropAction == Qt::MoveAction)
1246 if (drag->target() !=
this)
1247 removeAction(d->dragAction);
1256 if (d->dragAction) {
1268 if (event->type() == QEvent::MouseButtonPress) {
1269 QMouseEvent* me =
static_cast<QMouseEvent*
>(event);
1270 if (me->buttons() & Qt::RightButton)
1271 if (
QWidget* ww = qobject_cast<QWidget*>(watched))
1272 if (ww->parent() ==
this && !ww->isEnabled())
1273 QCoreApplication::postEvent(
this,
new QContextMenuEvent(QContextMenuEvent::Mouse, me->pos(), me->globalPos()));
1275 }
else if (event->type() == QEvent::ParentChange) {
1278 if (
QWidget* ww = qobject_cast<QWidget*>(watched)) {
1279 if (!this->isAncestorOf(ww)) {
1281 ww->removeEventFilter(
this);
1283 child->removeEventFilter(
this);
1289 if ((tb = qobject_cast<QToolButton*>(watched))) {
1290 const QList<QAction*> tbActions = tb->actions();
1291 if (!tbActions.isEmpty()) {
1293 if (event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::MouseButtonRelease) {
1294 QMouseEvent* me =
static_cast<QMouseEvent*
>(event);
1295 if (me->button() == Qt::MidButton
1297 QAction* act = tbActions.first();
1298 if (me->type() == QEvent::MouseButtonPress)
1299 tb->setDown(act->isEnabled());
1302 if (act->isEnabled()) {
1303 QMetaObject::invokeMethod(act,
"triggered", Qt::DirectConnection,
1304 Q_ARG(Qt::MouseButtons, me->button()),
1305 Q_ARG(Qt::KeyboardModifiers, QApplication::keyboardModifiers()));
1315 if (event->type() == QEvent::Show ||
event->type() == QEvent::Paint ||
event->type() == QEvent::EnabledChange) {
1316 QAction *act = tb->defaultAction();
1321 tb->setText(
i18nc(
"@action:intoolbar Text label of toolbar button",
"%1", text));
1322 tb->setToolTip(
i18nc(
"@info:tooltip Tooltip of toolbar button",
"%1", toolTip));
1330 if (
QWidget* ww = qobject_cast<QWidget*>(watched)) {
1331 switch (event->type()) {
1332 case QEvent::MouseButtonPress: {
1333 QMouseEvent* me =
static_cast<QMouseEvent*
>(event);
1334 QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(),
1335 me->button(), me->buttons(), me->modifiers());
1339 case QEvent::MouseMove: {
1340 QMouseEvent* me =
static_cast<QMouseEvent*
>(event);
1341 QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(),
1342 me->button(), me->buttons(), me->modifiers());
1346 case QEvent::MouseButtonRelease: {
1347 QMouseEvent* me =
static_cast<QMouseEvent*
>(event);
1348 QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(),
1349 me->button(), me->buttons(), me->modifiers());
1364 if (event->type() == QEvent::ActionRemoved) {
1365 QWidget* widget = widgetForAction(event->action());
1367 widget->removeEventFilter(
this);
1370 child->removeEventFilter(
this);
1376 if (event->type() == QEvent::ActionAdded) {
1377 QWidget* widget = widgetForAction(event->action());
1379 widget->installEventFilter(
this);
1382 child->installEventFilter(
this);
1384 if (!(widget->sizePolicy().horizontalPolicy() & QSizePolicy::GrowFlag)
1386 && !(orientation() == Qt::Vertical && toolButtonStyle() == Qt::ToolButtonTextBesideIcon)) {
1387 const int index = layout()->indexOf(widget);
1389 layout()->itemAt(index)->setAlignment(Qt::AlignJustify);
1395 d->adjustSeparatorVisibility();
1400 return KToolBar::Private::s_editable;
1405 if (KToolBar::Private::s_editable != editable) {
1406 KToolBar::Private::s_editable = editable;
1412 if (KToolBar::Private::s_locked != locked) {
1413 KToolBar::Private::s_locked = locked;
1417 toolbar->d->setLocked(locked);
1425 return KToolBar::Private::s_locked;
1428 #include "ktoolbar.moc"