Libksieve

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

KDE's Doxygen guidelines are available online.