Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdesigner_toolbar.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant reason:default
4
12
13#include <QtDesigner/abstractformwindow.h>
14#include <QtDesigner/abstractpropertyeditor.h>
15#include <QtDesigner/abstractformeditor.h>
16#include <actionprovider_p.h>
17#include <QtDesigner/qextensionmanager.h>
18#include <QtDesigner/abstractwidgetfactory.h>
19
20#include <QtWidgets/qapplication.h>
21#include <QtWidgets/qtoolbutton.h>
22#include <QtWidgets/qtoolbar.h>
23#include <QtWidgets/qmenu.h>
24
25#include <QtGui/qaction.h>
26#include <QtGui/qevent.h>
27#include <QtGui/qdrag.h>
28
29#include <QtCore/qdebug.h>
30
32
33using namespace Qt::StringLiterals;
34
35using ActionList = QList<QAction *>;
36
37namespace qdesigner_internal {
38// ------------------- ToolBarEventFilter
45
47 QObject(tb),
49 m_promotionTaskMenu(nullptr)
50{
51}
52
54{
55 // Look for 1st order children only..otherwise, we might get filters of nested widgets
56 for (QObject *o : tb->children()) {
57 if (!o->isWidgetType())
59 return ef;
60 }
61 return nullptr;
62}
63
65{
66 if (watched != m_toolBar)
68
69 bool handled = false;
70 switch (event->type()) {
71 case QEvent::ChildAdded: // Children should not interact with the mouse
72 if (auto *c = static_cast<const QChildEvent *>(event)->child(); c->isWidgetType()) {
73 QWidget *w = static_cast<QWidget *>(c);
76 }
77 break;
78 case QEvent::ContextMenu:
80 break;
81 case QEvent::DragEnter:
82 case QEvent::DragMove:
84 break;
85 case QEvent::DragLeave:
87 break;
88 case QEvent::Drop:
89 handled = handleDropEvent(static_cast<QDropEvent *>(event));
90 break;
93 break;
96 break;
97 case QEvent::MouseMove:
99 break;
100 default:
101 break;
102 }
103
105}
106
108{
111 const auto actions = m_toolBar->actions();
112 QAction *action = index != -1 ?actions.at(index) : 0;
114
115 // Insert before
116 if (action && index != 0 && !action->isSeparator()) {
117 QAction *newSeperatorAct = new QAction(tr("Insert Separator before '%1'").arg(action->objectName()), nullptr);
122 }
123
124 // Append separator
126 QAction *newSeperatorAct = new QAction(tr("Append Separator"), nullptr);
127 itemData.setValue(static_cast<QAction*>(nullptr));
131 }
132 // Promotion
136 // Remove
137 if (action) {
138 QAction *a = new QAction(tr("Remove action '%1'").arg(action->objectName()), nullptr);
142 rc.push_back(a);
143 }
144
145 QAction *remove_toolbar = new QAction(tr("Remove Toolbar '%1'").arg(m_toolBar->objectName()), nullptr);
148 return rc;
149}
150
152{
153 event->accept();
154
155 const QPoint globalPos = event->globalPos();
157
158 QMenu menu(nullptr);
159 for (auto *a : al)
162 return true;
163}
164
166{
168 if (!action)
169 return;
170
172 Q_ASSERT(a != nullptr);
173
175 Q_ASSERT(fw);
176
178 const int pos = actions.indexOf(a);
179 QAction *action_before = nullptr;
180 if (pos != -1 && actions.size() > pos + 1)
182
186}
187
189{
191 Q_ASSERT(fw);
195}
196
198{
202 fw->beginCommand(tr("Insert Separator"));
203 QAction *action = createAction(fw, u"separator"_s, true);
207 fw->endCommand();
208}
209
211{
213}
214
231
233{
238 }
239}
240
242{
244}
245
247{
249 return false;
250
253 // Keep selection in sync
254 fw->clearSelection(false);
258 }
260 }
264 event->accept();
265 return true;
266 }
267 return false;
268}
269
271{
273 return false;
274
275 // Accept the event, otherwise, form window selection will trigger
277 event->accept();
278 return true;
279}
280
282{
284 return false;
285
290 event->accept();
291 return true;
292 }
293 return false;
294}
295
297{
299 if (!d)
300 return false;
301
302 if (d->actionList().isEmpty()) {
303 event->ignore();
305 return true;
306 }
307
310 event->ignore();
312 return true;
313 }
314
315 d->accept(event);
317 return true;
318}
319
321{
323 return false;
324}
325
327{
329 if (!d)
330 return false;
331
332 if (d->actionList().isEmpty()) {
333 event->ignore();
335 return true;
336 }
337
339
341 if (!action || actions.contains(action)) {
342 event->ignore();
344 return true;
345 }
346
347 // Try to find action to 'insert before'. Click on action or in free area, else ignore.
348 QAction *beforeAction = nullptr;
349 const QPoint pos = event->position().toPoint();
351 if (index != -1) {
353 } else {
355 event->ignore();
357 return true;
358 }
359 }
360
367 return true;
368}
369
371{
373 if (index == - 1)
374 return false;
375
379
381 if (dropAction == Qt::MoveAction) {
383 const int nextIndex = index + 1;
387 }
388
389 QDrag *drag = new QDrag(m_toolBar);
392
393 if (drag->exec(dropAction) == Qt::IgnoreAction) {
395 if (dropAction == Qt::MoveAction) {
397 QAction *previous = nullptr;
398 if (index >= 0 && index < currentActions.size())
403 }
404 }
405 return true;
406}
407
409{
410 const int index = actionIndexAt(tb, pos, tb->orientation());
411 if (index == -1)
412 return nullptr;
413 return tb->actions().at(index);
414}
415
416//that's a trick to get access to the initStyleOption which is a protected member
417class FriendlyToolBar : public QToolBar {
418public:
419 friend class ToolBarEventFilter;
420};
421
428
430{
431 return handleArea(tb).contains(pos);
432}
433
434// Determine the free area behind the last action.
436{
437 QRect rc = QRect(QPoint(0, 0), tb->size());
438 const ActionList actionList = tb->actions();
441 switch (tb->orientation()) {
442 case Qt::Horizontal:
443 switch (tb->layoutDirection()) {
444 case Qt::LayoutDirectionAuto: // Should never happen
445 case Qt::LeftToRight:
447 break;
448 case Qt::RightToLeft:
450 break;
451 }
452 break;
453 case Qt::Vertical:
455 break;
456 }
457 return rc;
458}
459
460}
461
462QT_END_NAMESPACE
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.