From: Jean-Baptiste Mardelle Date: Tue, 12 Aug 2008 21:25:04 +0000 (+0000) Subject: Optimise monitor ruler (get rid of KRuler), it caused major slowdown (main timeline... X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=aa44a64120acd518139b74d1c7b8a33ee2b1b72a;p=kdenlive Optimise monitor ruler (get rid of KRuler), it caused major slowdown (main timeline ruler still needs rewrite) svn path=/branches/KDE4/; revision=2376 --- diff --git a/src/monitor.cpp b/src/monitor.cpp index f5e4b83f..9e6a8b08 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -92,7 +92,11 @@ Monitor::Monitor(QString name, MonitorManager *manager, QWidget *parent) QAction *resize2Action = configMenu->addAction(KIcon("transform-scale"), i18n("Resize (50%)")); connect(resize2Action, SIGNAL(triggered()), this, SLOT(slotSetSizeOneToTwo())); + QWidget *spacer = new QWidget(this); + spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + toolbar->addWidget(spacer); m_timePos = new KRestrictedLine(this); + m_timePos->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding); m_timePos->setInputMask("99:99:99:99"); toolbar->addWidget(m_timePos); @@ -131,9 +135,6 @@ Monitor::Monitor(QString name, MonitorManager *manager, QWidget *parent) connect(setThumbFrame, SIGNAL(triggered()), this, SLOT(slotSetThumbFrame())); } //render->createVideoXWindow(ui.video_frame->winId(), -1); - int width = m_ruler->width(); - m_ruler->setLength(width); - m_ruler->setMaximum(width); m_length = 0; m_monitorRefresh->show(); kDebug() << "/////// BUILDING MONITOR, ID: " << ui.video_frame->winId(); @@ -149,12 +150,12 @@ void Monitor::slotSetSizeOneToOne() { const int maxHeight = r.height() - 20; int width = render->renderWidth(); int height = render->renderHeight(); - kDebug()<<"// render info: "<= maxWidth || height >= maxHeight) { - width = width * 0.8; - height = height * 0.8; + width = width * 0.8; + height = height * 0.8; } - kDebug()<<"// MONITOR; set SIZE: "<setFixedSize(width, height); updateGeometry(); adjustSize(); @@ -168,12 +169,12 @@ void Monitor::slotSetSizeOneToTwo() { const int maxHeight = r.height() - 20; int width = render->renderWidth() / 2; int height = render->renderHeight() / 2; - kDebug()<<"// render info: "<= maxWidth || height >= maxHeight) { - width = width * 0.8; - height = height * 0.8; + width = width * 0.8; + height = height * 0.8; } - kDebug()<<"// MONITOR; set SIZE: "<setFixedSize(width, height); updateGeometry(); adjustSize(); @@ -188,9 +189,8 @@ void Monitor::resetSize() { // virtual void Monitor::mousePressEvent(QMouseEvent * event) { if (event->button() != Qt::RightButton) { - slotPlay(); - } - else m_contextMenu->popup(event->globalPos()); + slotPlay(); + } else m_contextMenu->popup(event->globalPos()); } // virtual @@ -294,11 +294,9 @@ void Monitor::slotForwardOneFrame() { void Monitor::seekCursor(int pos) { if (!m_isActive) m_monitorManager->activateMonitor(m_name); - //int rulerPos = (int)(pos * m_scale); m_position = pos; m_timePos->setText(m_monitorManager->timecode().getTimecodeFromFrames(pos)); - //kDebug() << "seek: " << pos << ", scale: " << m_scale; - m_ruler->slotNewValue(pos); //rulerPos); + m_ruler->slotNewValue(pos); } void Monitor::rendererStopped(int pos) { @@ -323,15 +321,8 @@ void Monitor::initMonitor() { }*/ void Monitor::adjustRulerSize(int length) { - int width = m_ruler->width(); - m_ruler->setLength(width); if (length > 0) m_length = length; - m_scale = (double) width / m_length; - if (m_scale == 0) m_scale = 1; - kDebug() << "RULER WIDT: " << width << ", RENDER LENGT: " << m_length << ", SCALE: " << m_scale; - m_ruler->setPixelPerMark(m_scale); - m_ruler->setMaximum(width); - //m_ruler->setLength(length); + m_ruler->adjustScale(m_length); } void Monitor::stop() { @@ -400,7 +391,7 @@ void Monitor::saveSceneList(QString path, QDomElement info) { MonitorRefresh::MonitorRefresh(QWidget* parent): QWidget(parent), m_renderer(NULL) { setAttribute(Qt::WA_PaintOnScreen); - setAttribute(Qt::WA_OpaquePaintEvent); //Qt::WA_NoSystemBackground); + setAttribute(Qt::WA_OpaquePaintEvent); //setAttribute(Qt::WA_NoSystemBackground); } void MonitorRefresh::setRenderer(Render* render) { diff --git a/src/smallruler.cpp b/src/smallruler.cpp index d64d0bc6..90166091 100644 --- a/src/smallruler.cpp +++ b/src/smallruler.cpp @@ -23,122 +23,89 @@ #include -static const int LITTLE_MARK_X2 = 8; -static const int LITTLE_MARK_X1 = 5; -static const int MIDDLE_MARK_X1 = 3; -static const int MIDDLE_MARK_X2 = 8; - -static const int LABEL_SIZE = 8; - #include "smallruler.h" SmallRuler::SmallRuler(QWidget *parent) - : KRuler(parent) { - setShowPointer(true); - setShowBigMarks(false); - setShowTinyMarks(false); - slotNewOffset(0); - setRulerMetricStyle(KRuler::Custom); - setLengthFixed(true); + : QWidget(parent), m_scale(1), m_maxval(25) { } -void SmallRuler::setPixelPerMark(double rate) { - kDebug() << " RULER SET RATE: " << rate; - if (rate > 0.5) { - setLittleMarkDistance(25); - setMediumMarkDistance(5 * 25); - } else if (rate > 0.09) { - setLittleMarkDistance(5 * 25); - setMediumMarkDistance(30 * 25); +void SmallRuler::adjustScale(int maximum) { + m_maxval = maximum; + m_scale = (double) width() / (double) maximum; + if (m_scale == 0) m_scale = 1; + + if (m_scale > 0.5) { + m_small = 25; + m_medium = 5 * 25; + } else if (m_scale > 0.09) { + m_small = 5 * 25; + m_medium = 30 * 25; } else { - setLittleMarkDistance(30 * 25); - setMediumMarkDistance(60 * 25); + m_small = 30 * 25; + m_medium = 60 * 25; } - - KRuler::setPixelPerMark(rate); + m_cursorPosition = m_cursorFramePosition * m_scale; + update(); } // virtual void SmallRuler::mousePressEvent(QMouseEvent * event) { - double pos = event->x() / pixelPerMark(); + const int pos = event->x() / m_scale; emit seekRenderer((int) pos); } // virtual void SmallRuler::mouseMoveEvent(QMouseEvent * event) { - double pos = event->x() / pixelPerMark(); + const int pos = event->x() / m_scale; emit seekRenderer((int) pos); } -void SmallRuler::slotNewValue(int _value) { - m_cursorPosition = (int)(_value); /// pixelPerMark()); - KRuler::slotNewValue(_value * pixelPerMark()); +void SmallRuler::slotNewValue(int value) { + m_cursorFramePosition = value; + int oldPos = m_cursorPosition; + m_cursorPosition = value * m_scale; + if (oldPos == m_cursorPosition) return; + const int offset = 6; + const int x = qMin(oldPos, m_cursorPosition); + const int w = qAbs(oldPos - m_cursorPosition); + update(x - offset, 9, w + 2 * offset, 6); +} + +//virtual +void SmallRuler::resizeEvent(QResizeEvent *) { + adjustScale(m_maxval); } // virtual void SmallRuler::paintEvent(QPaintEvent *e) { - // debug ("KRuler::drawContents, %s",(horizontal==dir)?"horizontal":"vertical"); - - QStylePainter p(this); - p.fillRect(e->rect(), QBrush(QColor(Qt::white))); - - int value = this->value(), - minval = minimum(), - maxval; - maxval = maximum() - + offset() - endOffset(); + QPainter p(this); + QRect r = e->rect(); + p.setClipRect(r); - //ioffsetval = value-offset; - // pixelpm = (int)ppm; - // left = clip.left(), - // right = clip.right(); - double f, fend, - offsetmin = (double)(minval - offset()), - offsetmax = (double)(maxval - offset()), - fontOffset = (((double)minval) > offsetmin) ? (double)minval : offsetmin; + double f, fend; + p.setPen(palette().dark().color()); - // draw labels - QFont font = p.font(); - font.setPointSize(LABEL_SIZE); - p.setFont(font); - - if (showLittleMarks()) { + if (r.top() < 9) { // draw the little marks - fend = pixelPerMark() * littleMarkDistance(); - if (fend > 2) for (f = offsetmin; f < offsetmax; f += fend) { - p.drawLine((int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2); + fend = m_scale * m_small; + if (fend > 2) for (f = 0; f < width(); f += fend) { + p.drawLine((int)f, 1, (int)f, 3); } - } - if (showMediumMarks()) { + // draw medium marks - fend = pixelPerMark() * mediumMarkDistance(); - if (fend > 2) for (f = offsetmin; f < offsetmax; f += fend) { - p.drawLine((int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2); + fend = m_scale * m_medium; + if (fend > 2) for (f = 0; f < width(); f += fend) { + p.drawLine((int)f, 1, (int)f, 5); } } - /* if (d->showem) { - // draw end marks - if (d->dir == Qt::Horizontal) { - p.drawLine(minval-d->offset, END_MARK_X1, minval-d->offset, END_MARK_X2); - p.drawLine(maxval-d->offset, END_MARK_X1, maxval-d->offset, END_MARK_X2); - } - else { - p.drawLine(END_MARK_X1, minval-d->offset, END_MARK_X2, minval-d->offset); - p.drawLine(END_MARK_X1, maxval-d->offset, END_MARK_X2, maxval-d->offset); - } - }*/ - // draw pointer - if (showPointer()) { - QPolygon pa(3); - pa.setPoints(3, value - 6, 0, value + 6, 0, value/*+0*/, 8); - p.setBrush(QBrush(Qt::yellow)); - p.drawPolygon(pa); - } - + QPolygon pa(3); + pa.setPoints(3, m_cursorPosition - 5, 14, m_cursorPosition + 5, 14, m_cursorPosition/*+0*/, 9); + p.setBrush(palette().dark().color()); + p.drawPolygon(pa); } #include "smallruler.moc" diff --git a/src/smallruler.h b/src/smallruler.h index 46ebb9ce..02f55433 100644 --- a/src/smallruler.h +++ b/src/smallruler.h @@ -21,26 +21,31 @@ #ifndef SMALLRULER_H #define SMALLRULER_H -#include +#include -class SmallRuler : public KRuler { +class SmallRuler : public QWidget { Q_OBJECT public: SmallRuler(QWidget *parent = 0); virtual void mousePressEvent(QMouseEvent * event); virtual void mouseMoveEvent(QMouseEvent * event); - void setPixelPerMark(double rate); + void adjustScale(int maximum); protected: - virtual void paintEvent(QPaintEvent * /*e*/); + virtual void paintEvent(QPaintEvent *e); + virtual void resizeEvent(QResizeEvent *); private: int m_cursorPosition; + int m_cursorFramePosition; double m_scale; + int m_medium; + int m_small; + int m_maxval; public slots: - void slotNewValue(int _value); + void slotNewValue(int value); signals: void seekRenderer(int);