File indexing completed on 2024-12-29 04:54:41
0001 /* 0002 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #include "selectsizewidget.h" 0007 #include "selectsizetypecombobox.h" 0008 0009 #include <QSpinBox> 0010 0011 #include <QHBoxLayout> 0012 0013 using namespace KSieveUi; 0014 0015 SelectSizeWidget::SelectSizeWidget(QWidget *parent) 0016 : QWidget(parent) 0017 , mSelectSizeType(new SelectSizeTypeComboBox(this)) 0018 , mSpinBoxSize(new QSpinBox(this)) 0019 { 0020 auto hbox = new QHBoxLayout(this); 0021 hbox->setContentsMargins({}); 0022 0023 mSpinBoxSize->setMinimum(1); 0024 mSpinBoxSize->setMaximum(99999); 0025 hbox->addWidget(mSpinBoxSize); 0026 connect(mSpinBoxSize, &QSpinBox::valueChanged, this, &SelectSizeWidget::valueChanged); 0027 0028 connect(mSelectSizeType, &SelectSizeTypeComboBox::valueChanged, this, &SelectSizeWidget::valueChanged); 0029 hbox->addWidget(mSelectSizeType); 0030 } 0031 0032 SelectSizeWidget::~SelectSizeWidget() = default; 0033 0034 QString SelectSizeWidget::code() const 0035 { 0036 const QString type = mSelectSizeType->code(); 0037 return QStringLiteral("%1%2").arg(mSpinBoxSize->value()).arg(type); 0038 } 0039 0040 void SelectSizeWidget::setCode(qlonglong value, const QString &identifier, const QString &name, QString &error) 0041 { 0042 if (identifier == QLatin1Char('K')) { 0043 value /= 1024; 0044 } else if (identifier == QLatin1Char('M')) { 0045 value /= (1024 * 1024); 0046 } else if (identifier == QLatin1Char('G')) { 0047 value /= (1024 * 1024 * 1024); 0048 } 0049 mSelectSizeType->setCode(identifier, name, error); 0050 mSpinBoxSize->setValue(value); 0051 } 0052 0053 #include "moc_selectsizewidget.cpp"