#include <MyQtextBrowser.h>
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 VideoTextobjectListEntry * | startPtr |
Pointer to the start of the list holding video objects embedded to the text. NULL if list is empty. | |
struct VideoTextobjectListEntry * | endPtr |
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. | |
HttpDownloader * | iHttpDownloader |
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. |
Reimplements some functions from QTextBrowser to behave as text editor with drag and drop support.
Text format IDs for custom text format objects.
Identifier numbers for different blocks found from diary entry file.
HTML | This block contains html code for the entry. |
VIDEO_OBJECT |
This block contains information about embedded video object.
|
Property IDs for custom text format objects.
VideoPlayer | Property for storing pointer to struct VideoTextobjectListEntry type of object. |
AudioPlayer |
Property for storing pointer to struct AudioTextobjectListEntry type of object.
|
Identifier numbers for different properties for embedded video object found from VIDEO_OBJECT block.
void MyQTextBrowser::AddReferencedPictures | ( | QStringList & | fileList | ) | [protected] |
Adds names of referenced pictures from currently open entry to fileList.
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.
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.
StartPosRemoved | Starting position of area from which characters were removed. | |
EndPosRemoved | Ending position of area from which characters were removed. |
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.
errorID | ID of possible error passed by HttpDownloader *iHttpDownloader. |
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 | ( | ) |
QString MyQTextBrowser::getHTMLfromFormattedFile | ( | QFile & | file | ) | [static] |
Get html formatted file from the new file type intorduced in xiaoning's diary 0.13.
file | Filehandle that holds the file. |
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).
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.
file | Filehandle that holds the formatted file. |
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.
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.
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.
filenameWithTotalPath | name and complete path of the file that should be set to this 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.
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.
optionID | ID of the option defined in enum FileSectionIdentifiers
| |
file | The file from which we are reading. |
void MyQTextBrowser::ReinsertCustomObjects | ( | ) | [protected] |
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.
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.
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.
fileContents | string to which the entries should be added. |
QFile MyQTextBrowser::iDownloadTargetFile [private] |
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.
MyQTextBrowser::iProtectCustomObjects [private] |
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.
QString MyQTextBrowser::pictureFilename [private] |
Stores the name of temporary file during download.
Used in dropEvent( QDropEvent * event ) and downloadFinished(int errorID).