KGantt

kganttdatetimetimeline.cpp
1 /*
2  * SPDX-FileCopyrightText: 2019 Dag Andersen <[email protected]>
3  *
4  * This file is part of the KGantt library.
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #include "kganttdatetimetimeline.h"
10 
11 #include <QApplication>
12 #include <QDateTime>
13 #include <QString>
14 #include <QPalette>
15 #include <QPen>
16 #include <QTimer>
17 #include <QDebug>
18 
19 
20 
21 namespace KGantt {
22  class Q_DECL_HIDDEN DateTimeTimeLine::Private
23  {
24  public:
25  Private() : options(Foreground) {}
26 
28  QDateTime dateTime;
29  QPen pen;
30  QTimer timer;
31  };
32 
33 }
34 
35 using namespace KGantt;
36 
37 
38 
39 
41  : _d( new Private())
42 {
43  _d->options = {};
44  _d->pen = QPen(QApplication::palette().color(QPalette::Highlight), 0);
45  connect(&_d->timer, SIGNAL(timeout()), this, SIGNAL(updated()));
46 }
47 
48 #define d d_func()
49 
51 {
52  return d->options;
53 }
54 
55 
57 {
58  d->options = options;
59  if (options & Foreground) {
60  d->options &= ~Background;
61  }
62  Q_EMIT updated();
63 }
64 
65 
67 {
68  return d->dateTime.isValid() ? d->dateTime : QDateTime::currentDateTime();
69 }
70 
71 
73 {
74  d->dateTime = dt;
75  Q_EMIT updated();
76 }
77 
78 
80 {
81  return d->timer.interval();
82 }
83 
84 
86 {
87  d->timer.stop();
88  d->timer.setInterval(msecs);
89  Q_EMIT updated();
90  if (msecs > 0) {
91  d->timer.start();
92  }
93 }
94 
95 
97 {
98  if (d->options & DateTimeTimeLine::UseCustomPen) {
99  return d->pen;
100  }
101  return QPen(QApplication::palette().color(QPalette::Highlight), 0);
102 }
103 
104 
106 {
107  d->pen = pen;
108  Q_EMIT updated();
109 }
110 
111 
113 {
114  return d->pen;
115 }
116 
117 
118 #undef d
void setInterval(int msec)
Set timer interval to msecs milliseconds.
Display the timeline in the background.
void setPen(const QPen &pen)
Set the custom pen to pen.
QPalette palette()
Paint the timeline using the pen set with setPen().
Global namespace.
DateTimeTimeLine::Options options() const
Display the timeline in the foreground.
QDateTime currentDateTime()
DateTimeTimeLine()
Create a timeline object.
void setDateTime(const QDateTime &dt)
Set datetime to dt.
void setOptions(DateTimeTimeLine::Options options)
Set options to options.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 22:32:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.