Libksieve

selectsizewidget.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
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
13using namespace KSieveUi;
14
15SelectSizeWidget::SelectSizeWidget(QWidget *parent)
16 : QWidget(parent)
17 , mSelectSizeType(new SelectSizeTypeComboBox(this))
18 , mSpinBoxSize(new QSpinBox(this))
19{
20 auto hbox = new QHBoxLayout(this);
21 hbox->setContentsMargins({});
22
23 mSpinBoxSize->setMinimum(1);
24 mSpinBoxSize->setMaximum(99999);
25 hbox->addWidget(mSpinBoxSize);
26 connect(mSpinBoxSize, &QSpinBox::valueChanged, this, &SelectSizeWidget::valueChanged);
27
28 connect(mSelectSizeType, &SelectSizeTypeComboBox::valueChanged, this, &SelectSizeWidget::valueChanged);
29 hbox->addWidget(mSelectSizeType);
30}
31
32SelectSizeWidget::~SelectSizeWidget() = default;
33
34QString SelectSizeWidget::code() const
35{
36 const QString type = mSelectSizeType->code();
37 return QStringLiteral("%1%2").arg(mSpinBoxSize->value()).arg(type);
38}
39
40void SelectSizeWidget::setCode(qlonglong value, const QString &identifier, const QString &name, QString &error)
41{
42 if (identifier == QLatin1Char('K')) {
43 value /= 1024;
44 } else if (identifier == QLatin1Char('M')) {
45 value /= (1024 * 1024);
46 } else if (identifier == QLatin1Char('G')) {
47 value /= (1024 * 1024 * 1024);
48 }
49 mSelectSizeType->setCode(identifier, name, error);
50 mSpinBoxSize->setValue(value);
51}
52
53#include "moc_selectsizewidget.cpp"
Type type(const QSqlDatabase &db)
void valueChanged(int i)
QString arg(Args &&... args) 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 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.