KSane

labeledentry.cpp
1/*
2 * SPDX-FileCopyrightText: 2007-2011 Kare Sars <kare.sars@iki .fi>
3 * SPDX-FileCopyrightText: 2014 Gregor Mitsch : port to KDE5 frameworks
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7
8// Local includes
9
10#include "labeledentry.h"
11
12// Qt includes
13
14#include <QHBoxLayout>
15#include <QLabel>
16#include <QLineEdit>
17#include <QPushButton>
18
19// KDE includes
20
21#include <KLocalizedString>
22
23namespace KSaneIface
24{
25
27 : KSaneOptionWidget(parent, ltext)
28{
29 initEntry();
30}
31
33 : KSaneOptionWidget(parent, option)
34{
35 initEntry();
36 setToolTip(option->description());
37 setLabelText(option->title());
38 connect(this, &LabeledEntry::entryEdited, option, &KSaneCore::Option::setValue);
39 connect(option, &KSaneCore::Option::valueChanged, this, &LabeledEntry::setValue);
40 QString value = option->value().toString();
41 m_entry->setText(value);
42}
43
44LabeledEntry::~LabeledEntry()
45{
46}
47
48void LabeledEntry::initEntry()
49{
50 m_entry = new QLineEdit(this);
51 m_reset = new QPushButton(this);
52 m_reset->setText(i18nc("Label for button to reset text in a KLineEdit", "Reset"));
53 m_set = new QPushButton(this);
54 m_set->setText(i18nc("Label for button to write text in a KLineEdit to sane", "Set"));
55
56 m_layout->addWidget(m_entry, 1, 0, 1, 2);
57 m_layout->addWidget(m_reset, 1, 2);
58 m_layout->addWidget(m_set, 1, 3);
59 m_layout->setColumnStretch(1, 50);
60
61 connect(m_reset, &QPushButton::clicked, this, &LabeledEntry::resetClicked);
62 connect(m_set, &QPushButton::clicked, this, &LabeledEntry::setClicked);
63}
64
65void LabeledEntry::setText(const QString &text)
66{
67 m_eText = text;
68 m_entry->setText(text);
69}
70
71void LabeledEntry::setValue(const QVariant &value)
72{
73 const QString text = value.toString();
74 if (!text.isEmpty()) {
75 setText(text);
76 }
77}
78
79void LabeledEntry::resetClicked()
80{
81 m_entry->setText(m_eText);
82}
83
84void LabeledEntry::setClicked()
85{
86 m_eText = m_entry->text();
87 Q_EMIT entryEdited(m_eText);
88}
89
90} // NameSpace KSaneIface
91
92#include "moc_labeledentry.cpp"
void valueChanged(const QVariant &value)
bool setValue(const QVariant &value)
QString title() const
QVariant value() const
QString description() const
Base class for option widgets.
LabeledEntry(QWidget *parent, const QString &text)
Create the entry.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void clicked(bool checked)
void setText(const QString &text)
void addWidget(QWidget *widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment)
void setColumnStretch(int column, int stretch)
void setText(const QString &)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const
QString toString() const const
void setToolTip(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:31 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.