All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Types | Public Slots | Signals | Public Member Functions
Qtilities::CoreGui::SearchBoxWidget Class Reference

The SearchBoxWidget class provides a ready to use search/replace widget. More...

#include <SearchBoxWidget.h>

List of all members.

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.

Detailed Description

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:

search_box_widget.jpg
Search Box Widget

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:

QPlainTextEdit* myTextEdit = new QPlainTextEdit;
SearchBoxWidget::SearchOptions search_options = 0;
SearchBoxWidget::ButtonFlags button_flags = 0;
SearchBoxWidget* searchBoxWidget = new SearchBoxWidget(search_options,SearchBoxWidget::SearchAndReplace,button_flags);
searchBoxWidget->setPlainTextEditor(myTextEdit);

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().


Member Enumeration Documentation

An enumeration which is used to indicate which buttons should be visible in the widget.

Enumerator:
NoButtons 

No buttons will be visible in the widget.

NextButtons 

The next buttons will be visible in the widget.

PreviousButtons 

The previous buttons will be visible in the widget.

HideButtonUp 

The button to hide the search box will be visible in the widget as a down arrow.

HideButtonDown 

The button to hide the search box will be visible in the widget as an up arrow.

An enumeration which indicates which search options must be present in the widget.

Enumerator:
CaseSensitive 

Indicates that an action to toggle case sensitivity must be present.

WholeWordsOnly 

Indicates that an action to toggle whole words only must be present.

RegEx 

Indicates that an action to toggle regular expressions must be present.

RegFixedString 

Indicates that an action to toggle regular expressions must be present.

RegWildcard 

Indicates that an action to toggle regular expressions must be present.

An enumeration which defines when notifications about changes to the search string is emitted.

Enumerator:
NotifyOnChange 

Notifications will be done everytime that the search string changed.

NotifyOnReturn 

Notifications will be done only when the user presses return.

An enumeration which is used to indicate in which mode the widget must be used.

Enumerator:
SearchOnly 

The widget will only show search related items.

SearchAndReplace 

The widget will show both show search and replace related items.

An enumeration which is used to indicate the target on which the search and place operations must be performed.

Enumerator:
ExternalTarget 

External target. Will emit needed signals for external target to connect to. This is the default.

TextEdit 

Text edit set using setTextEdit().

PlainTextEdit 

Plain text edit set using setPlainTextEdit().


Member Function Documentation

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.

See also:
setTextEditor();
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.

See also:
setPlainTextEditor();


Qtilities : Reference Documentation Back to top Copyright © 2009-2013, Jaco Naudé