Libkdepim

multiplyinglineeditor.h
1 /*
2  SPDX-FileCopyrightText: 2010 Casey Link <[email protected]>
3  SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <[email protected]>
4 
5  Refactored from earlier code by:
6  SPDX-FileCopyrightText: 2010 Volker Krause <[email protected]>
7  SPDX-FileCopyrightText: 2004 Cornelius Schumacher <[email protected]>
8 
9  SPDX-License-Identifier: LGPL-2.0-or-later
10 */
11 
12 #pragma once
13 
14 #include "kdepim_export.h"
15 
16 #include "multiplyingline.h"
17 
18 #include <KCompletion>
19 #include <QObject>
20 #include <QWidget>
21 
22 namespace KPIM
23 {
24 class MultiplyingLineView;
25 
26 /**
27  @short An Abstract Base Class used to create MultiplyingLines
28  Subclass this class and MultiplyingLine, then implement newLine() such that it allocates
29  and returns an instance of your MultiplyingLine.
30  */
31 class KDEPIM_EXPORT MultiplyingLineFactory : public QObject
32 {
33  Q_OBJECT
34 public:
35  explicit MultiplyingLineFactory(QObject *parent)
36  : QObject(parent)
37  {
38  }
39 
40  ~MultiplyingLineFactory() override = default;
41 
42  virtual MultiplyingLine *newLine(QWidget *parent) = 0;
43  virtual int maximumRecipients()
44  {
45  return -1;
46  }
47 };
48 
49 /**
50  @short An editor that adds rows (lines) of widgets and deletes them as the user edits
51 
52  Line widgets in the MultiplyingLineEditor are usually composed of multiple
53  basic widgets. An example is below:
54 
55  -------------------------------------------------
56  | ComboBox| Line edit | Checkbox | <-- 1 line
57  -------------------------------------------------
58  | ComboBox| Line edit | Checkbox | <-- another line
59 
60  Default behavior is one line with default settings, and when
61  the user edits it, another line is automatically added.
62  Lines are added and deleted on demand.
63 
64  Implement this class and MultiplyingLineData. Then implement
65  MultiplyingLineFactory to return instances of your line.
66 */
67 class KDEPIM_EXPORT MultiplyingLineEditor : public QWidget
68 {
69  Q_OBJECT
70  Q_PROPERTY(bool autoResizeView READ autoResizeView WRITE setAutoResizeView)
71  Q_PROPERTY(bool dynamicSizeHint READ dynamicSizeHint WRITE setDynamicSizeHint)
72 
73 public:
74  // We take ownership of factory
75  explicit MultiplyingLineEditor(MultiplyingLineFactory *factory, QWidget *parent = nullptr);
76 
77  ~MultiplyingLineEditor() override;
78 
79  /** Get the current line factory for this instance of the widget.
80  */
81  MultiplyingLineFactory *factory() const;
82 
83  /** Retrieve the data from the editor */
84  Q_REQUIRED_RESULT QVector<MultiplyingLineData::Ptr> allData() const;
85 
86  /** Retrieve the data of the active line */
87  MultiplyingLineData::Ptr activeData() const;
88 
89  /** Clear all lines from the widget.
90  */
91  void clear();
92 
93  /** Returns true if the user has made any modifications to the list of
94  recipients.
95  */
96  Q_REQUIRED_RESULT bool isModified();
97 
98  /** Resets the modified flag to false.
99  */
100  void clearModified();
101 
102  /** Adds data to one line of the editor.
103  @param data The data you want to add.
104  Can be used to add an empty/default line.
105  */
106  bool addData(const MultiplyingLineData::Ptr &data = MultiplyingLineData::Ptr(), bool showDialogBox = true);
107 
108  /** Removes data provided it can be found. The Data class must support operator==
109  @param data The data you want to add.
110  */
111  void removeData(const MultiplyingLineData::Ptr &data);
112 
113  /**
114  Set the width of the left most column to be the argument width.
115  This method allows other widgets to align their label/combobox column with ours
116  by communicating how many pixels that first column is for them.
117  @param w what the left most column width should be
118  @return the width that is actually being used.
119  */
120  int setFirstColumnWidth(int w);
121 
122  /**
123  Set completion mode for all lines
124  @param mode the completion mode
125  */
126  void setCompletionMode(KCompletion::CompletionMode mode);
127 
128  /**
129  Set the underlying view's frame shape, default is none.
130  @param shape of type QFrame::Shape
131  */
132  void setFrameStyle(int shape);
133 
134  /**
135  Make the line view follow it's children's size
136  @param resize turn on or off this behavior of auto resizing
137  */
138  void setAutoResizeView(bool resize);
139  Q_REQUIRED_RESULT bool autoResizeView();
140 
141  /**
142  * Sets whether the size hint of the editor shall be calculated
143  * dynamically by the number of lines. Default is @c true.
144  */
145  void setDynamicSizeHint(bool dynamic);
146  Q_REQUIRED_RESULT bool dynamicSizeHint() const;
147 
148  virtual QList<MultiplyingLine *> lines() const;
149 
150 Q_SIGNALS:
151  void focusUp();
152  void focusDown();
153  void completionModeChanged(KCompletion::CompletionMode);
154  void sizeHintChanged();
155  void lineDeleted(int pos);
156  void lineAdded(KPIM::MultiplyingLine *);
157 
158 public Q_SLOTS:
159  void setFocus();
160  void setFocusTop();
161  void setFocusBottom();
162 
163 protected:
164  virtual MultiplyingLine *activeLine() const;
165  bool mModified = false;
166 
167 private:
168  MultiplyingLineFactory *const mMultiplyingLineFactory;
169  MultiplyingLineView *mView = nullptr;
170 };
171 }
An editor that adds rows (lines) of widgets and deletes them as the user edits.
Class KCheckComboBox::KCheckComboBoxPrivate.
An Abstract Base Class used to create MultiplyingLines Subclass this class and MultiplyingLine,...
Abstract Base Class representing a line in the Multiplying line widget.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 04:11:22 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.