Showing Knob value on mouse over (#6835)

* Showing Knob value on mouse over

* Correcting minors source code issues

* Correcting double QTimer include

* Removing blank lines

* Removing space and add one

* Update src/gui/widgets/SimpleTextFloat.cpp

Co-authored-by: saker <sakertooth@gmail.com>

* Correcting QTimer

* Remove a parameter that has the default value

---------

Co-authored-by: saker <sakertooth@gmail.com>
This commit is contained in:
MrTopom
2023-08-29 21:32:11 +02:00
committed by GitHub
parent 1e6a66f4ac
commit fcdf4c0568
4 changed files with 62 additions and 7 deletions

View File

@@ -144,6 +144,9 @@ protected:
void wheelEvent( QWheelEvent * _me ) override;
void changeEvent(QEvent * ev) override;
void enterEvent(QEvent *event) override;
void leaveEvent(QEvent *event) override;
virtual float getValue( const QPoint & _p );
private slots:
@@ -160,6 +163,7 @@ private:
float _innerRadius = 1) const;
void drawKnob( QPainter * _p );
void showTextFloat(int msecBeforeDisplay, int msecDisplayTime);
void setPosition( const QPoint & _p );
bool updateAngle();

View File

@@ -31,6 +31,7 @@
#include "lmms_export.h"
class QLabel;
class QTimer;
namespace lmms::gui
{
@@ -44,6 +45,8 @@ public:
void setText(const QString & text);
void showWithDelay(int msecBeforeDisplay, int msecDisplayTime);
void setVisibilityTimeOut(int msecs);
void moveGlobal(QWidget * w, const QPoint & offset)
@@ -51,11 +54,14 @@ public:
move(w->mapToGlobal(QPoint(0, 0)) + offset);
}
void hide();
private:
QLabel * m_textLabel;
QTimer * m_showTimer;
QTimer * m_hideTimer;
};
} // namespace lmms::gui
#endif

View File

@@ -22,6 +22,8 @@
*
*/
#include "Knob.h"
#include <memory>
#include <QApplication>
#include <QFontMetrics>
@@ -34,7 +36,6 @@
#endif
#include "lmms_math.h"
#include "Knob.h"
#include "CaptionMenu.h"
#include "ConfigManager.h"
#include "ControllerConnection.h"
@@ -48,7 +49,6 @@
#include "SimpleTextFloat.h"
#include "StringPairDrag.h"
namespace lmms::gui
{
@@ -484,6 +484,13 @@ void Knob::drawKnob( QPainter * _p )
_p->drawImage( 0, 0, m_cache );
}
void Knob::showTextFloat(int msecBeforeDisplay, int msecDisplayTime)
{
s_textFloat->setText(displayValue());
s_textFloat->moveGlobal(this, QPoint(width() + 2, 0));
s_textFloat->showWithDelay(msecBeforeDisplay, msecDisplayTime);
}
float Knob::getValue( const QPoint & _p )
{
float value;
@@ -580,10 +587,8 @@ void Knob::mousePressEvent( QMouseEvent * _me )
emit sliderPressed();
s_textFloat->setText( displayValue() );
s_textFloat->moveGlobal( this,
QPoint( width() + 2, 0 ) );
s_textFloat->show();
showTextFloat(0, 0);
m_buttonPressed = true;
}
else if( _me->button() == Qt::LeftButton &&
@@ -613,6 +618,7 @@ void Knob::mouseMoveEvent( QMouseEvent * _me )
m_lastMousePos = _me->pos();
}
s_textFloat->setText( displayValue() );
s_textFloat->show();
}
@@ -638,7 +644,15 @@ void Knob::mouseReleaseEvent( QMouseEvent* event )
s_textFloat->hide();
}
void Knob::enterEvent(QEvent *event)
{
showTextFloat(700, 2000);
}
void Knob::leaveEvent(QEvent *event)
{
s_textFloat->hide();
}
void Knob::focusOutEvent( QFocusEvent * _fe )

View File

@@ -45,6 +45,14 @@ SimpleTextFloat::SimpleTextFloat() :
m_textLabel = new QLabel(this);
layout->addWidget(m_textLabel);
m_showTimer = new QTimer();
m_showTimer->setSingleShot(true);
QObject::connect(m_showTimer, &QTimer::timeout, this, &SimpleTextFloat::show);
m_hideTimer = new QTimer();
m_hideTimer->setSingleShot(true);
QObject::connect(m_hideTimer, &QTimer::timeout, this, &SimpleTextFloat::hide);
}
void SimpleTextFloat::setText(const QString & text)
@@ -52,6 +60,29 @@ void SimpleTextFloat::setText(const QString & text)
m_textLabel->setText(text);
}
void SimpleTextFloat::showWithDelay(int msecBeforeDisplay, int msecDisplayTime)
{
if (msecBeforeDisplay != 0)
{
m_showTimer->start(msecBeforeDisplay);
}
else
{
show();
}
if (msecDisplayTime != 0)
{
m_hideTimer->start(msecBeforeDisplay + msecDisplayTime);
}
}
void SimpleTextFloat::hide()
{
m_showTimer->stop();
m_hideTimer->stop();
QWidget::hide();
}
void SimpleTextFloat::setVisibilityTimeOut(int msecs)
{