Skip to content
Snippets Groups Projects
Commit bb08fb65 authored by Lasse Holmstedt's avatar Lasse Holmstedt
Browse files

added custom qmlviewer to creator

This qmlviewer will be also the default one when opening qmlproject files
as the runconfiguration was changed too.
parent aa4f9725
No related branches found
No related tags found
No related merge requests found
Showing
with 1296 additions and 7 deletions
......@@ -96,18 +96,28 @@ void QmlProjectRunConfiguration::ctor()
setDisplayName(tr("QML Viewer", "QMLRunConfiguration display name."));
// prepend creator/bin dir to search path (only useful for special creator-qml package)
const QString searchPath = QCoreApplication::applicationDirPath()
+ Utils::SynchronousProcess::pathSeparator()
+ QString(qgetenv("PATH"));
#ifdef Q_OS_MAC
const QString qmlViewerName = QLatin1String("QMLViewer");
#else
const QString qmlViewerName = QLatin1String("qmlviewer");
#endif
m_qmlViewerDefaultPath = Utils::SynchronousProcess::locateBinary(searchPath, qmlViewerName);
if (m_qmlViewerDefaultPath.isEmpty()) {
QDir qmlviewerExecutable(QCoreApplication::applicationDirPath());
#ifndef Q_OS_WIN
m_qmlViewerDefaultPath = qmlviewerExecutable.absoluteFilePath(qmlViewerName);
#else
m_qmlViewerDefaultPath = qmlviewerExecutable.absoluteFilePath(QString("%1.exe").arg(qmlViewerName));
#endif
QFileInfo qmlviewerFileInfo(m_qmlViewerDefaultPath);
if (!qmlviewerFileInfo.exists()) {
qWarning() << "QmlProjectRunConfiguration::ctor(): qmlviewer executable does not exist at" << m_qmlViewerDefaultPath;
m_qmlViewerDefaultPath.clear();
} else if (!qmlviewerFileInfo.isFile()) {
qWarning() << "QmlProjectRunConfiguration::ctor(): " << m_qmlViewerDefaultPath << " is not a file";
m_qmlViewerDefaultPath.clear();
}
}
}
QmlProjectRunConfiguration::~QmlProjectRunConfiguration()
......
......@@ -4,7 +4,7 @@ contains(QT_CONFIG, declarative) {
include(../../private_headers.pri)
exists($${QT_PRIVATE_HEADERS}/QtDeclarative/private/qdeclarativemetatype_p.h) {
SUBDIRS += qmldump
SUBDIRS += qmldump qmlviewer
} else {
warning()
warning("QmlDump utility has been disabled")
......@@ -12,6 +12,11 @@ contains(QT_CONFIG, declarative) {
warning("This means the Qml editor will lack correct completion and type checking.")
warning("To enable it, pass 'QT_PRIVATE_HEADERS=$QTDIR/include' to qmake, where $QTDIR is the source directory of qt.")
warning()
warning("QmlViewer has been disabled")
warning("This application depends on private headers from QtDeclarative module.")
warning("This means the QML debugging facilities will be limited.")
warning("To enable it, pass 'QT_PRIVATE_HEADERS=$QTDIR/include' to qmake, where $QTDIR is the source directory of qt.")
warning()
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.1">
<dict>
<key>CFBundleIconFile</key>
<string>@ICON@</string>
<key>CFBundleIdentifier</key>
<string>com.nokia.qt.qml</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleGetInfoString</key>
<string>Created by Qt/QMake</string>
<key>CFBundleSignature</key>
<string>@TYPEINFO@</string>
<key>CFBundleExecutable</key>
<string>@EXECUTABLE@</string>
</dict>
</plist>
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
import Qt 4.7
import Qt.labs.folderlistmodel 1.0
Rectangle {
id: root
property bool keyPressed: false
property variant folders: folders1
property variant view: view1
width: 320
height: 480
color: palette.window
FolderListModel {
id: folders1
nameFilters: [ "*.qml" ]
folder: qmlViewerFolder
}
FolderListModel {
id: folders2
nameFilters: [ "*.qml" ]
folder: qmlViewerFolder
}
SystemPalette { id: palette }
function down(path) {
if (folders == folders1) {
view = view2
folders = folders2;
view1.state = "exitLeft";
} else {
view = view1
folders = folders1;
view2.state = "exitLeft";
}
view.x = root.width;
view.state = "current";
view.focus = true;
folders.folder = path;
}
function up() {
var path = folders.parentFolder;
if (folders == folders1) {
view = view2
folders = folders2;
view1.state = "exitRight";
} else {
view = view1
folders = folders1;
view2.state = "exitRight";
}
view.x = -root.width;
view.state = "current";
view.focus = true;
folders.folder = path;
}
Component {
id: folderDelegate
Rectangle {
id: wrapper
function launch() {
if (folders.isFolder(index)) {
down(filePath);
} else {
qmlViewer.launch(filePath);
}
}
width: root.width
height: 52
color: "transparent"
Rectangle {
id: highlight; visible: false
anchors.fill: parent
gradient: Gradient {
GradientStop { id: t1; position: 0.0; color: palette.highlight }
GradientStop { id: t2; position: 1.0; color: Qt.lighter(palette.highlight) }
}
}
Item {
width: 48; height: 48
Image { source: "images/folder.png"; anchors.centerIn: parent; visible: folders.isFolder(index)}
}
Text {
id: nameText
anchors.fill: parent; verticalAlignment: Text.AlignVCenter
text: fileName
anchors.leftMargin: 54
font.pixelSize: 32
color: (wrapper.ListView.isCurrentItem && root.keyPressed) ? palette.highlightedText : palette.windowText
elide: Text.ElideRight
}
MouseArea {
id: mouseRegion
anchors.fill: parent
onClicked: { if (folders == wrapper.ListView.view.model) launch() }
}
states: [
State {
name: "pressed"
when: mouseRegion.pressed
PropertyChanges { target: highlight; visible: true }
PropertyChanges { target: nameText; color: palette.highlightedText }
}
]
}
}
ListView {
id: view1
anchors.top: titleBar.bottom
anchors.bottom: parent.bottom
x: 0
width: parent.width
model: folders1
delegate: folderDelegate
highlight: Rectangle { color: palette.highlight; visible: root.keyPressed && view1.count != 0 }
highlightMoveSpeed: 1000
pressDelay: 100
focus: true
state: "current"
states: [
State {
name: "current"
PropertyChanges { target: view1; x: 0 }
},
State {
name: "exitLeft"
PropertyChanges { target: view1; x: -root.width }
},
State {
name: "exitRight"
PropertyChanges { target: view1; x: root.width }
}
]
transitions: [
Transition {
to: "current"
SequentialAnimation {
NumberAnimation { properties: "x"; duration: 250 }
}
},
Transition {
NumberAnimation { properties: "x"; duration: 250 }
NumberAnimation { properties: "x"; duration: 250 }
}
]
Keys.onPressed: { root.keyPressed = true; }
}
ListView {
id: view2
anchors.top: titleBar.bottom
anchors.bottom: parent.bottom
x: parent.width
width: parent.width
model: folders2
delegate: folderDelegate
highlight: Rectangle { color: palette.highlight; visible: root.keyPressed && view2.count != 0 }
highlightMoveSpeed: 1000
pressDelay: 100
states: [
State {
name: "current"
PropertyChanges { target: view2; x: 0 }
},
State {
name: "exitLeft"
PropertyChanges { target: view2; x: -root.width }
},
State {
name: "exitRight"
PropertyChanges { target: view2; x: root.width }
}
]
transitions: [
Transition {
to: "current"
SequentialAnimation {
NumberAnimation { properties: "x"; duration: 250 }
}
},
Transition {
NumberAnimation { properties: "x"; duration: 250 }
}
]
Keys.onPressed: { root.keyPressed = true; }
}
Keys.onPressed: {
root.keyPressed = true;
if (event.key == Qt.Key_Return || event.key == Qt.Key_Select || event.key == Qt.Key_Right) {
view.currentItem.launch();
event.accepted = true;
} else if (event.key == Qt.Key_Left) {
up();
}
}
BorderImage {
source: "images/titlebar.sci";
width: parent.width;
height: 52
y: -7
id: titleBar
Rectangle {
id: upButton
width: 48
height: titleBar.height - 7
color: "transparent"
Image { anchors.centerIn: parent; source: "images/up.png" }
MouseArea { id: upRegion; anchors.centerIn: parent
width: 56
height: 56
onClicked: if (folders.parentFolder != "") up()
}
states: [
State {
name: "pressed"
when: upRegion.pressed
PropertyChanges { target: upButton; color: palette.highlight }
}
]
}
Rectangle {
color: "gray"
x: 48
width: 1
height: 44
}
Text {
anchors.left: upButton.right; anchors.right: parent.right; height: parent.height
anchors.leftMargin: 4; anchors.rightMargin: 4
text: folders.folder
color: "white"
elide: Text.ElideLeft; horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
font.pixelSize: 32
}
}
}
src/tools/qml/qmlviewer/content/images/folder.png

1.8 KiB

src/tools/qml/qmlviewer/content/images/titlebar.png

1.4 KiB

border.left: 10
border.top: 12
border.bottom: 12
border.right: 10
source: titlebar.png
src/tools/qml/qmlviewer/content/images/up.png

662 B

/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "deviceorientation.h"
QT_USE_NAMESPACE
class DefaultDeviceOrientation : public DeviceOrientation
{
Q_OBJECT
public:
DefaultDeviceOrientation() : DeviceOrientation(), m_orientation(DeviceOrientation::Portrait) {}
Orientation orientation() const {
return m_orientation;
}
void setOrientation(Orientation o) {
if (o != m_orientation) {
m_orientation = o;
emit orientationChanged();
}
}
Orientation m_orientation;
};
DeviceOrientation* DeviceOrientation::instance()
{
static DefaultDeviceOrientation *o = 0;
if (!o)
o = new DefaultDeviceOrientation;
return o;
}
#include "deviceorientation.moc"
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef ORIENTATION_H
#define ORIENTATION_H
#include <QObject>
QT_BEGIN_NAMESPACE
class DeviceOrientationPrivate;
class DeviceOrientation : public QObject
{
Q_OBJECT
Q_ENUMS(Orientation)
public:
enum Orientation {
UnknownOrientation,
Portrait,
Landscape,
PortraitInverted,
LandscapeInverted
};
virtual Orientation orientation() const = 0;
virtual void setOrientation(Orientation) = 0;
static DeviceOrientation *instance();
signals:
void orientationChanged();
protected:
DeviceOrientation() {}
private:
DeviceOrientationPrivate *d_ptr;
friend class DeviceOrientationPrivate;
};
QT_END_NAMESPACE
#endif
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "deviceorientation.h"
#include <QtDBus>
#include <mce/mode-names.h>
#include <mce/dbus-names.h>
class MaemoOrientation : public DeviceOrientation
{
Q_OBJECT
public:
MaemoOrientation()
: o(UnknownOrientation)
{
// enable the orientation sensor
QDBusConnection::systemBus().call(
QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH,
MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ));
// query the initial orientation
QDBusMessage reply = QDBusConnection::systemBus().call(
QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH,
MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET));
if (reply.type() == QDBusMessage::ErrorMessage) {
qWarning("Unable to retrieve device orientation: %s", qPrintable(reply.errorMessage()));
} else {
o = toOrientation(reply.arguments().value(0).toString());
}
// connect to the orientation change signal
QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
MCE_DEVICE_ORIENTATION_SIG,
this,
SLOT(deviceOrientationChanged(QString)));
}
~MaemoOrientation()
{
// disable the orientation sensor
QDBusConnection::systemBus().call(
QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH,
MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ));
}
inline Orientation orientation() const
{
return o;
}
void setOrientation(Orientation o)
{
}
private Q_SLOTS:
void deviceOrientationChanged(const QString &newOrientation)
{
o = toOrientation(newOrientation);
emit orientationChanged();
// printf("%d\n", o);
}
private:
static Orientation toOrientation(const QString &nativeOrientation)
{
if (nativeOrientation == MCE_ORIENTATION_LANDSCAPE)
return Landscape;
else if (nativeOrientation == MCE_ORIENTATION_LANDSCAPE_INVERTED)
return LandscapeInverted;
else if (nativeOrientation == MCE_ORIENTATION_PORTRAIT)
return Portrait;
else if (nativeOrientation == MCE_ORIENTATION_PORTRAIT_INVERTED)
return PortraitInverted;
return UnknownOrientation;
}
private:
Orientation o;
};
DeviceOrientation* DeviceOrientation::instance()
{
static MaemoOrientation *o = new MaemoOrientation;
return o;
}
#include "deviceorientation_maemo5.moc"
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "abstractformeditortool.h"
#include "qdeclarativedesignview.h"
#include <private/qdeclarativecontext_p.h>
#include <QDeclarativeEngine>
#include <QtDebug>
#include <QGraphicsItem>
#include <QDeclarativeItem>
namespace QmlViewer {
AbstractFormEditorTool::AbstractFormEditorTool(QDeclarativeDesignView *editorView)
: QObject(editorView), m_view(editorView)
{
}
AbstractFormEditorTool::~AbstractFormEditorTool()
{
}
QDeclarativeDesignView* AbstractFormEditorTool::view() const
{
return m_view;
}
QGraphicsScene* AbstractFormEditorTool::scene() const
{
return view()->scene();
}
void AbstractFormEditorTool::setItems(const QList<QGraphicsItem*> &itemList)
{
m_itemList = itemList;
selectedItemsChanged(m_itemList);
}
QList<QGraphicsItem*> AbstractFormEditorTool::items() const
{
return m_itemList;
}
bool AbstractFormEditorTool::topItemIsMovable(const QList<QGraphicsItem*> & itemList)
{
QGraphicsItem *firstSelectableItem = topMovableGraphicsItem(itemList);
if (firstSelectableItem == 0)
return false;
QDeclarativeItem *declarativeItem = dynamic_cast<QDeclarativeItem*>(firstSelectableItem->toGraphicsObject());
if (declarativeItem != 0)
return true;
return false;
}
bool AbstractFormEditorTool::topSelectedItemIsMovable(const QList<QGraphicsItem*> &itemList)
{
QList<QGraphicsItem*> selectedItems = view()->selectedItems();
foreach (QGraphicsItem *item, itemList) {
QDeclarativeItem *declarativeItem = toQDeclarativeItem(item);
if (declarativeItem
&& selectedItems.contains(declarativeItem)
/*&& (declarativeItem->qmlItemNode().hasShowContent() || selectNonContentItems)*/)
return true;
}
return false;
}
bool AbstractFormEditorTool::topItemIsResizeHandle(const QList<QGraphicsItem*> &/*itemList*/)
{
return false;
}
QDeclarativeItem *AbstractFormEditorTool::toQDeclarativeItem(QGraphicsItem *item)
{
return dynamic_cast<QDeclarativeItem*>(item->toGraphicsObject());
}
QGraphicsItem *AbstractFormEditorTool::topMovableGraphicsItem(const QList<QGraphicsItem*> &itemList)
{
foreach (QGraphicsItem *item, itemList) {
if (item->flags().testFlag(QGraphicsItem::ItemIsMovable))
return item;
}
return 0;
}
QDeclarativeItem *AbstractFormEditorTool::topMovableDeclarativeItem(const QList<QGraphicsItem*> &itemList)
{
foreach (QGraphicsItem *item, itemList) {
QDeclarativeItem *declarativeItem = toQDeclarativeItem(item);
if (declarativeItem /*&& (declarativeItem->qmlItemNode().hasShowContent())*/)
return declarativeItem;
}
return 0;
}
QList<QGraphicsObject*> AbstractFormEditorTool::toGraphicsObjectList(const QList<QGraphicsItem*> &itemList)
{
QList<QGraphicsObject*> gfxObjects;
foreach(QGraphicsItem *item, itemList) {
QGraphicsObject *obj = item->toGraphicsObject();
if (obj)
gfxObjects << obj;
}
return gfxObjects;
}
QList<QObject*> AbstractFormEditorTool::toObjectList(const QList<QGraphicsItem*> &itemList)
{
QList<QObject*> objects;
foreach(QGraphicsItem *item, itemList) {
QObject *obj = item->toGraphicsObject();
if (obj)
objects << obj;
}
return objects;
}
QString AbstractFormEditorTool::titleForItem(const QGraphicsItem *item)
{
QString className("QGraphicsItem");
QString objectStringId;
const QGraphicsObject *gfxObject = item->toGraphicsObject();
if (gfxObject) {
className = gfxObject->metaObject()->className();
className.replace(QRegExp("_QMLTYPE_\\d+"), "");
const QDeclarativeItem *declarativeItem = qobject_cast<const QDeclarativeItem*>(gfxObject);
if (declarativeItem) {
//QDeclarativeData *ddata = QDeclarativeData::get(declarativeItem);
//ddata->context->findObjectId(declarativeItem);
QDeclarativeContext *context = QDeclarativeEngine::contextForObject(declarativeItem);
if (context) {
QDeclarativeContextData *cdata = QDeclarativeContextData::get(context);
if (cdata)
objectStringId = cdata->findObjectId(declarativeItem);
}
}
if (objectStringId.isEmpty())
objectStringId = gfxObject->objectName();
if (!objectStringId.isEmpty())
return tr("%1 (%2)").arg(objectStringId, className);
}
return tr("(%1, type %2)").arg(className, QString::number(item->type()));
}
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef ABSTRACTFORMEDITORTOOL_H
#define ABSTRACTFORMEDITORTOOL_H
#include <qglobal.h>
#include <QList>
#include <QObject>
QT_BEGIN_NAMESPACE
class QMouseEvent;
class QGraphicsItem;
class QDeclarativeItem;
class QKeyEvent;
class QGraphicsScene;
class QGraphicsObject;
class QWheelEvent;
QT_END_NAMESPACE
namespace QmlViewer {
class QDeclarativeDesignView;
class FormEditorView;
class AbstractFormEditorTool : public QObject
{
Q_OBJECT
public:
AbstractFormEditorTool(QDeclarativeDesignView* view);
virtual ~AbstractFormEditorTool();
virtual void mousePressEvent(QMouseEvent *event) = 0;
virtual void mouseMoveEvent(QMouseEvent *event) = 0;
virtual void mouseReleaseEvent(QMouseEvent *event) = 0;
virtual void mouseDoubleClickEvent(QMouseEvent *event) = 0;
virtual void hoverMoveEvent(QMouseEvent *event) = 0;
virtual void wheelEvent(QWheelEvent *event) = 0;
virtual void keyPressEvent(QKeyEvent *event) = 0;
virtual void keyReleaseEvent(QKeyEvent *keyEvent) = 0;
virtual void itemsAboutToRemoved(const QList<QGraphicsItem*> &itemList) = 0;
virtual void clear() = 0;
virtual void graphicsObjectsChanged(const QList<QGraphicsObject*> &itemList) = 0;
void setItems(const QList<QGraphicsItem*> &itemList);
QList<QGraphicsItem*> items() const;
bool topItemIsMovable(const QList<QGraphicsItem*> &itemList);
bool topItemIsResizeHandle(const QList<QGraphicsItem*> &itemList);
bool topSelectedItemIsMovable(const QList<QGraphicsItem*> &itemList);
static QString titleForItem(const QGraphicsItem *item);
static QList<QObject*> toObjectList(const QList<QGraphicsItem*> &itemList);
static QList<QGraphicsObject*> toGraphicsObjectList(const QList<QGraphicsItem*> &itemList);
static QGraphicsItem* topMovableGraphicsItem(const QList<QGraphicsItem*> &itemList);
static QDeclarativeItem* topMovableDeclarativeItem(const QList<QGraphicsItem*> &itemList);
static QDeclarativeItem *toQDeclarativeItem(QGraphicsItem *item);
protected:
virtual void selectedItemsChanged(const QList<QGraphicsItem*> &itemList) = 0;
QDeclarativeDesignView *view() const;
QGraphicsScene* scene() const;
private:
QDeclarativeDesignView *m_view;
QList<QGraphicsItem*> m_itemList;
};
}
#endif // ABSTRACTFORMEDITORTOOL_H
#include "boundingrecthighlighter.h"
#include "qdeclarativedesignview.h"
#include "qmlviewerconstants.h"
#include <QGraphicsPolygonItem>
#include <QTimer>
#include <QDebug>
namespace QmlViewer {
const qreal AnimDelta = 0.025f;
const int AnimInterval = 30;
const int AnimFrames = 10;
BoundingBoxPolygonItem::BoundingBoxPolygonItem(QGraphicsItem *item) : QGraphicsPolygonItem(item)
{
QPen pen;
pen.setColor(QColor(108, 141, 221));
setPen(pen);
}
int BoundingBoxPolygonItem::type() const
{
return Constants::EditorItemType;
}
BoundingRectHighlighter::BoundingRectHighlighter(QDeclarativeDesignView *view) :
LayerItem(view->scene()),
m_view(view),
m_highlightPolygon(0),
m_highlightPolygonEdge(0),
m_animFrame(0)
{
m_animTimer = new QTimer(this);
m_animTimer->setInterval(AnimInterval);
connect(m_animTimer, SIGNAL(timeout()), SLOT(animTimeout()));
}
void BoundingRectHighlighter::animTimeout()
{
++m_animFrame;
if (m_animFrame == AnimFrames) {
m_animTimer->stop();
}
m_highlightPolygon->setPen(QPen(QColor(0, 22, 159)));
m_highlightPolygonEdge->setPen(QPen(QColor(158, 199, 255)));
qreal alpha = m_animFrame / float(AnimFrames);
m_highlightPolygonEdge->setOpacity(alpha);
}
void BoundingRectHighlighter::clear()
{
if (m_highlightPolygon) {
m_view->scene()->removeItem(m_highlightPolygon);
delete m_highlightPolygon;
m_highlightPolygon = 0;
delete m_highlightPolygonEdge;
m_highlightPolygonEdge = 0;
m_animTimer->stop();
disconnect(m_highlightedObject.data(), SIGNAL(xChanged()), this, SLOT(refresh()));
disconnect(m_highlightedObject.data(), SIGNAL(yChanged()), this, SLOT(refresh()));
disconnect(m_highlightedObject.data(), SIGNAL(widthChanged()), this, SLOT(refresh()));
disconnect(m_highlightedObject.data(), SIGNAL(heightChanged()), this, SLOT(refresh()));
disconnect(m_highlightedObject.data(), SIGNAL(rotationChanged()), this, SLOT(refresh()));
m_highlightedObject.clear();
}
}
void BoundingRectHighlighter::highlight(QGraphicsObject* item)
{
if (!item)
return;
bool animate = false;
QGraphicsPolygonItem *polygonItem = 0;
QGraphicsPolygonItem *polygonItemEdge = 0;
if (item != m_highlightedObject.data() || !m_highlightPolygon) {
animate = true;
polygonItem = new BoundingBoxPolygonItem(this);
polygonItemEdge = new BoundingBoxPolygonItem(this);
} else {
polygonItem = m_highlightPolygon;
polygonItemEdge = m_highlightPolygonEdge;
}
QPolygonF boundingRectInSceneSpace(item->mapToScene(item->boundingRect()));
QPolygonF boundingRectInLayerItemSpace = mapFromScene(boundingRectInSceneSpace);
polygonItem->setPolygon(boundingRectInLayerItemSpace);
polygonItem->setFlag(QGraphicsItem::ItemIsSelectable, false);
QRectF edgeRect = boundingRectInLayerItemSpace.boundingRect();
edgeRect.adjust(-1, -1, 1, 1);
polygonItemEdge->setPolygon(QPolygonF(edgeRect));
polygonItemEdge->setFlag(QGraphicsItem::ItemIsSelectable, false);
if (item != m_highlightedObject.data())
clear();
m_highlightPolygon = polygonItem;
m_highlightPolygonEdge = polygonItemEdge;
m_highlightedObject = item;
if (item != m_highlightedObject.data()) {
connect(m_highlightedObject.data(), SIGNAL(xChanged()), this, SLOT(refresh()));
connect(m_highlightedObject.data(), SIGNAL(yChanged()), this, SLOT(refresh()));
connect(m_highlightedObject.data(), SIGNAL(widthChanged()), this, SLOT(refresh()));
connect(m_highlightedObject.data(), SIGNAL(heightChanged()), this, SLOT(refresh()));
connect(m_highlightedObject.data(), SIGNAL(rotationChanged()), this, SLOT(refresh()));
}
if (animate) {
m_highlightPolygonEdge->setOpacity(0);
m_animFrame = 0;
m_animTimer->start();
}
}
void BoundingRectHighlighter::refresh()
{
if (!m_highlightedObject.isNull())
highlight(m_highlightedObject.data());
}
} // namespace QmlViewer
#ifndef BOUNDINGRECTHIGHLIGHTER_H
#define BOUNDINGRECTHIGHLIGHTER_H
#include <QObject>
#include <QWeakPointer>
#include "layeritem.h"
QT_FORWARD_DECLARE_CLASS(QGraphicsItem);
QT_FORWARD_DECLARE_CLASS(QPainter);
QT_FORWARD_DECLARE_CLASS(QWidget);
QT_FORWARD_DECLARE_CLASS(QStyleOptionGraphicsItem);
QT_FORWARD_DECLARE_CLASS(QTimer);
namespace QmlViewer {
class QDeclarativeDesignView;
class BoundingBoxPolygonItem : public QGraphicsPolygonItem
{
public:
explicit BoundingBoxPolygonItem(QGraphicsItem *item);
int type() const;
};
class BoundingRectHighlighter : public LayerItem
{
Q_OBJECT
public:
explicit BoundingRectHighlighter(QDeclarativeDesignView *view);
void clear();
void highlight(QGraphicsObject* item);
private slots:
void refresh();
void animTimeout();
private:
Q_DISABLE_COPY(BoundingRectHighlighter);
QDeclarativeDesignView *m_view;
QWeakPointer<QGraphicsObject> m_highlightedObject;
QGraphicsPolygonItem *m_highlightPolygon;
QGraphicsPolygonItem *m_highlightPolygonEdge;
QTimer *m_animTimer;
qreal m_animScale;
int m_animFrame;
};
} // namespace QmlViewer
#endif // BOUNDINGRECTHIGHLIGHTER_H
#include "colorpickertool.h"
#include "qdeclarativedesignview.h"
#include <QMouseEvent>
#include <QKeyEvent>
#include <QRectF>
#include <QRgb>
#include <QImage>
#include <QApplication>
#include <QDebug>
namespace QmlViewer {
ColorPickerTool::ColorPickerTool(QDeclarativeDesignView *view) :
AbstractFormEditorTool(view)
{
m_selectedColor.setRgb(0,0,0);
}
ColorPickerTool::~ColorPickerTool()
{
}
void ColorPickerTool::mousePressEvent(QMouseEvent */*event*/)
{
}
void ColorPickerTool::mouseMoveEvent(QMouseEvent *event)
{
pickColor(event->pos());
}
void ColorPickerTool::mouseReleaseEvent(QMouseEvent *event)
{
pickColor(event->pos());
}
void ColorPickerTool::mouseDoubleClickEvent(QMouseEvent */*event*/)
{
}
void ColorPickerTool::hoverMoveEvent(QMouseEvent */*event*/)
{
}
void ColorPickerTool::keyPressEvent(QKeyEvent */*event*/)
{
}
void ColorPickerTool::keyReleaseEvent(QKeyEvent */*keyEvent*/)
{
}
void ColorPickerTool::wheelEvent(QWheelEvent */*event*/)
{
}
void ColorPickerTool::itemsAboutToRemoved(const QList<QGraphicsItem*> &/*itemList*/)
{
}
void ColorPickerTool::clear()
{
view()->setCursor(Qt::CrossCursor);
}
void ColorPickerTool::graphicsObjectsChanged(const QList<QGraphicsObject*> &/*itemList*/)
{
}
void ColorPickerTool::selectedItemsChanged(const QList<QGraphicsItem*> &/*itemList*/)
{
}
void ColorPickerTool::pickColor(const QPoint &pos)
{
QRectF target(0,0, 1, 1);
QRect source(pos.x(), pos.y(), 1, 1);
QImage img(1, 1, QImage::Format_ARGB32);
QPainter painter(&img);
view()->render(&painter, target, source);
m_selectedColor = QColor::fromRgb(img.pixel(0, 0));
emit selectedColorChanged(m_selectedColor);
}
} // namespace QmlViewer
#ifndef COLORPICKERTOOL_H
#define COLORPICKERTOOL_H
#include "abstractformeditortool.h"
#include <QColor>
QT_FORWARD_DECLARE_CLASS(QPoint);
namespace QmlViewer {
class ColorPickerTool : public AbstractFormEditorTool
{
Q_OBJECT
public:
explicit ColorPickerTool(QDeclarativeDesignView *view);
virtual ~ColorPickerTool();
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseDoubleClickEvent(QMouseEvent *event);
void hoverMoveEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *keyEvent);
void wheelEvent(QWheelEvent *event);
void itemsAboutToRemoved(const QList<QGraphicsItem*> &itemList);
void clear();
void graphicsObjectsChanged(const QList<QGraphicsObject*> &itemList);
signals:
void selectedColorChanged(const QColor &color);
protected:
void selectedItemsChanged(const QList<QGraphicsItem*> &itemList);
private:
void pickColor(const QPoint &pos);
private:
QColor m_selectedColor;
};
} // namespace QmlViewer
#endif // COLORPICKERTOOL_H
INCLUDEPATH += $$PWD
HEADERS += \
$$PWD/abstractformeditortool.h \
$$PWD/selectiontool.h \
$$PWD/layeritem.h \
$$PWD/singleselectionmanipulator.h \
$$PWD/rubberbandselectionmanipulator.h \
$$PWD/selectionrectangle.h \
$$PWD/selectionindicator.h \
$$PWD/qmlviewerconstants.h \
$$PWD/boundingrecthighlighter.h \
$$PWD/subcomponenteditortool.h \
$$PWD/subcomponentmasklayeritem.h \
$$PWD/zoomtool.h \
$$PWD/colorpickertool.h \
$$PWD/qmltoolbar.h \
$$PWD/toolbarcolorbox.h
SOURCES += \
$$PWD/abstractformeditortool.cpp \
$$PWD/selectiontool.cpp \
$$PWD/layeritem.cpp \
$$PWD/singleselectionmanipulator.cpp \
$$PWD/rubberbandselectionmanipulator.cpp \
$$PWD/selectionrectangle.cpp \
$$PWD/selectionindicator.cpp \
$$PWD/boundingrecthighlighter.cpp \
$$PWD/subcomponenteditortool.cpp \
$$PWD/subcomponentmasklayeritem.cpp \
$$PWD/zoomtool.cpp \
$$PWD/colorpickertool.cpp \
$$PWD/qmltoolbar.cpp \
$$PWD/toolbarcolorbox.cpp
RESOURCES += $$PWD/editor.qrc
DEFINES += QWEAKPOINTER_ENABLE_ARROW
<RCC>
<qresource prefix="/qml">
<file>images/resize_handle.png</file>
<file>images/select.png</file>
<file>images/select-marquee.png</file>
<file>images/color-picker.png</file>
<file>images/play.png</file>
<file>images/pause.png</file>
<file>images/from-qml.png</file>
<file>images/zoom.png</file>
<file>images/to-qml.png</file>
</qresource>
</RCC>
src/tools/qml/qmlviewer/editor/images/color-picker.png

3.11 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment