File indexing completed on 2024-12-01 08:17:30
0001 // clang-format off 0002 /* 0003 * KDiff3 - Text Diff And Merge Tool 0004 * 0005 * SPDX-FileCopyrightText: 2002-2011 Joachim Eibl, joachim.eibl at gmx.de 0006 * SPDX-FileCopyrightText: 2018-2020 Michael Reeves reeves.87@gmail.com 0007 * SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 // clang-format on 0010 0011 #ifndef OPTIONS_H 0012 #define OPTIONS_H 0013 0014 #include "combiners.h" 0015 #include "RecentItems.h" 0016 #include "TypeUtils.h" 0017 0018 #include <boost/signals2.hpp> 0019 #include <list> 0020 #include <memory> 0021 0022 #include <QColor> 0023 #include <QFont> 0024 #include <QPoint> 0025 #include <QSize> 0026 #include <QStringList> 0027 0028 #include <KSharedConfig> 0029 #include <qcolor.h> 0030 0031 class ValueMap; 0032 0033 class OptionItemBase; 0034 0035 constexpr char KDIFF3_CONFIG_GROUP[] = "KDiff3 Options"; 0036 0037 enum e_LineEndStyle 0038 { 0039 eLineEndStyleUnix = 0, 0040 eLineEndStyleDos, 0041 eLineEndStyleOldMac, 0042 eLineEndStyleAutoDetect, 0043 eLineEndStyleUndefined, // only one line exists 0044 eLineEndStyleConflict // User must resolve manually 0045 }; 0046 0047 class Options 0048 { 0049 public: 0050 static boost::signals2::signal<void()> apply; 0051 static boost::signals2::signal<void()> resetToDefaults; 0052 static boost::signals2::signal<void()> setToCurrent; 0053 static boost::signals2::signal<void(ValueMap*)> read; 0054 static boost::signals2::signal<void(ValueMap*)> write; 0055 0056 static boost::signals2::signal<void()> preserve; 0057 static boost::signals2::signal<void()> unpreserve; 0058 static boost::signals2::signal<bool(const QString&, const QString&), find> accept; 0059 0060 void init(); 0061 0062 void readOptions(const KSharedConfigPtr config); 0063 void saveOptions(const KSharedConfigPtr config); 0064 0065 const QString parseOptions(const QStringList& optionList); 0066 [[nodiscard]] QString calcOptionHelp(); 0067 0068 [[nodiscard]] const QSize& getGeometry() const { return m_geometry; } 0069 [[nodiscard]] const QPoint& getPosition() const { return m_position; } 0070 0071 [[nodiscard]] bool isFullScreen() const { return m_bFullScreen; }; 0072 void setFullScreen(const bool fullScreen) { m_bFullScreen = fullScreen; }; 0073 0074 [[nodiscard]] bool isMaximized() const { return m_bMaximized; }; 0075 void setMaximized(const bool maximized) { m_bMaximized = maximized; }; 0076 0077 [[nodiscard]] bool isStatusBarVisible() const { return m_bShowStatusBar; } 0078 void setStatusBarState(bool inShown) { m_bShowStatusBar = inShown; } 0079 0080 [[nodiscard]] inline const QFont& defaultFont() { return mFont; }; 0081 [[nodiscard]] inline const QFont& appFont() { return mAppFont; }; 0082 0083 [[nodiscard]] bool wordWrapOn() const { return m_bWordWrap; } 0084 void setWordWrap(const bool enabled) { m_bWordWrap = enabled; } 0085 0086 [[nodiscard]] bool replaceTabs() const { return m_bReplaceTabs; } 0087 [[nodiscard]] bool autoIndent() const { return m_bAutoIndentation; } 0088 [[nodiscard]] qint32 tabSize() const { return m_tabSize; } 0089 0090 [[nodiscard]] bool ignoreComments() const { return m_bIgnoreComments; } 0091 0092 [[nodiscard]] bool whiteSpaceIsEqual() const { return m_bDmWhiteSpaceEqual; } 0093 0094 [[nodiscard]] const QColor& foregroundColor() const { return m_fgColor; }; 0095 [[nodiscard]] const QColor& backgroundColor() const 0096 { 0097 if(mPrintMode) return mPrintBackground; 0098 return m_bgColor; 0099 }; 0100 [[nodiscard]] const QColor& diffBackgroundColor() const { return m_diffBgColor; }; 0101 [[nodiscard]] const QColor& aColor() const { return m_colorA; }; 0102 [[nodiscard]] const QColor& bColor() const { return m_colorB; }; 0103 [[nodiscard]] const QColor& cColor() const { return m_colorC; }; 0104 0105 [[nodiscard]] const QColor& conflictColor() const { return m_colorForConflict; } 0106 0107 [[nodiscard]] RecentItems<maxNofRecentFiles>& getRecentFilesA() { return m_recentAFiles; } 0108 [[nodiscard]] RecentItems<maxNofRecentFiles>& getRecentFilesB() { return m_recentBFiles; } 0109 [[nodiscard]] RecentItems<maxNofRecentFiles>& getRecentFilesC() { return m_recentCFiles; } 0110 0111 [[nodiscard]] RecentItems<maxNofRecentFiles>& getRecentOutputFiles() { return m_recentOutputFiles; } 0112 0113 inline void beginPrint() { mPrintMode = true; } 0114 inline void endPrint() { mPrintMode = false; } 0115 0116 [[nodiscard]] inline const QColor& getCurrentRangeBgColor() const { return m_currentRangeBgColor; }; 0117 [[nodiscard]] inline const QColor& getCurrentRangeDiffBgColor() const { return m_currentRangeDiffBgColor; }; 0118 [[nodiscard]] inline const QColor& oldestFileColor() const { return m_oldestFileColor; } 0119 [[nodiscard]] inline const QColor& midAgeFileColor() const { return m_midAgeFileColor; } 0120 [[nodiscard]] inline const QColor& newestFileColor() const { return m_newestFileColor; } 0121 [[nodiscard]] inline const QColor& missingFileColor() const { return m_missingFileColor; } 0122 [[nodiscard]] inline const QColor& manualHelpRangeColor() const { return m_manualHelpRangeColor; } 0123 0124 private: 0125 void addOptionItem(std::shared_ptr<OptionItemBase> inItem); 0126 0127 friend class OptionDialog; 0128 std::list<std::shared_ptr<OptionItemBase>> mOptionItemList; 0129 0130 bool mPrintMode = false; 0131 0132 const QColor mPrintBackground = Qt::white; 0133 0134 // clang-format off 0135 // Some settings that are not available in the option dialog: 0136 QSize m_geometry = QSize(600, 400); 0137 QPoint m_position = QPoint(0, 22); 0138 bool m_bFullScreen = false; 0139 bool m_bMaximized = false; 0140 bool m_bShowStatusBar = true; 0141 // clang-format on 0142 0143 // These are the results of the option dialog. 0144 QFont mFont; 0145 QFont mAppFont; 0146 0147 //bool m_bItalicForDeltas; 0148 0149 QColor m_fgColor = Qt::black; 0150 QColor m_bgColor = Qt::white; 0151 QColor m_diffBgColor; 0152 QColor m_colorA; 0153 QColor m_colorB; 0154 QColor m_colorC; 0155 QColor m_colorForConflict = Qt::red; 0156 0157 QColor m_currentRangeBgColor; 0158 QColor m_currentRangeDiffBgColor; 0159 0160 QColor m_oldestFileColor = qRgb(0xf0, 0, 0); 0161 QColor m_midAgeFileColor = qRgb(0xc0, 0xc0, 0); 0162 QColor m_newestFileColor = qRgb(0, 0xd0, 0); 0163 QColor m_missingFileColor = qRgb(0, 0, 0); 0164 QColor m_manualHelpRangeColor = qRgb(0xff, 0xd0, 0x80); 0165 0166 bool m_bWordWrap = false; 0167 bool m_bReplaceTabs = false; 0168 bool m_bAutoIndentation = true; 0169 qint32 m_tabSize = 8; 0170 0171 public: 0172 bool m_bAutoCopySelection = false; 0173 bool m_bSameEncoding = true; 0174 QByteArray mEncodingA = nullptr; 0175 bool mAutoDetectA = true; 0176 QByteArray mEncodingB = nullptr; 0177 bool mAutoDetectB = true; 0178 QByteArray mEncodingC = nullptr; 0179 bool mAutoDetectC = true; 0180 QByteArray mEncodingOut = nullptr; 0181 bool m_bAutoSelectOutEncoding = true; 0182 QByteArray mEncodingPP = nullptr; 0183 e_LineEndStyle m_lineEndStyle = eLineEndStyleAutoDetect; 0184 0185 bool m_bTryHard = true; 0186 bool m_bShowWhiteSpaceCharacters = true; 0187 bool m_bShowWhiteSpace = true; 0188 bool m_bShowLineNumbers = false; 0189 bool m_bHorizDiffWindowSplitting = true; 0190 bool m_bShowInfoDialogs = true; 0191 bool m_bDiff3AlignBC = false; 0192 0193 qint32 m_whiteSpace2FileMergeDefault = 0; 0194 qint32 m_whiteSpace3FileMergeDefault = 0; 0195 bool m_bIgnoreCase = false; 0196 bool m_bIgnoreNumbers = false; 0197 bool m_bIgnoreComments = false; 0198 QString m_PreProcessorCmd; 0199 QString m_LineMatchingPreProcessorCmd; 0200 bool m_bRunRegExpAutoMergeOnMergeStart = false; 0201 QString m_autoMergeRegExp = ".*\\$(Version|Header|Date|Author).*\\$.*"; 0202 bool m_bRunHistoryAutoMergeOnMergeStart = false; 0203 QString m_historyStartRegExp = ".*\\$Log.*\\$.*"; 0204 QString m_historyEntryStartRegExp; 0205 bool m_bHistoryMergeSorting = false; 0206 QString m_historyEntryStartSortKeyOrder = "4,3,2,5,1,6"; 0207 qint32 m_maxNofHistoryEntries = -1; 0208 QString m_IrrelevantMergeCmd; 0209 bool m_bAutoSaveAndQuitOnMergeWithoutConflicts = false; 0210 0211 bool m_bAutoAdvance = false; 0212 qint32 m_autoAdvanceDelay = 500; 0213 0214 RecentItems<maxNofRecentFiles> m_recentAFiles; 0215 RecentItems<maxNofRecentFiles> m_recentBFiles; 0216 RecentItems<maxNofRecentFiles> m_recentCFiles; 0217 0218 RecentItems<maxNofRecentCodecs> m_recentEncodings; 0219 0220 RecentItems<maxNofRecentFiles> m_recentOutputFiles; 0221 0222 // Directory Merge options 0223 bool m_bDmSyncMode = false; 0224 bool m_bDmRecursiveDirs = true; 0225 bool m_bDmFollowFileLinks = true; 0226 bool m_bDmFollowDirLinks = true; 0227 bool m_bDmFindHidden = true; 0228 bool m_bDmCreateBakFiles; 0229 bool m_bDmBinaryComparison = true; 0230 bool m_bDmFullAnalysis = false; 0231 bool m_bDmTrustDate = false; 0232 bool m_bDmTrustDateFallbackToBinary = false; 0233 bool m_bDmTrustSize = false; 0234 bool m_bDmCopyNewer = false; 0235 //bool m_bDmShowOnlyDeltas; 0236 bool m_bDmShowIdenticalFiles = true; 0237 bool m_bDmUseCvsIgnore = false; 0238 bool m_bDmWhiteSpaceEqual = true; 0239 bool m_bDmCaseSensitiveFilenameComparison; 0240 bool m_bDmUnfoldSubdirs = false; 0241 bool m_bDmSkipDirStatus = false; 0242 QString m_DmFilePattern = "*"; 0243 QString m_DmFileAntiPattern = "*.orig;*.o;*.obj;*.rej;*.bak"; 0244 QString m_DmDirAntiPattern = "CVS;.deps;.svn;.hg;.git"; 0245 0246 bool m_bRightToLeftLanguage = false; 0247 0248 QString m_ignorableCmdLineOptions = QString("-u;-query;-html;-abort"); 0249 bool m_bEscapeKeyQuits = false; 0250 }; 0251 0252 #endif