File indexing completed on 2024-05-19 16:43:48

0001 /*************************************************************************
0002  *   Copyright (C) 2009 by Renaud Guezennec                              *
0003  *                                                                       *
0004  *   https://rolisteam.org/                                           *
0005  *                                                                       *
0006  *   rolisteam is free software; you can redistribute it and/or modify   *
0007  *   it under the terms of the GNU General Public License as published   *
0008  *   by the Free Software Foundation; either version 2 of the License,   *
0009  *   or (at your option) any later version.                              *
0010  *                                                                       *
0011  *   This program is distributed in the hope that it will be useful,     *
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of      *
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
0014  *   GNU General Public License for more details.                        *
0015  *                                                                       *
0016  *   You should have received a copy of the GNU General Public License   *
0017  *   along with this program; if not, write to the                       *
0018  *   Free Software Foundation, Inc.,                                     *
0019  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           *
0020  *************************************************************************/
0021 #include <QHBoxLayout>
0022 
0023 #include "centeredcheckbox.h"
0024 CenteredCheckBox::CenteredCheckBox(QWidget* wid) : QWidget(wid)
0025 {
0026     QHBoxLayout* layout= new QHBoxLayout();
0027     layout->setContentsMargins(QMargins());
0028     layout->setSpacing(0);
0029     setLayout(layout);
0030     layout->setAlignment(Qt::AlignCenter);
0031 
0032     m_editorCheckBox.reset(new QCheckBox());
0033     layout->addWidget(m_editorCheckBox.get());
0034 
0035     connect(m_editorCheckBox.get(), &QCheckBox::stateChanged, this, &CenteredCheckBox::commitEditor);
0036 }
0037 
0038 bool CenteredCheckBox::isCheckedDelegate() const
0039 {
0040     bool checked= false;
0041     switch(m_editorCheckBox->checkState())
0042     {
0043     case Qt::Unchecked:
0044         checked= false;
0045         break;
0046     case Qt::PartiallyChecked:
0047     case Qt::Checked:
0048         checked= true;
0049         break;
0050     }
0051     return checked;
0052 }
0053 
0054 void CenteredCheckBox::setCheckedDelegate(bool checked)
0055 {
0056     if(checked)
0057     {
0058         m_editorCheckBox->setCheckState(Qt::Checked);
0059     }
0060     else
0061     {
0062         m_editorCheckBox->setCheckState(Qt::Unchecked);
0063     }
0064     update();
0065 }