1 /*
2  * KDiff3 - Text Diff And Merge Tool
3  *
4  * SPDX-FileCopyrightText: 2002-2011 Joachim Eibl, joachim.eibl at gmx.de
5  * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #ifndef SMALLDIALOGS_H
9 #define SMALLDIALOGS_H
10 
11 #include "ui_opendialog.h"
12 
13 #include "Logging.h"
14 
15 #include <QCheckBox>
16 #include <QComboBox>
17 #include <QDialog>
18 #include <QPointer>
19 
20 class Options;
21 class QLineEdit;
22 class KDiff3App;
23 
24 enum class eWindowIndex
25 {
26     None = 0,
27     A,
28     B,
29     C,
30     Output,
31     invalid
32 };
33 
34 class OpenDialog: public QDialog
35 {
36     Q_OBJECT
37   public:
38     OpenDialog( // krazy:exclude=explicit
39         KDiff3App* pParent, const QString& n1, const QString& n2, const QString& n3,
40         bool bMerge, const QString& outputName, const QSharedPointer<Options>& pOptions);
41 
getFileA()42     const QString getFileA() const { return dialogUi.lineA->currentText(); }
getFileB()43     const QString getFileB() const { return dialogUi.lineB->currentText(); }
getFileC()44     const QString getFileC() const { return dialogUi.lineC->currentText(); }
45 
getOutputFile()46     const QString getOutputFile() const { return dialogUi.lineOut->currentText(); }
47 
merge()48     bool merge() const { return dialogUi.mergeCheckBox->isChecked(); }
49 
50     void accept() override;
51   private:
52     void selectURL(QComboBox* pLine, bool bDir, int i, bool bSave);
53 
54     void fixCurrentText(QComboBox* pCB);
55     QSharedPointer<Options> m_pOptions;
56     bool m_bInputFileNameChanged;
57 
58     Ui::OpenDialog dialogUi;
59   private Q_SLOTS:
60     void selectFileA();
61     void selectFileB();
62     void selectFileC();
63     void selectDirA();
64     void selectDirB();
65     void selectDirC();
66     void selectOutputName();
67     void selectOutputDir();
68     void internalSlot(int);
69     void inputFilenameChanged();
70     void slotSwapCopyNames(QAction*) const;
71   Q_SIGNALS:
72     void internalSignal(bool);
73 };
74 
75 class FindDialog: public QDialog
76 {
77     Q_OBJECT
78   public:
79     explicit FindDialog(QWidget* pParent);
80     void setVisible(bool) override;
81 
82     void restartFind();
nextWindow()83     inline void nextWindow()
84     {
85         currentLine = 0;
86         currentPos = 0;
87 
88         switch(currentWindow)
89         {
90             case eWindowIndex::invalid:
91                 qCWarning(kdiffMain) << "FindDialog::nextWindow called with invalid state.";
92                 Q_FALLTHROUGH();
93             case eWindowIndex::None:
94                 currentWindow = eWindowIndex::A;
95                 break;
96             case eWindowIndex::A:
97                 currentWindow = eWindowIndex::B;
98                 break;
99             case eWindowIndex::B:
100                 currentWindow = eWindowIndex::C;
101                 break;
102             case eWindowIndex::C:
103                 currentWindow = eWindowIndex::Output;
104                 break;
105             case eWindowIndex::Output:
106                 currentWindow = eWindowIndex::invalid;
107                 break;
108         }
109     }
110 
getCurrentWindow()111     inline eWindowIndex getCurrentWindow() { return currentWindow; }
112 
113   Q_SIGNALS:
114     void findNext();
115 
116   public:
117     QLineEdit* m_pSearchString;
118     QCheckBox* m_pSearchInA;
119     QCheckBox* m_pSearchInB;
120     QCheckBox* m_pSearchInC;
121     QCheckBox* m_pSearchInOutput;
122     QCheckBox* m_pCaseSensitive;
123 
124     int currentLine = 0;
125     int currentPos = 0;
126 
127   private:
128     eWindowIndex currentWindow = eWindowIndex::None;
129 };
130 
131 class RegExpTester: public QDialog
132 {
133     Q_OBJECT
134   private:
135     QLineEdit* m_pAutoMergeRegExpEdit;
136     QLineEdit* m_pAutoMergeMatchResult;
137     QLineEdit* m_pAutoMergeExampleEdit;
138     QLineEdit* m_pHistoryStartRegExpEdit;
139     QLineEdit* m_pHistoryStartMatchResult;
140     QLineEdit* m_pHistoryStartExampleEdit;
141     QLineEdit* m_pHistoryEntryStartRegExpEdit;
142     QLineEdit* m_pHistorySortKeyOrderEdit;
143     QLineEdit* m_pHistoryEntryStartExampleEdit;
144     QLineEdit* m_pHistoryEntryStartMatchResult;
145     QLineEdit* m_pHistorySortKeyResult;
146 
147   public:
148     RegExpTester(QWidget* pParent, const QString& autoMergeRegExpToolTip, const QString& historyStartRegExpToolTip,
149         const QString& historyEntryStartRegExpToolTip, const QString& historySortKeyOrderToolTip);
150     void init(const QString& autoMergeRegExp, const QString& historyStartRegExp, const QString& historyEntryStartRegExp, const QString& sortKeyOrder);
151     QString autoMergeRegExp();
152     QString historyStartRegExp();
153     QString historyEntryStartRegExp();
154     QString historySortKeyOrder();
155   public Q_SLOTS:
156     void slotRecalc();
157 };
158 
159 #endif
160