File indexing completed on 2024-05-12 17:10:47
0001 /*************************************************************************** 0002 * Copyright (C) 2010 by Sebastian Kugler <sebas@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU General Public License as published by * 0006 * the Free Software Foundation; either version 2 of the License, or * 0007 * (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the * 0016 * Free Software Foundation, Inc., * 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * 0018 ***************************************************************************/ 0019 0020 #include "actionconfigwidget.h" 0021 0022 #include <QCheckBox> 0023 #include <QLabel> 0024 #include <QMenu> 0025 #include <QMenuBar> 0026 #include <QAction> 0027 #include <QApplication> 0028 #include <QLayoutItem> 0029 0030 0031 ActionConfigWidget::ActionConfigWidget(QWidget* parent) : QWidget(parent) 0032 { 0033 m_gridLayout = new QGridLayout(this); 0034 setLayout(m_gridLayout); 0035 0036 // FIXME: pixelSize() returns an useful -1 here, pointSize() doesn't 0037 // that's correct though, since points != pixels, and the latter matter 0038 m_gridLayout->setVerticalSpacing(QApplication::font().pointSize() / 2); 0039 0040 } 0041 0042 ActionConfigWidget::~ActionConfigWidget() 0043 {} 0044 0045 void ActionConfigWidget::addWidgets(const QList<QPair<QString, QWidget*> > &configMap) 0046 { 0047 int row = m_gridLayout->rowCount(); 0048 row++; 0049 0050 QCheckBox* currentSectionCheckbox = nullptr; 0051 0052 QList<QPair<QString, QWidget*> >::const_iterator it; 0053 for (it = configMap.constBegin(); it != configMap.constEnd(); ++it) { 0054 QPair<QString, QWidget*> line = *it; 0055 if (line.first.isEmpty()) { 0056 // A title checkbox 0057 currentSectionCheckbox = qobject_cast<QCheckBox*>(line.second); 0058 currentSectionCheckbox->setChecked(true); 0059 m_gridLayout->addWidget(line.second, row, 0, 1, 3); 0060 0061 // allow left-aligning checkboxes without treating them as section header 0062 } else if (line.first == QLatin1String("NONE")) { 0063 m_gridLayout->addItem(new QSpacerItem(50, 3), row, 0); 0064 m_gridLayout->addWidget(line.second, row, 1, 1, 2); 0065 } else { 0066 // connect enabled / disabled 0067 QLabel* label = new QLabel(this); 0068 label->setText(line.first); 0069 0070 m_gridLayout->addItem(new QSpacerItem(50, 3), row, 0); 0071 m_gridLayout->addWidget(label, row, 1, Qt::AlignRight); 0072 m_gridLayout->addWidget(line.second, row, 2); 0073 0074 connect(currentSectionCheckbox, &QAbstractButton::toggled, 0075 label, &QWidget::setEnabled); 0076 connect(currentSectionCheckbox, &QAbstractButton::toggled, 0077 line.second, &QWidget::setEnabled); 0078 } 0079 row++; 0080 } 0081 }