[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the tools applications of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 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 | **
|
---|
[561] | 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.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at qt-info@nokia.com.
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "changeproperties.h"
|
---|
| 43 |
|
---|
| 44 | #include <QtGui>
|
---|
| 45 | #include <qt_windows.h>
|
---|
| 46 | #include <ActiveQt/ActiveQt>
|
---|
| 47 |
|
---|
| 48 | QT_BEGIN_NAMESPACE
|
---|
| 49 |
|
---|
| 50 | ChangeProperties::ChangeProperties(QWidget *parent)
|
---|
| 51 | : QDialog(parent), activex(0)
|
---|
| 52 | {
|
---|
| 53 | setupUi(this);
|
---|
| 54 |
|
---|
| 55 | listProperties->setColumnCount(3);
|
---|
| 56 | listProperties->headerItem()->setText(0, QLatin1String("Name"));
|
---|
| 57 | listProperties->headerItem()->setText(1, QLatin1String("Type"));
|
---|
| 58 | listProperties->headerItem()->setText(2, QLatin1String("Value"));
|
---|
| 59 |
|
---|
| 60 | listEditRequests->setColumnCount(1);
|
---|
| 61 | listEditRequests->headerItem()->setText(0, QLatin1String("Name"));
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | void ChangeProperties::setControl(QAxWidget *ax)
|
---|
| 65 | {
|
---|
| 66 | activex = ax;
|
---|
| 67 | updateProperties();
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | void ChangeProperties::on_listProperties_currentItemChanged(QTreeWidgetItem *current)
|
---|
| 71 | {
|
---|
| 72 | editValue->setEnabled(current != 0);
|
---|
| 73 | buttonSet->setEnabled(current != 0);
|
---|
| 74 | valueLabel->setEnabled(current != 0);
|
---|
| 75 |
|
---|
| 76 | if (!current)
|
---|
| 77 | return;
|
---|
| 78 |
|
---|
| 79 | editValue->setText(current->text(2));
|
---|
| 80 | QString prop = current->text(0);
|
---|
| 81 | valueLabel->setText(prop + QLatin1String(" ="));
|
---|
| 82 |
|
---|
| 83 | const QMetaObject *mo = activex->metaObject();
|
---|
| 84 | const QMetaProperty property = mo->property(mo->indexOfProperty(prop.toLatin1()));
|
---|
| 85 |
|
---|
| 86 | valueLabel->setEnabled(property.isWritable());
|
---|
| 87 | editValue->setEnabled(property.isWritable());
|
---|
| 88 | buttonSet->setEnabled(property.isWritable());
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | void ChangeProperties::on_buttonSet_clicked()
|
---|
| 92 | {
|
---|
| 93 | QTreeWidgetItem *item = listProperties->currentItem();
|
---|
| 94 | if (!item)
|
---|
| 95 | return;
|
---|
| 96 |
|
---|
| 97 | QString prop = item->text(0);
|
---|
| 98 | QVariant value = activex->property(prop.toLatin1());
|
---|
| 99 | QVariant::Type type = value.type();
|
---|
| 100 | if (!value.isValid()) {
|
---|
| 101 | const QMetaObject *mo = activex->metaObject();
|
---|
| 102 | const QMetaProperty property = mo->property(mo->indexOfProperty(prop.toLatin1()));
|
---|
| 103 | type = QVariant::nameToType(property.typeName());
|
---|
| 104 | }
|
---|
| 105 | switch (type) {
|
---|
| 106 | case QVariant::Color:
|
---|
| 107 | {
|
---|
| 108 | QColor col;
|
---|
| 109 | col.setNamedColor(editValue->text());
|
---|
| 110 | if (col.isValid()) {
|
---|
| 111 | value = qVariantFromValue(col);
|
---|
| 112 | } else {
|
---|
| 113 | QMessageBox::warning(this, tr("Can't parse input"),
|
---|
[846] | 114 | tr("Failed to create a color from %1\n"
|
---|
[2] | 115 | "The string has to be a valid color name (e.g. 'red')\n"
|
---|
| 116 | "or a RGB triple of format '#rrggbb'."
|
---|
[846] | 117 | ).arg(editValue->text()));
|
---|
[2] | 118 | }
|
---|
| 119 | }
|
---|
| 120 | break;
|
---|
| 121 | case QVariant::Font:
|
---|
| 122 | {
|
---|
| 123 | QFont fnt;
|
---|
| 124 | if (fnt.fromString(editValue->text())) {
|
---|
| 125 | value = qVariantFromValue(fnt);
|
---|
| 126 | } else {
|
---|
| 127 | QMessageBox::warning(this, tr("Can't parse input"),
|
---|
[846] | 128 | tr("Failed to create a font from %1\n"
|
---|
[2] | 129 | "The string has to have a format family,<point size> or\n"
|
---|
| 130 | "family,pointsize,stylehint,weight,italic,underline,strikeout,fixedpitch,rawmode."
|
---|
[846] | 131 | ).arg(editValue->text()));
|
---|
[2] | 132 | }
|
---|
| 133 | }
|
---|
| 134 | break;
|
---|
| 135 | case QVariant::Pixmap:
|
---|
| 136 | {
|
---|
| 137 | QString fileName = editValue->text();
|
---|
| 138 | if (fileName.isEmpty())
|
---|
| 139 | fileName = QFileDialog::getOpenFileName(this);
|
---|
| 140 | QPixmap pm(fileName);
|
---|
| 141 | if (pm.isNull())
|
---|
| 142 | return;
|
---|
| 143 |
|
---|
| 144 | value = qVariantFromValue(pm);
|
---|
| 145 | }
|
---|
| 146 | break;
|
---|
| 147 | case QVariant::Bool:
|
---|
| 148 | {
|
---|
| 149 | QString txt = editValue->text().toLower();
|
---|
| 150 | value = QVariant(txt != QLatin1String("0") && txt != QLatin1String("false"));
|
---|
| 151 | }
|
---|
| 152 | break;
|
---|
| 153 | case QVariant::List:
|
---|
| 154 | {
|
---|
| 155 | QStringList txtList = editValue->text().split(QRegExp(QLatin1String("[,;]")));
|
---|
| 156 | QList<QVariant> varList;
|
---|
| 157 | for (int i = 0; i < txtList.count(); ++i) {
|
---|
| 158 | QVariant svar(txtList.at(i));
|
---|
| 159 | QString str = svar.toString();
|
---|
| 160 | str = str.trimmed();
|
---|
| 161 | bool ok;
|
---|
| 162 | int n = str.toInt(&ok);
|
---|
| 163 | if (ok) {
|
---|
| 164 | varList << n;
|
---|
| 165 | continue;
|
---|
| 166 | }
|
---|
| 167 | double d = str.toDouble(&ok);
|
---|
| 168 | if (ok) {
|
---|
| 169 | varList << d;
|
---|
| 170 | continue;
|
---|
| 171 | }
|
---|
| 172 | varList << str;
|
---|
| 173 | }
|
---|
| 174 | value = varList;
|
---|
| 175 | }
|
---|
| 176 | break;
|
---|
| 177 |
|
---|
| 178 | default:
|
---|
| 179 | value = editValue->text();
|
---|
| 180 | break;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | Q_ASSERT(activex->setProperty(prop.toLatin1(), value));
|
---|
| 184 | updateProperties();
|
---|
| 185 | listProperties->setCurrentItem(listProperties->findItems(prop, Qt::MatchExactly).at(0));
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | void ChangeProperties::on_listEditRequests_itemChanged(QTreeWidgetItem *item)
|
---|
| 189 | {
|
---|
| 190 | if (!item)
|
---|
| 191 | return;
|
---|
| 192 |
|
---|
| 193 | QString property = item->text(0);
|
---|
| 194 | activex->setPropertyWritable(property.toLatin1(), item->checkState(0) == Qt::Checked);
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 |
|
---|
| 198 | void ChangeProperties::updateProperties()
|
---|
| 199 | {
|
---|
| 200 | bool hasControl = activex && !activex->isNull();
|
---|
| 201 | tabWidget->setEnabled(hasControl);
|
---|
| 202 |
|
---|
| 203 | listProperties->clear();
|
---|
| 204 | listEditRequests->clear();
|
---|
| 205 | if (hasControl) {
|
---|
| 206 | const QMetaObject *mo = activex->metaObject();
|
---|
| 207 | const int numprops = mo->propertyCount();
|
---|
| 208 | for (int i = mo->propertyOffset(); i < numprops; ++i) {
|
---|
| 209 | const QMetaProperty property = mo->property(i);
|
---|
| 210 | QTreeWidgetItem *item = new QTreeWidgetItem(listProperties);
|
---|
| 211 | item->setText(0, QString::fromLatin1(property.name()));
|
---|
| 212 | item->setText(1, QString::fromLatin1(property.typeName()));
|
---|
| 213 | if (!property.isDesignable()) {
|
---|
| 214 | item->setTextColor(0, Qt::gray);
|
---|
| 215 | item->setTextColor(1, Qt::gray);
|
---|
| 216 | item->setTextColor(2, Qt::gray);
|
---|
| 217 | }
|
---|
| 218 | QVariant var = activex->property(property.name());
|
---|
| 219 |
|
---|
| 220 | switch (var.type()) {
|
---|
| 221 | case QVariant::Color:
|
---|
| 222 | {
|
---|
| 223 | QColor col = qvariant_cast<QColor>(var);
|
---|
| 224 | item->setText(2, col.name());
|
---|
| 225 | }
|
---|
| 226 | break;
|
---|
| 227 | case QVariant::Font:
|
---|
| 228 | {
|
---|
| 229 | QFont fnt = qvariant_cast<QFont>(var);
|
---|
| 230 | item->setText(2, fnt.toString());
|
---|
| 231 | }
|
---|
| 232 | break;
|
---|
| 233 | case QVariant::Bool:
|
---|
| 234 | {
|
---|
| 235 | item->setText(2, var.toBool() ? QLatin1String("true") : QLatin1String("false"));
|
---|
| 236 | }
|
---|
| 237 | break;
|
---|
| 238 | case QVariant::Pixmap:
|
---|
| 239 | {
|
---|
| 240 | QPixmap pm = qvariant_cast<QPixmap>(var);
|
---|
| 241 | item->setIcon(2, pm);
|
---|
| 242 | }
|
---|
| 243 | break;
|
---|
| 244 | case QVariant::List:
|
---|
| 245 | {
|
---|
| 246 | QList<QVariant> varList = var.toList();
|
---|
| 247 | QStringList strList;
|
---|
| 248 | for (int i = 0; i < varList.count(); ++i) {
|
---|
| 249 | QVariant var = varList.at(i);
|
---|
| 250 | strList << var.toString();
|
---|
| 251 | }
|
---|
| 252 | item->setText(2, strList.join(QLatin1String(", ")));
|
---|
| 253 | }
|
---|
| 254 | break;
|
---|
| 255 | case QVariant::Int:
|
---|
| 256 | if (property.isEnumType()) {
|
---|
| 257 | const QMetaEnum enumerator = mo->enumerator(mo->indexOfEnumerator(property.typeName()));
|
---|
| 258 | item->setText(2, QString::fromLatin1(enumerator.valueToKey(var.toInt())));
|
---|
| 259 | break;
|
---|
| 260 | }
|
---|
| 261 | //FALLTHROUGH
|
---|
| 262 | default:
|
---|
| 263 | item->setText(2, var.toString());
|
---|
| 264 | break;
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | bool requesting = false;
|
---|
| 268 | #if 0
|
---|
| 269 | {
|
---|
| 270 | void *argv[] = { &requesting };
|
---|
| 271 | activex->qt_metacall(QMetaObject::Call(0x10000000) /*RequestingEdit*/, i, argv);
|
---|
| 272 | }
|
---|
| 273 | #endif
|
---|
| 274 | if (requesting) {
|
---|
| 275 | QTreeWidgetItem *check = new QTreeWidgetItem(listEditRequests);
|
---|
| 276 | check->setText(0, QString::fromLatin1(property.name()));
|
---|
| 277 | check->setCheckState(0, activex->propertyWritable(property.name()) ? Qt::Checked : Qt::Unchecked);
|
---|
| 278 | }
|
---|
| 279 | }
|
---|
| 280 | listProperties->setCurrentItem(listProperties->topLevelItem(0));
|
---|
| 281 | } else {
|
---|
| 282 | editValue->clear();
|
---|
| 283 | }
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | QT_END_NAMESPACE
|
---|