Commit 1b6c777c authored by Jason Wood's avatar Jason Wood

Ranges of 0 are now handled gracefully - it is now legal for minValue() to be equal to maxValue()

svn path=/trunk/kdenlive/; revision=266
parent 6870d054
......@@ -52,6 +52,7 @@ KFixedRuler::~KFixedRuler()
void KFixedRuler::calculateViewport()
{
int numValues = maxValue() - minValue();
if(numValues==0) numValues = 1;
double scale = (((double)width()-(2*margin())) / (double)numValues);
int firstPixel = (int)(minValue()*scale) - margin();
......@@ -78,7 +79,7 @@ void KFixedRuler::setRange(const int min, const int max)
if(minValue()!=min) {
hasChanged = true;
emit startValueChanged(min);
emit startValueChanged(min);
}
if(maxValue() != max) {
......@@ -90,7 +91,7 @@ void KFixedRuler::setRange(const int min, const int max)
if(hasChanged) {
calculateViewport();
}
}
}
/** Returns the minimum value of this ruler */
......
......@@ -352,6 +352,8 @@ KRuler::KRuler(int min, int max, double scale, KRulerModel *model, QWidget *pare
setSizePolicy(QSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed, FALSE));
invalidateBackBuffer();
// we draw everything ourselves, no need to draw background.
setBackgroundMode(Qt::NoBackground);
......@@ -383,6 +385,8 @@ KRuler::KRuler(KRulerModel *model, QWidget *parent, const char *name ) :
// we draw everything ourselves, no need to draw background.
setBackgroundMode(Qt::NoBackground);
invalidateBackBuffer();
}
KRuler::KRuler(QWidget *parent, const char *name ) :
......@@ -541,12 +545,14 @@ void KRuler::setSliderValue(int id, int value)
for(it = d->m_sliders.begin(); it != d->m_sliders.end(); it++) {
if((*it).getID() == id) {
invalidateBackBuffer((*it).leftBound((int)mapValueToLocal((*it).getValue()), height()),
(*it).rightBound((int)mapValueToLocal((*it).getValue()), height()) + 1);
invalidateBackBuffer(
(*it).leftBound((int)mapValueToLocal((*it).getValue()), height()),
(*it).rightBound((int)mapValueToLocal((*it).getValue()), height()) + 1);
if((*it).setValue(actValue)) {
invalidateBackBuffer((*it).leftBound((int)mapValueToLocal((*it).getValue()), height()),
(*it).rightBound((int)mapValueToLocal((*it).getValue()), height()) + 1);
invalidateBackBuffer(
(*it).leftBound((int)mapValueToLocal((*it).getValue()), height()),
(*it).rightBound((int)mapValueToLocal((*it).getValue()), height()) + 1);
emit sliderValueChanged(id, actValue);
break;
......@@ -607,7 +613,7 @@ void KRuler::setMinValue(int value)
void KRuler::setMaxValue(int value)
{
m_maxValue = (value > m_minValue) ? value : m_minValue + 1;
m_maxValue = (value > m_minValue) ? value : m_minValue;
setSlidersToRange();
}
......@@ -710,7 +716,7 @@ void KRuler::drawToBackBuffer(int start, int end)
// draw background, adding different colors before the start, and after the end values.
int startRuler = (int)mapValueToLocal(minValue());
int endRuler = (int)mapValueToLocal(maxValue());
int endRuler = (int)mapValueToLocal((maxValue() > minValue()) ? maxValue() : maxValue()+1);
if(startRuler > sx) {
painter.fillRect(sx, 0, startRuler-sx, height(), palette().active().background());
......@@ -728,10 +734,10 @@ void KRuler::drawToBackBuffer(int start, int end)
painter.setPen(palette().active().foreground());
painter.setBrush(palette().active().background());
//
// Special case draw for when the big ticks are always coincidental with small ticks.
// Nicely stops rounding errors from creeping in, and should be slightly faster.
//
//
// Special case draw for when the big ticks are always coincidental with small ticks.
// Nicely stops rounding errors from creeping in, and should be slightly faster.
//
if(!(m_bigTickEvery % m_smallTickEvery)) {
value = (int)((m_leftMostPixel+sx)/m_xValueSize);
value -= value % m_smallTickEvery;
......@@ -811,6 +817,11 @@ void KRuler::drawToBackBuffer(int start, int end)
update();
}
void KRuler::invalidateBackBuffer()
{
invalidateBackBuffer(0, width());
}
void KRuler::invalidateBackBuffer(int start, int end)
{
d->m_bufferDrawList.addRange(start, end);
......
......@@ -89,6 +89,8 @@ ruler, and could be used to indicate the start and end of a repeated section, fo
/** Draws the ruler to a back buffered QImage, but does not display it. This image can then be
blitted straight to the screen for speedy drawing. */
void drawToBackBuffer(int start, int end);
/** Specifies that the entire back buffer needs to be redrawn. */
void invalidateBackBuffer();
/** Specifies that part of the back buffer needs to be redrawn. */
void invalidateBackBuffer(int start, int end);
public slots: // public slots
......
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