18 #include "data/model/Model.h" 23 #include <QMutexLocker> 24 #include <QMouseEvent> 25 #include <QTextStream> 27 #include <QDomDocument> 28 #include <QDomElement> 29 #include <QDomNamedNodeMap> 33 #include "base/PlayParameterRepository.h" 38 m_haveDraggingRect(false),
39 m_haveCurrentMeasureRect(false)
57 connect(model, SIGNAL(completionChanged()),
60 connect(model, SIGNAL(alignmentCompletionChanged()),
90 if (modelName !=
"") {
91 text = QString(
"%1: %2").arg(modelName).arg(layerName);
102 QObject::setObjectName(name);
112 return PlayParameterRepository::getInstance()->getPlayParameters(model);
120 const void *vv = (
const void *)v;
128 const void *vv = (
const void *)v;
147 if (!m)
return false;
156 float &diff, QString &unit)
const 164 diff = fabsf(v1 - v0);
172 SVDEBUG <<
"Layer::alignToReference(" << frame <<
"): model = " << m <<
", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl;
173 if (m && m->getAlignmentReference()) {
174 return m->alignToReference(frame);
184 SVDEBUG <<
"Layer::alignFromReference(" << frame <<
"): model = " << m <<
", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl;
185 if (m && m->getAlignmentReference()) {
186 return m->alignFromReference(frame);
235 for (Clipboard::PointList::const_iterator i = clip.getPoints().begin();
236 i != clip.getPoints().end(); ++i) {
253 int sourceFrame = i->getFrame();
254 int referenceFrame = sourceFrame;
255 if (i->haveReferenceFrame()) {
256 referenceFrame = i->getReferenceFrame();
262 if (myMappedFrame != referenceFrame)
return true;
302 stream << QString(
"<measurement ");
305 stream << QString(
"startFrame=\"%1\" endFrame=\"%2\" ")
306 .arg(startFrame).arg(endFrame);
308 stream << QString(
"startX=\"%1\" endX=\"%2\" ")
309 .arg(pixrect.x()).arg(pixrect.x() << pixrect.width());
312 stream << QString(
"startY=\"%1\" endY=\"%2\"/>\n")
313 .arg(startY).arg(endY);
320 QString fs = attributes.value(
"startFrame");
324 rect.
endFrame = attributes.value(
"endFrame").toInt();
327 x0 = attributes.value(
"startX").toInt();
328 x1 = attributes.value(
"endX").toInt();
331 rect.
startY = attributes.value(
"startY").toDouble();
332 rect.
endY = attributes.value(
"endY").toDouble();
333 rect.
pixrect = QRect(x0, 0, x1 - x0, 0);
340 return tr(
"Make Measurement");
346 m_layer->addMeasureRectToSet(m_rect);
352 m_layer->deleteMeasureRectFromSet(m_rect);
358 return tr(
"Delete Measurement");
364 m_layer->deleteMeasureRectFromSet(m_rect);
370 m_layer->addMeasureRectToSet(m_rect);
377 QRect(e->x(), e->y(), 0, 0));
418 MeasureRectSet::const_iterator focusRectItr =
429 bool showFocus, QPoint focusPoint)
const 433 MeasureRectSet::const_iterator focusRectItr =
m_measureRects.end();
439 }
else if (showFocus) {
449 bool focused = (i == focusRectItr);
487 if (i->startFrame >= ef)
break;
488 if (i->endFrame <= sf)
continue;
491 int x0 = i->pixrect.x();
492 int x1 = x0 + i->pixrect.width();
503 i->pixrect = QRect(x0, i->pixrect.y(), x1 - x0, i->pixrect.height());
512 int y0 = lrint(r.
startY * v->height());
513 int y1 = lrint(r.
endY * v->height());
521 r.
startY = double(y) / double(v->height());
524 r.
endY = double(y) / double(v->height());
541 Layer::MeasureRectSet::const_iterator
545 MeasureRectSet::const_iterator focusRectItr =
m_measureRects.end();
550 if (!i->pixrect.adjusted(-2, -2, 2, 2).contains(focusPoint))
continue;
552 int cx = i->pixrect.x() + i->pixrect.width()/2;
553 int cy = i->pixrect.y() + i->pixrect.height()/2;
554 int xd = focusPoint.x() - cx;
555 int yd = focusPoint.y() - cy;
557 float d = sqrt(
float(xd * xd + yd * yd));
575 int x1 = v->width() + 1;
593 QString indent, QString extraAttributes)
const 598 extraAttributes = QString(
"%1 presentationName=\"%2\"")
602 stream << QString(
"<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5")
605 .arg(getObjectExportId(
this))
606 .arg(encodeEntities(objectName()))
608 .arg(extraAttributes);
611 stream << QString(
"/>\n");
615 stream << QString(
">\n");
619 i->toXml(stream, indent +
" ");
622 stream << QString(
"</layer>\n");
627 QString indent, QString extraAttributes)
const 632 extraAttributes = QString(
"%1 presentationName=\"%2\"")
636 stream << QString(
"<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n")
639 .arg(getObjectExportId(
this))
640 .arg(encodeEntities(objectName()))
642 .arg(extraAttributes);
MeasureRectSet m_measureRects
void toXml(QTextStream &stream, QString indent) const
static LayerFactory * getInstance()
int getFrameForX(int x) const
Return the closest frame to the given pixel x-coordinate.
void modelChangedWithin(int startFrame, int endFrame)
QString getLayerIconName(LayerType)
QPoint m_currentMeasureRectPoint
bool m_haveCurrentMeasureRect
virtual void addMeasurementRect(const QXmlAttributes &)
Add a measurement rectangle from the given XML attributes (presumably taken from a measurement elemen...
virtual bool hasTimeXAxis() const
MeasureRect m_draggingRect
void connectSignals(const Model *)
void showLayer(View *, bool show)
virtual void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Convert the layer's data (though not those of the model it refers to) into XML for file output.
void updateMeasurePixrects(View *v) const
virtual void measureDoubleClick(View *, QMouseEvent *)
virtual QString getName() const
virtual bool nearestMeasurementRectChanged(View *, QPoint prev, QPoint now) const
void addCommand(Command *command)
Add a command to the command history.
virtual void measureDrag(View *, QMouseEvent *)
virtual void toBriefXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Produce XML containing the layer's ID and type.
void paintMeasurementRect(View *v, QPainter &paint, const MeasureRect &r, bool focus) const
virtual bool getYScaleValue(const View *, int, float &, QString &) const
Return the value and unit at the given y coordinate in the given view.
virtual void updateMeasureRectYCoords(View *v, const MeasureRect &r) const
virtual void setLayerDormant(const View *v, bool dormant)
Indicate that a layer is not currently visible in the given view and is not expected to become visibl...
virtual void setObjectName(const QString &name)
bool operator<(const MeasureRect &mr) const
virtual QString getName() const
int alignToReference(int) const
virtual void setMeasureRectFromPixrect(View *v, MeasureRect &r, QRect pixrect) const
virtual void deleteCurrentMeasureRect()
QString getLayerPresentationName(LayerType type)
virtual void paintMeasurementRects(View *, QPainter &, bool showFocus, QPoint focusPoint) const
int getStartFrame() const
Retrieve the first visible sample frame on the widget.
int alignFromReference(int) const
virtual void setMeasureRectYCoord(View *v, MeasureRect &r, bool start, int y) const
void layerParametersChanged()
int getEndFrame() const
Retrieve the last visible sample frame on the widget.
static CommandHistory * getInstance()
std::map< const void *, bool > m_dormancy
bool clipboardHasDifferentAlignment(View *v, const Clipboard &clip) const
virtual QString getPropertyContainerIconName() const
virtual void measureEnd(View *, QMouseEvent *)
virtual bool getYScaleDifference(const View *v, int y0, int y1, float &diff, QString &unit) const
Return the difference between the values at the given y coordinates in the given view,...
void modelAlignmentCompletionChanged()
virtual int alignFromReference(View *v, int frame) const
virtual int alignToReference(View *v, int frame) const
LayerType getLayerType(const Layer *)
virtual const Model * getModel() const =0
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
virtual bool getXScaleValue(const View *v, int x, float &value, QString &unit) const
Return the value and unit at the given x coordinate in the given view.
virtual void setPresentationName(QString name)
void modelCompletionChanged()
QString m_presentationName
virtual void paint(View *, QPainter &, QRect) const =0
Paint the given rectangle of this layer onto the given view using the given painter,...
virtual void measureStart(View *, QMouseEvent *)
void addMeasureRectToSet(const MeasureRect &r)
MeasureRectSet::const_iterator findFocusedMeasureRect(QPoint) const
virtual QString getLayerPresentationName() const
virtual PlayParameters * getPlayParameters()
virtual bool isLayerDormant(const View *v) const
Return whether the layer is dormant (i.e.
int getXForFrame(int frame) const
Return the pixel x-coordinate corresponding to a given sample frame (which may be negative).
virtual void drawMeasurementRect(QPainter &p, const Layer *, QRect rect, bool focus) const