diff options
author | Thomas Hartmann <Thomas.Hartmann@digia.com> | 2013-09-13 17:06:10 +0200 |
---|---|---|
committer | Thomas Hartmann <Thomas.Hartmann@digia.com> | 2013-09-16 13:36:58 +0200 |
commit | dce623b1bf026df0680b359bc8e36ce928e7aea1 (patch) | |
tree | 0fd32e38c7ebcae2491207ad32de6c7d7b54ed87 /src/plugins/qmldesigner/components | |
parent | cf56178df17db9a4840e52627ec89532c76c41e5 (diff) | |
download | qt-creator-dce623b1bf026df0680b359bc8e36ce928e7aea1.tar.gz |
QmlDesigner: Porting to Qt Quick 2
This patch ports our Qt Quick views to Qt Quick 2.
Change-Id: Ie0cfd81e7ebb76d2ed667211ad063feaaff5aa14
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
Diffstat (limited to 'src/plugins/qmldesigner/components')
43 files changed, 219 insertions, 3352 deletions
diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.qrc b/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.qrc index 1343c93988..4869a43d22 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.qrc +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.qrc @@ -3,7 +3,7 @@ <file>qml/ItemsView.qml</file> <file>qml/ItemsViewStyle.qml</file> <file>qml/SectionView.qml</file> - <file>qml/ItemView.qml</file> + <file>qml/SingleItemView.qml</file> <file>qml/Scrollbar.qml</file> <file>qml/Selector.qml</file> diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimageprovider.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimageprovider.cpp index 6e3898cabd..6912e09cbb 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimageprovider.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimageprovider.cpp @@ -33,7 +33,7 @@ namespace QmlDesigner { namespace Internal { ItemLibraryImageProvider::ItemLibraryImageProvider() : - QDeclarativeImageProvider(QDeclarativeImageProvider::Pixmap) + QQuickImageProvider(QQuickImageProvider::Pixmap) { } diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimageprovider.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimageprovider.h index 10e4277b75..ed8f7e57d6 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimageprovider.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryimageprovider.h @@ -30,13 +30,13 @@ #ifndef ITEMLIBRARYIMAGEPROVIDER_H #define ITEMLIBRARYIMAGEPROVIDER_H -#include <QDeclarativeImageProvider> +#include <QQuickImageProvider> namespace QmlDesigner { namespace Internal { -class ItemLibraryImageProvider : public QDeclarativeImageProvider +class ItemLibraryImageProvider : public QQuickImageProvider { public: ItemLibraryImageProvider(); diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h index cae9d2fbab..8fe62142db 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h @@ -33,7 +33,7 @@ #include <QMap> #include <QIcon> #include <QAbstractListModel> -#include <QtDeclarative> +#include <QtQuick> QT_FORWARD_DECLARE_CLASS(QMimeData) diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp index 49b43f4816..5f39710130 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp @@ -49,20 +49,16 @@ #include <QMenu> #include <QApplication> -#include <QDeclarativeItem> - +#include <QQuickItem> namespace QmlDesigner { - - - ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) : QFrame(parent), m_iconProvider(m_resIconSize), m_itemIconSize(24, 24), m_resIconSize(24, 24), - m_itemsView(new QDeclarativeView(this)), + m_itemsView(new QQuickView()), m_resourcesView(new Internal::ItemLibraryTreeView(this)), m_filterFlag(QtBasic) { @@ -71,15 +67,11 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) : setWindowTitle(tr("Library", "Title of library view")); /* create Items view and its model */ - m_itemsView->setAttribute(Qt::WA_OpaquePaintEvent); - m_itemsView->setAttribute(Qt::WA_NoSystemBackground); - m_itemsView->setAcceptDrops(false); - m_itemsView->setFocusPolicy(Qt::ClickFocus); - m_itemsView->setResizeMode(QDeclarativeView::SizeRootObjectToView); + m_itemsView->setResizeMode(QQuickView::SizeRootObjectToView); m_itemLibraryModel = new Internal::ItemLibraryModel(this); m_itemLibraryModel->setItemIconSize(m_itemIconSize); - QDeclarativeContext *rootContext = m_itemsView->rootContext(); + QQmlContext *rootContext = m_itemsView->rootContext(); rootContext->setContextProperty(QLatin1String("itemLibraryModel"), m_itemLibraryModel.data()); rootContext->setContextProperty(QLatin1String("itemLibraryIconWidth"), m_itemIconSize.width()); rootContext->setContextProperty(QLatin1String("itemLibraryIconHeight"), m_itemIconSize.height()); @@ -92,7 +84,7 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) : // loading the qml has to come after all needed context properties are set m_itemsView->setSource(QUrl("qrc:/ItemLibrary/qml/ItemsView.qml")); - QDeclarativeItem *rootItem = qobject_cast<QDeclarativeItem*>(m_itemsView->rootObject()); + QQuickItem *rootItem = qobject_cast<QQuickItem*>(m_itemsView->rootObject()); connect(rootItem, SIGNAL(itemSelected(int)), this, SLOT(showItemInfo(int))); connect(rootItem, SIGNAL(itemDragged(int)), this, SLOT(startDragAndDrop(int))); connect(this, SIGNAL(scrollItemsView(QVariant)), rootItem, SLOT(scrollView(QVariant))); @@ -133,8 +125,9 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) : lineEditLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Fixed, QSizePolicy::Fixed), 1, 2); connect(m_filterLineEdit.data(), SIGNAL(filterChanged(QString)), this, SLOT(setSearchFilter(QString))); + QWidget *container = createWindowContainer(m_itemsView.data()); m_stackedWidget = new QStackedWidget(this); - m_stackedWidget->addWidget(m_itemsView.data()); + m_stackedWidget->addWidget(container); m_stackedWidget->addWidget(m_resourcesView.data()); QWidget *spacer = new QWidget(this); @@ -375,7 +368,7 @@ void ItemLibraryWidget::startDragAndDrop(int itemLibId) drag->setPreview(QPixmap::fromImage(image)); drag->setMimeData(mimeData); - QDeclarativeItem *rootItem = qobject_cast<QDeclarativeItem*>(m_itemsView->rootObject()); + QQuickItem *rootItem = qobject_cast<QQuickItem*>(m_itemsView->rootObject()); connect(rootItem, SIGNAL(stopDragAndDrop()), drag, SLOT(stopDrag())); drag->exec(); @@ -386,16 +379,6 @@ void ItemLibraryWidget::showItemInfo(int /*itemLibId*/) // qDebug() << "showing item info about id" << itemLibId; } -void ItemLibraryWidget::wheelEvent(QWheelEvent *event) -{ - if (m_stackedWidget->currentIndex() == 0 && - m_itemsView->rect().contains(event->pos())) { - emit scrollItemsView(event->delta()); - event->accept(); - } else - QFrame::wheelEvent(event); -} - void ItemLibraryWidget::removeImport(const QString &name) { if (!m_model) diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h index b9f7635e5c..0369771d12 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h @@ -38,7 +38,7 @@ #include <QFrame> #include <QToolButton> #include <QFileIconProvider> -#include <QDeclarativeView> +#include <QQuickView> QT_BEGIN_NAMESPACE class QFileSystemModel; @@ -105,7 +105,6 @@ public slots: void onMeegoChecked(bool b); protected: - void wheelEvent(QWheelEvent *event); void removeImport(const QString &name); void addImport(const QString &name, const QString &version); void emitImportChecked(); @@ -131,8 +130,9 @@ private: QWeakPointer<QFileSystemModel> m_resourcesFileSystemModel; QWeakPointer<QStackedWidget> m_stackedWidget; + QWeakPointer<Utils::FilterLineEdit> m_filterLineEdit; - QScopedPointer<QDeclarativeView> m_itemsView; + QScopedPointer<QQuickView> m_itemsView; QScopedPointer<Internal::ItemLibraryTreeView> m_resourcesView; QWeakPointer<Model> m_model; diff --git a/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsView.qml b/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsView.qml index b81f405258..793d7ea7f0 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsView.qml +++ b/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsView.qml @@ -27,7 +27,7 @@ ** ****************************************************************************/ -import QtQuick 1.0 +import QtQuick 2.1 /* The view displaying the item grid. diff --git a/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsViewStyle.qml b/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsViewStyle.qml index 24b613182a..e5f29de94c 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsViewStyle.qml +++ b/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsViewStyle.qml @@ -27,7 +27,7 @@ ** ****************************************************************************/ -import QtQuick 1.0 +import QtQuick 2.1 // the style used the items view diff --git a/src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml b/src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml index 0e1dba8095..33bc50fc80 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml +++ b/src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml @@ -27,7 +27,7 @@ ** ****************************************************************************/ -import QtQuick 1.0 +import QtQuick 2.1 // scrollbar for the items view diff --git a/src/plugins/qmldesigner/components/itemlibrary/qml/SectionView.qml b/src/plugins/qmldesigner/components/itemlibrary/qml/SectionView.qml index 9f582f5baa..fc2c7d31b7 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/qml/SectionView.qml +++ b/src/plugins/qmldesigner/components/itemlibrary/qml/SectionView.qml @@ -27,7 +27,7 @@ ** ****************************************************************************/ -import QtQuick 1.0 +import QtQuick 2.1 // view displaying one item library section including its grid @@ -98,7 +98,7 @@ Column { Component { id: itemDelegate - ItemView { + SingleItemView { id: item width: cellWidth diff --git a/src/plugins/qmldesigner/components/itemlibrary/qml/Selector.qml b/src/plugins/qmldesigner/components/itemlibrary/qml/Selector.qml index a67d4bfb8d..9e6a30e048 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/qml/Selector.qml +++ b/src/plugins/qmldesigner/components/itemlibrary/qml/Selector.qml @@ -27,7 +27,7 @@ ** ****************************************************************************/ -import QtQuick 1.0 +import QtQuick 2.1 // the coloured selector of the items view diff --git a/src/plugins/qmldesigner/components/itemlibrary/qml/ItemView.qml b/src/plugins/qmldesigner/components/itemlibrary/qml/SingleItemView.qml index 659daf66b9..399c88bcb6 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/qml/ItemView.qml +++ b/src/plugins/qmldesigner/components/itemlibrary/qml/SingleItemView.qml @@ -27,8 +27,7 @@ ** ****************************************************************************/ -import QtQuick 1.0 - +import QtQuick 2.1 // view displaying an item library grid item Item { diff --git a/src/plugins/qmldesigner/components/propertyeditor/basiclayouts.cpp b/src/plugins/qmldesigner/components/propertyeditor/basiclayouts.cpp deleted file mode 100644 index bce02e81eb..0000000000 --- a/src/plugins/qmldesigner/components/propertyeditor/basiclayouts.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** 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 -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "basiclayouts.h" - - -QT_BEGIN_NAMESPACE - -QBoxLayoutObject::QBoxLayoutObject(QObject *parent) -: QLayoutObject(parent), _layout(0) -{ -} - -QBoxLayoutObject::QBoxLayoutObject(QBoxLayout *layout, QObject *parent) -: QLayoutObject(parent), _layout(layout) -{ -} - -QLayout *QBoxLayoutObject::layout() const -{ - return _layout; -} - -void QBoxLayoutObject::addWidget(QWidget *wid) -{ - _layout->addWidget(wid); -} - -void QBoxLayoutObject::clearWidget() -{ -} - -QHBoxLayoutObject::QHBoxLayoutObject(QObject *parent) -: QBoxLayoutObject(new QHBoxLayout, parent) -{ -} - - -QVBoxLayoutObject::QVBoxLayoutObject(QObject *parent) -: QBoxLayoutObject(new QVBoxLayout, parent) -{ -} - -QT_END_NAMESPACE - -void BasicLayouts::registerDeclarativeTypes() -{ - qmlRegisterType<QBoxLayoutObject>("Bauhaus",1,0,"QBoxLayout"); - qmlRegisterType<QHBoxLayoutObject>("Bauhaus",1,0,"QHBoxLayout"); - qmlRegisterType<QVBoxLayoutObject>("Bauhaus",1,0,"QVBoxLayout"); -} - diff --git a/src/plugins/qmldesigner/components/propertyeditor/basiclayouts.h b/src/plugins/qmldesigner/components/propertyeditor/basiclayouts.h deleted file mode 100644 index d4af8b4524..0000000000 --- a/src/plugins/qmldesigner/components/propertyeditor/basiclayouts.h +++ /dev/null @@ -1,177 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** 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 -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef BASICLAYOUTS_H -#define BASICLAYOUTS_H - -#include <qlayoutobject.h> - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QBoxLayoutObject : public QLayoutObject -{ - Q_OBJECT - - Q_PROPERTY(QDeclarativeListProperty<QWidget> children READ children) - - Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin) - Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin) - Q_PROPERTY(int leftMargin READ leftMargin WRITE setLeftMargin) - Q_PROPERTY(int rightMargin READ rightMargin WRITE setRightMargin) - Q_PROPERTY(int spacing READ spacing WRITE setSpacing) - - Q_CLASSINFO("DefaultProperty", "children") -public: - QBoxLayoutObject(QObject *parent=0); - explicit QBoxLayoutObject(QBoxLayout *, QObject *parent=0); - virtual QLayout *layout() const; - - QDeclarativeListProperty<QWidget> children() { - return QDeclarativeListProperty<QWidget>(this, 0, children_append, 0, 0, children_clear); - } - -private: - friend class WidgetList; - void addWidget(QWidget *); - void clearWidget(); - - static void children_append(QDeclarativeListProperty<QWidget> *property, QWidget *widget) { - static_cast<QBoxLayoutObject*>(property->object)->addWidget(widget); - } - - static void children_clear(QDeclarativeListProperty<QWidget> *property) { - static_cast<QBoxLayoutObject*>(property->object)->clearWidget(); - } - - void getMargins() - { - _layout->getContentsMargins(&mLeft, &mTop, &mRight, &mBottom); - } - - void setMargins() - { - _layout->setContentsMargins(mLeft, mTop, mRight, mBottom); - } - - int topMargin() - { - getMargins(); - return mTop; - } - - void setTopMargin(int margin) - { - getMargins(); - mTop = margin; - setMargins(); - } - - int bottomMargin() - { - getMargins(); - return mBottom; - } - - void setBottomMargin(int margin) - { - getMargins(); - mBottom = margin; - setMargins(); - } - - int leftMargin() - { - getMargins(); - return mLeft; - } - - void setLeftMargin(int margin) - { - getMargins(); - mLeft = margin; - setMargins(); - } - - int rightMargin() - { - getMargins(); - return mRight; - } - - void setRightMargin(int margin) - { - getMargins(); - mRight = margin; - setMargins(); - } - - int spacing() const - { - return _layout->spacing(); - } - - void setSpacing(int spacing) - { - _layout->setSpacing(spacing); - } - - QBoxLayout *_layout; - - int mTop, mLeft, mBottom, mRight; - -}; - -class QHBoxLayoutObject : public QBoxLayoutObject -{ -Q_OBJECT -public: - QHBoxLayoutObject(QObject *parent=0); -}; - -class QVBoxLayoutObject : public QBoxLayoutObject -{ -Q_OBJECT -public: - QVBoxLayoutObject(QObject *parent=0); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QBoxLayoutObject) -QML_DECLARE_TYPE(QHBoxLayoutObject) -QML_DECLARE_TYPE(QVBoxLayoutObject) - - -class BasicLayouts { -public: - static void registerDeclarativeTypes(); -}; - -#endif // BASICLAYOUTS_H diff --git a/src/plugins/qmldesigner/components/propertyeditor/basicwidgets.cpp b/src/plugins/qmldesigner/components/propertyeditor/basicwidgets.cpp deleted file mode 100644 index a513410b5e..0000000000 --- a/src/plugins/qmldesigner/components/propertyeditor/basicwidgets.cpp +++ /dev/null @@ -1,1458 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** 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 -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "basicwidgets.h" -#include <utils/fileutils.h> -#include <qlayoutobject.h> -#include <QDeclarativeContext> -#include <QDeclarativeComponent> -#include <QDebug> -#include <QFile> -#include <QPixmap> -#include <QTimeLine> -#include <QFileInfo> -#include <QMenu> -#include <QAction> -#include <QListView> -#include <QApplication> -#include <QGraphicsOpacityEffect> -#include <QStyleFactory> -#include <QScopedPointer> - -#include <QTextEdit> - - -QT_BEGIN_NAMESPACE - -class WindowsStyleSingleton -{ - public: - static WindowsStyleSingleton* instance(); - QStyle* style() { return m_style.data(); }; - - private: - static WindowsStyleSingleton *m_instance; - - QScopedPointer<QStyle> m_style; - - WindowsStyleSingleton() : m_style(QStyleFactory::create(QLatin1String("windows"))) {} - WindowsStyleSingleton( const WindowsStyleSingleton& ); - - class WindowsWatcher { - public: ~WindowsWatcher() { - if ( WindowsStyleSingleton::m_instance != 0 ) - delete WindowsStyleSingleton::m_instance; - } - }; - friend class WindowsWatcher; -}; - -WindowsStyleSingleton* WindowsStyleSingleton::m_instance = 0; - -WindowsStyleSingleton* WindowsStyleSingleton::instance() -{ - static WindowsWatcher w; - if ( m_instance == 0 ) - m_instance = new WindowsStyleSingleton(); - return m_instance; -} - - -class QWidgetDeclarativeUI; - -class ResizeEventFilter : public QObject -{ - Q_OBJECT -public: - ResizeEventFilter(QObject *parent) : QObject(parent), m_target(0) { } - - void setTarget(QObject *target) { m_target = target; } - void setDuiTarget(QWidgetDeclarativeUI* dui_target) {m_dui_target = dui_target;} - -protected: - bool eventFilter(QObject *obj, QEvent *event); -private: - QObject *m_target; - QWidgetDeclarativeUI* m_dui_target; -}; - -class QWidgetDeclarativeUI : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QDeclarativeListProperty<QObject> children READ children) - Q_PROPERTY(QLayoutObject *layout READ layout WRITE setLayout) - Q_PROPERTY(QDeclarativeListProperty<Action> actions READ actions) - Q_PROPERTY(QFont font READ font WRITE setFont) - - Q_PROPERTY(QPoint pos READ pos) - Q_PROPERTY(QSize size READ size) - - Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged) - Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged) - - Q_PROPERTY(int globalX READ globalX WRITE setGlobalX) - Q_PROPERTY(int globalY READ globalY WRITE setGlobalY) - - Q_PROPERTY(bool focus READ hasFocus NOTIFY focusChanged) - Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged) - Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged) - Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged) - - Q_PROPERTY(QUrl styleSheetFile READ styleSheetFile WRITE setStyleSheetFile) - - Q_PROPERTY(QColor windowColor READ windowColor WRITE setWindowColor) - Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) - Q_PROPERTY(QColor baseColor READ baseColor WRITE setBaseColor) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) - Q_PROPERTY(QColor windowTextColor READ windowTextColor WRITE setWindowTextColor) - Q_PROPERTY(QColor buttonTextColor READ buttonTextColor WRITE setButtonTextColor) - Q_PROPERTY(QColor buttonColor READ buttonColor WRITE setButtonColor) - - Q_PROPERTY(int fixedWidth READ width WRITE setFixedWidth) - Q_PROPERTY(int fixedHeight READ height WRITE setFixedHeight) - - Q_PROPERTY(bool mouseOver READ mouseOver NOTIFY mouseOverChanged) - - Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged) - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - - Q_CLASSINFO("DefaultProperty", "children") - -signals: - void xChanged(); - void yChanged(); - void widthChanged(); - void heightChanged(); - void focusChanged(); - void mouseOverChanged(); - void opacityChanged(); - void visibleChanged(); - void enabledChanged(); - -public: - QWidgetDeclarativeUI(QObject *other) : QObject(other), _layout(0), _graphicsOpacityEffect(0) { - q = qobject_cast<QWidget*>(other); - ResizeEventFilter *filter(new ResizeEventFilter(q)); - filter->setTarget(q); - filter->setDuiTarget(this); - m_mouseOver = false; - q->installEventFilter(filter); - q->setStyle(WindowsStyleSingleton::instance()->style()); - Q_ASSERT(q); - } - virtual ~QWidgetDeclarativeUI() { - } - -public: - - void setMouseOver(bool _mouseOver) - { - m_mouseOver = _mouseOver; - } - - void emitResize() - { - emit widthChanged(); - emit heightChanged(); - } - - void emitMove() - { - emit xChanged(); - emit yChanged(); - } - - void emitFocusChanged() - { - emit focusChanged(); - } - - void emitMouseOverChanged() - { - emit mouseOverChanged(); - } - - - void emitVisibleChanged() - { - emit visibleChanged(); - } - - void emitEnabledChanged() - { - emit enabledChanged(); - } - - QDeclarativeListProperty<QObject> children() { - return QDeclarativeListProperty<QObject>(this, 0, children_append, children_count, children_at, children_clear); - } - - QLayoutObject *layout() const { return _layout; } - void setLayout(QLayoutObject *lo) - { - _layout = lo; - static_cast<QWidget *>(parent())->setLayout(lo->layout()); - } - - QFont font() const - { - return _font; - } - - void setFont(const QFont &font) - { - if (font != _font) { - _font = font; - static_cast<QWidget *>(parent())->setFont(_font); - } - } - - int x() const { - return q->x(); - } - - int globalX() const { - if (q->parentWidget()) - return q->mapToGlobal(QPoint(x(), 0)).x(); - else - return x(); - } - - bool hasFocus() const { - return q->hasFocus(); - } - - bool mouseOver() const { - return m_mouseOver; - } - - void setX(int x) { - q->move(x, y()); - } - - void setGlobalX(int newX) { - if (q->parentWidget()) - setX(q->mapFromGlobal(QPoint(newX, 1)).x()); - else - setX(newX); - } - - int y() const { - return q->y(); - } - - bool visible() const { - return q->isVisible(); - } - - void setVisible(bool visible) { - q->setVisible(visible); - } - - bool enabled() const { - return q->isEnabled(); - } - - void setEnabled(bool enabled) { - q->setEnabled(enabled); - } - - int globalY() const { - if (q->parentWidget()) - return q->mapToGlobal(QPoint(1,y())).y(); - else return y(); - } - - qreal opacity() const { - if (_graphicsOpacityEffect) - return _graphicsOpacityEffect->opacity(); - else - return 1; - } - - void setOpacity(qreal newOpacity) { - if (newOpacity != opacity()) { - if (!_graphicsOpacityEffect) { - _graphicsOpacityEffect = new QGraphicsOpacityEffect(this); - q->setGraphicsEffect(_graphicsOpacityEffect); - } - _graphicsOpacityEffect->setOpacity(newOpacity); - emit opacityChanged(); - } - } - - void setY(int y) { - q->move(x(), y); - } - - void setGlobalY(int newY) { - if (q->parentWidget()) - setY(q->parentWidget()->mapFromGlobal(QPoint(1, newY)).y()); - else - setY(newY); - } - - int width() const { - return q->width(); - } - - void setWidth(int width) { - q->resize(width, height()); - } - - int height() const { - return q->height(); - } - - void setHeight(int height) { - q->resize(width(), height); - } - - void setFixedWidth(int width) { - q->setFixedWidth(width); - } - - void setFixedHeight(int height) { - q->setFixedHeight(height); - } - - QPoint pos() const { - return q->pos(); - } - - QSize size() const { - return q->size(); - } - - QUrl styleSheetFile() const { - return _styleSheetFile; - } - - QColor windowColor() const - { return q->palette().color(QPalette::Window); } - - void setWindowColor(const QColor &color) - { - QPalette pal = q->palette(); - pal.setColor(QPalette::Window, color); - q->setPalette(pal); - } - - QColor backgroundColor() const - { return q->palette().color(QPalette::Background); } - - void setBackgroundColor(const QColor &color) - { - QPalette pal = q->palette(); - pal.setColor(QPalette::Background, color); - q->setPalette(pal); - } - - QColor baseColor() const - { return q->palette().color(QPalette::Base); } - - void setBaseColor(const QColor &color) - { - QPalette pal = q->palette(); - pal.setColor(QPalette::Base, color); - q->setPalette(pal); - } - - QColor textColor() const - { return q->palette().color(QPalette::Text); } - - void setTextColor(const QColor &color) - { - QPalette pal = q->palette(); - pal.setColor(QPalette::Text, color); - q->setPalette(pal); - } - - QColor windowTextColor() const - { return q->palette().color(QPalette::WindowText); } - - void setWindowTextColor(const QColor &color) - { - QPalette pal = q->palette(); - pal.setColor(QPalette::WindowText, color); - q->setPalette(pal); - } - - QColor buttonTextColor() const - { return q->palette().color(QPalette::ButtonText); } - - void setButtonTextColor(const QColor &color) - { - QPalette pal = q->palette(); - pal.setColor(QPalette::ButtonText, color); - q->setPalette(pal); - } - - QColor buttonColor() const - { return q->palette().color(QPalette::Button); } - - void setButtonColor(const QColor &color) - { - QPalette pal = q->palette(); - pal.setColor(QPalette::Button, color); - q->setPalette(pal); - } - - - void setStyleSheetFile(const QUrl &url) { - _styleSheetFile = url; - _styleSheetFile.setScheme("file"); //### todo - QString fileName; - if (!QFileInfo(_styleSheetFile.toLocalFile()).exists()) - fileName = (QLatin1Char(':') + _styleSheetFile.toLocalFile().split(QLatin1Char(':')).last()); //try if it is a resource - else - fileName = (_styleSheetFile.toLocalFile()); - Utils::FileReader reader; - if (reader.fetch(fileName)) - q->setStyleSheet(QString::fromUtf8(reader.data())); - else - qWarning() << QString::fromUtf8("setStyleSheetFile: %1").arg(reader.errorString()); - - } - - QDeclarativeListProperty<Action> actions() { - return QDeclarativeListProperty<Action>(this, 0, actions_append, actions_count, actions_at, actions_clear); - } - -private: - QWidget *q; - QLayoutObject *_layout; - QFont _font; - QUrl _styleSheetFile; - QGraphicsOpacityEffect *_graphicsOpacityEffect; - bool m_mouseOver; - - static void children_append(QDeclarativeListProperty<QObject> *property, QObject *o) { - QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object); - QWidget *q = p->q; - if (QWidget *w = qobject_cast<QWidget *>(o)) - w->setParent(static_cast<QWidget *>(q)); - else - o->setParent(q); - } - - static int children_count(QDeclarativeListProperty<QObject> *property) { - QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object); - QWidget *q = p->q; - return q->children().count(); - } - - static QObject * children_at(QDeclarativeListProperty<QObject> *property, int index) { - QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object); - QWidget *q = p->q; - return q->children().at(index); - } - - static void children_clear(QDeclarativeListProperty<QObject> *property) { - QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object); - QWidget *q = p->q; - QObjectList c = q->children(); - for (int i = 0; i < c.count(); ++i) - c.at(i)->setParent(0); - } - - // ### Original had an insert, and removeAt - static void actions_append(QDeclarativeListProperty<Action> *property, Action *o) { - QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object); - QWidget *w = p->q; - o->setParent(w); - w->addAction(o); - } - - static int actions_count(QDeclarativeListProperty<Action> *property) { - QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object); - QWidget *w = p->q; - return w->actions().count(); - } - static Action *actions_at(QDeclarativeListProperty<Action> *property, int index) { - QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object); - QWidget *w = p->q; - return qobject_cast<Action *>(w->actions().at(index)); - } - - static void actions_clear(QDeclarativeListProperty<Action> *property) { - QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object); - QWidget *w = p->q; - - while (!w->actions().empty()) - w->removeAction(w->actions().first()); - } -}; - -bool ResizeEventFilter::eventFilter(QObject *obj, QEvent *event) -{ - if (event->type() == QEvent::Resize) { - if (obj - && obj->isWidgetType() - && obj == m_target) { - m_dui_target->emitResize(); - return QObject::eventFilter(obj, event); - } - } else if (event->type() == QEvent::Move) { - if (obj - && obj->isWidgetType() - && obj == m_target) { - m_dui_target->emitMove(); - return QObject::eventFilter(obj, event); - } - } else if ((event->type() == QEvent::FocusIn) || (event->type() == QEvent::FocusOut)) { - if (obj - && obj->isWidgetType() - && obj == m_target) { - m_dui_target->emitFocusChanged(); - return QObject::eventFilter(obj, event); - } - } else if ((event->type() == QEvent::Enter) || (event->type() == QEvent::Leave)) { - if (obj - && obj->isWidgetType() - && obj == m_target) { - m_dui_target->setMouseOver(event->type() == QEvent::Enter); - m_dui_target->emitMouseOverChanged(); - return QObject::eventFilter(obj, event); - } - } else if ((event->type() == QEvent::Show) || (event->type() == QEvent::Hide)) { - if (obj - && obj->isWidgetType() - && obj == m_target) { - m_dui_target->emitVisibleChanged(); - return QObject::eventFilter(obj, event); - } - } else if (event->type() == QEvent::EnabledChange) { - if (obj - && obj->isWidgetType() - && obj == m_target) { - m_dui_target->emitEnabledChanged(); - return QObject::eventFilter(obj,event); - } - } - return QObject::eventFilter(obj, event); -} - - -class QTabObject : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QWidget *content READ content WRITE setContent) - Q_PROPERTY(QString label READ label WRITE setLabel) - Q_PROPERTY(QIcon icon READ icon WRITE setIcon) - Q_CLASSINFO("DefaultProperty", "content") -public: - QTabObject(QObject *parent = 0) : QObject(parent), _content(0) {} - - QWidget *content() const { return _content; } - void setContent(QWidget *content) - { - _content = content; - } - - QString label() const { return _label; } - void setLabel(const QString &label) - { - _label = label; - } - - QIcon icon() const { return _icon; } - void setIcon(const QIcon &icon) - { - _icon = icon; - } - -private: - QWidget *_content; - QString _label; - QIcon _icon; -}; - -class QPushButtonDeclarativeUI : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QUrl iconFromFile READ iconFromFile WRITE setIconFromFile) -public: - QPushButtonDeclarativeUI(QObject *parent = 0) : QObject(parent) - { - pb = qobject_cast<QPushButton*>(parent); - } -private: - QUrl iconFromFile() const - { - return _url; - } - - void setIconFromFile(const QUrl &url) { - _url = url; - - QString path; - if (_url.scheme() == QLatin1String("qrc")) - path = QLatin1Char(':') + _url.path(); - else - path = _url.toLocalFile(); - - QFile file(path); - if (file.open(QIODevice::ReadOnly)) { - QPixmap pixmap(path); - if (pixmap.isNull()) - qWarning() << "setIconFromFile: failed to load" << path; - pb->setIcon(pixmap); - } else { - qWarning() << QString::fromUtf8("setIconFromFile: %1: %2").arg(path, file.errorString()); - } - - } - - QPushButton *pb; - QUrl _url; -}; - -class ElidingLabel : public QLabel -{ - Q_OBJECT -public: - ElidingLabel(QWidget * parent = 0) : QLabel(parent) {} - -protected: - void paintEvent(QPaintEvent *event) - { - QFontMetrics fm(font()); - if (fm.width(text()) > (contentsRect().width() - 8) && text().length() > 4) { - QPainter p(this); - QString elided_txt; - elided_txt = fm.elidedText(text(), Qt::ElideRight, contentsRect().width() - 8, Qt::TextShowMnemonic); - p.drawText(contentsRect().adjusted(12, 0, 0, 0), Qt::TextSingleLine, elided_txt); - } - else - QLabel::paintEvent(event); - } - -}; - - -class QLabelDeclarativeUI : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QUrl iconFromFile READ iconFromFile WRITE setIconFromFile) -public: - QLabelDeclarativeUI(QObject *parent = 0) : QObject(parent) - { - lb = qobject_cast<ElidingLabel*>(parent); - } -private: - QUrl iconFromFile() const - { - return _url; - } - - void setIconFromFile(const QUrl &url) { - _url = url; - - QString path; - if (_url.scheme() == QLatin1String("qrc")) - path = QLatin1Char(':') + _url.path(); - else - path = _url.toLocalFile(); - - QFile file(path); - if (file.open(QIODevice::ReadOnly)) { - QPixmap pixmap(path); - if (pixmap.isNull()) - qWarning() << "setIconFromFile: failed to load" << path; - lb->setPixmap(pixmap); - } else { - qWarning() << QString::fromUtf8("setIconFromFile: %1: %2").arg(path, file.errorString()); - } - - } - - ElidingLabel *lb; - QUrl _url; -}; - -class QMenuDeclarativeUI : public QObject -{ - Q_OBJECT - - Q_CLASSINFO("DefaultProperty", "actions") - -public: - QMenuDeclarativeUI(QObject *parent = 0) : QObject(parent) - { - menu = qobject_cast<QMenu*>(parent); - } - -private: - //if not for the at() function, we could use QDeclarativeList instead - - QMenu *menu; - -}; - -class QToolButtonDeclarativeUI : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QUrl iconFromFile READ iconFromFile WRITE setIconFromFile) - Q_PROPERTY(QMenu *menu READ menu WRITE setMenu) - -public: - QToolButtonDeclarativeUI(QObject *parent = 0) : QObject(parent) - { - pb = qobject_cast<QToolButton*>(parent); - } -private: - - QMenu *menu() const { return pb->menu(); } - void setMenu(QMenu *menu) - { - menu->setParent(0); - pb->setMenu(menu); - menu->setParent(QApplication::topLevelWidgets().first()); - } - - QUrl iconFromFile() const - { - return _url; - } - - void setIconFromFile(const QUrl &url) { - _url = url; - - QString path; - if (_url.scheme() == QLatin1String("qrc")) - path = QLatin1Char(':') + _url.path(); - else - path = _url.toLocalFile(); - - QFile file(path); - if (file.open(QIODevice::ReadOnly)) { - QPixmap pixmap(path); - if (pixmap.isNull()) - qWarning() << "setIconFromFile: failed to load" << path; - pb->setIcon(pixmap); - } else { - qWarning() << QString::fromUtf8("setIconFromFile: %1: %2").arg(path, file.errorString()); - } - - } - - QToolButton *pb; - QUrl _url; -}; - -class AnimatedToolButton : public QToolButton -{ - -Q_OBJECT - - Q_PROPERTY(QUrl hoverIconFromFile READ hoverIconFromFile WRITE setHoverIconFromFile) - -public: - AnimatedToolButton( QWidget * parent = 0 ) : QToolButton(parent) - {} - -private: - QUrl hoverIconFromFile() const - { return m_hoverIconUrl; } - - void setHoverIconFromFile(const QUrl &url) - { m_hoverIconUrl= url; - m_hoverIcon = QIcon(m_hoverIconUrl.toLocalFile()); - } - - void leaveEvent(QEvent *) - { - setIcon(m_icon); - } - - void enterEvent(QEvent *) - { - m_icon = icon(); - setIcon(m_hoverIcon); - } - - QUrl m_hoverIconUrl; - QIcon m_hoverIcon; - QIcon m_icon; - -}; - -class QComboBoxDeclarativeUI : public QObject -{ - Q_OBJECT - Q_PROPERTY(QStringList items READ items WRITE setItems) - Q_PROPERTY(QString currentText READ currentText WRITE setCurrentText NOTIFY currentTextChanged) - -public: - QComboBoxDeclarativeUI(QObject *parent = 0) : QObject(parent), m_itemsSet(false) - { - cb = qobject_cast<QComboBox*>(parent); - connect(cb, SIGNAL(currentIndexChanged(QString)), this, SLOT(setCurrentText(QString))); - } - - QString currentText() const - { - return cb->currentText(); - } - -public slots: - void setCurrentText(const QString &text) - { - if (!m_itemsSet) - return; - int i = cb->findText(text); - if (i != -1) { - cb->setCurrentIndex(i); - emit currentTextChanged(); - } - } -public slots: - void setCurrentTextSilent(const QString &text) - { - if (!m_itemsSet) - return; - int i = cb->findText(text); - if (i != -1) { - blockSignals(true); - cb->setCurrentIndex(i); - blockSignals(false); - } - } -signals: - void currentTextChanged(); - void itemsChanged(); - -private: - void setItems(const QStringList &list) - { - _items = list; - cb->clear(); - blockSignals(true); - cb->addItems(list); - m_itemsSet = true; - blockSignals(false); - emit itemsChanged(); - } - - QStringList items() const - { - return _items; - } - - QComboBox *cb; - QStringList _items; - - bool m_itemsSet; -}; - -class QScrollAreaDeclarativeUI : public QObject -{ - Q_OBJECT - Q_PROPERTY(QWidget *content READ content WRITE setContent) - Q_CLASSINFO("DefaultProperty", "content") - -public: - QScrollAreaDeclarativeUI(QObject *parent = 0) : QObject(parent), _content(0) - { - sa = qobject_cast<QScrollArea*>(parent); - } - -private: - QWidget *content() const { return _content; } - void setContent(QWidget *content) - { - _content = content; - sa->setWidget(content); - sa->verticalScrollBar()->show(); - } - - QWidget *_content; - QScrollArea *sa; -}; - - -class WidgetLoader : public QWidget -{ - Q_OBJECT - Q_PROPERTY(QString sourceString READ sourceString WRITE setSourceString NOTIFY sourceChanged) - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl) - Q_PROPERTY(QString qmlData READ qmlData WRITE setQmlData NOTIFY qmlDataChanged) - Q_PROPERTY(QWidget *widget READ widget NOTIFY widgetChanged) - Q_PROPERTY(QDeclarativeComponent *component READ component NOTIFY sourceChanged) - -public: - WidgetLoader(QWidget * parent = 0) : QWidget(parent), m_source(QUrl()), m_widget(0), - m_component(0), m_layout(0) - { - m_layout = new QVBoxLayout(this); - m_layout->setContentsMargins(0,0,0,0); - } - - QUrl source() const; - void setSource(const QUrl &); - QString qmlData() const; - void setQmlData(const QString &data); - - QString sourceString() const - { return m_source.toString(); } - void setSourceString(const QString &url) - { setSource(QUrl(url)); } - - QWidget *widget() const; - QDeclarativeComponent *component() const - { return m_component; } - - void setBaseUrl(const QUrl &baseUrl); - - QUrl baseUrl() const; - -signals: - void widgetChanged(); - void sourceChanged(); - void qmlDataChanged(); - -private: - QUrl m_source; - QUrl m_baseUrl; - QString m_qmlData; - QWidget *m_widget; - QDeclarativeComponent *m_component; - QVBoxLayout *m_layout; - QHash<QString, QWidget*> m_cachedWidgets; -}; - -QUrl WidgetLoader::source() const -{ - return m_source; -} - -QUrl WidgetLoader::baseUrl() const -{ - return m_baseUrl; -} - -void WidgetLoader::setBaseUrl(const QUrl &baseUrl) -{ - if (m_baseUrl == baseUrl) - return; - m_baseUrl = baseUrl; -} - -QString WidgetLoader::qmlData() const -{ - return m_qmlData; -} - -void WidgetLoader::setQmlData(const QString &data) -{ - if (m_qmlData == data) - return; - - m_qmlData = data; - - setSource(QUrl()); - - foreach (QWidget *cachedWidget, m_cachedWidgets) - cachedWidget->hide(); - - if (m_qmlData.isEmpty()) { - emit sourceChanged(); - emit widgetChanged(); - return; - } - - if (m_component) { - delete m_component; - m_component = 0; - } - - QString stringHash = QString::number(qHash(data)); - - if (m_cachedWidgets.contains(stringHash)) { - m_widget = m_cachedWidgets.value(stringHash); - m_widget->show(); - } else { - m_component = new QDeclarativeComponent(qmlEngine(this), this); - m_component->setData (m_qmlData.toUtf8(), m_baseUrl); - if (m_component) { - emit sourceChanged(); - emit widgetChanged(); - - while (m_component->isLoading()) - QApplication::processEvents(); - - if (!m_component->isReady()) { - if (!m_component->errors().isEmpty()) - qWarning() << m_component->errors(); - emit sourceChanged(); - return; - } - - QDeclarativeContext *ctxt = new QDeclarativeContext(qmlContext(this)); - ctxt->setContextObject(this); - QObject *obj = m_component->create(ctxt); - if (obj) { - QWidget *widget = qobject_cast<QWidget *>(obj); - if (widget) { - m_cachedWidgets.insert(stringHash, widget); - m_widget = widget; - m_layout->addWidget(m_widget); - m_widget->show(); - } - } - } - } - -} - -void WidgetLoader::setSource(const QUrl &source) -{ - if (m_source == source) - return; - - setQmlData(""); - -// QWidget *oldWidget = m_widget; - - if (m_widget) { - //m_widget->deleteLater(); - m_widget->hide(); - m_widget = 0; - } - - foreach (QWidget *cachedWidget, m_cachedWidgets) - cachedWidget->hide(); - - m_source = source; - if (m_source.isEmpty()) { - emit sourceChanged(); - emit widgetChanged(); - return; - } - - if (m_component) { - delete m_component; - m_component = 0; - } - - if (m_cachedWidgets.contains(source.toString())) { - m_widget = m_cachedWidgets.value(source.toString()); - m_widget->show(); - } else { - m_component = new QDeclarativeComponent(qmlEngine(this), m_source, this); - - if (m_component) { - emit sourceChanged(); - emit widgetChanged(); - - while (m_component->isLoading()) - QApplication::processEvents(); - - if (!m_component->isReady()) { - if (!m_component->errors().isEmpty()) - qWarning() << m_component->errors(); - emit sourceChanged(); - return; - } - - QDeclarativeContext *ctxt = new QDeclarativeContext(qmlContext(this)); - ctxt->setContextObject(this); - QObject *obj = m_component->create(ctxt); - if (obj) { - QWidget *widget = qobject_cast<QWidget *>(obj); - if (widget) { - m_cachedWidgets.insert(source.toString(), widget); - m_widget = widget; - m_layout->addWidget(m_widget); - m_widget->show(); - } - } - } - } -} - -QWidget *WidgetLoader::widget() const -{ - return m_widget; -} - -class MyGroupBox : public QGroupBox -{ - Q_OBJECT - - Q_PROPERTY(bool animated READ isAnimated) - -public: - MyGroupBox(QWidget * parent = 0) : QGroupBox(parent), m_animated(false), m_firstExpand(true) - {} - -void setPixmap(const QPixmap &pixmap, qreal alpha = 1) -{ m_pixmap = pixmap; m_alpha = alpha;} - -void setAnimated(bool animated) -{ m_animated = animated; } - -void finishFirstExpand() -{ m_firstExpand = false; } - -bool isAnimated() -{ return m_animated; } - -public slots: - virtual void setVisible ( bool visible ); - -protected: - virtual void paintEvent(QPaintEvent * event); -private: - qreal m_alpha; - QPixmap m_pixmap; - bool m_animated; - bool m_firstExpand; -}; - -void MyGroupBox::paintEvent(QPaintEvent * event) -{ - QGroupBox::paintEvent(event); - if (m_animated) { - QPainter p(this); - if (!m_pixmap.isNull() && !m_firstExpand) { - p.setOpacity(m_alpha); - p.drawPixmap(5, 5, m_pixmap.width(), m_pixmap.height(), m_pixmap); - } - } -} - -void MyGroupBox::setVisible ( bool visible ) -{ - if (parentWidget()) - QGroupBox::setVisible(visible); -} - -class QGroupBoxDeclarativeUI : public QObject -{ - Q_OBJECT - - Q_PROPERTY(bool collapsed READ isCollapsed WRITE setCollapsed) - Q_PROPERTY(bool smooth READ isSmooth WRITE setSmooth) -public: - QGroupBoxDeclarativeUI(QObject *parent = 0) : QObject(parent), m_expanded(true) - { - gb = qobject_cast<MyGroupBox*>(parent); - connect(&m_timeLine, SIGNAL (frameChanged(int)), this, SLOT(animate(int))); - connect(&m_timeLine, SIGNAL(finished()), this, SLOT(finish())); - - m_timeLine.setDuration(100); - m_timeLine.setFrameRange(0, 5); - m_smooth = true; - } - - bool isCollapsed() - { return ! m_expanded; } - - void setCollapsed(bool collapsed) - { - if (collapsed) - collapse(); - else - expand(); - } - - bool isSmooth() - { return m_smooth; } - void setSmooth(bool smooth) - { m_smooth = smooth; } - -public slots: - void collapse(); - void expand(); - - void animate(int frame); - void finish(); - -private: - MyGroupBox *gb; - QTimeLine m_timeLine; - bool m_expanded; - int m_oldHeight; - int m_oldMAxHeight; - int m_oldMinHeight; - QPixmap m_contens; - bool m_smooth; - - void hideChildren(); - void showChildren(); - - void reLayout(); -}; - -void QGroupBoxDeclarativeUI::reLayout() -{ - gb->setUpdatesEnabled(false); - QLayout *layout = gb->parentWidget()->layout(); - QPoint oldPos = gb->pos(); - if (layout) { - layout->invalidate(); - layout->activate(); - } - gb->move(oldPos); - gb->setUpdatesEnabled(true); - gb->update(); -} - -void QGroupBoxDeclarativeUI::finish() -{ - if (m_expanded) { - showChildren(); - gb->setUpdatesEnabled(false); - gb->setMinimumHeight(m_oldMinHeight); - gb->setMaximumHeight(m_oldMAxHeight); - gb->setUpdatesEnabled(true); - //gb->resize(gb->sizeHint()); - gb->finishFirstExpand(); - } else { - gb->setMinimumHeight(30); - gb->setMaximumHeight(30); - gb->resize(gb->sizeHint().width(), 30); - } - reLayout(); - gb->setAnimated(false); -} - -void QGroupBoxDeclarativeUI::hideChildren() -{ - if (gb->isVisible()) { - gb->setMinimumHeight(gb->height()); - foreach (QWidget *widget, gb->findChildren<QWidget*>()) - if (widget->parent() == gb) { - widget->setProperty("wasVisibleGB", widget->property("visible")); - widget->hide(); - } - } -} - -void QGroupBoxDeclarativeUI::showChildren() -{ - foreach (QWidget *widget, gb->findChildren<QWidget*>()) { - if (widget->parent() == gb) { - if (widget->property("wasVisibleGB").toBool()) - widget->show(); - widget->setProperty("wasVisibleGB", QVariant()); - widget->ensurePolished(); - } - } - gb->show(); -} - -void QGroupBoxDeclarativeUI::collapse() -{ - m_oldMAxHeight = gb->maximumHeight(); - m_oldHeight = gb->height(); - m_oldMinHeight =gb->minimumHeight(); - if (!m_expanded) - return; - -#if QT_VERSION < 0x050000 - m_contens = QPixmap::grabWidget(gb, 5, 5, gb->width() - 5, gb->height() - 5); -#else - m_contens = gb->grab(QRect(5, 5, gb->width() - 5, gb->height() - 5)); -#endif - gb->setPixmap(m_contens,1); - hideChildren(); - m_expanded = false; - gb->setAnimated(true); - m_timeLine.start(); -} - -void QGroupBoxDeclarativeUI::expand() -{ - if (m_expanded) - return; - m_expanded = true; - gb->setAnimated(true); - m_timeLine.start(); -} - -void QGroupBoxDeclarativeUI::animate(int frame) -{ - if (!m_smooth) - return; - qreal height; - - if (m_expanded) { - height = ((qreal(frame) / 5.0) * qreal(m_oldHeight)) + (30.0 * (1.0 - qreal(frame) / 5.0)); - gb->setPixmap(m_contens, qreal(frame) / 5.0); - } else { - height = ((qreal(frame) / 5.0) * 30.0) + (qreal(m_oldHeight) * (1.0 - qreal(frame) / 5.0)); - qreal alpha = 0.8 - qreal(frame) / 4.0; - if (alpha < 0) - alpha = 0; - gb->setPixmap(m_contens, alpha); - } - - gb->setMaximumHeight(height); - gb->setMinimumHeight(height); - reLayout(); -} - -class QTabWidgetDeclarativeUI : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QDeclarativeListProperty<QTabObject> tabs READ tabs) - Q_CLASSINFO("DefaultProperty", "tabs") -public: - QTabWidgetDeclarativeUI(QObject *other) : QObject(other) {} - - QDeclarativeListProperty<QTabObject> tabs() { - return QDeclarativeListProperty<QTabObject>(this, 0, tabs_append, 0, 0, tabs_clear); - } - -private: - static void tabs_append(QDeclarativeListProperty<QTabObject> *property, QTabObject *o) { - QTabWidget *tw = static_cast<QTabWidget*>(property->object->parent()); - if (!o->icon().isNull()) - tw->addTab(o->content(), o->icon(), o->label()); - else - tw->addTab(o->content(), o->label()); - } - - static void tabs_clear(QDeclarativeListProperty<QTabObject> *property) { - QTabWidget *tw = static_cast<QTabWidget*>(property->object->parent()); - tw->clear(); - } -}; - -class ExpressionEdit : public QPlainTextEdit -{ - Q_OBJECT -public: - ExpressionEdit(QWidget *parent = 0) : QPlainTextEdit(parent) {} -signals: - void returnPressed(); - -protected: - void keyPressEvent( QKeyEvent * e ); -}; - -void ExpressionEdit::keyPressEvent(QKeyEvent * e) -{ - if ((e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) && (e->modifiers() == Qt::NoModifier)) - emit returnPressed(); - else - QPlainTextEdit::keyPressEvent(e); -} - - -class WidgetFrame : public QFrame -{ - Q_OBJECT -public: - WidgetFrame( QWidget * parent = 0, Qt::WindowFlags f = 0 ) : QFrame(parent, f) - {} -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QTabObject) -QML_DECLARE_TYPE(MyGroupBox) -QML_DECLARE_TYPE(WidgetLoader) -QML_DECLARE_TYPE(WidgetFrame) -QML_DECLARE_TYPE(AnimatedToolButton) - -void BasicWidgets::registerDeclarativeTypes() -{ - qmlRegisterExtendedType<QWidget,QWidgetDeclarativeUI>("Bauhaus",1,0,"QWidget"); - - //display - qmlRegisterType<QProgressBar>("Bauhaus",1,0,"QProgressBar"); - qmlRegisterType<QLCDNumber>("Bauhaus",1,0,"QLCDNumber"); - - //input - qmlRegisterType<QLineEdit>("Bauhaus",1,0,"QLineEdit"); - qmlRegisterType<QTextEdit>("Bauhaus",1,0,"QTextEdit"); - qmlRegisterType<ExpressionEdit>("Bauhaus",1,0,"ExpressionEdit"); - qmlRegisterType<QPlainTextEdit>("Bauhaus",1,0,"QPlainTextEdit"); - qmlRegisterType<QSpinBox>("Bauhaus",1,0,"QSpinBox"); - qmlRegisterType<QDoubleSpinBox>("Bauhaus",1,0,"QDoubleSpinBox"); - qmlRegisterType<QSlider>("Bauhaus",1,0,"QSlider"); - qmlRegisterType<QDateTimeEdit>("Bauhaus",1,0,"QDateTimeEdit"); - qmlRegisterType<QDateEdit>("Bauhaus",1,0,"QDateEdit"); - qmlRegisterType<QTimeEdit>("Bauhaus",1,0,"QTimeEdit"); - qmlRegisterType<QFontComboBox>("Bauhaus",1,0,"QFontComboBox"); - qmlRegisterType<QDial>("Bauhaus",1,0,"QDial"); - qmlRegisterType<QScrollBar>("Bauhaus",1,0,"QScrollBar"); - qmlRegisterType<QCalendarWidget>("Bauhaus",1,0,"QCalendarWidget"); - - - //qmlRegisterType<>("Bauhaus",1,0,QComboBox,QComboBox); //need a way to populate - //QML_REGISTER_EXTENDED_TYPE(QComboBox,QComboBox, QComboBox); //need a way to populate - - //buttons - //qmlRegisterType<>("Bauhaus",1,0,QPushButton,QPushButton); - qmlRegisterType<QCheckBox>("Bauhaus",1,0,"QCheckBox"); - qmlRegisterType<QGroupBox>("Bauhaus",1,0,"QGroupBox"); - qmlRegisterType<Action>("Bauhaus",1,0,"QAction"); - qmlRegisterType<QRadioButton>("Bauhaus",1,0,"QRadioButton"); - qmlRegisterType<FileWidget>("Bauhaus",1,0,"FileWidget"); - qmlRegisterType<LayoutWidget>("Bauhaus",1,0,"LayoutWidget"); - - //containers - qmlRegisterType<QFrame>("Bauhaus",1,0,"QFrame"); - qmlRegisterType<WidgetFrame>("Bauhaus",1,0,"WidgetFrame"); - qmlRegisterType<WidgetLoader>("Bauhaus",1,0,"WidgetLoader"); - qmlRegisterType<AnimatedToolButton>("Bauhaus",1,0,"AnimatedToolButton"); - qmlRegisterExtendedType<MyGroupBox,QGroupBoxDeclarativeUI>("Bauhaus",1,0,"QExtGroupBox"); - qmlRegisterExtendedType<QTabWidget,QTabWidgetDeclarativeUI>("Bauhaus",1,0,"QTabWidget"); - qmlRegisterExtendedType<QScrollArea,QScrollAreaDeclarativeUI>("Bauhaus",1,0,"QScrollArea"); - qmlRegisterExtendedType<QPushButton,QPushButtonDeclarativeUI>("Bauhaus",1,0,"QPushButton"); - qmlRegisterExtendedType<ElidingLabel,QLabelDeclarativeUI>("Bauhaus",1,0,"QLabel"); - qmlRegisterExtendedType<QToolButton, QToolButtonDeclarativeUI>("Bauhaus",1,0,"QToolButton"); - qmlRegisterExtendedType<QComboBox, QComboBoxDeclarativeUI>("Bauhaus",1,0,"QComboBox"); - qmlRegisterExtendedType<QMenu, QMenuDeclarativeUI>("Bauhaus",1,0,"QMenu"); - //qmlRegisterType<>("Bauhaus",1,0,BauhausoolBox,BauhausoolBox); - //qmlRegisterType<>("Bauhaus",1,0,QScrollArea,QScrollArea); - - //QML_REGISTER_EXTENDED_TYPE(BauhausColorButton,BauhausColorButton,BauhausColorButtonDeclarativeUI); - - //itemviews - //qmlRegisterType<>("Bauhaus",1,0,QListView,QListView); - //qmlRegisterType<>("Bauhaus",1,0,BauhausreeView,BauhausreeView); - //qmlRegisterType<>("Bauhaus",1,0,BauhausableView,BauhausableView); - - qmlRegisterType<QTabObject>("Bauhaus",1,0,"QTabObject"); //### with namespacing, this should just be 'Tab' -} - -#include "basicwidgets.moc" diff --git a/src/plugins/qmldesigner/components/propertyeditor/basicwidgets.h b/src/plugins/qmldesigner/components/propertyeditor/basicwidgets.h deleted file mode 100644 index b4454acf94..0000000000 --- a/src/plugins/qmldesigner/components/propertyeditor/basicwidgets.h +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** 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 -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef BASICWIDGETS_H -#define BASICWIDGETS_H - -#include <qdeclarative.h> -#include <QGraphicsView> -#include <QLabel> -#include <QPushButton> -#include <QToolButton> -#include <QCheckBox> -#include <QRadioButton> -#include <QLineEdit> -#include <QTextEdit> -#include <QPlainTextEdit> -#include <QDoubleSpinBox> -#include <QSlider> -#include <QDateEdit> -#include <QTimeEdit> -#include <QProgressBar> -#include <QGroupBox> -#include <QDial> -#include <QLCDNumber> -#include <QFontComboBox> -#include <QScrollBar> -#include <QCalendarWidget> -#include <QTabWidget> -#include <QMenu> -#include <QAction> -#include "filewidget.h" -#include "layoutwidget.h" - -QML_DECLARE_TYPE(QWidget) - -//display -QML_DECLARE_TYPE(QLabel) -QML_DECLARE_TYPE(QProgressBar) -QML_DECLARE_TYPE(QLCDNumber) - -//input -QML_DECLARE_TYPE(QLineEdit) -QML_DECLARE_TYPE(QTextEdit) -QML_DECLARE_TYPE(QPlainTextEdit) -QML_DECLARE_TYPE(QSpinBox) -QML_DECLARE_TYPE(QDoubleSpinBox) -QML_DECLARE_TYPE(QSlider) -QML_DECLARE_TYPE(QDateTimeEdit) -QML_DECLARE_TYPE(QDateEdit) -QML_DECLARE_TYPE(QTimeEdit) -QML_DECLARE_TYPE(QFontComboBox) -QML_DECLARE_TYPE(QDial) -QML_DECLARE_TYPE(QScrollBar) -QML_DECLARE_TYPE(QCalendarWidget) -QML_DECLARE_TYPE(QComboBox) - -//buttons -QML_DECLARE_TYPE(QPushButton) -QML_DECLARE_TYPE(QToolButton) -QML_DECLARE_TYPE(QCheckBox) -QML_DECLARE_TYPE(QRadioButton) - -//containers -QML_DECLARE_TYPE(QGroupBox) -QML_DECLARE_TYPE(QFrame) -QML_DECLARE_TYPE(QScrollArea) -QML_DECLARE_TYPE(QTabWidget) -QML_DECLARE_TYPE(FileWidget) -QML_DECLARE_TYPE(LayoutWidget) - - -class Action : public QAction { - Q_OBJECT -public: - Action(QObject *parent = 0) : QAction(parent) {} -}; - -QML_DECLARE_TYPE(QMenu) -QML_DECLARE_TYPE(Action) - -//QML_DECLARE_TYPE(QToolBox) - -//itemviews -//QML_DECLARE_TYPE(QListView) -//QML_DECLARE_TYPE(QTreeView) -//QML_DECLARE_TYPE(QTableView) - -//top-level windows? -class BasicWidgets { -public: - static void registerDeclarativeTypes(); -}; - -#endif // BASICWIDGETS_H diff --git a/src/plugins/qmldesigner/components/propertyeditor/behaviordialog.cpp b/src/plugins/qmldesigner/components/propertyeditor/behaviordialog.cpp deleted file mode 100644 index 0b356add1d..0000000000 --- a/src/plugins/qmldesigner/components/propertyeditor/behaviordialog.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** 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 -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "behaviordialog.h" - -#include <abstractview.h> -#include <nodeproperty.h> -#include <variantproperty.h> -#include <bindingproperty.h> - - -namespace QmlDesigner { - -void BehaviorDialog::registerDeclarativeType() -{ - qmlRegisterType<QmlDesigner::BehaviorWidget>("Bauhaus",1,0,"BehaviorWidget"); -} - -BehaviorWidget::BehaviorWidget(QWidget *parent) : QPushButton(parent), m_BehaviorDialog(new BehaviorDialog) -{ - setCheckable(true); - connect(this, SIGNAL(toggled(bool)), this, SLOT(buttonPressed(bool))); -} - -PropertyEditorNodeWrapper* BehaviorWidget::complexNode() const -{ - return m_complexNode; -} - -void BehaviorWidget::setComplexNode(PropertyEditorNodeWrapper* complexNode) -{ - m_complexNode = complexNode; - m_propertyName = complexNode->propertyName(); - m_modelNode = complexNode->parentModelNode(); - - if (!modelNode().isValid()) - m_BehaviorDialog->hide(); - - m_BehaviorDialog->setup(modelNode(), propertyName()); -} - -void BehaviorWidget::buttonPressed(bool show) -{ - if (show) { - if (m_BehaviorDialog->isVisible()) { - m_BehaviorDialog->reject(); - } else { - m_BehaviorDialog->setup(modelNode(), propertyName()); - m_BehaviorDialog->show(); - setChecked(false); - } - } -} - -BehaviorDialog::BehaviorDialog(QWidget *parent) : QDialog(parent), m_ui(new Internal::Ui::BehaviorDialog) -{ - m_ui->setupUi(this); - setModal(true); -} - - void BehaviorDialog::setup(const ModelNode &node, const PropertyName propertyName) -{ - m_modelNode = node; - m_ui->duration->setValue(100); - m_ui->velocity->setValue(2); - m_ui->spring->setValue(2); - m_ui->damping->setValue(2); - m_ui->stackedWidget->setCurrentIndex(0); - m_ui->curve->setCurrentIndex(0); - - if (m_modelNode.isValid()) { - m_propertyName = propertyName; - m_ui->id->setText(m_modelNode.id()); - m_ui->type->setText(m_modelNode.simplifiedTypeName()); - m_ui->propertyName->setText(propertyName); - if (m_modelNode.hasProperty(m_propertyName) && m_modelNode.property(m_propertyName).isNodeProperty()) { - NodeProperty nodeProperty(m_modelNode.nodeProperty(m_propertyName)); - if (nodeProperty.modelNode().type() == "Qt/SpringFollow") { - ModelNode springFollow = nodeProperty.modelNode(); - m_ui->curve->setCurrentIndex(1); - m_ui->stackedWidget->setCurrentIndex(1); - if (springFollow.hasProperty("velocity") && springFollow.property("velocity").isVariantProperty()) - m_ui->velocity->setValue(springFollow.variantProperty("velocity").value().toDouble()); - if (springFollow.hasProperty("spring") && springFollow.property("spring").isVariantProperty()) - m_ui->spring->setValue(springFollow.variantProperty("spring").value().toDouble()); - if (springFollow.hasProperty("damping") && springFollow.property("damping").isVariantProperty()) - m_ui->damping->setValue(springFollow.variantProperty("damping").value().toDouble()); - if (springFollow.hasProperty("source") && springFollow.property("source").isVariantProperty()) - m_ui->source->setText(springFollow.variantProperty("source").value().toString()); - } else if (nodeProperty.modelNode().type() == "Qt/Behavior") { - if (nodeProperty.modelNode().hasProperty("animation") && - nodeProperty.modelNode().property("animation").isNodeProperty() && - nodeProperty.modelNode().nodeProperty("animation").modelNode().type() == "Qt/NumberAnimation") { - m_ui->curve->setCurrentIndex(0); - ModelNode animation = nodeProperty.modelNode().nodeProperty("animation").modelNode(); - if (animation.hasProperty("duration") && animation.property("duration").isVariantProperty()) - m_ui->duration->setValue(animation.variantProperty("duration").value().toInt()); - if (animation.hasProperty("easing") && animation.property("easing").isVariantProperty()) { - QStringList easingItems; - for (int i = 0; i < m_ui->curve->count(); i++) - easingItems.append(m_ui->curve->itemText(i)); - m_ui->curve->setCurrentIndex(easingItems.indexOf(animation.variantProperty("easing").value().toString())); - } - } - } - } - } -} - -void BehaviorDialog::accept() -{ - QDialog::accept(); - if (m_modelNode.hasProperty(m_propertyName)) - m_modelNode.removeProperty(m_propertyName); - if (m_ui->comboBox->currentIndex() == 0) { - RewriterTransaction transaction(m_modelNode.view()->beginRewriterTransaction()); - ModelNode Behavior = m_modelNode.view()->createModelNode("Qt/Behavior", 4, 7); - m_modelNode.nodeProperty(m_propertyName).reparentHere(Behavior); - ModelNode animation = m_modelNode.view()->createModelNode("Qt/NumberAnimation", 4, 7); - animation.variantProperty("duration").setValue(m_ui->duration->value()); - animation.variantProperty("easing").setValue(m_ui->curve->currentText()); - Behavior.nodeProperty("animation").reparentHere(animation); - } else { - RewriterTransaction transaction(m_modelNode.view()->beginRewriterTransaction()); - ModelNode springFollow = m_modelNode.view()->createModelNode("Qt/SpringFollow", 4, 7); - m_modelNode.nodeProperty(m_propertyName).reparentHere(springFollow); - springFollow.variantProperty("velocity").setValue(m_ui->velocity->value()); - springFollow.variantProperty("spring").setValue(m_ui->spring->value()); - springFollow.variantProperty("damping").setValue(m_ui->damping->value()); - springFollow.bindingProperty("source").setExpression(m_ui->source->text()); - } -} - -void BehaviorDialog::reject() -{ - QDialog::reject(); -} - -} diff --git a/src/plugins/qmldesigner/components/propertyeditor/behaviordialog.h b/src/plugins/qmldesigner/components/propertyeditor/behaviordialog.h deleted file mode 100644 index 26151d8f7e..0000000000 --- a/src/plugins/qmldesigner/components/propertyeditor/behaviordialog.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** 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 -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef BEHAVIORDIALOG_H -#define BEHAVIORDIALOG_H - -#include <modelnode.h> -#include <propertyeditorvalue.h> - -#include <QPushButton> -#include <QDialog> -#include <QScopedPointer> - -#include "ui_behaviordialog.h" - -namespace QmlDesigner { - -class BehaviorDialog; - -class BehaviorWidget : public QPushButton -{ - Q_PROPERTY(PropertyEditorNodeWrapper* complexNode READ complexNode WRITE setComplexNode) - - Q_OBJECT - -public: - explicit BehaviorWidget(QWidget *parent = 0); - - ModelNode modelNode() const {return m_modelNode; } - PropertyName propertyName() const {return m_propertyName; } - - PropertyEditorNodeWrapper* complexNode() const; - void setComplexNode(PropertyEditorNodeWrapper* complexNode); - -public slots: - void buttonPressed(bool); - -private: - ModelNode m_modelNode; - PropertyName m_propertyName; - PropertyEditorNodeWrapper* m_complexNode; - QScopedPointer<BehaviorDialog> m_BehaviorDialog; -}; - -class BehaviorDialog : public QDialog -{ - Q_OBJECT -public: - explicit BehaviorDialog(QWidget *parent = 0); - void setup(const ModelNode &node, const PropertyName propertyName); - -public slots: - virtual void accept(); - virtual void reject(); - - static void registerDeclarativeType(); - -private: - ModelNode m_modelNode; - PropertyName m_propertyName; - QScopedPointer<Internal::Ui::BehaviorDialog> m_ui; -}; - - -} - -QML_DECLARE_TYPE(QmlDesigner::BehaviorWidget) - -#endif// BEHAVIORDIALOG_H diff --git a/src/plugins/qmldesigner/components/propertyeditor/behaviordialog.ui b/src/plugins/qmldesigner/components/propertyeditor/behaviordialog.ui deleted file mode 100644 index 2d0d3257d2..0000000000 --- a/src/plugins/qmldesigner/components/propertyeditor/behaviordialog.ui +++ /dev/null @@ -1,472 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>QmlDesigner::Internal::BehaviorDialog</class> - <widget class="QDialog" name="QmlDesigner::Internal::BehaviorDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>269</width> - <height>354</height> - </rect> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="windowTitle"> - <string>Dialog</string> - </property> - <property name="styleSheet"> - <string notr="true">QDialog { -qlineargradient(spread:pad, x1:0.585, y1:0.0284091, x2:0.517, y2:1, stop:0 rgba(85, 85, 85, 255), stop:1 rgba(173, 173, 173, 255)) -} - -</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <widget class="QLabel" name="label"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="text"> - <string>Type:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="type"> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_3"> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="text"> - <string>ID:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="id"> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_5"> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="text"> - <string>Property name:</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QLineEdit" name="propertyName"> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="3" column="0" colspan="2"> - <widget class="QComboBox" name="comboBox"> - <item> - <property name="text"> - <string>Animation</string> - </property> - </item> - <item> - <property name="text"> - <string>SpringFollow</string> - </property> - </item> - </widget> - </item> - <item row="4" column="0" colspan="2"> - <widget class="QGroupBox" name="groupBox"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>120</height> - </size> - </property> - <property name="title"> - <string>Settings</string> - </property> - <layout class="QGridLayout" name="gridLayout_4"> - <item row="0" column="0"> - <widget class="QStackedWidget" name="stackedWidget"> - <property name="currentIndex"> - <number>0</number> - </property> - <widget class="QWidget" name="page"> - <layout class="QGridLayout" name="gridLayout_2"> - <item row="0" column="0"> - <widget class="QLabel" name="label_7"> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="text"> - <string>Duration:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QSpinBox" name="duration"> - <property name="maximum"> - <number>10000</number> - </property> - <property name="singleStep"> - <number>10</number> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_8"> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="text"> - <string>Curve:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QComboBox" name="curve"> - <item> - <property name="text"> - <string>easeNone</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInQuad</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutQuad</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInOutQuad</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutInQuad</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInCubic</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutCubic</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInOutCubic</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutInCubic</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutInBounce</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInOutBounce</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutBounce</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInBounce</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutInBack</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInOutBack</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutBack</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInBack</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutInElastic</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInOutElastic</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutElastic</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInElastic</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutInCirc</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInOutCirc</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutCirc</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInCirc</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutInExpo</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInOutExpo</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutExpo</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInExpo</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutInSine</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInOutSine</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeOutSine</string> - </property> - </item> - <item> - <property name="text"> - <string notr="true">easeInSine</string> - </property> - </item> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="page_2"> - <layout class="QGridLayout" name="gridLayout_3"> - <item row="0" column="0"> - <widget class="QLabel" name="label_2"> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="text"> - <string>Source:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="source"/> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_9"> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="text"> - <string>Velocity:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QDoubleSpinBox" name="velocity"/> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_10"> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="text"> - <string>Spring:</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QDoubleSpinBox" name="spring"/> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_11"> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="text"> - <string>Damping:</string> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QDoubleSpinBox" name="damping"/> - </item> - </layout> - </widget> - </widget> - </item> - </layout> - </widget> - </item> - <item row="5" column="0" colspan="2"> - <widget class="QDialogButtonBox" name="ButtonGroup"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections> - <connection> - <sender>ButtonGroup</sender> - <signal>accepted()</signal> - <receiver>QmlDesigner::Internal::BehaviorDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>248</x> - <y>254</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>ButtonGroup</sender> - <signal>rejected()</signal> - <receiver>QmlDesigner::Internal::BehaviorDialog</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>316</x> - <y>260</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>comboBox</sender> - <signal>currentIndexChanged(int)</signal> - <receiver>stackedWidget</receiver> - <slot>setCurrentIndex(int)</slot> - <hints> - <hint type="sourcelabel"> - <x>52</x> - <y>106</y> - </hint> - <hint type="destinationlabel"> - <x>121</x> - <y>191</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/src/plugins/qmldesigner/components/propertyeditor/designerpropertymap.h b/src/plugins/qmldesigner/components/propertyeditor/designerpropertymap.h index 3cace3d004..ebdfcf3225 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/designerpropertymap.h +++ b/src/plugins/qmldesigner/components/propertyeditor/designerpropertymap.h @@ -30,13 +30,13 @@ #ifndef DESIGNERPROPERTYMAP_H #define DESIGNERPROPERTYMAP_H -#include <QDeclarativePropertyMap> -#include <qdeclarative.h> +#include <QQmlPropertyMap> +#include <QtQml> namespace QmlDesigner { template <class DefaultType> -class DesignerPropertyMap : public QDeclarativePropertyMap +class DesignerPropertyMap : public QQmlPropertyMap { public: @@ -50,7 +50,7 @@ private: }; template <class DefaultType> -DesignerPropertyMap<DefaultType>::DesignerPropertyMap(QObject *parent) : QDeclarativePropertyMap(parent), m_defaultValue(this) +DesignerPropertyMap<DefaultType>::DesignerPropertyMap(QObject *parent) : QQmlPropertyMap(parent), m_defaultValue(this) { } @@ -58,7 +58,7 @@ template <class DefaultType> QVariant DesignerPropertyMap<DefaultType>::value(const QString &key) const { if (contains(key)) - return QDeclarativePropertyMap::value(key); + return QQmlPropertyMap::value(key); return QVariant(&m_defaultValue); } diff --git a/src/plugins/qmldesigner/components/propertyeditor/layoutwidget.cpp b/src/plugins/qmldesigner/components/propertyeditor/layoutwidget.cpp deleted file mode 100644 index 163ff72bcd..0000000000 --- a/src/plugins/qmldesigner/components/propertyeditor/layoutwidget.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** 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 -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "layoutwidget.h" -#include <QGridLayout> -#include <QFile> -#include <QDebug> - -QT_BEGIN_NAMESPACE - - -LayoutWidget::LayoutWidget(QWidget *parent) : QFrame(parent) -{ - QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - QGridLayout *grid = new QGridLayout(this); - setLayout(grid); - grid->setContentsMargins(0,0,0,0); - grid->setSpacing(4); - - m_topButton = new QPushButton(this); - m_topButton->setCheckable(true); - m_topButton->setSizePolicy(policy); - - grid->addWidget(m_topButton, 0, 2, 2, 1, Qt::AlignHCenter); - - m_bottomButton = new QPushButton(this); - m_bottomButton->setCheckable(true); - - m_bottomButton->setSizePolicy(policy); - - grid->addWidget(m_bottomButton, 3, 2, 2, 1, Qt::AlignHCenter); - - m_leftButton = new QPushButton(this); - m_leftButton->setCheckable(true); - m_leftButton->setSizePolicy(policy); - - - grid->addWidget(m_leftButton, 2, 0, 1, 2, Qt::AlignVCenter); - - m_rightButton = new QPushButton(this); - m_rightButton->setCheckable(true); - m_rightButton->setSizePolicy(policy); - - grid->addWidget(m_rightButton, 2, 3, 1, 2, Qt::AlignVCenter); - - - m_middleButton = new QPushButton(this); - - grid->addWidget(m_middleButton, 2, 2, 1, 1, Qt::AlignCenter); - - connect(m_topButton, SIGNAL(toggled(bool)), this, SLOT(setTopAnchor(bool))); - connect(m_bottomButton, SIGNAL(toggled(bool)), this, SLOT(setBottomAnchor(bool))); - connect(m_leftButton, SIGNAL(toggled(bool)), this, SLOT(setLeftAnchor(bool))); - connect(m_rightButton, SIGNAL(toggled(bool)), this, SLOT(setRightAnchor(bool))); - - connect(m_middleButton, SIGNAL(pressed()), this, SIGNAL(fill())); -} - -LayoutWidget::~LayoutWidget() -{ -} - - void LayoutWidget::setIcon(QPushButton *button, QUrl url) - { - if (url.scheme() == QLatin1String("file")) { - QFile file(url.toLocalFile()); - if (file.open(QIODevice::ReadOnly)) { - QPixmap pixmap(url.toLocalFile()); - button->setIcon(pixmap); - } else { - qWarning() << QString::fromUtf8("setIconFromFile: %1: %2").arg( - file.fileName(), file.errorString()); - } - } - } - -QT_END_NAMESPACE - - diff --git a/src/plugins/qmldesigner/components/propertyeditor/layoutwidget.h b/src/plugins/qmldesigner/components/propertyeditor/layoutwidget.h deleted file mode 100644 index 10288c4ea2..0000000000 --- a/src/plugins/qmldesigner/components/propertyeditor/layoutwidget.h +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** 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 -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - - -#ifndef LAYOUTWIDGET_H -#define LAYOUTWIDGET_H - -#include <QFrame> -#include <QPushButton> -#include <QUrl> - -QT_BEGIN_NAMESPACE - -class LayoutWidget : public QFrame -{ - Q_OBJECT - - Q_PROPERTY(bool leftAnchor READ leftAnchor WRITE setLeftAnchor NOTIFY leftAnchorChanged) - Q_PROPERTY(bool rightAnchor READ rightAnchor WRITE setRightAnchor NOTIFY rightAnchorChanged) - Q_PROPERTY(bool bottomAnchor READ bottomAnchor WRITE setBottomAnchor NOTIFY bottomAnchorChanged) - Q_PROPERTY(bool topAnchor READ topAnchor WRITE setTopAnchor NOTIFY topAnchorChanged) - - Q_PROPERTY(QUrl leftButtonIcon READ icon WRITE setLeftButtonIcon) - Q_PROPERTY(QUrl rightButtonIcon READ icon WRITE setRightButtonIcon) - Q_PROPERTY(QUrl topButtonIcon READ icon WRITE setTopButtonIcon) - Q_PROPERTY(QUrl bottomButtonIcon READ icon WRITE setBottomButtonIcon) - -public: - - void setLeftButtonIcon(const QUrl &url) - { setIcon(m_leftButton, url); } - - void setRightButtonIcon(const QUrl &url) - { setIcon(m_rightButton, url); } - - void setTopButtonIcon(const QUrl &url) - { setIcon(m_topButton, url); } - - void setBottomButtonIcon(const QUrl &url) - { setIcon(m_bottomButton, url); } - - QUrl icon() const {return QUrl(); } - - LayoutWidget(QWidget *parent = 0); - ~LayoutWidget(); - - bool leftAnchor() const { return m_leftAnchor; } - bool rightAnchor() const { return m_rightAnchor; } - bool topAnchor() const { return m_topAnchor; } - bool bottomAnchor() const { return m_bottomAnchor; } - -public slots: - void setLeftAnchor(bool anchor) - { - if (anchor == m_leftAnchor) - return; - m_leftAnchor = anchor; - m_leftButton->setChecked(anchor); - emit leftAnchorChanged(); - } - - void setRightAnchor(bool anchor) - { - if (anchor == m_rightAnchor) - return; - m_rightAnchor = anchor; - m_rightButton->setChecked(anchor); - emit rightAnchorChanged(); - } - - void setTopAnchor(bool anchor) - { - if (anchor == m_topAnchor) - return; - m_topAnchor = anchor; - m_topButton->setChecked(anchor); - emit topAnchorChanged(); - } - - void setBottomAnchor(bool anchor) - { - if (anchor == m_bottomAnchor) - return; - m_bottomAnchor = anchor; - m_bottomButton->setChecked(anchor); - emit bottomAnchorChanged(); - } - -signals: - //void colorChanged(const QColor &color); - void fill(); - void topAnchorChanged(); - void bottomAnchorChanged(); - void leftAnchorChanged(); - void rightAnchorChanged(); - -private: - void setIcon(QPushButton *button, QUrl url); - bool m_leftAnchor, m_rightAnchor, m_topAnchor, m_bottomAnchor; - QPushButton *m_leftButton; - QPushButton *m_rightButton; - QPushButton *m_topButton; - QPushButton *m_bottomButton; - QPushButton *m_middleButton; -}; - -QT_END_NAMESPACE - -#endif - diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri b/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri index 070cc02dcf..61874b4252 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri @@ -2,12 +2,6 @@ VPATH += $$PWD SOURCES += propertyeditorview.cpp \ qmlanchorbindingproxy.cpp \ - resetwidget.cpp \ - qlayoutobject.cpp \ - basiclayouts.cpp \ - basicwidgets.cpp \ - behaviordialog.cpp \ - layoutwidget.cpp \ filewidget.cpp \ propertyeditorvalue.cpp \ fontwidget.cpp \ @@ -15,19 +9,13 @@ SOURCES += propertyeditorview.cpp \ siblingcombobox.cpp \ propertyeditortransaction.cpp \ propertyeditorcontextobject.cpp \ - quickpropertyeditorview.cpp \ + quick2propertyeditorview.cpp \ gradientlineqmladaptor.cpp \ propertyeditorqmlbackend.cpp \ propertyeditorwidget.cpp HEADERS += propertyeditorview.h \ qmlanchorbindingproxy.h \ - resetwidget.h \ - qlayoutobject.h \ - basiclayouts.h \ - basicwidgets.h \ - behaviordialog.h \ - layoutwidget.h \ filewidget.h \ propertyeditorvalue.h \ fontwidget.h \ @@ -36,12 +24,11 @@ HEADERS += propertyeditorview.h \ propertyeditortransaction.h \ designerpropertymap.h \ propertyeditorcontextobject.h \ - quickpropertyeditorview.h \ + quick2propertyeditorview.h \ gradientlineqmladaptor.h \ propertyeditorqmlbackend.h \ propertyeditorwidget.h -QT += declarative +QT += qml quick RESOURCES += propertyeditor.qrc -FORMS += behaviordialog.ui diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp index ce6b27bafa..51d4517476 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp @@ -42,7 +42,6 @@ PropertyEditorContextObject::PropertyEditorContextObject(QObject *parent) : } - int PropertyEditorContextObject::majorVersion() const { return m_majorVersion; diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h index 407d823ea6..96f43da3ca 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h @@ -32,7 +32,7 @@ #include <QObject> #include <QUrl> -#include <QDeclarativePropertyMap> +#include <QQmlPropertyMap> #include <QColor> namespace QmlDesigner { @@ -53,7 +53,7 @@ class PropertyEditorContextObject : public QObject Q_PROPERTY(int majorVersion READ majorVersion WRITE setMajorVersion NOTIFY majorVersionChanged) Q_PROPERTY(int minorVersion READ minorVersion WRITE setMinorVersion NOTIFY minorVersionChanged) - Q_PROPERTY(QDeclarativePropertyMap* backendValues READ backendValues WRITE setBackendValues NOTIFY backendValuesChanged) + Q_PROPERTY(QQmlPropertyMap* backendValues READ backendValues WRITE setBackendValues NOTIFY backendValuesChanged) public: PropertyEditorContextObject(QObject *parent = 0); @@ -66,7 +66,7 @@ public: bool isBaseState() const { return m_isBaseState; } bool selectionChanged() const { return m_selectionChanged; } - QDeclarativePropertyMap* backendValues() const { return m_backendValues; } + QQmlPropertyMap* backendValues() const { return m_backendValues; } Q_INVOKABLE QString convertColorToString(const QColor &color) { return color.name(); } @@ -141,7 +141,7 @@ public slots: emit selectionChangedChanged(); } - void setBackendValues(QDeclarativePropertyMap* newBackendValues) + void setBackendValues(QQmlPropertyMap* newBackendValues) { if (newBackendValues == m_backendValues) return; @@ -165,7 +165,7 @@ private: bool m_isBaseState; bool m_selectionChanged; - QDeclarativePropertyMap* m_backendValues; + QQmlPropertyMap* m_backendValues; int m_majorVersion; int m_minorVersion; diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp index 4f53f2dab6..37fa5bc6df 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp @@ -52,7 +52,8 @@ enum { debug = false }; -const char resourcePropertyEditorPath[] = ":/propertyeditor"; +const char propertyEditorPath[] = "/propertyEditorQmlSources"; +const char resourcePropertyEditorPath[] = ":/propertyEditorQmlSources"; static QmlJS::SimpleReaderNode::Ptr s_templateConfiguration = QmlJS::SimpleReaderNode::Ptr(); @@ -118,7 +119,7 @@ static inline QString sharedDirPath() namespace QmlDesigner { PropertyEditorQmlBackend::PropertyEditorQmlBackend(PropertyEditorView *propertyEditor) : - m_view(new QuickPropertyEditorView), m_propertyEditorTransaction(new PropertyEditorTransaction(propertyEditor)), m_dummyPropertyEditorValue(new PropertyEditorValue()), + m_view(new Quick2PropertyEditorView), m_propertyEditorTransaction(new PropertyEditorTransaction(propertyEditor)), m_dummyPropertyEditorValue(new PropertyEditorValue()), m_contextObject(new PropertyEditorContextObject()) { Q_ASSERT(QFileInfo(":/images/button_normal.png").exists()); @@ -203,7 +204,7 @@ void PropertyEditorQmlBackend::setValue(const QmlObjectNode & qmlObjectNode, con } -QDeclarativeContext *PropertyEditorQmlBackend::context() { +QQmlContext *PropertyEditorQmlBackend::context() { return m_view->rootContext(); } @@ -338,7 +339,7 @@ void PropertyEditorQmlBackend::initialSetup(const TypeName &typeName, const QUrl } QString PropertyEditorQmlBackend::propertyEditorResourcesPath() { - return sharedDirPath() + QLatin1String("/propertyeditor"); + return sharedDirPath() + QLatin1String(propertyEditorPath); } QString PropertyEditorQmlBackend::templateGeneration(NodeMetaInfo type, diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h index 8d1d7482d4..844915bad9 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h @@ -34,7 +34,7 @@ #include "designerpropertymap.h" #include "propertyeditorvalue.h" #include "propertyeditorcontextobject.h" -#include "quickpropertyeditorview.h" +#include "quick2propertyeditorview.h" #include <nodemetainfo.h> @@ -54,7 +54,7 @@ public: void initialSetup(const TypeName &typeName, const QUrl &qmlSpecificsFile, PropertyEditorView *propertyEditor); void setValue(const QmlObjectNode &fxObjectNode, const PropertyName &name, const QVariant &value); - QDeclarativeContext *context(); + QQmlContext *context(); PropertyEditorContextObject* contextObject(); QWidget *widget(); void setSource(const QUrl& url); @@ -86,7 +86,7 @@ private: static QString fixTypeNameForPanes(const QString &typeName); private: - QuickPropertyEditorView *m_view; + Quick2PropertyEditorView *m_view; Internal::QmlAnchorBindingProxy m_backendAnchorBinding; DesignerPropertyMap<PropertyEditorValue> m_backendValuesPropertyMap; QScopedPointer<PropertyEditorTransaction> m_propertyEditorTransaction; diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp index c64d154752..80a7a4029f 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp @@ -266,7 +266,7 @@ void PropertyEditorValue::registerDeclarativeTypes() { qmlRegisterType<PropertyEditorValue>("Bauhaus",1,0,"PropertyEditorValue"); qmlRegisterType<PropertyEditorNodeWrapper>("Bauhaus",1,0,"PropertyEditorNodeWrapper"); - qmlRegisterType<QDeclarativePropertyMap>("Bauhaus",1,0,"QDeclarativePropertyMap"); + qmlRegisterType<QQmlPropertyMap>("Bauhaus",1,0,"QQmlPropertyMap"); } PropertyEditorNodeWrapper::PropertyEditorNodeWrapper(PropertyEditorValue* parent) : QObject(parent), m_valuesPropertyMap(this) @@ -306,7 +306,7 @@ QmlDesigner::PropertyName PropertyEditorNodeWrapper::propertyName() const return m_editorValue->name(); } -QDeclarativePropertyMap* PropertyEditorNodeWrapper::properties() +QQmlPropertyMap *PropertyEditorNodeWrapper::properties() { return &m_valuesPropertyMap; } diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.h index 9f485cc8a6..17c51944ca 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.h @@ -33,8 +33,8 @@ #include <qmldesignercorelib_global.h> #include <QObject> -#include <QDeclarativePropertyMap> -#include <qdeclarative.h> +#include <QQmlPropertyMap> +#include <QtQml> #include <modelnode.h> class PropertyEditorValue; @@ -43,7 +43,7 @@ class PropertyEditorNodeWrapper : public QObject { Q_OBJECT Q_PROPERTY(bool exists READ exists NOTIFY existsChanged) - Q_PROPERTY(QDeclarativePropertyMap* properties READ properties NOTIFY propertiesChanged) + Q_PROPERTY(QQmlPropertyMap* properties READ properties NOTIFY propertiesChanged) Q_PROPERTY(QString type READ type NOTIFY typeChanged) public: @@ -51,7 +51,7 @@ public: PropertyEditorNodeWrapper(PropertyEditorValue* parent); bool exists(); QString type(); - QDeclarativePropertyMap* properties(); + QQmlPropertyMap* properties(); QmlDesigner::ModelNode parentModelNode() const; QmlDesigner::PropertyName propertyName() const; @@ -70,7 +70,7 @@ private: void setup(); QmlDesigner::ModelNode m_modelNode; - QDeclarativePropertyMap m_valuesPropertyMap; + QQmlPropertyMap m_valuesPropertyMap; PropertyEditorValue* m_editorValue; }; @@ -152,7 +152,7 @@ private: //variables QML_DECLARE_TYPE(PropertyEditorValue) QML_DECLARE_TYPE(PropertyEditorNodeWrapper) -QML_DECLARE_TYPE(QDeclarativePropertyMap) +QML_DECLARE_TYPE(QQmlPropertyMap) #endif // PROPERTYEDITORVALUE_H diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp index efa5a3ea29..594f5265e9 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp @@ -85,7 +85,7 @@ PropertyEditorView::PropertyEditorView(QWidget *parent) : m_stackedWidget->insertWidget(0, new QWidget(m_stackedWidget)); - QuickPropertyEditorView::registerQmlTypes(); + Quick2PropertyEditorView::registerQmlTypes(); setQmlDir(PropertyEditorQmlBackend::propertyEditorResourcesPath()); m_stackedWidget->setWindowTitle(tr("Properties")); } diff --git a/src/plugins/qmldesigner/components/propertyeditor/quick2propertyeditorview.cpp b/src/plugins/qmldesigner/components/propertyeditor/quick2propertyeditorview.cpp new file mode 100644 index 0000000000..4184dc1bc6 --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/quick2propertyeditorview.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** 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 +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "quick2propertyeditorview.h" + +#include "propertyeditorvalue.h" + +#include <QVBoxLayout> + +namespace QmlDesigner { + +void Quick2PropertyEditorView::execute() +{ + m_view.setSource(m_source); + + if (!m_source.isEmpty()) { + m_view.setSource(m_source); + connect(&m_view, SIGNAL(statusChanged(QQuickView::Status)), this, SLOT(continueExecute())); + } +} + +Quick2PropertyEditorView::Quick2PropertyEditorView(QWidget *parent) : + QWidget(parent) +{ + m_containerWidget = createWindowContainer(&m_view); + + QVBoxLayout *layout = new QVBoxLayout(this); + setLayout(layout); + layout->addWidget(m_containerWidget); + layout->setMargin(0); + m_view.setResizeMode(QQuickView::SizeRootObjectToView); +} + +QUrl Quick2PropertyEditorView::source() const +{ + return m_source; +} + +void Quick2PropertyEditorView::setSource(const QUrl& url) +{ + m_source = url; + execute(); +} + +QQmlEngine* Quick2PropertyEditorView::engine() +{ + return m_view.engine(); +} + +QQmlContext* Quick2PropertyEditorView::rootContext() +{ + return engine()->rootContext(); +} + +Quick2PropertyEditorView::Status Quick2PropertyEditorView::status() const +{ + return Quick2PropertyEditorView::Status(m_view.status()); +} + + +void Quick2PropertyEditorView::continueExecute() +{ + disconnect(&m_view, SIGNAL(statusChanged(QQuickView::Status)), this, SLOT(continueExecute())); + + if (!m_view.errors().isEmpty()) { + QList<QQmlError> errorList = m_view.errors(); + foreach (const QQmlError &error, errorList) { + qWarning() << error; + } + emit statusChanged(status()); + return; + } + + emit statusChanged(status()); +} + +void Quick2PropertyEditorView::registerQmlTypes() +{ + static bool declarativeTypesRegistered = false; + if (!declarativeTypesRegistered) { + declarativeTypesRegistered = true; + PropertyEditorValue::registerDeclarativeTypes(); + } +} + +} //QmlDesigner diff --git a/src/plugins/qmldesigner/components/propertyeditor/quickpropertyeditorview.h b/src/plugins/qmldesigner/components/propertyeditor/quick2propertyeditorview.h index b1a8839342..d1e916df58 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/quickpropertyeditorview.h +++ b/src/plugins/qmldesigner/components/propertyeditor/quick2propertyeditorview.h @@ -27,37 +27,35 @@ ** ****************************************************************************/ -#ifndef QUICKPROERTYEDITORVIEW_H -#define QUICKPROERTYEDITORVIEW_H +#ifndef QUICK2PROERTYEDITORVIEW_H +#define QUICK2PROERTYEDITORVIEW_H #include <QWidget> #include <QUrl> -#include <QDeclarativeEngine> -#include <QDeclarativeContext> +#include <QQuickView> +#include <QQmlEngine> +#include <QQmlContext> QT_BEGIN_NAMESPACE -class QDeclarativeContext; -class QDeclarativeError; -class QDeclarativeComponent; +class QQmlError; +class QQmlComponent; QT_END_NAMESPACE namespace QmlDesigner { -class QuickPropertyEditorView : public QWidget +class Quick2PropertyEditorView : public QWidget { Q_OBJECT Q_PROPERTY(QUrl source READ source WRITE setSource DESIGNABLE true) public: - explicit QuickPropertyEditorView(QWidget *parent = 0); + explicit Quick2PropertyEditorView(QWidget *parent = 0); QUrl source() const; void setSource(const QUrl&); - QDeclarativeEngine* engine(); - QDeclarativeContext* rootContext(); - - QWidget *rootWidget() const; + QQmlEngine* engine(); + QQmlContext* rootContext(); enum Status { Null, Ready, Loading, Error }; Status status() const; @@ -65,23 +63,22 @@ public: static void registerQmlTypes(); signals: - void statusChanged(QuickPropertyEditorView::Status); + void statusChanged(Quick2PropertyEditorView::Status); protected: - void setRootWidget(QWidget *); void execute(); private Q_SLOTS: void continueExecute(); private: - QScopedPointer<QWidget> m_root; + QWidget *m_containerWidget; QUrl m_source; - QDeclarativeEngine m_engine; - QWeakPointer<QDeclarativeComponent> m_component; + QQuickView m_view; + QWeakPointer<QQmlComponent> m_component; }; } //QmlDesigner -#endif // QUICKPROERTYEDITORVIEW_H +#endif // QUICK2PROERTYEDITORVIEW_H diff --git a/src/plugins/qmldesigner/components/propertyeditor/quickpropertyeditorview.cpp b/src/plugins/qmldesigner/components/propertyeditor/quickpropertyeditorview.cpp deleted file mode 100644 index d4ac338eb4..0000000000 --- a/src/plugins/qmldesigner/components/propertyeditor/quickpropertyeditorview.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** 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 -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "quickpropertyeditorview.h" - -#include "basiclayouts.h" -#include "basicwidgets.h" -#include "resetwidget.h" -#include "qlayoutobject.h" -#include <qmleditorwidgets/colorwidgets.h> -#include "gradientlineqmladaptor.h" -#include "behaviordialog.h" -#include "fontwidget.h" -#include "siblingcombobox.h" -#include "originwidget.h" - -#include <QDeclarativeItem> -#include <QDeclarativeEngine> -#include <QDeclarativeContext> - -namespace QmlDesigner { - -void QuickPropertyEditorView::execute() -{ - if (m_root) - delete m_root.data(); - - if (m_component) - delete m_component.data(); - - if (!m_source.isEmpty()) { - m_component = new QDeclarativeComponent(&m_engine, m_source, this); - if (!m_component->isLoading()) - continueExecute(); - else - connect(m_component.data(), SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(continueExecute())); - } -} - -QuickPropertyEditorView::QuickPropertyEditorView(QWidget *parent) : - QWidget(parent) -{ -} - -QUrl QuickPropertyEditorView::source() const -{ - return m_source; -} - -void QuickPropertyEditorView::setSource(const QUrl& url) -{ - m_source = url; - execute(); -} - -QDeclarativeEngine* QuickPropertyEditorView::engine() -{ - return &m_engine; -} - -QWidget *QuickPropertyEditorView::rootWidget() const -{ - return m_root.data(); -} - -QDeclarativeContext* QuickPropertyEditorView::rootContext() -{ - return m_engine.rootContext(); -} - -QuickPropertyEditorView::Status QuickPropertyEditorView::status() const -{ - if (!m_component) - return QuickPropertyEditorView::Null; - - return QuickPropertyEditorView::Status(m_component->status()); -} - - -void QuickPropertyEditorView::continueExecute() -{ - - disconnect(m_component.data(), SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(continueExecute())); - - if (m_component->isError()) { - QList<QDeclarativeError> errorList = m_component->errors(); - foreach (const QDeclarativeError &error, errorList) { - qWarning() << error; - } - emit statusChanged(status()); - return; - } - - QObject *obj = m_component->create(); - - if (m_component->isError()) { - QList<QDeclarativeError> errorList = m_component->errors(); - foreach (const QDeclarativeError &error, errorList) { - qWarning() << error; - } - emit statusChanged(status()); - return; - } - - setRootWidget(qobject_cast<QWidget *>(obj)); - emit statusChanged(status()); -} - -void QuickPropertyEditorView::setRootWidget(QWidget *widget) -{ - if (m_root.data() == widget) - return; - - window()->setAttribute(Qt::WA_OpaquePaintEvent, false); - window()->setAttribute(Qt::WA_NoSystemBackground, false); - widget->setParent(this); - if (isVisible()) - widget->setVisible(true); - resize(widget->size()); - m_root.reset(widget); - - if (m_root) { - QSize initialSize = m_root->size(); - if (initialSize != size()) - resize(initialSize); - } -} - -void QuickPropertyEditorView::registerQmlTypes() -{ - - static bool declarativeTypesRegistered = false; - if (!declarativeTypesRegistered) { - declarativeTypesRegistered = true; - BasicWidgets::registerDeclarativeTypes(); - BasicLayouts::registerDeclarativeTypes(); - ResetWidget::registerDeclarativeType(); - QLayoutObject::registerDeclarativeType(); - QmlEditorWidgets::ColorWidgets::registerDeclarativeTypes(); - BehaviorDialog::registerDeclarativeType(); - PropertyEditorValue::registerDeclarativeTypes(); - FontWidget::registerDeclarativeTypes(); - SiblingComboBox::registerDeclarativeTypes(); - OriginWidget::registerDeclarativeType(); - GradientLineQmlAdaptor::registerDeclarativeType(); - } -} - -} //QmlDesigner diff --git a/src/plugins/qmldesigner/components/propertyeditor/resetwidget.cpp b/src/plugins/qmldesigner/components/propertyeditor/resetwidget.cpp deleted file mode 100644 index f53658ba4c..0000000000 --- a/src/plugins/qmldesigner/components/propertyeditor/resetwidget.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** 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 -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - - -#include "resetwidget.h" -#include "qdeclarative.h" -#include <QVBoxLayout> -#include <QTableWidget> -#include <QHeaderView> -#include <QPushButton> - -#include <QDebug> -#include <QApplication> - -QML_DECLARE_TYPE(QmlDesigner::ResetWidget) - -namespace QmlDesigner { - - -ResetWidget::ResetWidget(QWidget *parent) : QGroupBox(parent), m_backendObject(0) -{ - m_vlayout = new QVBoxLayout(this); - m_vlayout->setContentsMargins(2,2,2,2); - - QPushButton *b = new QPushButton(this); - b->setText(tr("Reset All Properties")); - m_vlayout->addWidget(b); - - setLayout(m_vlayout); -} - -void ResetWidget::registerDeclarativeType() -{ - qmlRegisterType<QmlDesigner::ResetWidget>("Bauhaus", 1, 0, "ResetWidget"); -} - -void ResetWidget::resetView() -{ - m_tableWidget->clear(); - delete m_tableWidget; - setupView(); -} - -void ResetWidget::setupView() -{ - m_tableWidget = new QTableWidget(this); - m_vlayout->addWidget(m_tableWidget); - - m_tableWidget->setAlternatingRowColors(true); - m_tableWidget->horizontalHeader()->hide(); - m_tableWidget->verticalHeader()->hide(); - m_tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_tableWidget->setShowGrid(false); - m_tableWidget->setSortingEnabled(true); - m_tableWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - - const QMetaObject *metaObject = m_backendObject->metaObject(); - int count = metaObject->propertyCount(); - - m_tableWidget->setColumnCount(3); - m_tableWidget->setRowCount(count); - for (int i=0;i<count;i++) { - QMetaProperty metaProperty = metaObject->property(i); - addPropertyItem(metaProperty.name(), i); - } - m_tableWidget->resizeRowsToContents(); - m_tableWidget->resizeColumnsToContents(); - m_tableWidget->sortItems(0); - m_tableWidget->setColumnWidth(2, 40); - parentWidget()->resize(parentWidget()->width(), count * 28); - qApp->processEvents(); - -} - -void ResetWidget::addPropertyItem(const QString &name, int row) -{ - QTableWidgetItem *newItem = new QTableWidgetItem(name); - m_tableWidget->setItem(row, 0, newItem); - ResetWidgetPushButton *b = new ResetWidgetPushButton(m_tableWidget); - b->setName(name); - b->setText("reset"); - connect(b, SIGNAL(pressed(QString)), this, SLOT(buttonPressed(QString))); - b->setMaximumHeight(15); - b->setMinimumHeight(10); - m_tableWidget->setCellWidget(row, 2, b); -} - -void ResetWidget::buttonPressed(const QString &) -{ -} - -ResetWidgetPushButton::ResetWidgetPushButton(QWidget *parent) : QPushButton(parent) -{ - connect(this, SIGNAL(pressed()), this, SLOT(myPressed())); -} - -void ResetWidgetPushButton::myPressed() -{ - emit pressed(m_name); -} - - -} - diff --git a/src/plugins/qmldesigner/components/propertyeditor/resetwidget.h b/src/plugins/qmldesigner/components/propertyeditor/resetwidget.h deleted file mode 100644 index f56f6200d6..0000000000 --- a/src/plugins/qmldesigner/components/propertyeditor/resetwidget.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** 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 -** 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. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef ResetWidget_h -#define ResetWidget_h - -#include <QGroupBox> -#include <QPushButton> - -QT_BEGIN_NAMESPACE -class QListWidget; -class QVBoxLayout; -class QTableWidget; -QT_END_NAMESPACE - -namespace QmlDesigner { - -class ResetWidget : public QGroupBox -{ - - Q_OBJECT - - Q_PROPERTY(QObject *backendObject READ backendObject WRITE setBackendObject) - -public slots: - void resetView(); - -public: - ResetWidget(QWidget *parent = 0); - QObject* backendObject() - { - return m_backendObject; - } - - void setBackendObject(QObject* backendObject) - { - m_backendObject = backendObject; - setupView(); - } - - static void registerDeclarativeType(); - -public slots: - void buttonPressed(const QString &name); - - -private: - void setupView(); - - void addPropertyItem(const QString &name, int row); - - QObject* m_backendObject; - QVBoxLayout *m_vlayout; - QTableWidget *m_tableWidget; - -}; - -class ResetWidgetPushButton : public QPushButton -{ - Q_OBJECT - -public slots: - void myPressed(); - void setName(const QString &name) - { m_name = name; } - -signals: - void pressed(const QString &name); - -public: - ResetWidgetPushButton(QWidget *parent = 0); -private: - QString m_name; - -}; - -} - -#endif //ResetWidget_h - diff --git a/src/plugins/qmldesigner/components/stateseditor/HorizontalScrollBar.qml b/src/plugins/qmldesigner/components/stateseditor/HorizontalScrollBar.qml index a9fce48fda..a1077e7ead 100644 --- a/src/plugins/qmldesigner/components/stateseditor/HorizontalScrollBar.qml +++ b/src/plugins/qmldesigner/components/stateseditor/HorizontalScrollBar.qml @@ -27,7 +27,7 @@ ** ****************************************************************************/ -import QtQuick 1.0 +import QtQuick 2.1 Item { property variant flickable: this; diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditor.pri b/src/plugins/qmldesigner/components/stateseditor/stateseditor.pri index da160d20f2..185c6f2ede 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditor.pri +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditor.pri @@ -1,3 +1,5 @@ +QT *= qml quick + VPATH += $$PWD SOURCES += stateseditorwidget.cpp \ diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.cpp index 3b0216ea67..9988e7ba74 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.cpp @@ -36,7 +36,7 @@ namespace QmlDesigner { namespace Internal { StatesEditorImageProvider::StatesEditorImageProvider() - : QDeclarativeImageProvider(QDeclarativeImageProvider::Image) + : QQuickImageProvider(QQuickImageProvider::Image) { } diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.h b/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.h index 13b3c6b966..2af03fbf7a 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.h +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.h @@ -32,7 +32,7 @@ #include"abstractview.h" -#include <QDeclarativeImageProvider> +#include <QQuickImageProvider> #include <QWeakPointer> namespace QmlDesigner { @@ -40,7 +40,7 @@ namespace Internal { class StatesEditorView; -class StatesEditorImageProvider : public QDeclarativeImageProvider +class StatesEditorImageProvider : public QQuickImageProvider { public: StatesEditorImageProvider(); diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp index 73f6463777..a259390cd1 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp @@ -398,6 +398,9 @@ void StatesEditorView::currentStateChanged(const ModelNode &node) void StatesEditorView::instancesPreviewImageChanged(const QVector<ModelNode> &nodeList) { + if (!model()) + return; + int minimumIndex = 10000; int maximumIndex = -1; foreach (const ModelNode &node, nodeList) { diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp index a37de4a1b8..e089c620ce 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp @@ -38,10 +38,10 @@ #include <QBoxLayout> -#include <QDeclarativeView> -#include <QDeclarativeContext> -#include <QDeclarativeEngine> -#include <QDeclarativeItem> +#include <QQuickView> +#include <QQmlContext> +#include <QQmlEngine> +#include <QQuickItem> enum { debug = false @@ -51,15 +51,15 @@ namespace QmlDesigner { int StatesEditorWidget::currentStateInternalId() const { - Q_ASSERT(m_declarativeView->rootObject()); - Q_ASSERT(m_declarativeView->rootObject()->property("currentStateInternalId").isValid()); + Q_ASSERT(m_quickView->rootObject()); + Q_ASSERT(m_quickView->rootObject()->property("currentStateInternalId").isValid()); - return m_declarativeView->rootObject()->property("currentStateInternalId").toInt(); + return m_quickView->rootObject()->property("currentStateInternalId").toInt(); } void StatesEditorWidget::setCurrentStateInternalId(int internalId) { - m_declarativeView->rootObject()->setProperty("currentStateInternalId", internalId); + m_quickView->rootObject()->setProperty("currentStateInternalId", internalId); } void StatesEditorWidget::setNodeInstanceView(NodeInstanceView *nodeInstanceView) @@ -69,54 +69,56 @@ void StatesEditorWidget::setNodeInstanceView(NodeInstanceView *nodeInstanceView) void StatesEditorWidget::showAddNewStatesButton(bool showAddNewStatesButton) { - m_declarativeView->rootContext()->setContextProperty("canAddNewStates", showAddNewStatesButton); + m_quickView->rootContext()->setContextProperty("canAddNewStates", showAddNewStatesButton); } StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, StatesEditorModel *statesEditorModel): QWidget(), - m_declarativeView(new QDeclarativeView(this)), + m_quickView(new QQuickView()), m_statesEditorView(statesEditorView), m_imageProvider(0) { m_imageProvider = new Internal::StatesEditorImageProvider; m_imageProvider->setNodeInstanceView(statesEditorView->nodeInstanceView()); - m_declarativeView->engine()->addImageProvider( + m_quickView->engine()->addImageProvider( QLatin1String("qmldesigner_stateseditor"), m_imageProvider); - m_declarativeView->setAcceptDrops(false); + //m_quickView->setAcceptDrops(false); QVBoxLayout *layout = new QVBoxLayout(this); setMinimumHeight(160); layout->setMargin(0); layout->setSpacing(0); - layout->addWidget(m_declarativeView.data()); + QWidget *container = createWindowContainer(m_quickView.data()); + layout->addWidget(container); - m_declarativeView->setResizeMode(QDeclarativeView::SizeRootObjectToView); + m_quickView->setResizeMode(QQuickView::SizeRootObjectToView); - m_declarativeView->rootContext()->setContextProperty(QLatin1String("statesEditorModel"), statesEditorModel); + m_quickView->rootContext()->setContextProperty(QLatin1String("statesEditorModel"), statesEditorModel); QColor highlightColor = palette().highlight().color(); if (0.5*highlightColor.saturationF()+0.75-highlightColor.valueF() < 0) highlightColor.setHsvF(highlightColor.hsvHueF(),0.1 + highlightColor.saturationF()*2.0, highlightColor.valueF()); - m_declarativeView->rootContext()->setContextProperty(QLatin1String("highlightColor"), highlightColor); + m_quickView->rootContext()->setContextProperty(QLatin1String("highlightColor"), highlightColor); - m_declarativeView->rootContext()->setContextProperty("canAddNewStates", true); + m_quickView->rootContext()->setContextProperty("canAddNewStates", true); // Work around ASSERT in the internal QGraphicsScene that happens when // the scene is created + items set dirty in one event loop run (BAUHAUS-459) //QApplication::processEvents(); - m_declarativeView->setSource(QUrl("qrc:/stateseditor/stateslist.qml")); + m_quickView->setSource(QUrl("qrc:/stateseditor/stateslist.qml")); - if (!m_declarativeView->rootObject()) + if (!m_quickView->rootObject()) throw InvalidQmlSourceException(__LINE__, __FUNCTION__, __FILE__); - m_declarativeView->setFocusPolicy(Qt::ClickFocus); + QEvent event(QEvent::WindowActivate); - QApplication::sendEvent(m_declarativeView->scene(), &event); + QApplication::sendEvent(m_quickView.data(), &event); + - connect(m_declarativeView->rootObject(), SIGNAL(currentStateInternalIdChanged()), statesEditorView, SLOT(synchonizeCurrentStateFromWidget())); - connect(m_declarativeView->rootObject(), SIGNAL(createNewState()), statesEditorView, SLOT(createNewState())); - connect(m_declarativeView->rootObject(), SIGNAL(deleteState(int)), statesEditorView, SLOT(removeState(int))); + connect(m_quickView->rootObject(), SIGNAL(currentStateInternalIdChanged()), statesEditorView, SLOT(synchonizeCurrentStateFromWidget())); + connect(m_quickView->rootObject(), SIGNAL(createNewState()), statesEditorView, SLOT(createNewState())); + connect(m_quickView->rootObject(), SIGNAL(deleteState(int)), statesEditorView, SLOT(removeState(int))); setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred)); diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.h b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.h index 0d0e542588..f81b39a70d 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.h +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.h @@ -33,7 +33,7 @@ #include <QWidget> QT_BEGIN_NAMESPACE -class QDeclarativeView; +class QQuickView; QT_END_NAMESPACE namespace QmlDesigner { @@ -65,7 +65,7 @@ public: void showAddNewStatesButton(bool showAddNewStatesButton); private: - QWeakPointer<QDeclarativeView> m_declarativeView; + QWeakPointer<QQuickView> m_quickView; QWeakPointer<StatesEditorView> m_statesEditorView; Internal::StatesEditorImageProvider *m_imageProvider; }; diff --git a/src/plugins/qmldesigner/components/stateseditor/stateslist.qml b/src/plugins/qmldesigner/components/stateseditor/stateslist.qml index 01abea5281..821fa3b9d0 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateslist.qml +++ b/src/plugins/qmldesigner/components/stateseditor/stateslist.qml @@ -27,7 +27,7 @@ ** ****************************************************************************/ -import QtQuick 1.0 +import QtQuick 2.1 Rectangle { id: root |