1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the designer application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "tool_widgeteditor.h"
30
#include "formwindow.h"
33
#include <QtDesigner/QtDesigner>
34
#include <layoutinfo_p.h>
36
#include <QtGui/qevent.h>
37
#include <QtGui/QAction>
38
#include <QtCore/qdebug.h>
40
using namespace qdesigner_internal;
42
WidgetEditorTool::WidgetEditorTool(FormWindow *formWindow)
43
: QDesignerFormWindowToolInterface(formWindow),
44
m_formWindow(formWindow)
46
m_action = new QAction(tr("Edit Widgets"), this);
49
QAction *WidgetEditorTool::action() const
54
WidgetEditorTool::~WidgetEditorTool()
58
QDesignerFormEditorInterface *WidgetEditorTool::core() const
60
return m_formWindow->core();
63
QDesignerFormWindowInterface *WidgetEditorTool::formWindow() const
68
bool WidgetEditorTool::handleEvent(QWidget *widget, QWidget *managedWidget, QEvent *event)
70
switch (event->type()) {
75
if (LayoutInfo::isWidgetLaidout(core(), managedWidget)) {
76
m_formWindow->updateSelection(widget);
77
if (event->type() != QEvent::Resize)
78
m_formWindow->updateChildSelections(widget);
83
case QEvent::FocusOut:
85
if (widget == m_formWindow)
89
case QEvent::KeyPress:
90
if (core()->widgetFactory()->isPassiveInteractor(widget)) {
93
return handleKeyPressEvent(widget, managedWidget, static_cast<QKeyEvent*>(event));
95
case QEvent::KeyRelease:
96
if (core()->widgetFactory()->isPassiveInteractor(widget)) {
99
return handleKeyReleaseEvent(widget, managedWidget, static_cast<QKeyEvent*>(event));
101
case QEvent::MouseMove:
102
if (core()->widgetFactory()->isPassiveInteractor(widget)) {
105
return handleMouseMoveEvent(widget, managedWidget, static_cast<QMouseEvent*>(event));
107
case QEvent::MouseButtonPress:
108
if (core()->widgetFactory()->isPassiveInteractor(widget)) {
111
return handleMousePressEvent(widget, managedWidget, static_cast<QMouseEvent*>(event));
113
case QEvent::MouseButtonRelease:
114
if (core()->widgetFactory()->isPassiveInteractor(widget)) {
117
return handleMouseReleaseEvent(widget, managedWidget, static_cast<QMouseEvent*>(event));
119
case QEvent::MouseButtonDblClick:
120
if (core()->widgetFactory()->isPassiveInteractor(widget)) {
123
return handleMouseButtonDblClickEvent(widget, managedWidget, static_cast<QMouseEvent*>(event));
125
case QEvent::ContextMenu:
126
if (core()->widgetFactory()->isPassiveInteractor(widget)) {
129
return handleContextMenu(widget, managedWidget, static_cast<QContextMenuEvent*>(event));
140
bool WidgetEditorTool::handleContextMenu(QWidget *widget, QWidget *managedWidget, QContextMenuEvent *e)
142
return m_formWindow->handleContextMenu(widget, managedWidget, e);
145
bool WidgetEditorTool::handleMouseButtonDblClickEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e)
147
return m_formWindow->handleMouseButtonDblClickEvent(widget, managedWidget, e);
150
bool WidgetEditorTool::handleMousePressEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e)
152
return m_formWindow->handleMousePressEvent(widget, managedWidget, e);
155
bool WidgetEditorTool::handleMouseMoveEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e)
157
return m_formWindow->handleMouseMoveEvent(widget, managedWidget, e);
160
bool WidgetEditorTool::handleMouseReleaseEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e)
162
return m_formWindow->handleMouseReleaseEvent(widget, managedWidget, e);
165
bool WidgetEditorTool::handleKeyPressEvent(QWidget *widget, QWidget *managedWidget, QKeyEvent *e)
167
return m_formWindow->handleKeyPressEvent(widget, managedWidget, e);
170
bool WidgetEditorTool::handleKeyReleaseEvent(QWidget *widget, QWidget *managedWidget, QKeyEvent *e)
172
return m_formWindow->handleKeyReleaseEvent(widget, managedWidget, e);
175
bool WidgetEditorTool::handlePaintEvent(QWidget *widget, QWidget *managedWidget, QPaintEvent *e)
178
Q_UNUSED(managedWidget);
184
QWidget *WidgetEditorTool::editor() const
186
Q_ASSERT(formWindow() != 0);
187
return formWindow()->mainContainer();
190
void WidgetEditorTool::activated()
192
if (core()->widgetBox())
193
core()->widgetBox()->setEnabled(true);
195
if (m_formWindow == 0)
198
QList<QWidget*> sel = m_formWindow->selectedWidgets();
199
foreach (QWidget *w, sel)
200
m_formWindow->raiseSelection(w);
203
void WidgetEditorTool::deactivated()
205
if (core()->widgetBox())
206
core()->widgetBox()->setEnabled(false);
208
if (m_formWindow == 0)
211
m_formWindow->clearSelection();