KSane

ksaneoptionwidget.cpp
1/*
2 * SPDX-FileCopyrightText: 2011 Kare Sars <kare.sars@iki.fi>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6
7#include "ksaneoptionwidget.h"
8
9// KDE includes
10
11#include <KLocalizedString>
12
13namespace KSaneIface
14{
15
17 : QWidget(parent)
18{
19 m_label = new QLabel(this);
20 setLabelText(labelText);
21 initWidget();
22}
23
25 : QWidget(parent)
26{
27 m_option = option;
28 m_label = new QLabel;
29 connect(option, &KSaneCore::Option::optionReloaded, this, &KSaneOptionWidget::updateVisibility);
30 initWidget();
31}
32
33KSaneOptionWidget::~KSaneOptionWidget()
34{
35}
36
37void KSaneOptionWidget::initWidget()
38{
39 m_layout = new QGridLayout(this);
40 m_layout->addWidget(m_label, 0, 0, Qt::AlignRight);
41 m_layout->setColumnStretch(0, 0);
42 m_layout->setContentsMargins(0, 0, 0, 0);
43 updateVisibility();
44
45}
46
47void KSaneOptionWidget::updateVisibility()
48{
49 if (!m_option) {
50 return;
51 }
52
53 if (m_option->state() == KSaneCore::Option::StateHidden) {
54 hide();
55 } else {
56 show();
57 setEnabled(m_option->state() == KSaneCore::Option::StateActive);
58 }
59}
60
61void KSaneOptionWidget::setLabelText(const QString &text)
62{
63 if (text.isEmpty()) {
64 m_label->clear();
65 } else {
66 m_label->setText(i18nc("Label for a scanner option", "%1:", text));
67 }
68}
69
70int KSaneOptionWidget::labelWidthHint()
71{
72 return m_label->sizeHint().width();
73}
74
75void KSaneOptionWidget::setLabelWidth(int labelWidth)
76{
77 m_layout->setColumnMinimumWidth(0, labelWidth);
78}
79
80} // NameSpace KSaneIface
81
82#include "moc_ksaneoptionwidget.cpp"
OptionState state() const
KSaneOptionWidget(QWidget *parent, const QString &labelText)
Create the Widget.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void addWidget(QWidget *widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment)
void setColumnMinimumWidth(int column, int minSize)
void setColumnStretch(int column, int stretch)
void clear()
virtual QSize sizeHint() const const override
void setText(const QString &)
void setContentsMargins(const QMargins &margins)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
int width() const const
bool isEmpty() const const
AlignRight
void setEnabled(bool)
void hide()
void show()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.