|
a/src/qtgui/preview_w.cpp |
|
b/src/qtgui/preview_w.cpp |
|
... |
|
... |
67 |
static const QKeySequence closeTabKS(Qt::ControlModifier+Qt::Key_W);
|
67 |
static const QKeySequence closeTabKS(Qt::ControlModifier+Qt::Key_W);
|
68 |
static const QKeySequence printTabKS(Qt::ControlModifier+Qt::Key_P);
|
68 |
static const QKeySequence printTabKS(Qt::ControlModifier+Qt::Key_P);
|
69 |
|
69 |
|
70 |
void Preview::init()
|
70 |
void Preview::init()
|
71 |
{
|
71 |
{
|
72 |
setObjectName("Preview");
|
72 |
LOGDEB("Preview::init\n");
|
73 |
QVBoxLayout* previewLayout = new QVBoxLayout(this);
|
73 |
// Create the first tab (the tab widget is created with one
|
|
|
74 |
// initial tab for ease of use in designer, we remove it).
|
|
|
75 |
addEditorTab();
|
|
|
76 |
pvTab->removeTab(0);
|
74 |
|
77 |
|
75 |
pvTab = new QTabWidget(this);
|
78 |
for (const auto& ugroup : m_hData.ugroups) {
|
76 |
|
|
|
77 |
// Create the first tab. Should be possible to use addEditorTab
|
|
|
78 |
// but this causes a pb with the sizeing
|
|
|
79 |
QWidget *unnamed = new QWidget(pvTab);
|
|
|
80 |
QVBoxLayout *unnamedLayout = new QVBoxLayout(unnamed);
|
|
|
81 |
PreviewTextEdit *pvEdit = new PreviewTextEdit(unnamed, "pvEdit", this);
|
|
|
82 |
pvEdit->setReadOnly(true);
|
|
|
83 |
pvEdit->setUndoRedoEnabled(false);
|
|
|
84 |
unnamedLayout->addWidget(pvEdit);
|
|
|
85 |
pvTab->addTab(unnamed, "");
|
|
|
86 |
|
|
|
87 |
previewLayout->addWidget(pvTab);
|
|
|
88 |
|
|
|
89 |
// Create the buttons and entry field
|
|
|
90 |
QHBoxLayout *layout3 = new QHBoxLayout(0);
|
|
|
91 |
searchLabel = new QLabel(this);
|
|
|
92 |
layout3->addWidget(searchLabel);
|
|
|
93 |
|
|
|
94 |
searchTextCMB = new QComboBox(this);
|
|
|
95 |
searchTextCMB->setEditable(true);
|
|
|
96 |
searchTextCMB->setInsertPolicy(QComboBox::NoInsert);
|
|
|
97 |
searchTextCMB->setDuplicatesEnabled(false);
|
|
|
98 |
for (unsigned int i = 0; i < m_hData.ugroups.size(); i++) {
|
|
|
99 |
QString s;
|
79 |
QString s;
|
100 |
for (unsigned int j = 0; j < m_hData.ugroups[i].size(); j++) {
|
80 |
for (const auto& elt : ugroup) {
|
101 |
s.append(QString::fromUtf8(m_hData.ugroups[i][j].c_str()));
|
81 |
s.append(u8s2qs(elt));
|
102 |
if (j != m_hData.ugroups[i].size()-1)
|
|
|
103 |
s.append(" ");
|
|
|
104 |
}
|
82 |
}
|
|
|
83 |
s = s.trimmed();
|
105 |
searchTextCMB->addItem(s);
|
84 |
searchTextCMB->addItem(s);
|
106 |
}
|
85 |
}
|
107 |
searchTextCMB->setEditText("");
|
|
|
108 |
searchTextCMB->setCompleter(0);
|
86 |
searchTextCMB->setCompleter(0);
|
109 |
|
87 |
|
110 |
layout3->addWidget(searchTextCMB);
|
88 |
if (prefs.pvwidth > 100) {
|
111 |
|
89 |
resize(prefs.pvwidth, prefs.pvheight);
|
112 |
nextButton = new QPushButton(this);
|
90 |
} else {
|
113 |
nextButton->setEnabled(true);
|
|
|
114 |
layout3->addWidget(nextButton);
|
|
|
115 |
prevButton = new QPushButton(this);
|
|
|
116 |
prevButton->setEnabled(true);
|
|
|
117 |
layout3->addWidget(prevButton);
|
|
|
118 |
clearPB = new QPushButton(this);
|
|
|
119 |
clearPB->setEnabled(false);
|
|
|
120 |
layout3->addWidget(clearPB);
|
|
|
121 |
matchCheck = new QCheckBox(this);
|
|
|
122 |
layout3->addWidget(matchCheck);
|
|
|
123 |
|
|
|
124 |
previewLayout->addLayout(layout3);
|
|
|
125 |
|
|
|
126 |
resize(QSize(640, 480).expandedTo(minimumSizeHint()));
|
91 |
resize(QSize(640, 480).expandedTo(minimumSizeHint()));
|
127 |
|
92 |
}
|
128 |
// buddies
|
|
|
129 |
searchLabel->setBuddy(searchTextCMB);
|
|
|
130 |
|
|
|
131 |
searchLabel->setText(tr("&Search for:"));
|
|
|
132 |
nextButton->setText(tr("&Next"));
|
|
|
133 |
prevButton->setText(tr("&Previous"));
|
|
|
134 |
clearPB->setText(tr("Clear"));
|
|
|
135 |
matchCheck->setText(tr("Match &Case"));
|
|
|
136 |
|
|
|
137 |
QPushButton * bt = new QPushButton(tr("Close Tab"), this);
|
|
|
138 |
pvTab->setCornerWidget(bt);
|
|
|
139 |
|
93 |
|
140 |
(void)new HelpClient(this);
|
94 |
(void)new HelpClient(this);
|
141 |
HelpClient::installMap((const char *)objectName().toUtf8(),
|
95 |
HelpClient::installMap((const char *)objectName().toUtf8(),
|
142 |
"RCL.SEARCH.GUI.PREVIEW");
|
96 |
"RCL.SEARCH.GUI.PREVIEW");
|
143 |
|
97 |
|
144 |
// signals and slots connections
|
98 |
// signals and slots connections
|
145 |
connect(searchTextCMB, SIGNAL(activated(int)),
|
99 |
connect(searchTextCMB, SIGNAL(activated(int)),
|
146 |
this, SLOT(searchTextFromIndex(int)));
|
100 |
this, SLOT(searchTextFromIndex(int)));
|
147 |
connect(searchTextCMB, SIGNAL(editTextChanged(const QString&)),
|
101 |
connect(searchTextCMB, SIGNAL(editTextChanged(const QString&)),
|
148 |
this, SLOT(searchTextChanged(const QString&)));
|
102 |
this, SLOT(searchTextChanged(const QString&)));
|
149 |
connect(nextButton, SIGNAL(clicked()), this, SLOT(nextPressed()));
|
103 |
connect(nextPB, SIGNAL(clicked()), this, SLOT(nextPressed()));
|
150 |
connect(prevButton, SIGNAL(clicked()), this, SLOT(prevPressed()));
|
104 |
connect(prevPB, SIGNAL(clicked()), this, SLOT(prevPressed()));
|
151 |
connect(clearPB, SIGNAL(clicked()), searchTextCMB, SLOT(clearEditText()));
|
105 |
connect(clearPB, SIGNAL(clicked()), searchTextCMB, SLOT(clearEditText()));
|
152 |
connect(pvTab, SIGNAL(currentChanged(int)),
|
106 |
connect(pvTab, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
|
153 |
this, SLOT(currentChanged(int)));
|
|
|
154 |
connect(bt, SIGNAL(clicked()), this, SLOT(closeCurrentTab()));
|
107 |
connect(pvTab, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
|
155 |
|
108 |
|
156 |
connect(new QShortcut(closeKS, this), SIGNAL (activated()),
|
109 |
connect(new QShortcut(closeKS, this), SIGNAL (activated()),
|
157 |
this, SLOT (close()));
|
110 |
this, SLOT (close()));
|
158 |
connect(new QShortcut(nextDocInTabKS, this), SIGNAL (activated()),
|
111 |
connect(new QShortcut(nextDocInTabKS, this), SIGNAL (activated()),
|
159 |
this, SLOT (emitShowNext()));
|
112 |
this, SLOT (emitShowNext()));
|
|
... |
|
... |
162 |
connect(new QShortcut(closeTabKS, this), SIGNAL (activated()),
|
115 |
connect(new QShortcut(closeTabKS, this), SIGNAL (activated()),
|
163 |
this, SLOT (closeCurrentTab()));
|
116 |
this, SLOT (closeCurrentTab()));
|
164 |
connect(new QShortcut(printTabKS, this), SIGNAL (activated()),
|
117 |
connect(new QShortcut(printTabKS, this), SIGNAL (activated()),
|
165 |
this, SIGNAL (printCurrentPreviewRequest()));
|
118 |
this, SIGNAL (printCurrentPreviewRequest()));
|
166 |
|
119 |
|
167 |
if (prefs.pvwidth > 100) {
|
|
|
168 |
resize(prefs.pvwidth, prefs.pvheight);
|
|
|
169 |
}
|
|
|
170 |
currentChanged(pvTab->currentIndex());
|
120 |
currentChanged(pvTab->currentIndex());
|
171 |
}
|
121 |
}
|
172 |
|
122 |
|
173 |
void Preview::emitShowNext()
|
123 |
void Preview::emitShowNext()
|
174 |
{
|
124 |
{
|
|
... |
|
... |
201 |
prefs.pvwidth = width();
|
151 |
prefs.pvwidth = width();
|
202 |
prefs.pvheight = height();
|
152 |
prefs.pvheight = height();
|
203 |
|
153 |
|
204 |
/* Release all temporary files (but maybe none is actually set) */
|
154 |
/* Release all temporary files (but maybe none is actually set) */
|
205 |
for (int i = 0; i < pvTab->count(); i++) {
|
155 |
for (int i = 0; i < pvTab->count(); i++) {
|
206 |
QWidget *tw = pvTab->widget(i);
|
|
|
207 |
if (tw) {
|
|
|
208 |
PreviewTextEdit *edit =
|
156 |
PreviewTextEdit *edit = editor(i);
|
209 |
tw->findChild<PreviewTextEdit*>("pvEdit");
|
|
|
210 |
if (edit) {
|
157 |
if (edit) {
|
211 |
forgetTempFile(edit->m_tmpfilename);
|
158 |
forgetTempFile(edit->m_tmpfilename);
|
212 |
}
|
|
|
213 |
}
|
159 |
}
|
214 |
}
|
160 |
}
|
215 |
emit previewExposed(this, m_searchId, -1);
|
161 |
emit previewExposed(this, m_searchId, -1);
|
216 |
emit previewClosed(this);
|
162 |
emit previewClosed(this);
|
217 |
QWidget::closeEvent(e);
|
163 |
QWidget::closeEvent(e);
|
|
... |
|
... |
293 |
{
|
239 |
{
|
294 |
LOGDEB1("search line from index " << idx << "\n");
|
240 |
LOGDEB1("search line from index " << idx << "\n");
|
295 |
m_searchTextFromIndex = idx;
|
241 |
m_searchTextFromIndex = idx;
|
296 |
}
|
242 |
}
|
297 |
|
243 |
|
298 |
PreviewTextEdit *Preview::currentEditor()
|
|
|
299 |
{
|
|
|
300 |
LOGDEB2("Preview::currentEditor()\n");
|
|
|
301 |
QWidget *tw = pvTab->currentWidget();
|
|
|
302 |
PreviewTextEdit *edit = 0;
|
|
|
303 |
if (tw) {
|
|
|
304 |
edit = tw->findChild<PreviewTextEdit*>("pvEdit");
|
|
|
305 |
}
|
|
|
306 |
return edit;
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
// Save current document to file
|
244 |
// Save current document to file
|
310 |
void Preview::emitSaveDocToFile()
|
245 |
void Preview::emitSaveDocToFile()
|
311 |
{
|
246 |
{
|
312 |
PreviewTextEdit *ce = currentEditor();
|
247 |
PreviewTextEdit *ce = currentEditor();
|
313 |
if (ce && !ce->m_dbdoc.url.empty()) {
|
248 |
if (ce && !ce->m_dbdoc.url.empty()) {
|
|
... |
|
... |
325 |
LOGDEB("Preview::doSearch: text [" << qs2utf8s(_text) << "] idx " <<
|
260 |
LOGDEB("Preview::doSearch: text [" << qs2utf8s(_text) << "] idx " <<
|
326 |
m_searchTextFromIndex << " next " << next << " rev " << reverse <<
|
261 |
m_searchTextFromIndex << " next " << next << " rev " << reverse <<
|
327 |
" word " << wordOnly << "\n");
|
262 |
" word " << wordOnly << "\n");
|
328 |
QString text = _text;
|
263 |
QString text = _text;
|
329 |
|
264 |
|
330 |
bool matchCase = matchCheck->isChecked();
|
265 |
bool matchCase = casematchCB->isChecked();
|
331 |
PreviewTextEdit *edit = currentEditor();
|
266 |
PreviewTextEdit *edit = currentEditor();
|
332 |
if (edit == 0) {
|
267 |
if (edit == 0) {
|
333 |
// ??
|
268 |
// ??
|
334 |
return;
|
269 |
return;
|
335 |
}
|
270 |
}
|
|
... |
|
... |
417 |
|
352 |
|
418 |
// Called when user clicks on tab
|
353 |
// Called when user clicks on tab
|
419 |
void Preview::currentChanged(int index)
|
354 |
void Preview::currentChanged(int index)
|
420 |
{
|
355 |
{
|
421 |
LOGDEB2("PreviewTextEdit::currentChanged\n");
|
356 |
LOGDEB2("PreviewTextEdit::currentChanged\n");
|
422 |
QWidget *tw = pvTab->widget(index);
|
|
|
423 |
PreviewTextEdit *edit =
|
357 |
PreviewTextEdit *edit = editor(index);
|
424 |
tw->findChild<PreviewTextEdit*>("pvEdit");
|
|
|
425 |
LOGDEB1("Preview::currentChanged(). Editor: " << edit << "\n");
|
358 |
LOGDEB1("Preview::currentChanged(). Editor: " << edit << "\n");
|
426 |
|
359 |
|
427 |
if (edit == 0) {
|
360 |
if (edit == 0) {
|
428 |
LOGERR("Editor child not found\n");
|
361 |
LOGERR("Editor child not found\n");
|
429 |
return;
|
362 |
return;
|
430 |
}
|
363 |
}
|
431 |
edit->setFocus();
|
364 |
edit->setFocus();
|
432 |
// Disconnect the print signal and reconnect it to the current editor
|
365 |
// Disconnect the print signal and reconnect it to the current editor
|
433 |
LOGDEB("Disconnecting reconnecting print signal\n");
|
366 |
LOGDEB1("Disconnecting reconnecting print signal\n");
|
434 |
disconnect(this, SIGNAL(printCurrentPreviewRequest()), 0, 0);
|
367 |
disconnect(this, SIGNAL(printCurrentPreviewRequest()), 0, 0);
|
435 |
connect(this, SIGNAL(printCurrentPreviewRequest()), edit, SLOT(print()));
|
368 |
connect(this, SIGNAL(printCurrentPreviewRequest()), edit, SLOT(print()));
|
436 |
edit->installEventFilter(this);
|
369 |
edit->installEventFilter(this);
|
437 |
edit->viewport()->installEventFilter(this);
|
370 |
edit->viewport()->installEventFilter(this);
|
438 |
searchTextCMB->installEventFilter(this);
|
371 |
searchTextCMB->installEventFilter(this);
|
|
... |
|
... |
444 |
LOGDEB1("Preview::closeCurrentTab: m_loading " << m_loading << "\n");
|
377 |
LOGDEB1("Preview::closeCurrentTab: m_loading " << m_loading << "\n");
|
445 |
if (m_loading) {
|
378 |
if (m_loading) {
|
446 |
CancelCheck::instance().setCancel();
|
379 |
CancelCheck::instance().setCancel();
|
447 |
return;
|
380 |
return;
|
448 |
}
|
381 |
}
|
|
|
382 |
closeTab(pvTab->currentIndex());
|
|
|
383 |
}
|
|
|
384 |
|
|
|
385 |
void Preview::closeTab(int index)
|
|
|
386 |
{
|
|
|
387 |
LOGDEB1("Preview::closeTab: m_loading " << m_loading << "\n");
|
|
|
388 |
if (m_loading) {
|
|
|
389 |
CancelCheck::instance().setCancel();
|
|
|
390 |
return;
|
|
|
391 |
}
|
449 |
PreviewTextEdit *e = currentEditor();
|
392 |
PreviewTextEdit *edit = editor(index);
|
450 |
if (e)
|
393 |
if (edit)
|
451 |
forgetTempFile(e->m_tmpfilename);
|
394 |
forgetTempFile(edit->m_tmpfilename);
|
452 |
if (pvTab->count() > 1) {
|
395 |
if (pvTab->count() > 1) {
|
453 |
pvTab->removeTab(pvTab->currentIndex());
|
396 |
pvTab->removeTab(index);
|
454 |
} else {
|
397 |
} else {
|
455 |
close();
|
398 |
close();
|
456 |
}
|
399 |
}
|
457 |
}
|
400 |
}
|
458 |
|
401 |
|
|
|
402 |
PreviewTextEdit *Preview::editor(int index)
|
|
|
403 |
{
|
|
|
404 |
return dynamic_cast<PreviewTextEdit*>(pvTab->widget(index));
|
|
|
405 |
}
|
|
|
406 |
|
|
|
407 |
PreviewTextEdit *Preview::currentEditor()
|
|
|
408 |
{
|
|
|
409 |
LOGDEB2("Preview::currentEditor()\n");
|
|
|
410 |
return editor(pvTab->currentIndex());
|
|
|
411 |
}
|
|
|
412 |
|
459 |
PreviewTextEdit *Preview::addEditorTab()
|
413 |
PreviewTextEdit *Preview::addEditorTab()
|
460 |
{
|
414 |
{
|
461 |
LOGDEB1("PreviewTextEdit::addEditorTab()\n");
|
415 |
LOGDEB1("PreviewTextEdit::addEditorTab()\n");
|
462 |
QWidget *anon = new QWidget((QWidget *)pvTab);
|
|
|
463 |
QVBoxLayout *anonLayout = new QVBoxLayout(anon);
|
|
|
464 |
PreviewTextEdit *editor = new PreviewTextEdit(anon, "pvEdit", this);
|
416 |
PreviewTextEdit *editor = new PreviewTextEdit(pvTab, "pvEdit", this);
|
465 |
editor->setReadOnly(true);
|
417 |
editor->setReadOnly(true);
|
466 |
editor->setUndoRedoEnabled(false );
|
418 |
editor->setUndoRedoEnabled(false );
|
467 |
anonLayout->addWidget(editor);
|
|
|
468 |
pvTab->addTab(anon, "Tab");
|
419 |
pvTab->addTab(editor, "Tab");
|
469 |
pvTab->setCurrentIndex(pvTab->count() -1);
|
420 |
pvTab->setCurrentIndex(pvTab->count() - 1);
|
470 |
return editor;
|
421 |
return editor;
|
471 |
}
|
422 |
}
|
472 |
|
423 |
|
473 |
void Preview::setCurTabProps(const Rcl::Doc &doc, int docnum)
|
424 |
void Preview::setCurTabProps(const Rcl::Doc &doc, int docnum)
|
474 |
{
|
425 |
{
|
|
... |
|
... |
521 |
return false;
|
472 |
return false;
|
522 |
}
|
473 |
}
|
523 |
|
474 |
|
524 |
/* Check if we already have this page */
|
475 |
/* Check if we already have this page */
|
525 |
for (int i = 0; i < pvTab->count(); i++) {
|
476 |
for (int i = 0; i < pvTab->count(); i++) {
|
526 |
QWidget *tw = pvTab->widget(i);
|
|
|
527 |
if (tw) {
|
|
|
528 |
PreviewTextEdit *edit =
|
477 |
PreviewTextEdit *edit = editor(i);
|
529 |
tw->findChild<PreviewTextEdit*>("pvEdit");
|
|
|
530 |
if (edit && !edit->m_url.compare(doc.url) &&
|
478 |
if (edit && !edit->m_url.compare(doc.url) &&
|
531 |
!edit->m_ipath.compare(doc.ipath)) {
|
479 |
!edit->m_ipath.compare(doc.ipath)) {
|
532 |
pvTab->setCurrentIndex(i);
|
480 |
pvTab->setCurrentIndex(i);
|
533 |
return true;
|
481 |
return true;
|
534 |
}
|
|
|
535 |
}
|
482 |
}
|
536 |
}
|
483 |
}
|
537 |
|
484 |
|
538 |
// if just created the first tab was created during init
|
485 |
// if just created the first tab was created during init
|
539 |
if (!sametab && !m_justCreated && !addEditorTab()) {
|
486 |
if (!sametab && !m_justCreated && !addEditorTab()) {
|
|
... |
|
... |
545 |
return false;
|
492 |
return false;
|
546 |
}
|
493 |
}
|
547 |
raise();
|
494 |
raise();
|
548 |
return true;
|
495 |
return true;
|
549 |
}
|
496 |
}
|
|
|
497 |
|
550 |
void Preview::togglePlainPre()
|
498 |
void Preview::togglePlainPre()
|
551 |
{
|
499 |
{
|
552 |
switch (prefs.previewPlainPre) {
|
500 |
switch (prefs.previewPlainPre) {
|
553 |
case PrefsPack::PP_BR:
|
501 |
case PrefsPack::PP_BR:
|
554 |
prefs.previewPlainPre = PrefsPack::PP_PRE;
|
502 |
prefs.previewPlainPre = PrefsPack::PP_PRE;
|