|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Designer of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
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 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "newdynamicpropertydialog.h" |
|
43 #include "ui_newdynamicpropertydialog.h" |
|
44 #include <abstractdialoggui_p.h> |
|
45 #include <qdesigner_propertysheet_p.h> |
|
46 |
|
47 #include <QtGui/QPushButton> |
|
48 |
|
49 QT_BEGIN_NAMESPACE |
|
50 |
|
51 namespace qdesigner_internal { |
|
52 |
|
53 NewDynamicPropertyDialog::NewDynamicPropertyDialog(QDesignerDialogGuiInterface *dialogGui, |
|
54 QWidget *parent) : |
|
55 QDialog(parent), |
|
56 m_dialogGui(dialogGui), |
|
57 m_ui(new Ui::NewDynamicPropertyDialog) |
|
58 { |
|
59 m_ui->setupUi(this); |
|
60 connect(m_ui->m_lineEdit, SIGNAL(textChanged(QString)), this, SLOT(nameChanged(QString))); |
|
61 |
|
62 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); |
|
63 |
|
64 m_ui->m_comboBox->addItem(QLatin1String("String"), QVariant(QVariant::String)); |
|
65 m_ui->m_comboBox->addItem(QLatin1String("StringList"), QVariant(QVariant::StringList)); |
|
66 m_ui->m_comboBox->addItem(QLatin1String("Char"), QVariant(QVariant::Char)); |
|
67 m_ui->m_comboBox->addItem(QLatin1String("ByteArray"), QVariant(QVariant::ByteArray)); |
|
68 m_ui->m_comboBox->addItem(QLatin1String("Url"), QVariant(QVariant::Url)); |
|
69 m_ui->m_comboBox->addItem(QLatin1String("Bool"), QVariant(QVariant::Bool)); |
|
70 m_ui->m_comboBox->addItem(QLatin1String("Int"), QVariant(QVariant::Int)); |
|
71 m_ui->m_comboBox->addItem(QLatin1String("UInt"), QVariant(QVariant::UInt)); |
|
72 m_ui->m_comboBox->addItem(QLatin1String("LongLong"), QVariant(QVariant::LongLong)); |
|
73 m_ui->m_comboBox->addItem(QLatin1String("ULongLong"), QVariant(QVariant::ULongLong)); |
|
74 m_ui->m_comboBox->addItem(QLatin1String("Double"), QVariant(QVariant::Double)); |
|
75 m_ui->m_comboBox->addItem(QLatin1String("Size"), QVariant(QVariant::Size)); |
|
76 m_ui->m_comboBox->addItem(QLatin1String("SizeF"), QVariant(QVariant::SizeF)); |
|
77 m_ui->m_comboBox->addItem(QLatin1String("Point"), QVariant(QVariant::Point)); |
|
78 m_ui->m_comboBox->addItem(QLatin1String("PointF"), QVariant(QVariant::PointF)); |
|
79 m_ui->m_comboBox->addItem(QLatin1String("Rect"), QVariant(QVariant::Rect)); |
|
80 m_ui->m_comboBox->addItem(QLatin1String("RectF"), QVariant(QVariant::RectF)); |
|
81 m_ui->m_comboBox->addItem(QLatin1String("Date"), QVariant(QVariant::Date)); |
|
82 m_ui->m_comboBox->addItem(QLatin1String("Time"), QVariant(QVariant::Time)); |
|
83 m_ui->m_comboBox->addItem(QLatin1String("DateTime"), QVariant(QVariant::DateTime)); |
|
84 m_ui->m_comboBox->addItem(QLatin1String("Font"), QVariant(QVariant::Font)); |
|
85 m_ui->m_comboBox->addItem(QLatin1String("Palette"), QVariant(QVariant::Palette)); |
|
86 m_ui->m_comboBox->addItem(QLatin1String("Color"), QVariant(QVariant::Color)); |
|
87 m_ui->m_comboBox->addItem(QLatin1String("Pixmap"), QVariant(QVariant::Pixmap)); |
|
88 m_ui->m_comboBox->addItem(QLatin1String("Icon"), QVariant(QVariant::Icon)); |
|
89 m_ui->m_comboBox->addItem(QLatin1String("Cursor"), QVariant(QVariant::Cursor)); |
|
90 m_ui->m_comboBox->addItem(QLatin1String("SizePolicy"), QVariant(QVariant::SizePolicy)); |
|
91 m_ui->m_comboBox->addItem(QLatin1String("KeySequence"), QVariant(QVariant::KeySequence)); |
|
92 |
|
93 m_ui->m_comboBox->setCurrentIndex(0); // String |
|
94 setOkButtonEnabled(false); |
|
95 } |
|
96 |
|
97 void NewDynamicPropertyDialog::setOkButtonEnabled(bool e) |
|
98 { |
|
99 m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(e); |
|
100 } |
|
101 |
|
102 NewDynamicPropertyDialog::~NewDynamicPropertyDialog() |
|
103 { |
|
104 delete m_ui; |
|
105 } |
|
106 |
|
107 void NewDynamicPropertyDialog::setReservedNames(const QStringList &names) |
|
108 { |
|
109 m_reservedNames = names; |
|
110 } |
|
111 |
|
112 void NewDynamicPropertyDialog::setPropertyType(QVariant::Type t) |
|
113 { |
|
114 const int index = m_ui->m_comboBox->findData(QVariant(t)); |
|
115 if (index != -1) |
|
116 m_ui->m_comboBox->setCurrentIndex(index); |
|
117 } |
|
118 |
|
119 QString NewDynamicPropertyDialog::propertyName() const |
|
120 { |
|
121 return m_ui->m_lineEdit->text(); |
|
122 } |
|
123 |
|
124 QVariant NewDynamicPropertyDialog::propertyValue() const |
|
125 { |
|
126 const int index = m_ui->m_comboBox->currentIndex(); |
|
127 if (index == -1) |
|
128 return QVariant(); |
|
129 return m_ui->m_comboBox->itemData(index); |
|
130 } |
|
131 |
|
132 void NewDynamicPropertyDialog::information(const QString &message) |
|
133 { |
|
134 m_dialogGui->message(this, QDesignerDialogGuiInterface::PropertyEditorMessage, QMessageBox::Information, tr("Set Property Name"), message); |
|
135 } |
|
136 |
|
137 void NewDynamicPropertyDialog::nameChanged(const QString &s) |
|
138 { |
|
139 setOkButtonEnabled(!s.isEmpty()); |
|
140 } |
|
141 |
|
142 bool NewDynamicPropertyDialog::validatePropertyName(const QString& name) |
|
143 { |
|
144 if (m_reservedNames.contains(name)) { |
|
145 information(tr("The current object already has a property named '%1'.\nPlease select another, unique one.").arg(name)); |
|
146 return false; |
|
147 } |
|
148 if (!QDesignerPropertySheet::internalDynamicPropertiesEnabled() && name.startsWith(QLatin1String("_q_"))) { |
|
149 information(tr("The '_q_' prefix is reserved for the Qt library.\nPlease select another name.")); |
|
150 return false; |
|
151 } |
|
152 return true; |
|
153 } |
|
154 |
|
155 void NewDynamicPropertyDialog::on_m_buttonBox_clicked(QAbstractButton *btn) |
|
156 { |
|
157 const int role = m_ui->m_buttonBox->buttonRole(btn); |
|
158 switch (role) { |
|
159 case QDialogButtonBox::RejectRole: |
|
160 reject(); |
|
161 break; |
|
162 case QDialogButtonBox::AcceptRole: |
|
163 if (validatePropertyName(propertyName())) |
|
164 accept(); |
|
165 break; |
|
166 } |
|
167 } |
|
168 } |
|
169 |
|
170 QT_END_NAMESPACE |