Files
qt6-migration-pipeline/Lts/Common/LtsTimelineClassic/TimelineHeaderView.cpp
T

150 lines
3.1 KiB
C++
Executable File

#include "TimelineWidget.h"
#include "TimelineHeaderView.h"
#include <QPainter>
#include <QPainterPath>
#include <QPen>
#include <QPoint>
#include <QRect>
#include <QGuiApplication>
namespace LtsTimelineClassic
{
TimelineHeaderView::TimelineHeaderView(QWidget *parent)
: QHeaderView(Qt::Horizontal, parent)
, m_posMarkTime(0)
, m_paintingRange(rect())
, m_liveTime(0)
{
setSectionsClickable(true);
setStretchLastSection(true);
connect(this, &TimelineHeaderView::sectionResized,
this, &TimelineHeaderView::slotSectionResized);
}
#define GET_LOGGER NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Timeline.HeaderView")
void TimelineHeaderView::setPosMarkTime(qint64 time)
{
m_posMarkTime = time;
refreshData();
}
void TimelineHeaderView::setLiveTime(qint64 time)
{
m_liveTime = time;
refreshData();
}
void TimelineHeaderView::setPosMarkPos()
{
if (m_posMarkTime > 0)
{
int posMarkPos = EventTools::getEventPosition(m_posMarkTime);
emit signalSetPosMarkPos(posMarkPos);
refreshData();
}
}
void TimelineHeaderView::refreshData()
{
if (EventTools::getTimelineMin() > 0 && EventTools::getTimelineMax() > 1)
{
updateSection(1);
updateSection(0);
}
}
void TimelineHeaderView::slotSectionResized(int logicalIndex, int oldSize, int newSize)
{
(void)oldSize;
if (logicalIndex == 1)
m_paintingRange = QRect(0, 0, newSize, height());
refreshData();
}
void TimelineHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
{
painter->save();
QHeaderView::paintSection(painter, rect, logicalIndex);
painter->restore();
if (logicalIndex == 1)
{
int h = (rect.height() / 3);
int y = rect.height() - h;
int w = h;
painter->save();
painter->setClipping(true);
if (m_posMarkTime != 0)
{
double posMark = EventTools::getEventPosition(m_posMarkTime);
int x = + posMark;
if (x >= sectionPosition(1))
{
painter->setPen(QPen(QGuiApplication::palette().color(QPalette::Inactive, QPalette::Highlight)));
painter->setBrush(QGuiApplication::palette().highlight());
QPolygon pol;
pol.append(QPoint(x + (-w / 2), y + 0));
pol.append(QPoint(x + 0, y + h));
pol.append(QPoint(x + (w / 2), y + 0));
pol.append(QPoint(x + (-w / 2), y + 0));
QPainterPath path;
path.moveTo(x, y);
path.addPolygon(pol);
painter->drawPath(path);
}
}
if (m_liveTime != 0)
{
int posLive = EventTools::getEventPosition(m_liveTime);
int x = posLive;
if (x >= sectionPosition(1))
{
painter->setPen(QPen(QColor("green")));
painter->setBrush(QBrush(QColor("green")));
QPolygon pol;
pol.append(QPoint(x + (-w / 2), y + 0));
pol.append(QPoint(x + 0, y + h));
pol.append(QPoint(x + (w / 2), y + 0));
pol.append(QPoint(x + (-w / 2), y + 0));
QPainterPath path;
path.moveTo(x, y);
path.addPolygon(pol);
painter->drawPath(path);
}
}
painter->restore();
}
}
}