Mercurial > hg > svgui
changeset 227:6dab3ac2fe73
* Add scale to image
author | Chris Cannam |
---|---|
date | Mon, 12 Mar 2007 16:02:56 +0000 |
parents | 2ccd02015530 |
children | 1c4c9e3e44e6 |
files | view/Pane.cpp view/Pane.h view/View.cpp |
diffstat | 3 files changed, 208 insertions(+), 132 deletions(-) [+] |
line wrap: on
line diff
--- a/view/Pane.cpp Mon Mar 12 15:36:31 2007 +0000 +++ b/view/Pane.cpp Mon Mar 12 16:02:56 2007 +0000 @@ -409,11 +409,11 @@ } if (!m_manager || !m_manager->shouldShowVerticalScale()) { - break; + m_scaleWidth = 0; + } else { + m_scaleWidth = (*vi)->getVerticalScaleWidth(this, paint); } - m_scaleWidth = (*vi)->getVerticalScaleWidth(this, paint); - if (m_scaleWidth > 0 && r.left() < m_scaleWidth) { // Profiler profiler("Pane::paintEvent - painting vertical scale", true); @@ -702,6 +702,79 @@ paint.end(); } +bool +Pane::render(QPainter &paint, QRect rect) +{ + if (!View::render(paint, QRect(rect.x() + m_scaleWidth, rect.y(), + rect.width() - m_scaleWidth, rect.height()))) { + return false; + } + + if (m_scaleWidth > 0) { + + for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) { + --vi; + + paint.save(); + + paint.setPen(Qt::black); + paint.setBrush(Qt::white); + paint.drawRect(0, -1, m_scaleWidth, height()+1); + + paint.setBrush(Qt::NoBrush); + (*vi)->paintVerticalScale + (this, paint, QRect(0, 0, m_scaleWidth, height())); + + paint.restore(); + break; + } + } + + return true; +} + +QImage * +Pane::toNewImage() +{ + size_t f0 = getModelsStartFrame(); + size_t f1 = getModelsEndFrame(); + + size_t x0 = f0 / getZoomLevel(); + size_t x1 = f1 / getZoomLevel(); + + QImage *image = new QImage(x1 - x0 + m_scaleWidth, + height(), QImage::Format_RGB32); + + int formerScaleWidth = m_scaleWidth; + + if (m_manager && m_manager->shouldShowVerticalScale()) { + for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) { + --vi; + QPainter paint(image); + m_scaleWidth = (*vi)->getVerticalScaleWidth(this, paint); + break; + } + } else { + m_scaleWidth = 0; + } + + if (m_scaleWidth != formerScaleWidth) { + delete image; + image = new QImage(x1 - x0 + m_scaleWidth, + height(), QImage::Format_RGB32); + } + + QPainter *paint = new QPainter(image); + if (!render(*paint, image->rect())) { + delete paint; + delete image; + return 0; + } else { + delete paint; + return image; + } +} + size_t Pane::getFirstVisibleFrame() const {
--- a/view/Pane.h Mon Mar 12 15:36:31 2007 +0000 +++ b/view/Pane.h Mon Mar 12 16:02:56 2007 +0000 @@ -50,6 +50,9 @@ virtual size_t getFirstVisibleFrame() const; + virtual bool render(QPainter &paint, QRect rect); + virtual QImage *toNewImage(); + virtual QString toXmlString(QString indent = "", QString extraAttributes = "") const;
--- a/view/View.cpp Mon Mar 12 15:36:31 2007 +0000 +++ b/view/View.cpp Mon Mar 12 16:02:56 2007 +0000 @@ -1466,135 +1466,6 @@ QFrame::paintEvent(e); } -bool -View::render(QPainter &paint, QRect rect) -{ - size_t f0 = getModelsStartFrame(); - size_t f1 = getModelsEndFrame(); - - size_t x0 = f0 / m_zoomLevel; - size_t x1 = f1 / m_zoomLevel; - - size_t w = x1 - x0; - - size_t origCentreFrame = m_centreFrame; - - bool someLayersIncomplete = false; - - for (LayerList::iterator i = m_layers.begin(); - i != m_layers.end(); ++i) { - - int c = (*i)->getCompletion(this); - if (c < 100) { - someLayersIncomplete = true; - break; - } - } - - if (someLayersIncomplete) { - - QProgressDialog progress(tr("Waiting for layers to be ready..."), - tr("Cancel"), 0, 100, this); - - int layerCompletion = 0; - - while (layerCompletion < 100) { - - for (LayerList::iterator i = m_layers.begin(); - i != m_layers.end(); ++i) { - - int c = (*i)->getCompletion(this); - if (i == m_layers.begin() || c < layerCompletion) { - layerCompletion = c; - } - } - - if (layerCompletion >= 100) break; - - progress.setValue(layerCompletion); - qApp->processEvents(); - if (progress.wasCanceled()) { - update(); - return false; - } - - usleep(50000); - } - } - - QProgressDialog progress(tr("Rendering image..."), - tr("Cancel"), 0, w / width(), this); - - for (size_t x = 0; x < w; x += width()) { - - progress.setValue(x / width()); - qApp->processEvents(); - if (progress.wasCanceled()) { - m_centreFrame = origCentreFrame; - update(); - return false; - } - - m_centreFrame = (x + width()/2) * m_zoomLevel; - - QRect chunk(0, 0, width(), height()); - - if (hasLightBackground()) { - paint.setPen(Qt::white); - paint.setBrush(Qt::white); - } else { - paint.setPen(Qt::black); - paint.setBrush(Qt::black); - } - - paint.drawRect(QRect(rect.x() + x, rect.y(), width(), height())); - - paint.setPen(Qt::black); - paint.setBrush(Qt::NoBrush); - - for (LayerList::iterator i = m_layers.begin(); - i != m_layers.end(); ++i) { - - paint.setRenderHint(QPainter::Antialiasing, false); - - paint.save(); - paint.translate(rect.x() + x, rect.y()); - -// std::cerr << "Centre frame now: " << m_centreFrame << " drawing to " << chunk.x() << ", " << chunk.width() << std::endl; - - (*i)->paint(this, paint, chunk); - - paint.restore(); - } - } - - m_centreFrame = origCentreFrame; - update(); - return true; -} - -QImage * -View::toNewImage() -{ - size_t f0 = getModelsStartFrame(); - size_t f1 = getModelsEndFrame(); - - size_t x0 = f0 / getZoomLevel(); - size_t x1 = f1 / getZoomLevel(); - - QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32); - - QPainter *paint = new QPainter(image); - if (!render(*paint, image->rect())) { - delete paint; - delete image; - return 0; - } else { - delete paint; - return image; - } -} - void View::drawSelections(QPainter &paint) { @@ -1740,6 +1611,135 @@ paint.restore(); } +bool +View::render(QPainter &paint, QRect rect) +{ + size_t f0 = getModelsStartFrame(); + size_t f1 = getModelsEndFrame(); + + size_t x0 = f0 / m_zoomLevel; + size_t x1 = f1 / m_zoomLevel; + + size_t w = x1 - x0; + + size_t origCentreFrame = m_centreFrame; + + bool someLayersIncomplete = false; + + for (LayerList::iterator i = m_layers.begin(); + i != m_layers.end(); ++i) { + + int c = (*i)->getCompletion(this); + if (c < 100) { + someLayersIncomplete = true; + break; + } + } + + if (someLayersIncomplete) { + + QProgressDialog progress(tr("Waiting for layers to be ready..."), + tr("Cancel"), 0, 100, this); + + int layerCompletion = 0; + + while (layerCompletion < 100) { + + for (LayerList::iterator i = m_layers.begin(); + i != m_layers.end(); ++i) { + + int c = (*i)->getCompletion(this); + if (i == m_layers.begin() || c < layerCompletion) { + layerCompletion = c; + } + } + + if (layerCompletion >= 100) break; + + progress.setValue(layerCompletion); + qApp->processEvents(); + if (progress.wasCanceled()) { + update(); + return false; + } + + usleep(50000); + } + } + + QProgressDialog progress(tr("Rendering image..."), + tr("Cancel"), 0, w / width(), this); + + for (size_t x = 0; x < w; x += width()) { + + progress.setValue(x / width()); + qApp->processEvents(); + if (progress.wasCanceled()) { + m_centreFrame = origCentreFrame; + update(); + return false; + } + + m_centreFrame = (x + width()/2) * m_zoomLevel; + + QRect chunk(0, 0, width(), height()); + + if (hasLightBackground()) { + paint.setPen(Qt::white); + paint.setBrush(Qt::white); + } else { + paint.setPen(Qt::black); + paint.setBrush(Qt::black); + } + + paint.drawRect(QRect(rect.x() + x, rect.y(), width(), height())); + + paint.setPen(Qt::black); + paint.setBrush(Qt::NoBrush); + + for (LayerList::iterator i = m_layers.begin(); + i != m_layers.end(); ++i) { + + paint.setRenderHint(QPainter::Antialiasing, false); + + paint.save(); + paint.translate(rect.x() + x, rect.y()); + +// std::cerr << "Centre frame now: " << m_centreFrame << " drawing to " << chunk.x() << ", " << chunk.width() << std::endl; + + (*i)->paint(this, paint, chunk); + + paint.restore(); + } + } + + m_centreFrame = origCentreFrame; + update(); + return true; +} + +QImage * +View::toNewImage() +{ + size_t f0 = getModelsStartFrame(); + size_t f1 = getModelsEndFrame(); + + size_t x0 = f0 / getZoomLevel(); + size_t x1 = f1 / getZoomLevel(); + + QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32); + + QPainter *paint = new QPainter(image); + if (!render(*paint, image->rect())) { + delete paint; + delete image; + return 0; + } else { + delete paint; + return image; + } +} + QString View::toXmlString(QString indent, QString extraAttributes) const {