File indexing completed on 2024-05-12 04:20:40
0001 /* 0002 * SPDX-FileCopyrightText: 2019 Dag Andersen <danders@get2net.dk> 0003 * 0004 * This file is part of the KGantt library. 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KGANTTDATETIMETIMELINE_H 0010 #define KGANTTDATETIMETIMELINE_H 0011 0012 #include "kganttglobal.h" 0013 0014 #include <QObject> 0015 0016 class QDateTime; 0017 0018 namespace KGantt { 0019 0020 /*!\class KGantt::DateTimeTimeLine 0021 * \ingroup KGantt 0022 * 0023 * This class implements a timeline. 0024 * 0025 * The timeline can optionally be shown in the Background or in the Foreground. 0026 * Default is Foreground. 0027 * 0028 * The pen can be set with setPen(), and must be activated by setting the option UseCustomPen. 0029 * 0030 * The datetime can be set using setDateTime(). 0031 * 0032 * The timeline can priodically moved to the current datetime 0033 * by setting the interval > 0 with setInterval(). 0034 * Setting a zero interval turns the periodically update off. 0035 * 0036 * The timeline is off by default. 0037 * 0038 * For example: 0039 * \code 0040 * // Show a red timeline in the foreground 0041 * timeLine->setOptions(Foreground | UseCustomPen); 0042 * timeLine->setPen(QPen(Qt:red)); 0043 * // Update the timeline every 5 seconds 0044 * timeLine->setInterval(5000); 0045 * \endcode 0046 */ 0047 class KGANTT_EXPORT DateTimeTimeLine : public QObject 0048 { 0049 Q_OBJECT 0050 KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( DateTimeTimeLine ) 0051 public: 0052 enum Option { 0053 Foreground = 1, ///< Display the timeline in the foreground. 0054 Background = 2, ///< Display the timeline in the background. 0055 UseCustomPen = 4, ///< Paint the timeline using the pen set with setPen(). 0056 MaxOptions = 0xFFFF 0057 }; 0058 Q_DECLARE_FLAGS(Options, Option) 0059 0060 /** 0061 * Create a timeline object. 0062 * 0063 * By default, no timeline is displayed. 0064 */ 0065 DateTimeTimeLine(); 0066 0067 /** 0068 * @return options 0069 */ 0070 DateTimeTimeLine::Options options() const; 0071 0072 /** 0073 * Set options to @p options. 0074 * If both Background and Foreground are set, Foreground is used. 0075 */ 0076 void setOptions(DateTimeTimeLine::Options options); 0077 0078 /** 0079 * @return the datetime 0080 * If the datetime is not valid, the current datetime is returned. 0081 */ 0082 QDateTime dateTime() const; 0083 0084 /** 0085 * Set datetime to @p dt. 0086 */ 0087 void setDateTime(const QDateTime &dt); 0088 0089 /** 0090 * @return the update interval in milliseconds 0091 */ 0092 int interval() const; 0093 0094 /** 0095 * Set timer interval to @p msecs milliseconds. 0096 * Setting a zero time disables the timer. 0097 */ 0098 void setInterval(int msec); 0099 0100 /** 0101 * @return the pen that will be used for rendering the timeline 0102 * If no pen has been set with setPen(), a default pen is returned. 0103 */ 0104 QPen pen() const; 0105 0106 /** 0107 * Set the custom pen to @p pen. 0108 */ 0109 void setPen(const QPen &pen); 0110 0111 /** 0112 * @return the pen that has been set with setPen() 0113 */ 0114 QPen customPen() const; 0115 0116 Q_SIGNALS: 0117 void updated(); 0118 }; 0119 } 0120 0121 Q_DECLARE_OPERATORS_FOR_FLAGS(KGantt::DateTimeTimeLine::Options) 0122 0123 #endif /* KGANTTDATETIMETIMELINE_H */ 0124