1 /* This file is part of the KDE project 2 Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr> 3 Copyright (C) 2004-2012 Jarosław Staniek <staniek@kde.org> 4 Copyright (C) 2014 Wojciech Kosowicz <pcellix@gmail.com> 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Library General Public 8 License as published by the Free Software Foundation; either 9 version 2 of the License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Library General Public License for more details. 15 16 You should have received a copy of the GNU Library General Public License 17 along with this program; see the file COPYING. If not, write to 18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef KEXIDBTEXTEDIT_H 23 #define KEXIDBTEXTEDIT_H 24 25 #include <widget/dataviewcommon/kexiformdataiteminterface.h> 26 #include "kexidbtextwidgetinterface.h" 27 #include "kexidbutils.h" 28 #include <formeditor/FormWidgetInterface.h> 29 #include <KTextEdit> 30 #include <QPaintEvent> 31 32 class DataSourceLabel; 33 34 //! @short Multiline edit widget for Kexi forms 35 class KEXIFORMUTILS_EXPORT KexiDBTextEdit : public KTextEdit, 36 protected KexiDBTextWidgetInterface, 37 public KexiFormDataItemInterface, 38 public KFormDesigner::FormWidgetInterface 39 { 40 Q_OBJECT 41 Q_PROPERTY(QString dataSource READ dataSource WRITE setDataSource) 42 Q_PROPERTY(QString dataSourcePartClass READ dataSourcePluginId WRITE setDataSourcePluginId) 43 44 public: 45 explicit KexiDBTextEdit(QWidget *parent); 46 virtual ~KexiDBTextEdit(); 47 dataSource()48 inline QString dataSource() const { 49 return KexiFormDataItemInterface::dataSource(); 50 } dataSourcePluginId()51 inline QString dataSourcePluginId() const { 52 return KexiFormDataItemInterface::dataSourcePluginId(); 53 } 54 virtual QVariant value(); 55 virtual void setInvalidState(const QString& displayText); 56 57 //! \return true if editor's value is null (not empty) 58 //! Used for checking if a given constraint within table of form is met. 59 virtual bool valueIsNull(); 60 61 //! \return true if editor's value is empty (not necessary null). 62 //! Only few data types can accept "EMPTY" property 63 //! (use KDbField::hasEmptyProperty() to check this). 64 //! Used for checking if a given constraint within table or form is met. 65 virtual bool valueIsEmpty(); 66 67 /*! \return 'readOnly' flag for this widget. */ 68 virtual bool isReadOnly() const; 69 70 /*! \return the view widget of this item, e.g. line edit widget. */ 71 virtual QWidget* widget(); 72 73 virtual bool cursorAtStart(); 74 virtual bool cursorAtEnd(); 75 virtual void clear(); 76 77 void setColumnInfo(KDbConnection *conn, KDbQueryColumnInfo* cinfo) override; 78 79 /*! If \a displayDefaultValue is true, the value set by KexiDataItemInterface::setValue() 80 is displayed in a special way. Used by KexiFormDataProvider::fillDataItems(). 81 \a widget is equal to 'this'. 82 Reimplemented after KexiFormDataItemInterface. */ 83 virtual void setDisplayDefaultValue(QWidget* widget, bool displayDefaultValue); 84 85 //! Windows uses Ctrl+Tab for moving between tabs, so do not steal this shortcut 86 virtual void keyPressEvent(QKeyEvent *ke); 87 88 virtual bool event(QEvent *e); 89 90 //! Selects contents of the widget if there is such behaviour set (it is by default). 91 //! @todo add option for not selecting the field 92 virtual void selectAllOnFocusIfNeeded(); 93 94 public Q_SLOTS: 95 void setDataSource(const QString &ds); 96 97 void setDataSourcePluginId(const QString &pluginId); 98 99 virtual void setReadOnly(bool readOnly); 100 101 //! Reimplemented, so "undo" means the same as "cancelEditor" action 102 //! @todo enable "real" undo internally so user can use ctrl+z while editing 103 virtual void undo(); 104 105 //! Implemented for KexiDataItemInterface 106 virtual void moveCursorToEnd(); 107 108 //! Implemented for KexiDataItemInterface 109 virtual void moveCursorToStart(); 110 111 //! Implemented for KexiDataItemInterface 112 virtual void selectAll(); 113 114 protected Q_SLOTS: 115 void slotTextChanged(); 116 117 protected: 118 virtual void paintEvent(QPaintEvent *); 119 virtual void contextMenuEvent(QContextMenuEvent *e); 120 virtual void changeEvent(QEvent *e); 121 virtual void setValueInternal(const QVariant& add, bool removeOld); 122 virtual void focusOutEvent(QFocusEvent *e); 123 QMenu * createPopupMenu(const QPoint & pos); 124 void updateTextForDataSource(); 125 void createDataSourceLabel(); 126 void updatePalette(); 127 128 private: 129 //! Used for extending context menu 130 KexiDBWidgetContextMenuExtender m_menuExtender; 131 132 //! Used to disable slotTextChanged() 133 bool m_slotTextChanged_enabled; 134 135 DataSourceLabel *m_dataSourceLabel; 136 137 //! Text length allowed 138 int m_length; 139 140 QPalette m_originalPalette; //!< Used for read-only case 141 bool m_paletteChangeEvent_enabled; 142 }; 143 144 #endif 145