[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
klfmainwin.h
Go to the documentation of this file.
1 /***************************************************************************
2  * file klfmainwin.h
3  * This file is part of the KLatexFormula Project.
4  * Copyright (C) 2011 by Philippe Faist
5  * philippe.faist at bluewin.ch
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 /* $Id: klfmainwin.h 603 2011-02-26 23:14:55Z phfaist $ */
23 
24 #ifndef KLFMAINWIN_H
25 #define KLFMAINWIN_H
26 
27 #include <stdio.h>
28 
29 #include <QObject>
30 #include <QList>
31 #include <QFont>
32 #include <QCheckBox>
33 #include <QMenu>
34 #include <QTextEdit>
35 #include <QWidget>
36 #include <QMimeData>
37 #include <QThread>
38 #include <QMutex>
39 #include <QWaitCondition>
40 #include <QDialog>
41 
42 #include <klfbackend.h>
43 
44 #include <klflib.h>
45 #include <klfconfig.h>
46 #include <klflatexsymbols.h>
47 
48 
49 
50 class KLFLibBrowser;
51 class KLFStyleManager;
52 class KLFSettings;
54 class KLFLatexEdit;
55 
56 
57 
58 namespace Ui {
59  class KLFProgErr;
60  class KLFMainWin;
61 }
62 
63 class KLFMainWin;
64 
65 
66 class KLF_EXPORT KLFProgErr : public QDialog
67 {
68  Q_OBJECT
69 public:
70  KLFProgErr(QWidget *parent, QString errtext);
71  virtual ~KLFProgErr();
72 
73  static void showError(QWidget *parent, QString text);
74 
75 private:
76  Ui::KLFProgErr *u;
77 };
78 
79 
83 {
84 public:
87 
89  virtual QStringList supportedMimeFormats() = 0;
90 
96  virtual QString formatTitle(const QString& key) = 0;
97 
103  virtual QStringList formatFilePatterns(const QString& key) = 0;
104 
111  virtual bool saveToFile(const QString& key, const QString& fileName, const KLFBackend::klfOutput& output) = 0;
112 };
113 
123 class KLF_EXPORT KLFAbstractDataOpener
124 {
125 public:
126  KLFAbstractDataOpener(KLFMainWin *mainwin) : mMainWin(mainwin) { }
128 
130  virtual QStringList supportedMimeTypes() = 0;
131 
137  virtual bool canOpenFile(const QString& file) = 0;
138 
142  virtual bool canOpenData(const QByteArray& data) = 0;
143 
153  virtual bool openFile(const QString& file) = 0;
154 
166  virtual bool openData(const QByteArray& data, const QString& mimetype) = 0;
167 
168 protected:
170  KLFMainWin * mainWin() { return mMainWin; }
171 
172 private:
173  KLFMainWin *mMainWin;
174 };
175 
180 class KLF_EXPORT KLFPreviewBuilderThread : public QThread
181 {
182  Q_OBJECT
183 
184 public:
186  int labelwidth, int labelheight);
187  virtual ~KLFPreviewBuilderThread();
188  void run();
189 
190 signals:
191  void previewAvailable(const QImage& preview, bool latexerror);
192 
193 public slots:
194  bool inputChanged(const KLFBackend::klfInput& input);
195  void settingsChanged(const KLFBackend::klfSettings& settings, int labelwidth, int labelheight);
196 
197 protected:
200  int _lwidth, _lheight;
201 
204 
206  bool _abort;
207 };
208 
209 
210 class KLFAboutDialog;
211 class KLFWhatsNewDialog;
212 class KLFMainWinPopup;
213 
218 class KLF_EXPORT KLFMainWin : public QWidget
219 {
220  Q_OBJECT
221  Q_PROPERTY(QString widgetStyle READ widgetStyle WRITE setWidgetStyle)
222 
223 public:
224  KLFMainWin();
225  virtual ~KLFMainWin();
226 
228  void startupFinished();
229 
230  bool eventFilter(QObject *obj, QEvent *event);
231 
232  KLFStyle currentStyle() const;
233 
234  KLFBackend::klfSettings backendSettings() const { return _settings; }
235 
236  virtual QFont txtLatexFont() const;
237  virtual QFont txtPreambleFont() const;
238 
239  KLFBackend::klfSettings currentSettings() const { return _settings; }
240 
241  void applySettings(const KLFBackend::klfSettings& s);
242 
243  KLFBackend::klfOutput currentKLFBackendOutput() const { return _output; }
244 
245  enum altersetting_which { altersetting_LBorderOffset = 100,
254  altersetting_OutlineFonts
255  };
264  void alterSetting(altersetting_which, int ivalue);
266  void alterSetting(altersetting_which, QString svalue);
267 
268  KLFLibBrowser * libBrowserWidget() { return mLibBrowser; }
269  KLFLatexSymbols * latexSymbolsWidget() { return mLatexSymbols; }
270  KLFStyleManager * styleManagerWidget() { return mStyleManager; }
271  KLFSettings * settingsDialog() { return mSettingsDialog; }
272  QMenu * styleMenu() { return mStyleMenu; }
273  KLFLatexEdit *latexEdit();
274  KLFLatexSyntaxHighlighter * syntaxHighlighter();
275  KLFLatexSyntaxHighlighter * preambleSyntaxHighlighter();
276 
277  KLFConfig * klfConfig() { return & klfconfig; }
278 
279  QHash<QWidget*,bool> currentWindowShownStatus(bool mainWindowToo = false);
280  QHash<QWidget*,bool> prepareAllWindowShownStatus(bool visibleStatus, bool mainWindowToo = false);
281 
282  QString widgetStyle() const { return _widgetstyle; }
283 
284  void registerHelpLinkAction(const QString& path, QObject *object, const char * member, bool wantUrlParam);
285 
286  void registerOutputSaver(KLFAbstractOutputSaver *outputsaver);
287  void unregisterOutputSaver(KLFAbstractOutputSaver *outputsaver);
288 
289  void registerDataOpener(KLFAbstractDataOpener *dataopener);
290  void unregisterDataOpener(KLFAbstractDataOpener *dataopener);
291 
292  bool canOpenFile(const QString& fileName);
293  bool canOpenData(const QByteArray& data);
294  bool canOpenData(const QMimeData *mimeData);
295 
296 signals:
297 
298  void evaluateFinished(const KLFBackend::klfOutput& output);
299 
300  // dialogs (e.g. stylemanager) should connect to this in case styles change unexpectedly
301  void stylesChanged();
302 
303  void applicationLocaleChanged(const QString& newLocale);
304 
305 public slots:
306 
307  void slotEvaluate();
308  void slotClear() { slotClearLatex(); }
309  void slotClearLatex();
310  void slotClearAll();
311  void slotLibrary(bool showlib);
312  void slotLibraryButtonRefreshState(bool on);
313  void slotSymbols(bool showsymbs = true);
314  void slotSymbolsButtonRefreshState(bool on);
315  void slotExpandOrShrink();
316  void slotExpand(bool expanded = true);
317  void slotSetLatex(const QString& latex);
318  void slotSetMathMode(const QString& mathmode);
319  void slotSetPreamble(const QString& preamble);
322  void slotEnsurePreambleCmd(const QString& line);
323  void slotSetDPI(int DPI);
324  void slotSetFgColor(const QColor& fgcolor);
325  void slotSetFgColor(const QString& fgcolor);
326  void slotSetBgColor(const QColor& bgcolor);
327  void slotSetBgColor(const QString& bgcolor);
328 
329  // will actually save only if output non empty.
330  void slotEvaluateAndSave(const QString& output, const QString& format);
331 
332  bool openFile(const QString& file);
333  bool openFiles(const QStringList& fileList);
334  bool openData(const QMimeData *mimeData, bool *openerFound = NULL);
335  bool openData(const QByteArray& data);
336 
337  bool openLibFiles(const QStringList& files, bool showLibrary = true);
338  bool openLibFile(const QString& file, bool showLibrary = true);
339 
340  void setApplicationLocale(const QString& locale);
341 
342  void retranslateUi(bool alsoBaseUi = true);
343 
344  bool loadDefaultStyle();
345  bool loadNamedStyle(const QString& sty);
346 
347  void slotDrag();
348  void slotCopy();
349  void slotSave(const QString& suggestedFname = QString::null);
350  void slotSetExportProfile(const QString& exportProfile);
351 
352  void slotActivateEditor();
353  void slotActivateEditorSelectAll();
354 
355  void slotShowBigPreview();
356 
357  void slotPresetDPISender();
358  void slotLoadStyle(int stylenum);
359  void slotLoadStyle(const KLFStyle& style);
360  void slotSaveStyle();
361  void slotStyleManager();
362  void slotSettings();
363 
364 
365  void refreshWindowSizes();
366 
367  void refreshShowCorrectClearButton();
368 
369  void refreshStylePopupMenus();
370  void loadStyles();
371  void loadLibrary(); // load library stuff
372  void loadLibrarySavedState();
373  void saveStyles();
374  void restoreFromLibrary(const KLFLibEntry& entry, uint restoreflags);
375  void insertSymbol(const KLFLatexSymbol& symbol);
378  void insertDelimiter(const QString& delim, int charsBack = 1);
379  void saveSettings();
380  void saveLibraryState();
381  void loadSettings();
382 
383  void addWhatsNewText(const QString& htmlSnipplet);
384 
385  void showAbout();
386  void showWhatsNew();
387  void showSettingsHelpLinkAction(const QUrl& link);
388  void helpLinkAction(const QUrl& link);
389 
390  void setWidgetStyle(const QString& qtstyle);
391 
392  void setTxtLatexFont(const QFont& f);
393  void setTxtPreambleFont(const QFont& f);
394 
395  void showRealTimePreview(const QImage& preview, bool latexerror);
396 
397  void updatePreviewBuilderThreadInput();
398 
399  void displayError(const QString& errormsg);
400 
401  void setWindowShownStatus(const QHash<QWidget*,bool>& windowshownflags);
402 
403  void refreshAllWindowStyleSheets();
404 
405  void setQuitOnClose(bool quitOnClose);
406 
407  void quit();
408 
409 private slots:
410  // private : only as slot to an action containing the style # as user data
411  void slotLoadStyleAct();
412 
413  void slotOpenHistoryLibraryResource();
414 
415  void slotNewSymbolTyped(const QString& symbol);
416  void slotPopupClose();
417  void slotPopupAction(const QUrl& helpLinkUrl);
418  void slotPopupAcceptAll();
419 
420  void slotEditorContextMenuInsertActions(const QPoint& pos, QList<QAction*> *actionList);
421  void slotInsertMissingPackagesFromActionSender();
422 
423 protected:
424  Ui::KLFMainWin *u;
425 
432 
434 
436  struct HelpLinkAction {
437  HelpLinkAction(const QString& p, QObject *obj, const char *func, bool param)
438  : path(p), reciever(obj), memberFunc(func), wantParam(param) { }
442  bool wantParam;
443  };
445 
447 
449 
450  bool try_load_style_list(const QString& fileName);
451 
453 
456 
457  KLFBackend::klfSettings _settings; // settings we pass to KLFBackend
459 
460  KLFBackend::klfOutput _output; // output from KLFBackend
461  // KLFBackend::klfInput _lastrun_input; // input that generated _output (now _output.input)
462 
468 
470  void showExportMsgLabel(const QString& msg, int timeout = 3000);
472 
477  KLFBackend::klfInput collectInput(bool isFinal);
478 
480 
483 
484  bool event(QEvent *e);
485 #ifdef Q_WS_X11
486  bool x11Event(XEvent *event);
487 #endif
488  void childEvent(QChildEvent *e);
489  void closeEvent(QCloseEvent *e);
490  void hideEvent(QHideEvent *e);
491  void showEvent(QShowEvent *e);
492  void timerEvent(QTimerEvent *e);
493 
495 
504  // QHash<QWidget*, bool> _lastwindowshownstatus;
505  // QHash<QWidget*, QRect> _lastwindowgeometries;
506  // QHash<QWidget*, bool> _savedwindowshownstatus;
507 
509 
510  void getMissingCmdsFor(const QString& symbol, QStringList * missingCmds, QString *guiText,
511  bool wantHtmlText = true);
512 
515 };
516 
517 #endif
QHash< QWidget *, bool > pSavedWindowShownStatus
Definition: klfmainwin.h:503
KLFLatexSymbols * latexSymbolsWidget()
Definition: klfmainwin.h:269
QMenu * mStyleMenu
Definition: klfmainwin.h:452
QString _widgetstyle
Definition: klfmainwin.h:508
QWaitCondition _condnewinfoavail
Definition: klfmainwin.h:203
KLFConfig klfconfig
Definition: klfconfig.cpp:88
KLFStyleManager * mStyleManager
Definition: klfmainwin.h:428
bool _evaloutput_uptodate
Definition: klfmainwin.h:465
bool _ignore_close_event
Definition: klfmainwin.h:494
QList< KLFAbstractOutputSaver * > pOutputSavers
Definition: klfmainwin.h:513
virtual bool saveToFile(const QString &key, const QString &fileName, const KLFBackend::klfOutput &output)=0
KLFMainWin * mainWin()
Definition: klfmainwin.h:170
QHash< QWidget *, QRect > pLastWindowGeometries
Definition: klfmainwin.h:500
QList< HelpLinkAction > mHelpLinkActions
Definition: klfmainwin.h:444
KLFAbstractDataOpener(KLFMainWin *mainwin)
Definition: klfmainwin.h:126
QHash< QWidget *, bool > pLastWindowShownStatus
Definition: klfmainwin.h:499
x11Event(XEvent *event)
KLFLibResourceEngine * mHistoryLibResource
Definition: klfmainwin.h:446
QList< QWidget * > pWindowList
Definition: klfmainwin.h:496
Dialog that presents a selection of latex symbols to user.
virtual QStringList formatFilePatterns(const QString &key)=0
KLFStyleList _styles
Definition: klfmainwin.h:448
KLFBackend::klfOutput currentKLFBackendOutput() const
Definition: klfmainwin.h:243
QMenu * styleMenu()
Definition: klfmainwin.h:272
Structure that stores klatexformula's configuration in memory.
Definition: klfconfig.h:141
bool _firstshow
Definition: klfmainwin.h:455
showEvent(QShowEvent *event)
QList< KLFAbstractDataOpener * > pDataOpeners
Definition: klfmainwin.h:514
KLFAboutDialog * mAboutDialog
Definition: klfmainwin.h:430
bool _loadedlibrary
Definition: klfmainwin.h:454
A settings dialog.
Definition: klfsettings.h:46
QLabel * mExportMsgLabel
Definition: klfmainwin.h:469
KLFBackend::klfOutput _output
Definition: klfmainwin.h:460
hideEvent(QHideEvent *event)
QString widgetStyle() const
Definition: klfmainwin.h:282
HelpLinkAction(const QString &p, QObject *obj, const char *func, bool param)
Definition: klfmainwin.h:437
KLFBackend::klfSettings _settings
Definition: klfmainwin.h:199
KLFBackend::klfSettings _settings
Definition: klfmainwin.h:457
A text edit field that edits latex code.
Definition: klflatexedit.h:51
QSize _shrinkedsize
Definition: klfmainwin.h:481
KLFWhatsNewDialog * mWhatsNewDialog
Definition: klfmainwin.h:431
KLFBackend::klfSettings currentSettings() const
Definition: klfmainwin.h:239
KLFSettings * mSettingsDialog
Definition: klfmainwin.h:429
virtual ~KLFAbstractOutputSaver()
Definition: klfmainwin.h:86
KLFBackend::klfSettings backendSettings() const
Definition: klfmainwin.h:234
QList< QAction * > pExportProfileQuickMenuActionList
Definition: klfmainwin.h:479
An entry (single formula) in the library.
Definition: klflib.h:55
KLFLibBrowser * libBrowserWidget()
Definition: klfmainwin.h:268
KLFMainWinPopup * mPopup
Definition: klfmainwin.h:433
KLFLibBrowser * mLibBrowser
Definition: klfmainwin.h:426
KLFLatexSymbols * mLatexSymbols
Definition: klfmainwin.h:427
KLFBackend::klfInput _input
Definition: klfmainwin.h:198
closeEvent(QCloseEvent *event)
virtual QStringList supportedMimeFormats()=0
An abstract resource engine.
Definition: klflib.h:440
KLFPreviewBuilderThread * mPreviewBuilderThread
Definition: klfmainwin.h:467
KLFConfig * klfConfig()
Definition: klfmainwin.h:277
QSize _expandedsize
Definition: klfmainwin.h:482
virtual QString formatTitle(const QString &key)=0
event(QEvent *event)
virtual ~KLFAbstractDataOpener()
Definition: klfmainwin.h:127
Ui::KLFMainWin * u
Definition: klfmainwin.h:424
bool _settings_altered
Definition: klfmainwin.h:458
KLFStyleManager * styleManagerWidget()
Definition: klfmainwin.h:270
void slotClear()
Definition: klfmainwin.h:308
int pExportMsgLabelTimerId
Definition: klfmainwin.h:471
KLFSettings * settingsDialog()
Definition: klfmainwin.h:271

Generated by doxygen 1.8.6