File indexing completed on 2025-01-19 12:59:20
0001 /************************************************************************ 0002 * * 0003 * This file is part of Kooka, a scanning/OCR application using * 0004 * Qt <http://www.qt.io> and KDE Frameworks <http://www.kde.org>. * 0005 * * 0006 * Copyright (C) 2020 Jonathan Marten <jjm@keelhaul.me.uk> * 0007 * * 0008 * Kooka is free software; you can redistribute it and/or modify it * 0009 * under the terms of the GNU Library General Public License as * 0010 * published by the Free Software Foundation and appearing in the * 0011 * file COPYING included in the packaging of this file; either * 0012 * version 2 of the License, or (at your option) any later version. * 0013 * * 0014 * As a special exception, permission is given to link this program * 0015 * with any version of the KADMOS OCR/ICR engine (a product of * 0016 * reRecognition GmbH, Kreuzlingen), and distribute the resulting * 0017 * executable without including the source code for KADMOS in the * 0018 * source distribution. * 0019 * * 0020 * This program is distributed in the hope that it will be useful, * 0021 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0023 * GNU General Public License for more details. * 0024 * * 0025 * You should have received a copy of the GNU General Public * 0026 * License along with this program; see the file COPYING. If * 0027 * not, see <http://www.gnu.org/licenses/>. * 0028 * * 0029 ************************************************************************/ 0030 0031 #include "scanparamspage.h" 0032 0033 #include <qgridlayout.h> 0034 #include <qlabel.h> 0035 0036 #include "dialogbase.h" 0037 0038 0039 ScanParamsPage::ScanParamsPage(QWidget *parent, const char *name) 0040 : QWidget(parent) 0041 { 0042 setObjectName(name); 0043 0044 mLayout = new QGridLayout(this); 0045 mLayout->setSpacing(2*DialogBase::verticalSpacing()); 0046 mLayout->setColumnStretch(2, 1); 0047 mLayout->setColumnMinimumWidth(1, 2*DialogBase::horizontalSpacing()); 0048 0049 mNextRow = 0; 0050 mPendingGroup = nullptr; 0051 } 0052 0053 0054 void ScanParamsPage::checkPendingGroup() 0055 { 0056 if (mPendingGroup != nullptr) { // separator to add first? 0057 QWidget *w = mPendingGroup; 0058 mPendingGroup = nullptr; // avoid recursion! 0059 addRow(w); 0060 } 0061 } 0062 0063 0064 void ScanParamsPage::addRow(QWidget *wid) 0065 { 0066 if (wid == nullptr) { 0067 return; // must have one 0068 } 0069 0070 checkPendingGroup(); // add separator if needed 0071 mLayout->addWidget(wid, mNextRow, 0, 1, -1); 0072 ++mNextRow; 0073 } 0074 0075 0076 void ScanParamsPage::addRow(QLabel *lab, QWidget *wid, QLabel *unit, Qt::Alignment align) 0077 { 0078 if (wid == nullptr) { 0079 return; // must have one 0080 } 0081 wid->setMaximumWidth(MAX_CONTROL_WIDTH); 0082 0083 checkPendingGroup(); // add separator if needed 0084 0085 if (lab != nullptr) { 0086 lab->setMaximumWidth(MAX_LABEL_WIDTH); 0087 lab->setMinimumWidth(MIN_LABEL_WIDTH); 0088 mLayout->addWidget(lab, mNextRow, 0, Qt::AlignLeft | align); 0089 } 0090 0091 if (unit != nullptr) { 0092 mLayout->addWidget(wid, mNextRow, 2, align); 0093 mLayout->addWidget(unit, mNextRow, 3, Qt::AlignLeft | align); 0094 } else { 0095 mLayout->addWidget(wid, mNextRow, 2, 1, 2, align); 0096 } 0097 0098 ++mNextRow; 0099 } 0100 0101 0102 void ScanParamsPage::addRow(const QString &lab, QWidget *wid, QLabel *unit, Qt::Alignment align) 0103 { 0104 QLabel *l = nullptr; 0105 if (!lab.isEmpty()) 0106 { 0107 l = new QLabel(lab, this); 0108 l->setBuddy(wid); 0109 } 0110 addRow(l, wid, unit, align); 0111 } 0112 0113 0114 void ScanParamsPage::clearRow() 0115 { 0116 for (int c = 0; c<mLayout->columnCount(); ++c) 0117 { 0118 QLayoutItem *item = mLayout->itemAtPosition(mNextRow, c); 0119 if (item==nullptr) continue; 0120 QWidget *w = item->widget(); 0121 if (w!=nullptr) w->deleteLater(); 0122 } 0123 } 0124 0125 0126 bool ScanParamsPage::lastRow() 0127 { 0128 addGroup(nullptr); // hide last if present 0129 0130 mLayout->addWidget(new QLabel(QString(), this), mNextRow, 0, 1, -1, Qt::AlignTop); 0131 mLayout->setRowStretch(mNextRow, 9); 0132 0133 return (mNextRow > 0); 0134 } 0135 0136 0137 void ScanParamsPage::addGroup(QWidget *wid) 0138 { 0139 if (mPendingGroup!=nullptr) 0140 { 0141 mPendingGroup->hide(); // don't need this after all 0142 } 0143 0144 mPendingGroup = wid; 0145 }