~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/designer/src/components/formeditor/tool_widgeteditor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the designer application of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "tool_widgeteditor.h"
 
30
#include "formwindow.h"
 
31
 
 
32
// sdk
 
33
#include <QtDesigner/QtDesigner>
 
34
#include <layoutinfo_p.h>
 
35
 
 
36
#include <QtGui/qevent.h>
 
37
#include <QtGui/QAction>
 
38
#include <QtCore/qdebug.h>
 
39
 
 
40
using namespace qdesigner_internal;
 
41
 
 
42
WidgetEditorTool::WidgetEditorTool(FormWindow *formWindow)
 
43
    : QDesignerFormWindowToolInterface(formWindow),
 
44
      m_formWindow(formWindow)
 
45
{
 
46
    m_action = new QAction(tr("Edit Widgets"), this);
 
47
}
 
48
 
 
49
QAction *WidgetEditorTool::action() const
 
50
{
 
51
    return m_action;
 
52
}
 
53
 
 
54
WidgetEditorTool::~WidgetEditorTool()
 
55
{
 
56
}
 
57
 
 
58
QDesignerFormEditorInterface *WidgetEditorTool::core() const
 
59
{
 
60
    return m_formWindow->core();
 
61
}
 
62
 
 
63
QDesignerFormWindowInterface *WidgetEditorTool::formWindow() const
 
64
{
 
65
    return m_formWindow;
 
66
}
 
67
 
 
68
bool WidgetEditorTool::handleEvent(QWidget *widget, QWidget *managedWidget, QEvent *event)
 
69
{
 
70
    switch (event->type()) {
 
71
 
 
72
#if 0 // ### check me
 
73
    case QEvent::Resize:
 
74
    case QEvent::Move: {
 
75
        if (LayoutInfo::isWidgetLaidout(core(), managedWidget)) {
 
76
            m_formWindow->updateSelection(widget);
 
77
            if (event->type() != QEvent::Resize)
 
78
                m_formWindow->updateChildSelections(widget);
 
79
        }
 
80
    } break;
 
81
#endif
 
82
 
 
83
    case QEvent::FocusOut:
 
84
    case QEvent::FocusIn:
 
85
        if (widget == m_formWindow)
 
86
            break;
 
87
        return true;
 
88
 
 
89
    case QEvent::KeyPress:
 
90
        if (core()->widgetFactory()->isPassiveInteractor(widget)) {
 
91
            return false;
 
92
        }
 
93
        return handleKeyPressEvent(widget, managedWidget, static_cast<QKeyEvent*>(event));
 
94
 
 
95
    case QEvent::KeyRelease:
 
96
        if (core()->widgetFactory()->isPassiveInteractor(widget)) {
 
97
            return false;
 
98
        }
 
99
        return handleKeyReleaseEvent(widget, managedWidget, static_cast<QKeyEvent*>(event));
 
100
 
 
101
    case QEvent::MouseMove:
 
102
        if (core()->widgetFactory()->isPassiveInteractor(widget)) {
 
103
            return false;
 
104
        }
 
105
        return handleMouseMoveEvent(widget, managedWidget, static_cast<QMouseEvent*>(event));
 
106
 
 
107
    case QEvent::MouseButtonPress:
 
108
        if (core()->widgetFactory()->isPassiveInteractor(widget)) {
 
109
            return false;
 
110
        }
 
111
        return handleMousePressEvent(widget, managedWidget, static_cast<QMouseEvent*>(event));
 
112
 
 
113
    case QEvent::MouseButtonRelease:
 
114
        if (core()->widgetFactory()->isPassiveInteractor(widget)) {
 
115
            return false;
 
116
        }
 
117
        return handleMouseReleaseEvent(widget, managedWidget, static_cast<QMouseEvent*>(event));
 
118
 
 
119
    case QEvent::MouseButtonDblClick:
 
120
        if (core()->widgetFactory()->isPassiveInteractor(widget)) {
 
121
            return false;
 
122
        }
 
123
        return handleMouseButtonDblClickEvent(widget, managedWidget, static_cast<QMouseEvent*>(event));
 
124
 
 
125
    case QEvent::ContextMenu:
 
126
        if (core()->widgetFactory()->isPassiveInteractor(widget)) {
 
127
            return false;
 
128
        }
 
129
        return handleContextMenu(widget, managedWidget, static_cast<QContextMenuEvent*>(event));
 
130
 
 
131
    default: break;
 
132
 
 
133
    } // end switch
 
134
 
 
135
    return false;
 
136
}
 
137
 
 
138
// ### remove me
 
139
 
 
140
bool WidgetEditorTool::handleContextMenu(QWidget *widget, QWidget *managedWidget, QContextMenuEvent *e)
 
141
{
 
142
    return m_formWindow->handleContextMenu(widget, managedWidget, e);
 
143
}
 
144
 
 
145
bool WidgetEditorTool::handleMouseButtonDblClickEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e)
 
146
{
 
147
    return m_formWindow->handleMouseButtonDblClickEvent(widget, managedWidget, e);
 
148
}
 
149
 
 
150
bool WidgetEditorTool::handleMousePressEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e)
 
151
{
 
152
    return m_formWindow->handleMousePressEvent(widget, managedWidget, e);
 
153
}
 
154
 
 
155
bool WidgetEditorTool::handleMouseMoveEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e)
 
156
{
 
157
    return m_formWindow->handleMouseMoveEvent(widget, managedWidget, e);
 
158
}
 
159
 
 
160
bool WidgetEditorTool::handleMouseReleaseEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e)
 
161
{
 
162
    return m_formWindow->handleMouseReleaseEvent(widget, managedWidget, e);
 
163
}
 
164
 
 
165
bool WidgetEditorTool::handleKeyPressEvent(QWidget *widget, QWidget *managedWidget, QKeyEvent *e)
 
166
{
 
167
    return m_formWindow->handleKeyPressEvent(widget, managedWidget, e);
 
168
}
 
169
 
 
170
bool WidgetEditorTool::handleKeyReleaseEvent(QWidget *widget, QWidget *managedWidget, QKeyEvent *e)
 
171
{
 
172
    return m_formWindow->handleKeyReleaseEvent(widget, managedWidget, e);
 
173
}
 
174
 
 
175
bool WidgetEditorTool::handlePaintEvent(QWidget *widget, QWidget *managedWidget, QPaintEvent *e)
 
176
{
 
177
    Q_UNUSED(widget);
 
178
    Q_UNUSED(managedWidget);
 
179
    Q_UNUSED(e);
 
180
 
 
181
    return false;
 
182
}
 
183
 
 
184
QWidget *WidgetEditorTool::editor() const
 
185
{
 
186
    Q_ASSERT(formWindow() != 0);
 
187
    return formWindow()->mainContainer();
 
188
}
 
189
 
 
190
void WidgetEditorTool::activated()
 
191
{
 
192
    if (core()->widgetBox())
 
193
        core()->widgetBox()->setEnabled(true);
 
194
 
 
195
    if (m_formWindow == 0)
 
196
        return;
 
197
 
 
198
    QList<QWidget*> sel = m_formWindow->selectedWidgets();
 
199
    foreach (QWidget *w, sel)
 
200
        m_formWindow->raiseSelection(w);
 
201
}
 
202
 
 
203
void WidgetEditorTool::deactivated()
 
204
{
 
205
    if (core()->widgetBox())
 
206
        core()->widgetBox()->setEnabled(false);
 
207
 
 
208
    if (m_formWindow == 0)
 
209
        return;
 
210
 
 
211
    m_formWindow->clearSelection();
 
212
}
 
213