File indexing completed on 2024-04-21 05:51:39

0001 /*
0002  *  SPDX-FileCopyrightText: 2002-2003 Jesper K. Pedersen <blackie@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-only
0005  **/
0006 
0007 #ifndef __repeatwidget
0008 #define __repeatwidget
0009 
0010 #include "singlecontainerwidget.h"
0011 
0012 class QGroupBox;
0013 class QButtonGroup;
0014 class QDialog;
0015 class QSpinBox;
0016 class RepeatRegExp;
0017 class QGridLayout;
0018 
0019 /**
0020    Widget containging the configuration for a @ref RepeatWidget
0021    @internal
0022 */
0023 class RepeatRangeWindow : public QWidget
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     enum REPEATTYPE { ANY, ATLEAST, ATMOST, EXACTLY, MINMAX }; // krazy:exclude=spelling
0029 
0030     RepeatRangeWindow(QWidget *parent);
0031     QString text();
0032     int min();
0033     int max();
0034     void set(REPEATTYPE tp, int min, int max);
0035 
0036 protected Q_SLOTS:
0037     void slotItemChange(int which);
0038     void slotUpdateMinVal(int minVal);
0039     void slotUpdateMaxVal(int minVal);
0040 
0041 private:
0042     void createLine(QGridLayout *layout, const QString &text, QSpinBox **spin, REPEATTYPE tp);
0043 
0044     QSpinBox *_leastTimes = nullptr;
0045     QSpinBox *_mostTimes = nullptr;
0046     QSpinBox *_exactlyTimes = nullptr;
0047     QSpinBox *_rangeFrom = nullptr;
0048     QSpinBox *_rangeTo = nullptr;
0049     QGroupBox *_groupWidget = nullptr;
0050     QButtonGroup *_group = nullptr;
0051 };
0052 
0053 /**
0054    RegExp widget for `repeated content'
0055    @internal
0056 */
0057 class RepeatWidget : public SingleContainerWidget
0058 {
0059     Q_OBJECT
0060 
0061 public:
0062     RepeatWidget(RegExpEditorWindow *editorWindow, QWidget *parent);
0063     RepeatWidget(RepeatRegExp *regexp, RegExpEditorWindow *editorWindow, QWidget *parent);
0064     void init();
0065     QSize sizeHint() const override;
0066     RegExp *regExp() const override;
0067     RegExpType type() const override
0068     {
0069         return REPEAT;
0070     }
0071 
0072     int edit() override;
0073 
0074 protected:
0075     void paintEvent(QPaintEvent *e) override;
0076 
0077 protected Q_SLOTS:
0078     void slotConfigCanceled();
0079     void slotConfigWindowClosed();
0080 
0081 private:
0082     QDialog *_configWindow = nullptr;
0083     RepeatRangeWindow *_content = nullptr;
0084 
0085     mutable QSize _textSize;
0086     mutable QSize _childSize;
0087     QByteArray _backup;
0088 };
0089 
0090 #endif // __repeatwidget