"Fossies" - the Fresh Open Source Software Archive

Member "texstudio-2.12.22/src/latexeditorview.h" (15 Jan 2020, 12031 Bytes) of package /linux/misc/texstudio-2.12.22.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "latexeditorview.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.12.20_vs_2.12.22.

    1 /***************************************************************************
    2  *   copyright       : (C) 2008 by Benito van der Zander                   *
    3  *   http://www.xm1math.net/texmaker/                                      *
    4  *                                                                         *
    5  *   This program is free software; you can redistribute it and/or modify  *
    6  *   it under the terms of the GNU General Public License as published by  *
    7  *   the Free Software Foundation; either version 2 of the License, or     *
    8  *   (at your option) any later version.                                   *
    9  *                                                                         *
   10  ***************************************************************************/
   11 
   12 #ifndef LATEXEDITORVIEW_H
   13 #define LATEXEDITORVIEW_H
   14 #include "mostQtHeaders.h"
   15 #include "qdocument.h"
   16 #include "syntaxcheck.h"
   17 #include "grammarcheck.h"
   18 #include "bibtexreader.h"
   19 #include "cursorposition.h"
   20 #include "latexcompleter.h"
   21 class QDocumentLineHandle;
   22 
   23 class LatexDocument;
   24 class QCodeEdit;
   25 class QEditor;
   26 class QLineMarkPanel;
   27 class QLineNumberPanel;
   28 class QSearchReplacePanel;
   29 class QGotoLinePanel;
   30 class QStatusPanel;
   31 class LatexCompleter;
   32 class SpellerUtility;
   33 class SpellerManager;
   34 class DefaultInputBinding;
   35 class LatexEditorViewConfig;
   36 class Macro;
   37 class MacroExecContext;
   38 /*!
   39  * \brief represent link overlays
   40  * When pressing control, some structural elements in the text can be changed to links in order to jump to corresponding places
   41  *
   42  */
   43 struct LinkOverlay {
   44     enum LinkOverlayType {Invalid, RefOverlay, FileOverlay, UrlOverlay, UsepackageOverlay, BibFileOverlay, CiteOverlay, CommandOverlay, EnvOverlay};
   45     // for simpler access everything is public - only access for reading
   46     LinkOverlayType type;
   47     QDocumentLine docLine;
   48     QFormatRange formatRange;
   49 
   50     LinkOverlay() : type(Invalid) {}
   51     LinkOverlay(const LinkOverlay &o);
   52     LinkOverlay(const Token &token, LinkOverlayType ltype);
   53 
   54     bool isValid() const
   55     {
   56         return type != Invalid;
   57     }
   58     LinkOverlay & operator= (const LinkOverlay &) = default;    // Avoid GCC9 -Wdeprecated-copy warning
   59     bool operator ==(const LinkOverlay &o) const
   60     {
   61         return (docLine == o.docLine) && (formatRange == o.formatRange);
   62     }
   63     QString text() const;
   64 };
   65 /*!
   66  * \brief actual editor widget
   67  */
   68 class LatexEditorView : public QWidget
   69 {
   70     Q_OBJECT
   71 
   72 public:
   73     LatexEditorView(QWidget *parent, LatexEditorViewConfig *aconfig, LatexDocument *doc = nullptr);
   74     ~LatexEditorView();
   75 
   76     QCodeEdit *codeeditor;
   77     QEditor *editor;
   78 
   79     LatexDocument *document;
   80 
   81     QDateTime lastUsageTime;
   82 
   83     QEditor *getEditor() const
   84     {
   85         return editor;
   86     }
   87     LatexDocument *getDocument() const { return document; }
   88     Q_PROPERTY(QEditor *editor READ getEditor);
   89     Q_PROPERTY(LatexDocument *document READ getDocument);     //<- semicolon necessary due to qt bug 22992
   90 
   91     LatexEditorViewConfig *getConfig() { return config; }
   92 
   93     Q_INVOKABLE QString displayName() const;
   94     QString displayNameForUI() const;
   95 
   96     //  FindWidget *findwidget;
   97     //Functions affecting the editor
   98 
   99     Q_INVOKABLE void complete(int flags); ///< complete text
  100     bool gotoLineHandleAndSearchCommand(const QDocumentLineHandle *dlh, const QSet<QString> &searchFor, const QString &id);
  101     bool gotoLineHandleAndSearchString(const QDocumentLineHandle *dlh, const QString &str);
  102     bool gotoLineHandleAndSearchLabel(const QDocumentLineHandle *dlh, const QString &label);
  103     bool gotoLineHandleAndSearchBibItem(const QDocumentLineHandle *dlh, const QString &bibId);
  104 
  105     static QList<QAction *> getBaseActions();
  106     static void setBaseActions(QList<QAction *> baseActions);
  107     void setSpellerManager(SpellerManager *manager);
  108     bool setSpeller(const QString &name,bool updateComment=false);
  109     Q_INVOKABLE QString getSpeller();
  110 
  111     static void setCompleter(LatexCompleter *newCompleter);
  112     static LatexCompleter *getCompleter();
  113     bool containsBibTeXId(QString id);
  114 
  115     void updateCitationFormats();
  116     void updatePackageFormats();
  117 
  118     void clearLogMarks();
  119     void addLogEntry(int logEntryNumber, int lineNumber, int markID);
  120     void setLogMarksVisible(bool visible);
  121     QMultiHash<QDocumentLineHandle *, int> lineToLogEntries;
  122     QHash<int, QDocumentLineHandle *> logEntryToLine;
  123     QHash<int, int> logEntryToMarkID;
  124 
  125     static int hideTooltipWhenLeavingLine;
  126     static int syntaxErrorFormat;
  127 
  128     void setLineMarkToolTip(const QString &tooltip);
  129     void updateSettings();
  130     static void updateFormatSettings();
  131 
  132     QPoint getHoverPosistion() { return m_point; }
  133 
  134     static int deleteFormat, insertFormat, replaceFormat;
  135     static int preEditFormat;
  136 
  137     Q_INVOKABLE void closeCompleter();
  138     Q_INVOKABLE void removeBookmark(int lineNr, int bookmarkNumber);
  139     void removeBookmark(QDocumentLineHandle *dlh, int bookmarkNumber);
  140     Q_INVOKABLE void addBookmark(int lineNr, int bookmarkNumber);
  141     Q_INVOKABLE bool hasBookmark(int lineNr, int bookmarkNumber);
  142     bool hasBookmark(QDocumentLineHandle *dlh, int bookmarkNumber);
  143 
  144     QList<QDocumentCursor> autoPreviewCursor;
  145 
  146     static int bookMarkId(int bookmarkNumber);
  147 
  148     static void selectOptionInLatexArg(QDocumentCursor &cur);
  149 
  150     QDocumentCursor parenthizedTextSelection(const QDocumentCursor &cursor, bool includeParentheses = true);
  151     QDocumentCursor findFormatsBegin(const QDocumentCursor &cursor, QSet<int> allowedFormats, QSet<int> allowedLineEndFormats);
  152     void setLatexPackageList(QSet<QString> *lst) { latexPackageList = lst; }
  153 
  154     LatexParser lp;
  155 
  156     QString getSearchText();
  157     QString getReplaceText();
  158     bool getSearchIsCase();
  159     bool getSearchIsRegExp();
  160     bool getSearchIsWords();
  161 
  162     void updateReplamentList(const LatexParser &cmds, bool forceUpdate = false);
  163 
  164 private:
  165     QAction *lineNumberPanelAction, *lineMarkPanelAction, *lineFoldPanelAction, *lineChangePanelAction,
  166             *statusPanelAction, *searchReplacePanelAction, *gotoLinePanelAction;
  167     QLineMarkPanel *lineMarkPanel;
  168     QLineNumberPanel *lineNumberPanel;
  169     QSearchReplacePanel *searchReplacePanel;
  170     QGotoLinePanel *gotoLinePanel;
  171     QStatusPanel *statusPanel;
  172 
  173     QPoint m_point;
  174 
  175     static int environmentFormat, referencePresentFormat, referenceMissingFormat, referenceMultipleFormat, citationMissingFormat, citationPresentFormat, structureFormat, todoFormat,
  176            packagePresentFormat, packageMissingFormat, packageUndefinedFormat,
  177            wordRepetitionFormat, wordRepetitionLongRangeFormat, badWordFormat, grammarMistakeFormat, grammarMistakeSpecial1Format, grammarMistakeSpecial2Format, grammarMistakeSpecial3Format, grammarMistakeSpecial4Format,
  178            numbersFormat, verbatimFormat, commentFormat, pictureFormat, pweaveDelimiterFormat, pweaveBlockFormat, sweaveDelimiterFormat, sweaveBlockFormat, math_DelimiterFormat, math_KeywordFormat,
  179            asymptoteBlockFormat;
  180     static QList<int> grammarFormats;
  181     static QVector<bool> grammarFormatsDisabled;
  182     static QList<int> formatsList;
  183 
  184     QSet<QString> *latexPackageList;
  185 
  186     friend class DefaultInputBinding;
  187     friend class SyntaxCheckTest;
  188 
  189     SpellerManager *spellerManager;
  190     SpellerUtility *speller;
  191     bool useDefaultSpeller;
  192     static LatexCompleter *completer;
  193     QList<CursorPosition> changePositions; //line, index
  194     int curChangePos;
  195 
  196     LatexEditorViewConfig *config;
  197 
  198     bibtexReader *bibReader;
  199     QPoint lastPos;
  200 
  201     LinkOverlay linkOverlay;
  202     QCursor linkOverlayStoredCursor;
  203 
  204     QList<QPair<QDocumentLine, QFormatRange> > tempHighlightQueue;
  205 
  206     QMap<QString, QString> mReplacementList;
  207 
  208 private slots:
  209     void requestCitation(); //emits needCitation with selected text
  210     void openExternalFile();
  211     void openPackageDocumentation(QString package = QString());
  212     void emitChangeDiff();
  213     void emitGotoDefinitionFromAction();
  214     void emitFindLabelUsagesFromAction();
  215     void emitSyncPDFFromAction();
  216     void lineMarkClicked(int line);
  217     void lineMarkToolTip(int line, int mark);
  218     void triggeredThesaurus();
  219     void reloadSpeller();
  220     void changeSpellingDict(const QString &name);
  221     void copyImageFromAction();
  222     void saveImageFromAction();
  223 
  224 public slots:
  225     void cleanBib();
  226 
  227     void jumpChangePositionBackward();
  228     void jumpChangePositionForward();
  229 
  230     void jumpToBookmark(int bookmarkNumber);
  231     bool toggleBookmark(int bookmarkNumber, QDocumentLine line = QDocumentLine());
  232 
  233     void foldEverything(bool unFold);
  234     void foldLevel(bool unFold, int level);
  235     void foldBlockAt(bool unFold, int line);
  236 
  237     Q_INVOKABLE void zoomIn();
  238     Q_INVOKABLE void zoomOut();
  239     Q_INVOKABLE void resetZoom();
  240 
  241     void mayNeedToOpenCompleter(bool fromSingleChar=false);
  242     void documentContentChanged(int linenr, int count);
  243 
  244 private slots:
  245     void lineDeleted(QDocumentLineHandle *l);
  246     void textReplaceFromAction();
  247     void spellCheckingAlwaysIgnore();
  248     void populateSpellingMenu();
  249     void addReplaceActions(QMenu *menu, const QStringList &replacements, bool italic);
  250     void addSpellingActions(QMenu *menu, QString word, bool dedicatedMenu);
  251 
  252 public slots:
  253     void spellRemoveMarkers(const QString &newIgnoredWord);
  254     void mouseHovered(QPoint pos);
  255     bool closeElement();
  256     void insertHardLineBreaks(int newLength, bool smartScopeSelection, bool joinLines);
  257     void viewActivated();
  258     void clearOverlays();
  259     void paste();
  260     void insertSnippet(QString text);
  261 
  262     void deleteLines(bool toStart, bool toEnd);
  263     void moveLines(int delta);
  264     QList<QPair<int, int> > getSelectedLineBlocks();
  265     static QMultiMap<int, QDocumentCursor* > getSelectedLines(QList<QDocumentCursor>& cursors);
  266     void alignMirrors();
  267 
  268     void checkForLinkOverlay(QDocumentCursor cursor);
  269     bool hasLinkOverlay() const { return linkOverlay.isValid(); }
  270     const LinkOverlay &getLinkOverlay() const { return linkOverlay; }
  271 
  272 private:
  273     void setLinkOverlay(const LinkOverlay &overlay);
  274     void removeLinkOverlay();
  275     bool isNonTextFormat(int format);
  276     QString extractMath(QDocumentCursor cursor);
  277     bool moveToCommandStart (QDocumentCursor &cursor, QString commandPrefix);
  278     bool showMathEnvPreview(QDocumentCursor cursor, QString command, QString environment, QPoint pos);
  279 
  280 public slots:
  281     void temporaryHighlight(QDocumentCursor cur);
  282     void removeTemporaryHighlight();
  283 
  284     void displayLineGrammarErrorsInternal(int lineNr, const QList<GrammarError> &errors);
  285     void lineGrammarChecked(const void *doc, const void *line, int lineNr, const QList<GrammarError> &errors);
  286     void updateGrammarOverlays();
  287 
  288     void bibtexSectionFound(QString content);
  289 
  290 public:
  291     static void setGrammarOverlayDisabled(int type, bool show);
  292 
  293     bool isInMathHighlighting(const QDocumentCursor &cursor);
  294     void checkRTLLTRLanguageSwitching();
  295 
  296 signals:
  297     void lineHandleDeleted(QDocumentLineHandle *l);
  298     void showMarkTooltipForLogMessage(QList<int> logMessages);
  299     void needCitation(const QString &id);//request a new citation
  300     void showPreview(const QString &text);
  301     void showPreview(const QDocumentCursor &c);
  302     void showImgPreview(const QString &fileName);
  303     void openFile(const QString &name);
  304     void openFile(const QString &baseName, const QString &defaultExtension);
  305     void openCompleter();
  306     void thesaurus(int line, int col);
  307     void changeDiff(QPoint pt);
  308     void spellerChanged(const QString &name);
  309     void gotoDefinition(QDocumentCursor c);
  310     void findLabelUsages(LatexDocument *contextDoc, const QString &labelText);
  311     void syncPDFRequested(QDocumentCursor c);
  312     void bookmarkRemoved(QDocumentLineHandle *dlh);
  313     void bookmarkAdded(QDocumentLineHandle *dlh, int nr);
  314     void saveCurrentCursorToHistoryRequested();
  315     void execMacro(const Macro &macro, const MacroExecContext &context);
  316 
  317     void mouseBackPressed();
  318     void mouseForwardPressed();
  319     void cursorChangeByMouse();
  320         void focusReceived();
  321 
  322     void linesChanged(QString language, const void *doc, const QList<LineInfo> &lines, int firstLineNr);
  323     void searchBibtexSection(QString file, QString bibId);
  324     void openInternalDocViewer(QString package, QString command = "");
  325 
  326     void showExtendedSearch();
  327 
  328 private slots:
  329     void lineMarkContextMenuRequested(int lineNumber, QPoint globalPos);
  330     void foldContextMenuRequested(int lineNumber, QPoint globalPos);
  331 };
  332 Q_DECLARE_METATYPE(LatexEditorView *)
  333 
  334 
  335 class BracketInvertAffector: public PlaceHolder::Affector
  336 {
  337 public:
  338     virtual QString affect(const QKeyEvent *e, const QString &base, int ph, int mirror) const;
  339     static BracketInvertAffector *instance();
  340 };
  341 #endif