forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user