00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef KLFMAINWIN_H
00025 #define KLFMAINWIN_H
00026
00027 #include <stdio.h>
00028
00029 #include <QObject>
00030 #include <QList>
00031 #include <QFont>
00032 #include <QCheckBox>
00033 #include <QMenu>
00034 #include <QTextEdit>
00035 #include <QWidget>
00036 #include <QMimeData>
00037 #include <QThread>
00038 #include <QMutex>
00039 #include <QWaitCondition>
00040 #include <QDialog>
00041
00042 #include <klfbackend.h>
00043
00044 #include <klflib.h>
00045 #include <klfconfig.h>
00046 #include <klflatexsymbols.h>
00047
00048
00049
00050 class KLFLibBrowser;
00051 class KLFStyleManager;
00052 class KLFSettings;
00053 class KLFLatexSyntaxHighlighter;
00054 class KLFLatexEdit;
00055
00056
00057
00058 namespace Ui {
00059 class KLFProgErr;
00060 class KLFMainWin;
00061 }
00062
00063 class KLFMainWin;
00064
00065
00066 class KLF_EXPORT KLFProgErr : public QDialog
00067 {
00068 Q_OBJECT
00069 public:
00070 KLFProgErr(QWidget *parent, QString errtext);
00071 virtual ~KLFProgErr();
00072
00073 static void showError(QWidget *parent, QString text);
00074
00075 private:
00076 Ui::KLFProgErr *u;
00077 };
00078
00079
00082 class KLFAbstractOutputSaver
00083 {
00084 public:
00085 KLFAbstractOutputSaver() { }
00086 virtual ~KLFAbstractOutputSaver() { }
00087
00089 virtual QStringList supportedMimeFormats() = 0;
00090
00096 virtual QString formatTitle(const QString& key) = 0;
00097
00103 virtual QStringList formatFilePatterns(const QString& key) = 0;
00104
00111 virtual bool saveToFile(const QString& key, const QString& fileName, const KLFBackend::klfOutput& output) = 0;
00112 };
00113
00123 class KLF_EXPORT KLFAbstractDataOpener
00124 {
00125 public:
00126 KLFAbstractDataOpener(KLFMainWin *mainwin) : mMainWin(mainwin) { }
00127 virtual ~KLFAbstractDataOpener() { }
00128
00130 virtual QStringList supportedMimeTypes() = 0;
00131
00137 virtual bool canOpenFile(const QString& file) = 0;
00138
00142 virtual bool canOpenData(const QByteArray& data) = 0;
00143
00153 virtual bool openFile(const QString& file) = 0;
00154
00166 virtual bool openData(const QByteArray& data, const QString& mimetype) = 0;
00167
00168 protected:
00170 KLFMainWin * mainWin() { return mMainWin; }
00171
00172 private:
00173 KLFMainWin *mMainWin;
00174 };
00175
00180 class KLF_EXPORT KLFPreviewBuilderThread : public QThread
00181 {
00182 Q_OBJECT
00183
00184 public:
00185 KLFPreviewBuilderThread(QObject *parent, KLFBackend::klfInput input, KLFBackend::klfSettings settings,
00186 int labelwidth, int labelheight);
00187 virtual ~KLFPreviewBuilderThread();
00188 void run();
00189
00190 signals:
00191 void previewAvailable(const QImage& preview, bool latexerror);
00192
00193 public slots:
00194 bool inputChanged(const KLFBackend::klfInput& input);
00195 void settingsChanged(const KLFBackend::klfSettings& settings, int labelwidth, int labelheight);
00196
00197 protected:
00198 KLFBackend::klfInput _input;
00199 KLFBackend::klfSettings _settings;
00200 int _lwidth, _lheight;
00201
00202 QMutex _mutex;
00203 QWaitCondition _condnewinfoavail;
00204
00205 bool _hasnewinfo;
00206 bool _abort;
00207 };
00208
00209
00210 class KLFAboutDialog;
00211 class KLFWhatsNewDialog;
00212 class KLFMainWinPopup;
00213
00218 class KLF_EXPORT KLFMainWin : public QWidget
00219 {
00220 Q_OBJECT
00221 Q_PROPERTY(QString widgetStyle READ widgetStyle WRITE setWidgetStyle)
00222
00223 public:
00224 KLFMainWin();
00225 virtual ~KLFMainWin();
00226
00228 void startupFinished();
00229
00230 bool eventFilter(QObject *obj, QEvent *event);
00231
00232 KLFStyle currentStyle() const;
00233
00234 KLFBackend::klfSettings backendSettings() const { return _settings; }
00235
00236 virtual QFont txtLatexFont() const;
00237 virtual QFont txtPreambleFont() const;
00238
00239 KLFBackend::klfSettings currentSettings() const { return _settings; }
00240
00241 void applySettings(const KLFBackend::klfSettings& s);
00242
00243 KLFBackend::klfOutput currentKLFBackendOutput() const { return _output; }
00244
00245 enum altersetting_which { altersetting_LBorderOffset = 100,
00246 altersetting_TBorderOffset,
00247 altersetting_RBorderOffset,
00248 altersetting_BBorderOffset,
00249 altersetting_TempDir,
00250 altersetting_Latex,
00251 altersetting_Dvips,
00252 altersetting_Gs,
00253 altersetting_Epstopdf,
00254 altersetting_OutlineFonts
00255 };
00264 void alterSetting(altersetting_which, int ivalue);
00266 void alterSetting(altersetting_which, QString svalue);
00267
00268 KLFLibBrowser * libBrowserWidget() { return mLibBrowser; }
00269 KLFLatexSymbols * latexSymbolsWidget() { return mLatexSymbols; }
00270 KLFStyleManager * styleManagerWidget() { return mStyleManager; }
00271 KLFSettings * settingsDialog() { return mSettingsDialog; }
00272 QMenu * styleMenu() { return mStyleMenu; }
00273 KLFLatexEdit *latexEdit();
00274 KLFLatexSyntaxHighlighter * syntaxHighlighter();
00275 KLFLatexSyntaxHighlighter * preambleSyntaxHighlighter();
00276
00277 KLFConfig * klfConfig() { return & klfconfig; }
00278
00279 QHash<QWidget*,bool> currentWindowShownStatus(bool mainWindowToo = false);
00280 QHash<QWidget*,bool> prepareAllWindowShownStatus(bool visibleStatus, bool mainWindowToo = false);
00281
00282 QString widgetStyle() const { return _widgetstyle; }
00283
00284 void registerHelpLinkAction(const QString& path, QObject *object, const char * member, bool wantUrlParam);
00285
00286 void registerOutputSaver(KLFAbstractOutputSaver *outputsaver);
00287 void unregisterOutputSaver(KLFAbstractOutputSaver *outputsaver);
00288
00289 void registerDataOpener(KLFAbstractDataOpener *dataopener);
00290 void unregisterDataOpener(KLFAbstractDataOpener *dataopener);
00291
00292 bool canOpenFile(const QString& fileName);
00293 bool canOpenData(const QByteArray& data);
00294 bool canOpenData(const QMimeData *mimeData);
00295
00296 signals:
00297
00298 void evaluateFinished(const KLFBackend::klfOutput& output);
00299
00300
00301 void stylesChanged();
00302
00303 void applicationLocaleChanged(const QString& newLocale);
00304
00305 public slots:
00306
00307 void slotEvaluate();
00308 void slotClear() { slotClearLatex(); }
00309 void slotClearLatex();
00310 void slotClearAll();
00311 void slotLibrary(bool showlib);
00312 void slotLibraryButtonRefreshState(bool on);
00313 void slotSymbols(bool showsymbs = true);
00314 void slotSymbolsButtonRefreshState(bool on);
00315 void slotExpandOrShrink();
00316 void slotExpand(bool expanded = true);
00317 void slotSetLatex(const QString& latex);
00318 void slotSetMathMode(const QString& mathmode);
00319 void slotSetPreamble(const QString& preamble);
00322 void slotEnsurePreambleCmd(const QString& line);
00323 void slotSetDPI(int DPI);
00324 void slotSetFgColor(const QColor& fgcolor);
00325 void slotSetFgColor(const QString& fgcolor);
00326 void slotSetBgColor(const QColor& bgcolor);
00327 void slotSetBgColor(const QString& bgcolor);
00328
00329
00330 void slotEvaluateAndSave(const QString& output, const QString& format);
00331
00332 bool openFile(const QString& file);
00333 bool openFiles(const QStringList& fileList);
00334 bool openData(const QMimeData *mimeData, bool *openerFound = NULL);
00335 bool openData(const QByteArray& data);
00336
00337 bool openLibFiles(const QStringList& files, bool showLibrary = true);
00338 bool openLibFile(const QString& file, bool showLibrary = true);
00339
00340 void setApplicationLocale(const QString& locale);
00341
00342 void retranslateUi(bool alsoBaseUi = true);
00343
00344 bool loadDefaultStyle();
00345 bool loadNamedStyle(const QString& sty);
00346
00347 void slotDrag();
00348 void slotCopy();
00349 void slotSave(const QString& suggestedFname = QString::null);
00350 void slotSetExportProfile(const QString& exportProfile);
00351
00352 void slotActivateEditor();
00353 void slotActivateEditorSelectAll();
00354
00355 void slotShowBigPreview();
00356
00357 void slotPresetDPISender();
00358 void slotLoadStyle(int stylenum);
00359 void slotLoadStyle(const KLFStyle& style);
00360 void slotSaveStyle();
00361 void slotStyleManager();
00362 void slotSettings();
00363
00364
00365 void refreshWindowSizes();
00366
00367 void refreshShowCorrectClearButton();
00368
00369 void refreshStylePopupMenus();
00370 void loadStyles();
00371 void loadLibrary();
00372 void loadLibrarySavedState();
00373 void saveStyles();
00374 void restoreFromLibrary(const KLFLibEntry& entry, uint restoreflags);
00375 void insertSymbol(const KLFLatexSymbol& symbol);
00378 void insertDelimiter(const QString& delim, int charsBack = 1);
00379 void saveSettings();
00380 void saveLibraryState();
00381 void loadSettings();
00382
00383 void addWhatsNewText(const QString& htmlSnipplet);
00384
00385 void showAbout();
00386 void showWhatsNew();
00387 void showSettingsHelpLinkAction(const QUrl& link);
00388 void helpLinkAction(const QUrl& link);
00389
00390 void setWidgetStyle(const QString& qtstyle);
00391
00392 void setTxtLatexFont(const QFont& f);
00393 void setTxtPreambleFont(const QFont& f);
00394
00395 void showRealTimePreview(const QImage& preview, bool latexerror);
00396
00397 void updatePreviewBuilderThreadInput();
00398
00399 void displayError(const QString& errormsg);
00400
00401 void setWindowShownStatus(const QHash<QWidget*,bool>& windowshownflags);
00402
00403 void refreshAllWindowStyleSheets();
00404
00405 void setQuitOnClose(bool quitOnClose);
00406
00407 void quit();
00408
00409 private slots:
00410
00411 void slotLoadStyleAct();
00412
00413 void slotOpenHistoryLibraryResource();
00414
00415 void slotNewSymbolTyped(const QString& symbol);
00416 void slotPopupClose();
00417 void slotPopupAction(const QUrl& helpLinkUrl);
00418 void slotPopupAcceptAll();
00419
00420 void slotEditorContextMenuInsertActions(const QPoint& pos, QList<QAction*> *actionList);
00421 void slotInsertMissingPackagesFromActionSender();
00422
00423 protected:
00424 Ui::KLFMainWin *u;
00425
00426 KLFLibBrowser *mLibBrowser;
00427 KLFLatexSymbols *mLatexSymbols;
00428 KLFStyleManager *mStyleManager;
00429 KLFSettings *mSettingsDialog;
00430 KLFAboutDialog *mAboutDialog;
00431 KLFWhatsNewDialog *mWhatsNewDialog;
00432
00433 KLFMainWinPopup *mPopup;
00434
00436 struct HelpLinkAction {
00437 HelpLinkAction(const QString& p, QObject *obj, const char *func, bool param)
00438 : path(p), reciever(obj), memberFunc(func), wantParam(param) { }
00439 QString path;
00440 QObject *reciever;
00441 QByteArray memberFunc;
00442 bool wantParam;
00443 };
00444 QList<HelpLinkAction> mHelpLinkActions;
00445
00446 KLFLibResourceEngine *mHistoryLibResource;
00447
00448 KLFStyleList _styles;
00449
00450 bool try_load_style_list(const QString& fileName);
00451
00452 QMenu *mStyleMenu;
00453
00454 bool _loadedlibrary;
00455 bool _firstshow;
00456
00457 KLFBackend::klfSettings _settings;
00458 bool _settings_altered;
00459
00460 KLFBackend::klfOutput _output;
00461
00462
00465 bool _evaloutput_uptodate;
00467 KLFPreviewBuilderThread *mPreviewBuilderThread;
00468
00469 QLabel *mExportMsgLabel;
00470 void showExportMsgLabel(const QString& msg, int timeout = 3000);
00471 int pExportMsgLabelTimerId;
00472
00477 KLFBackend::klfInput collectInput(bool isFinal);
00478
00479 QList<QAction*> pExportProfileQuickMenuActionList;
00480
00481 QSize _shrinkedsize;
00482 QSize _expandedsize;
00483
00484 bool event(QEvent *e);
00485 #ifdef Q_WS_X11
00486 bool x11Event(XEvent *event);
00487 #endif
00488 void childEvent(QChildEvent *e);
00489 void closeEvent(QCloseEvent *e);
00490 void hideEvent(QHideEvent *e);
00491 void showEvent(QShowEvent *e);
00492 void timerEvent(QTimerEvent *e);
00493
00494 bool _ignore_close_event;
00495
00496 QList<QWidget*> pWindowList;
00499 QHash<QWidget*,bool> pLastWindowShownStatus;
00500 QHash<QWidget*,QRect> pLastWindowGeometries;
00503 QHash<QWidget*,bool> pSavedWindowShownStatus;
00504
00505
00506
00507
00508 QString _widgetstyle;
00509
00510 void getMissingCmdsFor(const QString& symbol, QStringList * missingCmds, QString *guiText,
00511 bool wantHtmlText = true);
00512
00513 QList<KLFAbstractOutputSaver*> pOutputSavers;
00514 QList<KLFAbstractDataOpener*> pDataOpeners;
00515 };
00516
00517 #endif