{
Q_UNUSED(widget);
if(option->levelOfDetail < 0.05) return;
QColor fillColor
= (option
->state
& QStyle::State_Selected) ? Bg.
dark(150) : Bg;
if (option
->state
& QStyle::State_MouseOver) fillColor = fillColor.light(125);
qreal width;
if (option
->state
& QStyle::State_MouseOver) { width = 1.0;
} else {
color = Fg;
width = 0.75;
}
painter
->setBrush
(QBrush(fillColor.
dark(option
->state
& QStyle::State_Sunken ?
120 : 100)));
painter
->setPen
(QPen(color, width
));
const QRectF exposed
= option
->exposedRect;
const qreal ex_left = exposed.left();
const qreal ex_right = exposed.right();
const qint64 start_tick = (qint64)ex_left/TICK_WIDTH;
const qint64 end_tick = (qint64)ex_right/TICK_WIDTH;
const qint64 n_tick = start_tick*TICK_WIDTH;
const qint64 n_tick_1 = n_tick - 1;
QTransform wt = painter->worldTransform();
wt.translate(n_tick_1, 0);
painter->setWorldTransform(wt);
for(qint64 i = 0; i <= end_tick-start_tick; i++) {
const qint64 time = i + start_tick + StartTime;
const qint64 time_mod_10 = time%10;
// Draw the tick mod 10 lines:
if(time%10 == 0) painter->drawLine(i*TICK_WIDTH, TICK_HEIGHT, i*TICK_WIDTH, -2*TICK_HEIGHT);
if(option->levelOfDetail < 0.5) return;
// Draw tick line every 10 ticks:
painter
->setPen
(QPen(color, width
));
const qint64 x = i*TICK_WIDTH;
const qint64 x_1 = (i*TICK_WIDTH) + 1;
// Draw full time every 10 ticks:
if(time%10 == 0) painter->drawText(pt, time_str);
// Draw time mod 10 (tick number):
painter->drawText(pt_1, time_mod_10_str);
}
}
void TimeRulerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
if(option->levelOfDetail < 0.05) return;
QColor fillColor = (option->state & QStyle::State_Selected) ? Bg.dark(150) : Bg;
if (option->state & QStyle::State_MouseOver)
fillColor = fillColor.light(125);
QColor color;
qreal width;
if (option->state & QStyle::State_MouseOver) {
color = QColor(Qt::yellow);
width = 1.0;
} else {
color = Fg;
width = 0.75;
}
painter->setFont(QApplication::font());
painter->setBrush(QBrush(fillColor.dark(option->state & QStyle::State_Sunken ? 120 : 100)));
painter->setPen(QPen(color, width));
const QRectF exposed = option->exposedRect;
const qreal ex_left = exposed.left();
const qreal ex_right = exposed.right();
const qint64 start_tick = (qint64)ex_left/TICK_WIDTH;
const qint64 end_tick = (qint64)ex_right/TICK_WIDTH;
const qint64 n_tick = start_tick*TICK_WIDTH;
const qint64 n_tick_1 = n_tick - 1;
QTransform wt = painter->worldTransform();
wt.translate(n_tick_1, 0);
painter->setWorldTransform(wt);
for(qint64 i = 0; i <= end_tick-start_tick; i++) {
const qint64 time = i + start_tick + StartTime;
const qint64 time_mod_10 = time%10;
// Draw the tick mod 10 lines:
if(time%10 == 0) painter->drawLine(i*TICK_WIDTH, TICK_HEIGHT, i*TICK_WIDTH, -2*TICK_HEIGHT);
if(option->levelOfDetail < 0.5) return;
// Draw tick line every 10 ticks:
painter->setPen(QPen(color, width));
const QString time_str = QString::number(time);
const QString time_mod_10_str = QString::number(time_mod_10);
const qint64 x = i*TICK_WIDTH;
const qint64 x_1 = (i*TICK_WIDTH) + 1;
const QPoint pt = QPoint(x , -1);
const QPoint pt_1 = QPoint(x_1, 11);
// Draw full time every 10 ticks:
if(time%10 == 0) painter->drawText(pt, time_str);
// Draw time mod 10 (tick number):
painter->drawText(pt_1, time_mod_10_str);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks