-
Notifications
You must be signed in to change notification settings - Fork 1
/
dlg_markup_sa.cc
158 lines (140 loc) · 5.47 KB
/
dlg_markup_sa.cc
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
/* ----------------------------------------------------------------------------
* Copyright (C) 2007-2010,2020 Th. Zoerner
* ----------------------------------------------------------------------------
* 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 3 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/>.
* ----------------------------------------------------------------------------
*
* Module description:
*
* This module implements a wrapper class that serves as owner of instances of
* the mark-up configuration dialog. There are static interfaces that
* instantiated the wrapper class for each of the pre-defined special-purpose
* mark-up formats. The wrapper class will only create the dialog, then wait
* for its completion signal, upon which it saves the results if applicable,
* and destroys the dialog and itself. The static interfaces ensure that there
* is only one instance of the wrapper and respective dialog for a given
* purpose.
*/
#include <QWidget>
#include <cstdio>
#include <string>
#include <memory>
#include "main_win.h"
#include "highlighter.h"
#include "config_file.h"
#include "dlg_higl.h"
#include "dlg_markup.h"
#include "dlg_markup_sa.h"
// ----------------------------------------------------------------------------
/**
* The constructor creates an instance of the mark-up configuration dialog for
* the given ID.
*/
DlgMarkupSA::DlgMarkupSA(HiglId id, const QString& title, Highlighter * higl,
MainText * mainText, MainWin * mainWin)
: m_id(id)
, m_higl(higl)
, m_mainText(mainText)
, m_mainWin(mainWin)
{
DlgHigl::initColorPalette();
m_dlgWin = std::make_unique<DlgMarkup>(id, higl->getFmtSpecForId(id), title, higl, mainText, mainWin);
connect(m_dlgWin.get(), &DlgMarkup::closeReq, this, &DlgMarkupSA::signalMarkupCloseReq);
connect(m_dlgWin.get(), &DlgMarkup::applyReq, this, &DlgMarkupSA::signalMarkupApplyReq);
}
/**
* This interface function is used to raise the window of the owned mark-up
* dialog, when the user requests to open the dialog when it already exists.
*/
void DlgMarkupSA::raiseWindow()
{
m_dlgWin->activateWindow();
m_dlgWin->raise();
}
/**
* This slot is connected to the signal sent when a mark-up editor dialog is
* closed. The function releases the dialog resources.
*/
void DlgMarkupSA::signalMarkupCloseReq(HiglId id)
{
Q_ASSERT(id == m_id);
if (this == s_bookmarkFmtDlg)
{
delete s_bookmarkFmtDlg;
s_bookmarkFmtDlg = nullptr;
}
else if (this == s_searchFmtDlg)
{
delete s_searchFmtDlg;
s_searchFmtDlg = nullptr;
}
}
/**
* This slot is connected to the signal sent by the mark-up editor upon "Apply"
* or "Ok". The function forwards the new format spec to the highlighter.
*/
void DlgMarkupSA::signalMarkupApplyReq(HiglId id, bool /*immediate*/)
{
Q_ASSERT((id == Highlighter::HIGL_ID_BOOKMARK) || (id == Highlighter::HIGL_ID_SEARCH));
m_higl->setFmtSpec(id, m_dlgWin->getFmtSpec());
m_dlgWin->resetModified();
ConfigFile::updateRcAfterIdle();
}
// ----------------------------------------------------------------------------
// Static interfaces
DlgMarkupSA * DlgMarkupSA::s_searchFmtDlg = nullptr;
DlgMarkupSA * DlgMarkupSA::s_searchIncFmtDlg = nullptr;
DlgMarkupSA * DlgMarkupSA::s_bookmarkFmtDlg = nullptr;
/**
* This common sub-function is used by the static interfaces for actually
* instantiating the wrapper class for a given mark-up ID. If the respective
* instance already exists, its dialog window is raised instead.
*/
void DlgMarkupSA::openDialog(DlgMarkupSA* &ptr, HiglId id, const QString& title,
Highlighter * higl, MainText * mainText, MainWin * mainWin) /*static*/
{
if (ptr == nullptr)
{
ptr = new DlgMarkupSA(id, title, higl, mainText, mainWin);
}
else
{
ptr->raiseWindow();
}
}
/**
* Open or raise the mark-up editor for the mark-up used for highlighting
* complete text lines that match a search.
*/
void DlgMarkupSA::editSearchFmt(Highlighter * higl, MainText * mainText, MainWin * mainWin) /*static*/
{
openDialog(DlgMarkupSA::s_searchFmtDlg, Highlighter::HIGL_ID_SEARCH, "Search matches mark-up", higl, mainText, mainWin);
}
/**
* Open or raise the mark-up editor for the mark-up used for highlighting the
* exact range of text that matches a search. Note this mark-up is always
* applied on top ot the above mark-up.
*/
void DlgMarkupSA::editSearchIncFmt(Highlighter * higl, MainText * mainText, MainWin * mainWin) /*static*/
{
openDialog(DlgMarkupSA::s_searchIncFmtDlg, Highlighter::HIGL_ID_SEARCH_INC, "Search increment mark-up", higl, mainText, mainWin);
}
/**
* Open or raise the mark-up editor for the mark-up used for highlighting
* bookmarked lines.
*/
void DlgMarkupSA::editBookmarkFmt(Highlighter * higl, MainText * mainText, MainWin * mainWin) /*static*/
{
openDialog(DlgMarkupSA::s_bookmarkFmtDlg, Highlighter::HIGL_ID_BOOKMARK, "Bookmarks mark-up", higl, mainText, mainWin);
}