Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+155
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* replaces the original header of the view - offers a user-movable position mark
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Mike Wille, SLSE, 2014-10-01
|
||||
*/
|
||||
|
||||
#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()) // has to be reset @ slotSectionResized
|
||||
, m_liveTime(0)
|
||||
{
|
||||
setSectionsClickable(true);
|
||||
|
||||
setStretchLastSection(true); // so that the whole viewport is filled with the last section (Event Section)
|
||||
|
||||
connect(this, &TimelineHeaderView::sectionResized,
|
||||
this, &TimelineHeaderView::slotSectionResized);
|
||||
// now wait for slotSectionResized (which is definitly going to be called)
|
||||
}
|
||||
|
||||
#define GET_LOGGER NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Timeline.HeaderView")
|
||||
|
||||
void TimelineHeaderView::setPosMarkTime(qint64 time)
|
||||
{
|
||||
m_posMarkTime = time;
|
||||
refreshData(); // new value, now recalc and show on view
|
||||
}
|
||||
|
||||
void TimelineHeaderView::setLiveTime(qint64 time)
|
||||
{
|
||||
m_liveTime = time;
|
||||
refreshData(); // new value, now recalc and show on view
|
||||
}
|
||||
|
||||
void TimelineHeaderView::setPosMarkPos()
|
||||
{
|
||||
//QRect sectionRect(0, 0, sectionSize(1), 0);
|
||||
|
||||
if (m_posMarkTime > 0) // must be a valid time
|
||||
{
|
||||
int posMarkPos = EventTools::getEventPosition(m_posMarkTime);//, sectionRect);
|
||||
emit signalSetPosMarkPos(posMarkPos);
|
||||
refreshData();
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineHeaderView::refreshData()
|
||||
{
|
||||
if (EventTools::getTimelineMin() > 0 && EventTools::getTimelineMax() > 1)
|
||||
{
|
||||
updateSection(1);
|
||||
updateSection(0); // because this section is often drawn on when position is very low
|
||||
}
|
||||
}
|
||||
|
||||
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(); // otherwise we can not draw.... dunno what paintSection does wrong
|
||||
QHeaderView::paintSection(painter, rect, logicalIndex);
|
||||
painter->restore(); // s.a.
|
||||
|
||||
// draw posMark
|
||||
if (logicalIndex == 1)
|
||||
{
|
||||
int h = (rect.height() / 3);
|
||||
int y = rect.height() - h;
|
||||
int w = h;
|
||||
|
||||
//QRect sectionRect(sectionPosition(1), 0, sectionSize(1), 0);
|
||||
|
||||
painter->save();
|
||||
painter->setClipping(true);
|
||||
|
||||
if (m_posMarkTime != 0) // if user changed posMark to a valid value
|
||||
{
|
||||
double posMark = EventTools::getEventPosition(m_posMarkTime);//, sectionRect);
|
||||
int x = /*sectionPosition(1)*/ + 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)); // p1
|
||||
pol.append(QPoint(x + 0, y + h)); // p2
|
||||
pol.append(QPoint(x + (w / 2), y + 0)); // p3
|
||||
pol.append(QPoint(x + (-w / 2), y + 0)); // p1
|
||||
|
||||
QPainterPath path;
|
||||
path.moveTo(x, y);
|
||||
path.addPolygon(pol);
|
||||
|
||||
painter->drawPath(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (m_liveTime != 0)
|
||||
{
|
||||
int posLive = EventTools::getEventPosition(m_liveTime);//, sectionRect);
|
||||
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)); // p1
|
||||
pol.append(QPoint(x + 0, y + h)); // p2
|
||||
pol.append(QPoint(x + (w / 2), y + 0)); // p3
|
||||
pol.append(QPoint(x + (-w / 2), y + 0)); // p1
|
||||
|
||||
QPainterPath path;
|
||||
path.moveTo(x, y);
|
||||
path.addPolygon(pol);
|
||||
|
||||
painter->drawPath(path);
|
||||
}
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user