File indexing completed on 2024-06-23 05:16:26
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 "multiplyingline.h" 0015 #include "multiplyinglineeditor.h" 0016 0017 #include <QPointer> 0018 #include <QScrollArea> 0019 0020 namespace KPIM 0021 { 0022 class MultiplyingLineView : public QScrollArea 0023 { 0024 Q_OBJECT 0025 public: 0026 explicit MultiplyingLineView(MultiplyingLineFactory *factory, MultiplyingLineEditor *parent); 0027 ~MultiplyingLineView() override = default; 0028 0029 QSize minimumSizeHint() const override; 0030 QSize sizeHint() const override; 0031 0032 [[nodiscard]] MultiplyingLine *activeLine() const; 0033 0034 MultiplyingLine *emptyLine() const; 0035 0036 [[nodiscard]] QList<MultiplyingLineData::Ptr> allData() const; 0037 0038 /** Removes data provided it can be found. The Data class must support operator== 0039 @param data The data you want to remove. 0040 */ 0041 void removeData(const MultiplyingLineData::Ptr &data); 0042 0043 /** Returns true if the user has made any modifications to the list of 0044 recipients. 0045 @return whether the view is modified or not. 0046 */ 0047 [[nodiscard]] bool isModified() const; 0048 0049 /** Resets the modified flag to false. 0050 */ 0051 void clearModified(); 0052 0053 /** Activates the line */ 0054 void activateLine(MultiplyingLine *line); 0055 0056 /**QScrollArea 0057 * Set the width of the left most column to be the argument width. 0058 * This method allows other widgets to align their label/combobox column with ours 0059 * by communicating how many pixels that first column is for them. 0060 * Returns the width that is actually being used. 0061 */ 0062 int setFirstColumnWidth(int); 0063 0064 /** 0065 Make this widget follow it's children's size 0066 @param resize turn on or off this behavior of auto resizing 0067 */ 0068 void setAutoResize(bool resize); 0069 [[nodiscard]] bool autoResize() const; 0070 0071 /** 0072 * Sets whether the size hint of the editor shall be calculated 0073 * dynamically by the number of lines. Default is @c true. 0074 */ 0075 void setDynamicSizeHint(bool dynamic); 0076 [[nodiscard]] bool dynamicSizeHint() const; 0077 0078 [[nodiscard]] QList<MultiplyingLine *> lines() const; 0079 MultiplyingLine *addLine(bool showDialogBox); 0080 0081 public Q_SLOTS: 0082 void setCompletionMode(KCompletion::CompletionMode mode); 0083 0084 void setFocus(); 0085 void setFocusTop(); 0086 void setFocusBottom(); 0087 0088 Q_SIGNALS: 0089 void focusUp(); 0090 void focusDown(); 0091 void focusRight(); 0092 void completionModeChanged(KCompletion::CompletionMode); 0093 void sizeHintChanged(); 0094 void lineDeleted(int pos); 0095 void lineAdded(KPIM::MultiplyingLine *); 0096 0097 protected: 0098 void resizeEvent(QResizeEvent *) override; 0099 void resizeView(); 0100 0101 protected Q_SLOTS: 0102 void slotReturnPressed(KPIM::MultiplyingLine *); 0103 void slotDownPressed(KPIM::MultiplyingLine *); 0104 void slotUpPressed(KPIM::MultiplyingLine *); 0105 void slotDecideLineDeletion(KPIM::MultiplyingLine *); 0106 void slotDeleteLine(); 0107 void moveScrollBarToEnd(); 0108 0109 private: 0110 QList<MultiplyingLine *> mLines; 0111 QPointer<MultiplyingLine> mCurDelLine = nullptr; 0112 QWidget *mPage = nullptr; 0113 QLayout *mTopLayout = nullptr; 0114 MultiplyingLineFactory *mMultiplyingLineFactory = nullptr; 0115 int mLineHeight = 0; 0116 int mFirstColumnWidth = 0; 0117 KCompletion::CompletionMode mCompletionMode = KCompletion::CompletionNone; 0118 bool mAutoResize = false; 0119 bool mDynamicSizeHint = true; 0120 bool mModified = false; 0121 }; 0122 }