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 #include "kganttdatetimetimeline.h" 0010 0011 #include <QApplication> 0012 #include <QDateTime> 0013 #include <QString> 0014 #include <QPalette> 0015 #include <QPen> 0016 #include <QTimer> 0017 #include <QDebug> 0018 0019 0020 0021 namespace KGantt { 0022 class Q_DECL_HIDDEN DateTimeTimeLine::Private 0023 { 0024 public: 0025 Private() : options(Foreground) {} 0026 0027 DateTimeTimeLine::Options options; 0028 QDateTime dateTime; 0029 QPen pen; 0030 QTimer timer; 0031 }; 0032 0033 } 0034 0035 using namespace KGantt; 0036 0037 0038 0039 0040 DateTimeTimeLine::DateTimeTimeLine() 0041 : _d( new Private()) 0042 { 0043 _d->options = {}; 0044 _d->pen = QPen(QApplication::palette().color(QPalette::Highlight), 0); 0045 connect(&_d->timer, SIGNAL(timeout()), this, SIGNAL(updated())); 0046 } 0047 0048 #define d d_func() 0049 0050 DateTimeTimeLine::Options DateTimeTimeLine::options() const 0051 { 0052 return d->options; 0053 } 0054 0055 0056 void DateTimeTimeLine::setOptions(DateTimeTimeLine::Options options) 0057 { 0058 d->options = options; 0059 if (options & Foreground) { 0060 d->options &= ~Background; 0061 } 0062 Q_EMIT updated(); 0063 } 0064 0065 0066 QDateTime DateTimeTimeLine::dateTime() const 0067 { 0068 return d->dateTime.isValid() ? d->dateTime : QDateTime::currentDateTime(); 0069 } 0070 0071 0072 void DateTimeTimeLine::setDateTime(const QDateTime &dt) 0073 { 0074 d->dateTime = dt; 0075 Q_EMIT updated(); 0076 } 0077 0078 0079 int DateTimeTimeLine::interval() const 0080 { 0081 return d->timer.interval(); 0082 } 0083 0084 0085 void DateTimeTimeLine::setInterval(int msecs) 0086 { 0087 d->timer.stop(); 0088 d->timer.setInterval(msecs); 0089 Q_EMIT updated(); 0090 if (msecs > 0) { 0091 d->timer.start(); 0092 } 0093 } 0094 0095 0096 QPen DateTimeTimeLine::pen() const 0097 { 0098 if (d->options & DateTimeTimeLine::UseCustomPen) { 0099 return d->pen; 0100 } 0101 return QPen(QApplication::palette().color(QPalette::Highlight), 0); 0102 } 0103 0104 0105 void DateTimeTimeLine::setPen(const QPen &pen) 0106 { 0107 d->pen = pen; 0108 Q_EMIT updated(); 0109 } 0110 0111 0112 QPen DateTimeTimeLine::customPen() const 0113 { 0114 return d->pen; 0115 } 0116 0117 0118 #undef d