/** * @RDE_HEADER@ * passive container for view which only draws QPushButtons to save ressources * $Id$ * $HeadURL$ * $Author$ * Created by Mike Wille, SLSE, 2014-10-01 */ #include "PassiveEventContainer.h" #include "EventGraphic.h" #include "EventTools.h" #include #include #include #include #include #include #include #include namespace LtsTimelineClassic { PassiveEventContainer::PassiveEventContainer(bool ignoreKnownRanges, QObject *parent) : QObject(parent) , m_ignoreKnownRanges(ignoreKnownRanges) { } PassiveEventContainer::~PassiveEventContainer() { qDeleteAll(m_eventGraphicList); } EventGraphicList PassiveEventContainer::getEventGraphicList() const { return m_eventGraphicList; } void PassiveEventContainer::setEventList(const EventGraphicList &eventGraphicList) { qDeleteAll(m_eventGraphicList); m_eventGraphicList = eventGraphicList; // copy } void PassiveEventContainer::paint(QPainter *painter, const QStyleOptionViewItem &option, const LineMap &lineMap, const QVector &knownRanges) const { EventTools::s_test++; bool alternate = option.features.testFlag(QStyleOptionViewItem::ViewItemFeature::Alternate); const QColor bg = QColor(alternate ? QRgb(0xF6D8CE) : QRgb(0xFBF2EF)); QColor cachedBg(Qt::white); if (alternate) cachedBg = cachedBg.darker(110); painter->fillRect(option.rect, QBrush(bg)); int posX1 = option.rect.x(); int posX2 = option.rect.right(); int posY1 = option.rect.y(); int posY2 = option.rect.bottom(); int h = posY2 - posY1 + 1; painter->save(); painter->setClipping(true); // no drawing outside painter->setClipRect(option.rect.adjusted(0, 0, 1, 1)); int eventWidth = EventTools::eventWidth(); if (m_ignoreKnownRanges) { painter->fillRect(QRect(posX1, posY1, posX2 - posX1, h), cachedBg);///*option.backgroundBrush);//*/QBrush(QColor("white"))); } else // draw known ranges { for (const auto &range : knownRanges) { int rangeStart = EventTools::getEventPosition(range.start); int rangeEnd = EventTools::getEventPosition(range.end); //if (posX1 >= option.rect.x() && posX1 < option.rect.x() + option.rect.width() + 1) if (rangeEnd >= posX1 && rangeStart <= posX2) // do not draw if out of view painter->fillRect(QRect(rangeStart, posY1, rangeEnd - rangeStart + eventWidth + 1, h), cachedBg);///*option.backgroundBrush);//*/QBrush(QColor("white"))); } } // // draw live time as known (if live) // if (liveTime > 0) // { // int liveStart = EventTools::getEventPosition(liveTime); // if (liveStart <= posX2) // do not draw if out of view // painter->fillRect(QRect(liveStart, posY1, posX2 - liveTime, h), QBrush(QColor("white"))); // } painter->restore(); // draw date text lines first, can be overdrawn //for (int i = 0; i < lineMap.count(); i++) for (auto i = lineMap.constBegin(); i != lineMap.constEnd(); ++i) { int posX = i.key(); //lineMap.at(i); painter->setPen(QPen(QBrush(QGuiApplication::palette().shadow()), 1.0)); if (posX > option.rect.x() && posX < (option.rect.x() + option.rect.width())) // do not draw if out of view painter->drawLine(posX, posY1, posX, posY2); } //EventTools::setValues(min, max, scrollBarPosition, zoomFactor); //refreshEventList(); // NOTE: painter's viewport is the whole timeline (without the header part) // NOTE: option.rect is the line and section the events get draw on, only EventTools::drawEvents(painter, m_eventGraphicList, option.rect.y()); // qWarning() << "<<< viewport" << painter->viewport() << "rect" << option.rect; } } // namespace LtsTimelineClassic