1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the Qt Designer of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** GNU General Public License Usage 31 ** Alternatively, this file may be used under the terms of the GNU 32 ** General Public License version 3.0 as published by the Free Software 33 ** Foundation and appearing in the file LICENSE.GPL included in the 34 ** packaging of this file. Please review the following information to 35 ** ensure the GNU General Public License version 3.0 requirements will be 36 ** met: http://www.gnu.org/copyleft/gpl.html. 37 ** 38 ** $QT_END_LICENSE$ 39 ** 40 ****************************************************************************/ 41 42 // 43 // W A R N I N G 44 // ------------- 45 // 46 // This file is not part of the Qt API. It exists for the convenience 47 // of Qt Designer. This header 48 // file may change from version to version without notice, or even be removed. 49 // 50 // We mean it. 51 // 52 53 #ifndef TEXTPROPERTYEDITOR_H 54 #define TEXTPROPERTYEDITOR_H 55 56 #include "shared_global_p.h" 57 #include "shared_enums_p.h" 58 59 #include <QtGui/QWidget> 60 61 QT_BEGIN_NAMESPACE 62 63 namespace qdesigner_internal { 64 65 class PropertyLineEdit; 66 67 // Inline-Editor for text properties. Does escaping of newline characters 68 // to '\n' and back and provides validation modes. The interface 69 // corresponds to that of QLineEdit. 70 class QDESIGNER_SHARED_EXPORT TextPropertyEditor : public QWidget 71 { 72 TextPropertyEditor(const TextPropertyEditor &); 73 TextPropertyEditor& operator=(const TextPropertyEditor &); 74 Q_OBJECT 75 Q_PROPERTY(QString text READ text WRITE setText USER true) 76 public: 77 enum EmbeddingMode { 78 // Stand-alone widget 79 EmbeddingNone, 80 // Disable frame 81 EmbeddingTreeView, 82 // For editing in forms 83 EmbeddingInPlace 84 }; 85 86 enum UpdateMode { 87 // Emit textChanged() as the user types 88 UpdateAsYouType, 89 // Emit textChanged() only when the user finishes (for QUrl, etc.) 90 UpdateOnFinished 91 }; 92 93 explicit TextPropertyEditor(QWidget *parent = 0, EmbeddingMode embeddingMode = EmbeddingNone, TextPropertyValidationMode validationMode = ValidationMultiLine); 94 textPropertyValidationMode()95 TextPropertyValidationMode textPropertyValidationMode() const { return m_validationMode; } 96 void setTextPropertyValidationMode(TextPropertyValidationMode vm); 97 updateMode()98 UpdateMode updateMode() const { return m_updateMode; } setUpdateMode(UpdateMode um)99 void setUpdateMode(UpdateMode um) { m_updateMode = um; } 100 101 QString text() const; 102 103 virtual QSize sizeHint () const; 104 virtual QSize minimumSizeHint () const; 105 106 void setAlignment(Qt::Alignment alignment); 107 108 bool hasAcceptableInput() const; 109 110 // installs an event filter object on the private QLineEdit 111 void installEventFilter(QObject *filterObject); 112 113 // Replace newline characters by literal "\n" for inline editing 114 // in mode ValidationMultiLine 115 static QString stringToEditorString(const QString &s, TextPropertyValidationMode validationMode = ValidationMultiLine); 116 117 // Replace literal "\n" by actual new lines in mode ValidationMultiLine 118 static QString editorStringToString(const QString &s, TextPropertyValidationMode validationMode = ValidationMultiLine); 119 120 // Returns whether newline characters are valid in validationMode. 121 static bool multiLine(TextPropertyValidationMode validationMode); 122 123 signals: 124 void textChanged(const QString &text); 125 void editingFinished(); 126 127 public slots: 128 void setText(const QString &text); 129 void selectAll(); 130 void clear(); 131 132 protected: 133 void resizeEvent(QResizeEvent * event ); 134 135 private slots: 136 void slotTextChanged(const QString &text); 137 void slotTextEdited(); 138 void slotEditingFinished(); 139 140 private: 141 void setRegExpValidator(const QString &pattern); 142 void markIntermediateState(); 143 144 TextPropertyValidationMode m_validationMode; 145 UpdateMode m_updateMode; 146 PropertyLineEdit* m_lineEdit; 147 148 // Cached text containing real newline characters. 149 QString m_cachedText; 150 bool m_textEdited; 151 }; 152 } 153 154 QT_END_NAMESPACE 155 156 #endif // TEXTPROPERTYEDITOR_H 157