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