Files
qt5-legatus-legacy/Lts/Common/LtsTimelineClassic/EventTools.h
T
2026-08-13 18:33:10 +02:00

214 lines
6.2 KiB
C++
Executable File

/**
* @RDE_HEADER@
* calculates, converts, and draws events by entering time or pixel position as value
* $Id$
* $HeadURL$
* $Author$
* Created by Mike Wille, SLSE, 2014-10-01
*/
#pragma once
#include "EventList.h"
#include <LtsTimelineClassic/ltstimelineclassic_export.h>
#include <QRect>
#include <time.h>
class QPainter;
namespace LtsTimelineClassic
{
/**
* @brief calculates, converts, and draws events by entering time or pixel position as value
*/
class LTSTIMELINECLASSIC_EXPORT EventTools
{
static const int s_EventTopPadding = 2;
static const int s_EventHeightPadding = -6;
static const int s_ButtonTopPadding = s_EventTopPadding + 2;
static const int s_ButtonHeightPadding = s_EventHeightPadding + 7;
public:
static int s_test;
static qint64 fromMsecsToSeconds(qint64 msecs)
{
return (msecs / 1000);
}
static qint64 fromSecondsToMsecs(qint64 minutes)
{
return (minutes * 1000);
}
static qint64 getBlockSizeTime(qint64 duration = 0);
/**
* @brief creates this class with all needed values and calculates all values to their relative values (relative)
* @param max last event in timeline in seconds since epoch
* @param min first event in timeline in seconds since epoch
* @param sbPos position of scrollbar in seconds since epoch
* @param zoomFactor percent points of how much to zoom into the view
* @param paintingRange boundaries of drawn on surface
*/
static void setValues(const qint64 min, const qint64 max, const qint64 sbPos, const qint64 zoomFactor);
/**
* @brief calculates all values relating to painting and measuring
* @param paintingRect rectangle to calculate with
*/
//static void setPaintingRect(const QRect &paintingRect);
static void setSection(const int x, const int length);
/**
* @brief returns true if EventTools has been correctly initialized with min > 0 & max > 1
* @return
*/
static bool isValid();
/**
* @brief tells if event tools has been created in relative mode
* @return true if event tools has been created in relative mode
*/
static bool isRelative();
/**
* @brief converts time/ seconds sicne epoch to pixel position by considering the classes values
* @param eventTime seconds since epoch
*/
static int getEventPosition(qint64 eventTime);
/**
* @brief returns minimum timeline position by respecting scrollbar position and zoom factor
* @return adjusted minimum timeline position
*/
static qint64 getAdjustedMin();
/**
* @brief returns maximum timeline position by respecting scrollbar position and zoom factor
* @return adjusted maximum timeline position
*/
static qint64 getAdjustedMax();
/**
* @brief returns minimum timeline position
* @return minimum timeline position
*/
static qint64 getTimelineMin();
/**
* @brief returns maximum timeline position
* @return maximum timeline position
*/
static qint64 getTimelineMax();
static qint64 getScrollbarPosition();
static void recalcBlockSizeTime();
/**
* @brief converts pixel position to time/ seconds since epoch by considering the classes values from minimum
* @param eventPosition pixel position
* @return seconds since epoch
*/
static qint64 getEventTime(double eventPosition);//, const QRect &paintingRect = QRect());
/**
* @brief draws all events from event list on the given painter by considering the classes values
* @param painter surface (container) on which the events have to be drawn
* @param eventList list of events to draw
* @param rect boundaries to draw in
*/
static void drawEvents(QPainter *painter, const EventGraphicList &eventGraphicList, const int verticalPosition);
/**
* @brief draws an line at the position of all mark events
* @param painter surface (container) on which the line have to be drawn
* @param eventList list of mark lines to draw
* @param viewHeight
* @param paintingRect
*/
static void drawMarkLines(QPainter *painter, const EventList &eventList, int viewHeight);//, const QRect &paintingRect = QRect());
/**
* @brief sets all events widgets geometry to rect on parent by considering the classes values
* @param eventList list of events to update
* @param rect boundaries to update geometries in
* @param parent parent to set widgets on
*/
//static void setGeometryForEvents(const EventGraphicList &eventGraphicList, const QRect &rect, QWidget* parent);
/**
* @brief calculates size of visual event by considering the classes values
* @param event event to calculate size
* @param paintingRect boundaries to respect
* @return rectangle of the event
*/
//static QRect getEventGraphicRect(ActiveEvent* event, const QRect& paintingRect = QRect());
/**
* @brief calculates the event graphics width
* @param x width to modify
* @return modified width
*/
static inline int eventWidth() // by height
{
return s_sectionHeight / 2;
}
/**
* @brief calculates the event end position respecting the graphicsWidth
* @param position old position
* @param graphicsWidth graphics width
* @return adjusted event position
*/
static inline int GetEndPos(int position, int graphicsWidth)
{
// -1 for cosmetical issues
return position - graphicsWidth - 1;
}
static inline float zoomFactor() { return s_zoomFactor; }
static inline void setSectionHeight(int sectionHeight) { s_sectionHeight = sectionHeight; }
static bool s_inUse;
private:
static qint64 _getBlockSizeTime();
/*
* @brief creates this class with all needed values without calculating all values (absolute)
* @param max last event in timeline in seconds since epoch
* @param min first event in timeline in seconds since epoch
* @param paintingRange boundaries of drawn on surface
*
static void setValues(const qint64 min, const qint64 max);*/
static qint64 s_minAdjusted;
static qint64 s_maxAdjusted;
static qint64 s_minTimeline;
static qint64 s_maxTimeline;
static qint64 s_sbPos;
static qint64 s_zoomFactor;
static int s_paintMin;
static int s_paintDiff;
static bool s_isValid; // check whether class has valid values (min > 0 && max > 2)
static int s_sectionHeight;
static qint64 s_blockSizeTime;
public:
static qint64 s_diff;
};
} // namespace LtsTimelineClassic