From 5a4f7ea7badb537a4dc145227056d40d80b15fb0 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 8 Apr 2015 17:19:56 +0200 Subject: [PATCH 1/4] Implement InverseMouseArea --- mix/InverseMouseArea.cpp | 59 ++++++++++++++++++++++++++++++++++++++++ mix/InverseMouseArea.h | 50 ++++++++++++++++++++++++++++++++++ mix/MixApplication.cpp | 3 +- mix/qml/StatusPane.qml | 15 ++++++++++ 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 mix/InverseMouseArea.cpp create mode 100644 mix/InverseMouseArea.h diff --git a/mix/InverseMouseArea.cpp b/mix/InverseMouseArea.cpp new file mode 100644 index 000000000..172862038 --- /dev/null +++ b/mix/InverseMouseArea.cpp @@ -0,0 +1,59 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file InverseMouseArea.cpp + * @author Yann yann@ethdev.com + * @date 2014 + * Ethereum IDE client. + */ + +#include +#include +#include +#include +#include "InverseMouseArea.h" + +using namespace dev::mix; + +void InverseMouseArea::itemChange(ItemChange _c, const ItemChangeData& _v) +{ + qDebug() << "itemCHange"; + Q_UNUSED(_v); + + if (_c == ItemSceneChange) + { + + window()->installEventFilter(this); + //this->parentItem()->installEventFilter(this); + } + +} + +bool InverseMouseArea::eventFilter(QObject* _obj, QEvent* _ev) +{ + qDebug() << _ev->type(); + Q_UNUSED(_obj); + if (_ev->type() == QEvent::MouseButtonPress) + { + qDebug() << "mouse event"; + if (!this->contains(static_cast(_ev)->pos())) + { + qDebug() << "click outside"; + emit clickedOutside(); + } + } + return false; +} diff --git a/mix/InverseMouseArea.h b/mix/InverseMouseArea.h new file mode 100644 index 000000000..8105e03de --- /dev/null +++ b/mix/InverseMouseArea.h @@ -0,0 +1,50 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file InverseMouseArea.h + * @author Yann yann@ethdev.com + * @date 2014 + * Ethereum IDE client. + */ + +#pragma once + +#include + +namespace dev +{ +namespace mix +{ + +class InverseMouseArea: public QQuickItem +{ + Q_OBJECT + +public: + InverseMouseArea(QQuickItem* _parent = 0): QQuickItem(_parent) {} + ~InverseMouseArea() { /*scene()->removeEventFilter(this);*/ } + +protected: + void itemChange(ItemChange _c, const ItemChangeData& _v); + bool eventFilter(QObject* _obj, QEvent *_ev); + +signals: + void clickedOutside(); +}; + +} +} + diff --git a/mix/MixApplication.cpp b/mix/MixApplication.cpp index 4822b8da5..d81a4f6b2 100644 --- a/mix/MixApplication.cpp +++ b/mix/MixApplication.cpp @@ -36,6 +36,7 @@ #include "SortFilterProxyModel.h" #include "Clipboard.h" #include "HttpServer.h" +#include "InverseMouseArea.h" extern int qInitResources_js(); using namespace dev::mix; @@ -89,9 +90,9 @@ void MixApplication::initialize() qmlRegisterType("org.ethereum.qml.QSolidityType", 1, 0, "QSolidityType"); qmlRegisterType("org.ethereum.qml.Clipboard", 1, 0, "Clipboard"); qmlRegisterType("HttpServer", 1, 0, "HttpServer"); + qmlRegisterType("org.ethereum.qml.InverseMouseArea", 1, 0, "InverseMouseArea"); qRegisterMetaType("CodeModel*"); qRegisterMetaType("ClientModel*"); - qRegisterMetaType("ClientModel*"); } MixApplication::~MixApplication() diff --git a/mix/qml/StatusPane.qml b/mix/qml/StatusPane.qml index 6524ef6d8..36df419ed 100644 --- a/mix/qml/StatusPane.qml +++ b/mix/qml/StatusPane.qml @@ -2,6 +2,7 @@ import QtQuick 2.2 import QtQuick.Controls 1.1 import QtQuick.Layouts 1.1 import QtQuick.Controls.Styles 1.3 +import org.ethereum.qml.InverseMouseArea 1.0 import "js/ErrorLocationFormater.js" as ErrorLocationFormater import "." @@ -247,6 +248,20 @@ Rectangle { Rectangle { + InverseMouseArea + { + id: outsideClick + anchors.fill: parent + } + + Connections + { + target: outsideClick + onClickedOutside: { + toggle(); + } + } + function toggle() { if (logsContainer.state === "opened") From d182406015445ace1cbd45dd3c541a6edd378c15 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 9 Apr 2015 10:44:46 +0200 Subject: [PATCH 2/4] Implement OutSideClick --- mix/InverseMouseArea.cpp | 40 ++++++++++++++++++++---------------- mix/InverseMouseArea.h | 9 +++++++- mix/qml/LogsPane.qml | 42 -------------------------------------- mix/qml/StatesComboBox.qml | 38 ++++++++++++++++++++++++++++++---- mix/qml/StatusPane.qml | 11 +++++----- mix/qml/TransactionLog.qml | 3 ++- 6 files changed, 71 insertions(+), 72 deletions(-) diff --git a/mix/InverseMouseArea.cpp b/mix/InverseMouseArea.cpp index 172862038..aa26b4ae5 100644 --- a/mix/InverseMouseArea.cpp +++ b/mix/InverseMouseArea.cpp @@ -30,30 +30,34 @@ using namespace dev::mix; void InverseMouseArea::itemChange(ItemChange _c, const ItemChangeData& _v) { - qDebug() << "itemCHange"; + if (!this->m_active) + return; Q_UNUSED(_v); - - if (_c == ItemSceneChange) - { - + if (_c == ItemSceneChange && window()) window()->installEventFilter(this); - //this->parentItem()->installEventFilter(this); - } - } bool InverseMouseArea::eventFilter(QObject* _obj, QEvent* _ev) { - qDebug() << _ev->type(); + if (!this->m_active) + return false; Q_UNUSED(_obj); - if (_ev->type() == QEvent::MouseButtonPress) - { - qDebug() << "mouse event"; - if (!this->contains(static_cast(_ev)->pos())) - { - qDebug() << "click outside"; - emit clickedOutside(); - } - } + if (_ev->type() == QEvent::MouseButtonPress && !this->contains(static_cast(_ev)->pos())) + emit clickedOutside(); return false; } + +bool InverseMouseArea::contains(const QPoint& _point) const +{ + if (!this->m_active) + return false; + QPointF global = this->parentItem()->mapToItem(0, QPointF(0, 0)); + return QRectF(global.x(), global.y(), this->parentItem()->width(), this->parentItem()->height()).contains(_point); +} + +void InverseMouseArea::setActive(bool _v) +{ + m_active = _v; + if (m_active && window()) + window()->installEventFilter(this); +} diff --git a/mix/InverseMouseArea.h b/mix/InverseMouseArea.h index 8105e03de..42f930ba6 100644 --- a/mix/InverseMouseArea.h +++ b/mix/InverseMouseArea.h @@ -22,6 +22,7 @@ #pragma once +#include #include namespace dev @@ -32,14 +33,20 @@ namespace mix class InverseMouseArea: public QQuickItem { Q_OBJECT + Q_PROPERTY(bool active MEMBER m_active WRITE setActive) public: InverseMouseArea(QQuickItem* _parent = 0): QQuickItem(_parent) {} - ~InverseMouseArea() { /*scene()->removeEventFilter(this);*/ } + ~InverseMouseArea() { if (window()) { window()->removeEventFilter(this); } } + void setActive(bool _v); protected: void itemChange(ItemChange _c, const ItemChangeData& _v); bool eventFilter(QObject* _obj, QEvent *_ev); + bool contains(const QPoint& _point) const; + +private: + bool m_active; signals: void clickedOutside(); diff --git a/mix/qml/LogsPane.qml b/mix/qml/LogsPane.qml index 21e14e817..175f7d96b 100644 --- a/mix/qml/LogsPane.qml +++ b/mix/qml/LogsPane.qml @@ -585,48 +585,6 @@ Rectangle } } } - - Rectangle - { - height: logStyle.generic.layout.headerButtonHeight - anchors.verticalCenter: parent.verticalCenter - color: "transparent" - width: 20 - Button - { - id: hideButton - action: hideAction - anchors.fill: parent - anchors.verticalCenter: parent.verticalCenter - height: 25 - style: - ButtonStyle { - background: - Rectangle { - height: logStyle.generic.layout.headerButtonHeight - implicitHeight: logStyle.generic.layout.headerButtonHeight - color: "transparent" - } - } - } - - Image { - id: hideImage - source: "qrc:/qml/img/exit.png" - anchors.centerIn: parent - fillMode: Image.PreserveAspectFit - width: 20 - height: 25 - } - - Action { - id: hideAction - tooltip: qsTr("Exit") - onTriggered: { - logsPane.parent.toggle(); - } - } - } } } diff --git a/mix/qml/StatesComboBox.qml b/mix/qml/StatesComboBox.qml index bc7a4853d..c3868e3ee 100644 --- a/mix/qml/StatesComboBox.qml +++ b/mix/qml/StatesComboBox.qml @@ -24,13 +24,15 @@ import QtQuick 2.0 import QtQuick.Controls 1.0 import QtQuick.Layouts 1.1 import QtGraphicalEffects 1.0 +import org.ethereum.qml.InverseMouseArea 1.0 Rectangle { id: statesComboBox width: 200 height: 23 - + border.width: 2 + border.color: "red" Component.onCompleted: { var top = dropDownList while (top.parent) { @@ -62,6 +64,12 @@ Rectangle { chosenItemText.text = statesComboBox.items.get(index).title } + function hideDropDown() + { + if (statesComboBox.state === "dropDown") + statesComboBox.state = ""; + } + signal comboClicked property variant colorItem @@ -76,14 +84,13 @@ Rectangle { { id: boldFont } - smooth: true + Rectangle { id: chosenItem width: parent.width height: statesComboBox.height color: statesComboBox.color - Text { id: chosenItemText anchors.left: parent.left @@ -97,7 +104,13 @@ Rectangle { MouseArea { anchors.fill: parent onClicked: { - statesComboBox.state = statesComboBox.state === "dropDown" ? "" : "dropDown" + if (outsideClick.trigerred) + { + outsideClick.trigerred = false; + return; + } + if (statesCombo.state === "") + statesCombo.state = "dropDown"; } } } @@ -124,8 +137,21 @@ Rectangle { anchors.topMargin: 23 color: statesComboBox.color + InverseMouseArea + { + property bool trigerred: false + id: outsideClick + anchors.fill: parent + active: false + onClickedOutside: { + trigerred = true; + statesCombo.hideDropDown() + } + } + ColumnLayout { spacing: 2 + TableView { id: listView height: 20 @@ -256,5 +282,9 @@ Rectangle { height: 20 implicitHeight: (statesComboBox.rowHeight * (statesComboBox.items.count)) } + PropertyChanges { + target: outsideClick + active: true + } } } diff --git a/mix/qml/StatusPane.qml b/mix/qml/StatusPane.qml index 36df419ed..9e10edbe9 100644 --- a/mix/qml/StatusPane.qml +++ b/mix/qml/StatusPane.qml @@ -252,13 +252,9 @@ Rectangle { { id: outsideClick anchors.fill: parent - } - - Connections - { - target: outsideClick + active: false onClickedOutside: { - toggle(); + logsContainer.toggle(); } } @@ -309,11 +305,14 @@ Rectangle { State { name: "opened"; PropertyChanges { target: logsContainer; height: 500; visible: true } + PropertyChanges { target: outsideClick; active: true } + }, State { name: "closed"; PropertyChanges { target: logsContainer; height: 0; visible: false } PropertyChanges { target: statusContainer; width: 600; height: 30 } + PropertyChanges { target: outsideClick; active: false } } ] transitions: Transition { diff --git a/mix/qml/TransactionLog.qml b/mix/qml/TransactionLog.qml index ad97846ae..ca8b37098 100644 --- a/mix/qml/TransactionLog.qml +++ b/mix/qml/TransactionLog.qml @@ -4,6 +4,7 @@ import QtQuick.Controls.Styles 1.1 import QtQuick.Dialogs 1.1 import QtQuick.Layouts 1.1 import org.ethereum.qml.RecordLogEntry 1.0 +import org.ethereum.qml.InverseMouseArea 1.0 Item { property ListModel fullModel: ListModel{} @@ -60,7 +61,7 @@ Item { target: projectModel.stateListModel onStateRun: { if (statesCombo.selectedIndex !== index) - statesCombo.setSelectedIndex( index ); + statesCombo.setSelectedIndex(index) } } } From 52d943aed99b393137d24ee54e10441a4ed6b81a Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 9 Apr 2015 10:49:52 +0200 Subject: [PATCH 3/4] small changes --- mix/InverseMouseArea.cpp | 2 +- mix/InverseMouseArea.h | 2 +- mix/qml/StatesComboBox.qml | 9 +-------- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/mix/InverseMouseArea.cpp b/mix/InverseMouseArea.cpp index aa26b4ae5..b696592b5 100644 --- a/mix/InverseMouseArea.cpp +++ b/mix/InverseMouseArea.cpp @@ -16,7 +16,7 @@ */ /** @file InverseMouseArea.cpp * @author Yann yann@ethdev.com - * @date 2014 + * @date 2015 * Ethereum IDE client. */ diff --git a/mix/InverseMouseArea.h b/mix/InverseMouseArea.h index 42f930ba6..52943bfad 100644 --- a/mix/InverseMouseArea.h +++ b/mix/InverseMouseArea.h @@ -16,7 +16,7 @@ */ /** @file InverseMouseArea.h * @author Yann yann@ethdev.com - * @date 2014 + * @date 2015 * Ethereum IDE client. */ diff --git a/mix/qml/StatesComboBox.qml b/mix/qml/StatesComboBox.qml index c3868e3ee..62758cbe4 100644 --- a/mix/qml/StatesComboBox.qml +++ b/mix/qml/StatesComboBox.qml @@ -31,8 +31,6 @@ Rectangle { width: 200 height: 23 - border.width: 2 - border.color: "red" Component.onCompleted: { var top = dropDownList while (top.parent) { @@ -85,7 +83,6 @@ Rectangle { id: boldFont } smooth: true - Rectangle { id: chosenItem width: parent.width @@ -105,11 +102,8 @@ Rectangle { anchors.fill: parent onClicked: { if (outsideClick.trigerred) - { outsideClick.trigerred = false; - return; - } - if (statesCombo.state === "") + else if (statesCombo.state === "") statesCombo.state = "dropDown"; } } @@ -151,7 +145,6 @@ Rectangle { ColumnLayout { spacing: 2 - TableView { id: listView height: 20 From ddb989200573977d0d6ebe6c11e98c688c1fbe73 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 9 Apr 2015 10:53:30 +0200 Subject: [PATCH 4/4] small changes --- mix/InverseMouseArea.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mix/InverseMouseArea.cpp b/mix/InverseMouseArea.cpp index b696592b5..06159033c 100644 --- a/mix/InverseMouseArea.cpp +++ b/mix/InverseMouseArea.cpp @@ -30,19 +30,15 @@ using namespace dev::mix; void InverseMouseArea::itemChange(ItemChange _c, const ItemChangeData& _v) { - if (!this->m_active) - return; Q_UNUSED(_v); - if (_c == ItemSceneChange && window()) + if (this->m_active && _c == ItemSceneChange && window()) window()->installEventFilter(this); } bool InverseMouseArea::eventFilter(QObject* _obj, QEvent* _ev) { - if (!this->m_active) - return false; Q_UNUSED(_obj); - if (_ev->type() == QEvent::MouseButtonPress && !this->contains(static_cast(_ev)->pos())) + if (this->m_active && _ev->type() == QEvent::MouseButtonPress && !this->contains(static_cast(_ev)->pos())) emit clickedOutside(); return false; }