Changeset View
Changeset View
Standalone View
Standalone View
src/ktoolbar.cpp
Show First 20 Lines • Show All 314 Lines • ▼ Show 20 Line(s) | 306 | if (!context) { | |||
---|---|---|---|---|---|
315 | 315 | | |||
316 | contextTop = contextOrient->addAction(i18nc("toolbar position string", "Top"), q, SLOT(slotContextTop())); | 316 | contextTop = contextOrient->addAction(i18nc("toolbar position string", "Top"), q, SLOT(slotContextTop())); | ||
317 | contextTop->setChecked(true); | 317 | contextTop->setChecked(true); | ||
318 | contextLeft = contextOrient->addAction(i18nc("toolbar position string", "Left"), q, SLOT(slotContextLeft())); | 318 | contextLeft = contextOrient->addAction(i18nc("toolbar position string", "Left"), q, SLOT(slotContextLeft())); | ||
319 | contextRight = contextOrient->addAction(i18nc("toolbar position string", "Right"), q, SLOT(slotContextRight())); | 319 | contextRight = contextOrient->addAction(i18nc("toolbar position string", "Right"), q, SLOT(slotContextRight())); | ||
320 | contextBottom = contextOrient->addAction(i18nc("toolbar position string", "Bottom"), q, SLOT(slotContextBottom())); | 320 | contextBottom = contextOrient->addAction(i18nc("toolbar position string", "Bottom"), q, SLOT(slotContextBottom())); | ||
321 | 321 | | |||
322 | QActionGroup *positionGroup = new QActionGroup(contextOrient); | 322 | QActionGroup *positionGroup = new QActionGroup(contextOrient); | ||
323 | Q_FOREACH (QAction *action, contextOrient->actions()) { | 323 | const auto orientActions = contextOrient->actions(); | ||
324 | for (QAction *action : orientActions) { | ||||
324 | action->setActionGroup(positionGroup); | 325 | action->setActionGroup(positionGroup); | ||
325 | action->setCheckable(true); | 326 | action->setCheckable(true); | ||
326 | } | 327 | } | ||
327 | 328 | | |||
328 | contextMode = new QMenu(i18n("Text Position"), context); | 329 | contextMode = new QMenu(i18n("Text Position"), context); | ||
329 | 330 | | |||
330 | contextIcons = contextMode->addAction(i18n("Icons Only"), q, SLOT(slotContextIcons())); | 331 | contextIcons = contextMode->addAction(i18n("Icons Only"), q, SLOT(slotContextIcons())); | ||
331 | contextText = contextMode->addAction(i18n("Text Only"), q, SLOT(slotContextText())); | 332 | contextText = contextMode->addAction(i18n("Text Only"), q, SLOT(slotContextText())); | ||
332 | contextTextRight = contextMode->addAction(i18n("Text Alongside Icons"), q, SLOT(slotContextTextRight())); | 333 | contextTextRight = contextMode->addAction(i18n("Text Alongside Icons"), q, SLOT(slotContextTextRight())); | ||
333 | contextTextUnder = contextMode->addAction(i18n("Text Under Icons"), q, SLOT(slotContextTextUnder())); | 334 | contextTextUnder = contextMode->addAction(i18n("Text Under Icons"), q, SLOT(slotContextTextUnder())); | ||
334 | 335 | | |||
335 | QActionGroup *textGroup = new QActionGroup(contextMode); | 336 | QActionGroup *textGroup = new QActionGroup(contextMode); | ||
336 | Q_FOREACH (QAction *action, contextMode->actions()) { | 337 | const auto modeActions = contextMode->actions(); | ||
338 | for (QAction *action : modeActions) { | ||||
337 | action->setActionGroup(textGroup); | 339 | action->setActionGroup(textGroup); | ||
338 | action->setCheckable(true); | 340 | action->setCheckable(true); | ||
339 | } | 341 | } | ||
340 | 342 | | |||
341 | contextSize = new QMenu(i18n("Icon Size"), context); | 343 | contextSize = new QMenu(i18n("Icon Size"), context); | ||
342 | 344 | | |||
343 | contextIconSizes.insert(contextSize->addAction(i18nc("@item:inmenu Icon size", "Default"), q, SLOT(slotContextIconSize())), | 345 | contextIconSizes.insert(contextSize->addAction(i18nc("@item:inmenu Icon size", "Default"), q, SLOT(slotContextIconSize())), | ||
344 | iconSizeSettings.defaultValue()); | 346 | iconSizeSettings.defaultValue()); | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 380 | if (it >= progression[ i ]) { | |||
391 | contextIconSizes.insert(contextSize->addAction(text, q, SLOT(slotContextIconSize())), it); | 393 | contextIconSizes.insert(contextSize->addAction(text, q, SLOT(slotContextIconSize())), it); | ||
392 | break; | 394 | break; | ||
393 | } | 395 | } | ||
394 | } | 396 | } | ||
395 | } | 397 | } | ||
396 | } | 398 | } | ||
397 | 399 | | |||
398 | QActionGroup *sizeGroup = new QActionGroup(contextSize); | 400 | QActionGroup *sizeGroup = new QActionGroup(contextSize); | ||
399 | Q_FOREACH (QAction *action, contextSize->actions()) { | 401 | const auto sizeActions = contextSize->actions(); | ||
402 | for (QAction *action : sizeActions) { | ||||
400 | action->setActionGroup(sizeGroup); | 403 | action->setActionGroup(sizeGroup); | ||
401 | action->setCheckable(true); | 404 | action->setCheckable(true); | ||
402 | } | 405 | } | ||
403 | 406 | | |||
404 | if (!q->toolBarsLocked() && !q->isMovable()) { | 407 | if (!q->toolBarsLocked() && !q->isMovable()) { | ||
405 | unlockedMovable = false; | 408 | unlockedMovable = false; | ||
406 | } | 409 | } | ||
407 | 410 | | |||
▲ Show 20 Lines • Show All 683 Lines • ▼ Show 20 Line(s) | 1092 | if (toolBarsEditable() && event->proposedAction() & (Qt::CopyAction | Qt::MoveAction) && | |||
1091 | QByteArray data = event->mimeData()->data(QStringLiteral("application/x-kde-action-list")); | 1094 | QByteArray data = event->mimeData()->data(QStringLiteral("application/x-kde-action-list")); | ||
1092 | 1095 | | |||
1093 | QDataStream stream(data); | 1096 | QDataStream stream(data); | ||
1094 | 1097 | | |||
1095 | QStringList actionNames; | 1098 | QStringList actionNames; | ||
1096 | 1099 | | |||
1097 | stream >> actionNames; | 1100 | stream >> actionNames; | ||
1098 | 1101 | | |||
1102 | const auto allCollections = KActionCollection::allCollections(); | ||||
1099 | for (const QString &actionName : qAsConst(actionNames)) { | 1103 | for (const QString &actionName : qAsConst(actionNames)) { | ||
1100 | Q_FOREACH (KActionCollection *ac, KActionCollection::allCollections()) { | 1104 | for (KActionCollection *ac : allCollections) { | ||
1101 | QAction *newAction = ac->action(actionName); | 1105 | QAction *newAction = ac->action(actionName); | ||
1102 | if (newAction) { | 1106 | if (newAction) { | ||
1103 | d->actionsBeingDragged.append(newAction); | 1107 | d->actionsBeingDragged.append(newAction); | ||
1104 | break; | 1108 | break; | ||
1105 | } | 1109 | } | ||
1106 | } | 1110 | } | ||
1107 | } | 1111 | } | ||
1108 | 1112 | | |||
Show All 19 Lines | |||||
1128 | 1132 | | |||
1129 | void KToolBar::dragMoveEvent(QDragMoveEvent *event) | 1133 | void KToolBar::dragMoveEvent(QDragMoveEvent *event) | ||
1130 | { | 1134 | { | ||
1131 | if (toolBarsEditable()) | 1135 | if (toolBarsEditable()) | ||
1132 | Q_FOREVER { | 1136 | Q_FOREVER { | ||
1133 | if (d->dropIndicatorAction) | 1137 | if (d->dropIndicatorAction) | ||
1134 | { | 1138 | { | ||
1135 | QAction *overAction = nullptr; | 1139 | QAction *overAction = nullptr; | ||
1136 | Q_FOREACH (QAction *action, actions()) { | 1140 | const auto actions = this->actions(); | ||
1141 | for (QAction *action : actions) { | ||||
1137 | // want to make it feel that half way across an action you're dropping on the other side of it | 1142 | // want to make it feel that half way across an action you're dropping on the other side of it | ||
1138 | QWidget *widget = widgetForAction(action); | 1143 | QWidget *widget = widgetForAction(action); | ||
1139 | if (event->pos().x() < widget->pos().x() + (widget->width() / 2)) { | 1144 | if (event->pos().x() < widget->pos().x() + (widget->width() / 2)) { | ||
1140 | overAction = action; | 1145 | overAction = action; | ||
1141 | break; | 1146 | break; | ||
1142 | } | 1147 | } | ||
1143 | } | 1148 | } | ||
1144 | 1149 | | |||
1145 | if (overAction != d->dropIndicatorAction) { | 1150 | if (overAction != d->dropIndicatorAction) { | ||
1146 | // Check to see if the indicator is already in the right spot | 1151 | // Check to see if the indicator is already in the right spot | ||
1147 | int dropIndicatorIndex = actions().indexOf(d->dropIndicatorAction); | 1152 | int dropIndicatorIndex = actions.indexOf(d->dropIndicatorAction); | ||
1148 | if (dropIndicatorIndex + 1 < actions().count()) { | 1153 | if (dropIndicatorIndex + 1 < actions.count()) { | ||
1149 | if (actions().at(dropIndicatorIndex + 1) == overAction) { | 1154 | if (actions.at(dropIndicatorIndex + 1) == overAction) { | ||
1150 | break; | 1155 | break; | ||
1151 | } | 1156 | } | ||
1152 | } else if (!overAction) { | 1157 | } else if (!overAction) { | ||
1153 | break; | 1158 | break; | ||
1154 | } | 1159 | } | ||
1155 | 1160 | | |||
1156 | insertAction(overAction, d->dropIndicatorAction); | 1161 | insertAction(overAction, d->dropIndicatorAction); | ||
1157 | } | 1162 | } | ||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Line(s) | 1281 | { | |||
1285 | 1290 | | |||
1286 | } else if (event->type() == QEvent::ParentChange) { | 1291 | } else if (event->type() == QEvent::ParentChange) { | ||
1287 | // Make sure we're not leaving stale event filters around, | 1292 | // Make sure we're not leaving stale event filters around, | ||
1288 | // when a child is reparented somewhere else | 1293 | // when a child is reparented somewhere else | ||
1289 | if (QWidget *ww = qobject_cast<QWidget *>(watched)) { | 1294 | if (QWidget *ww = qobject_cast<QWidget *>(watched)) { | ||
1290 | if (!this->isAncestorOf(ww)) { | 1295 | if (!this->isAncestorOf(ww)) { | ||
1291 | // New parent is not a subwidget - remove event filter | 1296 | // New parent is not a subwidget - remove event filter | ||
1292 | ww->removeEventFilter(this); | 1297 | ww->removeEventFilter(this); | ||
1293 | Q_FOREACH (QWidget *child, ww->findChildren<QWidget *>()) { | 1298 | const auto children = ww->findChildren<QWidget *>(); | ||
1299 | for (QWidget *child : children) { | ||||
1294 | child->removeEventFilter(this); | 1300 | child->removeEventFilter(this); | ||
1295 | } | 1301 | } | ||
1296 | } | 1302 | } | ||
1297 | } | 1303 | } | ||
1298 | } | 1304 | } | ||
1299 | 1305 | | |||
1300 | // Redirect mouse events to the toolbar when drag + drop editing is enabled | 1306 | // Redirect mouse events to the toolbar when drag + drop editing is enabled | ||
1301 | if (toolBarsEditable()) { | 1307 | if (toolBarsEditable()) { | ||
Show All 31 Lines | |||||
1333 | 1339 | | |||
1334 | void KToolBar::actionEvent(QActionEvent *event) | 1340 | void KToolBar::actionEvent(QActionEvent *event) | ||
1335 | { | 1341 | { | ||
1336 | if (event->type() == QEvent::ActionRemoved) { | 1342 | if (event->type() == QEvent::ActionRemoved) { | ||
1337 | QWidget *widget = widgetForAction(event->action()); | 1343 | QWidget *widget = widgetForAction(event->action()); | ||
1338 | if (widget) { | 1344 | if (widget) { | ||
1339 | widget->removeEventFilter(this); | 1345 | widget->removeEventFilter(this); | ||
1340 | 1346 | | |||
1341 | Q_FOREACH (QWidget *child, widget->findChildren<QWidget *>()) { | 1347 | const auto children = widget->findChildren<QWidget *>(); | ||
1348 | for (QWidget *child : children) { | ||||
1342 | child->removeEventFilter(this); | 1349 | child->removeEventFilter(this); | ||
1343 | } | 1350 | } | ||
1344 | } | 1351 | } | ||
1345 | } | 1352 | } | ||
1346 | 1353 | | |||
1347 | QToolBar::actionEvent(event); | 1354 | QToolBar::actionEvent(event); | ||
1348 | 1355 | | |||
1349 | if (event->type() == QEvent::ActionAdded) { | 1356 | if (event->type() == QEvent::ActionAdded) { | ||
1350 | QWidget *widget = widgetForAction(event->action()); | 1357 | QWidget *widget = widgetForAction(event->action()); | ||
1351 | if (widget) { | 1358 | if (widget) { | ||
1352 | widget->installEventFilter(this); | 1359 | widget->installEventFilter(this); | ||
1353 | 1360 | | |||
1354 | Q_FOREACH (QWidget *child, widget->findChildren<QWidget *>()) { | 1361 | const auto children = widget->findChildren<QWidget *>(); | ||
1362 | for (QWidget *child : children) { | ||||
1355 | child->installEventFilter(this); | 1363 | child->installEventFilter(this); | ||
1356 | } | 1364 | } | ||
1357 | // Center widgets that do not have any use for more space. See bug 165274 | 1365 | // Center widgets that do not have any use for more space. See bug 165274 | ||
1358 | if (!(widget->sizePolicy().horizontalPolicy() & QSizePolicy::GrowFlag) | 1366 | if (!(widget->sizePolicy().horizontalPolicy() & QSizePolicy::GrowFlag) | ||
1359 | // ... but do not center when using text besides icon in vertical toolbar. See bug 243196 | 1367 | // ... but do not center when using text besides icon in vertical toolbar. See bug 243196 | ||
1360 | && !(orientation() == Qt::Vertical && toolButtonStyle() == Qt::ToolButtonTextBesideIcon)) { | 1368 | && !(orientation() == Qt::Vertical && toolButtonStyle() == Qt::ToolButtonTextBesideIcon)) { | ||
1361 | const int index = layout()->indexOf(widget); | 1369 | const int index = layout()->indexOf(widget); | ||
1362 | if (index != -1) { | 1370 | if (index != -1) { | ||
Show All 18 Lines | 1386 | { | |||
1381 | } | 1389 | } | ||
1382 | } | 1390 | } | ||
1383 | 1391 | | |||
1384 | void KToolBar::setToolBarsLocked(bool locked) | 1392 | void KToolBar::setToolBarsLocked(bool locked) | ||
1385 | { | 1393 | { | ||
1386 | if (KToolBar::Private::s_locked != locked) { | 1394 | if (KToolBar::Private::s_locked != locked) { | ||
1387 | KToolBar::Private::s_locked = locked; | 1395 | KToolBar::Private::s_locked = locked; | ||
1388 | 1396 | | |||
1389 | Q_FOREACH (KMainWindow *mw, KMainWindow::memberList()) { | 1397 | const auto windows = KMainWindow::memberList(); | ||
1390 | Q_FOREACH (KToolBar *toolbar, mw->findChildren<KToolBar *>()) { | 1398 | for (KMainWindow *mw : windows) { | ||
1399 | const auto toolbars = mw->findChildren<KToolBar *>(); | ||||
1400 | for (KToolBar *toolbar : toolbars) { | ||||
1391 | toolbar->d->setLocked(locked); | 1401 | toolbar->d->setLocked(locked); | ||
1392 | } | 1402 | } | ||
1393 | } | 1403 | } | ||
1394 | } | 1404 | } | ||
1395 | } | 1405 | } | ||
1396 | 1406 | | |||
1397 | bool KToolBar::toolBarsLocked() | 1407 | bool KToolBar::toolBarsLocked() | ||
1398 | { | 1408 | { | ||
Show All 12 Lines |