Go to the documentation of this file.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 KLFLATEXSYMBOLS_H
00025 #define KLFLATEXSYMBOLS_H
00026
00027 #include <QList>
00028 #include <QString>
00029 #include <QStringList>
00030 #include <QEvent>
00031 #include <QStackedWidget>
00032 #include <QLayout>
00033 #include <QGridLayout>
00034 #include <QSpacerItem>
00035 #include <QPushButton>
00036 #include <QScrollArea>
00037 #include <QDomElement>
00038
00039 #include <klfbackend.h>
00040
00041 #include <klfsearchbar.h>
00042 #include <klfiteratorsearchable.h>
00043
00045 struct KLF_EXPORT KLFLatexSymbol
00046 {
00047 KLFLatexSymbol() : symbol(), preamble(), textmode(false), hidden(true) { }
00048 KLFLatexSymbol(const QString& s, const QStringList& p, bool txtmod)
00049 : symbol(s), preamble(p), textmode(txtmod), hidden(false) { }
00050 KLFLatexSymbol(const QDomElement& e);
00051
00052 inline bool valid() const { return !symbol.isEmpty(); }
00053
00054 QString symbol;
00055 QStringList preamble;
00056 bool textmode;
00057 struct BBOffset {
00058 BBOffset(int top = 0, int ri = 0, int bo = 0, int le = 0) : t(top), r(ri), b(bo), l(le) { }
00059 int t, r, b, l;
00060 } bbexpand;
00061
00062 bool hidden;
00063 };
00064
00065
00066
00067 class KLF_EXPORT KLFLatexSymbolsCache
00068 {
00069 public:
00070 enum { Ok = 0, BadHeader, BadVersion };
00071
00072 inline bool cacheNeedsSave() const { return flag_modified; }
00073
00074 QPixmap getPixmap(const KLFLatexSymbol& sym, bool fromcacheonly = true);
00075
00076 int precacheList(const QList<KLFLatexSymbol>& list, bool userfeedback, QWidget *parent = NULL);
00077
00078 void setBackendSettings(const KLFBackend::klfSettings& settings);
00079
00080 KLFLatexSymbol findSymbol(const QString& symbolCode);
00081 QStringList symbolCodeList();
00082 QPixmap findSymbolPixmap(const QString& symbolCode);
00083
00084 static KLFLatexSymbolsCache * theCache();
00085 static void saveTheCache();
00086
00087 private:
00089 KLFLatexSymbolsCache();
00091 KLFLatexSymbolsCache(const KLFLatexSymbolsCache& ) { }
00092
00093 QMap<KLFLatexSymbol,QPixmap> cache;
00094 bool flag_modified;
00095 KLFBackend::klfSettings backendsettings;
00096
00097 int loadCacheStream(QDataStream& stream);
00098 int saveCacheStream(QDataStream& stream);
00099
00100 static KLFLatexSymbolsCache * staticCache;
00101
00104 int loadCacheFrom(const QString& file, int version);
00105 };
00106
00107
00108
00109 class KLF_EXPORT KLFLatexSymbolsView : public QScrollArea, public KLFIteratorSearchable<int>
00110 {
00111 Q_OBJECT
00112 public:
00113 KLFLatexSymbolsView(const QString& category, QWidget *parent);
00114
00115 void setSymbolList(const QList<KLFLatexSymbol>& symbols);
00116 void appendSymbolList(const QList<KLFLatexSymbol>& symbols);
00117
00118 QString category() const { return _category; }
00119
00120
00121
00122 virtual SearchIterator searchIterBegin() { return 0; }
00123 virtual SearchIterator searchIterEnd() { return mSymbols.size(); }
00124
00125 virtual bool searchIterMatches(const SearchIterator& pos, const QString& queryString);
00126
00127 virtual void searchPerformed(const SearchIterator& result);
00128 virtual void searchAbort();
00129
00130 signals:
00131 void symbolActivated(const KLFLatexSymbol& symb);
00132
00133 public slots:
00134 void buildDisplay();
00135 void recalcLayout();
00136
00137 protected slots:
00138 void slotSymbolActivated();
00139
00140 protected:
00141 QString _category;
00142 QList<KLFLatexSymbol> _symbols;
00143
00144 private:
00145 QWidget *mFrame;
00146 QGridLayout *mLayout;
00147 QSpacerItem *mSpacerItem;
00148 QList<QWidget*> mSymbols;
00149
00150 void highlightSearchMatches(int currentMatch);
00151 };
00152
00153
00154 namespace Ui {
00155 class KLFLatexSymbols;
00156 }
00157
00158
00161 class KLF_EXPORT KLFLatexSymbols : public QWidget
00162 {
00163 Q_OBJECT
00164 public:
00165 KLFLatexSymbols(QWidget* parent, const KLFBackend::klfSettings& baseSettings);
00166 ~KLFLatexSymbols();
00167
00168 bool event(QEvent *event);
00169
00170 signals:
00171
00172 void insertSymbol(const KLFLatexSymbol& symb);
00173
00174 public slots:
00175
00176 void slotShowCategory(int cat);
00177
00178 void retranslateUi(bool alsoBaseUi = true);
00179
00180 protected:
00181 QStackedWidget *stkViews;
00182
00183 QList<KLFLatexSymbolsView *> mViews;
00184
00185 void closeEvent(QCloseEvent *ev);
00186 void showEvent(QShowEvent *ev);
00187
00188 private:
00189 Ui::KLFLatexSymbols *u;
00190
00191 KLFSearchBar * pSearchBar;
00192
00193 void read_symbols_create_ui();
00194 };
00195
00196
00197 KLF_EXPORT bool operator==(const KLFLatexSymbol& a, const KLFLatexSymbol& b);
00198
00199
00200
00201 #endif
00202