MCPcopy Create free account
hub / github.com/BatchDrake/SigDigger / paintEvent

Method paintEvent

Components/QTimeSlider.cpp:77–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77void
78QTimeSlider::paintEvent(QPaintEvent *ev)
79{
80 if (timercmp(&this->startTime, &this->endTime, <=)) {
81 QPainter p(this);
82 QString tickFormat;
83 QColor tickColor = this->palette().color(QPalette::WindowText);
84 QFont font;
85 qreal lastTextX = 0, textX;
86 struct timeval tvFirstTick;
87 int tw, th;
88 int i;
89 struct timeval diff;
90 qreal asMsec, x;
91 qreal pxPerTick, pxPerLabel;
92 qreal tickStepMsec = 1;
93 qreal tickSubStepMsec = .1;
94 qreal startMsec, alignStartMsec;
95 qreal saneTimeSteps[] = {
96 1e-2, 1e-1, .25, .5, 1, 10, 25, 50, 1e2, 250, 500,
97 1e3, 5e3, 10e3, 30e3, 60e3, 300e3, 900e3, 1800e3, 36000e3};
98
99 qint64 minTicks = 10;
100 qint64 maxTicks = this->width() / 2;
101 qreal maxTickLen = this->height() / 3;
102
103 QFontMetrics metrics(font);
104
105 th = metrics.height();
106
107 timersub(&this->endTime, &this->startTime, &diff);
108
109 startMsec = static_cast<qreal>(startTime.tv_sec) * 1e3
110 + static_cast<qreal>(startTime.tv_usec) * 1e-3;
111
112 asMsec = static_cast<qreal>(diff.tv_sec) * 1e3
113 + static_cast<qreal>(diff.tv_usec) * 1e-3;
114
115 /*
116 * We are going to assume that this tickStep has room for 10
117 * additional subSteps.
118 */
119 for (
120 i = 0;
121 i < static_cast<int>(sizeof(saneTimeSteps) / sizeof(qreal));
122 ++i) {
123 tickStepMsec = saneTimeSteps[i];
124 tickSubStepMsec = .1 * tickStepMsec;
125 if (asMsec / tickSubStepMsec >= static_cast<qreal>(minTicks)
126 && asMsec / tickSubStepMsec < static_cast<qreal>(maxTicks))
127 break;
128 }
129
130 // Too few ticks
131 if (asMsec / tickSubStepMsec < static_cast<qreal>(minTicks)) {
132 tickSubStepMsec = asMsec / static_cast<qreal>(minTicks);
133 tickStepMsec = 10 * tickSubStepMsec;
134 } else if (asMsec / tickSubStepMsec > static_cast<qreal>(maxTicks)){

Callers

nothing calls this directly

Calls 4

widthMethod · 0.80
pushLocalTZMethod · 0.80
popTZMethod · 0.80
colorMethod · 0.45

Tested by

no test coverage detected