File indexing completed on 2024-05-12 16:40:55
0001 /* This file is part of the KDE project 0002 Copyright (C) 2004 Jarosław Staniek <staniek@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KEXINAMEWIDGET_H 0021 #define KEXINAMEWIDGET_H 0022 0023 #include "kexiextwidgets_export.h" 0024 0025 #include <QLabel> 0026 0027 class QLineEdit; 0028 class KDbValidator; 0029 0030 //! A widget displaying object's name and caption and allowing editing. 0031 //! @see KexiNameDialog 0032 class KEXIEXTWIDGETS_EXPORT KexiNameWidget : public QWidget 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 explicit KexiNameWidget(const QString& message, QWidget * parent = 0); 0038 0039 KexiNameWidget(const QString& message, 0040 const QString& nameLabel, const QString& nameText, 0041 const QString& captionLabel, const QString& captionText, 0042 QWidget * parent = 0); 0043 0044 virtual ~KexiNameWidget(); 0045 0046 QLabel* captionLabel() const; 0047 QLabel* nameLabel() const; 0048 QLineEdit* captionLineEdit() const; 0049 QLineEdit* nameLineEdit() const; 0050 0051 QString messageText() const; 0052 void setMessageText(const QString& msg); 0053 0054 //! \return entered caption text 0055 QString captionText() const; 0056 0057 void setCaptionText(const QString& capt); 0058 //! \return entered name text, always in lower case 0059 0060 QString nameText() const; 0061 0062 QString originalNameText() const; 0063 0064 void setNameText(const QString& name); 0065 0066 /*! Sets i18n'ed warning message displayed when user leaves 'name' field 0067 without filling it (if acceptsEmptyValue() is false). 0068 By default the message is equal "Please enter the name.". */ 0069 void setWarningForName(const QString& txt); 0070 0071 /*! Sets i18n'ed warning message displayed when user leaves 'name' field 0072 without filling it (if acceptsEmptyValue() is false). 0073 By default the message is equal "Please enter the caption." */ 0074 void setWarningForCaption(const QString& txt); 0075 0076 /*! \return true if name or caption is empty. */ 0077 bool empty() const; 0078 0079 KDbValidator *nameValidator() const; 0080 0081 /*! Adds subvalidator for name field. In fact it is added to internal 0082 multivalidator. If \a owned is true, \a validator will be owned by the object. 0083 \sa KDbMultiValidator::addSubvalidator(). */ 0084 void addNameSubvalidator(KDbValidator* validator, bool owned = true); 0085 0086 /*! \return true if name text cannot be empty (true by default). */ 0087 bool isNameRequired() const; 0088 0089 void setNameRequired(bool set); 0090 0091 /*! \return true if caption text cannot be empty (false by default). */ 0092 bool isCaptionRequired() const; 0093 0094 void setCaptionRequired(bool set); 0095 0096 public Q_SLOTS: 0097 /*! Clears both name and caption. */ 0098 virtual void clear(); 0099 0100 /*! Checks if both fields have valid values 0101 (i.e. not empty if acceptsEmptyValue() is false). 0102 If not, warning message is shown and false is returned. */ 0103 bool checkValidity(); 0104 0105 Q_SIGNALS: 0106 /*! Emitted whenever return key is pressed on name or caption label. */ 0107 void returnPressed(); 0108 0109 /*! Emitted whenever the caption or the name text changes */ 0110 void textChanged(); 0111 0112 /*! Emitted whenever the message changes */ 0113 void messageChanged(); 0114 0115 protected Q_SLOTS: 0116 void slotNameTextChanged(const QString&); 0117 void slotCaptionTextChanged(const QString&); 0118 0119 protected: 0120 void init( 0121 const QString& message, 0122 const QString& nameLabel, const QString& nameText, 0123 const QString& captionLabel, const QString& captionText); 0124 0125 QLabel *messageLabel() const; 0126 0127 private: 0128 class Private; 0129 Private * const d; 0130 0131 friend class KexiNameDialog; 0132 }; 0133 0134 #endif