226 lines
5.1 KiB
C++
Executable File
226 lines
5.1 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* base class for received events
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Mike Wille, SLSE, 2014-10-01
|
|
*/
|
|
|
|
#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) // header says -1 (invalid / not an sub event)
|
|
, m_playerId(playerId)
|
|
, m_partyId(partyId)
|
|
, m_equipmentId(equipmentId)
|
|
, m_deleted(false)
|
|
, m_visible(true) // every event should be shown after creation
|
|
// absolute overkill: , m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Timeline.Event"))
|
|
{
|
|
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(); //data.shortName;
|
|
}
|
|
|
|
|
|
//qint64 Event::endTime() const
|
|
//{
|
|
// if (m_endTime == -1) // infinite (open end)
|
|
// return -1; // model will take current (exercise) time then
|
|
|
|
// if (m_endTime == 0) // not specified - event ends when it starts
|
|
// return m_startTime;
|
|
|
|
// return m_endTime; // in any other case
|
|
//}
|
|
|
|
|
|
void Event::setEndT(qint64 newEnd)
|
|
{
|
|
m_endTime = newEnd;
|
|
|
|
checkDuration();
|
|
}
|
|
|
|
|
|
bool Event::checkDuration()
|
|
{
|
|
// maximum 4 weeks duration (because of timeline's limited 'view distance')
|
|
|
|
|
|
// Deactivated for now..
|
|
//#define MAX_DURATION (4 * 7 * 24 * 60 * 60)
|
|
|
|
// int _duration = duration();
|
|
|
|
// if (_duration > MAX_DURATION)
|
|
// {
|
|
// WARNING_LOG(m_logger) << "Event::checkDuration: event (unique# " << m_uniqueId << ") duration too high! max: " << MAX_DURATION << " - is: " << _duration;
|
|
// return false;
|
|
// }
|
|
|
|
// if (_duration < -1 /* NOTE: -1 is a valid duration */)
|
|
// {
|
|
// WARNING_LOG(m_logger) << "Event::checkDuration: event (unique# " << m_uniqueId << ") duration too low! min: -1 - is: " << _duration;
|
|
// return false;
|
|
// }
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
qint64 Event::duration(bool ignoreLiveEvents) const
|
|
{
|
|
if (m_endTime > m_startTime) // valid!
|
|
{
|
|
if (m_duration == -1)
|
|
m_duration = m_endTime - m_startTime;
|
|
|
|
return m_duration;
|
|
}
|
|
|
|
if (m_endTime < 0 && !ignoreLiveEvents) // valid - but INFINITE (give back seconds from start until now!)
|
|
{
|
|
qint64 currentTime = (m_session != nullptr) ? m_session->partitionTime() : time(nullptr) /*bad fall-back*/;
|
|
qint64 duration = currentTime - m_startTime;
|
|
|
|
return duration;
|
|
}
|
|
|
|
return 0; // m_endTime == 0 (no duration / no end time) - endTime < startTime (error - 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();
|
|
|
|
// rectangle
|
|
painter->drawRect(rect);
|
|
|
|
// seperators
|
|
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()++; // reference!
|
|
ellipsePos.ry()++; // reference!
|
|
|
|
painter->drawEllipse(ellipsePos, rect.width() / 2, rect.height() / 2);
|
|
}
|
|
|
|
void Event::drawCustomEventGraphicRect(QPainter *painter, const QRect &rect)
|
|
{
|
|
painter->drawRect(rect);
|
|
}
|
|
|
|
//warning looks terrible on events with duration... qt bug?
|
|
void Event::drawCustomEventGraphicRoundedRect(QPainter *painter, const QRect &rect)
|
|
{
|
|
painter->drawRoundedRect(rect, 50, 50, Qt::RelativeSize);
|
|
}
|
|
|
|
}
|