File indexing completed on 2024-05-12 15:54:24
0001 /* 0002 * Copyright (C) 2019 Dag Andersen <danders@get2net.dk> 0003 * 0004 * This file is part of the KGantt library. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 0018 */ 0019 0020 #ifndef KGANTTDATETIMETIMELINE_H 0021 #define KGANTTDATETIMETIMELINE_H 0022 0023 #include "kganttglobal.h" 0024 0025 #include <QObject> 0026 0027 class QDateTime; 0028 0029 namespace KGantt { 0030 0031 /*!\class KGantt::DateTimeTimeLine 0032 * \ingroup KGantt 0033 * 0034 * This class implements a timeline. 0035 * 0036 * The timeline can optionally be shown in the Background or in the Foreground. 0037 * Default is Foreground. 0038 * 0039 * The pen can be set with setPen(), and must be activated by setting the option UseCustomPen. 0040 * 0041 * The datetime can be set using setDateTime(). 0042 * 0043 * The timeline can priodically moved to the current datetime 0044 * by setting the interval > 0 with setInterval(). 0045 * Setting a zero interval turns the periodically update off. 0046 * 0047 * The timeline is off by default. 0048 * 0049 * For example: 0050 * \code 0051 * // Show a red timeline in the foreground 0052 * timeLine->setOptions(Foreground | UseCustomPen); 0053 * timeLine->setPen(QPen(Qt:red)); 0054 * // Update the timeline every 5 seconds 0055 * timeLine->setInterval(5000); 0056 * \endcode 0057 */ 0058 class KGANTT_EXPORT DateTimeTimeLine : public QObject 0059 { 0060 Q_OBJECT 0061 KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( DateTimeTimeLine ) 0062 public: 0063 enum Option { 0064 Foreground = 1, ///< Display the timeline in the foreground. 0065 Background = 2, ///< Display the timeline in the background. 0066 UseCustomPen = 4, ///< Paint the timeline using the pen set with setPen(). 0067 MaxOptions = 0xFFFF 0068 }; 0069 Q_DECLARE_FLAGS(Options, Option) 0070 0071 /** 0072 * Create a timeline object. 0073 * 0074 * By default, no timeline is displayed. 0075 */ 0076 DateTimeTimeLine(); 0077 0078 /** 0079 * @return options 0080 */ 0081 DateTimeTimeLine::Options options() const; 0082 0083 /** 0084 * Set options to @p options. 0085 * If both Background and Foreground are set, Foreground is used. 0086 */ 0087 void setOptions(DateTimeTimeLine::Options options); 0088 0089 /** 0090 * @return the datetime 0091 * If the datetime is not valid, the current datetime is returned. 0092 */ 0093 QDateTime dateTime() const; 0094 0095 /** 0096 * Set datetime to @p dt. 0097 */ 0098 void setDateTime(const QDateTime &dt); 0099 0100 /** 0101 * @return the update interval in milliseconds 0102 */ 0103 int interval() const; 0104 0105 /** 0106 * Set timer interval to @p msecs milliseconds. 0107 * Setting a zero time disables the timer. 0108 */ 0109 void setInterval(int msec); 0110 0111 /** 0112 * @return the pen that will be used for rendering the timeline 0113 * If no pen has been set with setPen(), a default pen is returned. 0114 */ 0115 QPen pen() const; 0116 0117 /** 0118 * Set the custom pen to @p pen. 0119 */ 0120 void setPen(const QPen &pen); 0121 0122 /** 0123 * @return the pen that has been set with setPen() 0124 */ 0125 QPen customPen() const; 0126 0127 Q_SIGNALS: 0128 void updated(); 0129 }; 0130 } 0131 0132 Q_DECLARE_OPERATORS_FOR_FLAGS(KGantt::DateTimeTimeLine::Options) 0133 0134 #endif /* KGANTTDATETIMETIMELINE_H */ 0135