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 <KCompletion> 0017 #include <QSharedPointer> 0018 #include <QWidget> 0019 0020 namespace KPIM 0021 { 0022 /** 0023 @short ABC representing line data 0024 @author Casey Link 0025 */ 0026 class KDEPIM_EXPORT MultiplyingLineData 0027 { 0028 public: 0029 using Ptr = QSharedPointer<MultiplyingLineData>; 0030 virtual ~MultiplyingLineData() = default; 0031 0032 /** 0033 Clear data, reset to defaults 0034 */ 0035 virtual void clear() = 0; 0036 /** 0037 Is the data empty? 0038 */ 0039 virtual bool isEmpty() const = 0; 0040 }; 0041 0042 /** 0043 @short Abstract Base Class representing a line in the Multiplying line widget. 0044 This class (and its subclasses) represent the lines in the MultiplyingLineEditor. Users of the 0045 MultiplyingLineEditor widget should subclass this class, and add their own input widgets as members, 0046 then implement the pure virtual methods and connect all the appropriate slots. 0047 @author Casey Link 0048 */ 0049 class KDEPIM_EXPORT MultiplyingLine : public QWidget 0050 { 0051 Q_OBJECT 0052 public: 0053 explicit MultiplyingLine(QWidget *parent); 0054 ~MultiplyingLine() override = default; 0055 0056 /** 0057 This line is being activated. Focus should be set 0058 on the first or most important widget in the line. 0059 */ 0060 virtual void activate() = 0; 0061 /** 0062 Check if whatever receives focus in activate() 0063 currently has focus. 0064 @return true if this line is active 0065 */ 0066 virtual bool isActive() const = 0; 0067 0068 /** 0069 Determine if this line was modified. 0070 @return true if the user has made any modifications to this 0071 MultiplyingLine. 0072 */ 0073 virtual bool isModified() const = 0; 0074 0075 /** 0076 Resets the modified flag to false. 0077 */ 0078 virtual void clearModified() = 0; 0079 0080 /** 0081 Retrieve the data. 0082 @return the data associated with this line. 0083 */ 0084 virtual MultiplyingLineData::Ptr data() const = 0; 0085 /** 0086 Set the data of this line. The containing widgets should be 0087 populated accordingly. 0088 @param data the data to populate this line with 0089 */ 0090 virtual void setData(const MultiplyingLineData::Ptr &data) = 0; 0091 0092 /** 0093 Whether this line is empty or not. Usually there is a primary widget 0094 that can be tested (such as a line edit). 0095 @return true if this line is empty, false otherwise. 0096 */ 0097 virtual bool isEmpty() const = 0; 0098 0099 virtual bool canDeleteLineEdit() const = 0; 0100 0101 /** 0102 Set the width of the left most column to be the argument width. 0103 This method allows other widgets to align their label/combobox column with ours 0104 by communicating how many pixels that first column is for them. 0105 @param w the width to set the left most column to. 0106 @return the width that is actually being used. 0107 */ 0108 virtual int setColumnWidth(int w) = 0; 0109 0110 /** 0111 Used to set setup the correct chain of widgets to focus on 0112 when the user presses tab. 0113 @param previous the previous widget (probably from the preceding line) 0114 0115 Example with a 3 widget line: 0116 0117 void YourLine::fixTabOrder( QWidget *previous ) { 0118 setTabOrder( previous, mLeftMost ); 0119 setTabOrder( mLeftMost, mMiddle); 0120 setTabOrder( mMiddle, mRightMost); 0121 } 0122 */ 0123 virtual void fixTabOrder(QWidget *previous) = 0; 0124 0125 /** 0126 @return The final widget in this line on which if the user presses 0127 tab focus should be given to the next line. This will commonly 0128 be used as the parameter of fixTabOrder( QWidget *previous ). 0129 @see fixTabOrder( QWidget *previous ) 0130 */ 0131 virtual QWidget *tabOut() const = 0; 0132 0133 /** 0134 Clear the contents of this line. Reset to default state 0135 */ 0136 virtual void clear() = 0; 0137 0138 /** 0139 Sets the type of completion to be used for KLineEdits in this line 0140 @param mode the completion mode 0141 */ 0142 virtual void setCompletionMode(KCompletion::CompletionMode mode) = 0; 0143 0144 /** 0145 * Re implement this method if you need to do something 0146 * before a line is deleted. 0147 * 0148 * Default implementation does nothing. 0149 */ 0150 virtual void aboutToBeDeleted(); 0151 0152 Q_SIGNALS: 0153 /** 0154 Emitted when the return/enter key is pressed 0155 */ 0156 void returnPressed(KPIM::MultiplyingLine *); 0157 /** 0158 Emitted when the down key is pressed 0159 */ 0160 void downPressed(KPIM::MultiplyingLine *); 0161 /** 0162 Emitted when the up key is pressed 0163 */ 0164 void upPressed(KPIM::MultiplyingLine *); 0165 /** 0166 Emitted when the right key is pressed 0167 */ 0168 void rightPressed(); 0169 /** 0170 Should be emitted when the line should be deleted 0171 */ 0172 void deleteLine(KPIM::MultiplyingLine *); 0173 /** 0174 Emitted when the completion mode changes 0175 */ 0176 void completionModeChanged(KCompletion::CompletionMode); 0177 public Q_SLOTS: 0178 void slotPropagateDeletion(); 0179 0180 protected Q_SLOTS: 0181 void slotReturnPressed(); 0182 void slotFocusUp(); 0183 void slotFocusDown(); 0184 0185 protected: 0186 /** 0187 Handles key press events on this line. 0188 Default behavior handles Up and Down presses. 0189 */ 0190 void keyPressEvent(QKeyEvent *) override; 0191 }; 0192 }