diff options
author | Marco Bubke <marco.bubke@digia.com> | 2013-09-17 14:43:24 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@digia.com> | 2013-09-18 13:19:38 +0200 |
commit | 3130aacc82c29b1435de7ec93b5266872b66ce7a (patch) | |
tree | f52f6c7c586caab748faf54bc012f580b1759d8d | |
parent | 2d8c0dd4804a841c3f0649aecb16f44beeb78467 (diff) | |
download | qt-creator-3130aacc82c29b1435de7ec93b5266872b66ce7a.tar.gz |
QmlDesigner: Add ContentNotEditableIndicator
If you hover over a tab the content will be visulized as non editable.
Change-Id: If7fcc8aaa319e0f952f501f6e9e2fc767b89b636
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
9 files changed, 196 insertions, 6 deletions
diff --git a/src/plugins/qmldesigner/components/formeditor/contentnoteditableindicator.cpp b/src/plugins/qmldesigner/components/formeditor/contentnoteditableindicator.cpp new file mode 100644 index 0000000000..6763b10f4b --- /dev/null +++ b/src/plugins/qmldesigner/components/formeditor/contentnoteditableindicator.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** 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 "contentnoteditableindicator.h" +#include "nodemetainfo.h" + +namespace QmlDesigner { + +ContentNotEditableIndicator::ContentNotEditableIndicator(LayerItem *layerItem) + : m_layerItem(layerItem) +{ + +} + +ContentNotEditableIndicator::ContentNotEditableIndicator() +{ +} + +ContentNotEditableIndicator::~ContentNotEditableIndicator() +{ + clear(); +} + +void ContentNotEditableIndicator::clear() +{ + foreach (const EntryPair &entryPair, m_entryList) { + delete entryPair.second; + entryPair.first->blurContent(false); + } + + m_entryList.clear(); +} + +bool operator ==(const ContentNotEditableIndicator::EntryPair &firstPair, const ContentNotEditableIndicator::EntryPair &secondPair) +{ + return firstPair.first == secondPair.first; +} + +void ContentNotEditableIndicator::setItems(const QList<FormEditorItem*> &itemList) +{ + removeEntriesWhichAreNotInTheList(itemList); + addAddiationEntries(itemList); +} + +void ContentNotEditableIndicator::addAddiationEntries(const QList<FormEditorItem *> &itemList) +{ + foreach (FormEditorItem *formEditorItem, itemList) { + if (formEditorItem->qmlItemNode().modelNode().metaInfo().isSubclassOf("QtQuick.Loader", -1, -1)) { + + if (!m_entryList.contains(EntryPair(formEditorItem, 0))) { + QGraphicsRectItem *indicatorShape = new QGraphicsRectItem(m_layerItem); + QRectF boundingRectangleInSceneSpace = formEditorItem->qmlItemNode().instanceSceneTransform().mapRect(formEditorItem->qmlItemNode().instanceBoundingRect()); + indicatorShape->setRect(boundingRectangleInSceneSpace); + static QBrush brush(QColor(0, 0, 0, 130), Qt::BDiagPattern); + indicatorShape->setBrush(brush); + + formEditorItem->blurContent(true); + + m_entryList.append(EntryPair(formEditorItem, indicatorShape)); + } + + } + } +} + +void ContentNotEditableIndicator::removeEntriesWhichAreNotInTheList(const QList<FormEditorItem *> &itemList) +{ + QMutableListIterator<EntryPair> entryIterator(m_entryList); + + while (entryIterator.hasNext()) { + EntryPair &entryPair = entryIterator.next(); + if (!itemList.contains(entryPair.first)) { + delete entryPair.second; + entryPair.first->blurContent(false); + entryIterator.remove(); + } + } +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/formeditor/contentnoteditableindicator.h b/src/plugins/qmldesigner/components/formeditor/contentnoteditableindicator.h new file mode 100644 index 0000000000..2567bfaab1 --- /dev/null +++ b/src/plugins/qmldesigner/components/formeditor/contentnoteditableindicator.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** 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 QMLDESIGNER_CONTENTNOTEDITABLEINDICATOR_H +#define QMLDESIGNER_CONTENTNOTEDITABLEINDICATOR_H + +#include <QPointer> +#include <QGraphicsRectItem> +#include "layeritem.h" +#include "formeditoritem.h" + +namespace QmlDesigner { + +class ContentNotEditableIndicator +{ +public: + typedef QPair<FormEditorItem*, QGraphicsRectItem *> EntryPair; + + ContentNotEditableIndicator(LayerItem *layerItem); + ContentNotEditableIndicator(); + ~ContentNotEditableIndicator(); + + void clear(); + + void setItems(const QList<FormEditorItem*> &itemList); + +protected: + void addAddiationEntries(const QList<FormEditorItem*> &itemList); + void removeEntriesWhichAreNotInTheList(const QList<FormEditorItem*> &itemList); + +private: + QPointer<LayerItem> m_layerItem; + QList<EntryPair> m_entryList; +}; + +} // namespace QmlDesigner + +#endif // QMLDESIGNER_CONTENTNOTEDITABLEINDICATOR_H diff --git a/src/plugins/qmldesigner/components/formeditor/formeditor.pri b/src/plugins/qmldesigner/components/formeditor/formeditor.pri index 325534e372..8968c2f597 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditor.pri +++ b/src/plugins/qmldesigner/components/formeditor/formeditor.pri @@ -34,7 +34,8 @@ SOURCES += formeditoritem.cpp \ anchorindicator.cpp \ anchorindicatorgraphicsitem.cpp \ bindingindicator.cpp \ - bindingindicatorgraphicsitem.cpp + bindingindicatorgraphicsitem.cpp \ + contentnoteditableindicator.cpp HEADERS += formeditorscene.h \ formeditorwidget.h \ formeditoritem.h \ @@ -70,5 +71,6 @@ HEADERS += formeditorscene.h \ anchorindicator.h \ anchorindicatorgraphicsitem.h \ bindingindicator.h \ - bindingindicatorgraphicsitem.h + bindingindicatorgraphicsitem.h \ + contentnoteditableindicator.h RESOURCES += formeditor.qrc diff --git a/src/plugins/qmldesigner/components/formeditor/formeditoritem.cpp b/src/plugins/qmldesigner/components/formeditor/formeditoritem.cpp index 08a6662162..9ed39b9f63 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditoritem.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditoritem.cpp @@ -33,7 +33,6 @@ #include <modelnode.h> #include <nodemetainfo.h> - #include <QDebug> #include <QPainter> #include <QStyleOptionGraphicsItem> @@ -41,7 +40,6 @@ #include <cmath> - namespace QmlDesigner { @@ -269,6 +267,11 @@ void FormEditorItem::paintPlaceHolderForInvisbleItem(QPainter *painter) const } } +void FormEditorItem::paintComponentContentVisualisation(QPainter *painter, const QRectF &clippinRectangle) const +{ + painter->setBrush(QColor(0, 0, 0, 150)); + painter->fillRect(clippinRectangle, Qt::BDiagPattern); +} void FormEditorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { @@ -293,6 +296,9 @@ void FormEditorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, if (!qmlItemNode().isRootModelNode()) paintBoundingRect(painter); +// if (qmlItemNode().modelNode().metaInfo().isSubclassOf("QtQuick.Loader", -1, -1)) +// paintComponentContentVisualisation(painter, boundingRect()); + painter->restore(); } diff --git a/src/plugins/qmldesigner/components/formeditor/formeditoritem.h b/src/plugins/qmldesigner/components/formeditor/formeditoritem.h index 746aef33ca..ddc5c76b40 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditoritem.h +++ b/src/plugins/qmldesigner/components/formeditor/formeditoritem.h @@ -111,6 +111,7 @@ protected: AbstractFormEditorTool* tool() const; void paintBoundingRect(QPainter *painter) const; void paintPlaceHolderForInvisbleItem(QPainter *painter) const; + void paintComponentContentVisualisation(QPainter *painter, const QRectF &clippinRectangle) const; private: // functions FormEditorItem(const QmlItemNode &qmlItemNode, FormEditorScene* scene); diff --git a/src/plugins/qmldesigner/components/formeditor/movetool.cpp b/src/plugins/qmldesigner/components/formeditor/movetool.cpp index 7ca3fc7117..8a6132d406 100644 --- a/src/plugins/qmldesigner/components/formeditor/movetool.cpp +++ b/src/plugins/qmldesigner/components/formeditor/movetool.cpp @@ -48,7 +48,8 @@ MoveTool::MoveTool(FormEditorView *editorView) m_selectionIndicator(editorView->scene()->manipulatorLayerItem()), m_resizeIndicator(editorView->scene()->manipulatorLayerItem()), m_anchorIndicator(editorView->scene()->manipulatorLayerItem()), - m_bindingIndicator(editorView->scene()->manipulatorLayerItem()) + m_bindingIndicator(editorView->scene()->manipulatorLayerItem()), + m_contentNotEditableIndicator(editorView->scene()->manipulatorLayerItem()) { m_selectionIndicator.setCursor(Qt::SizeAllCursor); } @@ -67,6 +68,7 @@ void MoveTool::clear() m_resizeIndicator.clear(); m_anchorIndicator.clear(); m_bindingIndicator.clear(); + m_contentNotEditableIndicator.clear(); AbstractFormEditorTool::clear(); } @@ -130,6 +132,8 @@ void MoveTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList, view()->changeToSelectionTool(); return; } + + m_contentNotEditableIndicator.setItems(toFormEditorItemList(itemList)); } void MoveTool::keyPressEvent(QKeyEvent *event) diff --git a/src/plugins/qmldesigner/components/formeditor/movetool.h b/src/plugins/qmldesigner/components/formeditor/movetool.h index 6a498d7d2c..0b5a9ac2a4 100644 --- a/src/plugins/qmldesigner/components/formeditor/movetool.h +++ b/src/plugins/qmldesigner/components/formeditor/movetool.h @@ -36,7 +36,7 @@ #include "resizeindicator.h" #include "anchorindicator.h" #include "bindingindicator.h" - +#include "contentnoteditableindicator.h" namespace QmlDesigner { @@ -97,6 +97,7 @@ private: ResizeIndicator m_resizeIndicator; AnchorIndicator m_anchorIndicator; BindingIndicator m_bindingIndicator; + ContentNotEditableIndicator m_contentNotEditableIndicator; QList<FormEditorItem*> m_movingItems; }; diff --git a/src/plugins/qmldesigner/components/formeditor/selectiontool.cpp b/src/plugins/qmldesigner/components/formeditor/selectiontool.cpp index 716b125d2a..eb51bb808d 100644 --- a/src/plugins/qmldesigner/components/formeditor/selectiontool.cpp +++ b/src/plugins/qmldesigner/components/formeditor/selectiontool.cpp @@ -33,6 +33,7 @@ #include "resizehandleitem.h" +#include <nodemetainfo.h> #include <QGraphicsSceneMouseEvent> #include <QDebug> @@ -50,6 +51,7 @@ SelectionTool::SelectionTool(FormEditorView *editorView) m_resizeIndicator(editorView->scene()->manipulatorLayerItem()), m_anchorIndicator(editorView->scene()->manipulatorLayerItem()), m_bindingIndicator(editorView->scene()->manipulatorLayerItem()), + m_contentNotEditableIndicator(editorView->scene()->manipulatorLayerItem()), m_selectOnlyContentItems(false) { m_selectionIndicator.setCursor(Qt::ArrowCursor); @@ -146,6 +148,8 @@ void SelectionTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList, FormEditorItem *topSelectableItem = topMovableFormEditorItem(itemList, m_selectOnlyContentItems); scene()->highlightBoundingRect(topSelectableItem); + + m_contentNotEditableIndicator.setItems(toFormEditorItemList(itemList)); } void SelectionTool::mouseReleaseEvent(const QList<QGraphicsItem*> &itemList, diff --git a/src/plugins/qmldesigner/components/formeditor/selectiontool.h b/src/plugins/qmldesigner/components/formeditor/selectiontool.h index 85df5d495f..c97141e540 100644 --- a/src/plugins/qmldesigner/components/formeditor/selectiontool.h +++ b/src/plugins/qmldesigner/components/formeditor/selectiontool.h @@ -38,6 +38,7 @@ #include "resizeindicator.h" #include "anchorindicator.h" #include "bindingindicator.h" +#include "contentnoteditableindicator.h" #include <QTime> @@ -96,6 +97,7 @@ private: ResizeIndicator m_resizeIndicator; AnchorIndicator m_anchorIndicator; BindingIndicator m_bindingIndicator; + ContentNotEditableIndicator m_contentNotEditableIndicator; QTime m_mousePressTimer; bool m_selectOnlyContentItems; QCursor m_cursor; |