File indexing completed on 2024-05-12 04:33:22

0001 /*
0002  * SPDX-FileCopyrightText: 2007-2011 Kare Sars <kare.sars@iki .fi>
0003  * SPDX-FileCopyrightText: 2014 Gregor Mitsch : port to KDE5 frameworks
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006  */
0007 
0008 #include "labeledcheckbox.h"
0009 
0010 namespace KSaneIface
0011 {
0012 LabeledCheckbox::LabeledCheckbox(QWidget *parent, const QString &ltext)
0013     : KSaneOptionWidget(parent, QString())
0014 {
0015     initCheckBox(ltext);
0016 }
0017 
0018 LabeledCheckbox::LabeledCheckbox(QWidget *parent, KSaneCore::Option *option)
0019     : KSaneOptionWidget(parent, option)
0020 {
0021     initCheckBox(option->title());
0022     setToolTip(option->description());
0023     connect(this, &LabeledCheckbox::toggled, option, &KSaneCore::Option::setValue);
0024     connect(option, &KSaneCore::Option::valueChanged, this, &LabeledCheckbox::setValue);
0025 }
0026 
0027 LabeledCheckbox::~LabeledCheckbox()
0028 {
0029 }
0030 
0031 void LabeledCheckbox::initCheckBox(const QString &name)
0032 {
0033     chbx = new QCheckBox(name, this);
0034     m_layout->addWidget(chbx, 0, 1);
0035     m_layout->setColumnStretch(1, 50);
0036 
0037     connect(chbx, &QCheckBox::toggled, this, &LabeledCheckbox::toggled);
0038 }
0039 
0040 void LabeledCheckbox::setChecked(bool is_checked)
0041 {
0042     if (is_checked != chbx->isChecked()) {
0043         chbx->setChecked(is_checked);
0044     }
0045 }
0046 
0047 void LabeledCheckbox::setValue(const QVariant &value)
0048 {
0049     setChecked(value.toBool());
0050 }
0051 
0052 bool LabeledCheckbox::isChecked()
0053 {
0054     return chbx->isChecked();
0055 }
0056 
0057 }  // NameSpace KSaneIface
0058 
0059 #include "moc_labeledcheckbox.cpp"