Gav Wood
10 years ago
7 changed files with 161 additions and 48 deletions
@ -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 <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file InverseMouseArea.cpp
|
|||
* @author Yann yann@ethdev.com |
|||
* @date 2015 |
|||
* Ethereum IDE client. |
|||
*/ |
|||
|
|||
#include <QQuickWindow> |
|||
#include <QDebug> |
|||
#include <QQuickItem> |
|||
#include <QGraphicsSceneMouseEvent> |
|||
#include "InverseMouseArea.h" |
|||
|
|||
using namespace dev::mix; |
|||
|
|||
void InverseMouseArea::itemChange(ItemChange _c, const ItemChangeData& _v) |
|||
{ |
|||
Q_UNUSED(_v); |
|||
if (this->m_active && _c == ItemSceneChange && window()) |
|||
window()->installEventFilter(this); |
|||
} |
|||
|
|||
bool InverseMouseArea::eventFilter(QObject* _obj, QEvent* _ev) |
|||
{ |
|||
Q_UNUSED(_obj); |
|||
if (this->m_active && _ev->type() == QEvent::MouseButtonPress && !this->contains(static_cast<QMouseEvent*>(_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); |
|||
} |
@ -0,0 +1,57 @@ |
|||
/*
|
|||
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 <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file InverseMouseArea.h
|
|||
* @author Yann yann@ethdev.com |
|||
* @date 2015 |
|||
* Ethereum IDE client. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <QQuickWindow> |
|||
#include <QQuickItem> |
|||
|
|||
namespace dev |
|||
{ |
|||
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() { 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(); |
|||
}; |
|||
|
|||
} |
|||
} |
|||
|
Loading…
Reference in new issue