20 #include "data/model/Model.h" 21 #include "base/RealTime.h" 38 m_labelHeight(LabelTop)
53 int &resolution,
SnapType snap)
const 62 RealTime rtick = RealTime::fromMilliseconds(tick);
63 int rate =
m_model->getSampleRate();
65 RealTime rt = RealTime::frame2RealTime(frame, rate);
66 double ratio = rt / rtick;
68 int rounded = int(ratio);
69 RealTime rdrt = rtick * rounded;
71 int left = RealTime::realTime2Frame(rdrt, rate);
72 resolution = RealTime::realTime2Frame(rtick, rate);
73 int right = left + resolution;
91 if (abs(frame - left) > abs(right - frame)) {
101 int dl = -1, dr = -1;
116 if (dl >= 0 && dr >= 0) {
126 }
else if (dl >= 0) {
130 }
else if (dr >= 0) {
148 if (!
m_model || !v)
return 1000;
150 int sampleRate =
m_model->getSampleRate();
151 if (!sampleRate)
return 1000;
156 int minPixelSpacing = 50;
158 RealTime rtStart = RealTime::frame2RealTime(startFrame, sampleRate);
159 RealTime rtEnd = RealTime::frame2RealTime(endFrame, sampleRate);
161 int count = v->width() / minPixelSpacing;
162 if (count < 1) count = 1;
163 RealTime rtGap = (rtEnd - rtStart) / count;
166 quarterTicks =
false;
171 if (s > 0) { incms *= 5; s /= 5; }
172 if (s > 0) { incms *= 2; s /= 2; }
173 if (s > 0) { incms *= 6; s /= 6; quarterTicks =
true; }
174 if (s > 0) { incms *= 5; s /= 5; quarterTicks =
false; }
175 if (s > 0) { incms *= 2; s /= 2; }
176 if (s > 0) { incms *= 6; s /= 6; quarterTicks =
true; }
180 quarterTicks =
false;
184 int ms = rtGap.msec();
185 if (ms > 0) { incms *= 10; ms /= 10; }
186 if (ms > 0) { incms *= 10; ms /= 10; }
187 if (ms > 0) { incms *= 5; ms /= 5; }
188 if (ms > 0) { incms *= 2; ms /= 2; }
197 #ifdef DEBUG_TIME_RULER_LAYER 198 SVDEBUG <<
"TimeRulerLayer::paint (" << rect.x() <<
"," << rect.y()
199 <<
") [" << rect.width() <<
"x" << rect.height() <<
"]" << endl;
204 int sampleRate =
m_model->getSampleRate();
205 if (!sampleRate)
return;
209 #ifdef DEBUG_TIME_RULER_LAYER 210 cerr <<
"start frame = " << startFrame << endl;
213 bool quarter =
false;
216 int ms = lrint(1000.0 * (
double(startFrame) /
double(sampleRate)));
217 ms = (ms / incms) * incms - incms;
219 #ifdef DEBUG_TIME_RULER_LAYER 220 cerr <<
"start ms = " << ms <<
" at step " << incms << endl;
228 int minPixelSpacing = 50;
229 long incFrame = (incms * sampleRate) / 1000;
232 if (incX < minPixelSpacing * 2) {
233 ticks = quarter ? 4 : 5;
252 long frame = lrint((dms * sampleRate) / 1000.0);
258 #ifdef DEBUG_TIME_RULER_LAYER 259 SVDEBUG <<
"Considering frame = " << frame <<
", x = " << x << endl;
262 if (x >= rect.x() + rect.width() + 50) {
263 #ifdef DEBUG_TIME_RULER_LAYER 264 cerr <<
"X well out of range, ending here" << endl;
269 if (x >= rect.x() - 50 && ms >= minlabel) {
271 RealTime rt = RealTime::fromMilliseconds(ms);
273 #ifdef DEBUG_TIME_RULER_LAYER 274 cerr <<
"X in range, drawing line here for time " << rt.toText() << endl;
277 QString text(QString::fromStdString(rt.toText()));
278 QFontMetrics metrics =
paint.fontMetrics();
279 int tw = metrics.width(text);
282 (x < rect.x() - tw/2 ||
283 x >= rect.x() + rect.width() + tw/2)) {
284 #ifdef DEBUG_TIME_RULER_LAYER 285 cerr <<
"hm, maybe X isn't in range after all (x = " << x <<
", tw = " << tw <<
", rect.x() = " << rect.x() <<
", rect.width() = " << rect.width() <<
")" << endl;
289 paint.setPen(greyColour);
290 paint.drawLine(x, 0, x, v->height());
293 paint.drawLine(x, 0, x, 5);
294 paint.drawLine(x, v->height() - 6, x, v->height() - 1);
300 y = 6 + metrics.ascent();
303 y = v->height() / 2 - metrics.height() / 2 + metrics.ascent();
306 y = v->height() - metrics.height() + metrics.ascent() - 6;
314 paint.drawText(x+2 - tw/2, y, text);
321 paint.setPen(greyColour);
323 for (
int i = 1; i < ticks; ++i) {
325 dms = ms + (i * double(incms)) / ticks;
326 frame = lrint((dms * sampleRate) / 1000.0);
332 if (x < rect.x() || x >= rect.x() + rect.width()) {
333 #ifdef DEBUG_TIME_RULER_LAYER 339 #ifdef DEBUG_TIME_RULER_LAYER 340 cerr <<
"tick " << i <<
" in range, drawing at " << x << endl;
347 paint.drawLine(x, 0, x, v->height());
353 paint.drawLine(x, 0, x, sz);
354 paint.drawLine(x, v->height() - sz - 1, x, v->height() - 1);
368 (QString(darkbg ?
"White" :
"Black"));
381 QString indent, QString extraAttributes)
const static LayerFactory * getInstance()
int getFrameForX(int x) const
Return the closest frame to the given pixel x-coordinate.
virtual int getDefaultColourHint(bool dark, bool &impose)
void setProperties(const QXmlAttributes &attributes)
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
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 ViewManager * getViewManager() const
int getZoomLevel() const
Return the zoom level, i.e.
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,...
virtual QColor getBaseQColor() const
virtual bool snapToFeatureFrame(View *, int &, int &, SnapType) const
Adjust the given frame to snap to the nearest feature, if possible.
std::vector< QColor > getPartialShades(View *v) const
int getColourIndex(QString name) const
QString getLayerPresentationName(LayerType type)
int getStartFrame() const
Retrieve the first visible sample frame on the widget.
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 Layer * getLayer(int n)
Return the nth layer, counted in stacking order.
LayerType getLayerType(const Layer *)
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
LabelHeight m_labelHeight
virtual void drawVisibleText(QPainter &p, int x, int y, QString text, TextStyle style) const
virtual QString getLayerPresentationName() const
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.
OverlayMode getOverlayMode() const
int getMajorTickSpacing(View *, bool &quarterTicks) const
int getXForFrame(int frame) const
Return the pixel x-coordinate corresponding to a given sample frame (which may be negative).
static ColourDatabase * getInstance()