File indexing completed on 2024-05-12 16:40:53

0001 /* This file is part of the KDE project
0002    Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at>
0003    Copyright (C) 2004-2005 Jarosław Staniek <staniek@kde.org>
0004    Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Library General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 
0011    This program is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    Library General Public License for more details.
0015 
0016    You should have received a copy of the GNU Library General Public License
0017    along with this program; see the file COPYING.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #ifndef KEXIEDITOR_H
0023 #define KEXIEDITOR_H
0024 
0025 #include "kexiextwidgets_export.h"
0026 
0027 #include <KexiView.h>
0028 
0029 namespace KTextEditor
0030 {
0031 class Document;
0032 }
0033 
0034 //! An text editor view that uses both KTextEditor and KTextEdit
0035 /*! It is used for SQL and script editor. */
0036 class KEXIEXTWIDGETS_EXPORT KexiEditor : public KexiView
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041 
0042     /**
0043     * Constructor.
0044     *
0045     * \param parent The parent \a QWidget this KexiEditor is child
0046     *        of.  You don't need to free the KexiEditor cause Qt
0047     *        will handle that for us.
0048     * \param name The name this KexiEditor has. Used only for debugging.
0049     */
0050     explicit KexiEditor(QWidget *parent = 0);
0051 
0052     /**
0053     * Destructor.
0054     */
0055     virtual ~KexiEditor();
0056 
0057     /**
0058     * \return true if internally the KTextEditor::EditorChooser got
0059     * used else, if a simple KTextEdit is used, false is returned.
0060     */
0061     static bool isAdvancedEditor();
0062 
0063     /**
0064     * \return the text displayed in the editor-widget.
0065     */
0066     QString text();
0067 
0068     /**
0069     * Set the highlight-mode to \p highlightmodename . If
0070     * \a isAdvancedEditor returns false (KTextEdit is used
0071     * rather then KTextEditor), then the method just does
0072     * nothing. The \p highlightmodename could be any kind
0073     * of string like e.g. "python", "kjs" or "sql"
0074     * KTextEditor supports.
0075     */
0076     void setHighlightMode(const QString& highlightmodename);
0077 
0078     /**
0079     * Find row and column for this \p character and jump to the
0080     * position.
0081     */
0082     void jump(int character);
0083 
0084     /**
0085     * Set the cursor position to \p line and \p col .
0086     */
0087     void setCursorPosition(int line, int col);
0088 
0089     /**
0090     * Clear all remembered undo/redo-actions. Only
0091     * avaiable if \a isAdvancedEditor returns true.
0092     */
0093     void clearUndoRedo();
0094 
0095     /**
0096     * \return a default context menu implementation.
0097     */
0098     virtual QMenu* defaultContextMenu();
0099 
0100 public Q_SLOTS:
0101     /*! Sets editor's text to \a text. 'Dirty' flag remains unchanged. */
0102     void setText(const QString &text);
0103     /*! Display the configuration-dialog. Only avaiable if isAdvancedEditor() returns true. */
0104     void slotConfigureEditor();
0105 
0106 protected Q_SLOTS:
0107     void slotTextChanged(KTextEditor::Document *);
0108 
0109 protected:
0110     /*! Update the actions. This call is redirected to \a KexiView::updateActions */
0111     virtual void updateActions(bool activated) override;
0112 
0113 Q_SIGNALS:
0114     /*! Emitted if the text displayed in the editor changed. */
0115     void textChanged();
0116 
0117 private:
0118     /*! Private d-pointer class. */
0119     class Private;
0120     Private * const d;
0121 };
0122 
0123 #endif