The SearchBoxWidget class provides a ready to use search/replace widget. More...
#include <SearchBoxWidget.h>
Public Types | |
enum | ButtonFlag { NoButtons = 0, NextButtons = 1, PreviousButtons = 2, HideButtonUp = 4, HideButtonDown = 8 } |
An enumeration which is used to indicate which buttons should be visible in the widget. More... | |
enum | SearchOption { CaseSensitive = 1, WholeWordsOnly = 2, RegEx = 4, RegFixedString = 8, RegWildcard = 16 } |
An enumeration which indicates which search options must be present in the widget. More... | |
enum | SearchStringChangedNotificationMode { NotifyOnChange, NotifyOnReturn } |
An enumeration which defines when notifications about changes to the search string is emitted. More... | |
enum | WidgetMode { SearchOnly, SearchAndReplace } |
An enumeration which is used to indicate in which mode the widget must be used. More... | |
enum | WidgetTarget { ExternalTarget, TextEdit, PlainTextEdit } |
An enumeration which is used to indicate the target on which the search and place operations must be performed. More... |
Public Slots | |
void | setCurrentReplaceString (const QString &replace_string) |
Gets the current replace string in the replace text box. | |
void | setCurrentSearchString (const QString &search_string) |
Sets the current search string in the search text box. |
Signals | |
void | btnClose_clicked () |
Indicates that the close button was clicked. | |
void | btnFindNext_clicked () |
Indicates that the find next button was clicked. | |
void | btnFindPrevious_clicked () |
Indicates that the find previous button was clicked. | |
void | btnReplaceAll_clicked () |
Indicates that the replace all button was clicked. | |
void | btnReplaceNext_clicked () |
Indicates that the replace next button was clicked. | |
void | btnReplacePrevious_clicked () |
Indicates that the replace previous button was clicked. | |
void | replaceStringChanged (const QString &string) |
Signal emitted when the replace string changes with the new string passed as the paramater. | |
void | searchOptionsChanged () |
Indicates that the search options changed. | |
void | searchStringChanged (const QString &string) |
Signal emitted when the search string changes with the new string passed as the paramater. |
Public Member Functions | |
ButtonFlags | buttonFlags () const |
Function to get the button flags of the widget. | |
bool | caseSensitive () const |
Indicates if the search string must be handled in a case sensitive way. | |
void | clearInfoText () |
Clears the information string text. | |
QString | currentReplaceString () const |
Sets the current replace string in the replace text box. | |
QString | currentSearchString () const |
Gets the current search string in the search text box. | |
QTextDocument::FindFlags | findFlags () const |
Function which returns the QTextDocument::FindFlags for the current search options. | |
QString | infoText () const |
Gets the information string text. | |
QRegExp::PatternSyntax | patternSyntax () const |
Indicates if the search string must be interpreted as a regular expression. | |
QPlainTextEdit * | plainTextEditor () const |
Returns a reference to the plain text editor on which this widget performs its operations. | |
SearchBoxWidget (SearchOptions search_options=AllSearchOptions, WidgetMode mode=SearchOnly, ButtonFlags buttons=AllButtons, QWidget *parent=0) | |
Constructs a search box widget using the paramaters to customize the look of the widget. | |
SearchOptions | searchOptions () const |
Function to get the search options of the widget. | |
QMenu * | searchOptionsMenu () |
Function providing access to the search options menu. | |
SearchStringChangedNotificationMode | searchStringNotificationMode () const |
Gets the search string notification mode. | |
void | setButtonFlags (ButtonFlags button_flags) |
Function to set the button flags of the widget. | |
void | setCaseSensitive (bool toggle) |
Sets the case sensitivity search option. | |
void | setEditorFocus (bool select_text=true) |
Sets focus to the search string text editor. | |
void | setInfoText (const QString &info_text) |
Sets the information string text. | |
void | setMessage (const QString &message) |
Function to set the message string displayed in the search box. | |
void | setPatternSyntax (QRegExp::PatternSyntax pattern_syntax) |
Sets the regular expression search option. | |
void | setPlainTextEditor (QPlainTextEdit *plainTextEdit) |
Sets the text editor on which this widget must operate. | |
void | setSearchOptions (SearchOptions search_options) |
Function to set the search options of the widget. | |
void | setSearchStringNotificationMode (SearchStringChangedNotificationMode notification_mode) |
Sets the search string notification mode. | |
void | setTextEditor (QTextEdit *textEdit) |
Sets the text editor on which this widget must operate. | |
void | setWholeWordsOnly (bool toggle) |
Sets the whole words only search option. | |
void | setWidgetMode (WidgetMode widget_mode) |
Function to set the WidgetMode of the widget. | |
QTextEdit * | textEditor () const |
Returns a reference to the text editor on which this widget performs its operations. | |
bool | wholeWordsOnly () const |
Indicates if the search string must match only whole words. | |
WidgetMode | widgetMode () const |
Function to get the WidgetMode of the widget. | |
WidgetTarget | widgetTarget () const |
Current widget target. |
The SearchBoxWidget class provides a ready to use search/replace widget.
The search box widget is a generic, parameterizable search box widget. It is usually embedded into other widgets and connected to those widgets. It supports both a search only mode and a search and replace mode set using the setWidgetMode() function. The buttons shown are set using setButtonFlags() and the search options available to the user are set using setSearchOptions().
The widget in search and replace mode with all buttons enabled is shown below:
By default, the widget can be embedded anywhere as shown in the example below. When used in this way, the widget emits signals such as searchStringChanged(), searchOptionsChanged(), btnFindNext_clicked() etc. A signal is emitted for each button that is pressed.
The widget can also be used directly on a QTextEdit window by calling the setTextEdit() function. Alternatively it can be used on a QPlainTextEdit by calling the setPlainTextEditor() functions. When calling both these functions, the one that was called last will be used and at any time you can check what the widget target is using widgetTarget().
For example, if you want to use the search box widget to search and/or replace the contents of a QPlainTextEdit, you can do the following:
When using the search box widget with text edit and plain text edit targets, the buttons (except the HideButton) will not trigger their signals and the search string related signals will not trigger either. The widget will handle these buttons directly on the specified text edit. The behavior of the replace buttons will also change. They will only be enabled when text is selected in the text editor. The Qtilities::CoreGui::CodeEditorWidget uses the SearchBoxWidget class in this way.
The drop down menu provided next to the Search string text box can be extended with custom actions by modifying the QMenu reference provided by searchOptionsMenu().
An enumeration which is used to indicate which buttons should be visible in the widget.
An enumeration which indicates which search options must be present in the widget.
An enumeration which is used to indicate the target on which the search and place operations must be performed.
QMenu * Qtilities::CoreGui::SearchBoxWidget::searchOptionsMenu | ( | ) |
Function providing access to the search options menu.
This reference can be used to add menu items to the search options menu.
void Qtilities::CoreGui::SearchBoxWidget::setPlainTextEditor | ( | QPlainTextEdit * | plainTextEdit | ) |
Sets the text editor on which this widget must operate.
The widget can also be used directly on a QPlainTextEdit window by calling the setTextEdit() function. When using the search box widget in this way, the buttons (except the HideButton) will not trigger their signals and the search string related signals will not trigger either. The widget will handle these buttons directly on the specified text edit.
void Qtilities::CoreGui::SearchBoxWidget::setTextEditor | ( | QTextEdit * | textEdit | ) |
Sets the text editor on which this widget must operate.
The widget can also be used directly on a QTextEdit window by calling the setTextEdit() function. When using the search box widget in this way, the buttons (except the HideButton) will not trigger their signals and the search string related signals will not trigger either. The widget will handle these buttons directly on the specified text edit.
Qtilities : Reference Documentation | Back to top |
Copyright © 2009-2013, Jaco Naudé
|