KGantt

kganttdatetimetimelinedialog.cpp
1/*
2 * SPDX-FileCopyrightText: 2020 Dag Andersen <danders@get2net.dk>
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
24namespace 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
36using namespace KGantt;
37
38DateTimeTimeLineDialog::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();
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
67DateTimeTimeLineDialog::~DateTimeTimeLineDialog()
68{
69}
70
71void 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
93void 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
104void DateTimeTimeLineDialog::openColorDialog()
105{
106 QColorDialog dlg;
107 if (dlg.exec() == QDialog::Accepted) {
108 d->penColor = dlg.selectedColor();
109 updateColorButton();
110 }
111}
@ UseCustomPen
Paint the timeline using the pen set with setPen().
@ Background
Display the timeline in the background.
@ Foreground
Display the timeline in the foreground.
void setOptions(DateTimeTimeLine::Options options)
Set options to options.
void setInterval(int msec)
Set timer interval to msecs milliseconds.
void setPen(const QPen &pen)
Set the custom pen to pen.
void setDateTime(const QDateTime &dt)
Set datetime to dt.
Global namespace.
void clicked(bool checked)
QColor selectedColor() const const
virtual int exec()
QColor color() const const
void setColor(const QColor &color)
void setStyle(Qt::PenStyle style)
void setWidth(int width)
Qt::PenStyle style() const const
int width() const const
PenStyle
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QTime fromMSecsSinceStartOfDay(int msecs)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.