Libksieve

selectsizewidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 #include "selectsizewidget.h"
7 #include "selectsizetypecombobox.h"
8 
9 #include <QSpinBox>
10 
11 #include <QHBoxLayout>
12 
13 using namespace KSieveUi;
14 
15 SelectSizeWidget::SelectSizeWidget(QWidget *parent)
16  : QWidget(parent)
17 {
18  auto hbox = new QHBoxLayout(this);
19  hbox->setContentsMargins({});
20 
21  mSpinBoxSize = new QSpinBox(this);
22  mSpinBoxSize->setMinimum(1);
23  mSpinBoxSize->setMaximum(99999);
24  hbox->addWidget(mSpinBoxSize);
25  connect(mSpinBoxSize, QOverload<int>::of(&QSpinBox::valueChanged), this, &SelectSizeWidget::valueChanged);
26 
27  mSelectSizeType = new SelectSizeTypeComboBox(this);
28  connect(mSelectSizeType, &SelectSizeTypeComboBox::valueChanged, this, &SelectSizeWidget::valueChanged);
29  hbox->addWidget(mSelectSizeType);
30 }
31 
32 SelectSizeWidget::~SelectSizeWidget()
33 {
34 }
35 
36 QString SelectSizeWidget::code() const
37 {
38  const QString type = mSelectSizeType->code();
39  return QStringLiteral("%1%2").arg(mSpinBoxSize->value()).arg(type);
40 }
41 
42 void SelectSizeWidget::setCode(qlonglong value, const QString &identifier, const QString &name, QString &error)
43 {
44  if (identifier == QLatin1Char('K')) {
45  value /= 1024;
46  } else if (identifier == QLatin1Char('M')) {
47  value /= (1024 * 1024);
48  } else if (identifier == QLatin1Char('G')) {
49  value /= (1024 * 1024 * 1024);
50  }
51  mSelectSizeType->setCode(identifier, name, error);
52  mSpinBoxSize->setValue(value);
53 }
void valueChanged(int i)
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.