18 #include "data/model/Model.h" 19 #include "base/RealTime.h" 21 #include "base/Profiler.h" 22 #include "base/Clipboard.h" 25 #include "data/model/SparseOneDimensionalModel.h" 31 #include <QMouseEvent> 32 #include <QTextStream> 33 #include <QMessageBox> 44 m_editingPoint(0, tr(
"New Point")),
46 m_plotStyle(PlotInstants)
62 #ifdef DEBUG_TIME_INSTANT_LAYER 63 cerr <<
"TimeInstantLayer::setModel(" << model <<
")" << endl;
77 list.push_back(
"Plot Type");
84 if (name ==
"Plot Type")
return tr(
"Plot Type");
91 if (name ==
"Plot Type")
return ValueProperty;
97 int *min,
int *max,
int *deflt)
const 101 if (name ==
"Plot Type") {
105 if (deflt) *deflt = 0;
121 if (name ==
"Plot Type") {
124 case 0:
return tr(
"Instants");
125 case 1:
return tr(
"Segmentation");
134 if (name ==
"Plot Type") {
156 SparseOneDimensionalModel::PointList
163 if (!
m_model)
return SparseOneDimensionalModel::PointList();
167 SparseOneDimensionalModel::PointList onPoints =
170 if (!onPoints.empty()) {
174 SparseOneDimensionalModel::PointList prevPoints =
175 m_model->getPreviousPoints(frame);
176 SparseOneDimensionalModel::PointList nextPoints =
179 SparseOneDimensionalModel::PointList usePoints = prevPoints;
181 if (prevPoints.empty()) {
182 usePoints = nextPoints;
183 }
else if (
long(prevPoints.begin()->frame) < v->
getStartFrame() &&
185 usePoints = nextPoints;
186 }
else if (nextPoints.begin()->frame - frame <
187 frame - prevPoints.begin()->frame) {
188 usePoints = nextPoints;
191 if (!usePoints.empty()) {
194 if ((px > x && px - x > fuzz) ||
195 (px < x && x - px > fuzz + 1)) {
207 SparseOneDimensionalModel::PointList points =
m_model->getPreviousPoints(frame);
208 for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin();
209 i != points.end(); ++i) {
210 if (i->label !=
"")
return i->label;
222 SparseOneDimensionalModel::PointList points =
getLocalPoints(v, x);
224 if (points.empty()) {
226 return tr(
"In progress");
228 return tr(
"No local points");
232 long useFrame = points.begin()->frame;
234 RealTime rt = RealTime::frame2RealTime(useFrame,
m_model->getSampleRate());
238 if (points.begin()->label ==
"") {
239 text = QString(tr(
"Time:\t%1\nNo label"))
240 .arg(rt.toText(
true).c_str());
242 text = QString(tr(
"Time:\t%1\nLabel:\t%2"))
243 .arg(rt.toText(
true).c_str())
244 .arg(points.begin()->label);
260 resolution =
m_model->getResolution();
261 SparseOneDimensionalModel::PointList points;
266 if (points.empty())
return false;
267 frame = points.begin()->frame;
271 points =
m_model->getPoints(frame, frame);
275 for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin();
276 i != points.end(); ++i) {
280 if (i->frame >= frame) {
288 if (i->frame <= frame) {
297 SparseOneDimensionalModel::PointList::const_iterator j = i;
300 if (j == points.end()) {
306 }
else if (j->frame >= frame) {
308 if (j->frame - frame < frame - i->frame) {
330 int x0 = rect.left(), x1 = rect.right();
335 SparseOneDimensionalModel::PointList points(
m_model->getPoints
340 int index =
m_model->getIndexOf(*points.begin());
341 odd = ((index % 2) == 1);
347 brushColour.setAlpha(100);
348 paint.setBrush(brushColour);
350 QColor oddBrushColour(brushColour);
353 oddBrushColour = Qt::gray;
355 oddBrushColour = Qt::red;
357 oddBrushColour = Qt::blue;
359 oddBrushColour = Qt::green;
361 oddBrushColour = oddBrushColour.light(150);
363 oddBrushColour.setAlpha(100);
370 long illuminateFrame = -1;
373 SparseOneDimensionalModel::PointList localPoints =
375 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame;
381 for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin();
382 i != points.end(); ++i) {
384 const SparseOneDimensionalModel::Point &p(*i);
385 SparseOneDimensionalModel::PointList::const_iterator j = i;
390 p.frame != illuminateFrame)
continue;
396 if (j != points.end()) {
398 if (nx < x + 3) iw = 1;
405 if (p.frame == illuminateFrame) {
408 paint.setPen(brushColour);
413 paint.drawRect(x, 0, iw - 1, v->height() - 1);
415 paint.drawLine(x, 0, x, v->height() - 1);
419 if (odd)
paint.setBrush(oddBrushColour);
420 else paint.setBrush(brushColour);
424 if (j != points.end()) {
425 const SparseOneDimensionalModel::Point &q(*j);
433 if (illuminateFrame != p.frame &&
434 (nx < x + 5 || x >= v->width() - 1)) {
435 paint.setPen(Qt::NoPen);
438 paint.drawRect(x, -1, nx - x, v->height() + 1);
450 int lw =
paint.fontMetrics().width(p.label);
453 if (j != points.end()) {
455 if (nx >= x && nx - x - iw - 3 <= lw) good =
false;
471 #ifdef DEBUG_TIME_INSTANT_LAYER 472 cerr <<
"TimeInstantLayer::drawStart(" << e->x() <<
")" << endl;
478 if (frame < 0) frame = 0;
479 frame = frame /
m_model->getResolution() *
m_model->getResolution();
481 m_editingPoint = SparseOneDimensionalModel::Point(frame, tr(
"New Point"));
494 #ifdef DEBUG_TIME_INSTANT_LAYER 495 cerr <<
"TimeInstantLayer::drawDrag(" << e->x() <<
")" << endl;
501 if (frame < 0) frame = 0;
502 frame = frame /
m_model->getResolution() *
m_model->getResolution();
511 #ifdef DEBUG_TIME_INSTANT_LAYER 512 cerr <<
"TimeInstantLayer::drawEnd(" << e->x() <<
")" << endl;
515 QString newName = tr(
"Add Point at %1 s")
518 .toText(
false).c_str());
530 SparseOneDimensionalModel::PointList points =
getLocalPoints(v, e->x());
531 if (points.empty())
return;
555 SparseOneDimensionalModel::PointList points =
getLocalPoints(v, e->x());
556 if (points.empty())
return;
572 #ifdef DEBUG_TIME_INSTANT_LAYER 573 cerr <<
"TimeInstantLayer::editStart(" << e->x() <<
")" << endl;
578 SparseOneDimensionalModel::PointList points =
getLocalPoints(v, e->x());
579 if (points.empty())
return;
594 #ifdef DEBUG_TIME_INSTANT_LAYER 595 cerr <<
"TimeInstantLayer::editDrag(" << e->x() <<
")" << endl;
601 if (frame < 0) frame = 0;
602 frame = frame /
m_model->getResolution() *
m_model->getResolution();
617 #ifdef DEBUG_TIME_INSTANT_LAYER 618 cerr <<
"TimeInstantLayer::editEnd(" << e->x() <<
")" << endl;
622 QString newName = tr(
"Move Point to %1 s")
625 .toText(
false).c_str());
638 SparseOneDimensionalModel::PointList points =
getLocalPoints(v, e->x());
639 if (points.empty())
return false;
641 SparseOneDimensionalModel::Point point = *points.begin();
651 if (dialog->exec() == QDialog::Accepted) {
653 SparseOneDimensionalModel::Point newPoint = point;
655 newPoint.label = dialog->
getText();
657 SparseOneDimensionalModel::EditCommand *command =
658 new SparseOneDimensionalModel::EditCommand(
m_model, tr(
"Edit Point"));
659 command->deletePoint(point);
660 command->addPoint(newPoint);
673 SparseOneDimensionalModel::EditCommand *command =
674 new SparseOneDimensionalModel::EditCommand(
m_model,
675 tr(
"Drag Selection"));
677 SparseOneDimensionalModel::PointList points =
678 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
680 for (SparseOneDimensionalModel::PointList::iterator i = points.begin();
681 i != points.end(); ++i) {
683 if (s.contains(i->frame)) {
684 SparseOneDimensionalModel::Point newPoint(*i);
685 newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
686 command->deletePoint(*i);
687 command->addPoint(newPoint);
699 SparseOneDimensionalModel::EditCommand *command =
700 new SparseOneDimensionalModel::EditCommand(
m_model,
701 tr(
"Resize Selection"));
703 SparseOneDimensionalModel::PointList points =
704 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
707 double(newSize.getEndFrame() - newSize.getStartFrame()) /
708 double(s.getEndFrame() - s.getStartFrame());
710 for (SparseOneDimensionalModel::PointList::iterator i = points.begin();
711 i != points.end(); ++i) {
713 if (s.contains(i->frame)) {
715 double target = i->frame;
716 target = newSize.getStartFrame() +
717 double(target - s.getStartFrame()) * ratio;
719 SparseOneDimensionalModel::Point newPoint(*i);
720 newPoint.frame = lrint(target);
721 command->deletePoint(*i);
722 command->addPoint(newPoint);
734 SparseOneDimensionalModel::EditCommand *command =
735 new SparseOneDimensionalModel::EditCommand(
m_model,
736 tr(
"Delete Selection"));
738 SparseOneDimensionalModel::PointList points =
739 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
741 for (SparseOneDimensionalModel::PointList::iterator i = points.begin();
742 i != points.end(); ++i) {
743 if (s.contains(i->frame)) command->deletePoint(*i);
754 SparseOneDimensionalModel::PointList points =
755 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
757 for (SparseOneDimensionalModel::PointList::iterator i = points.begin();
758 i != points.end(); ++i) {
759 if (s.contains(i->frame)) {
760 Clipboard::Point point(i->frame, i->label);
772 const Clipboard::PointList &points = from.getPoints();
774 bool realign =
false;
778 QMessageBox::StandardButton button =
779 QMessageBox::question(v, tr(
"Re-align pasted instants?"),
780 tr(
"The instants you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"),
781 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
784 if (button == QMessageBox::Cancel) {
788 if (button == QMessageBox::Yes) {
793 SparseOneDimensionalModel::EditCommand *command =
794 new SparseOneDimensionalModel::EditCommand(
m_model, tr(
"Paste"));
796 for (Clipboard::PointList::const_iterator i = points.begin();
797 i != points.end(); ++i) {
799 if (!i->haveFrame())
continue;
805 frame = i->getFrame();
809 if (i->haveReferenceFrame()) {
810 frame = i->getReferenceFrame();
813 frame = i->getFrame();
817 if (frameOffset > 0) frame += frameOffset;
818 else if (frameOffset < 0) {
819 if (frame > -frameOffset) frame += frameOffset;
823 SparseOneDimensionalModel::Point newPoint(frame);
824 if (i->haveLabel()) {
825 newPoint.label = i->getLabel();
826 }
else if (i->haveValue()) {
827 newPoint.label = QString(
"%1").arg(i->getValue());
830 command->addPoint(newPoint);
842 (QString(darkbg ?
"Bright Purple" :
"Purple"));
847 QString indent, QString extraAttributes)
const 851 QString(
" plotStyle=\"%1\"")
862 attributes.value(
"plotStyle").toInt(&ok);
virtual QString getPropertyLabel(const PropertyName &) const
virtual void eraseDrag(View *v, QMouseEvent *)
int getFrameForX(int x) const
Return the closest frame to the given pixel x-coordinate.
virtual void copy(View *v, Selection s, Clipboard &to)
void setFrameTime(int frame)
virtual void resizeSelection(Selection s, Selection newSize)
virtual PropertyList getProperties() const
virtual QString getFeatureDescription(View *v, QPoint &) const
virtual void drawStart(View *v, QMouseEvent *)
virtual void drawDrag(View *v, QMouseEvent *)
virtual bool snapToFeatureFrame(View *, int &, int &resolution, SnapType) const
Adjust the given frame to snap to the nearest feature, if possible.
void connectSignals(const Model *)
virtual void moveSelection(Selection s, int newStartFrame)
virtual QString getLabelPreceding(int) const
SparseOneDimensionalModel::Point m_editingPoint
void setModel(SparseOneDimensionalModel *model)
SparseOneDimensionalModel * m_model
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.
virtual PropertyType getPropertyType(const PropertyName &) const
virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) const
virtual void drawEnd(View *v, QMouseEvent *)
virtual int getTextLabelHeight(const Layer *layer, QPainter &) const
virtual bool snapToFeatureFrame(View *v, int &frame, int &resolution, SnapType snap) const
Adjust the given frame to snap to the nearest feature, if possible.
virtual QColor getForegroundQColor(View *v) const
void setProperties(const QXmlAttributes &attributes)
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
virtual QColor getBaseQColor() const
void setText(QString text)
SparseOneDimensionalModel::EditCommand * m_editingCommand
int getColourIndex(QString name) const
virtual void paint(View *v, QPainter &paint, QRect rect) const
Paint the given rectangle of this layer onto the given view using the given painter,...
void setPlotStyle(PlotStyle style)
virtual QString getPropertyLabel(const PropertyName &) const
int getStartFrame() const
Retrieve the first visible sample frame on the widget.
virtual bool paste(View *v, const Clipboard &from, int frameOffset, bool interactive)
Paste from the given clipboard onto the layer at the given frame offset.
void layerParametersChanged()
virtual int getDefaultColourHint(bool dark, bool &impose)
virtual void setProperties(const QXmlAttributes &attributes)
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
int getEndFrame() const
Retrieve the last visible sample frame on the widget.
virtual int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const
virtual void eraseStart(View *v, QMouseEvent *)
bool clipboardHasDifferentAlignment(View *v, const Clipboard &clip) const
virtual bool isLayerScrollable(const View *v) const
This should return true if the layer can safely be scrolled automatically by a given view (simply cop...
virtual bool editOpen(View *, QMouseEvent *)
Open an editor on the item under the mouse (e.g.
virtual int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const
virtual int alignFromReference(View *v, int frame) const
virtual int alignToReference(View *v, int frame) const
virtual ~TimeInstantLayer()
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
virtual QString getPropertyValueLabel(const PropertyName &, int value) const
virtual void editEnd(View *v, QMouseEvent *)
virtual QString getPropertyValueLabel(const PropertyName &, int value) const
virtual void drawVisibleText(QPainter &p, int x, int y, QString text, TextStyle style) const
virtual void setProperty(const PropertyName &, int value)
virtual void deleteSelection(Selection s)
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.
virtual void editDrag(View *v, QMouseEvent *)
virtual PropertyList getProperties() const
void finish(SparseOneDimensionalModel::EditCommand *command)
virtual void eraseEnd(View *v, QMouseEvent *)
virtual PropertyType getPropertyType(const PropertyName &) const
int getXForFrame(int frame) const
Return the pixel x-coordinate corresponding to a given sample frame (which may be negative).
static ColourDatabase * getInstance()
virtual void setProperty(const PropertyName &, int value)
virtual void editStart(View *v, QMouseEvent *)
SparseOneDimensionalModel::PointList getLocalPoints(View *v, int) const