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

« back to all changes in this revision

Viewing changes to tools/designer/src/lib/shared/qdesigner_promotedwidget.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) 2005-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 "qdesigner_promotedwidget_p.h"
 
30
 
 
31
#include <QtDesigner/QExtensionManager>
 
32
 
 
33
#include <QtGui/QVBoxLayout>
 
34
#include <QtCore/QEvent>
 
35
#include <QtCore/QVariant>
 
36
#include <QtCore/qdebug.h>
 
37
 
 
38
PromotedWidgetPropertySheet::PromotedWidgetPropertySheet(QDesignerPromotedWidget *promoted,
 
39
                                QExtensionManager *extension_manager, QObject *parent)
 
40
    : QObject(parent)
 
41
{
 
42
    m_promoted = promoted;
 
43
    QWidget *child = promoted->child();
 
44
    m_sheet = qt_extension<QDesignerPropertySheetExtension*>(extension_manager, child);
 
45
}
 
46
 
 
47
PromotedWidgetPropertySheet::~PromotedWidgetPropertySheet()
 
48
{
 
49
}
 
50
 
 
51
int PromotedWidgetPropertySheet::count() const
 
52
{
 
53
    return m_sheet->count();
 
54
}
 
55
 
 
56
int PromotedWidgetPropertySheet::indexOf(const QString &name) const
 
57
{
 
58
    return m_sheet->indexOf(name);
 
59
}
 
60
 
 
61
QString PromotedWidgetPropertySheet::propertyName(int index) const
 
62
{
 
63
    return m_sheet->propertyName(index);
 
64
}
 
65
 
 
66
QString PromotedWidgetPropertySheet::propertyGroup(int index) const
 
67
{
 
68
    return m_sheet->propertyGroup(index);
 
69
}
 
70
 
 
71
void PromotedWidgetPropertySheet::setPropertyGroup(int index, const QString &group)
 
72
{
 
73
    m_sheet->setPropertyGroup(index, group);
 
74
}
 
75
 
 
76
bool PromotedWidgetPropertySheet::hasReset(int index) const
 
77
{
 
78
    return m_sheet->hasReset(index);
 
79
}
 
80
 
 
81
bool PromotedWidgetPropertySheet::reset(int index)
 
82
{
 
83
    return m_sheet->reset(index);
 
84
}
 
85
 
 
86
bool PromotedWidgetPropertySheet::isVisible(int index) const
 
87
{
 
88
    return m_sheet->isVisible(index);
 
89
}
 
90
 
 
91
void PromotedWidgetPropertySheet::setVisible(int index, bool b)
 
92
{
 
93
    m_sheet->setVisible(index, b);
 
94
}
 
95
 
 
96
bool PromotedWidgetPropertySheet::isAttribute(int index) const
 
97
{
 
98
    return m_sheet->isAttribute(index);
 
99
}
 
100
 
 
101
void PromotedWidgetPropertySheet::setAttribute(int index, bool b)
 
102
{
 
103
    m_sheet->setAttribute(index, b);
 
104
}
 
105
 
 
106
QVariant PromotedWidgetPropertySheet::property(int index) const
 
107
{
 
108
    QVariant result;
 
109
 
 
110
    QString name = propertyName(index);
 
111
    if (name == QLatin1String("geometry")) {
 
112
        result = m_promoted->geometry();
 
113
    } else {
 
114
        result = m_sheet->property(index);
 
115
    }
 
116
 
 
117
    return result;
 
118
}
 
119
 
 
120
void PromotedWidgetPropertySheet::setProperty(int index, const QVariant &value)
 
121
{
 
122
    QString name = propertyName(index);
 
123
    if (name == QLatin1String("geometry")) {
 
124
        if (value.type() == QVariant::Rect)
 
125
            m_promoted->setGeometry(value.toRect());
 
126
    } else {
 
127
        m_sheet->setProperty(index, value);
 
128
    }
 
129
}
 
130
 
 
131
bool PromotedWidgetPropertySheet::isChanged(int index) const
 
132
{
 
133
    return m_sheet->isChanged(index);
 
134
}
 
135
 
 
136
void PromotedWidgetPropertySheet::setChanged(int index, bool changed)
 
137
{
 
138
    m_sheet->setChanged(index, changed);
 
139
}
 
140
 
 
141
PromotedWidgetPropertySheetFactory::PromotedWidgetPropertySheetFactory(QExtensionManager *parent)
 
142
    : QExtensionFactory(parent)
 
143
{
 
144
}
 
145
 
 
146
QObject *PromotedWidgetPropertySheetFactory::createExtension(QObject *object,
 
147
                                            const QString &iid, QObject *parent) const
 
148
{
 
149
    if (iid != Q_TYPEID(QDesignerPropertySheetExtension))
 
150
        return 0;
 
151
    QDesignerPromotedWidget *promoted = qobject_cast<QDesignerPromotedWidget*>(object);
 
152
    if (promoted == 0)
 
153
        return 0;
 
154
    return new PromotedWidgetPropertySheet(promoted,
 
155
                                qobject_cast<QExtensionManager*>(this->parent()),
 
156
                                parent);
 
157
}
 
158
 
 
159
QDesignerPromotedWidget::QDesignerPromotedWidget(QDesignerWidgetDataBaseItemInterface *item, QWidget *parent)
 
160
    : QWidget(parent), m_child(0)
 
161
{
 
162
    (new QVBoxLayout(this))->setMargin(0);
 
163
 
 
164
    m_item = item;
 
165
    m_custom_class_name = item->name().toUtf8();
 
166
}
 
167
 
 
168
QDesignerPromotedWidget::~QDesignerPromotedWidget()
 
169
{
 
170
}
 
171
 
 
172
void QDesignerPromotedWidget::setChildWidget(QWidget *widget)
 
173
{
 
174
    if (m_child != 0) {
 
175
        layout()->removeWidget(m_child);
 
176
        m_child->setSizePolicy(sizePolicy());
 
177
        m_child->setParent(0);
 
178
    }
 
179
 
 
180
    m_child = widget;
 
181
 
 
182
    if (m_child != 0) {
 
183
        m_child->setParent(this);
 
184
        setSizePolicy(m_child->sizePolicy());
 
185
        m_child->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
 
186
        layout()->addWidget(m_child);
 
187
    }
 
188
}
 
189
 
 
190
QSize QDesignerPromotedWidget::sizeHint() const
 
191
{
 
192
    if (m_child == 0)
 
193
        return QSize();
 
194
    return m_child->sizeHint();
 
195
}
 
196
 
 
197
QSize QDesignerPromotedWidget::minimumSizeHint() const
 
198
{
 
199
    if (m_child == 0)
 
200
        return QSize();
 
201
    return m_child->minimumSizeHint();
 
202
}
 
203