20 #include "data/model/Model.h" 21 #include "base/RealTime.h" 22 #include "base/Preferences.h" 39 m_labelHeight(LabelTop)
54 int &resolution,
SnapType snap,
int)
const 56 auto model = ModelById::get(
m_model);
64 RealTime rtick = RealTime::fromMicroseconds(tickUSec);
65 sv_samplerate_t rate = model->getSampleRate();
67 RealTime rt = RealTime::frame2RealTime(frame, rate);
68 double ratio = rt / rtick;
70 int rounded = int(ratio);
71 RealTime rdrt = rtick * rounded;
73 sv_frame_t left = RealTime::realTime2Frame(rdrt, rate);
74 resolution = int(RealTime::realTime2Frame(rtick, rate));
75 sv_frame_t right = left + resolution;
108 if (dl >= 0 && dr >= 0) {
118 }
else if (dl >= 0) {
122 }
else if (dr >= 0) {
137 bool &quarterTicks)
const 140 auto model = ModelById::get(
m_model);
141 if (!model || !v)
return 1000 * 1000;
143 sv_samplerate_t sampleRate = model->getSampleRate();
144 if (!sampleRate)
return 1000 * 1000;
148 if (endFrame == startFrame) {
149 endFrame = startFrame + 1;
155 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 157 int exampleWidth = QFontMetrics(QFont()).width(
"10:42.987654");
160 RealTime rtStart = RealTime::frame2RealTime(startFrame, sampleRate);
161 RealTime rtEnd = RealTime::frame2RealTime(endFrame, sampleRate);
164 if (count < 1) count = 1;
165 RealTime rtGap = (rtEnd - rtStart) / count;
167 #ifdef DEBUG_TIME_RULER_LAYER 169 <<
", startFrame = " << startFrame <<
", endFrame = " << endFrame
170 <<
", rtStart = " << rtStart <<
", rtEnd = " << rtEnd
172 <<
", minPixelSpacing = " << minPixelSpacing
173 <<
", count = " << count <<
", rtGap = " << rtGap << endl;
177 quarterTicks =
false;
182 if (s > 0) { incus *= 5; s /= 5; }
183 if (s > 0) { incus *= 2; s /= 2; }
184 if (s > 0) { incus *= 6; s /= 6; quarterTicks =
true; }
185 if (s > 0) { incus *= 5; s /= 5; quarterTicks =
false; }
186 if (s > 0) { incus *= 2; s /= 2; }
187 if (s > 0) { incus *= 6; s /= 6; quarterTicks =
true; }
191 quarterTicks =
false;
193 }
else if (rtGap.msec() > 0) {
195 int ms = rtGap.msec();
196 if (ms > 0) { incus *= 10; ms /= 10; }
197 if (ms > 0) { incus *= 10; ms /= 10; }
198 if (ms > 0) { incus *= 5; ms /= 5; }
199 if (ms > 0) { incus *= 2; ms /= 2; }
202 int us = rtGap.usec();
203 if (us > 0) { incus *= 10; us /= 10; }
204 if (us > 0) { incus *= 10; us /= 10; }
205 if (us > 0) { incus *= 5; us /= 5; }
206 if (us > 0) { incus *= 2; us /= 2; }
209 #ifdef DEBUG_TIME_RULER_LAYER 210 SVCERR <<
"getMajorTickUSec: returning incus = " << incus << endl;
219 auto model = ModelById::get(
m_model);
220 sv_samplerate_t sampleRate = model->getSampleRate();
221 double dframe = (us * sampleRate) / 1000000.0;
223 sv_frame_t frame = sv_frame_t(floor(dframe + eps));
228 if (zoom.zone == ZoomLevel::FramesPerPixel) {
237 double off = dframe - double(frame);
241 x = int(x0 + off * (x1 - x0));
244 #ifdef DEBUG_TIME_RULER_LAYER 245 cerr <<
"Considering frame = " << frame <<
", x = " << x << endl;
254 #ifdef DEBUG_TIME_RULER_LAYER 255 SVCERR <<
"TimeRulerLayer::paint (" << rect.x() <<
"," << rect.y()
256 <<
") [" << rect.width() <<
"x" << rect.height() <<
"]" << endl;
259 auto model = ModelById::get(
m_model);
260 if (!model || !model->isOK())
return;
262 sv_samplerate_t sampleRate = model->getSampleRate();
263 if (!sampleRate)
return;
267 #ifdef DEBUG_TIME_RULER_LAYER 268 SVCERR <<
"start frame = " << startFrame << endl;
271 bool quarter =
false;
273 int64_t us = int64_t(floor(1000.0 * 1000.0 * (
double(startFrame) /
274 double(sampleRate))));
275 us = (us / incus) * incus - incus;
277 #ifdef DEBUG_TIME_RULER_LAYER 278 SVCERR <<
"start us = " << us <<
" at step " << incus << endl;
281 Preferences *prefs = Preferences::getInstance();
282 auto origTimeTextMode = prefs->getTimeToTextMode();
286 prefs->blockSignals(
true);
287 prefs->setTimeToTextMode(Preferences::TimeToTextUs);
296 sv_frame_t incFrame = lrint((
double(incus) * sampleRate) / 1000000);
297 int incX = int(round(v->
getZoomLevel().framesToPixels(
double(incFrame))));
299 if (incX < minPixelSpacing * 2) {
300 ticks = quarter ? 4 : 5;
318 double dus = double(us);
322 if (x >= rect.x() + rect.width() + 50) {
323 #ifdef DEBUG_TIME_RULER_LAYER 324 SVCERR <<
"X well out of range, ending here" << endl;
329 if (x >= rect.x() - 50 && us >= minlabel) {
331 RealTime rt = RealTime::fromMicroseconds(us);
333 #ifdef DEBUG_TIME_RULER_LAYER 334 SVCERR <<
"X in range, drawing line here for time " << rt.toText() <<
" (usec = " << us <<
")" << endl;
337 QString text(QString::fromStdString(rt.toText()));
339 QFontMetrics metrics = paint.fontMetrics();
340 int tw = metrics.width(text);
343 (x < rect.x() - tw/2 ||
344 x >= rect.x() + rect.width() + tw/2)) {
345 #ifdef DEBUG_TIME_RULER_LAYER 346 SVCERR <<
"hm, maybe X isn't in range after all (x = " << x <<
", tw = " << tw <<
", rect.x() = " << rect.x() <<
", rect.width() = " << rect.width() <<
")" << endl;
350 paint.setPen(greyColour);
354 paint.drawLine(x, 0, x, 5);
361 y = 6 + metrics.ascent();
364 y = v->
getPaintHeight() / 2 - metrics.height() / 2 + metrics.ascent();
367 y = v->
getPaintHeight() - metrics.height() + metrics.ascent() - 6;
375 paint.drawText(x+2 - tw/2, y, text);
382 paint.setPen(greyColour);
384 for (
int i = 1; i < ticks; ++i) {
386 dus = double(us) + (i * double(incus)) / ticks;
390 if (x < rect.x() || x >= rect.x() + rect.width()) {
391 #ifdef DEBUG_TIME_RULER_LAYER 397 #ifdef DEBUG_TIME_RULER_LAYER 398 SVCERR <<
"tick " << i <<
" in range, drawing at " << x << endl;
411 paint.drawLine(x, 0, x, sz);
418 prefs->setTimeToTextMode(origTimeTextMode);
419 prefs->blockSignals(
false);
429 (QString(darkbg ?
"White" :
"Black"));
442 QString indent, QString extraAttributes)
const static LayerFactory * getInstance()
virtual int getXForViewX(int viewx) const =0
Return the closest pixel x-coordinate corresponding to a given view x-coordinate. ...
int getXForUSec(LayerGeometryProvider *, double usec) const
int getDefaultColourHint(bool dark, bool &impose) override
virtual ZoomLevel getZoomLevel() const =0
Return the zoom level, i.e.
static int scalePixelSize(int pixels)
Take a "design pixel" size and scale it for the actual display.
void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override
Paint the given rectangle of this layer onto the given view using the given painter, superimposing it on top of any existing material in that view.
virtual sv_frame_t getFrameForX(int x) const =0
Return the closest frame to the given pixel x-coordinate.
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
std::vector< QColor > getPartialShades(LayerGeometryProvider *v) const
virtual QColor getBaseQColor() const
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
void setProperties(const QXmlAttributes &attributes) override
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
Interface for classes that provide geometry information (such as size, start frame, and a large number of other properties) about the disposition of a layer.
QString getLayerPresentationName(LayerType type)
int getColourIndex(QString name) const
Return the index of the colour with the given name, if found in the database.
virtual sv_frame_t getStartFrame() const =0
Retrieve the first visible sample frame on the widget.
bool snapToFeatureFrame(LayerGeometryProvider *, sv_frame_t &, int &, SnapType, int) const override
Adjust the given frame to snap to the nearest feature, if possible.
QString getLayerPresentationName() const override
virtual int getPaintHeight() const
virtual Layer * getLayer(int n)
Return the nth layer, counted in stacking order.
void setProperties(const QXmlAttributes &attributes) override
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
LayerType getLayerType(const Layer *)
virtual ViewManager * getViewManager() const =0
LabelHeight m_labelHeight
OverlayMode getOverlayMode() const
static void drawVisibleText(const LayerGeometryProvider *, QPainter &p, int x, int y, QString text, TextStyle style)
virtual sv_frame_t getEndFrame() const =0
Retrieve the last visible sample frame on the widget.
virtual int getXForFrame(sv_frame_t frame) const =0
Return the pixel x-coordinate corresponding to a given sample frame (which may be negative)...
virtual int getPaintWidth() const
static ColourDatabase * getInstance()
virtual View * getView()=0
int64_t getMajorTickUSec(LayerGeometryProvider *, bool &quarterTicks) const