qskinny/src/controls/QskEvent.cpp

121 lines
2.9 KiB
C++
Raw Normal View History

2018-08-03 08:15:28 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
2017-07-21 18:21:34 +02:00
#include "QskEvent.h"
#include "QskGesture.h"
2018-07-19 14:10:48 +02:00
#include <qevent.h>
2017-07-21 18:21:34 +02:00
static void qskRegisterEventTypes()
{
// We don't ask QEvent::registerEventType for unique ids as it prevents
// using them in switch/case statements. To avoid conflicts with other
// applications we at least try to reserve as soon as possible, so that
// applications behaving better than us does not get them.
for ( int i = QskEvent::NoEvent; i <= QskEvent::MaxEvent; i++ )
{
const int id = QEvent::registerEventType( i );
Q_ASSERT( id == i );
}
}
Q_CONSTRUCTOR_FUNCTION( qskRegisterEventTypes )
2018-02-06 14:57:34 +01:00
int qskTabChainIncrement( const QEvent* event )
{
if ( event && event->type() == QEvent::KeyPress )
{
const auto keyEvent = static_cast< const QKeyEvent* >( event );
if ( !( keyEvent->modifiers() & ( Qt::ControlModifier | Qt::AltModifier ) ) )
{
2018-08-03 08:15:28 +02:00
switch ( keyEvent->key() )
2018-02-06 14:57:34 +01:00
{
case Qt::Key_Tab:
return 1;
case Qt::Key_Backtab:
return -1;
}
}
}
return 0;
}
2018-08-03 08:15:28 +02:00
QskEvent::QskEvent( QskEvent::Type type )
: QEvent( static_cast< QEvent::Type >( type ) )
2017-07-21 18:21:34 +02:00
{
}
// -- QskGeometryChangeEvent
QskGeometryChangeEvent::QskGeometryChangeEvent(
2018-08-03 08:15:28 +02:00
const QRectF& rect, const QRectF& oldRect )
: QskEvent( QskEvent::GeometryChange )
, m_rect( rect )
, m_oldRect( oldRect )
2017-07-21 18:21:34 +02:00
{
}
bool QskGeometryChangeEvent::isResized() const
{
return ( m_rect.width() != m_oldRect.width() ) ||
( m_rect.height() != m_oldRect.height() );
}
bool QskGeometryChangeEvent::isMoved() const
{
return ( m_rect.x() != m_oldRect.x() ) ||
( m_rect.y() != m_oldRect.y() );
}
2017-12-22 14:15:24 +01:00
// -- QskWindowChangeEvent
2017-07-21 18:21:34 +02:00
QskWindowChangeEvent::QskWindowChangeEvent(
2018-08-03 08:15:28 +02:00
QQuickWindow* oldWindow, QQuickWindow* window )
: QskEvent( QskEvent::WindowChange )
, m_oldWindow( oldWindow )
, m_window( window )
2017-07-21 18:21:34 +02:00
{
}
// -- QskPopupEvent
QskPopupEvent::QskPopupEvent( Type type, QskPopup* popup )
: QskEvent( type )
, m_popup( popup )
{
}
2017-07-21 18:21:34 +02:00
// -- QskGestureEvent
2018-08-03 08:15:28 +02:00
QskGestureEvent::QskGestureEvent(
const QskGesture* gesture, bool ownedByEvent )
: QskEvent( QskEvent::Gesture )
, m_gesture( gesture )
, m_gestureOwnedByEvent( ownedByEvent )
2017-07-21 18:21:34 +02:00
{
}
QskGestureEvent::~QskGestureEvent()
{
if ( m_gestureOwnedByEvent )
delete m_gesture;
}
// -- QskAnimatorEvent
2018-08-03 08:15:28 +02:00
QskAnimatorEvent::QskAnimatorEvent( QskAspect::Aspect aspect, State state )
: QskEvent( QskEvent::Animator )
, m_aspect( aspect )
, m_state( state )
2017-07-21 18:21:34 +02:00
{
}
QskAnimatorEvent::~QskAnimatorEvent()
{
}