Libksieve

sievedatespinbox.cpp
1/*
2 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "sievedatespinbox.h"
8#include "libksieveui_debug.h"
9using namespace KSieveUi;
10
11SieveDateSpinBox::SieveDateSpinBox(QWidget *parent)
12 : QSpinBox(parent)
13{
14 setSpecialValueText(QStringLiteral("*"));
15}
16
17SieveDateSpinBox::~SieveDateSpinBox() = default;
18
19void SieveDateSpinBox::setRange(int minValue, int maxValue)
20{
21 // We need to define specialValueText => we set minimum to minimum - 1
22 setMaximum(maxValue);
23 setMinimum(minValue - 1);
24}
25
26void SieveDateSpinBox::setType(KSieveUi::SelectDateWidget::DateType type)
27{
28 mType = type;
29 switch (type) {
30 case SelectDateWidget::Year:
31 setRange(0, 9999);
32 break;
33 case SelectDateWidget::Month:
34 setRange(1, 12);
35 break;
36 case SelectDateWidget::Day:
37 setRange(1, 31);
38 break;
39 case SelectDateWidget::Hour:
40 setRange(0, 23);
41 break;
42 case SelectDateWidget::Minute:
43 setRange(0, 59);
44 break;
45 case SelectDateWidget::Second:
46 setRange(0, 59);
47 break;
48 case SelectDateWidget::Weekday:
49 setRange(0, 6);
50 break;
51 default:
52 qCWarning(LIBKSIEVEUI_LOG) << "This type mustn't be selected " << mType;
53 }
54}
55
56void SieveDateSpinBox::setCode(const QString &str)
57{
58 if (str == QLatin1StringView("*")) {
59 // setSpecialValue
61 } else {
62 setValue(str.toInt());
63 }
64}
65
66QString SieveDateSpinBox::code() const
67{
68 if (value() == minimum()) {
69 return QStringLiteral("*");
70 }
71 return convertValue();
72}
73
74QString SieveDateSpinBox::convertValue() const
75{
76 QString str;
77 switch (mType) {
78 case SelectDateWidget::Year:
79 str = QStringLiteral("%1").arg(value(), 4, 10, QLatin1Char('0'));
80 break;
81 case SelectDateWidget::Month:
82 str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
83 break;
84 case SelectDateWidget::Day:
85 str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
86 break;
87 case SelectDateWidget::Hour:
88 str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
89 break;
90 case SelectDateWidget::Minute:
91 str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
92 break;
93 case SelectDateWidget::Second:
94 str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
95 break;
96 case SelectDateWidget::Weekday:
97 str = QString::number(value());
98 break;
99 default:
100 qCWarning(LIBKSIEVEUI_LOG) << "This type mustn't be selected " << mType;
101 break;
102 }
103 return str;
104}
105
106#include "moc_sievedatespinbox.cpp"
Type type(const QSqlDatabase &db)
void setMaximum(int max)
void setMinimum(int min)
void setValue(int val)
QString arg(Args &&... args) const const
QString number(double n, char format, int precision)
int toInt(bool *ok, int base) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.