1 // Copyright (C) 2015-2016 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : PyEditor_Widget.cxx
20 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
23 #include "PyEditor_Editor.h"
24 #include "PyEditor_FindTool.h"
25 #include "PyEditor_Widget.h"
27 #include <QVBoxLayout>
30 \class PyEditor_Widget
31 \brief Wraps Python editor with the find/replace functionality to a single widget.
36 \param parent Parent widget.
38 PyEditor_Widget::PyEditor_Widget( QWidget* parent )
41 myEditor = new PyEditor_Editor( this );
44 myFindTool = new PyEditor_FindTool( myEditor, this );
47 QVBoxLayout* layout = new QVBoxLayout( this );
48 layout->setContentsMargins( 0, 0, 0, 0 );
49 layout->setSpacing( 3 );
50 layout->addWidget( myEditor );
51 layout->addWidget( myFindTool );
53 connect( myEditor, SIGNAL( modificationChanged( bool ) ),
54 this, SIGNAL( modificationChanged( bool ) ) );
55 connect( myEditor, SIGNAL( undoAvailable( bool ) ),
56 this, SIGNAL( undoAvailable( bool ) ) );
57 connect( myEditor, SIGNAL( redoAvailable( bool ) ),
58 this, SIGNAL( redoAvailable( bool ) ) );
59 connect( myEditor, SIGNAL( copyAvailable( bool ) ),
60 this, SIGNAL( copyAvailable( bool ) ) );
62 connect( myEditor, SIGNAL( selectionChanged() ),
63 this, SIGNAL( selectionChanged() ) );
64 connect( myEditor, SIGNAL( textChanged() ),
65 this, SIGNAL( textChanged() ) );
66 connect( myEditor, SIGNAL( cursorPositionChanged() ),
67 this, SIGNAL( cursorPositionChanged() ) );
69 setFocusProxy( myEditor );
74 \return Pointer to editor.
76 PyEditor_Editor* PyEditor_Widget::editor()
83 \return Pointer to find tool.
85 PyEditor_FindTool* PyEditor_Widget::findTool()
91 \brief Get all custom keywords from editor.
92 \return List of keywords.
94 QStringList PyEditor_Widget::keywords() const
96 return myEditor->keywords();
100 \brief Set custom keywords to editor.
101 \param keywords List of keywords.
102 \param type Type of keywords (group id).
103 \param color Color of keywords.
105 void PyEditor_Widget::appendKeywords( const QStringList& keywords, int type, const QColor& color )
107 myEditor->appendKeywords( keywords, type, color );
111 \brief Remove given custom keywords from editor.
112 \param keywords List of keywords to remove.
114 void PyEditor_Widget::removeKeywords( const QStringList& keywords )
116 myEditor->removeKeywords( keywords );
120 \brief Get current editor's completion policy.
121 \return Completion policy (see PyEditor_Editor::CompletionPolicy).
123 int PyEditor_Widget::completionPolicy() const
125 return (int) myEditor->completionPolicy();
129 \brief Set editor's completion policy.
130 \param policy Completion policy (see PyEditor_Editor::CompletionPolicy).
132 void PyEditor_Widget::setCompletionPolicy( int policy )
134 myEditor->setCompletionPolicy( (PyEditor_Editor::CompletionPolicy) policy );
138 \brief Activate Find dialog.
140 void PyEditor_Widget::find()
142 myFindTool->activateFind();
146 \brief Activate Replace dialog.
148 void PyEditor_Widget::replace()
150 myFindTool->activateReplace();
154 \brief Undo last editor's operation.
156 void PyEditor_Widget::undo()
162 \brief Redo last undone editor's operation.
164 void PyEditor_Widget::redo()
170 \brief Cut text selected in editor and put it into clipboard.
172 void PyEditor_Widget::cut()
178 \brief Copy text selected in editor into clipboard.
180 void PyEditor_Widget::copy()
186 \brief Paste text from clipboard into editor.
188 void PyEditor_Widget::paste()
194 \brief Delete text selected in editor.
196 void PyEditor_Widget::deleteSelected()
198 myEditor->deleteSelected();
202 \brief Select all text in editor.
204 void PyEditor_Widget::selectAll()
206 myEditor->selectAll();
210 \brief Clear content of editor.
212 void PyEditor_Widget::clear()
218 \brief Set/clear modified flag of editor.
219 \param on 'Modified' flag's value.
221 void PyEditor_Widget::setModified( bool on )
223 myEditor->document()->setModified( on );
227 \brief Get modified flag of editor.
228 \return 'Modified' flag's value.
230 bool PyEditor_Widget::isModified()
232 return myEditor->document()->isModified();
236 \brief Set text to editor.
237 \param text Text to be put into editor.
239 void PyEditor_Widget::setText( const QString& text )
241 myEditor->setPlainText( text );
245 \brief Get text from editor.
246 \return Current editor contents.
248 QString PyEditor_Widget::text() const
250 return myEditor->toPlainText();