1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
34 #include "qdeclarative.h"
35 #include "resetwidget.h"
36 #include <QVBoxLayout>
37 #include <QHBoxLayout>
38 #include <QStringList>
39 #include <QTableWidget>
40 #include <QHeaderView>
41 #include <QPushButton>
44 #include <QApplication>
46 QML_DECLARE_TYPE(QmlDesigner::ResetWidget)
48 namespace QmlDesigner {
51 ResetWidget::ResetWidget(QWidget *parent) : QGroupBox(parent), m_backendObject(0)
53 m_vlayout = new QVBoxLayout(this);
54 m_vlayout->setContentsMargins(2,2,2,2);
56 QPushButton *b = new QPushButton(this);
57 b->setText("reset all properties");
58 m_vlayout->addWidget(b);
63 void ResetWidget::registerDeclarativeType()
65 qmlRegisterType<QmlDesigner::ResetWidget>("Bauhaus", 1, 0, "ResetWidget");
68 void ResetWidget::resetView()
70 m_tableWidget->clear();
75 void ResetWidget::setupView()
77 m_tableWidget = new QTableWidget(this);
78 m_vlayout->addWidget(m_tableWidget);
80 m_tableWidget->setAlternatingRowColors(true);
81 m_tableWidget->horizontalHeader()->hide();
82 m_tableWidget->verticalHeader()->hide();
83 m_tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
84 m_tableWidget->setShowGrid(false);
85 m_tableWidget->setSortingEnabled(true);
86 m_tableWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
88 const QMetaObject *metaObject = m_backendObject->metaObject();
89 int count = metaObject->propertyCount();
91 m_tableWidget->setColumnCount(3);
92 m_tableWidget->setRowCount(count);
93 for (int i=0;i<count;i++) {
94 QMetaProperty metaProperty = metaObject->property(i);
95 addPropertyItem(metaProperty.name(), i);
97 m_tableWidget->resizeRowsToContents();
98 m_tableWidget->resizeColumnsToContents();
99 m_tableWidget->sortItems(0);
100 m_tableWidget->setColumnWidth(2, 40);
101 parentWidget()->resize(parentWidget()->width(), count * 28);
102 qApp->processEvents();
106 void ResetWidget::addPropertyItem(const QString &name, int row)
108 QTableWidgetItem *newItem = new QTableWidgetItem(name);
109 m_tableWidget->setItem(row, 0, newItem);
110 ResetWidgetPushButton *b = new ResetWidgetPushButton(m_tableWidget);
113 connect(b, SIGNAL(pressed(const QString &)), this, SLOT(buttonPressed(const QString &)));
114 b->setMaximumHeight(15);
115 b->setMinimumHeight(10);
116 m_tableWidget->setCellWidget(row, 2, b);
119 void ResetWidget::buttonPressed(const QString &)
123 ResetWidgetPushButton::ResetWidgetPushButton(QWidget *parent) : QPushButton(parent)
125 connect(this, SIGNAL(pressed()), this, SLOT(myPressed()));
128 void ResetWidgetPushButton::myPressed()
130 emit pressed(m_name);