MyQTextBrowser Class Reference

Text editor of Xiaoning's Diary. More...

#include <MyQtextBrowser.h>

List of all members.

Public Types

enum  CustomTextFormats { VideoPlayerTextFormat = QTextFormat::UserObject + 1, AudioPlayerTextFormat }
 Text format IDs for custom text format objects. More...
enum  TextFormatObjectProperties { VideoPlayer = 1, AudioPlayer }
 Property IDs for custom text format objects. More...
enum  FileSectionIdentifiers { HTML = 0, VIDEO_OBJECT }
 Identifier numbers for different blocks found from diary entry file. More...
enum  VideoObjectOptionIdentifiers { VIDEO_FILE_NAME = 0, VIDEO_LOCATION, VIDEO_VOLUME }
 Identifier numbers for different properties for embedded video object found from VIDEO_OBJECT block. More...

Public Slots

void ReloadDocument ()
 Slot to request reloading the content of the editor.

Signals

void insertPicture (QString relativeFilename, int width, int height)
 Signal to notify DiaryControls object to start picture insertion procedure.
void setHTMLToEditor (const QString &code)
 Connected to base classes insertHtml-slot.

Public Member Functions

 MyQTextBrowser (QWidget *parent)
void setMouseTracker (QWidget *mouseTracker)
 Set tracker widget for mouse move events.
void HandleUiLanguageChange ()
 Reload the texts in elemnets.
void setupVideoTextObject ()
 Initializes custom object for adding video to texts.
void insertVideoObject (const QString &filenameWithTotalPath)
 Inserts video object to the current location of text cursor.
QString getFormattedFile ()
bool insertFormattedFile (QFile &file)
 Load and insert a file that is formatted with new xiaonings_diary_file_format introduced in 0.13.
void insertLegacyHtmlFormatFile (QFile &file)
 Load and insert a file that is in old html format used in xiaoning's diary 0.01 - 0.12.
QStringList getreferencedFiles ()
 Create list of files the diary entry is linking to (pictures, videos etc.) doesn't return the content of background music playlist.

Static Public Member Functions

static QString getHTMLfromFormattedFile (QFile &file)
 Get html formatted file from the new file type intorduced in xiaoning's diary 0.13.

Protected Slots

void downloadFinished (int errorID)
 Handler for finished downloads.
void EntryChanged (int position, int charsRemoved, int charsAdded)
 Check if any custom text objects have been removed due to text change.
void sliderMoved (int position)
 Calls CheckVideoWidgetVisibilities() to update the visibilities of video objects.

Protected Member Functions

void mouseMoveEvent (QMouseEvent *event)
 Handler for mousemove event. Reports mouse movements to iMouseTracker.
void dropEvent (QDropEvent *event)
 Handler for drop events.
void dragEnterEvent (QDragEnterEvent *event)
 Handler for drag events.
void dragMoveEvent (QDragMoveEvent *event)
 Handler for drag move events.
void LoadVideoObject (QString &relativeFilename, int locationInText, int volume)
 Create a new video object loaded from a file and insert it to the text.
bool parseOption (int optionID, QFile &file)
 Parse a description of object block from a file and insert the object to the editor.
void AddVideoObjectToList (struct VideoTextobjectListEntry *newEntry)
 Add a new video object to internal list of video objects.
void CheckVideoObjectListAndDeleteRemoved (int StartPosRemoved, int EndPosRemoved)
 Walk through the list of video objects and compare their locations to start and end position of removal to determine if they were removed.
void UpdateVideoObjectLocations (int charsRemoved, int charsAdded, int position)
 Walk through the list of video objects and update their locations according to how many characters were added or removed and where.
void CheckVideoWidgetVisibilities ()
 Check what video object are within the editor area and hide the ones that are not.
void AddReferencedPictures (QStringList &fileList)
 Adds names of referenced pictures from currently open entry to fileList.
void WriteVideoObjectsToFile (QString &fileContents)
 Writes entries for referenced video objects to the end of QString fileContents passed as parameter.
void ReplaceCustomObjectsWithPlaceholders ()
 Walks through the lists of custom objects and replaces their ObjectReplacementCharacters with '*'.
void ReinsertCustomObjects ()
 Puts back the ObjectReplacementCharacters.
void ClearAllCustomObjects ()
 Delete all custom objects.

Private Attributes

struct VideoTextobjectListEntrystartPtr
 Pointer to the start of the list holding video objects embedded to the text. NULL if list is empty.
struct VideoTextobjectListEntryendPtr
 Pointer to the last entry of the list holding video objects embedded to the text. NULL if list is empty.
QWidget * iMouseTracker
 Pointer to widget that wants to track the mouse movements.
QWidget * iParent
 Stores the pointer to parent widget.
QFile iDownloadTargetFile
 File object to temporarily store downloaded data when downloading pictures from internet.
QString pictureFilename
 Stores the name of temporary file during download.
bool iDownloadInProgress
 Keeps track on if we are downloading something or not. We will handle only one picture addition at a time so refuse any drops while downloading.
HttpDownloaderiHttpDownloader
 Pointer to HttpDownloader object that handles downloading pictures from internet.
bool iProtectCustomObjects
 Protects custom objects from getting deleted when reloading the content of the editor.


Detailed Description

Text editor of Xiaoning's Diary.

Reimplements some functions from QTextBrowser to behave as text editor with drag and drop support.


Member Enumeration Documentation

Text format IDs for custom text format objects.

Enumerator:
VideoPlayerTextFormat  Indicates the textformat for video player.
AudioPlayerTextFormat  Indicates the textformat for audio player.

Note:
Audio player is not implemented yet. Will be done after I finish designing the general structure for handling custom text objects of multiple types.

Identifier numbers for different blocks found from diary entry file.

See also:
FileSectionIdentifierStrings
Enumerator:
HTML  This block contains html code for the entry.
VIDEO_OBJECT  This block contains information about embedded video object.

See also:
enum VideoObjectOptionIdentifiers

Property IDs for custom text format objects.

Enumerator:
VideoPlayer  Property for storing pointer to struct VideoTextobjectListEntry type of object.
AudioPlayer  Property for storing pointer to struct AudioTextobjectListEntry type of object.

Note:
Audio player is not implemented yet. Will be done after I finish designing the general structure for handling custom text objects of multiple types.

Identifier numbers for different properties for embedded video object found from VIDEO_OBJECT block.

See also:
VideoObjectOptionIdentifierStrings
Enumerator:
VIDEO_FILE_NAME  Property defines name of the video file attached to this video object.
VIDEO_LOCATION  Property defines location of the video object in the text.
VIDEO_VOLUME  Property defines the initial volume of the video.


Member Function Documentation

void MyQTextBrowser::AddReferencedPictures ( QStringList &  fileList  )  [protected]

Adds names of referenced pictures from currently open entry to fileList.

Parameters:
fileList List to which add the filenames.

void MyQTextBrowser::AddVideoObjectToList ( struct VideoTextobjectListEntry newEntry  )  [protected]

Add a new video object to internal list of video objects.

Parameters:
newEntry Pointer to the list entry structure that should be added to the list.

void MyQTextBrowser::CheckVideoObjectListAndDeleteRemoved ( int  StartPosRemoved,
int  EndPosRemoved 
) [protected]

Walk through the list of video objects and compare their locations to start and end position of removal to determine if they were removed.

Parameters:
StartPosRemoved Starting position of area from which characters were removed.
EndPosRemoved Ending position of area from which characters were removed.
If a video object is located between StartPosRemoved and EndPosRemoved it will be deleted and its entry will be removed from the list of video objects.

void MyQTextBrowser::downloadFinished ( int  errorID  )  [protected, slot]

Handler for finished downloads.

Connected to iHttpDownloader's HttpDownloader::downloadFinished(int errorID) signal. Closes temporary file (iDownloadTargetFile) and if download was succesfull will start scaling and adding procedure of the downloaded picture.

Parameters:
errorID ID of possible error passed by HttpDownloader *iHttpDownloader.
See also:
HttpDownloader::downloadFinished(int errorID)

void MyQTextBrowser::EntryChanged ( int  position,
int  charsRemoved,
int  charsAdded 
) [protected, slot]

Check if any custom text objects have been removed due to text change.

Connected to textdocuments contentsChange ( int position, int charsRemoved, int charsAdded ) signal that is emitted every time the entry is changed. Walks through the lists of custom textobjects and cleans them up if they are removed from entry

QString MyQTextBrowser::getFormattedFile (  ) 

Todo:
Walk through list of custom text objects and add them

Todo:
Add placeholders for custom text

QString MyQTextBrowser::getHTMLfromFormattedFile ( QFile &  file  )  [static]

Get html formatted file from the new file type intorduced in xiaoning's diary 0.13.

Parameters:
file Filehandle that holds the file.
Returns:
Html-part of the file.
The new filetype has a section containing some html code. This code part has all the actual text of the file so this function can be used for pulling out the text part for purposes suchs as searching certain phraces from the entries.

QStringList MyQTextBrowser::getreferencedFiles (  ) 

Create list of files the diary entry is linking to (pictures, videos etc.) doesn't return the content of background music playlist.

The function will search for <img> tags from html file in editor object and use ParseFileName( const QString &data, const int index, QStringList &fileList ) to get the names of pictures in <img> tags.

Other types of files are looked from the lists that hold information about custom text objects ( list generated by struct VideoTextobjectListEntry entries for referenced videos for example).

Returns:
List of files that are linked to in html file in editor.

Todo:
Add any files linked by custom text objects

void MyQTextBrowser::HandleUiLanguageChange (  ) 

Reload the texts in elemnets.

Called by Xiaoning's Diary when reload of UI language is required. This may be during start of the program or when user changes the UI language.

bool MyQTextBrowser::insertFormattedFile ( QFile &  file  ) 

Load and insert a file that is formatted with new xiaonings_diary_file_format introduced in 0.13.

Parameters:
file Filehandle that holds the formatted file.
Returns:
true if loading was succesfull, false if there was a problem.

void MyQTextBrowser::insertLegacyHtmlFormatFile ( QFile &  file  ) 

Load and insert a file that is in old html format used in xiaoning's diary 0.01 - 0.12.

Parameters:
file Filehandle that holds the file.

void MyQTextBrowser::insertPicture ( QString  relativeFilename,
int  width,
int  height 
) [signal]

Signal to notify DiaryControls object to start picture insertion procedure.

Connected to DiaryControls::insertAndScalePicture(QString relativeFilename, int width, int height). Signaled from dropEvent( QDropEvent * event ) when picture was dropped or downloadFinished(int errorID) when a picture was downloaded sucesfully.

Parameters:
relativeFilename filename relative to diary entry storage path (relative to path where html-files are stored).
width original width of the picture.
height original height of the picture.

void MyQTextBrowser::insertVideoObject ( const QString &  filenameWithTotalPath  ) 

Inserts video object to the current location of text cursor.

Parameters:
filenameWithTotalPath name and complete path of the file that should be set to this object.
This function will copy the video from filenameWithTotalPath to diary_entry_storage_path/DD_MM_YYYY/ and insert a video object that will play this copy to the text. The video object is inserted immediately with it's controls diasbled till copying is complete and the copy progress will be shown within the object.

void MyQTextBrowser::LoadVideoObject ( QString &  relativeFilename,
int  locationInText,
int  volume 
) [protected]

Create a new video object loaded from a file and insert it to the text.

Parameters:
relativeFilename name and path to the file relative to diary entry storage path.
locationInText location in the text where this object should be inserted.
volume Initial volume for this object.

bool MyQTextBrowser::parseOption ( int  optionID,
QFile &  file 
) [protected]

Parse a description of object block from a file and insert the object to the editor.

Parameters:
optionID ID of the option defined in enum FileSectionIdentifiers
  • If HTML will read lines till meets the END tag and insert the read lines to editor as html.
  • If VIDEO_OBJECT, will read lines and parse settings from them till meets END tag. The video object will be inserted to the text if parsing was success.
file The file from which we are reading.
Returns:
true on success, false if there was a problem parsing the block.

void MyQTextBrowser::ReinsertCustomObjects (  )  [protected]

Puts back the ObjectReplacementCharacters.

See also:
void ReplaceCustomObjectsWithPlaceholders()

void MyQTextBrowser::ReloadDocument (  )  [slot]

Slot to request reloading the content of the editor.

Sets iProtectCustomObjects, replaces all custom objects with * saves the content of editor to QString as html, clears the editor, sets previously saved content back to editor, replaces previously set * characters with object replacement characters for custom objects and resets iProtectCustomObjects.

void MyQTextBrowser::ReplaceCustomObjectsWithPlaceholders (  )  [protected]

Walks through the lists of custom objects and replaces their ObjectReplacementCharacters with '*'.

This function is used when reloading the content. When taking the content as html the ObjectReplacementCharacters are omitted so we need temporarily to replace them with something more visible. The ObjectReplacementCharacters are written back by ReinsertCustomObjects() after other content has been reloaded. This same method is used when saving and loading the entries to/from files.

void MyQTextBrowser::setMouseTracker ( QWidget *  mouseTracker  ) 

Set tracker widget for mouse move events.

Parameters:
mouseTracker Widget that we need to report the mouse movements within this editor to. Used for implement support for mouse tracking in background animations.

void MyQTextBrowser::UpdateVideoObjectLocations ( int  charsRemoved,
int  charsAdded,
int  position 
) [protected]

Walk through the list of video objects and update their locations according to how many characters were added or removed and where.

The function will go through the internal list of video objects and if the object is located at the same place or after the place pointed by position parameter, it's location is updated according to charsRemoved and charsAdded. This is done when ever the content of the text edit is changed.

Parameters:
charsRemoved How many characters were removed.
charsAdded How many characters were added.
position From what position characters werer removed or added.

void MyQTextBrowser::WriteVideoObjectsToFile ( QString &  fileContents  )  [protected]

Writes entries for referenced video objects to the end of QString fileContents passed as parameter.

Parameters:
fileContents string to which the entries should be added.


Member Data Documentation

File object to temporarily store downloaded data when downloading pictures from internet.

If a link to a picture that is located to internet is dropped, dropEvent( QDropEvent * event ) opens temporary file with iDownloadTargetFile and passes it to MyQTextBrowser::iHttpDownloader object when starting download. When download finishes downloadFinished(int errorID) will close the file and use pictureFilename to start picture addition procedure by signaling insertPicture(QString relativeFilename, int width, int height).

QWidget * MyQTextBrowser::iMouseTracker [private]

Pointer to widget that wants to track the mouse movements.

Pointer is used in mouseMoveEvent( QMouseEvent * event ) and set by calling setMouseTracker(QWidget *mouseTracker).

QWidget * MyQTextBrowser::iParent [private]

Stores the pointer to parent widget.

Used in mouseMoveEvent( QMouseEvent * event ) for calculating the actual coordinates of the mouse cursor in relation to te main window.

Protects custom objects from getting deleted when reloading the content of the editor.

The editor is emptied as part of the reloading process and if there wouldn't be any protection the custom objects would be deleted at the same. This is not what I want to happen so set this true before starting the reload procedure and set back to false after it's done.

Stores the name of temporary file during download.

Used in dropEvent( QDropEvent * event ) and downloadFinished(int errorID).

See also:
iDownloadTargetFile


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

Generated on Thu Mar 3 17:42:04 2011 for Xiaoning's Diary by  doxygen 1.5.9