260 KConfigGroup cg(KSharedConfig::openConfig(), QString());
266 connect(
q, SIGNAL(allowedAreasChanged(Qt::ToolBarAreas)),
268 connect(
q, SIGNAL(iconSizeChanged(QSize)),
270 connect(
q, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
272 connect(
q, SIGNAL(movableChanged(
bool)),
274 connect(
q, SIGNAL(orientationChanged(Qt::Orientation)),
280 connect(
q, SIGNAL(movableChanged(
bool)),
283 q->setAcceptDrops(
true);
286 QDBusConnection::sessionBus().connect(QString(), QStringLiteral(
"/KisToolBar"), QStringLiteral(
"org.kde.KisToolBar"),
310 context =
new QMenu(q);
312 contextButtonTitle = context->addSection(i18nc(
"@title:menu",
"Show Text"));
313 contextShowText = context->addAction(QString(), q, SLOT(slotContextShowText()));
315 context->addSection(i18nc(
"@title:menu",
"Toolbar Settings"));
317 contextOrient =
new QMenu(i18nc(
"Toolbar orientation",
"Orientation"), context);
319 contextTop = contextOrient->addAction(i18nc(
"toolbar position string",
"Top"), q, SLOT(slotContextTop()));
320 contextTop->setChecked(
true);
321 contextLeft = contextOrient->addAction(i18nc(
"toolbar position string",
"Left"), q, SLOT(slotContextLeft()));
322 contextRight = contextOrient->addAction(i18nc(
"toolbar position string",
"Right"), q, SLOT(slotContextRight()));
323 contextBottom = contextOrient->addAction(i18nc(
"toolbar position string",
"Bottom"), q, SLOT(slotContextBottom()));
325 QActionGroup *positionGroup =
new QActionGroup(contextOrient);
326 Q_FOREACH (QAction *action, contextOrient->actions()) {
327 action->setActionGroup(positionGroup);
328 action->setCheckable(
true);
331 contextMode =
new QMenu(i18n(
"Text Position"), context);
333 contextIcons = contextMode->addAction(i18n(
"Icons Only"), q, SLOT(slotContextIcons()));
334 contextText = contextMode->addAction(i18n(
"Text Only"), q, SLOT(slotContextText()));
335 contextTextRight = contextMode->addAction(i18n(
"Text Alongside Icons"), q, SLOT(slotContextTextRight()));
336 contextTextUnder = contextMode->addAction(i18n(
"Text Under Icons"), q, SLOT(slotContextTextUnder()));
338 QActionGroup *textGroup =
new QActionGroup(contextMode);
339 Q_FOREACH (QAction *action, contextMode->actions()) {
340 action->setActionGroup(textGroup);
341 action->setCheckable(
true);
344 contextSize =
new QMenu(i18n(
"Icon Size"), context);
346 contextIconSizes.insert(contextSize->addAction(i18nc(
"@item:inmenu Icon size",
"Default"), q, SLOT(slotContextIconSize())),
347 iconSizeSettings.defaultValue());
350 avSizes << 16 << 22 << 24 << 32 << 48 << 64 << 128 << 256;
352 std::sort(avSizes.begin(), avSizes.end());
354 if (avSizes.count() < 10) {
356 Q_FOREACH (
int it, avSizes) {
359 text = i18n(
"Small (%1x%2)", it, it);
360 }
else if (it < 25) {
361 text = i18n(
"Medium (%1x%2)", it, it);
362 }
else if (it < 35) {
363 text = i18n(
"Large (%1x%2)", it, it);
365 text = i18n(
"Huge (%1x%2)", it, it);
369 contextIconSizes.insert(contextSize->addAction(text, q, SLOT(slotContextIconSize())), it);
373 const int progression[] = { 16, 22, 32, 48, 64, 96, 128, 192, 256 };
375 for (
uint i = 0; i < 9; i++) {
376 Q_FOREACH (
int it, avSizes) {
377 if (it >= progression[ i ]) {
380 text = i18n(
"Small (%1x%2)", it, it);
381 }
else if (it < 25) {
382 text = i18n(
"Medium (%1x%2)", it, it);
383 }
else if (it < 35) {
384 text = i18n(
"Large (%1x%2)", it, it);
386 text = i18n(
"Huge (%1x%2)", it, it);
390 contextIconSizes.insert(contextSize->addAction(text, q, SLOT(slotContextIconSize())), it);
397 QActionGroup *sizeGroup =
new QActionGroup(contextSize);
398 Q_FOREACH (QAction *action, contextSize->actions()) {
399 action->setActionGroup(sizeGroup);
400 action->setCheckable(
true);
403 if (!q->toolBarsLocked() && !q->isMovable()) {
404 unlockedMovable =
false;
407 delete contextLockAction;
408 contextLockAction =
new KToggleAction(
KisIconUtils::loadIcon(QStringLiteral(
"system-lock-screen")), i18n(
"Lock Toolbar Positions"), q);
409 contextLockAction->setChecked(q->toolBarsLocked());
410 connect(contextLockAction, SIGNAL(toggled(
bool)), q, SLOT(slotLockToolBars(
bool)));
413 context->addMenu(contextMode);
414 context->addMenu(contextSize);
415 context->addMenu(contextOrient);
416 context->addSeparator();
418 connect(context, SIGNAL(aboutToShow()), q, SLOT(slotContextAboutToShow()));
421 contextButtonAction = q->actionAt(q->mapFromGlobal(globalPos));
422 if (contextButtonAction) {
423 contextShowText->setText(contextButtonAction->text());
424 contextShowText->setIcon(contextButtonAction->icon());
425 contextShowText->setCheckable(
true);
428 contextOrient->menuAction()->setVisible(!q->toolBarsLocked());
592 KXmlGuiWindow *kmw = qobject_cast<KXmlGuiWindow *>(q->mainWindow());
595 QAction *configureAction = 0;
596 const char *actionName;
598 configureAction = findAction(QLatin1String(actionName));
600 if (!configureAction && kmw) {
604 if (configureAction) {
605 context->addAction(configureAction);
608 context->addAction(contextLockAction);
614 if (!q->toolBarsLocked() && tbAction && tbAction->associatedWidgets().count() > 0) {
615 context->addAction(tbAction);
622 switch (q->toolButtonStyle()) {
623 case Qt::ToolButtonIconOnly:
625 contextIcons->setChecked(
true);
627 case Qt::ToolButtonTextBesideIcon:
628 contextTextRight->setChecked(
true);
630 case Qt::ToolButtonTextOnly:
631 contextText->setChecked(
true);
633 case Qt::ToolButtonTextUnderIcon:
634 contextTextUnder->setChecked(
true);
638 QMapIterator< QAction *, int > it = contextIconSizes;
639 while (it.hasNext()) {
641 if (it.value() == q->iconSize().width()) {
642 it.key()->setChecked(
true);
647 switch (q->mainWindow()->toolBarArea(q)) {
648 case Qt::BottomToolBarArea:
649 contextBottom->setChecked(
true);
651 case Qt::LeftToolBarArea:
652 contextLeft->setChecked(
true);
654 case Qt::RightToolBarArea:
655 contextRight->setChecked(
true);
658 case Qt::TopToolBarArea:
659 contextTop->setChecked(
true);
663 const bool showButtonSettings = contextButtonAction
664 && !contextShowText->text().isEmpty()
665 && contextTextRight->isChecked();
666 contextButtonTitle->setVisible(showButtonSettings);
667 contextShowText->setVisible(showButtonSettings);
668 if (showButtonSettings) {
669 contextShowText->setChecked(contextButtonAction->priority() >= QAction::NormalPriority);
713 Q_ASSERT(contextButtonAction);
714 const QAction::Priority priority = contextShowText->isChecked()
715 ? QAction::NormalPriority : QAction::LowPriority;
716 contextButtonAction->setPriority(priority);
719 QString componentName;
722 if (findAction(contextButtonAction->objectName(), &client)) {
726 if (filename.isEmpty()) {
727 componentName = QCoreApplication::applicationName();
728 filename = componentName + QStringLiteral(
"ui.xmlgui");
734 QDomDocument document;
735 document.setContent(configFile);
738 actionElem.setAttribute(QStringLiteral(
"priority"), priority);
868 QDomNode textNode = element.namedItem(QStringLiteral(
"text"));
872 if (textNode.isElement()) {
873 QDomElement textElement = textNode.toElement();
874 domain = textElement.attribute(QStringLiteral(
"translationDomain")).toUtf8();
875 text = textElement.text().toUtf8();
876 context = textElement.attribute(QStringLiteral(
"context")).toUtf8();
878 textNode = element.namedItem(QStringLiteral(
"Text"));
879 if (textNode.isElement()) {
880 QDomElement textElement = textNode.toElement();
881 domain = textElement.attribute(QStringLiteral(
"translationDomain")).toUtf8();
882 text = textElement.text().toUtf8();
883 context = textElement.attribute(QStringLiteral(
"context")).toUtf8();
887 if (domain.isEmpty()) {
888 domain = element.ownerDocument().documentElement().attribute(QStringLiteral(
"translationDomain")).toUtf8();
889 if (domain.isEmpty()) {
890 domain = KLocalizedString::applicationDomain();
894 if (!text.isEmpty() && !context.isEmpty()) {
895 i18nText = i18ndc(domain.constData(), context.constData(), text.constData());
896 }
else if (!text.isEmpty()) {
897 i18nText = i18nd(domain.constData(), text.constData());
900 if (!i18nText.isEmpty()) {
901 setWindowTitle(i18nText);
917 bool loadingAppDefaults =
true;
918 if (element.hasAttribute(QStringLiteral(
"tempXml"))) {
920 loadingAppDefaults =
false;
921 const QString
iconSizeDefault = element.attribute(QStringLiteral(
"iconSizeDefault"));
925 const QString toolButtonStyleDefault = element.attribute(QStringLiteral(
"toolButtonStyleDefault"));
926 if (!toolButtonStyleDefault.isEmpty()) {
931 bool newLine =
false;
932 QString attrNewLine = element.attribute(QStringLiteral(
"newline")).toLower();
933 if (!attrNewLine.isEmpty()) {
934 newLine = attrNewLine == QStringLiteral(
"true");
937 mw->insertToolBarBreak(
this);
942 int newIconSize = -1;
943 if (element.hasAttribute(QStringLiteral(
"iconSize"))) {
945 newIconSize = element.attribute(QStringLiteral(
"iconSize")).trimmed().toInt(&ok);
950 if (newIconSize != -1) {
954 const QString newToolButtonStyle = element.attribute(QStringLiteral(
"iconText"));
955 if (!newToolButtonStyle.isEmpty()) {
961 QString attrHidden = element.attribute(QStringLiteral(
"hidden")).toLower();
962 if (!attrHidden.isEmpty()) {
963 hidden = attrHidden == QStringLiteral(
"true");
967 Qt::ToolBarArea pos = Qt::NoToolBarArea;
969 QString attrPosition = element.attribute(QStringLiteral(
"position")).toLower();
970 if (!attrPosition.isEmpty()) {
974 if (pos != Qt::NoToolBarArea) {
975 mw->addToolBar(pos,
this);
1057 if (
toolBarsEditable() && event->proposedAction() & (Qt::CopyAction | Qt::MoveAction) &&
1058 event->mimeData()->hasFormat(QStringLiteral(
"application/x-kde-action-list"))) {
1059 QByteArray data =
event->mimeData()->data(QStringLiteral(
"application/x-kde-action-list"));
1061 QDataStream stream(data);
1065 stream >> actionNames;
1067 Q_FOREACH (
const QString &actionName, actionNames) {
1069 QAction *newAction = ac->
action(actionName);
1078 QAction *overAction = actionAt(event->pos());
1080 QFrame *dropIndicatorWidget =
new QFrame(
this);
1081 dropIndicatorWidget->resize(8, height() - 4);
1082 dropIndicatorWidget->setFrameShape(QFrame::VLine);
1083 dropIndicatorWidget->setLineWidth(3);
1089 event->acceptProposedAction();
1094 QToolBar::dragEnterEvent(event);
1245 if (event->type() == QEvent::MouseButtonPress) {
1246 QMouseEvent *me =
static_cast<QMouseEvent *
>(event);
1247 if (me->buttons() & Qt::RightButton)
1248 if (QWidget *ww = qobject_cast<QWidget *>(watched))
1249 if (ww->parent() ==
this && !ww->isEnabled()) {
1250 QCoreApplication::postEvent(
this,
new QContextMenuEvent(QContextMenuEvent::Mouse, me->pos(), me->globalPos()));
1253 }
else if (event->type() == QEvent::ParentChange) {
1256 if (QWidget *ww = qobject_cast<QWidget *>(watched)) {
1257 if (!this->isAncestorOf(ww)) {
1259 ww->removeEventFilter(
this);
1260 Q_FOREACH (QWidget *child, ww->findChildren<QWidget *>()) {
1261 child->removeEventFilter(
this);
1268 if ((tb = qobject_cast<QToolButton *>(watched))) {
1270 if (!tbActions.isEmpty()) {
1272 if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease) {
1273 QMouseEvent *me =
static_cast<QMouseEvent *
>(event);
1274 if (me->button() == Qt::MiddleButton
1276 QAction *act = tbActions.first();
1277 if (me->type() == QEvent::MouseButtonPress) {
1278 tb->setDown(act->isEnabled());
1281 if (act->isEnabled()) {
1282 QMetaObject::invokeMethod(act,
"triggered", Qt::DirectConnection,
1283 Q_ARG(Qt::MouseButtons, me->button()),
1284 Q_ARG(Qt::KeyboardModifiers, QApplication::keyboardModifiers()));
1294 if (event->type() == QEvent::Show || event->type() == QEvent::Paint || event->type() == QEvent::EnabledChange) {
1295 QAction *act = tb->defaultAction();
1297 const QString text = KLocalizedString::removeAcceleratorMarker(act->iconText().isEmpty() ? act->text() : act->iconText());
1298 const QString toolTip = KLocalizedString::removeAcceleratorMarker(act->toolTip());
1300 tb->setText(i18nc(
"@action:intoolbar Text label of toolbar button",
"%1", text));
1301 tb->setToolTip(i18nc(
"@info:tooltip Tooltip of toolbar button",
"%1", toolTip));
1309 if (QWidget *ww = qobject_cast<QWidget *>(watched)) {
1310 switch (event->type()) {
1311 case QEvent::MouseButtonPress: {
1312 QMouseEvent *me =
static_cast<QMouseEvent *
>(event);
1313 QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(),
1314 me->button(), me->buttons(), me->modifiers());
1318 case QEvent::MouseMove: {
1319 QMouseEvent *me =
static_cast<QMouseEvent *
>(event);
1320 QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(),
1321 me->button(), me->buttons(), me->modifiers());
1325 case QEvent::MouseButtonRelease: {
1326 QMouseEvent *me =
static_cast<QMouseEvent *
>(event);
1327 QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(),
1328 me->button(), me->buttons(), me->modifiers());
1338 return QToolBar::eventFilter(watched, event);
1343 if (event->type() == QEvent::ActionRemoved) {
1344 QWidget *widget = widgetForAction(event->action());
1346 widget->removeEventFilter(
this);
1348 Q_FOREACH (QWidget *child, widget->findChildren<QWidget *>()) {
1349 child->removeEventFilter(
this);
1352 QToolButton *tb = qobject_cast<QToolButton *>(widget);
1354 tb->disconnect(
this, SLOT(slotToolButtonToggled(
bool)));
1359 QToolBar::actionEvent(event);
1361 if (event->type() == QEvent::ActionAdded) {
1362 QWidget *widget = widgetForAction(event->action());
1364 widget->installEventFilter(
this);
1366 Q_FOREACH (QWidget *child, widget->findChildren<QWidget *>()) {
1367 child->installEventFilter(
this);
1370 if (!(widget->sizePolicy().horizontalPolicy() & QSizePolicy::GrowFlag)
1372 && !(orientation() == Qt::Vertical && toolButtonStyle() == Qt::ToolButtonTextBesideIcon)) {
1373 const int index = layout()->indexOf(widget);
1375 layout()->itemAt(index)->setAlignment(Qt::AlignJustify);
1380 QToolButton *tb = qobject_cast<QToolButton *>(widget);
1381 if (tb && event->action()->icon().isNull() ==
false) {
1383 connect(tb, SIGNAL(toggled(
bool)),
this, SLOT(slotToolButtonToggled(
bool)));
1384 widget->setFixedSize(32, 32);