[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project

src/klflatexsymbols.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   file klflatexsymbols.h
00003  *   This file is part of the KLatexFormula Project.
00004  *   Copyright (C) 2007 by Philippe Faist
00005  *   philippe.faist@bluewin.ch
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /* $Id: klflatexsymbols.h 486 2010-09-11 10:24:46Z philippe $ */
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& /*other*/) { }
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   // reimplemented from KLFIteratorSearchable
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 

Generated by doxygen 1.7.3