Krita Source Code Documentation
Loading...
Searching...
No Matches
KisToolBar Class Reference

Floatable toolbar with auto resize. More...

#include <ktoolbar.h>

+ Inheritance diagram for KisToolBar:

Classes

class  Private
 

Public Member Functions

void addXMLGUIClient (KisKXMLGUIClient *client)
 
void applySettings (const KConfigGroup &cg)
 
bool eventFilter (QObject *watched, QEvent *event) override
 
int iconSizeDefault () const
 
 KisToolBar (const QString &objectName, QWidget *parent, bool readConfig=true)
 
void loadState (const QDomElement &element)
 
KisKMainWindowmainWindow () const
 
void removeXMLGUIClient (KisKXMLGUIClient *client)
 
void saveSettings (KConfigGroup &cg)
 
void saveState (QDomElement &element) const
 
void setIconDimensions (int size)
 
 ~KisToolBar () override
 

Static Public Member Functions

static void emitToolbarStyleChanged ()
 
static void setToolBarsEditable (bool editable)
 
static void setToolBarsLocked (bool locked)
 
static bool toolBarsEditable ()
 
static bool toolBarsLocked ()
 
static KisToolBarStateModeltoolBarStateModel ()
 

Protected Slots

virtual void slotMovableChanged (bool movable)
 

Protected Member Functions

void actionEvent (QActionEvent *) override
 
void contextMenuEvent (QContextMenuEvent *) override
 
void dragEnterEvent (QDragEnterEvent *) override
 
void dragLeaveEvent (QDragLeaveEvent *) override
 
void dragMoveEvent (QDragMoveEvent *) override
 
void dropEvent (QDropEvent *) override
 
void mouseMoveEvent (QMouseEvent *) override
 
void mousePressEvent (QMouseEvent *) override
 
void mouseReleaseEvent (QMouseEvent *) override
 

Private Attributes

Private *const d
 

Detailed Description

Floatable toolbar with auto resize.

A KDE-style toolbar.

KisToolBar can be used as a standalone widget, but KisKMainWindow provides easy factories and management of one or more toolbars.

KisToolBar uses a global config group to load toolbar settings on construction. It will reread this config group on a KApplication::appearanceChanged() signal.

Note
If you can't depend on KXmlGui but you want to integrate with KDE, you can use QToolBar with: Set ToolButtonStyle to Qt::ToolButtonFollowStyle, this will make QToolBar use the settings for "Main Toolbar" Additionally set QToolBar::setProperty("otherToolbar", true) to use settings for "Other toolbars" Settings from "Other toolbars" will only work on widget styles derived from KStyle
Author
Reginald Stadlbauer reggi.nosp@m.e@kd.nosp@m.e.org, Stephan Kulow coolo.nosp@m.@kde.nosp@m..org, Sven Radej radej.nosp@m.@kde.nosp@m..org, Hamish Rodda rodda.nosp@m.@kde.nosp@m..org.

Definition at line 46 of file ktoolbar.h.

Constructor & Destructor Documentation

◆ KisToolBar()

KisToolBar::KisToolBar ( const QString & objectName,
QWidget * parent,
bool readConfig = true )
explicit

Constructor.

This constructor takes care of adding the toolbar to the mainwindow, if parent is a QMainWindow.

Normally KDE applications do not call this directly, they either call KisKMainWindow::toolBar(name), or they use XML-GUI and specify toolbars using XML.

Parameters
objectNameThe QObject name of this toolbar, required so that QMainWindow can save and load the toolbar position, and so that KisToolBar can find out if it's the main toolbar.
parentThe standard toolbar parent (usually a KisKMainWindow)
readConfigwhether to apply the configuration (global and application-specific)

Definition at line 799 of file ktoolbar.cpp.

800 : QToolBar(parent),
801 d(new Private(this))
802{
803 setObjectName(objectName);
804 // mainToolBar -> isMainToolBar = true -> buttonStyle is configurable
805 // others -> isMainToolBar = false -> ### hardcoded default for buttonStyle !!! should be configurable? -> hidden key added
806 d->init(readConfig, objectName == QStringLiteral("mainToolBar"));
807
808 // KisToolBar is auto-added to the top area of the main window if parent is a QMainWindow
809 if (QMainWindow *mw = qobject_cast<QMainWindow *>(parent)) {
810 mw->addToolBar(this);
811 }
812}
void init(bool readConfig=true, bool isMainToolBar=false)
Definition ktoolbar.cpp:253
Private *const d
Definition ktoolbar.h:177

References d, and KisToolBar::Private::init().

◆ ~KisToolBar()

KisToolBar::~KisToolBar ( )
override

Destroys the toolbar.

Definition at line 814 of file ktoolbar.cpp.

815{
816 delete d->contextLockAction;
817 delete d;
818}
KToggleAction * contextLockAction
Definition ktoolbar.cpp:170

References KisToolBar::Private::contextLockAction, and d.

Member Function Documentation

◆ actionEvent()

void KisToolBar::actionEvent ( QActionEvent * event)
overrideprotected

Definition at line 1341 of file ktoolbar.cpp.

1342{
1343 if (event->type() == QEvent::ActionRemoved) {
1344 QWidget *widget = widgetForAction(event->action());
1345 if (widget) {
1346 widget->removeEventFilter(this);
1347
1348 Q_FOREACH (QWidget *child, widget->findChildren<QWidget *>()) {
1349 child->removeEventFilter(this);
1350 }
1351 // Remove Krita's palette manipulation
1352 QToolButton *tb = qobject_cast<QToolButton *>(widget);
1353 if (tb) {
1354 tb->disconnect(this, SLOT(slotToolButtonToggled(bool)));
1355 }
1356 }
1357 }
1358
1359 QToolBar::actionEvent(event);
1360
1361 if (event->type() == QEvent::ActionAdded) {
1362 QWidget *widget = widgetForAction(event->action());
1363 if (widget) {
1364 widget->installEventFilter(this);
1365
1366 Q_FOREACH (QWidget *child, widget->findChildren<QWidget *>()) {
1367 child->installEventFilter(this);
1368 }
1369 // Center widgets that do not have any use for more space. See bug 165274
1370 if (!(widget->sizePolicy().horizontalPolicy() & QSizePolicy::GrowFlag)
1371 // ... but do not center when using text besides icon in vertical toolbar. See bug 243196
1372 && !(orientation() == Qt::Vertical && toolButtonStyle() == Qt::ToolButtonTextBesideIcon)) {
1373 const int index = layout()->indexOf(widget);
1374 if (index != -1) {
1375 layout()->itemAt(index)->setAlignment(Qt::AlignJustify);
1376 }
1377 }
1378 // NOTE: set a fixed button size, same size as the buttonsize used in kis_paintop_box
1379 // and toggle highlight color on checked buttons, same as in KisHighlightedButton
1380 QToolButton *tb = qobject_cast<QToolButton *>(widget);
1381 if (tb && event->action()->icon().isNull() == false) {
1382 d->customizeButtonPalette(tb, tb->isChecked());
1383 connect(tb, SIGNAL(toggled(bool)), this, SLOT(slotToolButtonToggled(bool)));
1384 widget->setFixedSize(32, 32);
1385 }
1386 }
1387 }
1388
1390}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void customizeButtonPalette(QToolButton *button, bool checked)
Definition ktoolbar.cpp:560
void adjustSeparatorVisibility()
Definition ktoolbar.cpp:443

References KisToolBar::Private::adjustSeparatorVisibility(), connect(), KisToolBar::Private::customizeButtonPalette(), and d.

◆ addXMLGUIClient()

void KisToolBar::addXMLGUIClient ( KisKXMLGUIClient * client)

Adds an XML gui client that uses this toolbar

Since
4.8.1

Definition at line 845 of file ktoolbar.cpp.

846{
847 d->xmlguiClients << client;
848}
QSet< KisKXMLGUIClient * > xmlguiClients
Definition ktoolbar.cpp:153

References d, and KisToolBar::Private::xmlguiClients.

◆ applySettings()

void KisToolBar::applySettings ( const KConfigGroup & cg)

Read the toolbar settings from group configGroup in config and apply them.

Definition at line 1020 of file ktoolbar.cpp.

1021{
1022 Q_ASSERT(!cg.name().isEmpty());
1023
1024 if (cg.hasKey("IconSize")) {
1025 d->iconSizeSettings[Level_UserSettings] = cg.readEntry("IconSize", 0);
1026 }
1027 if (cg.hasKey("ToolButtonStyle")) {
1028 d->toolButtonStyleSettings[Level_UserSettings] = d->toolButtonStyleFromString(cg.readEntry("ToolButtonStyle", QString()));
1029 }
1030
1032}
IntSetting toolButtonStyleSettings
Definition ktoolbar.cpp:220
void applyCurrentSettings()
Definition ktoolbar.cpp:544
static Qt::ToolButtonStyle toolButtonStyleFromString(const QString &style)
Definition ktoolbar.cpp:473
IntSetting iconSizeSettings
Definition ktoolbar.cpp:219
@ Level_UserSettings
Definition ktoolbar.cpp:82

References KisToolBar::Private::applyCurrentSettings(), d, KisToolBar::Private::iconSizeSettings, Level_UserSettings, KisToolBar::Private::toolButtonStyleFromString(), and KisToolBar::Private::toolButtonStyleSettings.

◆ contextMenuEvent()

void KisToolBar::contextMenuEvent ( QContextMenuEvent * event)
overrideprotected

Definition at line 855 of file ktoolbar.cpp.

856{
857 QToolBar::contextMenuEvent(event);
858}

◆ dragEnterEvent()

void KisToolBar::dragEnterEvent ( QDragEnterEvent * event)
overrideprotected

Definition at line 1055 of file ktoolbar.cpp.

1056{
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"));
1060
1061 QDataStream stream(data);
1062
1063 QStringList actionNames;
1064
1065 stream >> actionNames;
1066
1067 Q_FOREACH (const QString &actionName, actionNames) {
1069 QAction *newAction = ac->action(actionName);
1070 if (newAction) {
1071 d->actionsBeingDragged.append(newAction);
1072 break;
1073 }
1074 }
1075 }
1076
1077 if (d->actionsBeingDragged.count()) {
1078 QAction *overAction = actionAt(event->pos());
1079
1080 QFrame *dropIndicatorWidget = new QFrame(this);
1081 dropIndicatorWidget->resize(8, height() - 4);
1082 dropIndicatorWidget->setFrameShape(QFrame::VLine);
1083 dropIndicatorWidget->setLineWidth(3);
1084
1085 d->dropIndicatorAction = insertWidget(overAction, dropIndicatorWidget);
1086
1087 insertAction(overAction, d->dropIndicatorAction);
1088
1089 event->acceptProposedAction();
1090 return;
1091 }
1092 }
1093
1094 QToolBar::dragEnterEvent(event);
1095}
A container for a set of QAction objects.
static const QList< KisKActionCollection * > & allCollections()
QAction * action(int index) const
QList< QAction * > actionsBeingDragged
Definition ktoolbar.cpp:222
QAction * dropIndicatorAction
Definition ktoolbar.cpp:223
static bool toolBarsEditable()

References KisKActionCollection::action(), KisToolBar::Private::actionsBeingDragged, KisKActionCollection::allCollections(), d, KisToolBar::Private::dropIndicatorAction, and toolBarsEditable().

◆ dragLeaveEvent()

void KisToolBar::dragLeaveEvent ( QDragLeaveEvent * event)
overrideprotected

Definition at line 1136 of file ktoolbar.cpp.

1137{
1138 // Want to clear this even if toolBarsEditable was changed mid-drag (unlikely)
1139 delete d->dropIndicatorAction;
1140 d->dropIndicatorAction = 0L;
1141 d->actionsBeingDragged.clear();
1142
1143 if (toolBarsEditable()) {
1144 event->accept();
1145 return;
1146 }
1147
1148 QToolBar::dragLeaveEvent(event);
1149}

References KisToolBar::Private::actionsBeingDragged, d, KisToolBar::Private::dropIndicatorAction, and toolBarsEditable().

◆ dragMoveEvent()

void KisToolBar::dragMoveEvent ( QDragMoveEvent * event)
overrideprotected

Definition at line 1097 of file ktoolbar.cpp.

1098{
1099 if (toolBarsEditable())
1100 Q_FOREVER {
1102 {
1103 QAction *overAction = 0L;
1104 Q_FOREACH (QAction *action, actions()) {
1105 // want to make it feel that half way across an action you're dropping on the other side of it
1106 QWidget *widget = widgetForAction(action);
1107 if (event->pos().x() < widget->pos().x() + (widget->width() / 2)) {
1108 overAction = action;
1109 break;
1110 }
1111 }
1112
1113 if (overAction != d->dropIndicatorAction) {
1114 // Check to see if the indicator is already in the right spot
1115 int dropIndicatorIndex = actions().indexOf(d->dropIndicatorAction);
1116 if (dropIndicatorIndex + 1 < actions().count()) {
1117 if (actions()[ dropIndicatorIndex + 1 ] == overAction) {
1118 break;
1119 }
1120 } else if (!overAction) {
1121 break;
1122 }
1123
1124 insertAction(overAction, d->dropIndicatorAction);
1125 }
1126
1127 event->accept();
1128 return;
1129 }
1130 break;
1131 }
1132
1133 QToolBar::dragMoveEvent(event);
1134}

References d, KisToolBar::Private::dropIndicatorAction, and toolBarsEditable().

◆ dropEvent()

void KisToolBar::dropEvent ( QDropEvent * event)
overrideprotected

Definition at line 1151 of file ktoolbar.cpp.

1152{
1153 if (toolBarsEditable()) {
1154 Q_FOREACH (QAction *action, d->actionsBeingDragged) {
1155 if (actions().contains(action)) {
1156 removeAction(action);
1157 }
1158 insertAction(d->dropIndicatorAction, action);
1159 }
1160 }
1161
1162 // Want to clear this even if toolBarsEditable was changed mid-drag (unlikely)
1163 delete d->dropIndicatorAction;
1164 d->dropIndicatorAction = 0L;
1165 d->actionsBeingDragged.clear();
1166
1167 if (toolBarsEditable()) {
1168 event->accept();
1169 return;
1170 }
1171
1172 QToolBar::dropEvent(event);
1173}

References KisToolBar::Private::actionsBeingDragged, d, KisToolBar::Private::dropIndicatorAction, and toolBarsEditable().

◆ emitToolbarStyleChanged()

void KisToolBar::emitToolbarStyleChanged ( )
static

Emits a dbus signal to tell all toolbars in all applications, that the user settings have changed.

Since
5.0

Definition at line 1414 of file ktoolbar.cpp.

1415{
1416#ifdef HAVE_DBUS
1417 QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KisToolBar"), QStringLiteral("org.kde.KisToolBar"), QStringLiteral("styleChanged"));
1418 QDBusConnection::sessionBus().send(message);
1419#endif
1420}

◆ eventFilter()

bool KisToolBar::eventFilter ( QObject * watched,
QEvent * event )
override

Reimplemented to support context menu activation on disabled tool buttons.

Definition at line 1242 of file ktoolbar.cpp.

1243{
1244 // Generate context menu events for disabled buttons too...
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()));
1251 }
1252
1253 } else if (event->type() == QEvent::ParentChange) {
1254 // Make sure we're not leaving stale event filters around,
1255 // when a child is reparented somewhere else
1256 if (QWidget *ww = qobject_cast<QWidget *>(watched)) {
1257 if (!this->isAncestorOf(ww)) {
1258 // New parent is not a subwidget - remove event filter
1259 ww->removeEventFilter(this);
1260 Q_FOREACH (QWidget *child, ww->findChildren<QWidget *>()) {
1261 child->removeEventFilter(this);
1262 }
1263 }
1264 }
1265 }
1266
1267 QToolButton *tb;
1268 if ((tb = qobject_cast<QToolButton *>(watched))) {
1269 const QList<QAction *> tbActions = tb->actions();
1270 if (!tbActions.isEmpty()) {
1271 // Handle MMB on toolbar buttons
1272 if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease) {
1273 QMouseEvent *me = static_cast<QMouseEvent *>(event);
1274 if (me->button() == Qt::MiddleButton /*&&
1275 act->receivers(SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)))*/) {
1276 QAction *act = tbActions.first();
1277 if (me->type() == QEvent::MouseButtonPress) {
1278 tb->setDown(act->isEnabled());
1279 } else {
1280 tb->setDown(false);
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()));
1285 }
1286 }
1287 }
1288 }
1289
1290 // CJK languages use more verbose accelerator marker: they add a Latin
1291 // letter in parenthesis, and put accelerator on that. Hence, the default
1292 // removal of ampersand only may not be enough there, instead the whole
1293 // parenthesis construct should be removed. Use KLocalizedString's method to do this.
1294 if (event->type() == QEvent::Show || event->type() == QEvent::Paint || event->type() == QEvent::EnabledChange) {
1295 QAction *act = tb->defaultAction();
1296 if (act) {
1297 const QString text = KLocalizedString::removeAcceleratorMarker(act->iconText().isEmpty() ? act->text() : act->iconText());
1298 const QString toolTip = KLocalizedString::removeAcceleratorMarker(act->toolTip());
1299 // Filtering messages requested by translators (scripting).
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));
1302 }
1303 }
1304 }
1305 }
1306
1307 // Redirect mouse events to the toolbar when drag + drop editing is enabled
1308 if (toolBarsEditable()) {
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());
1315 mousePressEvent(&newEvent);
1316 return true;
1317 }
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());
1322 mouseMoveEvent(&newEvent);
1323 return true;
1324 }
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());
1329 mouseReleaseEvent(&newEvent);
1330 return true;
1331 }
1332 default:
1333 break;
1334 }
1335 }
1336 }
1337
1338 return QToolBar::eventFilter(watched, event);
1339}
void mousePressEvent(QMouseEvent *) override
void mouseMoveEvent(QMouseEvent *) override
void mouseReleaseEvent(QMouseEvent *) override

References mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), and toolBarsEditable().

◆ iconSizeDefault()

int KisToolBar::iconSizeDefault ( ) const

Returns the default size for this type of toolbar.

Returns
the default size for this type of toolbar.

Definition at line 1045 of file ktoolbar.cpp.

1046{
1047 return 22;
1048}

◆ loadState()

void KisToolBar::loadState ( const QDomElement & element)

Load state from an XML element, called by KisKXMLGUIBuilder.

Definition at line 860 of file ktoolbar.cpp.

861{
862 QMainWindow *mw = mainWindow();
863 if (!mw) {
864 return;
865 }
866
867 {
868 QDomNode textNode = element.namedItem(QStringLiteral("text"));
869 QByteArray domain;
870 QByteArray text;
871 QByteArray context;
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();
877 } else {
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();
884 }
885 }
886
887 if (domain.isEmpty()) {
888 domain = element.ownerDocument().documentElement().attribute(QStringLiteral("translationDomain")).toUtf8();
889 if (domain.isEmpty()) {
890 domain = KLocalizedString::applicationDomain();
891 }
892 }
893 QString i18nText;
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());
898 }
899
900 if (!i18nText.isEmpty()) {
901 setWindowTitle(i18nText);
902 }
903 }
904
905 /*
906 This method is called in order to load toolbar settings from XML.
907 However this can be used in two rather different cases:
908 - for the initial loading of the app's XML. In that case the settings
909 are only the defaults (Level_AppXML), the user's KConfig settings will override them
910
911 - for later re-loading when switching between parts in KisKXMLGUIFactory.
912 In that case the XML contains the final settings, not the defaults.
913 We do need the defaults, and the toolbar might have been completely
914 deleted and recreated meanwhile. So we store the app-default settings
915 into the XML.
916 */
917 bool loadingAppDefaults = true;
918 if (element.hasAttribute(QStringLiteral("tempXml"))) {
919 // this isn't the first time, so the app-xml defaults have been saved into the (in-memory) XML
920 loadingAppDefaults = false;
921 const QString iconSizeDefault = element.attribute(QStringLiteral("iconSizeDefault"));
922 if (!iconSizeDefault.isEmpty()) {
924 }
925 const QString toolButtonStyleDefault = element.attribute(QStringLiteral("toolButtonStyleDefault"));
926 if (!toolButtonStyleDefault.isEmpty()) {
928 }
929 } else {
930 // loading app defaults
931 bool newLine = false;
932 QString attrNewLine = element.attribute(QStringLiteral("newline")).toLower();
933 if (!attrNewLine.isEmpty()) {
934 newLine = attrNewLine == QStringLiteral("true");
935 }
936 if (newLine && mw) {
937 mw->insertToolBarBreak(this);
938 }
939
940 }
941
942 int newIconSize = -1;
943 if (element.hasAttribute(QStringLiteral("iconSize"))) {
944 bool ok;
945 newIconSize = element.attribute(QStringLiteral("iconSize")).trimmed().toInt(&ok);
946 if (!ok) {
947 newIconSize = -1;
948 }
949 }
950 if (newIconSize != -1) {
951 d->iconSizeSettings[loadingAppDefaults ? Level_AppXML : Level_UserSettings] = newIconSize;
952 }
953
954 const QString newToolButtonStyle = element.attribute(QStringLiteral("iconText"));
955 if (!newToolButtonStyle.isEmpty()) {
956 d->toolButtonStyleSettings[loadingAppDefaults ? Level_AppXML : Level_UserSettings] = d->toolButtonStyleFromString(newToolButtonStyle);
957 }
958
959 bool hidden = false;
960 {
961 QString attrHidden = element.attribute(QStringLiteral("hidden")).toLower();
962 if (!attrHidden.isEmpty()) {
963 hidden = attrHidden == QStringLiteral("true");
964 }
965 }
966
967 Qt::ToolBarArea pos = Qt::NoToolBarArea;
968 {
969 QString attrPosition = element.attribute(QStringLiteral("position")).toLower();
970 if (!attrPosition.isEmpty()) {
971 pos = KisToolBar::Private::positionFromString(attrPosition);
972 }
973 }
974 if (pos != Qt::NoToolBarArea) {
975 mw->addToolBar(pos, this);
976 }
977
978 setVisible(!hidden);
979
981}
static Qt::ToolBarArea positionFromString(const QString &position)
Definition ktoolbar.cpp:502
int iconSizeDefault() const
KisKMainWindow * mainWindow() const
@ Level_AppXML
Definition ktoolbar.cpp:82

References KisToolBar::Private::applyCurrentSettings(), d, iconSizeDefault(), KisToolBar::Private::iconSizeSettings, Level_AppXML, Level_UserSettings, mainWindow(), KisToolBar::Private::positionFromString(), KisToolBar::Private::toolButtonStyleFromString(), and KisToolBar::Private::toolButtonStyleSettings.

◆ mainWindow()

KisKMainWindow * KisToolBar::mainWindow ( ) const

Returns the main window that this toolbar is docked with.

Definition at line 1034 of file ktoolbar.cpp.

1035{
1036 return qobject_cast<KisKMainWindow *>(const_cast<QObject *>(parent()));
1037}
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

◆ mouseMoveEvent()

void KisToolBar::mouseMoveEvent ( QMouseEvent * event)
overrideprotected

Definition at line 1189 of file ktoolbar.cpp.

1190{
1191 if (!toolBarsEditable() || !d->dragAction) {
1192 return QToolBar::mouseMoveEvent(event);
1193 }
1194
1195 if ((event->pos() - d->dragStartPosition).manhattanLength() < QApplication::startDragDistance()) {
1196 event->accept();
1197 return;
1198 }
1199
1200 QDrag *drag = new QDrag(this);
1201 QMimeData *mimeData = new QMimeData;
1202
1203 QByteArray data;
1204 {
1205 QDataStream stream(&data, QIODevice::WriteOnly);
1206
1207 QStringList actionNames;
1208 actionNames << d->dragAction->objectName();
1209
1210 stream << actionNames;
1211 }
1212
1213 mimeData->setData(QStringLiteral("application/x-kde-action-list"), data);
1214
1215 drag->setMimeData(mimeData);
1216
1217 Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
1218
1219 if (dropAction == Qt::MoveAction)
1220 // Only remove from this toolbar if it was moved to another toolbar
1221 // Otherwise the receiver moves it.
1222 if (drag->target() != this) {
1223 removeAction(d->dragAction);
1224 }
1225
1226 d->dragAction = 0L;
1227 event->accept();
1228}

References d, KisToolBar::Private::dragAction, KisToolBar::Private::dragStartPosition, and toolBarsEditable().

◆ mousePressEvent()

void KisToolBar::mousePressEvent ( QMouseEvent * event)
overrideprotected

Definition at line 1175 of file ktoolbar.cpp.

1176{
1177 if (toolBarsEditable() && event->button() == Qt::LeftButton) {
1178 if (QAction *action = actionAt(event->pos())) {
1179 d->dragAction = action;
1180 d->dragStartPosition = event->pos();
1181 event->accept();
1182 return;
1183 }
1184 }
1185
1186 QToolBar::mousePressEvent(event);
1187}

References d, KisToolBar::Private::dragAction, KisToolBar::Private::dragStartPosition, and toolBarsEditable().

◆ mouseReleaseEvent()

void KisToolBar::mouseReleaseEvent ( QMouseEvent * event)
overrideprotected

Definition at line 1230 of file ktoolbar.cpp.

1231{
1232 // Want to clear this even if toolBarsEditable was changed mid-drag (unlikely)
1233 if (d->dragAction) {
1234 d->dragAction = 0L;
1235 event->accept();
1236 return;
1237 }
1238
1239 QToolBar::mouseReleaseEvent(event);
1240}

References d, and KisToolBar::Private::dragAction.

◆ removeXMLGUIClient()

void KisToolBar::removeXMLGUIClient ( KisKXMLGUIClient * client)

Removes an XML gui client that uses this toolbar

Since
4.8.5

Definition at line 850 of file ktoolbar.cpp.

851{
852 d->xmlguiClients.remove(client);
853}

References d, and KisToolBar::Private::xmlguiClients.

◆ saveSettings()

void KisToolBar::saveSettings ( KConfigGroup & cg)

Save the toolbar settings to group configGroup in config.

Definition at line 820 of file ktoolbar.cpp.

821{
822 Q_ASSERT(!cg.name().isEmpty());
823
824 const int currentIconSize = iconSize().width();
825 //qDebug() << objectName() << currentIconSize << d->iconSizeSettings.toString() << "defaultValue=" << d->iconSizeSettings.defaultValue();
826 if (!cg.hasDefault("IconSize") && currentIconSize == d->iconSizeSettings.defaultValue()) {
827 cg.revertToDefault("IconSize");
829 } else {
830 cg.writeEntry("IconSize", currentIconSize);
831 d->iconSizeSettings[Level_UserSettings] = currentIconSize;
832 }
833
834 const Qt::ToolButtonStyle currentToolButtonStyle = toolButtonStyle();
835 if (!cg.hasDefault("ToolButtonStyle") && currentToolButtonStyle == d->toolButtonStyleSettings.defaultValue()) {
836 cg.revertToDefault("ToolButtonStyle");
838 } else {
839 cg.writeEntry("ToolButtonStyle", d->toolButtonStyleToString(currentToolButtonStyle));
840 d->toolButtonStyleSettings[Level_UserSettings] = currentToolButtonStyle;
841 }
842}
int iconSize(qreal width, qreal height)
static QString toolButtonStyleToString(Qt::ToolButtonStyle)
Definition ktoolbar.cpp:487
@ Unset
Definition ktoolbar.cpp:85

References d, KisToolBar::Private::IntSetting::defaultValue(), iconSize(), KisToolBar::Private::iconSizeSettings, Level_UserSettings, KisToolBar::Private::toolButtonStyleSettings, KisToolBar::Private::toolButtonStyleToString(), and Unset.

◆ saveState()

void KisToolBar::saveState ( QDomElement & element) const

Save state into an XML element, called by KisKXMLGUIBuilder.

Definition at line 985 of file ktoolbar.cpp.

986{
987 Q_ASSERT(!current.isNull());
988
989 current.setAttribute(QStringLiteral("tempXml"), QLatin1String("true"));
990
991 current.setAttribute(QStringLiteral("noMerge"), QLatin1String("1"));
992 current.setAttribute(QStringLiteral("position"), d->getPositionAsString().toLower());
993 current.setAttribute(QStringLiteral("hidden"), isHidden() ? QLatin1String("true") : QLatin1String("false"));
994
995 const int currentIconSize = iconSize().width();
996 if (currentIconSize == d->iconSizeSettings.defaultValue()) {
997 current.removeAttribute(QStringLiteral("iconSize"));
998 } else {
999 current.setAttribute(QStringLiteral("iconSize"), iconSize().width());
1000 }
1001
1002 if (toolButtonStyle() == d->toolButtonStyleSettings.defaultValue()) {
1003 current.removeAttribute(QStringLiteral("iconText"));
1004 } else {
1005 current.setAttribute(QStringLiteral("iconText"), d->toolButtonStyleToString(toolButtonStyle()));
1006 }
1007
1008 // Note: if this method is used by more than KisKXMLGUIBuilder, e.g. to save XML settings to *disk*,
1009 // then the stuff below shouldn't always be done. This is not the case currently though.
1011 current.setAttribute(QStringLiteral("iconSizeDefault"), d->iconSizeSettings[Level_AppXML]);
1012 }
1014 const Qt::ToolButtonStyle bs = static_cast<Qt::ToolButtonStyle>(d->toolButtonStyleSettings[Level_AppXML]);
1015 current.setAttribute(QStringLiteral("toolButtonStyleDefault"), d->toolButtonStyleToString(bs));
1016 }
1017}
QString getPositionAsString() const
Definition ktoolbar.cpp:291

References d, KisToolBar::Private::IntSetting::defaultValue(), KisToolBar::Private::getPositionAsString(), iconSize(), KisToolBar::Private::iconSizeSettings, Level_AppXML, KisToolBar::Private::toolButtonStyleSettings, KisToolBar::Private::toolButtonStyleToString(), and Unset.

◆ setIconDimensions()

void KisToolBar::setIconDimensions ( int size)

Convenience function to set icon size

Definition at line 1039 of file ktoolbar.cpp.

1040{
1041 QToolBar::setIconSize(QSize(size, size));
1043}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References d, KisToolBar::Private::iconSizeSettings, and Level_UserSettings.

◆ setToolBarsEditable()

void KisToolBar::setToolBarsEditable ( bool editable)
static

Enable or disable toolbar editing via drag & drop of actions. This is called by KisKEditToolbar and should generally be set to disabled whenever KisKEditToolbar is not active.

Definition at line 1397 of file ktoolbar.cpp.

1398{
1399 if (KisToolBar::Private::s_editable != editable) {
1401 }
1402}
static bool s_editable
Definition ktoolbar.cpp:151

References KisToolBar::Private::s_editable.

◆ setToolBarsLocked()

void KisToolBar::setToolBarsLocked ( bool locked)
static

Allows you to lock and unlock all toolbars (i.e., disallow/allow moving of the toolbars).

Definition at line 1404 of file ktoolbar.cpp.

1405{
1406 s_toolBarsModel->settoolBarsLocked(locked);
1407}

◆ slotMovableChanged

void KisToolBar::slotMovableChanged ( bool movable)
protectedvirtualslot

Definition at line 1050 of file ktoolbar.cpp.

1051{
1052 setMovable(movable);
1053}

◆ toolBarsEditable()

bool KisToolBar::toolBarsEditable ( )
static

Returns whether the toolbars are currently editable (drag & drop of actions).

Definition at line 1392 of file ktoolbar.cpp.

1393{
1395}

References KisToolBar::Private::s_editable.

◆ toolBarsLocked()

bool KisToolBar::toolBarsLocked ( )
static

Returns whether the toolbars are locked (i.e., moving of the toolbars disallowed).

Definition at line 1409 of file ktoolbar.cpp.

1410{
1411 return s_toolBarsModel->toolBarsLocked();
1412}

◆ toolBarStateModel()

KisToolBarStateModel * KisToolBar::toolBarStateModel ( )
static

Definition at line 1422 of file ktoolbar.cpp.

1423{
1424 return s_toolBarsModel;
1425}

Member Data Documentation

◆ d

Private* const KisToolBar::d
private

Definition at line 177 of file ktoolbar.h.


The documentation for this class was generated from the following files: