1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 5 ** 6 ** This file is part of the Graphics Dojo project on Qt Labs. 7 ** 8 ** This file may be used under the terms of the GNU General Public 9 ** License version 2.0 or 3.0 as published by the Free Software Foundation 10 ** and appearing in the file LICENSE.GPL included in the packaging of 11 ** this file. Please review the following information to ensure GNU 12 ** General Public Licensing requirements will be met: 13 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and 14 ** http://www.gnu.org/copyleft/gpl.html. 15 ** 16 ** If you are unsure which license is appropriate for your use, please 17 ** contact the sales department at qt-sales@nokia.com. 18 ** 19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21 ** 22 ****************************************************************************/ 23 24 25 #ifndef HTML_EDITOR_H 26 #define HTML_EDITOR_H 27 28 #include <QMainWindow> 29 #include <QFrame> 30 #include <QProgressBar> 31 #include <QToolButton> 32 #include <QMenu> 33 #include <QAction> 34 #include <QBuffer> 35 #include <QByteArray> 36 #include <QXmlQuery> 37 #include <QStringList> 38 #include "highlighter.h" 39 40 class Ui_HTMLEditorMainWindow; 41 class Ui_InsertHtmlDialog; 42 class Ui_TablePropertyDialog; 43 44 class QLabel; 45 class QSlider; 46 class QUrl; 47 48 class HtmlEditor : public QMainWindow 49 { 50 Q_OBJECT 51 52 public: 53 QMap<QString, QString> templateMap; 54 QString myEditorName; 55 bool isEmbeddedEditor; 56 QString loadedContent; 57 QFrame *frameCornerWidget; 58 QMenu *menuSettings; 59 QToolButton *toolButtonSettings; 60 QAction *actionHideMenu; 61 QAction *actionReadOnly; 62 QAction *actionShowHTML; 63 QProgressBar *loadProgress; 64 bool loadActive; 65 bool stopLoading; 66 bool loadSuccess; 67 QStringList imageTypes; 68 QBuffer *xmlQueryBuffer; 69 QByteArray *xmlDocument; 70 QXmlQuery xmlQuery; 71 QStringList xmlResult; 72 73 HtmlEditor(QString, bool embedded = false, QWidget *parent = 0); 74 ~HtmlEditor(); 75 76 static QUrl guessUrlFromString(const QString &string); 77 QString &noScript(QString &); 78 79 protected: 80 virtual void closeEvent(QCloseEvent *e); 81 82 private: 83 void execCommand(const QString&); 84 void execCommand(const QString &cmd, const QString &arg); 85 bool queryCommandState(const QString&); 86 87 public slots: 88 void loadStarted(); 89 void loadProgressed(int); 90 void loadFinished(bool); 91 void fileNew(); 92 void fileNewFromTemplate(); 93 void fileRevert(); 94 void fileOpen(); 95 bool fileSave(); 96 bool fileSaveAs(); 97 void fileOpenInBrowser(); 98 void editSelectAll(); 99 void styleParagraph(); 100 void styleHeading1(); 101 void styleHeading2(); 102 void styleHeading3(); 103 void styleHeading4(); 104 void styleHeading5(); 105 void styleHeading6(); 106 void stylePreformatted(); 107 void styleAddress(); 108 void formatStrikeThrough(); 109 void formatAlignLeft(); 110 void formatAlignCenter(); 111 void formatAlignRight(); 112 void formatAlignJustify(); 113 void formatIncreaseIndent(); 114 void formatDecreaseIndent(); 115 void formatNumberedList(); 116 void formatBulletedList(); 117 void formatFontName(); 118 void formatFontSize(); 119 void formatTextColor(); 120 void formatBackgroundColor(); 121 void insertImageFromFile(); 122 void insertImageFromUrl(); 123 void createLink(); 124 void insertHtml(); 125 void insertTable(); 126 void zoomOut(); 127 void zoomIn(); 128 void adjustActions(); 129 void adjustWYSIWYG(); 130 void adjustHTML(); 131 void changeTab(int); 132 void openLink(const QUrl&); 133 void changeZoom(int); 134 void linkHovered(const QString &, const QString &, const QString &); 135 void adjustIconSizes(); 136 bool load(const QString &f); 137 bool loadCurrent(); 138 bool loadTemplate(const QString &f); 139 bool save(); 140 void setCurrentFileName(const QString &fileName); 141 void setCurrentTemplateName(const QString &templateName); 142 void hideTearOffMenus(); 143 void enableFileNewFromTemplateAction(bool enable = true); 144 void checkRevertStatus(); 145 void setContentEditable(bool); setLoadActive()146 void setLoadActive() { loadActive = true; } setLoadInactive()147 void setLoadInactive() { loadActive = false; } setLoadSuccess(bool success)148 void setLoadSuccess(bool success) { loadSuccess = success; } 149 void javaScriptWindowObjectCleared(); 150 void showHtmlTab(bool enable = true); 151 void closeXmlBuffer(); 152 void clearContent(); 153 154 // helper functions (not only) for template use 155 bool loadCurrentTemplate(); reloadTemplate()156 bool reloadTemplate() { return loadCurrentTemplate(); } 157 QString getIconData(); 158 QString getColor(QString currentColor = QString()); 159 QString getImage(QString currentImage = QString()); 160 bool isZippedImage(QString imageType); 161 QString getImageData(QString imageType); 162 bool queryXml(QString id, QString queryString, bool sort = true, QString systemEntityName = QString()) { return queryLocalXml(id, queryString, sort, systemEntityName); } 163 bool queryLocalXml(QString id, QString queryString, bool sort = true, QString systemEntityName = QString()); getXmlResult()164 QStringList getXmlResult() { return xmlResult; } 165 bool isBios(QString id); 166 bool isDevice(QString id); 167 QString romStatus(QString id, bool translated = false); 168 int rank(QString id); 169 QString comment(QString id); 170 QString systemInfo(QString id); 171 QString emuInfo(QString id); 172 QStringList videoSnapUrls(QString id); 173 QString softwareInfo(QString list, QString id); 174 void openLinkInDefaultBrowser(QString linkUrl); 175 QStringList customSystemArtwork(); 176 QStringList customSoftwareArtwork(); 177 bool customArtworkZipped(QString artworkName); 178 QString customSystemArtworkUrl(QString id, QString artworkName); 179 QString customSystemArtworkData(QString id, QString artworkName); 180 QString customSoftwareArtworkUrl(QString listName, QString softwareName, QString artworkName); 181 QString customSoftwareArtworkData(QString listName, QString softwareName, QString artworkName); 182 bool systemManualExists(const QString &id); 183 QStringList systemManualPaths(const QString &id); 184 QStringList systemManualUrls(const QString &id); 185 void openSystemManual(const QString &id); 186 bool softwareManualExists(const QString &list, const QString &id); 187 QStringList softwareManualPaths(const QString &list, const QString &id); 188 QStringList softwareManualUrls(const QString &list, const QString &id); 189 void openSoftwareManual(const QString &list, const QString &id); 190 QString operatingSystemName(); 191 192 private: 193 Ui_HTMLEditorMainWindow *ui; 194 QString fileName; 195 QString templateName; 196 bool htmlDirty; 197 bool wysiwygDirty; 198 bool generateEmptyContent; 199 bool localModified; 200 QString emptyContent; 201 QLabel *zoomLabel; 202 QSlider *zoomSlider; 203 Highlighter *highlighter; 204 Ui_InsertHtmlDialog *ui_dialog; 205 QDialog *insertHtmlDialog; 206 Ui_TablePropertyDialog *ui_tablePropertyDialog; 207 QDialog *tablePropertyDialog; 208 }; 209 210 #endif // HTML_EDITOR_H 211