Commit 3697a1a2 authored by Simon Eugster's avatar Simon Eugster

Abstract Scopes: Mouse tracking ability moved to ASW to reduce duplicated code

svn path=/trunk/kdenlive/; revision=4796
parent 8890a9cc
......@@ -17,6 +17,7 @@
#include <QFuture>
#include <QColor>
#include <QMenu>
#include <QMouseEvent>
#include <QPainter>
const int REALTIME_FPS = 30;
......@@ -30,10 +31,12 @@ const QPen AbstractScopeWidget::penThin (QBrush(QColor(250,250,250)), 1, Qt:
const QPen AbstractScopeWidget::penLight(QBrush(QColor(200,200,250,150)), 1, Qt::SolidLine);
const QPen AbstractScopeWidget::penDark (QBrush(QColor(0,0,20,250)), 1, Qt::SolidLine);
AbstractScopeWidget::AbstractScopeWidget(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent) :
AbstractScopeWidget::AbstractScopeWidget(Monitor *projMonitor, Monitor *clipMonitor, bool trackMouse, QWidget *parent) :
QWidget(parent),
m_projMonitor(projMonitor),
m_clipMonitor(clipMonitor),
m_mousePos(0,0),
m_mouseWithinWidget(false),
offset(5),
m_accelFactorHUD(1),
m_accelFactorScope(1),
......@@ -80,6 +83,11 @@ AbstractScopeWidget::AbstractScopeWidget(Monitor *projMonitor, Monitor *clipMoni
b &= connect(m_aRealtime, SIGNAL(toggled(bool)), this, SLOT(slotResetRealtimeFactor(bool)));
b &= connect(m_aAutoRefresh, SIGNAL(toggled(bool)), this, SLOT(slotAutoRefreshToggled(bool)));
Q_ASSERT(b);
// Enable mouse tracking if desired.
// Causes the mouseMoved signal to be emitted when the mouse moves inside the
// widget, even when no mouse button is pressed.
this->setMouseTracking(trackMouse);
}
AbstractScopeWidget::~AbstractScopeWidget()
......@@ -249,6 +257,18 @@ void AbstractScopeWidget::paintEvent(QPaintEvent *)
davinci.drawImage(m_scopeRect.topLeft(), m_imgHUD);
}
void AbstractScopeWidget::mouseMoveEvent(QMouseEvent *event)
{
m_mousePos = event->pos();
m_mouseWithinWidget = true;
emit signalMousePositionChanged();
}
void AbstractScopeWidget::leaveEvent(QEvent *)
{
m_mouseWithinWidget = false;
emit signalMousePositionChanged();
}
void AbstractScopeWidget::customContextMenuRequested(const QPoint &pos)
{
m_menu->exec(this->mapToGlobal(pos));
......
......@@ -64,7 +64,7 @@ class AbstractScopeWidget : public QWidget
Q_OBJECT
public:
AbstractScopeWidget(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent = 0);
AbstractScopeWidget(Monitor *projMonitor, Monitor *clipMonitor, bool trackMouse = false, QWidget *parent = 0);
virtual ~AbstractScopeWidget(); // Must be virtual because of inheritance, to avoid memory leaks
QPalette m_scopePalette;
......@@ -103,6 +103,12 @@ protected:
how many times faster the scope should be calculated. */
QAction *m_aRealtime;
/** The mouse position; Updated when the mouse enters the widget
AND mouse tracking has been enabled. */
QPoint m_mousePos;
/** Knows whether the mouse currently lies within the widget or not.
Can e.g. be used for drawing a HUD only when the mouse is in the widget. */
bool m_mouseWithinWidget;
/** Offset from the widget's borders */
const uchar offset;
......@@ -166,12 +172,15 @@ protected:
///// Reimplemented /////
void mouseMoveEvent(QMouseEvent *);
void leaveEvent(QEvent *);
void mouseReleaseEvent(QMouseEvent *);
void paintEvent(QPaintEvent *);
void resizeEvent(QResizeEvent *);
void showEvent(QShowEvent *); // Called when the widget is activated via the Menu entry
// void raise(); // Called only when manually calling the event -> useless
protected slots:
/** Forces an update of all layers. */
void forceUpdate(bool doUpdate = true);
......@@ -187,6 +196,10 @@ signals:
void signalScopeRenderingFinished(uint mseconds, uint accelerationFactor);
void signalBackgroundRenderingFinished(uint mseconds, uint accelerationFactor);
/** For the mouse position itself see m_mousePos.
To check whether the mouse has leaved the widget, see m_mouseWithinWidget. */
void signalMousePositionChanged();
private:
/** Counts the number of frames that have been rendered in the active monitor.
......
......@@ -37,8 +37,7 @@ const QPointF YUV_Yl(-.437, .100);
Vectorscope::Vectorscope(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent) :
AbstractScopeWidget(projMonitor, clipMonitor, parent),
m_gain(1),
m_circleEnabled(false)
m_gain(1)
{
ui = new Ui::Vectorscope_UI();
ui->setupUi(this);
......@@ -65,6 +64,7 @@ Vectorscope::Vectorscope(Monitor *projMonitor, Monitor *clipMonitor, QWidget *pa
b &= connect(ui->backgroundMode, SIGNAL(currentIndexChanged(int)), this, SLOT(slotBackgroundChanged()));
b &= connect(ui->sliderGain, SIGNAL(valueChanged(int)), this, SLOT(slotGainChanged(int)));
b &= connect(ui->paintMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceUpdateScope()));
b &= connect(this, SIGNAL(signalMousePositionChanged()), this, SLOT(forceUpdateHUD()));
ui->sliderGain->setValue(0);
......@@ -88,8 +88,7 @@ Vectorscope::Vectorscope(Monitor *projMonitor, Monitor *clipMonitor, QWidget *pa
Q_ASSERT(b);
this->setMouseTracking(true);
// To make the 1.0x text show
slotGainChanged(ui->sliderGain->value());
init();
......@@ -172,7 +171,7 @@ QImage Vectorscope::renderHUD(uint)
QImage hud;
if (m_circleEnabled) {
if (m_mouseWithinWidget) {
// Mouse moved: Draw a circle over the scope
hud = QImage(m_scopeRect.size(), QImage::Format_ARGB32);
......@@ -208,7 +207,7 @@ QImage Vectorscope::renderHUD(uint)
float angle = copysign(acos(dx/r)*180/M_PI, dy);
davinci.drawText(QPoint(10, m_scopeRect.height()), i18n("%1°", QString::number(angle, 'f', 1)));
m_circleEnabled = false;
// m_circleEnabled = false;
} else {
hud = QImage(0, 0, QImage::Format_ARGB32);
}
......@@ -390,26 +389,3 @@ void Vectorscope::slotBackgroundChanged()
}
forceUpdateBackground();
}
///// Events /////
void Vectorscope::mouseMoveEvent(QMouseEvent *event)
{
// Draw a circle around the center,
// showing percentage number of the radius length
m_circleEnabled = true;
m_mousePos = event->pos();
forceUpdateHUD();
}
void Vectorscope::leaveEvent(QEvent *event)
{
// Repaint the HUD without the circle
m_circleEnabled = false;
QWidget::leaveEvent(event);
forceUpdateHUD();
}
......@@ -34,10 +34,6 @@ public:
QString widgetName() const;
protected:
void mouseMoveEvent(QMouseEvent *);
void leaveEvent(QEvent *);
///// Implemented methods /////
QRect scopeRect();
QImage renderHUD(uint accelerationFactor);
......@@ -71,9 +67,6 @@ private:
QPoint m_centerPoint, pR75, pG75, pB75, pCy75, pMg75, pYl75;
bool m_circleEnabled;
QPoint m_mousePos;
/** Updates the dimension. Only necessary when the widget has been resized. */
void updateDimensions();
int cw;
......
......@@ -21,7 +21,7 @@
const QSize Waveform::m_textWidth(35,0);
Waveform::Waveform(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent) :
AbstractScopeWidget(projMonitor, clipMonitor, parent)
AbstractScopeWidget(projMonitor, clipMonitor, true, parent)
{
ui = new Ui::Waveform_UI();
ui->setupUi(this);
......@@ -31,11 +31,9 @@ Waveform::Waveform(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent)
bool b = true;
b &= connect(ui->paintMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceUpdateScope()));
b &= connect(this, SIGNAL(signalMousePositionChanged()), this, SLOT(forceUpdateHUD()));
Q_ASSERT(b);
// Track the mouse also when no button held down
this->setMouseTracking(true);
init();
m_waveformGenerator = new WaveformGenerator();
}
......@@ -94,7 +92,7 @@ QImage Waveform::renderHUD(uint)
int x = scopeRect().width()-m_textWidth.width()+3;
int y = m_mousePos.y() - scopeRect().y();
if (scopeRect().height() > 0 && m_lineEnabled) {
if (scopeRect().height() > 0 && m_mouseWithinWidget) {
davinci.drawLine(0, y, scopeRect().size().width()-m_textWidth.width(), y);
int val = 255*(1-(float)y/scopeRect().height());
davinci.drawText(x, scopeRect().height()/2, QVariant(val).toString());
......@@ -124,23 +122,3 @@ QImage Waveform::renderBackground(uint)
emit signalBackgroundRenderingFinished(0, 1);
return QImage();
}
///// Events /////
void Waveform::mouseMoveEvent(QMouseEvent *event)
{
// Note: Mouse tracking has to be enabled
m_lineEnabled = true;
m_mousePos = event->pos();
forceUpdateHUD();
}
void Waveform::leaveEvent(QEvent *event)
{
// Repaint the HUD without the circle
m_lineEnabled = false;
QWidget::leaveEvent(event);
forceUpdateHUD();
}
......@@ -31,17 +31,12 @@ protected:
virtual void readConfig();
void writeConfig();
void mouseMoveEvent(QMouseEvent *);
void leaveEvent(QEvent *);
private:
Ui::Waveform_UI *ui;
WaveformGenerator *m_waveformGenerator;
static const QSize m_textWidth;
bool m_lineEnabled;
QPoint m_mousePos;
QImage m_waveform;
/// Implemented methods ///
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment