[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
klflatexsymbols.h
Go to the documentation of this file.
1 /***************************************************************************
2  * file klflatexsymbols.h
3  * This file is part of the KLatexFormula Project.
4  * Copyright (C) 2011 by Philippe Faist
5  * philippe.faist@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: klflatexsymbols.h 603 2011-02-26 23:14:55Z phfaist $ */
23 
24 #ifndef KLFLATEXSYMBOLS_H
25 #define KLFLATEXSYMBOLS_H
26 
27 #include <QList>
28 #include <QString>
29 #include <QStringList>
30 #include <QEvent>
31 #include <QStackedWidget>
32 #include <QLayout>
33 #include <QGridLayout>
34 #include <QSpacerItem>
35 #include <QPushButton>
36 #include <QScrollArea>
37 #include <QDomElement>
38 
39 #include <klfbackend.h>
40 
41 #include <klfsearchbar.h>
42 #include <klfiteratorsearchable.h>
43 
45 struct KLF_EXPORT KLFLatexSymbol
46 {
47  KLFLatexSymbol() : symbol(), preamble(), textmode(false), hidden(true) { }
48  KLFLatexSymbol(const QString& s, const QStringList& p, bool txtmod)
49  : symbol(s), preamble(p), textmode(txtmod), hidden(false) { }
50  KLFLatexSymbol(const QDomElement& e);
51 
52  inline bool valid() const { return !symbol.isEmpty(); }
53 
56  bool textmode;
57  struct BBOffset {
58  BBOffset(int top = 0, int ri = 0, int bo = 0, int le = 0) : t(top), r(ri), b(bo), l(le) { }
59  int t, r, b, l;
60  } bbexpand;
61 
62  bool hidden;
63 };
64 
65 
66 
67 class KLF_EXPORT KLFLatexSymbolsCache
68 {
69 public:
70  enum { Ok = 0, BadHeader, BadVersion };
71 
72  inline bool cacheNeedsSave() const { return flag_modified; }
73 
74  QPixmap getPixmap(const KLFLatexSymbol& sym, bool fromcacheonly = true);
75 
76  int precacheList(const QList<KLFLatexSymbol>& list, bool userfeedback, QWidget *parent = NULL);
77 
78  void setBackendSettings(const KLFBackend::klfSettings& settings);
79 
80  KLFLatexSymbol findSymbol(const QString& symbolCode);
81  QStringList symbolCodeList();
82  QPixmap findSymbolPixmap(const QString& symbolCode);
83 
84  static KLFLatexSymbolsCache * theCache();
85  static void saveTheCache();
86 
87 private:
91  KLFLatexSymbolsCache(const KLFLatexSymbolsCache& /*other*/) { }
92 
94  bool flag_modified;
95  KLFBackend::klfSettings backendsettings;
96 
97  int loadCacheStream(QDataStream& stream);
98  int saveCacheStream(QDataStream& stream);
99 
100  static KLFLatexSymbolsCache * staticCache;
101 
104  int loadCacheFrom(const QString& file, int version);
105 };
106 
107 
108 
109 class KLF_EXPORT KLFLatexSymbolsView : public QScrollArea, public KLFIteratorSearchable<int>
110 {
111  Q_OBJECT
112 public:
113  KLFLatexSymbolsView(const QString& category, QWidget *parent);
114 
115  void setSymbolList(const QList<KLFLatexSymbol>& symbols);
116  void appendSymbolList(const QList<KLFLatexSymbol>& symbols);
117 
118  QString category() const { return _category; }
119 
120  // reimplemented from KLFIteratorSearchable
121 
122  virtual SearchIterator searchIterBegin() { return 0; }
123  virtual SearchIterator searchIterEnd() { return mSymbols.size(); }
124 
125  virtual bool searchIterMatches(const SearchIterator& pos, const QString& queryString);
126 
127  virtual void searchPerformed(const SearchIterator& result);
128  virtual void searchAbort();
129 
130 signals:
131  void symbolActivated(const KLFLatexSymbol& symb);
132 
133 public slots:
134  void buildDisplay();
135  void recalcLayout();
136 
137 protected slots:
138  void slotSymbolActivated();
139 
140 protected:
143 
144 private:
145  QWidget *mFrame;
146  QGridLayout *mLayout;
147  QSpacerItem *mSpacerItem;
148  QList<QWidget*> mSymbols;
149 
150  void highlightSearchMatches(int currentMatch);
151 };
152 
153 
154 namespace Ui {
155  class KLFLatexSymbols;
156 }
157 
158 
161 class KLF_EXPORT KLFLatexSymbols : public QWidget
162 {
163  Q_OBJECT
164 public:
165  KLFLatexSymbols(QWidget* parent, const KLFBackend::klfSettings& baseSettings);
166  ~KLFLatexSymbols();
167 
168  bool event(QEvent *event);
169 
170 signals:
171 
172  void insertSymbol(const KLFLatexSymbol& symb);
173 
174 public slots:
175 
176  void slotShowCategory(int cat);
177 
178  void retranslateUi(bool alsoBaseUi = true);
179 
180 protected:
182 
184 
185  void closeEvent(QCloseEvent *ev);
186  void showEvent(QShowEvent *ev);
187 
188 private:
189  Ui::KLFLatexSymbols *u;
190 
191  KLFSearchBar * pSearchBar;
192 
193  void read_symbols_create_ui();
194 };
195 
196 
197 KLF_EXPORT bool operator==(const KLFLatexSymbol& a, const KLFLatexSymbol& b);
198 
199 
200 
201 #endif
202 
QList< KLFLatexSymbol > _symbols
QString category() const
virtual bool searchIterMatches(const SearchIterator &pos, const QString &queryString)=0
QStringList preamble
QStackedWidget * stkViews
virtual SearchIterator searchIterBegin()
bool valid() const
QList< KLFLatexSymbolsView * > mViews
Dialog that presents a selection of latex symbols to user.
virtual void searchPerformed(const SearchIterator &resultMatchPosition)
showEvent(QShowEvent *event)
virtual void searchAbort()
BBOffset(int top=0, int ri=0, int bo=0, int le=0)
KLFLatexSymbol(const QString &s, const QStringList &p, bool txtmod)
KLF_EXPORT bool operator==(const KLFLatexSymbol &a, const KLFLatexSymbol &b)
closeEvent(QCloseEvent *event)
event(QEvent *event)
virtual SearchIterator searchIterEnd()
bool cacheNeedsSave() const

Generated by doxygen 1.8.5