Libksieve

selectconvertparameterwidget.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 "selectconvertparameterwidget.h"
7
8#include <KLocalizedString>
9
10#include "libksieveui_debug.h"
11#include <QHBoxLayout>
12#include <QLabel>
13#include <QSpinBox>
14
15using namespace KSieveUi;
16SelectConvertParameterWidget::SelectConvertParameterWidget(QWidget *parent)
17 : QWidget(parent)
18{
19 initialize();
20}
21
22SelectConvertParameterWidget::~SelectConvertParameterWidget() = default;
23
24void SelectConvertParameterWidget::setCode(const QStringList &code, QString &error)
25{
26 if (code.isEmpty()) {
27 return;
28 }
29
30 const auto codeCount{code.count()};
31 if (codeCount < 2) {
32 error += i18n("Not enough arguments for SelectConvertParameterWidget. Expected 2 arguments.") + QLatin1Char('\n');
33 qCDebug(LIBKSIEVEUI_LOG) << " SelectConvertParameterWidget::setCode parsing error ?";
34 return;
35 }
36 if (codeCount > 2) {
37 error += i18n("Too many arguments for SelectConvertParameterWidget, \"%1\"", code.count()) + QLatin1Char('\n');
38 qCDebug(LIBKSIEVEUI_LOG) << " too many argument " << code.count();
39 }
40
41 QString widthStr = code.at(0);
42 widthStr.remove(QStringLiteral("pix-x="));
43
44 QString heightStr = code.at(1);
45 heightStr.remove(QStringLiteral("pix-y="));
46 mWidth->setValue(widthStr.toInt());
47 mHeight->setValue(heightStr.toInt());
48}
49
50QString SelectConvertParameterWidget::code() const
51{
52 return QStringLiteral("[\"pix-x=%1\",\"pix-y=%2\"]").arg(mWidth->value()).arg(mHeight->value());
53}
54
55void SelectConvertParameterWidget::initialize()
56{
57 auto hbox = new QHBoxLayout(this);
58 hbox->setContentsMargins({});
59 mWidth = new QSpinBox(this);
60 mWidth->setSuffix(i18n(" px"));
61 mWidth->setMinimum(1);
62 mWidth->setMaximum(9999);
63 mWidth->setValue(300);
64 hbox->addWidget(mWidth);
65 connect(mWidth, &QSpinBox::valueChanged, this, &SelectConvertParameterWidget::valueChanged);
66
67 auto lab = new QLabel(QStringLiteral("x"), this);
68 hbox->addWidget(lab);
69
70 mHeight = new QSpinBox(this);
71 mHeight->setSuffix(i18n(" px"));
72 mHeight->setMinimum(1);
73 mHeight->setMaximum(9999);
74 mHeight->setValue(200);
75 hbox->addWidget(mHeight);
76
77 connect(mHeight, &QSpinBox::valueChanged, this, &SelectConvertParameterWidget::valueChanged);
78}
79
80#include "moc_selectconvertparameterwidget.cpp"
QString i18n(const char *text, const TYPE &arg...)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
void initialize(StandardShortcut id)
const_reference at(qsizetype i) const const
qsizetype count() const const
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setMaximum(int max)
void setMinimum(int min)
void setSuffix(const QString &suffix)
void setValue(int val)
void valueChanged(int i)
QString arg(Args &&... args) const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
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.