diff --git a/src/plugins/qmljsinspector/images/color-picker-small-hicontrast.png b/src/plugins/qmljsinspector/images/color-picker-small-hicontrast.png new file mode 100644 index 0000000000000000000000000000000000000000..95b88ac8f0a20ce091821002793d1cfc3302c0b2 Binary files /dev/null and b/src/plugins/qmljsinspector/images/color-picker-small-hicontrast.png differ diff --git a/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp b/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp index c33e59f3a8d8a70e6109b9882b605b7e266238e9..6cd083b644cf80dc0c578ae493186349eef3cf66 100644 --- a/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp +++ b/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp @@ -1,5 +1,6 @@ #include "qmlinspectortoolbar.h" #include "qmljsinspectorconstants.h" +#include "qmljstoolbarcolorbox.h" #include <extensionsystem/pluginmanager.h> #include <coreplugin/icore.h> @@ -41,6 +42,8 @@ QmlInspectorToolbar::QmlInspectorToolbar(QObject *parent) : m_fourthAnimSpeedAction(0), m_eighthAnimSpeedAction(0), m_tenthAnimSpeedAction(0), + m_menuPauseAction(0), + m_colorBox(0), m_emitSignals(true), m_isRunning(false), m_animationSpeed(1.0f), @@ -242,6 +245,12 @@ void QmlInspectorToolbar::createActions(const Core::Context &context) configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::ZOOM_ACTION)->action())); configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::COLOR_PICKER_ACTION)->action())); + m_colorBox = new ToolBarColorBox(configBar); + m_colorBox->setMinimumSize(20, 20); + m_colorBox->setMaximumSize(20, 20); + m_colorBox->setInnerBorderColor(QColor(192,192,192)); + m_colorBox->setOuterBorderColor(QColor(58,58,58)); + configBarLayout->addWidget(m_colorBox); //configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::TO_QML_ACTION)->action())); configBarLayout->addStretch(); @@ -391,6 +400,11 @@ void QmlInspectorToolbar::activateZoomOnClick() } } +void QmlInspectorToolbar::setSelectedColor(const QColor &color) +{ + m_colorBox->setColor(color); +} + void QmlInspectorToolbar::activateFromQml() { if (m_emitSignals) diff --git a/src/plugins/qmljsinspector/qmlinspectortoolbar.h b/src/plugins/qmljsinspector/qmlinspectortoolbar.h index ccc653f2d216118e444abcc9660f6eea10cde9b4..efed26f50f6cfdff4ea4151ccd52dcea6fe3951f 100644 --- a/src/plugins/qmljsinspector/qmlinspectortoolbar.h +++ b/src/plugins/qmljsinspector/qmlinspectortoolbar.h @@ -4,12 +4,16 @@ #include <QObject> QT_FORWARD_DECLARE_CLASS(QAction); +QT_FORWARD_DECLARE_CLASS(QColor); namespace Core { class Context; } namespace QmlJSInspector { + +class ToolBarColorBox; + namespace Internal { class QmlInspectorToolbar : public QObject @@ -40,6 +44,7 @@ public slots: void activateZoomTool(); void changeAnimationSpeed(qreal slowdownFactor); void setDesignModeBehavior(bool inDesignMode); + void setSelectedColor(const QColor &color); signals: void animationSpeedChanged(qreal slowdownFactor = 1.0f); @@ -91,6 +96,8 @@ private: QAction *m_tenthAnimSpeedAction; QAction *m_menuPauseAction; + ToolBarColorBox *m_colorBox; + bool m_emitSignals; bool m_isRunning; qreal m_animationSpeed; diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.cpp b/src/plugins/qmljsinspector/qmljsclientproxy.cpp index e0260ed4429871fcb969479c70a7bbb2f3761226..8217b67d9aec867028b988f26fe80e4c77a3eff5 100644 --- a/src/plugins/qmljsinspector/qmljsclientproxy.cpp +++ b/src/plugins/qmljsinspector/qmljsclientproxy.cpp @@ -80,6 +80,8 @@ bool ClientProxy::connectToViewer(const QString &host, quint16 port) SIGNAL(animationSpeedChanged(qreal)), this, SIGNAL(animationSpeedChanged(qreal))); disconnect(m_designClient, SIGNAL(designModeBehaviorChanged(bool)), this, SIGNAL(designModeBehaviorChanged(bool))); + disconnect(m_designClient, + SIGNAL(selectedColorChanged(QColor)), this, SIGNAL(selectedColorChanged(QColor))); emit aboutToDisconnect(); @@ -224,6 +226,7 @@ void ClientProxy::connectionStateChanged() connect(m_designClient, SIGNAL(designModeBehaviorChanged(bool)), SIGNAL(designModeBehaviorChanged(bool))); connect(m_designClient, SIGNAL(reloaded()), this, SIGNAL(serverReloaded())); + connect(m_designClient, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor))); } (void) new DebuggerClient(m_conn); diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.h b/src/plugins/qmljsinspector/qmljsclientproxy.h index a36948186295d1dbfffd8f7228e1295532bcc849..3a2bcad21007a4d1b7d671c9f006cc394fa80e7f 100644 --- a/src/plugins/qmljsinspector/qmljsclientproxy.h +++ b/src/plugins/qmljsinspector/qmljsclientproxy.h @@ -95,6 +95,7 @@ signals: void animationSpeedChanged(qreal slowdownFactor); void designModeBehaviorChanged(bool inDesignMode); void serverReloaded(); + void selectedColorChanged(const QColor &color); public slots: void queryEngineContext(int id); diff --git a/src/plugins/qmljsinspector/qmljsdesigndebugclient.cpp b/src/plugins/qmljsinspector/qmljsdesigndebugclient.cpp index d76f75fbd49e7c5059b047c5909efcff655df347..f503fefea0450174cb5304faf59ac81ce79a3c47 100644 --- a/src/plugins/qmljsinspector/qmljsdesigndebugclient.cpp +++ b/src/plugins/qmljsinspector/qmljsdesigndebugclient.cpp @@ -43,6 +43,8 @@ #include "qmljsclientproxy.h" #include "qmljsinspectorconstants.h" +#include <QColor> + namespace QmlJSInspector { namespace Internal { @@ -98,6 +100,10 @@ void QmlJSDesignDebugClient::messageReceived(const QByteArray &message) emit designModeBehaviorChanged(inDesignMode); } else if (type == "RELOADED") { emit reloaded(); + } else if (type == "COLOR_CHANGED") { + QColor col; + ds >> col; + emit selectedColorChanged(col); } } diff --git a/src/plugins/qmljsinspector/qmljsdesigndebugclient.h b/src/plugins/qmljsinspector/qmljsdesigndebugclient.h index f1f45a9242b00fb684aad01864aa11e7ca10560d..217f969e89c5d00ba932def4d49a62c8caef925a 100644 --- a/src/plugins/qmljsinspector/qmljsdesigndebugclient.h +++ b/src/plugins/qmljsinspector/qmljsdesigndebugclient.h @@ -75,6 +75,7 @@ public: signals: void currentObjectsChanged(const QList<int> &debugIds); + void selectedColorChanged(const QColor &color); void colorPickerActivated(); void selectToolActivated(); void selectMarqueeToolActivated(); diff --git a/src/plugins/qmljsinspector/qmljsinspector.pro b/src/plugins/qmljsinspector/qmljsinspector.pro index d543ca86938f650655d57c2d08a7703d9eaf6a53..ac2dc277a54f7c625f13387c38eb038bd7d49160 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.pro +++ b/src/plugins/qmljsinspector/qmljsinspector.pro @@ -19,6 +19,7 @@ qmljsclientproxy.h \ qmljsinspector.h \ qmlinspectortoolbar.h \ qmljslivetextpreview.h \ +qmljstoolbarcolorbox.h \ qmljsdesigndebugclient.h SOURCES += \ @@ -29,6 +30,7 @@ qmljsclientproxy.cpp \ qmljsinspector.cpp \ qmlinspectortoolbar.cpp \ qmljslivetextpreview.cpp \ +qmljstoolbarcolorbox.cpp \ qmljsdesigndebugclient.cpp OTHER_FILES += QmlJSInspector.pluginspec diff --git a/src/plugins/qmljsinspector/qmljsinspector.qrc b/src/plugins/qmljsinspector/qmljsinspector.qrc index 36b7587803dbdd2385f9cbbdf82b02fcbb0c5e1b..95700236cb2ad50e9f57125c12608abcb9cc31b2 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.qrc +++ b/src/plugins/qmljsinspector/qmljsinspector.qrc @@ -18,5 +18,6 @@ <file>images/zoom-small.png</file> <file>images/select-marquee-small.png</file> <file>images/designmode.png</file> + <file>images/color-picker-small-hicontrast.png</file> </qresource> </RCC> diff --git a/src/plugins/qmljsinspector/qmljsinspectorplugin.cpp b/src/plugins/qmljsinspector/qmljsinspectorplugin.cpp index a19b9b463e6bcbc9dd2e4adba90c3b1448adfdd9..f69fb16967ff60b24aaf8bfe5b200f817ee200c1 100644 --- a/src/plugins/qmljsinspector/qmljsinspectorplugin.cpp +++ b/src/plugins/qmljsinspector/qmljsinspectorplugin.cpp @@ -173,6 +173,7 @@ void InspectorPlugin::extensionsInitialized() connect(_clientProxy, SIGNAL(selectMarqueeToolActivated()), m_toolbar, SLOT(activateMarqueeSelectTool())); connect(_clientProxy, SIGNAL(zoomToolActivated()), m_toolbar, SLOT(activateZoomTool())); connect(_clientProxy, SIGNAL(designModeBehaviorChanged(bool)), m_toolbar, SLOT(setDesignModeBehavior(bool))); + connect(_clientProxy, SIGNAL(selectedColorChanged(QColor)), m_toolbar, SLOT(setSelectedColor(QColor))); connect(_clientProxy, SIGNAL(animationSpeedChanged(qreal)), m_toolbar, SLOT(changeAnimationSpeed(qreal))); } diff --git a/src/plugins/qmljsinspector/qmljstoolbarcolorbox.cpp b/src/plugins/qmljsinspector/qmljstoolbarcolorbox.cpp new file mode 100644 index 0000000000000000000000000000000000000000..64d4f7411ae9d5e26845bc6f0e1570cdb165c501 --- /dev/null +++ b/src/plugins/qmljsinspector/qmljstoolbarcolorbox.cpp @@ -0,0 +1,108 @@ +#include "qmljstoolbarcolorbox.h" + +#include <QPixmap> +#include <QPainter> +#include <QMenu> +#include <QAction> +#include <QContextMenuEvent> +#include <QClipboard> +#include <QApplication> +#include <QColorDialog> +#include <QDrag> +#include <QMimeData> + +#include <QDebug> + +namespace QmlJSInspector { + +ToolBarColorBox::ToolBarColorBox(QWidget *parent) : + QLabel(parent) +{ + m_color = Qt::white; + m_borderColorOuter = Qt::white; + m_borderColorInner = QColor(143, 143 ,143); + + m_copyHexColorAction = new QAction(QIcon(":/qml/images/color-picker-small-hicontrast.png"), tr("Copy Color"), this); + connect(m_copyHexColorAction, SIGNAL(triggered()), SLOT(copyColorToClipboard())); + setScaledContents(false); +} + +void ToolBarColorBox::setColor(const QColor &color) +{ + m_color = color; + + QPixmap pix = createDragPixmap(width()); + setPixmap(pix); + update(); +} + +void ToolBarColorBox::setInnerBorderColor(const QColor &color) +{ + m_borderColorInner = color; + setColor(m_color); +} + +void ToolBarColorBox::setOuterBorderColor(const QColor &color) + { + m_borderColorOuter = color; + setColor(m_color); + } + +void ToolBarColorBox::mousePressEvent(QMouseEvent *event) +{ + m_dragBeginPoint = event->pos(); + m_dragStarted = false; +} + +void ToolBarColorBox::mouseMoveEvent(QMouseEvent *event) +{ + if (event->buttons() & Qt::LeftButton + && QPoint(event->pos() - m_dragBeginPoint).manhattanLength() > QApplication::startDragDistance() + && !m_dragStarted) + { + m_dragStarted = true; + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + mimeData->setText(m_color.name()); + drag->setMimeData(mimeData); + drag->setPixmap(createDragPixmap()); + + drag->exec(); + } +} + +QPixmap ToolBarColorBox::createDragPixmap(int size) const +{ + QPixmap pix(size, size); + QPainter p(&pix); + + p.setBrush(QBrush(m_color)); + p.setPen(QPen(QBrush(m_borderColorInner),1)); + + p.fillRect(0, 0, size, size, m_borderColorOuter); + p.drawRect(1,1, size - 3, size - 3); + return pix; +} + +void ToolBarColorBox::contextMenuEvent(QContextMenuEvent *ev) +{ + QMenu contextMenu; + contextMenu.addAction(m_copyHexColorAction); + contextMenu.exec(ev->globalPos()); +} + +void ToolBarColorBox::mouseDoubleClickEvent(QMouseEvent *) +{ + QColorDialog dialog(m_color); + dialog.show(); +} + +void ToolBarColorBox::copyColorToClipboard() +{ + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(m_color.name()); +} + + +} // namespace QmlJSInspector diff --git a/src/plugins/qmljsinspector/qmljstoolbarcolorbox.h b/src/plugins/qmljsinspector/qmljstoolbarcolorbox.h new file mode 100644 index 0000000000000000000000000000000000000000..1b375544c282c0c8e4917a4f89d05624fca95d2c --- /dev/null +++ b/src/plugins/qmljsinspector/qmljstoolbarcolorbox.h @@ -0,0 +1,46 @@ +#ifndef TOOLBARCOLORBOX_H +#define TOOLBARCOLORBOX_H + +#include <QLabel> +#include <QColor> +#include <QPoint> + +QT_FORWARD_DECLARE_CLASS(QContextMenuEvent); +QT_FORWARD_DECLARE_CLASS(QAction); + +namespace QmlJSInspector { + +class ToolBarColorBox : public QLabel +{ + Q_OBJECT +public: + explicit ToolBarColorBox(QWidget *parent = 0); + void setColor(const QColor &color); + void setInnerBorderColor(const QColor &color); + void setOuterBorderColor(const QColor &color); + +protected: + void contextMenuEvent(QContextMenuEvent *ev); + void mouseDoubleClickEvent(QMouseEvent *); + void mousePressEvent(QMouseEvent *ev); + void mouseMoveEvent(QMouseEvent *ev); +private slots: + void copyColorToClipboard(); + +private: + QPixmap createDragPixmap(int size = 24) const; + +private: + bool m_dragStarted; + QPoint m_dragBeginPoint; + QAction *m_copyHexColorAction; + QColor m_color; + + QColor m_borderColorOuter; + QColor m_borderColorInner; + +}; + +} // namespace QmlJSInspector + +#endif // TOOLBARCOLORBOX_H diff --git a/src/tools/qml/qmlobserver/qdeclarativedesigndebugserver.cpp b/src/tools/qml/qmlobserver/qdeclarativedesigndebugserver.cpp index 1d53adf6454386309ea3fc88dbc2cfc9f01bef8d..367e74c41afba6f8303dde58f0c9416ed3fafc1e 100644 --- a/src/tools/qml/qmlobserver/qdeclarativedesigndebugserver.cpp +++ b/src/tools/qml/qmlobserver/qdeclarativedesigndebugserver.cpp @@ -1,5 +1,7 @@ #include "qdeclarativedesigndebugserver.h" + #include <QStringList> +#include <QColor> #include <QDebug> @@ -128,3 +130,13 @@ void QDeclarativeDesignDebugServer::reloaded() sendMessage(message); } +void QDeclarativeDesignDebugServer::selectedColorChanged(const QColor &color) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << QByteArray("COLOR_CHANGED") + << color; + + sendMessage(message); +} diff --git a/src/tools/qml/qmlobserver/qdeclarativedesigndebugserver.h b/src/tools/qml/qmlobserver/qdeclarativedesigndebugserver.h index a2f2890feb34d0618282f4cdcde4e4f076e8790a..55a91a7af33dd81c0432386a90969c2f03e57aec 100644 --- a/src/tools/qml/qmlobserver/qdeclarativedesigndebugserver.h +++ b/src/tools/qml/qmlobserver/qdeclarativedesigndebugserver.h @@ -47,6 +47,7 @@ QT_BEGIN_NAMESPACE +class QColor; class QDeclarativeEngine; class QDeclarativeContext; class QDeclarativeWatcher; @@ -64,6 +65,9 @@ public: void setCurrentTool(QmlViewer::Constants::DesignTool toolId); void reloaded(); +public Q_SLOTS: + void selectedColorChanged(const QColor &color); + Q_SIGNALS: void currentObjectsChanged(const QList<QObject*> &objects); void designModeBehaviorChanged(bool inDesignMode); diff --git a/src/tools/qml/qmlobserver/qdeclarativedesignview.cpp b/src/tools/qml/qmlobserver/qdeclarativedesignview.cpp index 76de0ab06ef688394984520159f48ee43a6106c8..d1316925e7f3dc575122304bbb4ad75566cdd788 100644 --- a/src/tools/qml/qmlobserver/qdeclarativedesignview.cpp +++ b/src/tools/qml/qmlobserver/qdeclarativedesignview.cpp @@ -58,6 +58,8 @@ QDeclarativeDesignView::QDeclarativeDesignView(QWidget *parent) : connect(this, SIGNAL(statusChanged(QDeclarativeView::Status)), SLOT(onStatusChanged(QDeclarativeView::Status))); connect(m_colorPickerTool, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor))); + connect(m_colorPickerTool, SIGNAL(selectedColorChanged(QColor)), + qmlDesignDebugServer(), SLOT(selectedColorChanged(QColor))); createToolbar(); }