220 lines
3.6 KiB
C++
Executable File
220 lines
3.6 KiB
C++
Executable File
|
|
|
|
|
|
#include "Event.h"
|
|
|
|
#include <LtsSession/lts_session.h>
|
|
|
|
#include <QRect>
|
|
#include <QPainter>
|
|
#include <QPainterPath>
|
|
|
|
#include <time.h>
|
|
|
|
namespace LtsTimelineClassic
|
|
{
|
|
Event::Event(int uniqueId, int typeId, qint64 startTime,
|
|
qint64 endTime, int playerId, int partyId, int equipmentId, const QStringList &path,
|
|
const EventPaintFunc &paintFunc, const QColor &paintColor, const QJsonObject &detailData, int subEventId,
|
|
const LtsUtils::QPoint3D &pos, LtsSession::LtsSession *session)
|
|
: m_path(path)
|
|
, m_detailData(detailData)
|
|
, m_position(pos)
|
|
, m_paintFunc(paintFunc)
|
|
, m_session(session)
|
|
, m_eventColor(paintColor)
|
|
, m_startTime(startTime)
|
|
, m_endTime(endTime)
|
|
, m_uniqueId(uniqueId)
|
|
, m_typeId(typeId)
|
|
, m_subEventId(subEventId)
|
|
, m_playerId(playerId)
|
|
, m_partyId(partyId)
|
|
, m_equipmentId(equipmentId)
|
|
, m_deleted(false)
|
|
, m_visible(true)
|
|
|
|
{
|
|
checkDuration();
|
|
}
|
|
|
|
void Event::setVisible(bool visibility)
|
|
{
|
|
if (visibility)
|
|
show();
|
|
else
|
|
hide();
|
|
}
|
|
|
|
|
|
void Event::hide()
|
|
{
|
|
this->m_visible = false;
|
|
}
|
|
|
|
|
|
void Event::show()
|
|
{
|
|
this->m_visible = true;
|
|
}
|
|
|
|
QString Event::getShortActuator() const
|
|
{
|
|
return m_path.isEmpty() ? QString() : m_path.last();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Event::setEndT(qint64 newEnd)
|
|
{
|
|
m_endTime = newEnd;
|
|
|
|
checkDuration();
|
|
}
|
|
|
|
|
|
bool Event::checkDuration()
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
qint64 Event::duration(bool ignoreLiveEvents) const
|
|
{
|
|
if (m_endTime > m_startTime)
|
|
{
|
|
if (m_duration == -1)
|
|
m_duration = m_endTime - m_startTime;
|
|
|
|
return m_duration;
|
|
}
|
|
|
|
if (m_endTime < 0 && !ignoreLiveEvents)
|
|
{
|
|
qint64 currentTime = (m_session != nullptr) ? m_session->partitionTime() : time(nullptr) ;
|
|
qint64 duration = currentTime - m_startTime;
|
|
|
|
return duration;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
void Event::drawMultipleEventGraphic(QPainter *painter, const QRect &rect)
|
|
{
|
|
painter->save();
|
|
painter->setBrush(Qt::white);
|
|
|
|
int x = rect.x();
|
|
int y = rect.y();
|
|
int h = rect.height();
|
|
int w = rect.width();
|
|
|
|
|
|
painter->drawRect(rect);
|
|
|
|
|
|
int s1 = y + h - (h * 0.4);
|
|
int s2 = y + h - (h * 0.2);
|
|
|
|
painter->drawLine(QPoint(x, s1),
|
|
QPoint(x + w, s1));
|
|
painter->drawLine(QPoint(x, s2),
|
|
QPoint(x + w, s2));
|
|
|
|
painter->restore();
|
|
}
|
|
|
|
void Event::drawCustomEventGraphicTriangle(QPainter *painter, const QRect &rect)
|
|
{
|
|
int x = rect.x();
|
|
int y = rect.y();
|
|
int h = rect.height();
|
|
int w = rect.width();
|
|
|
|
QPolygon pol;
|
|
pol.append(QPoint(x + 0, y + h));
|
|
pol.append(QPoint(x + (w / 2), y + 0));
|
|
pol.append(QPoint(x + w, y + h));
|
|
pol.append(QPoint(x + 0, y + h));
|
|
|
|
QPainterPath path;
|
|
path.moveTo(x, y);
|
|
path.addPolygon(pol);
|
|
|
|
painter->drawPath(path);
|
|
}
|
|
|
|
void Event::drawCustomEventGraphicInvertTriangle(QPainter *painter, const QRect &rect)
|
|
{
|
|
int x = rect.x();
|
|
int y = rect.y();
|
|
int h = rect.height();
|
|
int w = rect.width();
|
|
|
|
QPolygon pol;
|
|
pol.append(QPoint( x + 0 , y + 0));
|
|
pol.append(QPoint( x+ w , y + 0));
|
|
pol.append(QPoint(x + ( w / 2 ), y + h));
|
|
pol.append(QPoint( x + 0 , y + 0));
|
|
|
|
QPainterPath path;
|
|
path.moveTo(x, y);
|
|
path.addPolygon(pol);
|
|
|
|
painter->drawPath(path);
|
|
}
|
|
void Event::drawCustomEventGraphicEllipse(QPainter *painter, const QRect &rect)
|
|
{
|
|
QPoint ellipsePos = rect.center();
|
|
ellipsePos.rx()++;
|
|
ellipsePos.ry()++;
|
|
|
|
painter->drawEllipse(ellipsePos, rect.width() / 2, rect.height() / 2);
|
|
}
|
|
|
|
void Event::drawCustomEventGraphicRect(QPainter *painter, const QRect &rect)
|
|
{
|
|
painter->drawRect(rect);
|
|
}
|
|
|
|
|
|
void Event::drawCustomEventGraphicRoundedRect(QPainter *painter, const QRect &rect)
|
|
{
|
|
painter->drawRoundedRect(rect, 50, 50, Qt::RelativeSize);
|
|
}
|
|
|
|
}
|