Skip to content

Commit

Permalink
Fix #4201: BB editor: adjust cursor position (#5489)
Browse files Browse the repository at this point in the history
This fixes an offset for cursors whose pointer position varies between
different themes.
  • Loading branch information
JohannesLorenz committed May 24, 2020
1 parent d5a2366 commit 3a985ff
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions data/themes/classic/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ TrackContentObjectView {
qproperty-textColor: rgb( 255, 255, 255 );
qproperty-textShadowColor: rgb( 0, 0, 0 );
qproperty-gradient: true; /* boolean property, set true to have a gradient */
/* finger tip offset of cursor */
qproperty-mouseHotspotHand: 3px 3px;
}

/* instrument pattern */
Expand Down
2 changes: 2 additions & 0 deletions data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@ TrackContentObjectView {
qproperty-textColor: #fff;
qproperty-textShadowColor: rgba(0,0,0,200);
qproperty-gradient: false; /* boolean property, set true to have a gradient */
/* finger tip offset of cursor */
qproperty-mouseHotspotHand: 7px 2px;
}

/* instrument pattern */
Expand Down
9 changes: 8 additions & 1 deletion include/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QtCore/QList>
#include <QWidget>
#include <QSignalMapper>
#include <QSize>
#include <QColor>
#include <QMimeData>

Expand Down Expand Up @@ -201,6 +202,9 @@ class TrackContentObjectView : public selectableObject, public ModelView
Q_PROPERTY( QColor textShadowColor READ textShadowColor WRITE setTextShadowColor )
Q_PROPERTY( QColor BBPatternBackground READ BBPatternBackground WRITE setBBPatternBackground )
Q_PROPERTY( bool gradient READ gradient WRITE setGradient )
// We have to use a QSize here because using QPoint isn't supported.
// width -> x, height -> y
Q_PROPERTY( QSize mouseHotspotHand WRITE setMouseHotspotHand )

public:
TrackContentObjectView( TrackContentObject * tco, TrackView * tv );
Expand Down Expand Up @@ -233,6 +237,7 @@ class TrackContentObjectView : public selectableObject, public ModelView
void setTextShadowColor( const QColor & c );
void setBBPatternBackground( const QColor & c );
void setGradient( const bool & b );
void setMouseHotspotHand(const QSize & s);

// access needsUpdate member variable
bool needsUpdate();
Expand Down Expand Up @@ -302,8 +307,10 @@ protected slots:
QColor m_textShadowColor;
QColor m_BBPatternBackground;
bool m_gradient;
QSize m_mouseHotspotHand; // QSize must be used because QPoint isn't supported by property system
bool m_cursorSetYet;

bool m_needsUpdate;
bool m_needsUpdate;
inline void setInitialMousePos( QPoint pos )
{
m_initialMousePos = pos;
Expand Down
17 changes: 15 additions & 2 deletions src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ TrackContentObjectView::TrackContentObjectView( TrackContentObject * tco,
m_textShadowColor( 0, 0, 0 ),
m_BBPatternBackground( 0, 0, 0 ),
m_gradient( true ),
m_mouseHotspotHand( 0, 0 ),
m_cursorSetYet( false ),
m_needsUpdate( true )
{
if( s_textFloat == NULL )
Expand All @@ -268,7 +270,7 @@ TrackContentObjectView::TrackContentObjectView( TrackContentObject * tco,
setAttribute( Qt::WA_OpaquePaintEvent, true );
setAttribute( Qt::WA_DeleteOnClose, true );
setFocusPolicy( Qt::StrongFocus );
setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) );
setCursor( QCursor( embed::getIconPixmap( "hand" ), m_mouseHotspotHand.width(), m_mouseHotspotHand.height() ) );
move( 0, 0 );
show();

Expand Down Expand Up @@ -317,6 +319,12 @@ TrackContentObjectView::~TrackContentObjectView()
*/
void TrackContentObjectView::update()
{
if( !m_cursorSetYet )
{
setCursor( QCursor( embed::getIconPixmap( "hand" ), m_mouseHotspotHand.width(), m_mouseHotspotHand.height() ) );
m_cursorSetYet = true;
}

if( fixedTCOs() )
{
updateLength();
Expand Down Expand Up @@ -387,6 +395,11 @@ void TrackContentObjectView::setBBPatternBackground( const QColor & c )
void TrackContentObjectView::setGradient( const bool & b )
{ m_gradient = b; }

void TrackContentObjectView::setMouseHotspotHand(const QSize & s)
{
m_mouseHotspotHand = s;
}

// access needsUpdate member variable
bool TrackContentObjectView::needsUpdate()
{ return m_needsUpdate; }
Expand Down Expand Up @@ -572,7 +585,7 @@ void TrackContentObjectView::leaveEvent( QEvent * e )
{
if( cursor().shape() != Qt::BitmapCursor )
{
setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) );
setCursor( QCursor( embed::getIconPixmap( "hand" ), m_mouseHotspotHand.width(), m_mouseHotspotHand.height() ) );
}
if( e != NULL )
{
Expand Down

0 comments on commit 3a985ff

Please sign in to comment.