Libksieve

selectconvertparameterwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 #include "selectconvertparameterwidget.h"
7 
8 #include <KLocalizedString>
9 
10 #include "libksieve_debug.h"
11 #include <QHBoxLayout>
12 #include <QLabel>
13 #include <QSpinBox>
14 
15 using namespace KSieveUi;
16 SelectConvertParameterWidget::SelectConvertParameterWidget(QWidget *parent)
17  : QWidget(parent)
18 {
19  initialize();
20 }
21 
22 SelectConvertParameterWidget::~SelectConvertParameterWidget()
23 {
24 }
25 
26 void SelectConvertParameterWidget::setCode(const QStringList &code, QString &error)
27 {
28  if (code.isEmpty()) {
29  return;
30  }
31 
32  if (code.count() < 2) {
33  error += i18n("Not enough arguments for SelectConvertParameterWidget. Expected 2 arguments.") + QLatin1Char('\n');
34  qCDebug(LIBKSIEVE_LOG) << " SelectConvertParameterWidget::setCode parsing error ?";
35  return;
36  }
37  if (code.count() > 2) {
38  error += i18n("Too many arguments for SelectConvertParameterWidget, \"%1\"", code.count()) + QLatin1Char('\n');
39  qCDebug(LIBKSIEVE_LOG) << " too many argument " << code.count();
40  }
41 
42  QString widthStr = code.at(0);
43  widthStr.remove(QStringLiteral("pix-x="));
44 
45  QString heightStr = code.at(1);
46  heightStr.remove(QStringLiteral("pix-y="));
47  mWidth->setValue(widthStr.toInt());
48  mHeight->setValue(heightStr.toInt());
49 }
50 
51 QString SelectConvertParameterWidget::code() const
52 {
53  return QStringLiteral("[\"pix-x=%1\",\"pix-y=%2\"]").arg(mWidth->value()).arg(mHeight->value());
54 }
55 
56 void SelectConvertParameterWidget::initialize()
57 {
58  QBoxLayout *hbox = new QHBoxLayout(this);
59  hbox->setContentsMargins({});
60  mWidth = new QSpinBox(this);
61  mWidth->setSuffix(i18n(" px"));
62  mWidth->setMinimum(1);
63  mWidth->setMaximum(9999);
64  mWidth->setValue(300);
65  hbox->addWidget(mWidth);
66  connect(mWidth, QOverload<int>::of(&QSpinBox::valueChanged), this, &SelectConvertParameterWidget::valueChanged);
67 
68  auto lab = new QLabel(QStringLiteral("x"), this);
69  hbox->addWidget(lab);
70 
71  mHeight = new QSpinBox(this);
72  mHeight->setSuffix(i18n(" px"));
73  mHeight->setMinimum(1);
74  mHeight->setMaximum(9999);
75  mHeight->setValue(200);
76  hbox->addWidget(mHeight);
77 
78  connect(mHeight, QOverload<int>::of(&QSpinBox::valueChanged), this, &SelectConvertParameterWidget::valueChanged);
79 }
void setContentsMargins(int left, int top, int right, int bottom)
const T & at(int i) const const
KCRASH_EXPORT void initialize()
QString & remove(int position, int n)
void valueChanged(int i)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
int count(const T &value) const const
int toInt(bool *ok, int base) const const
bool isEmpty() const const
QString i18n(const char *text, const TYPE &arg...)
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 Sun Apr 11 2021 23:09:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.