diff --git a/colorwheel.cpp b/colorwheel.cpp index bdc87a1..38a95c2 100644 --- a/colorwheel.cpp +++ b/colorwheel.cpp @@ -144,10 +144,11 @@ bool ColorWheel::isHitMode() noexcept { QColor ColorWheel::hueAt( const QVector2D in_mouseVec ) noexcept { const QVector2D vec { 1.0, 0.0 }; + qreal angle = qRadiansToDegrees( std::acos( QVector2D::dotProduct( vec, in_mouseVec ) / ( in_mouseVec.length() * vec.length() ) ) ); m_quadHit - = getQuadrant( QPoint( static_cast( mapFromGlobal( QCursor::pos() ).x() ), static_cast( mapFromGlobal( QCursor::pos() ).y() ) ) ); + = getQuadrant( QPoint( static_cast( mapFromGlobal( m_mouseGlobalPos ).x() ), static_cast( mapFromGlobal( m_mouseGlobalPos ).y() ) ) ); if ( m_quadHit == UpDown::DOWN ) { angle = ONETURN - angle; @@ -185,6 +186,10 @@ void ColorWheel::updateMousePosition( const QPoint position ) { m_mouseVec = QVector2D( static_cast( position.x() - width() / 2.0F ), static_cast( position.y() - height() / 2.0F ) ); } +void ColorWheel::updateMouseGlobalPosition( const QPointF position ) { + m_mouseGlobalPos = position; +} + // ***************************** // PROTECTED // ***************************** @@ -196,6 +201,7 @@ void ColorWheel::mousePressEvent( QMouseEvent* event ) { } updateMousePosition( event->pos() ); + updateMouseGlobalPosition( event->globalPosition() ); if ( !isHitMode() ) { return; @@ -226,6 +232,7 @@ void ColorWheel::mouseMoveEvent( QMouseEvent* event ) { } updateMousePosition( event->pos() ); + updateMouseGlobalPosition( event->globalPosition() ); switch ( m_hitMode ) { case HitPosition::WHEEL: diff --git a/colorwheel.h b/colorwheel.h index 767864c..7b0c046 100644 --- a/colorwheel.h +++ b/colorwheel.h @@ -37,6 +37,7 @@ class ColorWheel : public QQuickPaintedItem { QPolygonF m_arrow; QVector2D m_mouseVec; + QPointF m_mouseGlobalPos; qreal m_outerRadius; qreal m_innerRadius; qreal m_indicatorSize; @@ -48,6 +49,7 @@ class ColorWheel : public QQuickPaintedItem { [[nodiscard]] UpDown getQuadrant( QPoint position ) noexcept; void updateMousePosition( QPoint position ); + void updateMouseGlobalPosition( QPointF position ); protected: void mousePressEvent( QMouseEvent* event ) override;