Warning, file /sdk/lokalize/src/xlifftextedit.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002   This file is part of Lokalize
0003 
0004   SPDX-FileCopyrightText: 2007-2014 Nick Shaforostoff <shafff@ukr.net>
0005   SPDX-FileCopyrightText: 2018-2019 Simon Depiets <sdepiets@gmail.com>
0006 
0007   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0008 */
0009 
0010 
0011 #ifndef XLIFFTEXTEDITOR_H
0012 #define XLIFFTEXTEDITOR_H
0013 
0014 #include "pos.h"
0015 #include "catalogstring.h"
0016 
0017 #include <ktextedit.h>
0018 class QMouseEvent;
0019 class SyntaxHighlighter;//TODO rename
0020 class KCompletionBox;
0021 class MyCompletionBox;
0022 
0023 class TranslationUnitTextEdit: public KTextEdit
0024 {
0025     Q_OBJECT
0026 public:
0027     explicit TranslationUnitTextEdit(Catalog* catalog, DocPosition::Part part, QWidget* parent = nullptr);
0028     ~TranslationUnitTextEdit() override;
0029     //NOTE remove this when Qt is fixed (hack for unbreakable spaces bug #162016)
0030     QString toPlainText();
0031 
0032     ///@returns targetWithTags for the sake of not calling XliffStorage/doContent twice
0033     CatalogString showPos(DocPosition pos, const CatalogString& refStr = CatalogString(), bool keepCursor = true);
0034     DocPosition currentPos()const
0035     {
0036         return m_currentPos;
0037     }
0038 
0039     void cursorToStart();
0040 
0041     bool isSpellCheckingEnabled() const
0042     {
0043         return m_enabled;
0044     }
0045     void setSpellCheckingEnabled(bool enable);
0046     void setVisualizeSeparators(bool enable);
0047     bool shouldBlockBeSpellChecked(const QString &block) const override
0048     {
0049         Q_UNUSED(block);
0050         return true;
0051     }
0052     void insertPlainTextWithCursorCheck(const QString &text);
0053 
0054 public Q_SLOTS:
0055     void reflectApprovementState();
0056     void reflectUntranslatedState();
0057 
0058     bool removeTargetSubstring(int start = 0, int end = -1, bool refresh = true);
0059     void insertCatalogString(CatalogString catStr, int start = 0, bool refresh = true);
0060 
0061     void source2target();
0062     void tagMenu();
0063     void tagImmediate();
0064     void insertTag(InlineTag tag);
0065     void spellReplace();
0066     void launchLanguageTool();
0067 
0068     void emitCursorPositionChanged();//for leds
0069 
0070     void doExplicitCompletion();
0071     void zoomRequestedSlot(qreal fontSize);
0072 
0073 protected:
0074     void keyPressEvent(QKeyEvent *keyEvent) override;
0075     void keyReleaseEvent(QKeyEvent* e) override;
0076     QMimeData* createMimeDataFromSelection() const override;
0077     void insertFromMimeData(const QMimeData* source) override;
0078     void mouseReleaseEvent(QMouseEvent* event) override;
0079     void dropEvent(QDropEvent *event) override;
0080     void dragEnterEvent(QDragEnterEvent *event) override;
0081 
0082     void contextMenuEvent(QContextMenuEvent *event) override;
0083     void wheelEvent(QWheelEvent *event) override;
0084     bool event(QEvent *event) override;
0085 
0086 private:
0087     ///@a refStr is for proper numbering
0088     void setContent(const CatalogString& catStr, const CatalogString& refStr = CatalogString());
0089 
0090     int strForMicePosIfUnderTag(QPoint mice, CatalogString& str, bool tryHarder = false);
0091 
0092     void requestToggleApprovement();
0093 
0094     void doTag(bool immediate);
0095 
0096     void doCompletion(int pos);
0097 
0098 private Q_SLOTS:
0099     //for Undo/Redo tracking
0100     void contentsChanged(int position, int charsRemoved, int charsAdded);
0101     void completionActivated(const QString&);
0102     void fileLoaded();
0103 
0104     void slotLanguageToolFinished(const QString &result);
0105     void slotLanguageToolError(const QString &str);
0106 
0107 Q_SIGNALS:
0108     void toggleApprovementRequested();
0109     void undoRequested();
0110     void redoRequested();
0111     void findRequested();
0112     void findNextRequested();
0113     void replaceRequested();
0114     void gotoFirstRequested();
0115     void gotoLastRequested();
0116     void gotoPrevRequested();
0117     void gotoNextRequested();
0118     void gotoPrevFuzzyRequested();
0119     void gotoNextFuzzyRequested();
0120     void gotoPrevUntranslatedRequested();
0121     void gotoNextUntranslatedRequested();
0122     void gotoPrevFuzzyUntrRequested();
0123     void gotoNextFuzzyUntrRequested();
0124     void gotoEntryRequested(const DocPosition&);
0125     void zoomRequested(qreal);
0126 
0127 
0128     void tagInsertRequested(const InlineTag& tag);
0129 
0130     void binaryUnitSelectRequested(const QString&);
0131     void languageToolChanged(const QString&);
0132     void tmLookupRequested(DocPosition::Part, const QString&);
0133 
0134     void contentsModified(const DocPosition&);
0135     void approvedEntryDisplayed();
0136     void nonApprovedEntryDisplayed();
0137     void translatedEntryDisplayed();
0138     void untranslatedEntryDisplayed();
0139     void cursorPositionChanged(int column);
0140 
0141 private:
0142     int m_currentUnicodeNumber; //alt+NUM thing
0143     bool m_langUsesSpaces; //e.g. Chinese doesn't
0144 
0145     Catalog* m_catalog;
0146     DocPosition::Part m_part;
0147     DocPosition m_currentPos;
0148     SyntaxHighlighter* m_highlighter;
0149     bool m_enabled;
0150 
0151     MyCompletionBox* m_completionBox;
0152 
0153     //for undo/redo tracking
0154     QString _oldMsgstr;
0155     QString _oldMsgstrAscii; //HACK to workaround #218246
0156 
0157     //For text move with mouse
0158     int m_cursorSelectionStart;
0159     int m_cursorSelectionEnd;
0160 
0161     //For LanguageTool timer
0162     QTimer* m_languageToolTimer;
0163 };
0164 
0165 
0166 void insertContent(QTextCursor& cursor, const CatalogString& catStr, const CatalogString& refStr = CatalogString(), bool insertText = true);
0167 
0168 
0169 #endif