Incidenceeditor

incidencecompletionpriority.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
3 SPDX-FileContributor: Kevin Krammer <krake@kdab.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "incidencecompletionpriority.h"
9using namespace Qt::Literals::StringLiterals;
10
11#include "ui_dialogdesktop.h"
12
13#include <KCalendarCore/Todo>
14
15using namespace IncidenceEditorNG;
16
17class IncidenceEditorNG::IncidenceCompletionPriorityPrivate
18{
19 IncidenceCompletionPriority *const q;
20
21public:
22 explicit IncidenceCompletionPriorityPrivate(IncidenceCompletionPriority *parent)
23 : q(parent)
24 {
25 }
26
27public:
28 Ui::EventOrTodoDesktop *mUi = nullptr;
29 int mOrigPercentCompleted = -1;
30
31public: // slots
32 void sliderValueChanged(int);
33};
34
35void IncidenceCompletionPriorityPrivate::sliderValueChanged(int value)
36{
37 if (q->sender() == mUi->mCompletionSlider) {
38 mOrigPercentCompleted = -1;
39 }
40
41 mUi->mCompletedLabel->setText(QStringLiteral("%1%").arg(value));
43}
44
45IncidenceCompletionPriority::IncidenceCompletionPriority(Ui::EventOrTodoDesktop *ui)
47 , d(new IncidenceCompletionPriorityPrivate(this))
48{
49 Q_ASSERT(ui != nullptr);
50 setObjectName("IncidenceCompletionPriority"_L1);
51
52 d->mUi = ui;
53
54 d->sliderValueChanged(d->mUi->mCompletionSlider->value());
55 d->mUi->mCompletionPriorityWidget->hide();
56 d->mUi->mTaskLabel->hide();
57 const QFontMetrics metrics(d->mUi->mCompletedLabel->font());
58 d->mUi->mCompletedLabel->setMinimumWidth(metrics.boundingRect(QStringLiteral("100%")).width());
59 d->mUi->mTaskSeparator->hide();
60
61 connect(d->mUi->mCompletionSlider, &QSlider::valueChanged, this, [this](int val) {
62 d->sliderValueChanged(val);
63 });
64 connect(d->mUi->mPriorityCombo, &QComboBox::currentIndexChanged, this, &IncidenceCompletionPriority::checkDirtyStatus);
65}
66
67IncidenceCompletionPriority::~IncidenceCompletionPriority() = default;
68
69void IncidenceCompletionPriority::load(const KCalendarCore::Incidence::Ptr &incidence)
70{
71 mLoadedIncidence = incidence;
72
73 // TODO priority might be valid for other incidence types as well
74 // only for Todos
76 if (todo == nullptr) {
77 mWasDirty = false;
78 return;
79 }
80
81 d->mUi->mCompletionPriorityWidget->show();
82 d->mUi->mTaskLabel->show();
83 d->mUi->mTaskSeparator->show();
84
85 d->mOrigPercentCompleted = todo->percentComplete();
86 d->mUi->mCompletionSlider->blockSignals(true);
87 d->mUi->mCompletionSlider->setValue(todo->percentComplete());
88 d->sliderValueChanged(d->mUi->mCompletionSlider->value());
89 d->mUi->mCompletionSlider->blockSignals(false);
90
91 d->mUi->mPriorityCombo->blockSignals(true);
92 d->mUi->mPriorityCombo->setCurrentIndex(todo->priority());
93 d->mUi->mPriorityCombo->blockSignals(false);
94
95 mWasDirty = false;
96}
97
98void IncidenceCompletionPriority::save(const KCalendarCore::Incidence::Ptr &incidence)
99{
100 // TODO priority might be valid for other incidence types as well
101 // only for Todos
103 if (todo == nullptr) {
104 return;
105 }
106
107 // we only have multiples of ten on our combo. If the combo did not change its value,
108 // see if we have an original value to restore
109 if (d->mOrigPercentCompleted != -1) {
110 todo->setPercentComplete(d->mOrigPercentCompleted);
111 } else {
112 const int pct = d->mUi->mCompletionSlider->value();
113 if (pct >= 100) {
114 todo->setCompleted(QDateTime::currentDateTimeUtc());
116 } else {
117 todo->setCompleted(false);
119 }
120 todo->setPercentComplete(pct);
121 }
122 todo->setPriority(d->mUi->mPriorityCombo->currentIndex());
123}
124
125bool IncidenceCompletionPriority::isDirty() const
126{
128
129 if (!todo) {
130 return false;
131 }
132
133 if (d->mUi->mCompletionSlider->value() != todo->percentComplete()) {
134 return true;
135 }
136
137 if (d->mUi->mPriorityCombo->currentIndex() != todo->priority()) {
138 return true;
139 }
140
141 return false;
142}
143
144#include "moc_incidencecompletionpriority.cpp"
KCal Incidences are complicated objects.
void checkDirtyStatus()
Checks if the dirty status has changed until last check and emits the dirtyStatusChanged signal if ne...
QSharedPointer< IncidenceT > incidence() const
Convenience method to get a pointer for a specific const Incidence Type.
AKONADI_CALENDAR_EXPORT KCalendarCore::Todo::Ptr todo(const Akonadi::Item &item)
void valueChanged(int value)
void currentIndexChanged(int index)
QDateTime currentDateTimeUtc()
QObject * sender() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.