OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / components / propertyeditor / resetwidget.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33
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>
42
43 #include <QDebug>
44 #include <QApplication>
45
46 QML_DECLARE_TYPE(QmlDesigner::ResetWidget)
47
48 namespace QmlDesigner {
49
50
51 ResetWidget::ResetWidget(QWidget *parent) : QGroupBox(parent), m_backendObject(0)
52 {
53     m_vlayout = new QVBoxLayout(this);
54     m_vlayout->setContentsMargins(2,2,2,2);
55
56     QPushButton *b = new QPushButton(this);
57     b->setText("reset all properties");
58     m_vlayout->addWidget(b);
59
60     setLayout(m_vlayout);
61 }
62
63 void ResetWidget::registerDeclarativeType()
64 {
65     qmlRegisterType<QmlDesigner::ResetWidget>("Bauhaus", 1, 0, "ResetWidget");
66 }
67
68 void ResetWidget::resetView()
69 {
70     m_tableWidget->clear();
71     delete m_tableWidget;
72     setupView();
73 }
74
75 void ResetWidget::setupView()
76 {
77     m_tableWidget = new QTableWidget(this);
78     m_vlayout->addWidget(m_tableWidget);
79
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);
87
88     const QMetaObject *metaObject = m_backendObject->metaObject();
89     int count = metaObject->propertyCount();
90
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);
96     }
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();
103
104 }
105
106 void ResetWidget::addPropertyItem(const QString &name, int row)
107 {
108     QTableWidgetItem *newItem = new QTableWidgetItem(name);
109     m_tableWidget->setItem(row, 0, newItem);
110     ResetWidgetPushButton *b = new  ResetWidgetPushButton(m_tableWidget);
111     b->setName(name);
112     b->setText("reset");
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);
117 }
118
119 void ResetWidget::buttonPressed(const QString &)
120 {
121 }
122
123 ResetWidgetPushButton::ResetWidgetPushButton(QWidget *parent) : QPushButton(parent)
124 {
125     connect(this, SIGNAL(pressed()), this, SLOT(myPressed()));
126 }
127
128 void ResetWidgetPushButton::myPressed()
129 {
130     emit pressed(m_name);
131 }
132
133
134 }
135