0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the Qt Designer of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include "qdesigner_toolbar_p.h"
|
|
43 |
#include "qdesigner_command_p.h"
|
|
44 |
#include "actionrepository_p.h"
|
|
45 |
#include "actionprovider_p.h"
|
|
46 |
#include "qdesigner_utils_p.h"
|
|
47 |
#include "qdesigner_objectinspector_p.h"
|
|
48 |
#include "promotiontaskmenu_p.h"
|
|
49 |
|
|
50 |
#include <QtDesigner/QDesignerFormWindowInterface>
|
|
51 |
#include <QtDesigner/QDesignerPropertyEditorInterface>
|
|
52 |
#include <QtDesigner/QDesignerFormEditorInterface>
|
|
53 |
#include <actionprovider_p.h>
|
|
54 |
#include <QtDesigner/QExtensionManager>
|
|
55 |
#include <QtDesigner/QDesignerWidgetFactoryInterface>
|
|
56 |
|
|
57 |
#include <QtGui/QAction>
|
|
58 |
#include <QtGui/QApplication>
|
|
59 |
#include <QtGui/QToolButton>
|
|
60 |
#include <QtGui/QToolBar>
|
|
61 |
#include <QtGui/QMenu>
|
|
62 |
#include <QtGui/qevent.h>
|
|
63 |
#include <QtGui/QApplication>
|
|
64 |
#include <QtCore/QDebug>
|
|
65 |
|
|
66 |
Q_DECLARE_METATYPE(QAction*)
|
|
67 |
|
|
68 |
QT_BEGIN_NAMESPACE
|
|
69 |
|
|
70 |
typedef QList<QAction*> ActionList;
|
|
71 |
|
|
72 |
namespace qdesigner_internal {
|
|
73 |
// ------------------- ToolBarEventFilter
|
|
74 |
void ToolBarEventFilter::install(QToolBar *tb)
|
|
75 |
{
|
|
76 |
ToolBarEventFilter *tf = new ToolBarEventFilter(tb);
|
|
77 |
tb->installEventFilter(tf);
|
|
78 |
tb->setAcceptDrops(true); // ### fake
|
|
79 |
}
|
|
80 |
|
|
81 |
ToolBarEventFilter::ToolBarEventFilter(QToolBar *tb) :
|
|
82 |
QObject(tb),
|
|
83 |
m_toolBar(tb),
|
|
84 |
m_promotionTaskMenu(0)
|
|
85 |
{
|
|
86 |
}
|
|
87 |
|
|
88 |
ToolBarEventFilter *ToolBarEventFilter::eventFilterOf(const QToolBar *tb)
|
|
89 |
{
|
|
90 |
// Look for 1st order children only..otherwise, we might get filters of nested widgets
|
|
91 |
const QObjectList children = tb->children();
|
|
92 |
const QObjectList::const_iterator cend = children.constEnd();
|
|
93 |
for (QObjectList::const_iterator it = children.constBegin(); it != cend; ++it) {
|
|
94 |
QObject *o = *it;
|
|
95 |
if (!o->isWidgetType())
|
|
96 |
if (ToolBarEventFilter *ef = qobject_cast<ToolBarEventFilter *>(o))
|
|
97 |
return ef;
|
|
98 |
}
|
|
99 |
return 0;
|
|
100 |
}
|
|
101 |
|
|
102 |
bool ToolBarEventFilter::eventFilter (QObject *watched, QEvent *event)
|
|
103 |
{
|
|
104 |
if (watched != m_toolBar)
|
|
105 |
return QObject::eventFilter (watched, event);
|
|
106 |
|
|
107 |
switch (event->type()) {
|
|
108 |
case QEvent::ChildAdded: {
|
|
109 |
// Children should not interact with the mouse
|
|
110 |
const QChildEvent *ce = static_cast<const QChildEvent *>(event);
|
|
111 |
if (QWidget *w = qobject_cast<QWidget *>(ce->child())) {
|
|
112 |
w->setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
|
113 |
w->setFocusPolicy(Qt::NoFocus);
|
|
114 |
}
|
|
115 |
}
|
|
116 |
break;
|
|
117 |
case QEvent::ContextMenu:
|
|
118 |
return handleContextMenuEvent(static_cast<QContextMenuEvent*>(event));
|
|
119 |
case QEvent::DragEnter:
|
|
120 |
case QEvent::DragMove:
|
|
121 |
return handleDragEnterMoveEvent(static_cast<QDragMoveEvent *>(event));
|
|
122 |
case QEvent::DragLeave:
|
|
123 |
return handleDragLeaveEvent(static_cast<QDragLeaveEvent *>(event));
|
|
124 |
case QEvent::Drop:
|
|
125 |
return handleDropEvent(static_cast<QDropEvent *>(event));
|
|
126 |
case QEvent::MouseButtonPress:
|
|
127 |
return handleMousePressEvent(static_cast<QMouseEvent*>(event));
|
|
128 |
case QEvent::MouseButtonRelease:
|
|
129 |
return handleMouseReleaseEvent(static_cast<QMouseEvent*>(event));
|
|
130 |
case QEvent::MouseMove:
|
|
131 |
return handleMouseMoveEvent(static_cast<QMouseEvent*>(event));
|
|
132 |
default:
|
|
133 |
break;
|
|
134 |
}
|
|
135 |
return QObject::eventFilter (watched, event);
|
|
136 |
}
|
|
137 |
|
|
138 |
ActionList ToolBarEventFilter::contextMenuActions(const QPoint &globalPos)
|
|
139 |
{
|
|
140 |
ActionList rc;
|
|
141 |
const int index = actionIndexAt(m_toolBar, m_toolBar->mapFromGlobal(globalPos), m_toolBar->orientation());
|
|
142 |
const ActionList actions = m_toolBar->actions();
|
|
143 |
QAction *action = index != -1 ?actions.at(index) : 0;
|
|
144 |
QVariant itemData;
|
|
145 |
|
|
146 |
// Insert before
|
|
147 |
if (action && index != 0 && !action->isSeparator()) {
|
|
148 |
QAction *newSeperatorAct = new QAction(tr("Insert Separator before '%1'").arg(action->objectName()), 0);
|
|
149 |
qVariantSetValue(itemData, action);
|
|
150 |
newSeperatorAct->setData(itemData);
|
|
151 |
connect(newSeperatorAct, SIGNAL(triggered()), this, SLOT(slotInsertSeparator()));
|
|
152 |
rc.push_back(newSeperatorAct);
|
|
153 |
}
|
|
154 |
|
|
155 |
// Append separator
|
|
156 |
if (actions.empty() || !actions.back()->isSeparator()) {
|
|
157 |
QAction *newSeperatorAct = new QAction(tr("Append Separator"), 0);
|
|
158 |
qVariantSetValue(itemData, static_cast<QAction*>(0));
|
|
159 |
newSeperatorAct->setData(itemData);
|
|
160 |
connect(newSeperatorAct, SIGNAL(triggered()), this, SLOT(slotInsertSeparator()));
|
|
161 |
rc.push_back(newSeperatorAct);
|
|
162 |
}
|
|
163 |
// Promotion
|
|
164 |
if (!m_promotionTaskMenu)
|
|
165 |
m_promotionTaskMenu = new PromotionTaskMenu(m_toolBar, PromotionTaskMenu::ModeSingleWidget, this);
|
|
166 |
m_promotionTaskMenu->addActions(formWindow(), PromotionTaskMenu::LeadingSeparator|PromotionTaskMenu::TrailingSeparator, rc);
|
|
167 |
// Remove
|
|
168 |
if (action) {
|
|
169 |
QAction *a = new QAction(tr("Remove action '%1'").arg(action->objectName()), 0);
|
|
170 |
qVariantSetValue(itemData, action);
|
|
171 |
a->setData(itemData);
|
|
172 |
connect(a, SIGNAL(triggered()), this, SLOT(slotRemoveSelectedAction()));
|
|
173 |
rc.push_back(a);
|
|
174 |
}
|
|
175 |
|
|
176 |
QAction *remove_toolbar = new QAction(tr("Remove Toolbar '%1'").arg(m_toolBar->objectName()), 0);
|
|
177 |
connect(remove_toolbar, SIGNAL(triggered()), this, SLOT(slotRemoveToolBar()));
|
|
178 |
rc.push_back(remove_toolbar);
|
|
179 |
return rc;
|
|
180 |
}
|
|
181 |
|
|
182 |
bool ToolBarEventFilter::handleContextMenuEvent(QContextMenuEvent * event )
|
|
183 |
{
|
|
184 |
event->accept();
|
|
185 |
|
|
186 |
const QPoint globalPos = event->globalPos();
|
|
187 |
const ActionList al = contextMenuActions(event->globalPos());
|
|
188 |
|
|
189 |
QMenu menu(0);
|
|
190 |
const ActionList::const_iterator acend = al.constEnd();
|
|
191 |
for (ActionList::const_iterator it = al.constBegin(); it != acend; ++it)
|
|
192 |
menu.addAction(*it);
|
|
193 |
menu.exec(globalPos);
|
|
194 |
return true;
|
|
195 |
}
|
|
196 |
|
|
197 |
void ToolBarEventFilter::slotRemoveSelectedAction()
|
|
198 |
{
|
|
199 |
QAction *action = qobject_cast<QAction*>(sender());
|
|
200 |
if (!action)
|
|
201 |
return;
|
|
202 |
|
|
203 |
QAction *a = qvariant_cast<QAction*>(action->data());
|
|
204 |
Q_ASSERT(a != 0);
|
|
205 |
|
|
206 |
QDesignerFormWindowInterface *fw = formWindow();
|
|
207 |
Q_ASSERT(fw);
|
|
208 |
|
|
209 |
const ActionList actions = m_toolBar->actions();
|
|
210 |
const int pos = actions.indexOf(a);
|
|
211 |
QAction *action_before = 0;
|
|
212 |
if (pos != -1 && actions.count() > pos + 1)
|
|
213 |
action_before = actions.at(pos + 1);
|
|
214 |
|
|
215 |
RemoveActionFromCommand *cmd = new RemoveActionFromCommand(fw);
|
|
216 |
cmd->init(m_toolBar, a, action_before);
|
|
217 |
fw->commandHistory()->push(cmd);
|
|
218 |
}
|
|
219 |
|
|
220 |
void ToolBarEventFilter::slotRemoveToolBar()
|
|
221 |
{
|
|
222 |
QDesignerFormWindowInterface *fw = formWindow();
|
|
223 |
Q_ASSERT(fw);
|
|
224 |
DeleteToolBarCommand *cmd = new DeleteToolBarCommand(fw);
|
|
225 |
cmd->init(m_toolBar);
|
|
226 |
fw->commandHistory()->push(cmd);
|
|
227 |
}
|
|
228 |
|
|
229 |
void ToolBarEventFilter::slotInsertSeparator()
|
|
230 |
{
|
|
231 |
QDesignerFormWindowInterface *fw = formWindow();
|
|
232 |
QAction *theSender = qobject_cast<QAction*>(sender());
|
|
233 |
QAction *previous = qvariant_cast<QAction *>(theSender->data());
|
|
234 |
fw->beginCommand(tr("Insert Separator"));
|
|
235 |
QAction *action = createAction(fw, QLatin1String("separator"), true);
|
|
236 |
InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw);
|
|
237 |
cmd->init(m_toolBar, action, previous);
|
|
238 |
fw->commandHistory()->push(cmd);
|
|
239 |
fw->endCommand();
|
|
240 |
}
|
|
241 |
|
|
242 |
QDesignerFormWindowInterface *ToolBarEventFilter::formWindow() const
|
|
243 |
{
|
|
244 |
return QDesignerFormWindowInterface::findFormWindow(m_toolBar);
|
|
245 |
}
|
|
246 |
|
|
247 |
QAction *ToolBarEventFilter::createAction(QDesignerFormWindowInterface *fw, const QString &objectName, bool separator)
|
|
248 |
{
|
|
249 |
QAction *action = new QAction(fw);
|
|
250 |
fw->core()->widgetFactory()->initialize(action);
|
|
251 |
if (separator)
|
|
252 |
action->setSeparator(true);
|
|
253 |
|
|
254 |
action->setObjectName(objectName);
|
|
255 |
fw->ensureUniqueObjectName(action);
|
|
256 |
|
|
257 |
qdesigner_internal::AddActionCommand *cmd = new qdesigner_internal::AddActionCommand(fw);
|
|
258 |
cmd->init(action);
|
|
259 |
fw->commandHistory()->push(cmd);
|
|
260 |
|
|
261 |
return action;
|
|
262 |
}
|
|
263 |
|
|
264 |
void ToolBarEventFilter::adjustDragIndicator(const QPoint &pos)
|
|
265 |
{
|
|
266 |
if (QDesignerFormWindowInterface *fw = formWindow()) {
|
|
267 |
QDesignerFormEditorInterface *core = fw->core();
|
|
268 |
if (QDesignerActionProviderExtension *a = qt_extension<QDesignerActionProviderExtension*>(core->extensionManager(), m_toolBar))
|
|
269 |
a->adjustIndicator(pos);
|
|
270 |
}
|
|
271 |
}
|
|
272 |
|
|
273 |
void ToolBarEventFilter::hideDragIndicator()
|
|
274 |
{
|
|
275 |
adjustDragIndicator(QPoint(-1, -1));
|
|
276 |
}
|
|
277 |
|
|
278 |
bool ToolBarEventFilter::handleMousePressEvent(QMouseEvent *event)
|
|
279 |
{
|
|
280 |
if (event->button() != Qt::LeftButton || withinHandleArea(m_toolBar, event->pos()))
|
|
281 |
return false;
|
|
282 |
|
|
283 |
if (QDesignerFormWindowInterface *fw = formWindow()) {
|
|
284 |
QDesignerFormEditorInterface *core = fw->core();
|
|
285 |
// Keep selection in sync
|
|
286 |
fw->clearSelection(false);
|
|
287 |
if (QDesignerObjectInspector *oi = qobject_cast<QDesignerObjectInspector *>(core->objectInspector())) {
|
|
288 |
oi->clearSelection();
|
|
289 |
oi->selectObject(m_toolBar);
|
|
290 |
}
|
|
291 |
core->propertyEditor()->setObject(m_toolBar);
|
|
292 |
}
|
|
293 |
m_startPosition = m_toolBar->mapFromGlobal(event->globalPos());
|
|
294 |
event->accept();
|
|
295 |
return true;
|
|
296 |
}
|
|
297 |
|
|
298 |
bool ToolBarEventFilter::handleMouseReleaseEvent(QMouseEvent *event)
|
|
299 |
{
|
|
300 |
if (event->button() != Qt::LeftButton || m_startPosition.isNull() || withinHandleArea(m_toolBar, event->pos()))
|
|
301 |
return false;
|
|
302 |
|
|
303 |
// Accept the event, otherwise, form window selection will trigger
|
|
304 |
m_startPosition = QPoint();
|
|
305 |
event->accept();
|
|
306 |
return true;
|
|
307 |
}
|
|
308 |
|
|
309 |
bool ToolBarEventFilter::handleMouseMoveEvent(QMouseEvent *event)
|
|
310 |
{
|
|
311 |
if (m_startPosition.isNull() || withinHandleArea(m_toolBar, event->pos()))
|
|
312 |
return false;
|
|
313 |
|
|
314 |
const QPoint pos = m_toolBar->mapFromGlobal(event->globalPos());
|
|
315 |
if ((pos - m_startPosition).manhattanLength() > qApp->startDragDistance()) {
|
|
316 |
startDrag(m_startPosition, event->modifiers());
|
|
317 |
m_startPosition = QPoint();
|
|
318 |
event->accept();
|
|
319 |
return true;
|
|
320 |
}
|
|
321 |
return false;
|
|
322 |
}
|
|
323 |
|
|
324 |
bool ToolBarEventFilter::handleDragEnterMoveEvent(QDragMoveEvent *event)
|
|
325 |
{
|
|
326 |
const ActionRepositoryMimeData *d = qobject_cast<const ActionRepositoryMimeData*>(event->mimeData());
|
|
327 |
if (!d)
|
|
328 |
return false;
|
|
329 |
|
|
330 |
if (d->actionList().isEmpty()) {
|
|
331 |
event->ignore();
|
|
332 |
hideDragIndicator();
|
|
333 |
return true;
|
|
334 |
}
|
|
335 |
|
|
336 |
QAction *action = d->actionList().first();
|
|
337 |
if (!action || action->menu() || m_toolBar->actions().contains(action) || !Utils::isObjectAncestorOf(formWindow()->mainContainer(), action)) {
|
|
338 |
event->ignore();
|
|
339 |
hideDragIndicator();
|
|
340 |
return true;
|
|
341 |
}
|
|
342 |
|
|
343 |
d->accept(event);
|
|
344 |
adjustDragIndicator(event->pos());
|
|
345 |
return true;
|
|
346 |
}
|
|
347 |
|
|
348 |
bool ToolBarEventFilter::handleDragLeaveEvent(QDragLeaveEvent *)
|
|
349 |
{
|
|
350 |
hideDragIndicator();
|
|
351 |
return false;
|
|
352 |
}
|
|
353 |
|
|
354 |
bool ToolBarEventFilter::handleDropEvent(QDropEvent *event)
|
|
355 |
{
|
|
356 |
const ActionRepositoryMimeData *d = qobject_cast<const ActionRepositoryMimeData*>(event->mimeData());
|
|
357 |
if (!d)
|
|
358 |
return false;
|
|
359 |
|
|
360 |
if (d->actionList().isEmpty()) {
|
|
361 |
event->ignore();
|
|
362 |
hideDragIndicator();
|
|
363 |
return true;
|
|
364 |
}
|
|
365 |
|
|
366 |
QAction *action = d->actionList().first();
|
|
367 |
|
|
368 |
const ActionList actions = m_toolBar->actions();
|
|
369 |
if (!action || actions.contains(action)) {
|
|
370 |
event->ignore();
|
|
371 |
hideDragIndicator();
|
|
372 |
return true;
|
|
373 |
}
|
|
374 |
|
|
375 |
// Try to find action to 'insert before'. Click on action or in free area, else ignore.
|
|
376 |
QAction *beforeAction = 0;
|
|
377 |
const QPoint pos = event->pos();
|
|
378 |
const int index = actionIndexAt(m_toolBar, pos, m_toolBar->orientation());
|
|
379 |
if (index != -1) {
|
|
380 |
beforeAction = actions.at(index);
|
|
381 |
} else {
|
|
382 |
if (!freeArea(m_toolBar).contains(pos)) {
|
|
383 |
event->ignore();
|
|
384 |
hideDragIndicator();
|
|
385 |
return true;
|
|
386 |
}
|
|
387 |
}
|
|
388 |
|
|
389 |
event->acceptProposedAction();
|
|
390 |
QDesignerFormWindowInterface *fw = formWindow();
|
|
391 |
InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw);
|
|
392 |
cmd->init(m_toolBar, action, beforeAction);
|
|
393 |
fw->commandHistory()->push(cmd);
|
|
394 |
hideDragIndicator();
|
|
395 |
return true;
|
|
396 |
}
|
|
397 |
|
|
398 |
void ToolBarEventFilter::startDrag(const QPoint &pos, Qt::KeyboardModifiers modifiers)
|
|
399 |
{
|
|
400 |
const int index = actionIndexAt(m_toolBar, pos, m_toolBar->orientation());
|
|
401 |
if (index == - 1)
|
|
402 |
return;
|
|
403 |
|
|
404 |
const ActionList actions = m_toolBar->actions();
|
|
405 |
QAction *action = actions.at(index);
|
|
406 |
QDesignerFormWindowInterface *fw = formWindow();
|
|
407 |
|
|
408 |
const Qt::DropAction dropAction = (modifiers & Qt::ControlModifier) ? Qt::CopyAction : Qt::MoveAction;
|
|
409 |
if (dropAction == Qt::MoveAction) {
|
|
410 |
RemoveActionFromCommand *cmd = new RemoveActionFromCommand(fw);
|
|
411 |
const int nextIndex = index + 1;
|
|
412 |
QAction *nextAction = nextIndex < actions.size() ? actions.at(nextIndex) : 0;
|
|
413 |
cmd->init(m_toolBar, action, nextAction);
|
|
414 |
fw->commandHistory()->push(cmd);
|
|
415 |
}
|
|
416 |
|
|
417 |
QDrag *drag = new QDrag(m_toolBar);
|
|
418 |
drag->setPixmap(ActionRepositoryMimeData::actionDragPixmap( action));
|
|
419 |
drag->setMimeData(new ActionRepositoryMimeData(action, dropAction));
|
|
420 |
|
|
421 |
if (drag->start(dropAction) == Qt::IgnoreAction) {
|
|
422 |
hideDragIndicator();
|
|
423 |
if (dropAction == Qt::MoveAction) {
|
|
424 |
const ActionList currentActions = m_toolBar->actions();
|
|
425 |
QAction *previous = 0;
|
|
426 |
if (index >= 0 && index < currentActions.size())
|
|
427 |
previous = currentActions.at(index);
|
|
428 |
InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw);
|
|
429 |
cmd->init(m_toolBar, action, previous);
|
|
430 |
fw->commandHistory()->push(cmd);
|
|
431 |
}
|
|
432 |
}
|
|
433 |
}
|
|
434 |
|
|
435 |
QAction *ToolBarEventFilter::actionAt(const QToolBar *tb, const QPoint &pos)
|
|
436 |
{
|
|
437 |
const int index = actionIndexAt(tb, pos, tb->orientation());
|
|
438 |
if (index == -1)
|
|
439 |
return 0;
|
|
440 |
return tb->actions().at(index);
|
|
441 |
}
|
|
442 |
|
|
443 |
//that's a trick to get acces to the initStyleOption which is a protected member
|
|
444 |
class FriendlyToolBar : public QToolBar {
|
|
445 |
public:
|
|
446 |
friend class ToolBarEventFilter;
|
|
447 |
};
|
|
448 |
|
|
449 |
QRect ToolBarEventFilter::handleArea(const QToolBar *tb)
|
|
450 |
{
|
|
451 |
QStyleOptionToolBar opt;
|
|
452 |
static_cast<const FriendlyToolBar*>(tb)->initStyleOption(&opt);
|
|
453 |
return tb->style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, tb);
|
|
454 |
}
|
|
455 |
|
|
456 |
bool ToolBarEventFilter::withinHandleArea(const QToolBar *tb, const QPoint &pos)
|
|
457 |
{
|
|
458 |
return handleArea(tb).contains(pos);
|
|
459 |
}
|
|
460 |
|
|
461 |
// Determine the free area behind the last action.
|
|
462 |
QRect ToolBarEventFilter::freeArea(const QToolBar *tb)
|
|
463 |
{
|
|
464 |
QRect rc = QRect(QPoint(0, 0), tb->size());
|
|
465 |
const ActionList actionList = tb->actions();
|
|
466 |
QRect exclusionRectangle = actionList.empty() ? handleArea(tb) : tb->actionGeometry(actionList.back());
|
|
467 |
switch (tb->orientation()) {
|
|
468 |
case Qt::Horizontal:
|
|
469 |
switch (tb->layoutDirection()) {
|
|
470 |
case Qt::LeftToRight:
|
|
471 |
rc.setX(exclusionRectangle.right() + 1);
|
|
472 |
break;
|
|
473 |
case Qt::RightToLeft:
|
|
474 |
rc.setRight(exclusionRectangle.x());
|
|
475 |
break;
|
|
476 |
}
|
|
477 |
break;
|
|
478 |
case Qt::Vertical:
|
|
479 |
rc.setY(exclusionRectangle.bottom() + 1);
|
|
480 |
break;
|
|
481 |
}
|
|
482 |
return rc;
|
|
483 |
}
|
|
484 |
|
|
485 |
}
|
|
486 |
|
|
487 |
QT_END_NAMESPACE
|