Commit 38ada4d8 authored by Jason Wood's avatar Jason Wood

Added functionality to allow the ruler to emit signals when we drag a marker...

Added functionality to allow the ruler to emit signals when we drag a marker near the edge of a visible area of the ruler. This allows whatever is controlling the ruler to "scroll" it if necessary.

The ruler itself cannot handle this functionality, as the ruler does not handle it's own viewing position.

svn path=/trunk/kdenlive/; revision=303
parent c84b1272
......@@ -31,6 +31,11 @@
#include "krulersliderbase.h"
#include "krulermodel.h"
namespace {
uint g_scrollTimerDelay = 50;
uint g_scrollThreshold = 50;
}
class KRulerPrivateSliderDiamond : public KRulerSliderBase {
public:
KRulerPrivateSliderDiamond() {
......@@ -337,7 +342,8 @@ KRuler::KRuler(int min, int max, double scale, KRulerModel *model, QWidget *pare
m_maxValue(max),
d(new KRulerPrivate()),
m_rulerModel(0),
m_leftMostPixel(0)
m_leftMostPixel(0),
m_scrollTimer(this, "scroll timer")
{
setRulerModel(model);
......@@ -354,9 +360,10 @@ KRuler::KRuler(int min, int max, double scale, KRulerModel *model, QWidget *pare
invalidateBackBuffer();
// we draw everything ourselves, no need to draw background.
setBackgroundMode(Qt::NoBackground);
connect(&m_scrollTimer, SIGNAL(timeout()), this, SLOT(slotTimerScrollEvent()));
}
KRuler::KRuler(KRulerModel *model, QWidget *parent, const char *name ) :
......@@ -367,7 +374,8 @@ KRuler::KRuler(KRulerModel *model, QWidget *parent, const char *name ) :
m_maxValue(100),
d(new KRulerPrivate()),
m_rulerModel(0),
m_leftMostPixel(0)
m_leftMostPixel(0),
m_scrollTimer(this, "scroll timer")
{
setRulerModel(model);
......@@ -387,6 +395,7 @@ KRuler::KRuler(KRulerModel *model, QWidget *parent, const char *name ) :
setBackgroundMode(Qt::NoBackground);
invalidateBackBuffer();
connect(&m_scrollTimer, SIGNAL(timeout()), this, SLOT(slotTimerScrollEvent()));
}
KRuler::KRuler(QWidget *parent, const char *name ) :
......@@ -397,7 +406,8 @@ KRuler::KRuler(QWidget *parent, const char *name ) :
m_maxValue(0),
d(new KRulerPrivate()),
m_rulerModel(0),
m_leftMostPixel(0)
m_leftMostPixel(0),
m_scrollTimer(this, "scroll timer")
{
setRulerModel(0);
......@@ -412,10 +422,11 @@ KRuler::KRuler(QWidget *parent, const char *name ) :
setSizePolicy(QSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed, FALSE));
// we draw everything ourselves, no need to draw background.
// we draw everything ourselves, no need to draw background.
setBackgroundMode(Qt::NoBackground);
m_autoClickSlider = -1;
connect(&m_scrollTimer, SIGNAL(timeout()), this, SLOT(slotTimerScrollEvent()));
}
KRuler::~KRuler()
......@@ -666,6 +677,7 @@ void KRuler::mouseReleaseEvent(QMouseEvent *event)
d->m_oldValue=-1;
setSliderValue(activeSliderID(), (int)floor(mapLocalToValue((int)event->x())+0.5));
}
m_scrollTimer.stop();
}
}
......@@ -674,6 +686,20 @@ void KRuler::mouseMoveEvent(QMouseEvent *event)
if(event->state() & (QMouseEvent::LeftButton | QMouseEvent::RightButton | QMouseEvent::MidButton)) {
if(d->m_oldValue != -1) {
setSliderValue(activeSliderID(), (int)floor(mapLocalToValue((int)event->x())+0.5));
if(event->x() < g_scrollThreshold) {
m_scrollRight = false;
if(!m_scrollTimer.isActive()) {
m_scrollTimer.start(g_scrollTimerDelay, false);
}
} else if(width() - event->x() < g_scrollThreshold) {
m_scrollRight = true;
if(!m_scrollTimer.isActive()) {
m_scrollTimer.start(g_scrollTimerDelay, false);
}
} else {
m_scrollTimer.stop();
}
}
}
}
......@@ -836,3 +862,12 @@ void KRuler::setSlidersToRange()
if(getSliderValue(count) > maxValue()) setSliderValue(count, maxValue());
}
}
void KRuler::slotTimerScrollEvent()
{
if(m_scrollRight) {
emit requestScrollRight();
} else {
emit requestScrollLeft();
}
}
......@@ -20,6 +20,7 @@
#include <qwidget.h>
#include <qpixmap.h>
#include <qtimer.h>
class KRulerModel;
......@@ -104,6 +105,10 @@ signals: // Signals
void sliderValueChanged(int, int);
/** Emitted when the scale of the ruler changes. */
void scaleChanged(double);
/** Emitted when the ruler would like to be scrolled to the right. */
void requestScrollRight();
/** Emitted when the ruler would like to be scrolled to the left. */
void requestScrollLeft();
protected slots: // Protected slots
/** Sets the leftmost pixel which is displayed on the widget. To understand why this
......@@ -119,6 +124,10 @@ protected slots: // Protected slots
tested it enough yet to understand the implications.*/
void setValueScale(double size);
/** called when the scroll timer is active and times out. We should emit a relevant signal
* to say that we would like our position updated. */
void slotTimerScrollEvent();
private: // private variables
QSize m_sizeHint;
/** This is the back buffer image, to which the ruler is drawn before being displayed on
......@@ -145,6 +154,11 @@ private: // private variables
/** This slider is automatically "clicked" if a mouse event occurs and no slider
is under the mouse. */
int m_autoClickSlider;
/** Timer for edge-of-ruler dragging notifications. This timer will be started when we start
* dragging at the edge of a ruler, and will stop when we stop dragging. */
QTimer m_scrollTimer;
/** True if the scroll timer events should emit requestScrollRight signals, false otherwise. */
bool m_scrollRight;
private: // private methods
/** Sets the slider under the specified coordinate to be active, and setting other sliders
......
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