diff options
author | Jason Barron <jbarron@trolltech.com> | 2009-06-25 13:49:53 (GMT) |
---|---|---|
committer | Jason Barron <jbarron@trolltech.com> | 2009-06-25 13:49:53 (GMT) |
commit | db8f05e257019694f5e8076845626008f2adc3dd (patch) | |
tree | 05d3959403cf15ac5f702091439e028af01f343b /tools/designer/src/lib/shared | |
parent | 8aafaa65a1d16f8b982279f5aceedf1e281ddb5a (diff) | |
parent | 796a5a2c7d8c91a46ac761dde18b7da2ec6c177b (diff) | |
download | Qt-db8f05e257019694f5e8076845626008f2adc3dd.zip Qt-db8f05e257019694f5e8076845626008f2adc3dd.tar.gz Qt-db8f05e257019694f5e8076845626008f2adc3dd.tar.bz2 |
Merge commit 'qt/master-stable' into 4.6-stable
Bring Qt 4.6 into the Qt-S60 repo.
Conflicts:
configure.exe
mkspecs/features/qttest_p4.prf
qmake/generators/makefile.cpp
src/corelib/io/qdir.cpp
src/corelib/io/qprocess.h
src/corelib/kernel/qcoreevent.h
src/corelib/kernel/qobject.cpp
src/corelib/kernel/qsharedmemory_unix.cpp
src/corelib/thread/qthread_p.h
src/corelib/tools/qvector.h
src/gui/dialogs/qdialog.cpp
src/gui/dialogs/qfiledialog.cpp
src/gui/dialogs/qfiledialog_p.h
src/gui/dialogs/qmessagebox.cpp
src/gui/graphicsview/qgraphicsitem.cpp
src/gui/graphicsview/qgraphicsview.cpp
src/gui/image/qpixmapcache.cpp
src/gui/kernel/qapplication.cpp
src/gui/kernel/qapplication_p.h
src/gui/kernel/qwidget.cpp
src/gui/kernel/qwidget_p.h
src/gui/painting/qdrawhelper.cpp
src/gui/painting/qpaintengine_raster.cpp
src/gui/text/qfontengine_qpf.cpp
src/gui/widgets/qmenubar.cpp
src/network/socket/qlocalserver.cpp
src/testlib/qtestcase.cpp
src/testlib/testlib.pro
tests/auto/qimagereader/tst_qimagereader.cpp
tests/auto/qitemdelegate/tst_qitemdelegate.cpp
tests/auto/qnetworkreply/tst_qnetworkreply.cpp
tests/auto/qpixmap/qpixmap.pro
Diffstat (limited to 'tools/designer/src/lib/shared')
30 files changed, 710 insertions, 207 deletions
diff --git a/tools/designer/src/lib/shared/actioneditor.cpp b/tools/designer/src/lib/shared/actioneditor.cpp index 7f96a15..e60b212 100644 --- a/tools/designer/src/lib/shared/actioneditor.cpp +++ b/tools/designer/src/lib/shared/actioneditor.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::ActionEditor -*/ - #include "actioneditor_p.h" #include "filterwidget_p.h" #include "actionrepository_p.h" diff --git a/tools/designer/src/lib/shared/codedialog.cpp b/tools/designer/src/lib/shared/codedialog.cpp index 5a2db33..0b18f5e 100644 --- a/tools/designer/src/lib/shared/codedialog.cpp +++ b/tools/designer/src/lib/shared/codedialog.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::CodeDialog -*/ - #include "codedialog_p.h" #include "qdesigner_utils_p.h" #include "iconloader_p.h" diff --git a/tools/designer/src/lib/shared/csshighlighter.cpp b/tools/designer/src/lib/shared/csshighlighter.cpp index d5e045b..f7144c5 100644 --- a/tools/designer/src/lib/shared/csshighlighter.cpp +++ b/tools/designer/src/lib/shared/csshighlighter.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::StyleSheetEditorDialog -*/ - #include "csshighlighter_p.h" QT_BEGIN_NAMESPACE diff --git a/tools/designer/src/lib/shared/formwindowbase.cpp b/tools/designer/src/lib/shared/formwindowbase.cpp index b569b51..377ae43 100644 --- a/tools/designer/src/lib/shared/formwindowbase.cpp +++ b/tools/designer/src/lib/shared/formwindowbase.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::FormWindowBase -*/ - #include "formwindowbase_p.h" #include "connectionedit_p.h" #include "qdesigner_command_p.h" diff --git a/tools/designer/src/lib/shared/newformwidget.cpp b/tools/designer/src/lib/shared/newformwidget.cpp index d79d77a..503e597 100644 --- a/tools/designer/src/lib/shared/newformwidget.cpp +++ b/tools/designer/src/lib/shared/newformwidget.cpp @@ -310,9 +310,8 @@ QImage NewFormWidget::grabForm(QDesignerFormEditorInterface *core, const QString &workingDir, const qdesigner_internal::DeviceProfile &dp) { - qdesigner_internal::QDesignerFormBuilder formBuilder(core, - qdesigner_internal::QDesignerFormBuilder::DisableScripts, - dp); + qdesigner_internal::NewFormWidgetFormBuilder + formBuilder(core, qdesigner_internal::QDesignerFormBuilder::DisableScripts, dp); if (!workingDir.isEmpty()) formBuilder.setWorkingDirectory(workingDir); diff --git a/tools/designer/src/lib/shared/orderdialog.cpp b/tools/designer/src/lib/shared/orderdialog.cpp index 3f14ca6..0df3866 100644 --- a/tools/designer/src/lib/shared/orderdialog.cpp +++ b/tools/designer/src/lib/shared/orderdialog.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::OrderDialog -*/ - #include "orderdialog_p.h" #include "iconloader_p.h" #include "ui_orderdialog.h" diff --git a/tools/designer/src/lib/shared/plaintexteditor.cpp b/tools/designer/src/lib/shared/plaintexteditor.cpp index ce5cd5b..f30df3d 100644 --- a/tools/designer/src/lib/shared/plaintexteditor.cpp +++ b/tools/designer/src/lib/shared/plaintexteditor.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::PlainTextEditorDialog -*/ - #include "plaintexteditor_p.h" #include "abstractsettings_p.h" diff --git a/tools/designer/src/lib/shared/pluginmanager.cpp b/tools/designer/src/lib/shared/pluginmanager.cpp index 9dc8c7b..100a088 100644 --- a/tools/designer/src/lib/shared/pluginmanager.cpp +++ b/tools/designer/src/lib/shared/pluginmanager.cpp @@ -16,6 +16,8 @@ ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the +What usually causes this mess is specifying a Z-order (raise/lower) widget or changing the tab order and then deleting the widget. Designer did not delete the widget from those settings, causing uic to report this when applying them. I believe we fixed that 4.5. + ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. @@ -72,6 +74,11 @@ static const char *classAttributeC = "class"; static const char *customwidgetElementC = "customwidget"; static const char *extendsElementC = "extends"; static const char *addPageMethodC = "addpagemethod"; +static const char *propertySpecsC = "propertyspecifications"; +static const char *stringPropertySpecC = "stringpropertyspecification"; +static const char *stringPropertyNameAttrC = "name"; +static const char *stringPropertyTypeAttrC = "type"; +static const char *stringPropertyNoTrAttrC = "notr"; static const char *jambiLanguageC = "jambi"; enum { debugPluginManager = 0 }; @@ -141,6 +148,10 @@ static inline QString getDesignerLanguage(QDesignerFormEditorInterface *core) class QDesignerCustomWidgetSharedData : public QSharedData { public: + // Type of a string property + typedef QPair<qdesigner_internal::TextPropertyValidationMode, bool> StringPropertyType; + typedef QHash<QString, StringPropertyType> StringPropertyTypeMap; + explicit QDesignerCustomWidgetSharedData(const QString &thePluginPath) : pluginPath(thePluginPath) {} void clearXML(); @@ -152,6 +163,7 @@ public: QString xmlAddPageMethod; QString xmlExtends; + StringPropertyTypeMap xmlStringPropertyTypeMap; }; void QDesignerCustomWidgetSharedData::clearXML() @@ -161,6 +173,7 @@ void QDesignerCustomWidgetSharedData::clearXML() xmlLanguage.clear(); xmlAddPageMethod.clear(); xmlExtends.clear(); + xmlStringPropertyTypeMap.clear(); } // ---------------- QDesignerCustomWidgetData @@ -220,6 +233,17 @@ QString QDesignerCustomWidgetData::pluginPath() const return m_d->pluginPath; } +bool QDesignerCustomWidgetData::xmlStringPropertyType(const QString &name, StringPropertyType *type) const +{ + QDesignerCustomWidgetSharedData::StringPropertyTypeMap::const_iterator it = m_d->xmlStringPropertyTypeMap.constFind(name); + if (it == m_d->xmlStringPropertyTypeMap.constEnd()) { + *type = StringPropertyType(qdesigner_internal::ValidationRichText, true); + return false; + } + *type = it.value(); + return true; +} + // Wind a QXmlStreamReader until it finds an element. Returns index or one of FindResult enum FindResult { FindError = -2, ElementNotFound = -1 }; @@ -249,6 +273,82 @@ static inline QString msgXmlError(const QString &name, const QString &errorMessa return QDesignerPluginManager::tr("An XML error was encountered when parsing the XML of the custom widget %1: %2").arg(name, errorMessage); } +static inline QString msgAttributeMissing(const QString &name) +{ + return QDesignerPluginManager::tr("A required attribute ('%1') is missing.").arg(name); +} + +static qdesigner_internal::TextPropertyValidationMode typeStringToType(const QString &v, bool *ok) +{ + *ok = true; + if (v == QLatin1String("multiline")) + return qdesigner_internal::ValidationMultiLine; + if (v == QLatin1String("richtext")) + return qdesigner_internal::ValidationRichText; + if (v == QLatin1String("stylesheet")) + return qdesigner_internal::ValidationStyleSheet; + if (v == QLatin1String("singleline")) + return qdesigner_internal::ValidationSingleLine; + if (v == QLatin1String("objectname")) + return qdesigner_internal::ValidationObjectName; + if (v == QLatin1String("objectnamescope")) + return qdesigner_internal::ValidationObjectNameScope; + if (v == QLatin1String("url")) + return qdesigner_internal::ValidationURL; + *ok = false; + return qdesigner_internal::ValidationRichText; +} + +static bool parsePropertySpecs(QXmlStreamReader &sr, + QDesignerCustomWidgetSharedData::StringPropertyTypeMap *rc, + QString *errorMessage) +{ + const QString propertySpecs = QLatin1String(propertySpecsC); + const QString stringPropertySpec = QLatin1String(stringPropertySpecC); + const QString stringPropertyTypeAttr = QLatin1String(stringPropertyTypeAttrC); + const QString stringPropertyNoTrAttr = QLatin1String(stringPropertyNoTrAttrC); + const QString stringPropertyNameAttr = QLatin1String(stringPropertyNameAttrC); + + while (!sr.atEnd()) { + switch(sr.readNext()) { + case QXmlStreamReader::StartElement: { + if (sr.name() != stringPropertySpec) { + *errorMessage = QDesignerPluginManager::tr("An invalid property specification ('%1') was encountered. Supported types: %2").arg(sr.name().toString(), stringPropertySpec); + return false; + } + const QXmlStreamAttributes atts = sr.attributes(); + const QString name = atts.value(stringPropertyNameAttr).toString(); + const QString type = atts.value(stringPropertyTypeAttr).toString(); + const QString notrS = atts.value(stringPropertyNoTrAttr).toString(); //Optional + + if (type.isEmpty()) { + *errorMessage = msgAttributeMissing(stringPropertyTypeAttr); + return false; + } + if (name.isEmpty()) { + *errorMessage = msgAttributeMissing(stringPropertyNameAttr); + return false; + } + bool typeOk; + const bool noTr = notrS == QLatin1String("true") || notrS == QLatin1String("1"); + QDesignerCustomWidgetSharedData::StringPropertyType v(typeStringToType(type, &typeOk), !noTr); + if (!typeOk) { + *errorMessage = QDesignerPluginManager::tr("'%1' is not a valid string property specification!").arg(type); + return false; + } + rc->insert(name, v); + } + break; + case QXmlStreamReader::EndElement: // Outer </stringproperties> + if (sr.name() == propertySpecs) + return true; + default: + break; + } + } + return true; +} + QDesignerCustomWidgetData::ParseResult QDesignerCustomWidgetData::parseXml(const QString &xml, const QString &name, QString *errorMessage) { @@ -311,10 +411,11 @@ QDesignerCustomWidgetData::ParseResult default: break; } - // Find <extends>, <addPageMethod> + // Find <extends>, <addPageMethod>, <stringproperties> elements.clear(); elements.push_back(QLatin1String(extendsElementC)); elements.push_back(QLatin1String(addPageMethodC)); + elements.push_back(QLatin1String(propertySpecsC)); while (true) { switch (findElement(elements, sr)) { case FindError: @@ -336,6 +437,12 @@ QDesignerCustomWidgetData::ParseResult return ParseError; } break; + case 2: // <stringproperties> + if (!parsePropertySpecs(sr, &m_d->xmlStringPropertyTypeMap, errorMessage)) { + *errorMessage = msgXmlError(name, *errorMessage); + return ParseError; + } + break; } } return rc; @@ -345,6 +452,8 @@ QDesignerCustomWidgetData::ParseResult class QDesignerPluginManagerPrivate { public: + typedef QPair<QString, QString> ClassNamePropertyNameKey; + QDesignerPluginManagerPrivate(QDesignerFormEditorInterface *core); void clearCustomWidgets(); @@ -562,7 +671,7 @@ bool QDesignerPluginManager::registerNewPlugins() const int before = m_d->m_registeredPlugins.size(); foreach (const QString &path, m_d->m_pluginPaths) - registerPath(path); + registerPath(path); const bool newPluginsFound = m_d->m_registeredPlugins.size() > before; // We force a re-initialize as Jambi collection might return // different widget lists when switching projects. @@ -654,6 +763,15 @@ QDesignerCustomWidgetData QDesignerPluginManager::customWidgetData(QDesignerCust return m_d->m_customWidgetData.at(index); } +QDesignerCustomWidgetData QDesignerPluginManager::customWidgetData(const QString &name) const +{ + const int count = m_d->m_customWidgets.size(); + for (int i = 0; i < count; i++) + if (m_d->m_customWidgets.at(i)->name() == name) + return m_d->m_customWidgetData.at(i); + return QDesignerCustomWidgetData(); +} + QObjectList QDesignerPluginManager::instances() const { QStringList plugins = registeredPlugins(); diff --git a/tools/designer/src/lib/shared/pluginmanager_p.h b/tools/designer/src/lib/shared/pluginmanager_p.h index e374f42..f73bc74 100644 --- a/tools/designer/src/lib/shared/pluginmanager_p.h +++ b/tools/designer/src/lib/shared/pluginmanager_p.h @@ -54,9 +54,11 @@ #define PLUGINMANAGER_H #include "shared_global_p.h" +#include "shared_enums_p.h" #include <QtCore/QSharedDataPointer> #include <QtCore/QMap> +#include <QtCore/QPair> #include <QtCore/QStringList> QT_BEGIN_NAMESPACE @@ -70,6 +72,9 @@ class QDesignerCustomWidgetSharedData; /* Information contained in the Dom XML of a custom widget. */ class QDESIGNER_SHARED_EXPORT QDesignerCustomWidgetData { public: + // StringPropertyType: validation mode and translatable flag. + typedef QPair<qdesigner_internal::TextPropertyValidationMode, bool> StringPropertyType; + explicit QDesignerCustomWidgetData(const QString &pluginPath = QString()); enum ParseResult { ParseOk, ParseWarning, ParseError }; @@ -93,6 +98,8 @@ public: QString xmlExtends() const; // Optional. The name to be used in the widget box. QString xmlDisplayName() const; + // Type of a string property + bool xmlStringPropertyType(const QString &name, StringPropertyType *type) const; private: QSharedDataPointer<QDesignerCustomWidgetSharedData> m_d; @@ -128,6 +135,7 @@ public: CustomWidgetList registeredCustomWidgets() const; QDesignerCustomWidgetData customWidgetData(QDesignerCustomWidgetInterface *w) const; + QDesignerCustomWidgetData customWidgetData(const QString &className) const; bool registerNewPlugins(); diff --git a/tools/designer/src/lib/shared/previewconfigurationwidget.cpp b/tools/designer/src/lib/shared/previewconfigurationwidget.cpp index 2cf362f..2b45759 100644 --- a/tools/designer/src/lib/shared/previewconfigurationwidget.cpp +++ b/tools/designer/src/lib/shared/previewconfigurationwidget.cpp @@ -65,43 +65,27 @@ #include <QtCore/QFileInfo> #include <QtCore/QSharedData> -// #define DEFAULT_SKINS_FROM_RESOURCE -#ifdef DEFAULT_SKINS_FROM_RESOURCE -QT_BEGIN_NAMESPACE + static const char *skinResourcePathC = ":/skins/"; -QT_END_NAMESPACE -#else -# include <QtCore/QLibraryInfo> -#endif QT_BEGIN_NAMESPACE static const char *skinExtensionC = "skin"; -namespace { - // Pair of skin name, path - typedef QPair<QString, QString> SkinNamePath; - typedef QList<SkinNamePath> Skins; - enum { SkinComboNoneIndex = 0 }; -} +// Pair of skin name, path +typedef QPair<QString, QString> SkinNamePath; +typedef QList<SkinNamePath> Skins; +enum { SkinComboNoneIndex = 0 }; // find default skins (resources) static const Skins &defaultSkins() { static Skins rc; if (rc.empty()) { -#ifdef DEFAULT_SKINS_FROM_RESOURCE const QString skinPath = QLatin1String(skinResourcePathC); -#else - QString skinPath = QLibraryInfo::location(QLibraryInfo::PrefixPath); - skinPath += QDir::separator(); - skinPath += QLatin1String("tools"); - skinPath += QDir::separator(); - skinPath += QLatin1String("qvfb"); -#endif QString pattern = QLatin1String("*."); pattern += QLatin1String(skinExtensionC); const QDir dir(skinPath, pattern); - const QFileInfoList list = dir.entryInfoList(); + const QFileInfoList list = dir.entryInfoList(QDir::Dirs|QDir::NoDotAndDotDot, QDir::Name); if (list.empty()) return rc; const QFileInfoList::const_iterator lcend = list.constEnd(); diff --git a/tools/designer/src/lib/shared/previewmanager.cpp b/tools/designer/src/lib/shared/previewmanager.cpp index 8ed1772..ac16741 100644 --- a/tools/designer/src/lib/shared/previewmanager.cpp +++ b/tools/designer/src/lib/shared/previewmanager.cpp @@ -67,6 +67,7 @@ #include <QtGui/QAction> #include <QtGui/QActionGroup> #include <QtGui/QCursor> +#include <QtGui/QMatrix> #include <QtCore/QMap> #include <QtCore/QDebug> @@ -149,11 +150,16 @@ QGraphicsProxyWidget *DesignerZoomWidget::createProxyWidget(QGraphicsItem *paren return new DesignerZoomProxyWidget(parent, wFlags); } -// --------- Widget Preview skin: Forward the key events to the window +// PreviewDeviceSkin: Forwards the key events to the window and +// provides context menu with rotation options. Derived class +// can apply additional transformations to the skin. + class PreviewDeviceSkin : public DeviceSkin { Q_OBJECT public: + enum Direction { DirectionUp, DirectionLeft, DirectionRight }; + explicit PreviewDeviceSkin(const DeviceSkinParameters ¶meters, QWidget *parent); virtual void setPreview(QWidget *w); QSize screenSize() const { return m_screenSize; } @@ -164,15 +170,36 @@ private slots: void slotPopupMenu(); protected: - virtual void populateContextMenu(QMenu *m); + virtual void populateContextMenu(QMenu *) {} + +private slots: + void slotDirection(QAction *); + +protected: + // Fit the widget in case the orientation changes (transposing screensize) + virtual void fitWidget(const QSize &size); + // Calculate the complete transformation for the skin + // (base class implementation provides rotation). + virtual QMatrix skinTransform() const; private: const QSize m_screenSize; + Direction m_direction; + + QAction *m_directionUpAction; + QAction *m_directionLeftAction; + QAction *m_directionRightAction; + QAction *m_closeAction; }; PreviewDeviceSkin::PreviewDeviceSkin(const DeviceSkinParameters ¶meters, QWidget *parent) : - DeviceSkin(parameters, parent), - m_screenSize(parameters.screenSize()) + DeviceSkin(parameters, parent), + m_screenSize(parameters.screenSize()), + m_direction(DirectionUp), + m_directionUpAction(0), + m_directionLeftAction(0), + m_directionRightAction(0), + m_closeAction(0) { connect(this, SIGNAL(skinKeyPressEvent(int,QString,bool)), this, SLOT(slotSkinKeyPressEvent(int,QString,bool))); @@ -195,7 +222,6 @@ void PreviewDeviceSkin::slotSkinKeyPressEvent(int code, const QString& text, boo QKeyEvent e(QEvent::KeyPress,code,0,text,autorep); QApplication::sendEvent(focusWidget, &e); } - } void PreviewDeviceSkin::slotSkinKeyReleaseEvent(int code, const QString& text, bool autorep) @@ -206,16 +232,83 @@ void PreviewDeviceSkin::slotSkinKeyReleaseEvent(int code, const QString& text, b } } +// Create a checkable action with integer data and +// set it checked if it matches the currentState. +static inline QAction + *createCheckableActionIntData(const QString &label, + int actionValue, int currentState, + QActionGroup *ag, QObject *parent) +{ + QAction *a = new QAction(label, parent); + a->setData(actionValue); + a->setCheckable(true); + if (actionValue == currentState) + a->setChecked(true); + ag->addAction(a); + return a; +} + void PreviewDeviceSkin::slotPopupMenu() { QMenu menu(this); + // Create actions + if (!m_directionUpAction) { + QActionGroup *directionGroup = new QActionGroup(this); + connect(directionGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotDirection(QAction*))); + directionGroup->setExclusive(true); + m_directionUpAction = createCheckableActionIntData(tr("&Portrait"), DirectionUp, m_direction, directionGroup, this); + m_directionLeftAction = createCheckableActionIntData(tr("Landscape (&CCW)"), DirectionLeft, m_direction, directionGroup, this); + m_directionRightAction = createCheckableActionIntData(tr("&Landscape (CW)"), DirectionRight, m_direction, directionGroup, this); + m_closeAction = new QAction(tr("&Close"), this); + connect(m_closeAction, SIGNAL(triggered()), parentWidget(), SLOT(close())); + } + menu.addAction(m_directionUpAction); + menu.addAction(m_directionLeftAction); + menu.addAction(m_directionRightAction); + menu.addSeparator(); populateContextMenu(&menu); + menu.addAction(m_closeAction); menu.exec(QCursor::pos()); } -void PreviewDeviceSkin::populateContextMenu(QMenu *menu) +void PreviewDeviceSkin::slotDirection(QAction *a) +{ + const Direction newDirection = static_cast<Direction>(a->data().toInt()); + if (m_direction == newDirection) + return; + const Qt::Orientation newOrientation = newDirection == DirectionUp ? Qt::Vertical : Qt::Horizontal; + const Qt::Orientation oldOrientation = m_direction == DirectionUp ? Qt::Vertical : Qt::Horizontal; + m_direction = newDirection; + QApplication::setOverrideCursor(Qt::WaitCursor); + if (oldOrientation != newOrientation) { + QSize size = screenSize(); + if (newOrientation == Qt::Horizontal) + size.transpose(); + fitWidget(size); + } + setTransform(skinTransform()); + QApplication::restoreOverrideCursor(); +} + +void PreviewDeviceSkin::fitWidget(const QSize &size) +{ + view()->setFixedSize(size); +} + +QMatrix PreviewDeviceSkin::skinTransform() const { - connect(menu->addAction(tr("&Close")), SIGNAL(triggered()), parentWidget(), SLOT(close())); + QMatrix newTransform; + switch (m_direction) { + case DirectionUp: + break; + case DirectionLeft: + newTransform.rotate(270.0); + break; + case DirectionRight: + newTransform.rotate(90.0); + break; + } + return newTransform; } // ------------ PreviewConfigurationPrivate @@ -257,16 +350,20 @@ signals: void zoomPercentChanged(int); protected: - virtual void populateContextMenu(QMenu *m); + virtual void populateContextMenu(QMenu *m); + virtual QMatrix skinTransform() const; + virtual void fitWidget(const QSize &size); private: ZoomMenu *m_zoomMenu; + QAction *m_zoomSubMenuAction; ZoomWidget *m_zoomWidget; }; ZoomablePreviewDeviceSkin::ZoomablePreviewDeviceSkin(const DeviceSkinParameters ¶meters, QWidget *parent) : PreviewDeviceSkin(parameters, parent), m_zoomMenu(new ZoomMenu(this)), + m_zoomSubMenuAction(0), m_zoomWidget(new DesignerZoomWidget) { connect(m_zoomMenu, SIGNAL(zoomChanged(int)), this, SLOT(setZoomPercent(int))); @@ -279,10 +376,20 @@ ZoomablePreviewDeviceSkin::ZoomablePreviewDeviceSkin(const DeviceSkinParameters setView(m_zoomWidget); } -void ZoomablePreviewDeviceSkin::setPreview(QWidget *formWidget) +static inline qreal zoomFactor(int percent) { - formWidget->setFixedSize(screenSize()); + return qreal(percent) / 100.0; +} + +static inline QSize scaleSize(int zoomPercent, const QSize &size) +{ + return zoomPercent == 100 ? size : (QSizeF(size) * zoomFactor(zoomPercent)).toSize(); +} + +void ZoomablePreviewDeviceSkin::setPreview(QWidget *formWidget) +{ m_zoomWidget->setWidget(formWidget); + m_zoomWidget->resize(scaleSize(zoomPercent(), screenSize())); } int ZoomablePreviewDeviceSkin::zoomPercent() const @@ -290,32 +397,50 @@ int ZoomablePreviewDeviceSkin::zoomPercent() const return m_zoomWidget->zoom(); } -void ZoomablePreviewDeviceSkin::setZoomPercent(int z) +void ZoomablePreviewDeviceSkin::setZoomPercent(int zp) { - if (z == zoomPercent()) + if (zp == zoomPercent()) return; // If not triggered by the menu itself: Update it - if (m_zoomMenu->zoom() != z) - m_zoomMenu->setZoom(z); + if (m_zoomMenu->zoom() != zp) + m_zoomMenu->setZoom(zp); - const QCursor oldCursor = cursor(); - QApplication::setOverrideCursor(Qt::WaitCursor); - // DeviceSkin has double, not qreal. - const double hundred = 100.0; - setZoom(static_cast<double>(z) / hundred); - m_zoomWidget->setZoom(z); + QApplication::setOverrideCursor(Qt::WaitCursor); + m_zoomWidget->setZoom(zp); + setTransform(skinTransform()); QApplication::restoreOverrideCursor(); } void ZoomablePreviewDeviceSkin::populateContextMenu(QMenu *menu) { - m_zoomMenu->addActions(menu); - menu->addSeparator(); - PreviewDeviceSkin::populateContextMenu(menu); + if (!m_zoomSubMenuAction) { + m_zoomSubMenuAction = new QAction(tr("&Zoom"), this); + QMenu *zoomSubMenu = new QMenu; + m_zoomSubMenuAction->setMenu(zoomSubMenu); + m_zoomMenu->addActions(zoomSubMenu); + } + menu->addAction(m_zoomSubMenuAction); menu->addSeparator(); } +QMatrix ZoomablePreviewDeviceSkin::skinTransform() const +{ + // Complete transformation consisting of base class rotation and zoom. + QMatrix rc = PreviewDeviceSkin::skinTransform(); + const int zp = zoomPercent(); + if (zp != 100) { + const qreal factor = zoomFactor(zp); + rc.scale(factor, factor); + } + return rc; +} + +void ZoomablePreviewDeviceSkin::fitWidget(const QSize &size) +{ + m_zoomWidget->resize(scaleSize(zoomPercent(), size)); +} + // ------------- PreviewConfiguration static const char *styleKey = "Style"; diff --git a/tools/designer/src/lib/shared/promotionmodel.cpp b/tools/designer/src/lib/shared/promotionmodel.cpp index 77d0bbb..1df9cbe 100644 --- a/tools/designer/src/lib/shared/promotionmodel.cpp +++ b/tools/designer/src/lib/shared/promotionmodel.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::PromotionModel -*/ - #include "promotionmodel_p.h" #include "widgetdatabase_p.h" diff --git a/tools/designer/src/lib/shared/qdesigner_formbuilder.cpp b/tools/designer/src/lib/shared/qdesigner_formbuilder.cpp index 6394847..b92a48d 100644 --- a/tools/designer/src/lib/shared/qdesigner_formbuilder.cpp +++ b/tools/designer/src/lib/shared/qdesigner_formbuilder.cpp @@ -473,6 +473,20 @@ QPixmap QDesignerFormBuilder::createPreviewPixmap(const QDesignerFormWindowInter return rc; } +// ---------- NewFormWidgetFormBuilder + +NewFormWidgetFormBuilder::NewFormWidgetFormBuilder(QDesignerFormEditorInterface *core, + Mode mode, + const DeviceProfile &deviceProfile) : + QDesignerFormBuilder(core, mode, deviceProfile) +{ +} + +void NewFormWidgetFormBuilder::createCustomWidgets(DomCustomWidgets *dc) +{ + QSimpleResource::handleDomCustomWidgets(core(), dc); +} + } // namespace qdesigner_internal QT_END_NAMESPACE diff --git a/tools/designer/src/lib/shared/qdesigner_formbuilder_p.h b/tools/designer/src/lib/shared/qdesigner_formbuilder_p.h index b982e1c..ee40085 100644 --- a/tools/designer/src/lib/shared/qdesigner_formbuilder_p.h +++ b/tools/designer/src/lib/shared/qdesigner_formbuilder_p.h @@ -75,7 +75,7 @@ namespace qdesigner_internal { class DesignerPixmapCache; class DesignerIconCache; -/* Form builder used for previewing forms, widget box and new form dialog. +/* Form builder used for previewing forms and widget box. * It applies the system settings to its toplevel window. */ class QDESIGNER_SHARED_EXPORT QDesignerFormBuilder: public QFormBuilder @@ -159,6 +159,21 @@ private: bool m_mainWidget; }; +// Form builder for a new form widget (preview). To allow for promoted +// widgets in the template, it implements the handling of custom widgets +// (adding of them to the widget database). + +class QDESIGNER_SHARED_EXPORT NewFormWidgetFormBuilder: public QDesignerFormBuilder { +public: + NewFormWidgetFormBuilder(QDesignerFormEditorInterface *core, + Mode mode, + const DeviceProfile &deviceProfile = DeviceProfile()); + +protected: + virtual void createCustomWidgets(DomCustomWidgets *); +}; + + } // namespace qdesigner_internal QT_END_NAMESPACE diff --git a/tools/designer/src/lib/shared/qdesigner_promotiondialog.cpp b/tools/designer/src/lib/shared/qdesigner_promotiondialog.cpp index 8453c16..a1c47d2 100644 --- a/tools/designer/src/lib/shared/qdesigner_promotiondialog.cpp +++ b/tools/designer/src/lib/shared/qdesigner_promotiondialog.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::QDesignerPromotionDialog -*/ - #include "qdesigner_promotiondialog_p.h" #include "promotionmodel_p.h" #include "iconloader_p.h" diff --git a/tools/designer/src/lib/shared/qdesigner_propertyeditor.cpp b/tools/designer/src/lib/shared/qdesigner_propertyeditor.cpp index 7c7d9d7..3875d0e 100644 --- a/tools/designer/src/lib/shared/qdesigner_propertyeditor.cpp +++ b/tools/designer/src/lib/shared/qdesigner_propertyeditor.cpp @@ -40,16 +40,56 @@ ****************************************************************************/ #include "qdesigner_propertyeditor_p.h" -#ifdef Q_OS_WIN -# include <widgetfactory_p.h> -#endif -#include <QAction> -#include <QLineEdit> -#include <QAbstractButton> +#include "pluginmanager_p.h" + +#include <QtDesigner/QDesignerFormEditorInterface> +#include <widgetfactory_p.h> +#include <QtGui/QAction> +#include <QtGui/QLineEdit> +#include <QtGui/QAbstractButton> QT_BEGIN_NAMESPACE namespace qdesigner_internal { +typedef QDesignerPropertyEditor::StringPropertyParameters StringPropertyParameters; +// A map of property name to type +typedef QHash<QString, StringPropertyParameters> PropertyNameTypeMap; + +// Compile a map of hard-coded string property types +static const PropertyNameTypeMap &stringPropertyTypes() +{ + static PropertyNameTypeMap propertyNameTypeMap; + if (propertyNameTypeMap.empty()) { + const StringPropertyParameters richtext(ValidationRichText, true); + // Accessibility. Both are texts the narrator reads + propertyNameTypeMap.insert(QLatin1String("accessibleDescription"), richtext); + propertyNameTypeMap.insert(QLatin1String("accessibleName"), richtext); + // object names + const StringPropertyParameters objectName(ValidationObjectName, false); + propertyNameTypeMap.insert(QLatin1String("buddy"), objectName); + propertyNameTypeMap.insert(QLatin1String("currentItemName"), objectName); + propertyNameTypeMap.insert(QLatin1String("currentPageName"), objectName); + propertyNameTypeMap.insert(QLatin1String("currentTabName"), objectName); + propertyNameTypeMap.insert(QLatin1String("layoutName"), objectName); + propertyNameTypeMap.insert(QLatin1String("spacerName"), objectName); + // Style sheet + propertyNameTypeMap.insert(QLatin1String("styleSheet"), StringPropertyParameters(ValidationStyleSheet, false)); + // Buttons/ QCommandLinkButton + const StringPropertyParameters multiline(ValidationMultiLine, true); + propertyNameTypeMap.insert(QLatin1String("description"), multiline); + propertyNameTypeMap.insert(QLatin1String("iconText"), multiline); + // Tooltips, etc. + propertyNameTypeMap.insert(QLatin1String("toolTip"), richtext); + propertyNameTypeMap.insert(QLatin1String("whatsThis"), richtext); + propertyNameTypeMap.insert(QLatin1String("windowIconText"), richtext); + propertyNameTypeMap.insert(QLatin1String("html"), richtext); + // A QWizard page id + propertyNameTypeMap.insert(QLatin1String("pageId"), StringPropertyParameters(ValidationSingleLine, false)); + // QPlainTextEdit + propertyNameTypeMap.insert(QLatin1String("plainText"), StringPropertyParameters(ValidationMultiLine, true)); + } + return propertyNameTypeMap; +} QDesignerPropertyEditor::QDesignerPropertyEditor(QWidget *parent, Qt::WindowFlags flags) : QDesignerPropertyEditorInterface(parent, flags) @@ -68,33 +108,19 @@ QDesignerPropertyEditor::StringPropertyParameters QDesignerPropertyEditor::textP return StringPropertyParameters(vm, false); } - // Accessibility. Both are texts the narrator reads - if (propertyName == QLatin1String("accessibleDescription") || propertyName == QLatin1String("accessibleName")) - return StringPropertyParameters(ValidationRichText, true); - - // Names - if (propertyName == QLatin1String("buddy") - || propertyName == QLatin1String("currentItemName") - || propertyName == QLatin1String("currentPageName") - || propertyName == QLatin1String("currentTabName") - || propertyName == QLatin1String("layoutName") - || propertyName == QLatin1String("spacerName")) - return StringPropertyParameters(ValidationObjectName, false); - - if (propertyName.endsWith(QLatin1String("Name"))) - return StringPropertyParameters(ValidationSingleLine, true); - - // Multi line? - if (propertyName == QLatin1String("styleSheet")) - return StringPropertyParameters(ValidationStyleSheet, false); - - if (propertyName == QLatin1String("description") || propertyName == QLatin1String("iconText")) // QCommandLinkButton - return StringPropertyParameters(ValidationMultiLine, true); + // Check custom widgets by class. + const QString className = WidgetFactory::classNameOf(core, object); + const QDesignerCustomWidgetData customData = core->pluginManager()->customWidgetData(className); + if (!customData.isNull()) { + StringPropertyParameters customType; + if (customData.xmlStringPropertyType(propertyName, &customType)) + return customType; + } - if (propertyName == QLatin1String("toolTip") || propertyName.endsWith(QLatin1String("ToolTip")) || - propertyName == QLatin1String("whatsThis") || - propertyName == QLatin1String("windowIconText") || propertyName == QLatin1String("html")) - return StringPropertyParameters(ValidationRichText, true); + // Check hardcoded property ames + const PropertyNameTypeMap::const_iterator hit = stringPropertyTypes().constFind(propertyName); + if (hit != stringPropertyTypes().constEnd()) + return hit.value(); // text: Check according to widget type. if (propertyName == QLatin1String("text")) { @@ -104,17 +130,17 @@ QDesignerPropertyEditor::StringPropertyParameters QDesignerPropertyEditor::textP return StringPropertyParameters(ValidationMultiLine, true); return StringPropertyParameters(ValidationRichText, true); } - if (propertyName == QLatin1String("pageId")) // A QWizard page id - return StringPropertyParameters(ValidationSingleLine, false); - if (propertyName == QLatin1String("plainText")) // QPlainTextEdit - return StringPropertyParameters(ValidationMultiLine, true); + // Fuzzy matching + if (propertyName.endsWith(QLatin1String("Name"))) + return StringPropertyParameters(ValidationSingleLine, true); + + if (propertyName.endsWith(QLatin1String("ToolTip"))) + return StringPropertyParameters(ValidationRichText, true); #ifdef Q_OS_WIN // No translation for the active X "control" property - if (propertyName == QLatin1String("control") && WidgetFactory::classNameOf(core, object) == QLatin1String("QAxWidget")) + if (propertyName == QLatin1String("control") && className == QLatin1String("QAxWidget")) return StringPropertyParameters(ValidationSingleLine, false); -#else - Q_UNUSED(core); #endif // default to single diff --git a/tools/designer/src/lib/shared/qdesigner_taskmenu.cpp b/tools/designer/src/lib/shared/qdesigner_taskmenu.cpp index cce0528..d85e18f 100644 --- a/tools/designer/src/lib/shared/qdesigner_taskmenu.cpp +++ b/tools/designer/src/lib/shared/qdesigner_taskmenu.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::QDesignerTaskMenu -*/ - #include "qdesigner_taskmenu_p.h" #include "qdesigner_command_p.h" #include "richtexteditor_p.h" diff --git a/tools/designer/src/lib/shared/qdesigner_toolbar.cpp b/tools/designer/src/lib/shared/qdesigner_toolbar.cpp index cb77801..898be1e 100644 --- a/tools/designer/src/lib/shared/qdesigner_toolbar.cpp +++ b/tools/designer/src/lib/shared/qdesigner_toolbar.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::Sentinel -*/ - #include "qdesigner_toolbar_p.h" #include "qdesigner_command_p.h" #include "actionrepository_p.h" @@ -65,7 +61,6 @@ TRANSLATOR qdesigner_internal::Sentinel #include <QtGui/QMenu> #include <QtGui/qevent.h> #include <QtGui/QApplication> -#include <QtGui/private/qtoolbarlayout_p.h> #include <QtCore/QDebug> Q_DECLARE_METATYPE(QAction*) @@ -445,11 +440,17 @@ QAction *ToolBarEventFilter::actionAt(const QToolBar *tb, const QPoint &pos) return tb->actions().at(index); } +//that's a trick to get acces to the initStyleOption which is a protected member +class FriendlyToolBar : public QToolBar { +public: + friend class ToolBarEventFilter; +}; + QRect ToolBarEventFilter::handleArea(const QToolBar *tb) { - const QToolBarLayout *tbl = qobject_cast<QToolBarLayout *>(tb->layout()); - Q_ASSERT(tbl); - return tbl->handleRect(); + QStyleOptionToolBar opt; + static_cast<const FriendlyToolBar*>(tb)->initStyleOption(&opt); + return tb->style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, tb); } bool ToolBarEventFilter::withinHandleArea(const QToolBar *tb, const QPoint &pos) diff --git a/tools/designer/src/lib/shared/qdesigner_widgetbox.cpp b/tools/designer/src/lib/shared/qdesigner_widgetbox.cpp index 5ba8ad7..d94a397 100644 --- a/tools/designer/src/lib/shared/qdesigner_widgetbox.cpp +++ b/tools/designer/src/lib/shared/qdesigner_widgetbox.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::QDesignerWidgetBox -*/ - #include "qdesigner_widgetbox_p.h" #include "qdesigner_utils_p.h" diff --git a/tools/designer/src/lib/shared/qsimpleresource.cpp b/tools/designer/src/lib/shared/qsimpleresource.cpp index 8d29002..69d48fd 100644 --- a/tools/designer/src/lib/shared/qsimpleresource.cpp +++ b/tools/designer/src/lib/shared/qsimpleresource.cpp @@ -41,6 +41,7 @@ #include "qsimpleresource_p.h" #include "widgetfactory_p.h" +#include "widgetdatabase_p.h" #include <formscriptrunner_p.h> #include <properties_p.h> @@ -57,6 +58,8 @@ #include <QtGui/QWidget> #include <QtGui/QAction> #include <QtCore/QDebug> +#include <QtCore/QCoreApplication> + QT_BEGIN_NAMESPACE @@ -267,6 +270,136 @@ bool QSimpleResource::warningsEnabled() return m_warningsEnabled; } +// Custom widgets handling helpers + +// Add unique fake slots and signals to lists +bool QSimpleResource::addFakeMethods(const DomSlots *domSlots, QStringList &fakeSlots, QStringList &fakeSignals) +{ + if (!domSlots) + return false; + + bool rc = false; + foreach (const QString &fakeSlot, domSlots->elementSlot()) + if (fakeSlots.indexOf(fakeSlot) == -1) { + fakeSlots += fakeSlot; + rc = true; + } + + foreach (const QString &fakeSignal, domSlots->elementSignal()) + if (fakeSignals.indexOf(fakeSignal) == -1) { + fakeSignals += fakeSignal; + rc = true; + } + return rc; +} + +void QSimpleResource::addFakeMethodsToWidgetDataBase(const DomCustomWidget *domCustomWidget, WidgetDataBaseItem *item) +{ + const DomSlots *domSlots = domCustomWidget->elementSlots(); + if (!domSlots) + return; + + // Merge in new slots, signals + QStringList fakeSlots = item->fakeSlots(); + QStringList fakeSignals = item->fakeSignals(); + if (addFakeMethods(domSlots, fakeSlots, fakeSignals)) { + item->setFakeSlots(fakeSlots); + item->setFakeSignals(fakeSignals); + } +} + +// Perform one iteration of adding the custom widgets to the database, +// looking up the base class and inheriting its data. +// Remove the succeeded custom widgets from the list. +// Classes whose base class could not be found are left in the list. + +void QSimpleResource::addCustomWidgetsToWidgetDatabase(const QDesignerFormEditorInterface *core, + QList<DomCustomWidget*>& custom_widget_list) +{ + QDesignerWidgetDataBaseInterface *db = core->widgetDataBase(); + for (int i=0; i < custom_widget_list.size(); ) { + bool classInserted = false; + DomCustomWidget *custom_widget = custom_widget_list[i]; + const QString customClassName = custom_widget->elementClass(); + const QString base_class = custom_widget->elementExtends(); + QString includeFile; + IncludeType includeType = IncludeLocal; + if (const DomHeader *header = custom_widget->elementHeader()) { + includeFile = header->text(); + if (header->hasAttributeLocation() && header->attributeLocation() == QLatin1String("global")) + includeType = IncludeGlobal; + } + const bool domIsContainer = custom_widget->elementContainer(); + // Append a new item + if (base_class.isEmpty()) { + WidgetDataBaseItem *item = new WidgetDataBaseItem(customClassName); + item->setPromoted(false); + item->setGroup(QCoreApplication::translate("Designer", "Custom Widgets")); + item->setIncludeFile(buildIncludeFile(includeFile, includeType)); + item->setContainer(domIsContainer); + item->setCustom(true); + addFakeMethodsToWidgetDataBase(custom_widget, item); + db->append(item); + custom_widget_list.removeAt(i); + classInserted = true; + } else { + // Create a new entry cloned from base class. Note that this will ignore existing + // classes, eg, plugin custom widgets. + QDesignerWidgetDataBaseItemInterface *item = + appendDerived(db, customClassName, QCoreApplication::translate("Designer", "Promoted Widgets"), + base_class, + buildIncludeFile(includeFile, includeType), + true,true); + // Ok, base class found. + if (item) { + // Hack to accommodate for old UI-files in which "container" is not set properly: + // Apply "container" from DOM only if true (else, eg classes from QFrame might not accept + // dropping child widgets on them as container=false). This also allows for + // QWidget-derived stacked pages. + if (domIsContainer) + item->setContainer(domIsContainer); + + addFakeMethodsToWidgetDataBase(custom_widget, static_cast<WidgetDataBaseItem*>(item)); + custom_widget_list.removeAt(i); + classInserted = true; + } + } + // Skip failed item. + if (!classInserted) + i++; + } + +} + +void QSimpleResource::handleDomCustomWidgets(const QDesignerFormEditorInterface *core, + const DomCustomWidgets *dom_custom_widgets) +{ + if (dom_custom_widgets == 0) + return; + QList<DomCustomWidget*> custom_widget_list = dom_custom_widgets->elementCustomWidget(); + // Attempt to insert each item derived from its base class. + // This should at most require two iterations in the event that the classes are out of order + // (derived first, max depth: promoted custom plugin = 2) + for (int iteration = 0; iteration < 2; iteration++) { + addCustomWidgetsToWidgetDatabase(core, custom_widget_list); + if (custom_widget_list.empty()) + return; + } + // Oops, there are classes left whose base class could not be found. + // Default them to QWidget with warnings. + const QString fallBackBaseClass = QLatin1String("QWidget"); + for (int i=0; i < custom_widget_list.size(); i++ ) { + DomCustomWidget *custom_widget = custom_widget_list[i]; + const QString customClassName = custom_widget->elementClass(); + const QString base_class = custom_widget->elementExtends(); + qDebug() << "** WARNING The base class " << base_class << " of the custom widget class " << customClassName + << " could not be found. Defaulting to " << fallBackBaseClass << '.'; + custom_widget->setElementExtends(fallBackBaseClass); + } + // One more pass. + addCustomWidgetsToWidgetDatabase(core, custom_widget_list); +} + // ------------ FormBuilderClipboard FormBuilderClipboard::FormBuilderClipboard(QWidget *w) diff --git a/tools/designer/src/lib/shared/qsimpleresource_p.h b/tools/designer/src/lib/shared/qsimpleresource_p.h index 8d45c3c..a25cb88 100644 --- a/tools/designer/src/lib/shared/qsimpleresource_p.h +++ b/tools/designer/src/lib/shared/qsimpleresource_p.h @@ -55,15 +55,21 @@ #include "shared_global_p.h" #include "abstractformbuilder.h" +#include <QtCore/QStringList> QT_BEGIN_NAMESPACE class DomScript; +class DomCustomWidgets; +class DomCustomWidget; +class DomSlots; class QDesignerFormEditorInterface; namespace qdesigner_internal { +class WidgetDataBaseItem; + class QDESIGNER_SHARED_EXPORT QSimpleResource : public QAbstractFormBuilder { public: @@ -92,6 +98,11 @@ public: static QString customWidgetScript(QDesignerFormEditorInterface *core, const QString &className); static bool hasCustomWidgetScript(QDesignerFormEditorInterface *core, QObject *object); + // Implementation for FormBuilder::createDomCustomWidgets() that adds + // the custom widgets to the widget database + static void handleDomCustomWidgets(const QDesignerFormEditorInterface *core, + const DomCustomWidgets *dom_custom_widgets); + protected: virtual QIcon nameToIcon(const QString &filePath, const QString &qrcPath); virtual QString iconToFilePath(const QIcon &pm) const; @@ -105,7 +116,13 @@ protected: typedef QList<DomScript*> DomScripts; static void addScript(const QString &script, ScriptSource source, DomScripts &domScripts); + static bool addFakeMethods(const DomSlots *domSlots, QStringList &fakeSlots, QStringList &fakeSignals); + private: + static void addCustomWidgetsToWidgetDatabase(const QDesignerFormEditorInterface *core, + QList<DomCustomWidget*>& custom_widget_list); + static void addFakeMethodsToWidgetDataBase(const DomCustomWidget *domCustomWidget, WidgetDataBaseItem *item); + static bool m_warningsEnabled; QDesignerFormEditorInterface *m_core; }; diff --git a/tools/designer/src/lib/shared/qtresourceview.cpp b/tools/designer/src/lib/shared/qtresourceview.cpp index 22439a2..34087ee 100644 --- a/tools/designer/src/lib/shared/qtresourceview.cpp +++ b/tools/designer/src/lib/shared/qtresourceview.cpp @@ -44,6 +44,7 @@ #include "qtresourcemodel_p.h" #include "qtresourceeditordialog_p.h" #include "iconloader_p.h" +#include "filterwidget_p.h" // For FilterWidget #include <QtDesigner/QDesignerFormEditorInterface> @@ -144,6 +145,7 @@ public: void slotReloadResources(); void slotCopyResourcePath(); void slotListWidgetContextMenuRequested(const QPoint &pos); + void slotFilterChanged(const QString &pattern); void createPaths(); QTreeWidgetItem *createPath(const QString &path, QTreeWidgetItem *parent); void createResources(const QString &path); @@ -152,16 +154,20 @@ public: void restoreSettings(); void saveSettings(); void updateActions(); + void filterOutResources(); QPixmap makeThumbnail(const QPixmap &pix) const; QDesignerFormEditorInterface *m_core; QtResourceModel *m_resourceModel; QToolBar *m_toolBar; + qdesigner_internal::FilterWidget *m_filterWidget; QTreeWidget *m_treeWidget; QListWidget *m_listWidget; QSplitter *m_splitter; - QMap<QString, QStringList> m_pathToContents; // full path to contents file names + QMap<QString, QStringList> m_pathToContents; // full path to contents file names (full path to its resource filenames) + QMap<QString, QString> m_pathToParentPath; // full path to full parent path + QMap<QString, QStringList> m_pathToSubPaths; // full path to full sub paths QMap<QString, QTreeWidgetItem *> m_pathToItem; QMap<QTreeWidgetItem *, QString> m_itemToPath; QMap<QString, QListWidgetItem *> m_resourceToItem; @@ -175,6 +181,7 @@ public: bool m_ignoreGuiSignals; QString m_settingsKey; bool m_resourceEditingEnabled; + QString m_filterPattern; }; QtResourceViewPrivate::QtResourceViewPrivate(QDesignerFormEditorInterface *core) : @@ -251,6 +258,12 @@ void QtResourceViewPrivate::slotListWidgetContextMenuRequested(const QPoint &pos menu.exec(m_listWidget->mapToGlobal(pos)); } +void QtResourceViewPrivate::slotFilterChanged(const QString &pattern) +{ + m_filterPattern = pattern; + filterOutResources(); +} + void QtResourceViewPrivate::storeExpansionState() { QMapIterator<QString, QTreeWidgetItem *> it(m_pathToItem); @@ -294,6 +307,7 @@ void QtResourceViewPrivate::updateActions() m_editResourcesAction->setVisible(m_resourceEditingEnabled); m_editResourcesAction->setEnabled(resourceActive); m_reloadResourcesAction->setEnabled(resourceActive); + m_filterWidget->setEnabled(resourceActive); } void QtResourceViewPrivate::slotResourceSetActivated(QtResourceSet *resourceSet) @@ -307,6 +321,8 @@ void QtResourceViewPrivate::slotResourceSetActivated(QtResourceSet *resourceSet) const QString currentResource = m_itemToResource.value(m_listWidget->currentItem()); m_treeWidget->clear(); m_pathToContents.clear(); + m_pathToParentPath.clear(); + m_pathToSubPaths.clear(); m_pathToItem.clear(); m_itemToPath.clear(); m_listWidget->clear(); @@ -320,6 +336,7 @@ void QtResourceViewPrivate::slotResourceSetActivated(QtResourceSet *resourceSet) q_ptr->selectResource(currentResource); else if (!currentPath.isEmpty()) q_ptr->selectResource(currentPath); + filterOutResources(); } void QtResourceViewPrivate::slotCurrentPathChanged(QTreeWidgetItem *item) @@ -362,9 +379,6 @@ void QtResourceViewPrivate::createPaths() const QString root(QLatin1Char(':')); - QMap<QString, QString> pathToParentPath; // full path to full parent path - QMap<QString, QStringList> pathToSubPaths; // full path to full sub paths - QMap<QString, QString> contents = m_resourceModel->contents(); QMapIterator<QString, QString> itContents(contents); while (itContents.hasNext()) { @@ -372,11 +386,11 @@ void QtResourceViewPrivate::createPaths() const QFileInfo fi(filePath); QString dirPath = fi.absolutePath(); m_pathToContents[dirPath].append(fi.fileName()); - while (!pathToParentPath.contains(dirPath) && dirPath != root) { + while (!m_pathToParentPath.contains(dirPath) && dirPath != root) { // create all parent paths const QFileInfo fd(dirPath); const QString parentDirPath = fd.absolutePath(); - pathToParentPath[dirPath] = parentDirPath; - pathToSubPaths[parentDirPath].append(dirPath); + m_pathToParentPath[dirPath] = parentDirPath; + m_pathToSubPaths[parentDirPath].append(dirPath); dirPath = parentDirPath; } } @@ -387,13 +401,126 @@ void QtResourceViewPrivate::createPaths() QPair<QString, QTreeWidgetItem *> pathToParentItem = pathToParentItemQueue.dequeue(); const QString path = pathToParentItem.first; QTreeWidgetItem *item = createPath(path, pathToParentItem.second); - QStringList subPaths = pathToSubPaths.value(path); + QStringList subPaths = m_pathToSubPaths.value(path); QStringListIterator itSubPaths(subPaths); while (itSubPaths.hasNext()) pathToParentItemQueue.enqueue(qMakePair(itSubPaths.next(), item)); } } +void QtResourceViewPrivate::filterOutResources() +{ + QMap<QString, bool> pathToMatchingContents; // true means the path has any matching contents + QMap<QString, bool> pathToVisible; // true means the path has to be shown + + // 1) we go from root path recursively. + // 2) we check every path if it contains at least one matching resource - if empty we add it + // to pathToMatchingContents and pathToVisible with false, if non empty + // we add it with true and change every parent path in pathToVisible to true. + // 3) we hide these items which has pathToVisible value false. + + const bool matchAll = m_filterPattern.isEmpty(); + const QString root(QLatin1Char(':')); + + QQueue<QString> pathQueue; + pathQueue.enqueue(root); + while (!pathQueue.isEmpty()) { + const QString path = pathQueue.dequeue(); + + QStringList fileNames = m_pathToContents.value(path); + QStringListIterator it(fileNames); + bool hasContents = matchAll; + if (!matchAll) { // the case filter is not empty - we check if the path contains anything + while (it.hasNext()) { + QString fileName = it.next(); + hasContents = fileName.contains(m_filterPattern, Qt::CaseInsensitive); + if (hasContents) // the path contains at least one resource which matches the filter + break; + } + } + + pathToMatchingContents[path] = hasContents; + pathToVisible[path] = hasContents; + + if (hasContents) { // if the path is going to be shown we need to show all its parent paths + QString parentPath = m_pathToParentPath.value(path); + while (!parentPath.isEmpty()) { + QString p = parentPath; + if (pathToVisible.value(p)) // parent path is already shown, we break the loop + break; + pathToVisible[p] = true; + parentPath = m_pathToParentPath.value(p); + } + } + + QStringList subPaths = m_pathToSubPaths.value(path); // we do the same for children paths + QStringListIterator itSubPaths(subPaths); + while (itSubPaths.hasNext()) + pathQueue.enqueue(itSubPaths.next()); + } + + // we setup here new path and resource to be activated + const QString currentPath = m_itemToPath.value(m_treeWidget->currentItem()); + QString newCurrentPath = currentPath; + QString currentResource = m_itemToResource.value(m_listWidget->currentItem()); + if (!matchAll) { + bool searchForNewPathWithContents = true; + + if (!currentPath.isEmpty()) { // if the currentPath is empty we will search for a new path too + QMap<QString, bool>::ConstIterator it = pathToMatchingContents.constFind(currentPath); + if (it != pathToMatchingContents.constEnd() && it.value()) // the current item has contents, we don't need to search for another path + searchForNewPathWithContents = false; + } + + if (searchForNewPathWithContents) { + // we find the first path with the matching contents + QMap<QString, bool>::ConstIterator itContents = pathToMatchingContents.constBegin(); + while (itContents != pathToMatchingContents.constEnd()) { + if (itContents.value()) { + newCurrentPath = itContents.key(); // the new path will be activated + break; + } + + itContents++; + } + } + + QFileInfo fi(currentResource); + if (!fi.fileName().contains(m_filterPattern, Qt::CaseInsensitive)) { // the case when the current resource is filtered out + const QStringList fileNames = m_pathToContents.value(newCurrentPath); + QStringListIterator it(fileNames); + while (it.hasNext()) { // we try to select the first matching resource from the newCurrentPath + QString fileName = it.next(); + if (fileName.contains(m_filterPattern, Qt::CaseInsensitive)) { + QDir dirPath(newCurrentPath); + currentResource = dirPath.absoluteFilePath(fileName); // the new resource inside newCurrentPath will be activated + break; + } + } + } + } + + QTreeWidgetItem *newCurrentItem = m_pathToItem.value(newCurrentPath); + if (currentPath != newCurrentPath) + m_treeWidget->setCurrentItem(newCurrentItem); + else + slotCurrentPathChanged(newCurrentItem); // trigger filtering on the current path + + QListWidgetItem *currentResourceItem = m_resourceToItem.value(currentResource); + if (currentResourceItem) { + m_listWidget->setCurrentItem(currentResourceItem); + m_listWidget->scrollToItem(currentResourceItem); + } + + QMapIterator<QString, bool> it(pathToVisible); // hide all paths filtered out + while (it.hasNext()) { + const QString path = it.next().key(); + QTreeWidgetItem *item = m_pathToItem.value(path); + if (item) + item->setHidden(!it.value()); + } +} + QTreeWidgetItem *QtResourceViewPrivate::createPath(const QString &path, QTreeWidgetItem *parent) { QTreeWidgetItem *item = 0; @@ -417,27 +544,32 @@ QTreeWidgetItem *QtResourceViewPrivate::createPath(const QString &path, QTreeWid void QtResourceViewPrivate::createResources(const QString &path) { + const bool matchAll = m_filterPattern.isEmpty(); + QDir dir(path); - QStringList files = m_pathToContents.value(path); - QStringListIterator it(files); + QStringList fileNames = m_pathToContents.value(path); + QStringListIterator it(fileNames); while (it.hasNext()) { - QString file = it.next(); - QString filePath = dir.absoluteFilePath(file); - QFileInfo fi(filePath); - if (fi.isFile()) { - QListWidgetItem *item = new QListWidgetItem(fi.fileName(), m_listWidget); - const QPixmap pix = QPixmap(filePath); - if (pix.isNull()) { - item->setToolTip(filePath); - } else { - item->setIcon(QIcon(makeThumbnail(pix))); - const QSize size = pix.size(); - item->setToolTip(QtResourceView::tr("Size: %1 x %2\n%3").arg(size.width()).arg(size.height()).arg(filePath)); + QString fileName = it.next(); + const bool showProperty = matchAll || fileName.contains(m_filterPattern, Qt::CaseInsensitive); + if (showProperty) { + QString filePath = dir.absoluteFilePath(fileName); + QFileInfo fi(filePath); + if (fi.isFile()) { + QListWidgetItem *item = new QListWidgetItem(fi.fileName(), m_listWidget); + const QPixmap pix = QPixmap(filePath); + if (pix.isNull()) { + item->setToolTip(filePath); + } else { + item->setIcon(QIcon(makeThumbnail(pix))); + const QSize size = pix.size(); + item->setToolTip(QtResourceView::tr("Size: %1 x %2\n%3").arg(size.width()).arg(size.height()).arg(filePath)); + } + item->setFlags(item->flags() | Qt::ItemIsDragEnabled); + item->setData(Qt::UserRole, filePath); + m_itemToResource[item] = filePath; + m_resourceToItem[filePath] = item; } - item->setFlags(item->flags() | Qt::ItemIsDragEnabled); - item->setData(Qt::UserRole, filePath); - m_itemToResource[item] = filePath; - m_resourceToItem[filePath] = item; } } } @@ -464,6 +596,11 @@ QtResourceView::QtResourceView(QDesignerFormEditorInterface *core, QWidget *pare connect(d_ptr->m_copyResourcePathAction, SIGNAL(triggered()), this, SLOT(slotCopyResourcePath())); d_ptr->m_copyResourcePathAction->setEnabled(false); + //d_ptr->m_filterWidget = new qdesigner_internal::FilterWidget(0, qdesigner_internal::FilterWidget::LayoutAlignNone); + d_ptr->m_filterWidget = new qdesigner_internal::FilterWidget(d_ptr->m_toolBar); + d_ptr->m_toolBar->addWidget(d_ptr->m_filterWidget); + connect(d_ptr->m_filterWidget, SIGNAL(filterChanged(QString)), this, SLOT(slotFilterChanged(QString))); + d_ptr->m_splitter = new QSplitter; d_ptr->m_splitter->setChildrenCollapsible(false); d_ptr->m_splitter->addWidget(d_ptr->m_treeWidget); diff --git a/tools/designer/src/lib/shared/qtresourceview_p.h b/tools/designer/src/lib/shared/qtresourceview_p.h index 1d3a1b0..7a96ddb 100644 --- a/tools/designer/src/lib/shared/qtresourceview_p.h +++ b/tools/designer/src/lib/shared/qtresourceview_p.h @@ -113,6 +113,7 @@ private: Q_PRIVATE_SLOT(d_func(), void slotReloadResources()) Q_PRIVATE_SLOT(d_func(), void slotCopyResourcePath()) Q_PRIVATE_SLOT(d_func(), void slotListWidgetContextMenuRequested(const QPoint &pos)) + Q_PRIVATE_SLOT(d_func(), void slotFilterChanged(const QString &pattern)) }; class QDESIGNER_SHARED_EXPORT QtResourceViewDialog : public QDialog diff --git a/tools/designer/src/lib/shared/richtexteditor.cpp b/tools/designer/src/lib/shared/richtexteditor.cpp index 8aa036b..42cf449 100644 --- a/tools/designer/src/lib/shared/richtexteditor.cpp +++ b/tools/designer/src/lib/shared/richtexteditor.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::RichTextEditorDialog -*/ - #include "richtexteditor_p.h" #include "htmlhighlighter_p.h" #include "iconselector_p.h" diff --git a/tools/designer/src/lib/shared/scriptdialog.cpp b/tools/designer/src/lib/shared/scriptdialog.cpp index 616f0c9..ef4d08f 100644 --- a/tools/designer/src/lib/shared/scriptdialog.cpp +++ b/tools/designer/src/lib/shared/scriptdialog.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::ScriptDialog -*/ - #include "scriptdialog_p.h" #include "qscripthighlighter_p.h" diff --git a/tools/designer/src/lib/shared/scripterrordialog.cpp b/tools/designer/src/lib/shared/scripterrordialog.cpp index c4a7e07..326cba2 100644 --- a/tools/designer/src/lib/shared/scripterrordialog.cpp +++ b/tools/designer/src/lib/shared/scripterrordialog.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::ScriptErrorDialog -*/ - #include "scripterrordialog_p.h" #include <QtGui/QTextEdit> diff --git a/tools/designer/src/lib/shared/stylesheeteditor.cpp b/tools/designer/src/lib/shared/stylesheeteditor.cpp index 2056fcf..de64135 100644 --- a/tools/designer/src/lib/shared/stylesheeteditor.cpp +++ b/tools/designer/src/lib/shared/stylesheeteditor.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::StyleSheetEditorDialog -*/ - #include "stylesheeteditor_p.h" #include "csshighlighter_p.h" #include "iconselector_p.h" diff --git a/tools/designer/src/lib/shared/widgetfactory.cpp b/tools/designer/src/lib/shared/widgetfactory.cpp index 3822fec..56a1744 100644 --- a/tools/designer/src/lib/shared/widgetfactory.cpp +++ b/tools/designer/src/lib/shared/widgetfactory.cpp @@ -39,10 +39,6 @@ ** ****************************************************************************/ -/* -TRANSLATOR qdesigner_internal::WidgetFactory -*/ - #include "widgetfactory_p.h" #include "widgetdatabase_p.h" #include "metadatabase_p.h" diff --git a/tools/designer/src/lib/shared/zoomwidget.cpp b/tools/designer/src/lib/shared/zoomwidget.cpp index f4ab48e..a404dcb 100644 --- a/tools/designer/src/lib/shared/zoomwidget.cpp +++ b/tools/designer/src/lib/shared/zoomwidget.cpp @@ -143,9 +143,10 @@ ZoomView::ZoomView(QWidget *parent) : m_zoom(100), m_zoomFactor(1.0), m_zoomContextMenuEnabled(false), - m_autoScrollSuppressed(true), m_zoomMenu(0) { + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setFrameShape(QFrame::NoFrame); setScene(m_scene); if (debugZoomWidget) @@ -187,8 +188,6 @@ void ZoomView::setZoom(int percent) resetTransform(); scale(m_zoomFactor, m_zoomFactor); - if (m_autoScrollSuppressed) - scrollToOrigin(); } void ZoomView::applyZoom() @@ -210,16 +209,6 @@ void ZoomView::setZoomContextMenuEnabled(bool e) m_zoomContextMenuEnabled = e; } -bool ZoomView::isAutoScrollSuppressed() const -{ - return m_autoScrollSuppressed; -} - -void ZoomView::setAutoScrollSuppressed(bool s) -{ - m_autoScrollSuppressed = s; -} - ZoomMenu *ZoomView::zoomMenu() { if (!m_zoomMenu) { @@ -469,13 +458,16 @@ void ZoomWidget::resizeEvent(QResizeEvent *event) * and the use the size ZoomView::resizeEvent(event); */ if (m_proxy && !m_viewResizeBlocked) { if (debugZoomWidget > 1) - qDebug() << ">ZoomWidget (" << size() << ")::resizeEvent from " << event->oldSize() << " to " << event->size(); + qDebug() << '>' << Q_FUNC_INFO << size() << ")::resizeEvent from " << event->oldSize() << " to " << event->size(); const QSizeF newViewPortSize = size() - viewPortMargin(); const QSizeF widgetSizeF = newViewPortSize / zoomFactor() - widgetDecorationSizeF(); m_widgetResizeBlocked = true; m_proxy->widget()->resize(widgetSizeF.toSize()); + setSceneRect(QRectF(QPointF(0, 0), widgetSizeF)); scrollToOrigin(); m_widgetResizeBlocked = false; + if (debugZoomWidget > 1) + qDebug() << '<' << Q_FUNC_INFO << widgetSizeF << m_proxy->widget()->size() << m_proxy->size(); } } @@ -559,7 +551,7 @@ QGraphicsProxyWidget *ZoomWidget::createProxyWidget(QGraphicsItem *parent, Qt::W void ZoomWidget::dump() const { - qDebug() << "ZoomWidget " << geometry() << " Viewport " << viewport()->geometry() + qDebug() << "ZoomWidget::dump " << geometry() << " Viewport " << viewport()->geometry() << "Scroll: " << scrollPosition() << "Matrix: " << matrix() << " SceneRect: " << sceneRect(); if (m_proxy) { qDebug() << "Proxy Pos: " << m_proxy->pos() << "Proxy " << m_proxy->size() diff --git a/tools/designer/src/lib/shared/zoomwidget_p.h b/tools/designer/src/lib/shared/zoomwidget_p.h index fe850f7..92c857e 100644 --- a/tools/designer/src/lib/shared/zoomwidget_p.h +++ b/tools/designer/src/lib/shared/zoomwidget_p.h @@ -104,8 +104,6 @@ class QDESIGNER_SHARED_EXPORT ZoomView : public QGraphicsView { Q_PROPERTY(int zoom READ zoom WRITE setZoom DESIGNABLE true SCRIPTABLE true) Q_PROPERTY(bool zoomContextMenuEnabled READ isZoomContextMenuEnabled WRITE setZoomContextMenuEnabled DESIGNABLE true SCRIPTABLE true) - Q_PROPERTY(bool autoScrollSuppressed READ isAutoScrollSuppressed WRITE setAutoScrollSuppressed DESIGNABLE true SCRIPTABLE true) - Q_OBJECT Q_DISABLE_COPY(ZoomView) public: @@ -120,10 +118,6 @@ public: bool isZoomContextMenuEnabled() const; void setZoomContextMenuEnabled(bool e); - // Suppress scrolling when changing zoom. Default: on - bool isAutoScrollSuppressed() const; - void setAutoScrollSuppressed(bool s); - QGraphicsScene &scene() { return *m_scene; } const QGraphicsScene &scene() const { return *m_scene; } @@ -149,8 +143,7 @@ private: int m_zoom; qreal m_zoomFactor; - bool m_zoomContextMenuEnabled; - bool m_autoScrollSuppressed; + bool m_zoomContextMenuEnabled; bool m_resizeBlocked; ZoomMenu *m_zoomMenu; }; |