Olive
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | Private Slots | Private Attributes | List of all members
TextEditDialog Class Reference

The TextEditDialog class. More...

#include <texteditdialog.h>

Inheritance diagram for TextEditDialog:

Public Member Functions

 TextEditDialog (QWidget *parent=nullptr, const QString &s=nullptr, bool rich_text=true)
 TextEditDialog Constructor. More...
 
const QString & get_string ()
 Retrieve the current text in the dialog. More...
 

Private Slots

virtual void accept () override
 Override of accept() to store the entered text string so it can be retrieved by get_string(). More...
 
void SetFontWeight (int i)
 Slot for the font_weight combobox to set the font weight based on its data value. More...
 
void SetAlignmentFromProperty ()
 Slot for text alignment buttons to set alignment based on their properties. More...
 
void UpdateUIFromTextCursor ()
 Slot for when the text edit widget's cursor moves so the rich text toolbar can stay up to date. More...
 

Private Attributes

bool rich_text_
 Internal rich text mode value. More...
 
QString result_str
 Internal storage of text entered, saved when the user clicks OK. More...
 
QTextEdit * textEdit
 Main text editing widget. More...
 
QPushButton * italic_button
 Toggle button for setting the italic state of the currently selected text. More...
 
QPushButton * underline_button
 Toggle button for setting the underlined state of the currently selected text. More...
 
QFontComboBox * font_list
 ComboBox for the list of font families that the selected text can be set to. More...
 
QComboBox * font_weight
 ComboBox for the list of font weights that the selected text can be set to. More...
 
LabelSliderfont_size
 A slider to set the current font size. More...
 
ColorButtonfont_color
 A color selector for setting the current text color. More...
 
QPushButton * left_align_button
 Button for setting the current text row(s) to left alignment. More...
 
QPushButton * center_align_button
 Button for setting the current text row(s) to center alignment. More...
 
QPushButton * right_align_button
 Button for setting the current text row(s) to right alignment. More...
 
QPushButton * justify_align_button
 Button for setting the current text row(s) to justified alignment. More...
 

Detailed Description

The TextEditDialog class.

A separate window for editing text. This window can be resized arbitrarily and also provides a toolbar for rich text editing (if rich text is enabled). This dialog can be run from anywhere. Once the dialog has closed (i.e. returned from exec() ), the text entered into it can be retrieved using get_string().

TODO: Add a live signal for updating the calling function.

Constructor & Destructor Documentation

TextEditDialog::TextEditDialog ( QWidget *  parent = nullptr,
const QString &  s = nullptr,
bool  rich_text = true 
)

TextEditDialog Constructor.

Parameters
parentQWidget parent. Usually MainWindow.
sThe starting string when the dialog opens. It'll be read as rich text HTML or plain text based on the rich_text parameter (which defaults to rich text HTML). It can also be left empty to start blank.
rich_textSet the editing mode of the editor. If TRUE, the dialog will interpret the string in s as rich text HTML and also return rich text HTML through get_string(). It'll also show a toolbar with rich text options (i.e. font, italic, underline, size, etc.) If FALSE, the dialog will run in plain text mode interpreting the string in s as plain text and returning plain text through get_string(). It also will not show the rich text editing toolbar.

Member Function Documentation

void TextEditDialog::accept ( )
overrideprivatevirtualslot

Override of accept() to store the entered text string so it can be retrieved by get_string().

const QString & TextEditDialog::get_string ( )

Retrieve the current text in the dialog.

This function can be called after the user has accepted the dialog (i.e. made changes and clicked OK). This will return either plain text or rich text (HTML) depending on the mode it's running in (rich/plain text mode is set in the constructor). The value this returns only gets updated when the user clicks OK so it cannot be used to retrieve live text updates from the dialog.

Returns

The text entered once the user accepted this dialog.

void TextEditDialog::SetAlignmentFromProperty ( )
privateslot

Slot for text alignment buttons to set alignment based on their properties.

Intended slot for left_align_button, center_align_button, right_align_button, and justify_align_button. Pulls from their property("a") value which should be a member of the Qt::Alignment enum.

void TextEditDialog::SetFontWeight ( int  i)
privateslot

Slot for the font_weight combobox to set the font weight based on its data value.

Parameters
iIndex of the font_weight to retrieve the desired font weight from
void TextEditDialog::UpdateUIFromTextCursor ( )
privateslot

Slot for when the text edit widget's cursor moves so the rich text toolbar can stay up to date.

In rich text mode, different parts of a text document can be formatted in different ways. As the user moves around the text, the UI buttons should be consistent with whatever text is currently selected. This slot should therefore be connected to QTextEdit::cursorPositionChanged() and will change the "checked" state of the formatting buttons and current index of the comboboxes to match the currently selected text.

Member Data Documentation

QPushButton* TextEditDialog::center_align_button
private

Button for setting the current text row(s) to center alignment.

ColorButton* TextEditDialog::font_color
private

A color selector for setting the current text color.

QFontComboBox* TextEditDialog::font_list
private

ComboBox for the list of font families that the selected text can be set to.

LabelSlider* TextEditDialog::font_size
private

A slider to set the current font size.

QComboBox* TextEditDialog::font_weight
private

ComboBox for the list of font weights that the selected text can be set to.

QPushButton* TextEditDialog::italic_button
private

Toggle button for setting the italic state of the currently selected text.

QPushButton* TextEditDialog::justify_align_button
private

Button for setting the current text row(s) to justified alignment.

QPushButton* TextEditDialog::left_align_button
private

Button for setting the current text row(s) to left alignment.

QString TextEditDialog::result_str
private

Internal storage of text entered, saved when the user clicks OK.

bool TextEditDialog::rich_text_
private

Internal rich text mode value.

This is set in the constructor and cannot be changed during the lifetime of this dialog.

QPushButton* TextEditDialog::right_align_button
private

Button for setting the current text row(s) to right alignment.

QTextEdit* TextEditDialog::textEdit
private

Main text editing widget.

QPushButton* TextEditDialog::underline_button
private

Toggle button for setting the underlined state of the currently selected text.


The documentation for this class was generated from the following files: