File indexing completed on 2024-06-23 05:16:25
0001 /* 0002 SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com> 0003 SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net> 0004 0005 Refactored from earlier code by: 0006 SPDX-FileCopyrightText: 2010 Volker Krause <vkrause@kde.org> 0007 SPDX-FileCopyrightText: 2004 Cornelius Schumacher <schumacher@kde.org> 0008 0009 SPDX-License-Identifier: LGPL-2.0-or-later 0010 */ 0011 0012 #pragma once 0013 0014 #include "kdepim_export.h" 0015 0016 #include "multiplyingline.h" 0017 0018 #include <KCompletion> 0019 #include <QObject> 0020 #include <QWidget> 0021 0022 namespace KPIM 0023 { 0024 class MultiplyingLineView; 0025 0026 /** 0027 @short An Abstract Base Class used to create MultiplyingLines 0028 Subclass this class and MultiplyingLine, then implement newLine() such that it allocates 0029 and returns an instance of your MultiplyingLine. 0030 */ 0031 class KDEPIM_EXPORT MultiplyingLineFactory : public QObject 0032 { 0033 Q_OBJECT 0034 public: 0035 explicit MultiplyingLineFactory(QObject *parent) 0036 : QObject(parent) 0037 { 0038 } 0039 0040 ~MultiplyingLineFactory() override = default; 0041 0042 virtual MultiplyingLine *newLine(QWidget *parent) = 0; 0043 virtual int maximumRecipients() 0044 { 0045 return -1; 0046 } 0047 }; 0048 0049 /** 0050 @short An editor that adds rows (lines) of widgets and deletes them as the user edits 0051 0052 Line widgets in the MultiplyingLineEditor are usually composed of multiple 0053 basic widgets. An example is below: 0054 0055 ------------------------------------------------- 0056 | ComboBox| Line edit | Checkbox | <-- 1 line 0057 ------------------------------------------------- 0058 | ComboBox| Line edit | Checkbox | <-- another line 0059 0060 Default behavior is one line with default settings, and when 0061 the user edits it, another line is automatically added. 0062 Lines are added and deleted on demand. 0063 0064 Implement this class and MultiplyingLineData. Then implement 0065 MultiplyingLineFactory to return instances of your line. 0066 */ 0067 class KDEPIM_EXPORT MultiplyingLineEditor : public QWidget 0068 { 0069 Q_OBJECT 0070 Q_PROPERTY(bool autoResizeView READ autoResizeView WRITE setAutoResizeView) 0071 Q_PROPERTY(bool dynamicSizeHint READ dynamicSizeHint WRITE setDynamicSizeHint) 0072 0073 public: 0074 // We take ownership of factory 0075 explicit MultiplyingLineEditor(MultiplyingLineFactory *factory, QWidget *parent = nullptr); 0076 0077 ~MultiplyingLineEditor() override; 0078 0079 /** Get the current line factory for this instance of the widget. 0080 */ 0081 MultiplyingLineFactory *factory() const; 0082 0083 /** Retrieve the data from the editor */ 0084 [[nodiscard]] QList<MultiplyingLineData::Ptr> allData() const; 0085 0086 /** Retrieve the data of the active line */ 0087 MultiplyingLineData::Ptr activeData() const; 0088 0089 /** Clear all lines from the widget. 0090 */ 0091 void clear(); 0092 0093 /** Returns true if the user has made any modifications to the list of 0094 recipients. 0095 */ 0096 [[nodiscard]] bool isModified(); 0097 0098 /** Resets the modified flag to false. 0099 */ 0100 void clearModified(); 0101 0102 /** Adds data to one line of the editor. 0103 @param data The data you want to add. 0104 Can be used to add an empty/default line. 0105 */ 0106 bool addData(const MultiplyingLineData::Ptr &data = MultiplyingLineData::Ptr(), bool showDialogBox = true); 0107 0108 /** Removes data provided it can be found. The Data class must support operator== 0109 @param data The data you want to add. 0110 */ 0111 void removeData(const MultiplyingLineData::Ptr &data); 0112 0113 /** 0114 Set the width of the left most column to be the argument width. 0115 This method allows other widgets to align their label/combobox column with ours 0116 by communicating how many pixels that first column is for them. 0117 @param w what the left most column width should be 0118 @return the width that is actually being used. 0119 */ 0120 int setFirstColumnWidth(int w); 0121 0122 /** 0123 Set completion mode for all lines 0124 @param mode the completion mode 0125 */ 0126 void setCompletionMode(KCompletion::CompletionMode mode); 0127 0128 /** 0129 Set the underlying view's frame shape, default is none. 0130 @param shape of type QFrame::Shape 0131 */ 0132 void setFrameStyle(int shape); 0133 0134 /** 0135 Make the line view follow it's children's size 0136 @param resize turn on or off this behavior of auto resizing 0137 */ 0138 void setAutoResizeView(bool resize); 0139 [[nodiscard]] bool autoResizeView(); 0140 0141 /** 0142 * Sets whether the size hint of the editor shall be calculated 0143 * dynamically by the number of lines. Default is @c true. 0144 */ 0145 void setDynamicSizeHint(bool dynamic); 0146 [[nodiscard]] bool dynamicSizeHint() const; 0147 0148 virtual QList<MultiplyingLine *> lines() const; 0149 0150 Q_SIGNALS: 0151 void focusUp(); 0152 void focusDown(); 0153 void completionModeChanged(KCompletion::CompletionMode); 0154 void sizeHintChanged(); 0155 void lineDeleted(int pos); 0156 void lineAdded(KPIM::MultiplyingLine *); 0157 0158 public Q_SLOTS: 0159 void setFocus(); 0160 void setFocusTop(); 0161 void setFocusBottom(); 0162 0163 protected: 0164 virtual MultiplyingLine *activeLine() const; 0165 bool mModified = false; 0166 0167 private: 0168 MultiplyingLineFactory *const mMultiplyingLineFactory; 0169 MultiplyingLineView *mView = nullptr; 0170 }; 0171 }