File indexing completed on 2024-04-28 05:51:09

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 __kmultiformlistbox
0008 #define __kmultiformlistbox
0009 
0010 #include "kmultiformlistboxentry.h"
0011 
0012 #include <KLocalizedString>
0013 #include <QWidget>
0014 
0015 class QDataStream;
0016 class KMultiFormListBoxFactory;
0017 class KMultiFormListBoxShower;
0018 
0019 typedef QList<KMultiFormListBoxEntry *> KMultiFormListBoxEntryList;
0020 typedef QList<QWidget *> WidgetList;
0021 
0022 /**
0023  The main class used to get an KMultiFormListBox widget.
0024 
0025  The KMultiFormListBox widget consist of a sub-widget which is repeated a
0026  number of times, it is up to the end user to determine the number of times
0027  the sub widget is repeated, and he may require an additional copy simply
0028  by pressing a ``Add'' or ``More Entries'' button.  The KMultiFormListBox
0029  widget has two different faces (i.e. two different end user
0030  interfaces). One (Windowed) will show a listbox from which the end user
0031  can access each subwidget containing data by pressing the LMB on a name
0032  for the element. The other face (MultiVisible) shows all the subwidgets in
0033  one huge ``Listbox''.
0034 
0035  To use the KMultiFormListBox widget you must create a class which is inherited
0036  from the @ref KMultiFormListBoxFactory class. This new class must override the
0037  function `create'. This function must return a freshly made instance of
0038  the class @ref KMultiFormListBoxEntry (or a subclass of this). The KMultiFormListBoxEntry
0039  instance is the one inserted into the KMultiFormListBox widget (one instance for
0040  each sub widget in the KMultiFormListBox widget).
0041 
0042  @author Jesper Kjær Pedersen <blackie@kde.org>
0043  **/
0044 class KMultiFormListBox : public QWidget
0045 {
0046     Q_OBJECT
0047 
0048 public:
0049     enum KMultiFormListBoxType { MultiVisible, Windowed };
0050 
0051     /**
0052        @param factory A factory used to generate the instances of
0053        KMultiFormListBoxEntry class which is repeated in the KMultiFormListBox
0054        @param parent A pointer to the parent widget
0055      **/
0056     explicit KMultiFormListBox(KMultiFormListBoxFactory *factory,
0057                                KMultiFormListBoxType tp = Windowed,
0058                                QWidget *parent = nullptr,
0059                                bool showUpDownButtons = true,
0060                                bool showHelpButton = true,
0061                                const QString &addButtonText = i18n("Add"));
0062 
0063     /**
0064        @return The elements in the KMultiFormListBox.
0065      **/
0066     KMultiFormListBoxEntryList elements();
0067     const KMultiFormListBoxEntryList elements() const;
0068 
0069     /**
0070          TODO.
0071     **/
0072     void append(KMultiFormListBoxEntry *);
0073 
0074     /** write data out to stream */
0075     void toStream(QDataStream &stream) const;
0076 
0077     /** reads data in from stream */
0078     void fromStream(QDataStream &stream);
0079 
0080 public Q_SLOTS:
0081 
0082     /**
0083        Adds an empty element to the KMultiFormListBox.
0084 
0085        This slot is only required for the @ref MultiVisible face. It should
0086        be connected to a button which lets the user know that he may get more
0087        elements in this KMultiFormListBox by pressing it.  The button should
0088        be labeled ``More Entries'' or something similar.
0089      **/
0090     void addElement(); // Adds an empty element to the KMultiFormListBox
0091 
0092     /**
0093          Changes the face of the KMultiFormListBox.
0094          @param face The new face of the KMultiFormListBox
0095     **/
0096     void slotChangeFace(KMultiFormListBoxType newFace);
0097 
0098 private:
0099     KMultiFormListBoxShower *theWidget = nullptr;
0100     KMultiFormListBoxFactory *_factory = nullptr;
0101 };
0102 
0103 #endif /* kmultiformlistbox */