File indexing completed on 2024-05-12 05:09:47
0001 /*************************************************************************** 0002 Copyright (C) 2003-2021 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #ifndef TELLICO_FIELDWIDGET_H 0026 #define TELLICO_FIELDWIDGET_H 0027 0028 #include "../datavectors.h" 0029 0030 #include <QWidget> 0031 0032 class QLabel; 0033 class QCheckBox; 0034 class QString; 0035 0036 namespace Tellico { 0037 namespace Data { 0038 class Field; 0039 } 0040 namespace GUI { 0041 0042 /** 0043 * The FieldWidget class is a box that shows a label, then a widget which depends 0044 * on the field type, and then a checkbox for multiple editing. 0045 * 0046 * @author Robby Stephenson 0047 */ 0048 class FieldWidget : public QWidget { 0049 Q_OBJECT 0050 0051 public: 0052 FieldWidget(Data::FieldPtr field, QWidget* parent); 0053 virtual ~FieldWidget() {} 0054 0055 Data::FieldPtr field() const { return m_field; } 0056 virtual QString text() const = 0; 0057 void setText(const QString& text); 0058 void clear(); 0059 0060 int labelWidth() const; 0061 void setLabelWidth(int width); 0062 bool isEnabled(); 0063 bool expands() const; 0064 void editMultiple(bool show); 0065 // calls updateFieldHook() 0066 void updateField(Data::FieldPtr oldField, Data::FieldPtr newField); 0067 0068 // only used by LineFieldWidget, really 0069 virtual void addCompletionObjectItem(const QString&) {} 0070 0071 public Q_SLOTS: 0072 virtual void insertDefault(); 0073 void setEnabled(bool enabled); 0074 0075 Q_SIGNALS: 0076 void valueChanged(Tellico::Data::FieldPtr field); 0077 void fieldChanged(Tellico::Data::FieldPtr field); 0078 0079 protected Q_SLOTS: 0080 void checkModified(); 0081 0082 protected: 0083 QLabel* label() { return m_label; } // needed so the URLField can handle clicks on the label 0084 virtual QWidget* widget() = 0; 0085 void registerWidget(); 0086 void setField(Tellico::Data::FieldPtr field); 0087 virtual void setTextImpl(const QString& text) = 0; 0088 virtual void clearImpl() = 0; 0089 0090 // not all widgets have to be updated when the field changes 0091 virtual void updateFieldHook(Data::FieldPtr, Data::FieldPtr) {} 0092 0093 private Q_SLOTS: 0094 void multipleChecked(); 0095 0096 private: 0097 Data::FieldPtr m_field; 0098 QLabel* m_label; 0099 QCheckBox* m_editMultiple; 0100 QString m_oldValue; 0101 0102 bool m_expands; 0103 bool m_settingText; 0104 }; 0105 0106 } // end GUI namespace 0107 } // end namespace 0108 #endif