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;
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;
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(
i18nc(
"Toolbar orientation",
"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 d->xmlguiClients.remove(client);
874 #ifndef KDE_NO_DEPRECATED
876 QPointer<KToolBar> guard(
this);
877 const QPoint globalPos =
event->globalPos();
878 d->contextMenu(globalPos)->exec(globalPos);
882 d->slotContextAboutToHide();
888 QToolBar::contextMenuEvent(event);
894 const QString fallback = Private::toolButtonStyleToString(Qt::ToolButtonTextBesideIcon);
895 return KToolBar::Private::toolButtonStyleFromString(group.
readEntry(
"ToolButtonStyle", fallback));
905 QDomNode textNode = element.namedItem(
"text");
908 if (textNode.isElement())
910 QDomElement textElement = textNode.toElement();
911 text = textElement.text().toUtf8();
912 context = textElement.attribute(
"context").toUtf8();
916 textNode = element.namedItem(
"Text");
917 if (textNode.isElement())
919 QDomElement textElement = textNode.toElement();
920 text = textElement.text().toUtf8();
921 context = textElement.attribute(
"context").toUtf8();
926 if (!text.isEmpty() && !context.isEmpty())
927 i18nText =
i18nc(context, text);
928 else if (!text.isEmpty())
929 i18nText =
i18n(text);
931 if (!i18nText.isEmpty())
932 setWindowTitle(i18nText);
947 bool loadingAppDefaults =
true;
948 if (element.hasAttribute(
"tempXml")) {
950 loadingAppDefaults =
false;
952 if (!iconSizeDefault.isEmpty()) {
953 d->iconSizeSettings[
Level_AppXML] = iconSizeDefault.toInt();
955 const QString toolButtonStyleDefault = element.attribute(
"toolButtonStyleDefault");
956 if (!toolButtonStyleDefault.isEmpty()) {
957 d->toolButtonStyleSettings[
Level_AppXML] = d->toolButtonStyleFromString(toolButtonStyleDefault);
961 bool newLine =
false;
962 QString attrNewLine = element.attribute(
"newline").toLower();
963 if (!attrNewLine.isEmpty())
964 newLine = attrNewLine ==
"true";
966 mw->insertToolBarBreak(
this);
969 int newIconSize = -1;
970 if (element.hasAttribute(
"iconSize")) {
972 newIconSize = element.attribute(
"iconSize").trimmed().toInt(&ok);
976 if (newIconSize != -1)
979 const QString newToolButtonStyle = element.attribute(
"iconText");
980 if (!newToolButtonStyle.isEmpty())
985 QString attrHidden = element.attribute(
"hidden").toLower();
986 if (!attrHidden.isEmpty())
987 hidden = attrHidden ==
"true";
990 Qt::ToolBarArea pos = Qt::NoToolBarArea;
992 QString attrPosition = element.attribute(
"position").toLower();
993 if (!attrPosition.isEmpty())
994 pos = KToolBar::Private::positionFromString(attrPosition);
996 if (pos != Qt::NoToolBarArea)
997 mw->addToolBar(pos,
this);
1001 d->applyCurrentSettings();
1008 Q_ASSERT(!current.isNull());
1010 current.setAttribute(
"tempXml",
"true");
1012 current.setAttribute(
"noMerge",
"1");
1013 current.setAttribute(
"position", d->getPositionAsString().toLower());
1014 current.setAttribute(
"hidden", isHidden() ?
"true" :
"false");
1016 const int currentIconSize = iconSize().width();
1017 if (currentIconSize == d->iconSizeSettings.defaultValue())
1018 current.removeAttribute(
"iconSize");
1020 current.setAttribute(
"iconSize", iconSize().width());
1022 if (toolButtonStyle() == d->toolButtonStyleSettings.defaultValue())
1023 current.removeAttribute(
"iconText");
1025 current.setAttribute(
"iconText", d->toolButtonStyleToString(toolButtonStyle()));
1030 current.setAttribute(
"iconSizeDefault", d->iconSizeSettings[
Level_AppXML]);
1033 const Qt::ToolButtonStyle bs =
static_cast<Qt::ToolButtonStyle
>(d->toolButtonStyleSettings[
Level_AppXML]);
1034 current.setAttribute(
"toolButtonStyleDefault", d->toolButtonStyleToString(bs));
1041 Q_ASSERT(!cg.
name().isEmpty());
1042 Q_UNUSED(forceGlobal);
1047 if (cg.
hasKey(
"Hidden")) {
1048 const bool hidden = cg.
readEntry(
"Hidden",
false);
1056 if (cg.
hasKey(
"IconSize")) {
1059 if (cg.
hasKey(
"ToolButtonStyle")) {
1063 d->applyCurrentSettings();
1073 QToolBar::setIconSize(
QSize(size, size));
1090 if (
toolBarsEditable() && event->proposedAction() & (Qt::CopyAction | Qt::MoveAction) &&
1091 event->mimeData()->hasFormat(
"application/x-kde-action-list")) {
1092 QByteArray data =
event->mimeData()->data(
"application/x-kde-action-list");
1094 QDataStream stream(data);
1098 stream >> actionNames;
1100 foreach (
const QString& actionName, actionNames) {
1102 QAction* newAction = ac->
action(actionName.toLatin1().constData());
1104 d->actionsBeingDragged.append(newAction);
1110 if (d->actionsBeingDragged.count()) {
1111 QAction* overAction = actionAt(event->pos());
1114 dropIndicatorWidget->resize(8, height() - 4);
1115 dropIndicatorWidget->setFrameShape(QFrame::VLine);
1116 dropIndicatorWidget->setLineWidth(3);
1118 d->dropIndicatorAction = insertWidget(overAction, dropIndicatorWidget);
1120 insertAction(overAction, d->dropIndicatorAction);
1122 event->acceptProposedAction();
1127 QToolBar::dragEnterEvent(event);
1134 if (d->dropIndicatorAction) {
1136 foreach (
QAction* action, actions()) {
1138 QWidget* widget = widgetForAction(action);
1139 if (event->pos().x() < widget->pos().x() + (widget->width() / 2)) {
1140 overAction = action;
1145 if (overAction != d->dropIndicatorAction) {
1147 int dropIndicatorIndex = actions().indexOf(d->dropIndicatorAction);
1148 if (dropIndicatorIndex + 1 < actions().count()) {
1149 if (actions()[ dropIndicatorIndex + 1 ] == overAction)
1151 }
else if (!overAction) {
1155 insertAction(overAction, d->dropIndicatorAction);
1164 QToolBar::dragMoveEvent(event);
1170 delete d->dropIndicatorAction;
1171 d->dropIndicatorAction = 0L;
1172 d->actionsBeingDragged.clear();
1179 QToolBar::dragLeaveEvent(event);
1185 foreach (
QAction* action, d->actionsBeingDragged) {
1186 if (actions().contains(action))
1187 removeAction(action);
1188 insertAction(d->dropIndicatorAction, action);
1193 delete d->dropIndicatorAction;
1194 d->dropIndicatorAction = 0L;
1195 d->actionsBeingDragged.clear();
1202 QToolBar::dropEvent(event);
1208 if (
KAction* action = qobject_cast<KAction*>(actionAt(event->pos()))) {
1209 d->dragAction = action;
1210 d->dragStartPosition =
event->pos();
1216 QToolBar::mousePressEvent(event);
1222 return QToolBar::mouseMoveEvent(event);
1224 if ((event->pos() - d->dragStartPosition).manhattanLength() < QApplication::startDragDistance()) {
1229 QDrag *drag =
new QDrag(
this);
1230 QMimeData *mimeData =
new QMimeData;
1234 QDataStream stream(&data, QIODevice::WriteOnly);
1237 actionNames << d->dragAction->objectName();
1239 stream << actionNames;
1242 mimeData->setData(
"application/x-kde-action-list", data);
1244 drag->setMimeData(mimeData);
1246 Qt::DropAction dropAction = drag->start(Qt::MoveAction);
1248 if (dropAction == Qt::MoveAction)
1251 if (drag->target() !=
this)
1252 removeAction(d->dragAction);
1261 if (d->dragAction) {
1267 QToolBar::mouseReleaseEvent(event);
1273 if (event->type() == QEvent::MouseButtonPress) {
1274 QMouseEvent* me =
static_cast<QMouseEvent*
>(event);
1275 if (me->buttons() & Qt::RightButton)
1276 if (
QWidget* ww = qobject_cast<QWidget*>(watched))
1277 if (ww->parent() ==
this && !ww->isEnabled())
1278 QCoreApplication::postEvent(
this,
new QContextMenuEvent(QContextMenuEvent::Mouse, me->pos(), me->globalPos()));
1280 }
else if (event->type() == QEvent::ParentChange) {
1283 if (
QWidget* ww = qobject_cast<QWidget*>(watched)) {
1284 if (!this->isAncestorOf(ww)) {
1286 ww->removeEventFilter(
this);
1288 child->removeEventFilter(
this);
1294 if ((tb = qobject_cast<QToolButton*>(watched))) {
1296 if (!tbActions.isEmpty()) {
1298 if (event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::MouseButtonRelease) {
1299 QMouseEvent* me =
static_cast<QMouseEvent*
>(event);
1300 if (me->button() == Qt::MidButton
1302 QAction* act = tbActions.first();
1303 if (me->type() == QEvent::MouseButtonPress)
1304 tb->setDown(act->isEnabled());
1307 if (act->isEnabled()) {
1308 QMetaObject::invokeMethod(act,
"triggered", Qt::DirectConnection,
1309 Q_ARG(Qt::MouseButtons, me->button()),
1310 Q_ARG(Qt::KeyboardModifiers, QApplication::keyboardModifiers()));
1320 if (event->type() == QEvent::Show ||
event->type() == QEvent::Paint ||
event->type() == QEvent::EnabledChange) {
1321 QAction *act = tb->defaultAction();
1326 tb->setText(
i18nc(
"@action:intoolbar Text label of toolbar button",
"%1", text));
1327 tb->setToolTip(
i18nc(
"@info:tooltip Tooltip of toolbar button",
"%1", toolTip));
1335 if (
QWidget* ww = qobject_cast<QWidget*>(watched)) {
1336 switch (event->type()) {
1337 case QEvent::MouseButtonPress: {
1338 QMouseEvent* me =
static_cast<QMouseEvent*
>(event);
1339 QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(),
1340 me->button(), me->buttons(), me->modifiers());
1344 case QEvent::MouseMove: {
1345 QMouseEvent* me =
static_cast<QMouseEvent*
>(event);
1346 QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(),
1347 me->button(), me->buttons(), me->modifiers());
1351 case QEvent::MouseButtonRelease: {
1352 QMouseEvent* me =
static_cast<QMouseEvent*
>(event);
1353 QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(),
1354 me->button(), me->buttons(), me->modifiers());
1364 return QToolBar::eventFilter(watched, event);
1369 if (event->type() == QEvent::ActionRemoved) {
1370 QWidget* widget = widgetForAction(event->action());
1372 widget->removeEventFilter(
this);
1375 child->removeEventFilter(
this);
1379 QToolBar::actionEvent(event);
1381 if (event->type() == QEvent::ActionAdded) {
1382 QWidget* widget = widgetForAction(event->action());
1384 widget->installEventFilter(
this);
1387 child->installEventFilter(
this);
1389 if (!(widget->sizePolicy().horizontalPolicy() & QSizePolicy::GrowFlag)
1391 && !(orientation() == Qt::Vertical && toolButtonStyle() == Qt::ToolButtonTextBesideIcon)) {
1392 const int index = layout()->indexOf(widget);
1394 layout()->itemAt(index)->setAlignment(Qt::AlignJustify);
1400 d->adjustSeparatorVisibility();
1405 return KToolBar::Private::s_editable;
1410 if (KToolBar::Private::s_editable != editable) {
1411 KToolBar::Private::s_editable = editable;
1417 if (KToolBar::Private::s_locked != locked) {
1418 KToolBar::Private::s_locked = locked;
1422 toolbar->d->setLocked(locked);
1430 return KToolBar::Private::s_locked;
1433 #include "ktoolbar.moc"
QAction * toolBarMenuAction()
Returns a pointer to the mainwindows action responsible for the toolbars menu.
QString i18n(const char *text)
A container for a set of QAction objects.
int currentSize(KIconLoader::Group group) const
Returns the current size of the icon group.
void setSettingsDirty()
Tell the main window that it should save its settings when being closed.
virtual KActionCollection * actionCollection() const
Retrieves the entire action collection for the GUI client.
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document...
static KIconLoader * global()
Returns the global icon loader initialized with the global KComponentData.
bool hasDefault(const QString &key) const
static const QList< KActionCollection * > & allCollections()
Access the list of all action collections in existence for this app.
#define KDE_NO_DEPRECATED
const char * name(StandardAction id)
This will return the internal name of a given standard action.
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
virtual QString xmlFile() const
This will return the name of the XML file as set by setXMLFile().
static KGlobalSettings * self()
Return the KGlobalSettings singleton.
QString i18nc(const char *ctxt, const char *text)
KSharedConfigPtr config()
QList< int > querySizes(KIconLoader::Group group) const
Query available sizes for a group.
void deleteEntry(const QString &pKey, WriteConfigFlags pFlags=Normal)
KDE top level main window with predefined action layout
KDE top level main window
virtual KComponentData componentData() const
void setupToolbarMenuActions()
static QString readConfigFile(const QString &filename, const KComponentData &componentData=KComponentData())
A wrapper around QIcon that provides KDE icon features.
QString componentName() const
KIconTheme * theme() const
Returns a pointer to the current theme.
KGuiItem ok()
Returns the 'Ok' gui item.
bool hasKey(const QString &key) const
QString removeAcceleratorMarker(const QString &label) const
Class to encapsulate user-driven action or event.
const KComponentData & mainComponent()
bool authorize(const QString &genericAction)
QAction * action(int index) const
Return the QAction* at position "index" in the action collection.
static bool saveConfigFile(const QDomDocument &doc, const QString &filename, const KComponentData &componentData=KComponentData())
T readEntry(const QString &key, const T &aDefault) const
void revertToDefault(const QString &key)
static QDomElement actionPropertiesElement(QDomDocument &doc)
static QDomElement findActionByName(QDomElement &elem, const QString &sName, bool create)
static QList< KMainWindow * > memberList()
List of members of KMainWindow class.
QString defaultValue(const QString &t)