Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion colorwheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>( mapFromGlobal( QCursor::pos() ).x() ), static_cast<int>( mapFromGlobal( QCursor::pos() ).y() ) ) );
= getQuadrant( QPoint( static_cast<int>( mapFromGlobal( m_mouseGlobalPos ).x() ), static_cast<int>( mapFromGlobal( m_mouseGlobalPos ).y() ) ) );

if ( m_quadHit == UpDown::DOWN ) {
angle = ONETURN - angle;
Expand Down Expand Up @@ -185,6 +186,10 @@ void ColorWheel::updateMousePosition( const QPoint position ) {
m_mouseVec = QVector2D( static_cast<float>( position.x() - width() / 2.0F ), static_cast<float>( position.y() - height() / 2.0F ) );
}

void ColorWheel::updateMouseGlobalPosition( const QPointF position ) {
m_mouseGlobalPos = position;
}

// *****************************
// PROTECTED
// *****************************
Expand All @@ -196,6 +201,7 @@ void ColorWheel::mousePressEvent( QMouseEvent* event ) {
}

updateMousePosition( event->pos() );
updateMouseGlobalPosition( event->globalPosition() );

if ( !isHitMode() ) {
return;
Expand Down Expand Up @@ -226,6 +232,7 @@ void ColorWheel::mouseMoveEvent( QMouseEvent* event ) {
}

updateMousePosition( event->pos() );
updateMouseGlobalPosition( event->globalPosition() );

switch ( m_hitMode ) {
case HitPosition::WHEEL:
Expand Down
2 changes: 2 additions & 0 deletions colorwheel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down