- float durationRatio = duration / m_maxItemDuration;
- int intensity = std::min(255, (int)(durationRatio * 255.0f));
- // painter->setBrush(*(pItem->getBrush()));
- QColor color(intensity, 255-intensity, 0);
- painter->setBrush(QBrush(color));
- painter->setPen(color);
- QRectF rect;
- rect.setLeft(scalePositionHorizontally(pItem->getBeginTime()));
- rect.setTop(-height/2);
- rect.setWidth(scaleDurationHorizontally(duration));
- rect.setHeight(height);
- painter->drawRect(rect);
-
- // now draw all children
- int numChildren = pItem->childCount();
- for (int c = 0; c < numChildren; c++)
- {
- drawTimelineItem(painter, pItem->child(c), height-1);
- }
+ // only draw if the item will extend beyond the minimum offset
+ float leftOffset = scalePositionHorizontally(pItem->getBeginTime());
+ float scaledWidth = scaleDurationHorizontally(duration);
+ if (minimumOffset < leftOffset + scaledWidth)
+ {
+ float durationRatio = duration / m_maxItemDuration;
+ int intensity = std::min(255, (int)(durationRatio * 255.0f));
+ // painter->setBrush(*(pItem->getBrush()));
+ QColor color(intensity, 255-intensity, 0);
+ painter->setBrush(QBrush(color));
+ painter->setPen(color);
+
+ // Clamp the item so that it is 1 pixel wide.
+ // This is intentionally being done before updating the minimum offset
+ // so that small items after the current item will not be drawn
+ if (scaledWidth < 1)
+ {
+ scaledWidth = 1;
+ }
+
+ // update minimum offset
+ minimumOffset = leftOffset + scaledWidth;
+
+ // draw the colored box that represents this item
+ QRectF rect;
+ rect.setLeft(leftOffset);
+ rect.setTop(-height/2);
+ rect.setWidth(scaledWidth);
+ rect.setHeight(height);
+ painter->drawRect(rect);
+
+ // now draw all children
+ int numChildren = pItem->childCount();
+ for (int c = 0; c < numChildren; c++)
+ {
+ drawTimelineItem(painter, pItem->child(c), height-1, minimumOffset);
+ }
+ }