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>
89class KToolBar::Private
95#ifndef KDE_NO_DEPRECATED
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;
137 KMenu *contextMenu(
const QPoint &globalPos);
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)
204 QString toString()
const {
207 str += QString::number(values[level]) +
' ';
211 int& operator[](
int index) {
return values[index]; }
215 IntSetting iconSizeSettings;
216 IntSetting toolButtonStyleSettings;
223 QPoint dragStartPosition;
226bool KToolBar::Private::s_editable =
false;
227bool KToolBar::Private::s_locked =
true;
229void KToolBar::Private::init(
bool readConfig,
bool _isMainToolBar)
231 isMainToolBar = _isMainToolBar;
243 connect(q, SIGNAL(allowedAreasChanged(Qt::ToolBarAreas)),
245 connect(q, SIGNAL(iconSizeChanged(QSize)),
247 connect(q, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
249 connect(q, SIGNAL(movableChanged(
bool)),
251 connect(q, SIGNAL(orientationChanged(Qt::Orientation)),
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()));
271QString KToolBar::Private::getPositionAsString()
const
275 case Qt::BottomToolBarArea:
277 case Qt::LeftToolBarArea:
279 case Qt::RightToolBarArea:
281 case Qt::TopToolBarArea:
287KMenu *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);
386 unlockedMovable =
false;
388 delete contextLockAction;
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);
417void KToolBar::Private::setLocked(
bool locked)
420 q->setMovable(!locked);
423void 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);
452Qt::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;
465QString 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";
481Qt::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;
495void KToolBar::Private::slotAppearanceChanged()
498 applyCurrentSettings();
501void 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);
531void KToolBar::Private::applyCurrentSettings()
534 const int currentIconSize = iconSizeSettings.currentValue();
535 q->setIconSize(QSize(currentIconSize, currentIconSize));
537 q->setToolButtonStyle(
static_cast<Qt::ToolButtonStyle
>(toolButtonStyleSettings.currentValue()));
545QAction *KToolBar::Private::findAction(
const QString &actionName,
KXMLGUIClient **clientOut)
const
559void 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);
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);
648void KToolBar::Private::slotContextAboutToHide()
662 configureAction = findAction(actionName);
664 if (!configureAction && kmw) {
668 if (configureAction) {
669 context->removeAction(configureAction);
672 context->removeAction(contextLockAction);
675void KToolBar::Private::slotContextLeft()
677 q->
mainWindow()->addToolBar(Qt::LeftToolBarArea, q);
680void KToolBar::Private::slotContextRight()
682 q->
mainWindow()->addToolBar(Qt::RightToolBarArea, q);
685void 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);
716void KToolBar::Private::slotContextTop()
718 q->
mainWindow()->addToolBar(Qt::TopToolBarArea, q);
721void KToolBar::Private::slotContextBottom()
723 q->
mainWindow()->addToolBar(Qt::BottomToolBarArea, q);
726void KToolBar::Private::slotContextIcons()
728 q->setToolButtonStyle(Qt::ToolButtonIconOnly);
732void KToolBar::Private::slotContextText()
734 q->setToolButtonStyle(Qt::ToolButtonTextOnly);
738void KToolBar::Private::slotContextTextUnder()
740 q->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
744void KToolBar::Private::slotContextTextRight()
746 q->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
750void KToolBar::Private::slotContextIconSize()
752 QAction* action = qobject_cast<QAction*>(q->sender());
753 if (action && contextIconSizes.contains(action)) {
754 const int iconSize = contextIconSizes.value(action);
759void KToolBar::Private::slotLockToolBars(
bool lock)
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);
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());
832 if (cg.
hasKey(
"Hidden")) {
836 const int currentIconSize = iconSize().width();
838 if (!cg.
hasDefault(
"IconSize") && currentIconSize == d->iconSizeSettings.defaultValue()) {
846 const Qt::ToolButtonStyle currentToolButtonStyle = toolButtonStyle();
847 if (!cg.
hasDefault(
"ToolButtonStyle") && currentToolButtonStyle == d->toolButtonStyleSettings.defaultValue()) {
851 cg.
writeEntry(
"ToolButtonStyle", d->toolButtonStyleToString(currentToolButtonStyle));
856#ifndef KDE_NO_DEPRECATED
859 d->xmlguiClients.clear();
860 d->xmlguiClients << client;
866 d->xmlguiClients << client;
871 d->xmlguiClients.remove(client);
876#ifndef KDE_NO_DEPRECATED
878 QPointer<KToolBar> guard(
this);
879 const QPoint globalPos =
event->globalPos();
880 d->contextMenu(globalPos)->exec(globalPos);
884 d->slotContextAboutToHide();
890 QToolBar::contextMenuEvent(event);
896 const QString fallback = Private::toolButtonStyleToString(Qt::ToolButtonTextBesideIcon);
897 return KToolBar::Private::toolButtonStyleFromString(
group.readEntry(
"ToolButtonStyle", fallback));
907 QDomNode textNode = element.namedItem(
"text");
910 if (textNode.isElement())
912 QDomElement textElement = textNode.toElement();
913 text = textElement.text().toUtf8();
914 context = textElement.attribute(
"context").toUtf8();
918 textNode = element.namedItem(
"Text");
919 if (textNode.isElement())
921 QDomElement textElement = textNode.toElement();
922 text = textElement.text().toUtf8();
923 context = textElement.attribute(
"context").toUtf8();
928 if (!text.isEmpty() && !context.isEmpty())
929 i18nText =
i18nc(context, text);
930 else if (!text.isEmpty())
931 i18nText =
i18n(text);
933 if (!i18nText.isEmpty())
934 setWindowTitle(i18nText);
949 bool loadingAppDefaults =
true;
950 if (element.hasAttribute(
"tempXml")) {
952 loadingAppDefaults =
false;
954 if (!iconSizeDefault.isEmpty()) {
955 d->iconSizeSettings[
Level_AppXML] = iconSizeDefault.toInt();
957 const QString toolButtonStyleDefault = element.attribute(
"toolButtonStyleDefault");
958 if (!toolButtonStyleDefault.isEmpty()) {
959 d->toolButtonStyleSettings[
Level_AppXML] = d->toolButtonStyleFromString(toolButtonStyleDefault);
963 bool newLine =
false;
964 QString attrNewLine = element.attribute(
"newline").toLower();
965 if (!attrNewLine.isEmpty())
966 newLine = attrNewLine ==
"true";
968 mw->insertToolBarBreak(
this);
971 int newIconSize = -1;
972 if (element.hasAttribute(
"iconSize")) {
974 newIconSize = element.attribute(
"iconSize").trimmed().toInt(&ok);
978 if (newIconSize != -1)
981 const QString newToolButtonStyle = element.attribute(
"iconText");
982 if (!newToolButtonStyle.isEmpty())
987 QString attrHidden = element.attribute(
"hidden").toLower();
988 if (!attrHidden.isEmpty())
989 hidden = attrHidden ==
"true";
992 Qt::ToolBarArea pos = Qt::NoToolBarArea;
994 QString attrPosition = element.attribute(
"position").toLower();
995 if (!attrPosition.isEmpty())
996 pos = KToolBar::Private::positionFromString(attrPosition);
998 if (pos != Qt::NoToolBarArea)
999 mw->addToolBar(pos,
this);
1001 setVisible(!hidden);
1003 d->applyCurrentSettings();
1010 Q_ASSERT(!current.isNull());
1012 current.setAttribute(
"tempXml",
"true");
1014 current.setAttribute(
"noMerge",
"1");
1015 current.setAttribute(
"position", d->getPositionAsString().toLower());
1016 current.setAttribute(
"hidden", isHidden() ?
"true" :
"false");
1018 const int currentIconSize = iconSize().width();
1019 if (currentIconSize == d->iconSizeSettings.defaultValue())
1020 current.removeAttribute(
"iconSize");
1022 current.setAttribute(
"iconSize", iconSize().width());
1024 if (toolButtonStyle() == d->toolButtonStyleSettings.defaultValue())
1025 current.removeAttribute(
"iconText");
1027 current.setAttribute(
"iconText", d->toolButtonStyleToString(toolButtonStyle()));
1032 current.setAttribute(
"iconSizeDefault", d->iconSizeSettings[
Level_AppXML]);
1035 const Qt::ToolButtonStyle bs =
static_cast<Qt::ToolButtonStyle
>(d->toolButtonStyleSettings[
Level_AppXML]);
1036 current.setAttribute(
"toolButtonStyleDefault", d->toolButtonStyleToString(bs));
1043 Q_ASSERT(!cg.
name().isEmpty());
1044 Q_UNUSED(forceGlobal);
1049 if (cg.
hasKey(
"Hidden")) {
1050 const bool hidden = cg.
readEntry(
"Hidden",
false);
1058 if (cg.
hasKey(
"IconSize")) {
1061 if (cg.
hasKey(
"ToolButtonStyle")) {
1065 d->applyCurrentSettings();
1070 return qobject_cast<KMainWindow*>(
const_cast<QObject*
>(parent()));
1075 QToolBar::setIconSize(QSize(size, size));
1092 if (
toolBarsEditable() && event->proposedAction() & (Qt::CopyAction | Qt::MoveAction) &&
1093 event->mimeData()->hasFormat(
"application/x-kde-action-list")) {
1094 QByteArray data =
event->mimeData()->data(
"application/x-kde-action-list");
1096 QDataStream stream(data);
1098 QStringList actionNames;
1100 stream >> actionNames;
1102 foreach (
const QString& actionName, actionNames) {
1104 QAction* newAction = ac->
action(actionName.toLatin1().constData());
1106 d->actionsBeingDragged.append(newAction);
1112 if (d->actionsBeingDragged.count()) {
1113 QAction* overAction = actionAt(event->pos());
1116 dropIndicatorWidget->resize(8, height() - 4);
1117 dropIndicatorWidget->setFrameShape(QFrame::VLine);
1118 dropIndicatorWidget->setLineWidth(3);
1120 d->dropIndicatorAction = insertWidget(overAction, dropIndicatorWidget);
1122 insertAction(overAction, d->dropIndicatorAction);
1124 event->acceptProposedAction();
1129 QToolBar::dragEnterEvent(event);
1136 if (d->dropIndicatorAction) {
1138 foreach (
QAction* action, actions()) {
1140 QWidget* widget = widgetForAction(action);
1141 if (event->pos().x() < widget->pos().x() + (widget->width() / 2)) {
1142 overAction = action;
1147 if (overAction != d->dropIndicatorAction) {
1149 int dropIndicatorIndex = actions().indexOf(d->dropIndicatorAction);
1150 if (dropIndicatorIndex + 1 < actions().count()) {
1151 if (actions()[ dropIndicatorIndex + 1 ] == overAction)
1153 }
else if (!overAction) {
1157 insertAction(overAction, d->dropIndicatorAction);
1166 QToolBar::dragMoveEvent(event);
1172 delete d->dropIndicatorAction;
1173 d->dropIndicatorAction = 0L;
1174 d->actionsBeingDragged.clear();
1181 QToolBar::dragLeaveEvent(event);
1187 foreach (
QAction* action, d->actionsBeingDragged) {
1188 if (actions().contains(action))
1189 removeAction(action);
1190 insertAction(d->dropIndicatorAction, action);
1195 delete d->dropIndicatorAction;
1196 d->dropIndicatorAction = 0L;
1197 d->actionsBeingDragged.clear();
1204 QToolBar::dropEvent(event);
1210 if (
KAction* action = qobject_cast<KAction*>(actionAt(event->pos()))) {
1211 d->dragAction = action;
1212 d->dragStartPosition =
event->pos();
1218 QToolBar::mousePressEvent(event);
1224 return QToolBar::mouseMoveEvent(event);
1226 if ((event->pos() - d->dragStartPosition).manhattanLength() < QApplication::startDragDistance()) {
1231 QDrag *drag =
new QDrag(
this);
1232 QMimeData *mimeData =
new QMimeData;
1236 QDataStream stream(&data, QIODevice::WriteOnly);
1238 QStringList actionNames;
1239 actionNames << d->dragAction->objectName();
1241 stream << actionNames;
1244 mimeData->setData(
"application/x-kde-action-list", data);
1246 drag->setMimeData(mimeData);
1248 Qt::DropAction dropAction = drag->start(Qt::MoveAction);
1250 if (dropAction == Qt::MoveAction)
1253 if (drag->target() !=
this)
1254 removeAction(d->dragAction);
1263 if (d->dragAction) {
1269 QToolBar::mouseReleaseEvent(event);
1275 if (event->type() == QEvent::MouseButtonPress) {
1276 QMouseEvent* me =
static_cast<QMouseEvent*
>(event);
1277 if (me->buttons() & Qt::RightButton)
1278 if (
QWidget* ww = qobject_cast<QWidget*>(watched))
1279 if (ww->parent() ==
this && !ww->isEnabled())
1280 QCoreApplication::postEvent(
this,
new QContextMenuEvent(QContextMenuEvent::Mouse, me->pos(), me->globalPos()));
1282 }
else if (event->type() == QEvent::ParentChange) {
1285 if (
QWidget* ww = qobject_cast<QWidget*>(watched)) {
1286 if (!this->isAncestorOf(ww)) {
1288 ww->removeEventFilter(
this);
1290 child->removeEventFilter(
this);
1296 if ((tb = qobject_cast<QToolButton*>(watched))) {
1298 if (!tbActions.isEmpty()) {
1300 if (event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::MouseButtonRelease) {
1301 QMouseEvent* me =
static_cast<QMouseEvent*
>(event);
1302 if (me->button() == Qt::MidButton
1304 QAction* act = tbActions.first();
1305 if (me->type() == QEvent::MouseButtonPress)
1306 tb->setDown(act->isEnabled());
1309 if (act->isEnabled()) {
1310 QMetaObject::invokeMethod(act,
"triggered", Qt::DirectConnection,
1311 Q_ARG(Qt::MouseButtons, me->button()),
1312 Q_ARG(Qt::KeyboardModifiers, QApplication::keyboardModifiers()));
1322 if (event->type() == QEvent::Show || event->type() == QEvent::Paint || event->type() == QEvent::EnabledChange) {
1323 QAction *act = tb->defaultAction();
1328 tb->setText(
i18nc(
"@action:intoolbar Text label of toolbar button",
"%1", text));
1329 tb->setToolTip(
i18nc(
"@info:tooltip Tooltip of toolbar button",
"%1", toolTip));
1337 if (
QWidget* ww = qobject_cast<QWidget*>(watched)) {
1338 switch (event->type()) {
1339 case QEvent::MouseButtonPress: {
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::MouseMove: {
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());
1353 case QEvent::MouseButtonRelease: {
1354 QMouseEvent* me =
static_cast<QMouseEvent*
>(event);
1355 QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(),
1356 me->button(), me->buttons(), me->modifiers());
1366 return QToolBar::eventFilter(watched, event);
1371 if (event->type() == QEvent::ActionRemoved) {
1372 QWidget* widget = widgetForAction(event->action());
1374 widget->removeEventFilter(
this);
1377 child->removeEventFilter(
this);
1381 QToolBar::actionEvent(event);
1383 if (event->type() == QEvent::ActionAdded) {
1384 QWidget* widget = widgetForAction(event->action());
1386 widget->installEventFilter(
this);
1389 child->installEventFilter(
this);
1391 if (!(widget->sizePolicy().horizontalPolicy() & QSizePolicy::GrowFlag)
1393 && !(orientation() == Qt::Vertical && toolButtonStyle() == Qt::ToolButtonTextBesideIcon)) {
1394 const int index = layout()->indexOf(widget);
1396 layout()->itemAt(index)->setAlignment(Qt::AlignJustify);
1402 d->adjustSeparatorVisibility();
1407 return KToolBar::Private::s_editable;
1412 if (KToolBar::Private::s_editable != editable) {
1413 KToolBar::Private::s_editable = editable;
1419 if (KToolBar::Private::s_locked != locked) {
1420 KToolBar::Private::s_locked = locked;
1424 toolbar->d->setLocked(locked);
1432 return KToolBar::Private::s_locked;
1435#include "ktoolbar.moc"
A container for a set of QAction objects.
static const QList< KActionCollection * > & allCollections()
Access the list of all action collections in existence for this app.
QAction * action(int index) const
Return the QAction* at position "index" in the action collection.
Class to encapsulate user-driven action or event.
QString componentName() const
void deleteEntry(const char *pKey, WriteConfigFlags pFlags=Normal)
bool hasDefault(const char *key) const
bool hasKey(const char *key) const
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QString readEntry(const char *key, const char *aDefault=0) const
void revertToDefault(const char *key)
static KGlobalSettings * self()
Return the KGlobalSettings singleton.
@ MainToolbar
Main toolbar icons.
static KIconLoader * global()
Returns the global icon loader initialized with the global KComponentData.
int currentSize(KIconLoader::Group group) const
Returns the current size of the icon group.
KIconTheme * theme() const
Returns a pointer to the current theme.
QList< int > querySizes(KIconLoader::Group group) const
Query available sizes for a group.
A wrapper around QIcon that provides KDE icon features.
QString removeAcceleratorMarker(const QString &label) const
KDE top level main window
void setSettingsDirty()
Tell the main window that it should save its settings when being closed.
static QList< KMainWindow * > memberList()
List of members of KMainWindow class.
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document,...
virtual QString xmlFile() const
This will return the name of the XML file as set by setXMLFile().
virtual KActionCollection * actionCollection() const
Retrieves the entire action collection for the GUI client.
virtual KComponentData componentData() const
static QString readConfigFile(const QString &filename, const KComponentData &componentData=KComponentData())
static QDomElement actionPropertiesElement(QDomDocument &doc)
static QDomElement findActionByName(QDomElement &elem, const QString &sName, bool create)
static bool saveConfigFile(const QDomDocument &doc, const QString &filename, const KComponentData &componentData=KComponentData())
KDE top level main window with predefined action layout
QAction * toolBarMenuAction()
Returns a pointer to the mainwindows action responsible for the toolbars menu.
void setupToolbarMenuActions()
QString defaultValue(const QString &t)
QString i18n(const char *text)
QString i18nc(const char *ctxt, const char *text)
TsConfig readConfig(const QString &fname)
bool authorize(const QString &genericAction)
const KComponentData & mainComponent()
KSharedConfigPtr config()
const char * name(StandardAction id)
This will return the internal name of a given standard action.