6#include "QskSubWindowArea.h"
8#include "QskPlatform.h"
9#include "QskSubWindow.h"
17 for (
auto child : area->children() )
19 if (
auto window = qobject_cast< QskSubWindow* >( child ) )
21 window->removeEventFilter( area );
22 window->installEventFilter( area );
28 const QRectF& rect,
const QPointF& pos )
30 const qreal tolerance = qskMMToPixels( area->window(), 3 );
33 if ( pos.x() <= rect.left() + tolerance )
35 edges |= Qt::LeftEdge;
37 else if ( pos.x() >= rect.right() - tolerance )
39 edges |= Qt::RightEdge;
42 if ( pos.y() <= rect.top() + tolerance )
46 else if ( pos.y() >= rect.bottom() - tolerance )
48 edges |= Qt::BottomEdge;
54static void qskDragWindow(
const QPointF& off, Qt::Edges edges,
QskSubWindow* window )
58 window->setPosition( window->position() + off );
62 QRectF rect( window->position(), window->size() );
64 if ( edges & Qt::LeftEdge )
65 rect.setLeft( rect.left() + off.x() );
67 if ( edges & Qt::RightEdge )
68 rect.setRight( rect.right() + off.x() );
70 if ( edges & Qt::TopEdge )
71 rect.setTop( rect.top() + off.y() );
73 if ( edges & Qt::BottomEdge )
74 rect.setBottom( rect.bottom() + off.y() );
80class QskSubWindowArea::PrivateData
84 : isDraggableByHeaderOnly( false )
91 bool isDraggableByHeaderOnly : 1;
93 Qt::Edges draggedEdges;
97QskSubWindowArea::QskSubWindowArea( QQuickItem* parent )
99 , m_data( new PrivateData() )
105QskSubWindowArea::~QskSubWindowArea()
111 if ( event->isResized() )
119void QskSubWindowArea::itemChange(
120 QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData& value )
126 case QQuickItem::ItemChildAddedChange:
130 QMetaObject::invokeMethod(
this,
131 [
this ] { qskUpdateEventFilter(
this ); }, Qt::QueuedConnection );
135 case QQuickItem::ItemChildRemovedChange:
137 if ( qobject_cast< QskSubWindow* >( value.item ) )
138 value.item->removeEventFilter(
this );
149bool QskSubWindowArea::eventFilter( QObject*
object, QEvent* event )
151 if (
QskSubWindow* window = qobject_cast< QskSubWindow* >(
object ) )
153 switch ( event->type() )
155 case QEvent::MouseButtonPress:
156 case QEvent::MouseButtonRelease:
157 case QEvent::MouseMove:
159 bool ok = mouseEventFilter( window,
static_cast< QMouseEvent*
>( event ) );
167 setActive( window,
true );
172 setActive( window,
false );
182 return Inherited::eventFilter(
object, event );
185bool QskSubWindowArea::mouseEventFilter(
QskSubWindow* window,
const QMouseEvent* event )
187 if ( window ==
nullptr || window->parentItem() !=
this )
192 switch ( event->type() )
194 case QEvent::MouseButtonPress:
196 const auto mousePos = qskMousePosition( event );
198 if ( !( cr.contains( mousePos ) &&
199 event->button() == Qt::LeftButton ) )
204 if ( event->button() == Qt::LeftButton )
205 window->setFocus(
true );
208 if ( window->titleBarRect().contains( qskMousePosition( event ) ) )
216 bool doDrag = !m_data->isDraggableByHeaderOnly;
220 doDrag = window->titleBarRect().contains( mousePos );
225 m_data->isDragging =
true;
226 m_data->draggedEdges = qskSelectedEdges(
this, cr, mousePos );
227 m_data->mousePos = qskMouseScenePosition( event );
229 setDragging( window,
true );
235 case QEvent::MouseMove:
237 if ( m_data->isDragging )
239 const auto scenePos = qskMouseScenePosition( event );
241 qskDragWindow( scenePos - m_data->mousePos,
242 m_data->draggedEdges, window );
244 m_data->mousePos = scenePos;
249 case QEvent::MouseButtonRelease:
251 if ( m_data->isDragging )
253 setDragging( window,
false );
255 m_data->mousePos = QPointF();
256 m_data->isDragging =
false;
271void QskSubWindowArea::setDragging(
QskSubWindow* window,
bool on )
273 window->setOpacity( on ? 0.6 : 1.0 );
276void QskSubWindowArea::setActive(
QskSubWindow* window,
bool on )
278 qDebug() << window << on;
281#include "moc_QskSubWindowArea.cpp"
void itemChange(ItemChange, const ItemChangeData &) override
QRectF contentsRect() const
virtual void geometryChangeEvent(QskGeometryChangeEvent *)
void setGeometry(qreal x, qreal y, qreal width, qreal height)
void geometryChangeEvent(QskGeometryChangeEvent *) override