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: // Children should not interact with the mouse
71 if (auto *c = static_cast<const QChildEvent *>(event)->child(); c->isWidgetType()) {
72 QWidget *w = static_cast<QWidget *>(c);
75 }
76 break;
77 case QEvent::ContextMenu:
79 break;
80 case QEvent::DragEnter:
81 case QEvent::DragMove:
83 break;
84 case QEvent::DragLeave:
86 break;
87 case QEvent::Drop:
88 handled = handleDropEvent(static_cast<QDropEvent *>(event));
89 break;
92 break;
95 break;
96 case QEvent::MouseMove:
98 break;
99 default:
100 break;
101 }
102
104}
105
107{
110 const auto actions = m_toolBar->actions();
111 QAction *action = index != -1 ?actions.at(index) : 0;
113
114 // Insert before
115 if (action && index != 0 && !action->isSeparator()) {
116 QAction *newSeperatorAct = new QAction(tr("Insert Separator before '%1'").arg(action->objectName()), nullptr);
121 }
122
123 // Append separator
125 QAction *newSeperatorAct = new QAction(tr("Append Separator"), nullptr);
126 itemData.setValue(static_cast<QAction*>(nullptr));
130 }
131 // Promotion
135 // Remove
136 if (action) {
137 QAction *a = new QAction(tr("Remove action '%1'").arg(action->objectName()), nullptr);
141 rc.push_back(a);
142 }
143
144 QAction *remove_toolbar = new QAction(tr("Remove Toolbar '%1'").arg(m_toolBar->objectName()), nullptr);
147 return rc;
148}
149
151{
152 event->accept();
153
154 const QPoint globalPos = event->globalPos();
156
157 QMenu menu(nullptr);
158 for (auto *a : al)
161 return true;
162}
163
165{
167 if (!action)
168 return;
169
171 Q_ASSERT(a != nullptr);
172
174 Q_ASSERT(fw);
175
177 const int pos = actions.indexOf(a);
178 QAction *action_before = nullptr;
179 if (pos != -1 && actions.size() > pos + 1)
181
185}
186
188{
190 Q_ASSERT(fw);
194}
195
197{
201 fw->beginCommand(tr("Insert Separator"));
202 QAction *action = createAction(fw, u"separator"_s, true);
206 fw->endCommand();
207}
208
210{
212}
213
230
232{
237 }
238}
239
241{
243}
244
246{
248 return false;
249
252 // Keep selection in sync
253 fw->clearSelection(false);
257 }
259 }
263 event->accept();
264 return true;
265 }
266 return false;
267}
268
270{
272 return false;
273
274 // Accept the event, otherwise, form window selection will trigger
276 event->accept();
277 return true;
278}
279
281{
283 return false;
284
289 event->accept();
290 return true;
291 }
292 return false;
293}
294
296{
298 if (!d)
299 return false;
300
301 if (d->actionList().isEmpty()) {
302 event->ignore();
304 return true;
305 }
306
309 event->ignore();
311 return true;
312 }
313
314 d->accept(event);
316 return true;
317}
318
320{
322 return false;
323}
324
326{
328 if (!d)
329 return false;
330
331 if (d->actionList().isEmpty()) {
332 event->ignore();
334 return true;
335 }
336
338
340 if (!action || actions.contains(action)) {
341 event->ignore();
343 return true;
344 }
345
346 // Try to find action to 'insert before'. Click on action or in free area, else ignore.
347 QAction *beforeAction = nullptr;
348 const QPoint pos = event->position().toPoint();
350 if (index != -1) {
352 } else {
354 event->ignore();
356 return true;
357 }
358 }
359
366 return true;
367}
368
370{
372 if (index == - 1)
373 return false;
374
378
380 if (dropAction == Qt::MoveAction) {
382 const int nextIndex = index + 1;
386 }
387
388 QDrag *drag = new QDrag(m_toolBar);
391
392 if (drag->exec(dropAction) == Qt::IgnoreAction) {
394 if (dropAction == Qt::MoveAction) {
396 QAction *previous = nullptr;
397 if (index >= 0 && index < currentActions.size())
402 }
403 }
404 return true;
405}
406
408{
409 const int index = actionIndexAt(tb, pos, tb->orientation());
410 if (index == -1)
411 return nullptr;
412 return tb->actions().at(index);
413}
414
415//that's a trick to get access to the initStyleOption which is a protected member
416class FriendlyToolBar : public QToolBar {
417public:
418 friend class ToolBarEventFilter;
419};
420
427
429{
430 return handleArea(tb).contains(pos);
431}
432
433// Determine the free area behind the last action.
435{
436 QRect rc = QRect(QPoint(0, 0), tb->size());
437 const ActionList actionList = tb->actions();
440 switch (tb->orientation()) {
441 case Qt::Horizontal:
442 switch (tb->layoutDirection()) {
443 case Qt::LayoutDirectionAuto: // Should never happen
444 case Qt::LeftToRight:
446 break;
447 case Qt::RightToLeft:
449 break;
450 }
451 break;
452 case Qt::Vertical:
454 break;
455 }
456 return rc;
457}
458
459}
460
461QT_END_NAMESPACE
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.