Chris@303: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@303: Chris@303: /* Chris@303: Sonic Visualiser Chris@303: An audio file viewer and annotation editor. Chris@303: Centre for Digital Music, Queen Mary, University of London. Chris@303: This file copyright 2006 Chris Cannam. Chris@303: Chris@303: This program is free software; you can redistribute it and/or Chris@303: modify it under the terms of the GNU General Public License as Chris@303: published by the Free Software Foundation; either version 2 of the Chris@303: License, or (at your option) any later version. See the file Chris@303: COPYING included with this distribution for more information. Chris@303: */ Chris@303: Chris@303: #include "ImageLayer.h" Chris@303: Chris@303: #include "data/model/Model.h" Chris@303: #include "base/RealTime.h" Chris@303: #include "base/Profiler.h" Chris@303: #include "view/View.h" Chris@303: Chris@303: #include "data/model/ImageModel.h" Chris@303: Chris@303: #include "widgets/ImageDialog.h" Chris@303: Chris@303: #include Chris@303: #include Chris@303: #include Chris@303: Chris@303: #include Chris@303: #include Chris@303: Chris@303: ImageLayer::ImageMap Chris@303: ImageLayer::m_images; Chris@303: Chris@303: ImageLayer::ImageLayer() : Chris@303: Layer(), Chris@303: m_model(0), Chris@303: m_editing(false), Chris@303: m_originalPoint(0, "", ""), Chris@303: m_editingPoint(0, "", ""), Chris@303: m_editingCommand(0) Chris@303: { Chris@303: Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::setModel(ImageModel *model) Chris@303: { Chris@303: if (m_model == model) return; Chris@303: m_model = model; Chris@303: Chris@303: connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); Chris@303: connect(m_model, SIGNAL(modelChanged(size_t, size_t)), Chris@303: this, SIGNAL(modelChanged(size_t, size_t))); Chris@303: Chris@303: connect(m_model, SIGNAL(completionChanged()), Chris@303: this, SIGNAL(modelCompletionChanged())); Chris@303: Chris@303: // std::cerr << "ImageLayer::setModel(" << model << ")" << std::endl; Chris@303: Chris@303: emit modelReplaced(); Chris@303: } Chris@303: Chris@303: Layer::PropertyList Chris@303: ImageLayer::getProperties() const Chris@303: { Chris@303: return Layer::getProperties(); Chris@303: } Chris@303: Chris@303: QString Chris@303: ImageLayer::getPropertyLabel(const PropertyName &name) const Chris@303: { Chris@303: return ""; Chris@303: } Chris@303: Chris@303: Layer::PropertyType Chris@303: ImageLayer::getPropertyType(const PropertyName &name) const Chris@303: { Chris@303: return Layer::getPropertyType(name); Chris@303: } Chris@303: Chris@303: int Chris@303: ImageLayer::getPropertyRangeAndValue(const PropertyName &name, Chris@303: int *min, int *max, int *deflt) const Chris@303: { Chris@303: return Layer::getPropertyRangeAndValue(name, min, max, deflt); Chris@303: } Chris@303: Chris@303: QString Chris@303: ImageLayer::getPropertyValueLabel(const PropertyName &name, Chris@303: int value) const Chris@303: { Chris@303: return Layer::getPropertyValueLabel(name, value); Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::setProperty(const PropertyName &name, int value) Chris@303: { Chris@303: Layer::setProperty(name, value); Chris@303: } Chris@303: Chris@303: bool Chris@303: ImageLayer::getValueExtents(float &, float &, bool &, QString &) const Chris@303: { Chris@303: return false; Chris@303: } Chris@303: Chris@303: bool Chris@303: ImageLayer::isLayerScrollable(const View *v) const Chris@303: { Chris@303: QPoint discard; Chris@303: return !v->shouldIlluminateLocalFeatures(this, discard); Chris@303: } Chris@303: Chris@303: Chris@303: ImageModel::PointList Chris@303: ImageLayer::getLocalPoints(View *v, int x, int y) const Chris@303: { Chris@303: if (!m_model) return ImageModel::PointList(); Chris@303: Chris@303: std::cerr << "ImageLayer::getLocalPoints(" << x << "," << y << "):"; Chris@303: Chris@303: long frame0 = v->getFrameForX(-150); Chris@303: long frame1 = v->getFrameForX(v->width() + 150); Chris@303: Chris@303: ImageModel::PointList points(m_model->getPoints(frame0, frame1)); Chris@303: Chris@303: ImageModel::PointList rv; Chris@303: Chris@303: //!!! need to store drawn size as well as original size for each Chris@303: //image, but for now: Chris@303: Chris@303: for (ImageModel::PointList::iterator i = points.begin(); Chris@303: i != points.end(); ++i) { Chris@303: Chris@303: const ImageModel::Point &p(*i); Chris@303: Chris@303: int px = v->getXForFrame(p.frame); Chris@303: Chris@303: if (x >= px && x < px + 100) { Chris@303: rv.insert(p); Chris@303: } Chris@303: } Chris@303: Chris@303: std::cerr << rv.size() << " point(s)" << std::endl; Chris@303: Chris@303: return rv; Chris@303: } Chris@303: Chris@303: QString Chris@303: ImageLayer::getFeatureDescription(View *v, QPoint &pos) const Chris@303: { Chris@303: int x = pos.x(); Chris@303: Chris@303: if (!m_model || !m_model->getSampleRate()) return ""; Chris@303: Chris@303: ImageModel::PointList points = getLocalPoints(v, x, pos.y()); Chris@303: Chris@303: if (points.empty()) { Chris@303: if (!m_model->isReady()) { Chris@303: return tr("In progress"); Chris@303: } else { Chris@303: return ""; Chris@303: } Chris@303: } Chris@303: Chris@303: long useFrame = points.begin()->frame; Chris@303: Chris@303: RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); Chris@303: Chris@303: QString text; Chris@303: /* Chris@303: if (points.begin()->label == "") { Chris@303: text = QString(tr("Time:\t%1\nHeight:\t%2\nLabel:\t%3")) Chris@303: .arg(rt.toText(true).c_str()) Chris@303: .arg(points.begin()->height) Chris@303: .arg(points.begin()->label); Chris@303: } Chris@303: Chris@303: pos = QPoint(v->getXForFrame(useFrame), Chris@303: getYForHeight(v, points.begin()->height)); Chris@303: */ Chris@303: return text; Chris@303: } Chris@303: Chris@303: Chris@303: //!!! too much overlap with TimeValueLayer/TimeInstantLayer/TextLayer Chris@303: Chris@303: bool Chris@303: ImageLayer::snapToFeatureFrame(View *v, int &frame, Chris@303: size_t &resolution, Chris@303: SnapType snap) const Chris@303: { Chris@303: if (!m_model) { Chris@303: return Layer::snapToFeatureFrame(v, frame, resolution, snap); Chris@303: } Chris@303: Chris@303: resolution = m_model->getResolution(); Chris@303: ImageModel::PointList points; Chris@303: Chris@303: if (snap == SnapNeighbouring) { Chris@303: Chris@303: points = getLocalPoints(v, v->getXForFrame(frame), -1); Chris@303: if (points.empty()) return false; Chris@303: frame = points.begin()->frame; Chris@303: return true; Chris@303: } Chris@303: Chris@303: points = m_model->getPoints(frame, frame); Chris@303: int snapped = frame; Chris@303: bool found = false; Chris@303: Chris@303: for (ImageModel::PointList::const_iterator i = points.begin(); Chris@303: i != points.end(); ++i) { Chris@303: Chris@303: if (snap == SnapRight) { Chris@303: Chris@303: if (i->frame > frame) { Chris@303: snapped = i->frame; Chris@303: found = true; Chris@303: break; Chris@303: } Chris@303: Chris@303: } else if (snap == SnapLeft) { Chris@303: Chris@303: if (i->frame <= frame) { Chris@303: snapped = i->frame; Chris@303: found = true; // don't break, as the next may be better Chris@303: } else { Chris@303: break; Chris@303: } Chris@303: Chris@303: } else { // nearest Chris@303: Chris@303: ImageModel::PointList::const_iterator j = i; Chris@303: ++j; Chris@303: Chris@303: if (j == points.end()) { Chris@303: Chris@303: snapped = i->frame; Chris@303: found = true; Chris@303: break; Chris@303: Chris@303: } else if (j->frame >= frame) { Chris@303: Chris@303: if (j->frame - frame < frame - i->frame) { Chris@303: snapped = j->frame; Chris@303: } else { Chris@303: snapped = i->frame; Chris@303: } Chris@303: found = true; Chris@303: break; Chris@303: } Chris@303: } Chris@303: } Chris@303: Chris@303: frame = snapped; Chris@303: return found; Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::paint(View *v, QPainter &paint, QRect rect) const Chris@303: { Chris@303: if (!m_model || !m_model->isOK()) return; Chris@303: Chris@303: int sampleRate = m_model->getSampleRate(); Chris@303: if (!sampleRate) return; Chris@303: Chris@303: // Profiler profiler("ImageLayer::paint", true); Chris@303: Chris@303: int x0 = rect.left(), x1 = rect.right(); Chris@303: long frame0 = v->getFrameForX(x0); Chris@303: long frame1 = v->getFrameForX(x1); Chris@303: Chris@303: ImageModel::PointList points(m_model->getPoints(frame0, frame1)); Chris@303: if (points.empty()) return; Chris@303: Chris@303: QColor penColour; Chris@303: penColour = v->getForeground(); Chris@303: Chris@303: // std::cerr << "ImageLayer::paint: resolution is " Chris@303: // << m_model->getResolution() << " frames" << std::endl; Chris@303: Chris@303: QPoint localPos; Chris@303: long illuminateFrame = -1; Chris@303: Chris@303: if (v->shouldIlluminateLocalFeatures(this, localPos)) { Chris@303: ImageModel::PointList localPoints = getLocalPoints(v, localPos.x(), Chris@303: localPos.y()); Chris@303: if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; Chris@303: } Chris@303: Chris@303: paint.save(); Chris@303: paint.setClipRect(rect.x(), 0, rect.width(), v->height()); Chris@303: Chris@303: for (ImageModel::PointList::const_iterator i = points.begin(); Chris@303: i != points.end(); ++i) { Chris@303: Chris@303: const ImageModel::Point &p(*i); Chris@303: Chris@303: int x = v->getXForFrame(p.frame); Chris@303: Chris@303: int nx = x + 2000; Chris@303: ImageModel::PointList::const_iterator j = i; Chris@303: ++j; Chris@303: if (j != points.end()) { Chris@303: int jx = v->getXForFrame(j->frame); Chris@303: if (jx < nx) nx = jx; Chris@303: } Chris@303: /* Chris@303: if (illuminateFrame == p.frame) { Chris@303: paint.setBrush(penColour); Chris@303: paint.setPen(v->getBackground()); Chris@303: } else { Chris@303: paint.setPen(penColour); Chris@303: paint.setBrush(brushColour); Chris@303: } Chris@303: */ Chris@303: QString label = p.label; Chris@303: QString imageName = p.image; Chris@303: Chris@303: int nw = nx - x; Chris@303: if (nw < 10) nw = 20; Chris@303: Chris@303: int top = 10; Chris@303: if (v->height() < 50) top = 5; Chris@303: Chris@303: int bottom = top; Chris@303: Chris@303: QRect labelRect; Chris@303: if (label != "") { Chris@303: float aspect = getImageAspect(imageName); Chris@303: int iw = lrintf((v->height() - v->height()/4 - top - bottom) Chris@303: * aspect); Chris@303: labelRect = paint.fontMetrics().boundingRect Chris@303: (QRect(0, 0, iw, v->height()/4), Chris@303: Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, label); Chris@303: bottom += labelRect.height() + 5; Chris@303: } Chris@303: Chris@303: QImage image = getImage(v, Chris@303: imageName, Chris@303: QSize(nw, v->height() - top - bottom)); Chris@303: Chris@303: if (image.isNull()) { Chris@303: image = QImage(":icons/emptypage.png"); Chris@303: } Chris@303: Chris@303: paint.setRenderHint(QPainter::Antialiasing, false); Chris@303: Chris@303: int boxWidth = image.width(); Chris@303: Chris@303: if (label != "") { Chris@303: boxWidth = std::max(boxWidth, labelRect.width()); Chris@303: } Chris@303: Chris@303: paint.drawRect(x-1, top-1, boxWidth+1, v->height() - 2 * top +1); Chris@303: Chris@303: paint.setRenderHint(QPainter::Antialiasing, true); Chris@303: Chris@303: paint.drawImage(x + (boxWidth - image.width())/2, top, image); Chris@303: Chris@303: paint.drawText(QRect(x, v->height() - bottom + 5, Chris@303: boxWidth, labelRect.height()), Chris@303: Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, Chris@303: label); Chris@303: } Chris@303: Chris@303: paint.restore(); Chris@303: paint.setRenderHint(QPainter::Antialiasing, false); Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::setLayerDormant(const View *v, bool dormant) Chris@303: { Chris@303: if (dormant) { Chris@303: // Delete the images named in the view's scaled map from the Chris@303: // general image map as well. They can always be re-loaded Chris@303: // if it turns out another view still needs them. Chris@303: for (ImageMap::iterator i = m_scaled[v].begin(); Chris@303: i != m_scaled[v].end(); ++i) { Chris@303: m_images.erase(i->first); Chris@303: } Chris@303: m_scaled.erase(v); Chris@303: } Chris@303: } Chris@303: Chris@303: //!!! how to reap no-longer-used images? Chris@303: Chris@303: float Chris@303: ImageLayer::getImageAspect(QString name) const Chris@303: { Chris@303: if (m_images.find(name) == m_images.end()) { Chris@303: m_images[name] = QImage(name); Chris@303: } Chris@303: if (m_images[name].isNull()) return 1.f; Chris@303: return float(m_images[name].width()) / float(m_images[name].height()); Chris@303: } Chris@303: Chris@303: QImage Chris@303: ImageLayer::getImage(View *v, QString name, QSize maxSize) const Chris@303: { Chris@303: bool need = false; Chris@303: Chris@303: // std::cerr << "ImageLayer::getImage(" << v << ", " << name.toStdString() << ", (" Chris@303: // << maxSize.width() << "x" << maxSize.height() << "))" << std::endl; Chris@303: Chris@303: if (!m_scaled[v][name].isNull() && Chris@303: (m_scaled[v][name].width() == maxSize.width() || Chris@303: m_scaled[v][name].height() == maxSize.height())) { Chris@303: // std::cerr << "cache hit" << std::endl; Chris@303: return m_scaled[v][name]; Chris@303: } Chris@303: Chris@303: if (m_images.find(name) == m_images.end()) { Chris@303: m_images[name] = QImage(name); Chris@303: } Chris@303: Chris@303: if (m_images[name].isNull()) { Chris@303: // std::cerr << "null image" << std::endl; Chris@303: m_scaled[v][name] = QImage(); Chris@303: } else { Chris@303: m_scaled[v][name] = Chris@303: m_images[name].scaled(maxSize, Chris@303: Qt::KeepAspectRatio, Chris@303: Qt::SmoothTransformation); Chris@303: } Chris@303: Chris@303: return m_scaled[v][name]; Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::drawStart(View *v, QMouseEvent *e) Chris@303: { Chris@303: // std::cerr << "ImageLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl; Chris@303: Chris@303: if (!m_model) { Chris@303: std::cerr << "ImageLayer::drawStart: no model" << std::endl; Chris@303: return; Chris@303: } Chris@303: Chris@303: long frame = v->getFrameForX(e->x()); Chris@303: if (frame < 0) frame = 0; Chris@303: frame = frame / m_model->getResolution() * m_model->getResolution(); Chris@303: Chris@303: m_editingPoint = ImageModel::Point(frame, "", ""); Chris@303: m_originalPoint = m_editingPoint; Chris@303: Chris@303: if (m_editingCommand) m_editingCommand->finish(); Chris@303: m_editingCommand = new ImageModel::EditCommand(m_model, "Add Image"); Chris@303: m_editingCommand->addPoint(m_editingPoint); Chris@303: Chris@303: m_editing = true; Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::drawDrag(View *v, QMouseEvent *e) Chris@303: { Chris@303: // std::cerr << "ImageLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl; Chris@303: Chris@303: if (!m_model || !m_editing) return; Chris@303: Chris@303: long frame = v->getFrameForX(e->x()); Chris@303: if (frame < 0) frame = 0; Chris@303: frame = frame / m_model->getResolution() * m_model->getResolution(); Chris@303: Chris@303: m_editingCommand->deletePoint(m_editingPoint); Chris@303: m_editingPoint.frame = frame; Chris@303: m_editingCommand->addPoint(m_editingPoint); Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::drawEnd(View *v, QMouseEvent *) Chris@303: { Chris@303: // std::cerr << "ImageLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl; Chris@303: if (!m_model || !m_editing) return; Chris@303: Chris@303: bool ok = false; Chris@303: Chris@303: ImageDialog dialog(tr("Select image"), "", tr("")); Chris@303: if (dialog.exec() == QDialog::Accepted) { Chris@303: ImageModel::ChangeImageCommand *command = Chris@303: new ImageModel::ChangeImageCommand Chris@303: (m_model, m_editingPoint, dialog.getImage(), dialog.getLabel()); Chris@303: m_editingCommand->addCommand(command); Chris@303: } Chris@303: Chris@303: m_editingCommand->finish(); Chris@303: m_editingCommand = 0; Chris@303: m_editing = false; Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::editStart(View *v, QMouseEvent *e) Chris@303: { Chris@303: // std::cerr << "ImageLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; Chris@303: Chris@303: if (!m_model) return; Chris@303: Chris@303: ImageModel::PointList points = getLocalPoints(v, e->x(), e->y()); Chris@303: if (points.empty()) return; Chris@303: Chris@303: m_editOrigin = e->pos(); Chris@303: m_editingPoint = *points.begin(); Chris@303: m_originalPoint = m_editingPoint; Chris@303: Chris@303: if (m_editingCommand) { Chris@303: m_editingCommand->finish(); Chris@303: m_editingCommand = 0; Chris@303: } Chris@303: Chris@303: m_editing = true; Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::editDrag(View *v, QMouseEvent *e) Chris@303: { Chris@303: if (!m_model || !m_editing) return; Chris@303: Chris@303: long frameDiff = v->getFrameForX(e->x()) - v->getFrameForX(m_editOrigin.x()); Chris@303: long frame = m_originalPoint.frame + frameDiff; Chris@303: Chris@303: if (frame < 0) frame = 0; Chris@303: frame = (frame / m_model->getResolution()) * m_model->getResolution(); Chris@303: Chris@303: if (!m_editingCommand) { Chris@303: m_editingCommand = new ImageModel::EditCommand(m_model, tr("Move Image")); Chris@303: } Chris@303: Chris@303: m_editingCommand->deletePoint(m_editingPoint); Chris@303: m_editingPoint.frame = frame; Chris@303: m_editingCommand->addPoint(m_editingPoint); Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::editEnd(View *, QMouseEvent *) Chris@303: { Chris@303: // std::cerr << "ImageLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; Chris@303: if (!m_model || !m_editing) return; Chris@303: Chris@303: if (m_editingCommand) { Chris@303: m_editingCommand->finish(); Chris@303: } Chris@303: Chris@303: m_editingCommand = 0; Chris@303: m_editing = false; Chris@303: } Chris@303: Chris@303: bool Chris@303: ImageLayer::editOpen(View *v, QMouseEvent *e) Chris@303: { Chris@303: if (!m_model) return false; Chris@303: Chris@303: ImageModel::PointList points = getLocalPoints(v, e->x(), e->y()); Chris@303: if (points.empty()) return false; Chris@303: Chris@303: QString image = points.begin()->image; Chris@303: QString label = points.begin()->label; Chris@303: Chris@303: ImageDialog dialog(tr("Select image"), Chris@303: image, Chris@303: label); Chris@303: Chris@303: if (dialog.exec() == QDialog::Accepted) { Chris@303: ImageModel::ChangeImageCommand *command = Chris@303: new ImageModel::ChangeImageCommand Chris@303: (m_model, *points.begin(), dialog.getImage(), dialog.getLabel()); Chris@303: CommandHistory::getInstance()->addCommand(command); Chris@303: } Chris@303: Chris@303: return true; Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::moveSelection(Selection s, size_t newStartFrame) Chris@303: { Chris@303: if (!m_model) return; Chris@303: Chris@303: ImageModel::EditCommand *command = Chris@303: new ImageModel::EditCommand(m_model, tr("Drag Selection")); Chris@303: Chris@303: ImageModel::PointList points = Chris@303: m_model->getPoints(s.getStartFrame(), s.getEndFrame()); Chris@303: Chris@303: for (ImageModel::PointList::iterator i = points.begin(); Chris@303: i != points.end(); ++i) { Chris@303: Chris@303: if (s.contains(i->frame)) { Chris@303: ImageModel::Point newPoint(*i); Chris@303: newPoint.frame = i->frame + newStartFrame - s.getStartFrame(); Chris@303: command->deletePoint(*i); Chris@303: command->addPoint(newPoint); Chris@303: } Chris@303: } Chris@303: Chris@303: command->finish(); Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::resizeSelection(Selection s, Selection newSize) Chris@303: { Chris@303: if (!m_model) return; Chris@303: Chris@303: ImageModel::EditCommand *command = Chris@303: new ImageModel::EditCommand(m_model, tr("Resize Selection")); Chris@303: Chris@303: ImageModel::PointList points = Chris@303: m_model->getPoints(s.getStartFrame(), s.getEndFrame()); Chris@303: Chris@303: double ratio = Chris@303: double(newSize.getEndFrame() - newSize.getStartFrame()) / Chris@303: double(s.getEndFrame() - s.getStartFrame()); Chris@303: Chris@303: for (ImageModel::PointList::iterator i = points.begin(); Chris@303: i != points.end(); ++i) { Chris@303: Chris@303: if (s.contains(i->frame)) { Chris@303: Chris@303: double target = i->frame; Chris@303: target = newSize.getStartFrame() + Chris@303: double(target - s.getStartFrame()) * ratio; Chris@303: Chris@303: ImageModel::Point newPoint(*i); Chris@303: newPoint.frame = lrint(target); Chris@303: command->deletePoint(*i); Chris@303: command->addPoint(newPoint); Chris@303: } Chris@303: } Chris@303: Chris@303: command->finish(); Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::deleteSelection(Selection s) Chris@303: { Chris@303: if (!m_model) return; Chris@303: Chris@303: ImageModel::EditCommand *command = Chris@303: new ImageModel::EditCommand(m_model, tr("Delete Selection")); Chris@303: Chris@303: ImageModel::PointList points = Chris@303: m_model->getPoints(s.getStartFrame(), s.getEndFrame()); Chris@303: Chris@303: for (ImageModel::PointList::iterator i = points.begin(); Chris@303: i != points.end(); ++i) { Chris@303: if (s.contains(i->frame)) command->deletePoint(*i); Chris@303: } Chris@303: Chris@303: command->finish(); Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::copy(Selection s, Clipboard &to) Chris@303: { Chris@303: if (!m_model) return; Chris@303: Chris@303: ImageModel::PointList points = Chris@303: m_model->getPoints(s.getStartFrame(), s.getEndFrame()); Chris@303: Chris@303: for (ImageModel::PointList::iterator i = points.begin(); Chris@303: i != points.end(); ++i) { Chris@303: if (s.contains(i->frame)) { Chris@303: //!!! inadequate Chris@303: Clipboard::Point point(i->frame, i->label); Chris@303: to.addPoint(point); Chris@303: } Chris@303: } Chris@303: } Chris@303: Chris@303: bool Chris@303: ImageLayer::paste(const Clipboard &from, int frameOffset, bool /* interactive */) Chris@303: { Chris@303: if (!m_model) return false; Chris@303: Chris@303: const Clipboard::PointList &points = from.getPoints(); Chris@303: Chris@303: ImageModel::EditCommand *command = Chris@303: new ImageModel::EditCommand(m_model, tr("Paste")); Chris@303: Chris@303: for (Clipboard::PointList::const_iterator i = points.begin(); Chris@303: i != points.end(); ++i) { Chris@303: Chris@303: if (!i->haveFrame()) continue; Chris@303: size_t frame = 0; Chris@303: if (frameOffset > 0 || -frameOffset < i->getFrame()) { Chris@303: frame = i->getFrame() + frameOffset; Chris@303: } Chris@303: ImageModel::Point newPoint(frame); Chris@303: Chris@303: //!!! inadequate Chris@303: Chris@303: if (i->haveLabel()) { Chris@303: newPoint.label = i->getLabel(); Chris@303: } else if (i->haveValue()) { Chris@303: newPoint.label = QString("%1").arg(i->getValue()); Chris@303: } else { Chris@303: newPoint.label = tr("New Point"); Chris@303: } Chris@303: Chris@303: command->addPoint(newPoint); Chris@303: } Chris@303: Chris@303: command->finish(); Chris@303: return true; Chris@303: } Chris@303: Chris@303: QString Chris@303: ImageLayer::toXmlString(QString indent, QString extraAttributes) const Chris@303: { Chris@303: return Layer::toXmlString(indent, extraAttributes); Chris@303: } Chris@303: Chris@303: void Chris@303: ImageLayer::setProperties(const QXmlAttributes &attributes) Chris@303: { Chris@303: } Chris@303: