1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
/*
This is part of TeXworks, an environment for working with TeX documents
Copyright (C) 2007-08 Jonathan Kew
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
For links to further information, or to contact the author,
see <http://texworks.org/>.
*/
#ifndef TWUtils_H
#define TWUtils_H
#include <QDebug>
#include <QAction>
#include <QString>
#include <QList>
#include <QHash>
#include <QDir>
#include <QMap>
#include <QPair>
#include <hunspell.h>
#define TEXWORKS_NAME "TeXworks" /* app name, for use in menus, messages, etc */
class QMainWindow;
class QCompleter;
class TeXDocument;
// static utility methods
class TWUtils
{
public:
// is the given file a PDF document? image? Postscript?
static bool isPDFfile(const QString& fileName);
static bool isImageFile(const QString& fileName);
static bool isPostscriptFile(const QString& fileName);
// return the path to our "library" folder for resources like templates, completion lists, etc
static const QString getLibraryPath(const QString& subdir);
static void copyResources(const QDir& resDir, const QString& libPath);
static void insertHelpMenuItems(QMenu* helpMenu);
// return a sorted list of all the available text codecs
static QList<QTextCodec*> *findCodecs();
// get list of available translations
static QStringList *getTranslationList();
// get list of available dictionaries
static QStringList *getDictionaryList();
// get dictionary for a given language
static Hunhandle *getDictionary(const QString& language);
// list of filename filters for the Open/Save dialogs
static QStringList* filterList();
static void setDefaultFilters();
// perform the updates to a menu; used by the documents to update their own menus
static void updateRecentFileActions(QObject *parent, QList<QAction*> &actions, QMenu *menu);
// update the SelWinActions in a menu, used by the documents
static void updateWindowMenu(QWidget *window, QMenu *menu);
// return just the filename from a full pathname, suitable for UI display
static QString strippedName(const QString &fullFileName);
// window positioning utilities
typedef void (WindowArrangementFunction)(const QWidgetList& windows, const QRect& bounds);
static void tileWindowsInRect(const QWidgetList& windows, const QRect& bounds);
static void stackWindowsInRect(const QWidgetList& windows, const QRect& bounds);
static void zoomToScreen(QWidget *window);
static void zoomToHalfScreen(QWidget *window, bool rhs = false);
static void sideBySide(QWidget *window1, QWidget *window2);
static void ensureOnScreen(QWidget *window);
static void applyToolbarOptions(QMainWindow *theWindow, int iconSize, bool showText);
// find a "word", in TeX terms, returning whether it's a natural-language word or a control seq, punctuation, etc
static bool findNextWord(const QString& text, int index, int& start, int& end);
static QChar closerMatching(QChar c);
static QChar openerMatching(QChar c);
static void readConfig();
static int balanceDelim(const QString& text, int pos, QChar delim, int direction);
static int findOpeningDelim(const QString& text, int pos);
static const QString& includeTextCommand();
static const QString& includePdfCommand();
static const QString& includeImageCommand();
static const QString& includePostscriptCommand();
static const QString& cleanupPatterns();
static void installCustomShortcuts(QWidget * widget, bool recursive = true);
private:
TWUtils();
static QList<QTextCodec*> *codecList;
static QStringList *dictionaryList;
static QStringList *translationList;
static QHash<const QString,Hunhandle*> *dictionaries;
static QStringList *filters;
static QMap<QChar,QChar> pairOpeners;
static QMap<QChar,QChar> pairClosers;
static QString sIncludeTextCommand;
static QString sIncludePdfCommand;
static QString sIncludeImageCommand;
static QString sIncludePostscriptCommand;
static QString sCleanupPatterns;
};
// this special QAction class is used in Window menus, so that it's easy to recognize the dynamically-created items
class SelWinAction : public QAction
{
Q_OBJECT
public:
SelWinAction(QObject *parent, const QString &fileName);
};
// filter used to stop Command-keys getting inserted into edit text items
// (only used on Mac OS X)
class CmdKeyFilter: public QObject
{
Q_OBJECT
public:
static CmdKeyFilter *filter();
protected:
bool eventFilter(QObject *obj, QEvent *event);
private:
static CmdKeyFilter *filterObj;
};
// specification of an "engine" used to process files
class Engine : public QObject
{
Q_OBJECT
public:
Engine();
Engine(const QString& name, const QString& program, const QStringList arguments, bool showPdf);
Engine(const Engine& orig);
Engine& operator=(const Engine& rhs);
const QString name() const;
const QString program() const;
const QStringList arguments() const;
bool showPdf() const;
void setName(const QString& name);
void setProgram(const QString& program);
void setArguments(const QStringList& arguments);
void setShowPdf(bool showPdf);
private:
QString f_name;
QString f_program;
QStringList f_arguments;
bool f_showPdf;
};
#endif
|