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
11
12#include <QtDesigner/abstractformwindow.h>
13#include <QtDesigner/abstractpropertyeditor.h>
14#include <QtDesigner/abstractformeditor.h>
15#include <actionprovider_p.h>
16#include <QtDesigner/qextensionmanager.h>
17#include <QtDesigner/abstractwidgetfactory.h>
18
19#include <QtWidgets/qapplication.h>
20#include <QtWidgets/qtoolbutton.h>
21#include <QtWidgets/qtoolbar.h>
22#include <QtWidgets/qmenu.h>
23
24#include <QtGui/qaction.h>
25#include <QtGui/qevent.h>
26#include <QtGui/qdrag.h>
27
28#include <QtCore/qdebug.h>
29
31
32using namespace Qt::StringLiterals;
33
34using ActionList = QList<QAction *>;
35
36namespace qdesigner_internal {
37// ------------------- ToolBarEventFilter
44
46 QObject(tb),
48 m_promotionTaskMenu(nullptr)
49{
50}
51
53{
54 // Look for 1st order children only..otherwise, we might get filters of nested widgets
55 for (QObject *o : tb->children()) {
56 if (!o->isWidgetType())
58 return ef;
59 }
60 return nullptr;
61}
62
64{
65 if (watched != m_toolBar)
67
68 bool handled = false;
69 switch (event->type()) {
70 case QEvent::ChildAdded: {
71 // Children should not interact with the mouse
72 const QChildEvent *ce = static_cast<const QChildEvent *>(event);
73 if (QWidget *w = qobject_cast<QWidget *>(ce->child())) {
76 }
77 }
78 break;
79 case QEvent::ContextMenu:
81 break;
82 case QEvent::DragEnter:
83 case QEvent::DragMove:
85 break;
86 case QEvent::DragLeave:
88 break;
89 case QEvent::Drop:
90 handled = handleDropEvent(static_cast<QDropEvent *>(event));
91 break;
94 break;
97 break;
98 case QEvent::MouseMove:
100 break;
101 default:
102 break;
103 }
104
106}
107
109{
112 const auto actions = m_toolBar->actions();
113 QAction *action = index != -1 ?actions.at(index) : 0;
115
116 // Insert before
117 if (action && index != 0 && !action->isSeparator()) {
118 QAction *newSeperatorAct = new QAction(tr("Insert Separator before '%1'").arg(action->objectName()), nullptr);
123 }
124
125 // Append separator
127 QAction *newSeperatorAct = new QAction(tr("Append Separator"), nullptr);
128 itemData.setValue(static_cast<QAction*>(nullptr));
132 }
133 // Promotion
137 // Remove
138 if (action) {
139 QAction *a = new QAction(tr("Remove action '%1'").arg(action->objectName()), nullptr);
143 rc.push_back(a);
144 }
145
146 QAction *remove_toolbar = new QAction(tr("Remove Toolbar '%1'").arg(m_toolBar->objectName()), nullptr);
149 return rc;
150}
151
153{
154 event->accept();
155
156 const QPoint globalPos = event->globalPos();
158
159 QMenu menu(nullptr);
160 for (auto *a : al)
163 return true;
164}
165
167{
169 if (!action)
170 return;
171
173 Q_ASSERT(a != nullptr);
174
176 Q_ASSERT(fw);
177
179 const int pos = actions.indexOf(a);
180 QAction *action_before = nullptr;
181 if (pos != -1 && actions.size() > pos + 1)
183
187}
188
190{
192 Q_ASSERT(fw);
196}
197
199{
203 fw->beginCommand(tr("Insert Separator"));
204 QAction *action = createAction(fw, u"separator"_s, true);
208 fw->endCommand();
209}
210
212{
214}
215
232
234{
239 }
240}
241
243{
245}
246
248{
250 return false;
251
254 // Keep selection in sync
255 fw->clearSelection(false);
259 }
261 }
265 event->accept();
266 return true;
267 }
268 return false;
269}
270
272{
274 return false;
275
276 // Accept the event, otherwise, form window selection will trigger
278 event->accept();
279 return true;
280}
281
283{
285 return false;
286
291 event->accept();
292 return true;
293 }
294 return false;
295}
296
298{
300 if (!d)
301 return false;
302
303 if (d->actionList().isEmpty()) {
304 event->ignore();
306 return true;
307 }
308
311 event->ignore();
313 return true;
314 }
315
316 d->accept(event);
318 return true;
319}
320
322{
324 return false;
325}
326
328{
330 if (!d)
331 return false;
332
333 if (d->actionList().isEmpty()) {
334 event->ignore();
336 return true;
337 }
338
340
342 if (!action || actions.contains(action)) {
343 event->ignore();
345 return true;
346 }
347
348 // Try to find action to 'insert before'. Click on action or in free area, else ignore.
349 QAction *beforeAction = nullptr;
350 const QPoint pos = event->position().toPoint();
352 if (index != -1) {
354 } else {
356 event->ignore();
358 return true;
359 }
360 }
361
368 return true;
369}
370
372{
374 if (index == - 1)
375 return false;
376
380
382 if (dropAction == Qt::MoveAction) {
384 const int nextIndex = index + 1;
388 }
389
390 QDrag *drag = new QDrag(m_toolBar);
393
394 if (drag->exec(dropAction) == Qt::IgnoreAction) {
396 if (dropAction == Qt::MoveAction) {
398 QAction *previous = nullptr;
399 if (index >= 0 && index < currentActions.size())
404 }
405 }
406 return true;
407}
408
410{
411 const int index = actionIndexAt(tb, pos, tb->orientation());
412 if (index == -1)
413 return nullptr;
414 return tb->actions().at(index);
415}
416
417//that's a trick to get access to the initStyleOption which is a protected member
418class FriendlyToolBar : public QToolBar {
419public:
420 friend class ToolBarEventFilter;
421};
422
429
431{
432 return handleArea(tb).contains(pos);
433}
434
435// Determine the free area behind the last action.
437{
438 QRect rc = QRect(QPoint(0, 0), tb->size());
439 const ActionList actionList = tb->actions();
442 switch (tb->orientation()) {
443 case Qt::Horizontal:
444 switch (tb->layoutDirection()) {
445 case Qt::LayoutDirectionAuto: // Should never happen
446 case Qt::LeftToRight:
448 break;
449 case Qt::RightToLeft:
451 break;
452 }
453 break;
454 case Qt::Vertical:
456 break;
457 }
458 return rc;
459}
460
461}
462
463QT_END_NAMESPACE
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.