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 <QtDesigner/QtDesigner>
30
#include "formwindow_widgetstack.h"
32
#include <QtGui/QWidget>
33
#include <QtGui/qevent.h>
34
#include <QtGui/QAction>
36
#include <QtCore/qdebug.h>
38
using namespace qdesigner_internal;
40
FormWindowWidgetStack::FormWindowWidgetStack(QWidget *parent)
46
FormWindowWidgetStack::~FormWindowWidgetStack()
50
int FormWindowWidgetStack::count() const
52
return m_tools.count();
55
QDesignerFormWindowToolInterface *FormWindowWidgetStack::currentTool() const
57
return tool(m_current_index);
60
void FormWindowWidgetStack::setCurrentTool(int index)
62
if (index < 0 || index >= count()) {
63
qWarning("FormWindowWidgetStack::setCurrentTool(): invalid index: %d", index);
67
if (index == m_current_index)
70
if (m_current_index != -1)
71
m_tools.at(m_current_index)->deactivated();
73
m_current_index = index;
75
QDesignerFormWindowToolInterface *tool = m_tools.at(m_current_index);
77
QWidget *w = tool->editor();
79
if (w->rect() != rect())
80
w->setGeometry(rect());
84
emit currentToolChanged(index);
87
void FormWindowWidgetStack::setSenderAsCurrentTool()
89
QDesignerFormWindowToolInterface *tool = 0;
90
QAction *action = qobject_cast<QAction*>(sender());
92
qWarning("FormWindowWidgetStack::setSenderAsCurrentTool(): sender is not a QAction");
96
foreach (QDesignerFormWindowToolInterface *t, m_tools) {
97
if (action == t->action()) {
104
qWarning("FormWindowWidgetStack::setSenderAsCurrentTool(): unknown tool");
108
setCurrentTool(tool);
111
int FormWindowWidgetStack::indexOf(QDesignerFormWindowToolInterface *tool) const
113
for (int i = 0; i < m_tools.size(); ++i) {
114
if (m_tools.at(i) == tool)
121
void FormWindowWidgetStack::setCurrentTool(QDesignerFormWindowToolInterface *tool)
123
int index = indexOf(tool);
125
qWarning("FormWindowWidgetStack::setCurrentTool(): unknown tool");
129
setCurrentTool(index);
132
void FormWindowWidgetStack::addTool(QDesignerFormWindowToolInterface *tool)
134
QWidget *w = tool->editor();
138
m_tools.append(tool);
140
connect(tool->action(), SIGNAL(triggered()), this, SLOT(setSenderAsCurrentTool()));
143
void FormWindowWidgetStack::resizeEvent(QResizeEvent *event)
145
QWidget::resizeEvent(event);
147
QRect r = QRect(0, 0, event->size().width(), event->size().height());
149
// We always resize the widget tool
150
QDesignerFormWindowToolInterface *widget_tool = tool(0);
151
if (widget_tool != 0 && widget_tool->editor() != 0)
152
widget_tool->editor()->setGeometry(r);
154
QDesignerFormWindowToolInterface *cur_tool = currentTool();
155
if (cur_tool == widget_tool)
158
if (cur_tool != 0 && cur_tool->editor() != 0)
159
cur_tool->editor()->setGeometry(r);
162
QDesignerFormWindowToolInterface *FormWindowWidgetStack::tool(int index) const
164
if (index < 0 || index >= count())
167
return m_tools.at(index);
170
int FormWindowWidgetStack::currentIndex() const
172
return m_current_index;