KGantt

kganttdatetimetimelinedialog.cpp
1 /*
2  * SPDX-FileCopyrightText: 2020 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 
10 #include "kganttdatetimetimelinedialog.h"
11 #include "ui_kganttdatetimetimelinedialog.h"
12 #include "kganttdatetimetimeline.h"
13 #include "kganttpenstylecombobox.h"
14 
15 #include <QPixmap>
16 #include <QPainter>
17 #include <QPen>
18 #include <QColorDialog>
19 #include <QTime>
20 #include <QTimer>
21 #include <QMetaEnum>
22 #include <QAbstractItemModel>
23 
24 namespace KGantt {
25  class DateTimeTimeLineDialog::Private
26  {
27  public:
28  Private() : timeLine(nullptr) {}
29 
30  Ui::DateTimeTimeLineDialog ui;
31  DateTimeTimeLine *timeLine;
32  QColor penColor;
33  };
34 }
35 
36 using namespace KGantt;
37 
38 DateTimeTimeLineDialog::DateTimeTimeLineDialog(DateTimeTimeLine *timeLine, QWidget* parent)
39  : QDialog(parent)
40  , d( new Private())
41 {
42  d->timeLine = timeLine;
43  d->ui.setupUi(this);
44 
45  DateTimeTimeLine::Options opt = d->timeLine->options();
46  if (opt & DateTimeTimeLine::Foreground) {
47  d->ui.foreground->setChecked(true);
48  } else if (opt & DateTimeTimeLine::Background) {
49  d->ui.background->setChecked(true);
50  }
51  d->ui.useCustomPen->setCheckState((opt & DateTimeTimeLine::UseCustomPen) ? Qt::Checked : Qt::Unchecked);
52 
53  QPen pen = d->timeLine->pen(); // get standard if not set
54  d->ui.penWidth->setValue(pen.width());
55  d->ui.penStyle->setCurrentStyle(pen.style());
56  d->penColor = pen.color();
57 
58  d->ui.updateInterval->setTime(QTime::fromMSecsSinceStartOfDay(d->timeLine->interval()));
59  d->ui.dateTime->setDateTime(timeLine->dateTime());
60 
61  connect(d->ui.buttonBox, &QDialogButtonBox::accepted, this, &DateTimeTimeLineDialog::ok);
62  connect(d->ui.openColorDialog, &QAbstractButton::clicked, this, &DateTimeTimeLineDialog::openColorDialog);
63 
64  QTimer::singleShot(0, this, SLOT(updateColorButton())); // wait for correct button size
65 }
66 
67 DateTimeTimeLineDialog::~DateTimeTimeLineDialog()
68 {
69 }
70 
71 void DateTimeTimeLineDialog::ok()
72 {
74  if (d->ui.foreground->isChecked()) {
76  } else if (d->ui.background->isChecked()) {
78  }
79  if (d->ui.useCustomPen->checkState()) {
81  }
82  d->timeLine->setOptions(opt);
83  QPen pen;
84  pen.setWidth(d->ui.penWidth->value());
85  pen.setStyle(static_cast<Qt::PenStyle>(d->ui.penStyle->currentData().toInt()));
86  pen.setColor(d->penColor);
87  d->timeLine->setPen(pen);
88 
89  d->timeLine->setInterval(d->ui.updateInterval->time().msecsSinceStartOfDay());
90  d->timeLine->setDateTime(d->ui.dateTime->dateTime());
91 }
92 
93 void DateTimeTimeLineDialog::updateColorButton()
94 {
95  QSize size = d->ui.openColorDialog->size();
96  qInfo()<<Q_FUNC_INFO<<size<<d->penColor;
97  QPixmap px(size);
98  px.fill();
99  QPainter painter(&px);
100  painter.fillRect(0, 0, size.width(), size.height(), d->penColor);
101  d->ui.openColorDialog->setIcon(QIcon(px));
102 }
103 
104 void DateTimeTimeLineDialog::openColorDialog()
105 {
106  QColorDialog dlg;
107  if (dlg.exec() == QDialog::Accepted) {
108  d->penColor = dlg.selectedColor();
109  updateColorButton();
110  }
111 }
Qt::PenStyle style() const const
void setStyle(Qt::PenStyle style)
int width() const const
Display the timeline in the background.
virtual int exec()
QColor color() const const
void clicked(bool checked)
Paint the timeline using the pen set with setPen().
Global namespace.
void setColor(const QColor &color)
QColor selectedColor() const const
Display the timeline in the foreground.
int width() const const
void setWidth(int width)
int height() const const
QTime fromMSecsSinceStartOfDay(int msecs)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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.