File indexing completed on 2024-04-21 15:12:14

0001 /* This file is part of the KDE Project         -*- mode:c++; -*-
0002    Copyright (C) 2010 Jonathan Marten <jjm@keelhaul.me.uk>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library 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 GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef SCANPARAMSPAGE_H
0021 #define SCANPARAMSPAGE_H
0022 
0023 #include <qwidget.h>
0024 
0025 #include "kookascan_export.h"
0026 
0027 //  Limits for the scan option and label, to keep them to reasonable sizes
0028 #define MAX_CONTROL_WIDTH       300
0029 #define MAX_LABEL_WIDTH         150
0030 #define MIN_LABEL_WIDTH         50
0031 
0032 class QLabel;
0033 class QGridLayout;
0034 
0035 
0036 /**
0037  * This class represents a single options page (Basic, Other or Advanced)
0038  * within the scan parameter GUI.
0039  *
0040  * @author Jonathan Marten
0041  */
0042 
0043 class KOOKASCAN_EXPORT ScanParamsPage : public QWidget
0044 {
0045     Q_OBJECT
0046 
0047 public:
0048     /**
0049      * Create a new options page.
0050      *
0051      * @param parent  The parent widget
0052      * @param name    Qt object name
0053      */
0054     explicit ScanParamsPage(QWidget *parent, const char *name = nullptr);
0055 
0056     /**
0057      * Destructor.
0058      */
0059     virtual ~ScanParamsPage() = default;
0060 
0061     /**
0062      * Add a standard parameter row to the page.
0063      *
0064      * @param lab    Label for the parameter, normally from @c KScanOption::getLabel(),
0065      *               or @c nullptr for no label.
0066      * @param wid    Scan control widget, normally from @c KScanOption::widget().
0067      * @param unit   SANE unit label, normally from @c KScanOption::getUnit(), or
0068      *               @c nullptr for no unit label.
0069      * @param align  Special alignment flags for layout row.
0070 
0071      * @note The layout coloumns are used as follows:  the @p lab label goes in
0072      * column 0, left aligned.  Column 1 is a spacer.  If the @p unit label is
0073      * present then it goes in column 3 and the @p wid widget in column 2.  If
0074      * there is no @p unit label then the @p wid widget spans columns 2 and 3.
0075      */
0076     void addRow(QLabel *lab, QWidget *wid, QLabel *unit = nullptr, Qt::Alignment align = Qt::Alignment());
0077 
0078     /**
0079      * Add a standard parameter row to the page.
0080      *
0081      * @param lab    Label text for the parameter, or a null string for no label.
0082      * @param wid    Scan control widget, normally from @c KScanOption::widget().
0083      * @param unit   SANE unit label, normally from @c KScanOption::getUnit(), or
0084      *               @c nullptr for no unit label.
0085      * @param align  Special alignment flags for layout row.
0086 
0087      * @see the previous overload for column and alignment information.
0088      */
0089     void addRow(const QString &lab, QWidget *wid, QLabel *unit = nullptr, Qt::Alignment align = Qt::Alignment());
0090 
0091     /**
0092      * Add a full width widget to the page.
0093      *
0094      * @param wid The widget to add.
0095      */
0096     void addRow(QWidget *wid);
0097 
0098     /**
0099      * Finish off the layout by adding a stretch widget (so that all the created
0100      * parameters are aligned to the top), and check whether any widgets have
0101      * been added.
0102      *
0103      * @return @c true if any parameter widgets are present
0104      */
0105     bool lastRow();
0106 
0107     /**
0108      * Add a group separator to the layout.  Because of the widget sorting there
0109      * may be nothing following, or another group, so the group is retained as
0110      * "pending" and added just before the next row.
0111      *
0112      * @param wid The widget to add.
0113      */
0114     void addGroup(QWidget *wid);
0115 
0116     /**
0117      * Retrieve the current layout row, which is the next row that
0118      * will be filled by either of the @c addRow() functions.
0119      *
0120      * @return the current row
0121      **/
0122     int currentRow() const              { return (mNextRow); }
0123 
0124     /**
0125      * Set the current layout row, which is the next row that will be filled
0126      * by either of the @c addRow() functions.
0127      *
0128      * @param row The layout row to set.
0129      **/
0130     void setCurrentRow(int row)             { mNextRow = row; }
0131 
0132     /**
0133      * Clear the current layout row and delete any widgets which it contains.
0134      **/
0135     void clearRow();
0136 
0137 private:
0138     void checkPendingGroup();
0139 
0140     QGridLayout *mLayout;
0141     int mNextRow;
0142     QWidget *mPendingGroup;
0143 };
0144 
0145 #endif // SCANPARAMSPAGE_H