|
a/src/qtgui/preview_w.cpp |
|
b/src/qtgui/preview_w.cpp |
|
... |
|
... |
57 |
#include "guiutils.h"
|
57 |
#include "guiutils.h"
|
58 |
#include "docseqhist.h"
|
58 |
#include "docseqhist.h"
|
59 |
#include "rclhelp.h"
|
59 |
#include "rclhelp.h"
|
60 |
#include "preview_load.h"
|
60 |
#include "preview_load.h"
|
61 |
#include "preview_plaintorich.h"
|
61 |
#include "preview_plaintorich.h"
|
|
|
62 |
#include "rclmain_w.h"
|
62 |
|
63 |
|
63 |
static const QKeySequence closeKS(Qt::Key_Escape);
|
64 |
static const QKeySequence closeKS(Qt::Key_Escape);
|
64 |
static const QKeySequence nextDocInTabKS(Qt::ShiftModifier+Qt::Key_Down);
|
65 |
static const QKeySequence nextDocInTabKS(Qt::ShiftModifier+Qt::Key_Down);
|
65 |
static const QKeySequence prevDocInTabKS(Qt::ShiftModifier+Qt::Key_Up);
|
66 |
static const QKeySequence prevDocInTabKS(Qt::ShiftModifier+Qt::Key_Up);
|
66 |
static const QKeySequence closeTabKS(Qt::ControlModifier+Qt::Key_W);
|
67 |
static const QKeySequence closeTabKS(Qt::ControlModifier+Qt::Key_W);
|
|
... |
|
... |
161 |
connect(new QShortcut(closeTabKS, this), SIGNAL (activated()),
|
162 |
connect(new QShortcut(closeTabKS, this), SIGNAL (activated()),
|
162 |
this, SLOT (closeCurrentTab()));
|
163 |
this, SLOT (closeCurrentTab()));
|
163 |
connect(new QShortcut(printTabKS, this), SIGNAL (activated()),
|
164 |
connect(new QShortcut(printTabKS, this), SIGNAL (activated()),
|
164 |
this, SIGNAL (printCurrentPreviewRequest()));
|
165 |
this, SIGNAL (printCurrentPreviewRequest()));
|
165 |
|
166 |
|
166 |
m_dynSearchActive = false;
|
|
|
167 |
m_canBeep = true;
|
|
|
168 |
if (prefs.pvwidth > 100) {
|
167 |
if (prefs.pvwidth > 100) {
|
169 |
resize(prefs.pvwidth, prefs.pvheight);
|
168 |
resize(prefs.pvwidth, prefs.pvheight);
|
170 |
}
|
169 |
}
|
171 |
m_loading = false;
|
|
|
172 |
currentChanged(pvTab->currentIndex());
|
170 |
currentChanged(pvTab->currentIndex());
|
173 |
m_justCreated = true;
|
|
|
174 |
}
|
171 |
}
|
175 |
|
172 |
|
176 |
void Preview::emitShowNext()
|
173 |
void Preview::emitShowNext()
|
177 |
{
|
174 |
{
|
178 |
if (m_loading)
|
175 |
if (m_loading)
|
|
... |
|
... |
193 |
}
|
190 |
}
|
194 |
}
|
191 |
}
|
195 |
|
192 |
|
196 |
void Preview::closeEvent(QCloseEvent *e)
|
193 |
void Preview::closeEvent(QCloseEvent *e)
|
197 |
{
|
194 |
{
|
198 |
LOGDEB("Preview::closeEvent. m_loading " << (m_loading) << "\n" );
|
195 |
LOGDEB("Preview::closeEvent. m_loading " << m_loading << "\n");
|
199 |
if (m_loading) {
|
196 |
if (m_loading) {
|
200 |
CancelCheck::instance().setCancel();
|
197 |
CancelCheck::instance().setCancel();
|
201 |
e->ignore();
|
198 |
e->ignore();
|
202 |
return;
|
199 |
return;
|
203 |
}
|
200 |
}
|
|
... |
|
... |
224 |
|
221 |
|
225 |
bool Preview::eventFilter(QObject *target, QEvent *event)
|
222 |
bool Preview::eventFilter(QObject *target, QEvent *event)
|
226 |
{
|
223 |
{
|
227 |
if (event->type() != QEvent::KeyPress) {
|
224 |
if (event->type() != QEvent::KeyPress) {
|
228 |
#if 0
|
225 |
#if 0
|
229 |
LOGDEB("Preview::eventFilter(): " << (eventTypeToStr(event->type())) << "\n" );
|
226 |
LOGDEB("Preview::eventFilter(): " << eventTypeToStr(event->type()) <<
|
|
|
227 |
"\n");
|
230 |
if (event->type() == QEvent::MouseButtonRelease) {
|
228 |
if (event->type() == QEvent::MouseButtonRelease) {
|
231 |
QMouseEvent *mev = (QMouseEvent *)event;
|
229 |
QMouseEvent *mev = (QMouseEvent *)event;
|
232 |
LOGDEB("Mouse: GlobalY " << (mev->globalY()) << " y " << (mev->y()) << "\n" );
|
230 |
LOGDEB("Mouse: GlobalY " << mev->globalY() << " y " << mev->y() <<
|
|
|
231 |
"\n");
|
233 |
}
|
232 |
}
|
234 |
#endif
|
233 |
#endif
|
235 |
return false;
|
234 |
return false;
|
236 |
}
|
235 |
}
|
237 |
|
236 |
|
238 |
PreviewTextEdit *edit = currentEditor();
|
237 |
PreviewTextEdit *edit = currentEditor();
|
239 |
QKeyEvent *keyEvent = (QKeyEvent *)event;
|
238 |
QKeyEvent *keyEvent = (QKeyEvent *)event;
|
240 |
|
239 |
|
241 |
if (m_dynSearchActive) {
|
240 |
if (m_dynSearchActive) {
|
242 |
if (keyEvent->key() == Qt::Key_F3) {
|
241 |
if (keyEvent->key() == Qt::Key_F3) {
|
243 |
LOGDEB2("Preview::eventFilter: got F3\n" );
|
242 |
LOGDEB2("Preview::eventFilter: got F3\n");
|
244 |
doSearch(searchTextCMB->currentText(), true,
|
243 |
doSearch(searchTextCMB->currentText(), true,
|
245 |
(keyEvent->modifiers() & Qt::ShiftModifier) != 0);
|
244 |
(keyEvent->modifiers() & Qt::ShiftModifier) != 0);
|
246 |
return true;
|
245 |
return true;
|
247 |
}
|
246 |
}
|
248 |
if (target != searchTextCMB)
|
247 |
if (target != searchTextCMB)
|
|
... |
|
... |
251 |
if (edit &&
|
250 |
if (edit &&
|
252 |
(target == edit || target == edit->viewport())) {
|
251 |
(target == edit || target == edit->viewport())) {
|
253 |
if (keyEvent->key() == Qt::Key_Slash ||
|
252 |
if (keyEvent->key() == Qt::Key_Slash ||
|
254 |
(keyEvent->key() == Qt::Key_F &&
|
253 |
(keyEvent->key() == Qt::Key_F &&
|
255 |
(keyEvent->modifiers() & Qt::ControlModifier))) {
|
254 |
(keyEvent->modifiers() & Qt::ControlModifier))) {
|
256 |
LOGDEB2("Preview::eventFilter: got / or C-F\n" );
|
255 |
LOGDEB2("Preview::eventFilter: got / or C-F\n");
|
257 |
searchTextCMB->setFocus();
|
256 |
searchTextCMB->setFocus();
|
258 |
m_dynSearchActive = true;
|
257 |
m_dynSearchActive = true;
|
259 |
return true;
|
258 |
return true;
|
260 |
} else if (keyEvent->key() == Qt::Key_Space) {
|
259 |
} else if (keyEvent->key() == Qt::Key_Space) {
|
261 |
LOGDEB2("Preview::eventFilter: got Space\n" );
|
260 |
LOGDEB2("Preview::eventFilter: got Space\n");
|
262 |
int value = edit->verticalScrollBar()->value();
|
261 |
int value = edit->verticalScrollBar()->value();
|
263 |
value += edit->verticalScrollBar()->pageStep();
|
262 |
value += edit->verticalScrollBar()->pageStep();
|
264 |
edit->verticalScrollBar()->setValue(value);
|
263 |
edit->verticalScrollBar()->setValue(value);
|
265 |
return true;
|
264 |
return true;
|
266 |
} else if (keyEvent->key() == Qt::Key_Backspace) {
|
265 |
} else if (keyEvent->key() == Qt::Key_Backspace) {
|
267 |
LOGDEB2("Preview::eventFilter: got Backspace\n" );
|
266 |
LOGDEB2("Preview::eventFilter: got Backspace\n");
|
268 |
int value = edit->verticalScrollBar()->value();
|
267 |
int value = edit->verticalScrollBar()->value();
|
269 |
value -= edit->verticalScrollBar()->pageStep();
|
268 |
value -= edit->verticalScrollBar()->pageStep();
|
270 |
edit->verticalScrollBar()->setValue(value);
|
269 |
edit->verticalScrollBar()->setValue(value);
|
271 |
return true;
|
270 |
return true;
|
272 |
}
|
271 |
}
|
|
... |
|
... |
276 |
return false;
|
275 |
return false;
|
277 |
}
|
276 |
}
|
278 |
|
277 |
|
279 |
void Preview::searchTextChanged(const QString & text)
|
278 |
void Preview::searchTextChanged(const QString & text)
|
280 |
{
|
279 |
{
|
281 |
LOGDEB1("Search line text changed. text: '" << ((const char *)text.toUtf8()) << "'\n" );
|
280 |
LOGDEB1("Search line text changed. text: '" << qs2utf8s(text) << "'\n");
|
282 |
m_searchTextFromIndex = -1;
|
281 |
m_searchTextFromIndex = -1;
|
283 |
if (text.isEmpty()) {
|
282 |
if (text.isEmpty()) {
|
284 |
m_dynSearchActive = false;
|
283 |
m_dynSearchActive = false;
|
285 |
clearPB->setEnabled(false);
|
284 |
clearPB->setEnabled(false);
|
286 |
} else {
|
285 |
} else {
|
|
... |
|
... |
290 |
}
|
289 |
}
|
291 |
}
|
290 |
}
|
292 |
|
291 |
|
293 |
void Preview::searchTextFromIndex(int idx)
|
292 |
void Preview::searchTextFromIndex(int idx)
|
294 |
{
|
293 |
{
|
295 |
LOGDEB1("search line from index " << (idx) << "\n" );
|
294 |
LOGDEB1("search line from index " << idx << "\n");
|
296 |
m_searchTextFromIndex = idx;
|
295 |
m_searchTextFromIndex = idx;
|
297 |
}
|
296 |
}
|
298 |
|
297 |
|
299 |
PreviewTextEdit *Preview::currentEditor()
|
298 |
PreviewTextEdit *Preview::currentEditor()
|
300 |
{
|
299 |
{
|
301 |
LOGDEB2("Preview::currentEditor()\n" );
|
300 |
LOGDEB2("Preview::currentEditor()\n");
|
302 |
QWidget *tw = pvTab->currentWidget();
|
301 |
QWidget *tw = pvTab->currentWidget();
|
303 |
PreviewTextEdit *edit = 0;
|
302 |
PreviewTextEdit *edit = 0;
|
304 |
if (tw) {
|
303 |
if (tw) {
|
305 |
edit = tw->findChild<PreviewTextEdit*>("pvEdit");
|
304 |
edit = tw->findChild<PreviewTextEdit*>("pvEdit");
|
306 |
}
|
305 |
}
|
|
... |
|
... |
321 |
// false, the search string has been modified, we search for the new string,
|
320 |
// false, the search string has been modified, we search for the new string,
|
322 |
// starting from the current position
|
321 |
// starting from the current position
|
323 |
void Preview::doSearch(const QString &_text, bool next, bool reverse,
|
322 |
void Preview::doSearch(const QString &_text, bool next, bool reverse,
|
324 |
bool wordOnly)
|
323 |
bool wordOnly)
|
325 |
{
|
324 |
{
|
326 |
LOGDEB("Preview::doSearch: text [" << ((const char *)_text.toUtf8()) << "] idx " << (m_searchTextFromIndex) << " next " << (int(next)) << " rev " << (int(reverse)) << " word " << (int(wordOnly)) << "\n" );
|
325 |
LOGDEB("Preview::doSearch: text [" << qs2utf8s(_text) << "] idx " <<
|
|
|
326 |
m_searchTextFromIndex << " next " << next << " rev " << reverse <<
|
|
|
327 |
" word " << wordOnly << "\n");
|
327 |
QString text = _text;
|
328 |
QString text = _text;
|
328 |
|
329 |
|
329 |
bool matchCase = matchCheck->isChecked();
|
330 |
bool matchCase = matchCheck->isChecked();
|
330 |
PreviewTextEdit *edit = currentEditor();
|
331 |
PreviewTextEdit *edit = currentEditor();
|
331 |
if (edit == 0) {
|
332 |
if (edit == 0) {
|
|
... |
|
... |
333 |
return;
|
334 |
return;
|
334 |
}
|
335 |
}
|
335 |
|
336 |
|
336 |
if (text.isEmpty() || m_searchTextFromIndex != -1) {
|
337 |
if (text.isEmpty() || m_searchTextFromIndex != -1) {
|
337 |
if (!edit->m_plaintorich->haveAnchors()) {
|
338 |
if (!edit->m_plaintorich->haveAnchors()) {
|
338 |
LOGDEB("NO ANCHORS\n" );
|
339 |
LOGDEB("NO ANCHORS\n");
|
339 |
return;
|
340 |
return;
|
340 |
}
|
341 |
}
|
341 |
// The combobox indices are equal to the search ugroup indices
|
342 |
// The combobox indices are equal to the search ugroup indices
|
342 |
// in hldata, that's how we built the list.
|
343 |
// in hldata, that's how we built the list.
|
343 |
if (reverse) {
|
344 |
if (reverse) {
|
344 |
edit->m_plaintorich->prevAnchorNum(m_searchTextFromIndex);
|
345 |
edit->m_plaintorich->prevAnchorNum(m_searchTextFromIndex);
|
345 |
} else {
|
346 |
} else {
|
346 |
edit->m_plaintorich->nextAnchorNum(m_searchTextFromIndex);
|
347 |
edit->m_plaintorich->nextAnchorNum(m_searchTextFromIndex);
|
347 |
}
|
348 |
}
|
348 |
QString aname = edit->m_plaintorich->curAnchorName();
|
349 |
QString aname = edit->m_plaintorich->curAnchorName();
|
349 |
LOGDEB("Calling scrollToAnchor(" << ((const char *)aname.toUtf8()) << ")\n" );
|
350 |
LOGDEB("Calling scrollToAnchor(" << qs2utf8s(aname) << ")\n");
|
350 |
edit->scrollToAnchor(aname);
|
351 |
edit->scrollToAnchor(aname);
|
351 |
// Position the cursor approximately at the anchor (top of
|
352 |
// Position the cursor approximately at the anchor (top of
|
352 |
// viewport) so that searches start from here
|
353 |
// viewport) so that searches start from here
|
353 |
QTextCursor cursor = edit->cursorForPosition(QPoint(0, 0));
|
354 |
QTextCursor cursor = edit->cursorForPosition(QPoint(0, 0));
|
354 |
edit->setTextCursor(cursor);
|
355 |
edit->setTextCursor(cursor);
|
|
... |
|
... |
364 |
QTextCursor cursor = edit->textCursor();
|
365 |
QTextCursor cursor = edit->textCursor();
|
365 |
cursor.setPosition(cursor.anchor(), QTextCursor::KeepAnchor);
|
366 |
cursor.setPosition(cursor.anchor(), QTextCursor::KeepAnchor);
|
366 |
edit->setTextCursor(cursor);
|
367 |
edit->setTextCursor(cursor);
|
367 |
}
|
368 |
}
|
368 |
Chrono chron;
|
369 |
Chrono chron;
|
369 |
LOGDEB("Preview::doSearch: first find call\n" );
|
370 |
LOGDEB("Preview::doSearch: first find call\n");
|
370 |
QTextDocument::FindFlags flags = 0;
|
371 |
QTextDocument::FindFlags flags = 0;
|
371 |
if (reverse)
|
372 |
if (reverse)
|
372 |
flags |= QTextDocument::FindBackward;
|
373 |
flags |= QTextDocument::FindBackward;
|
373 |
if (wordOnly)
|
374 |
if (wordOnly)
|
374 |
flags |= QTextDocument::FindWholeWords;
|
375 |
flags |= QTextDocument::FindWholeWords;
|
375 |
if (matchCase)
|
376 |
if (matchCase)
|
376 |
flags |= QTextDocument::FindCaseSensitively;
|
377 |
flags |= QTextDocument::FindCaseSensitively;
|
377 |
bool found = edit->find(text, flags);
|
378 |
bool found = edit->find(text, flags);
|
378 |
LOGDEB("Preview::doSearch: first find call return: found " << (found) << " " << (chron.secs()) << " S\n" );
|
379 |
LOGDEB("Preview::doSearch: first find call return: found " << found <<
|
|
|
380 |
" " << chron.secs() << " S\n");
|
379 |
// If not found, try to wrap around.
|
381 |
// If not found, try to wrap around.
|
380 |
if (!found) {
|
382 |
if (!found) {
|
381 |
LOGDEB("Preview::doSearch: wrapping around\n" );
|
383 |
LOGDEB("Preview::doSearch: wrapping around\n");
|
382 |
if (reverse) {
|
384 |
if (reverse) {
|
383 |
edit->moveCursor (QTextCursor::End);
|
385 |
edit->moveCursor (QTextCursor::End);
|
384 |
} else {
|
386 |
} else {
|
385 |
edit->moveCursor (QTextCursor::Start);
|
387 |
edit->moveCursor (QTextCursor::Start);
|
386 |
}
|
388 |
}
|
387 |
LOGDEB("Preview::doSearch: 2nd find call\n" );
|
389 |
LOGDEB("Preview::doSearch: 2nd find call\n");
|
388 |
chron.restart();
|
390 |
chron.restart();
|
389 |
found = edit->find(text, flags);
|
391 |
found = edit->find(text, flags);
|
390 |
LOGDEB("Preview::doSearch: 2nd find call return found " << (found) << " " << (chron.secs()) << " S\n" );
|
392 |
LOGDEB("Preview::doSearch: 2nd find call return found " << found <<
|
|
|
393 |
" " << chron.secs() << " S\n");
|
391 |
}
|
394 |
}
|
392 |
|
395 |
|
393 |
if (found) {
|
396 |
if (found) {
|
394 |
m_canBeep = true;
|
397 |
m_canBeep = true;
|
395 |
} else {
|
398 |
} else {
|
396 |
if (m_canBeep)
|
399 |
if (m_canBeep)
|
397 |
QApplication::beep();
|
400 |
QApplication::beep();
|
398 |
m_canBeep = false;
|
401 |
m_canBeep = false;
|
399 |
}
|
402 |
}
|
400 |
LOGDEB("Preview::doSearch: return\n" );
|
403 |
LOGDEB("Preview::doSearch: return\n");
|
401 |
}
|
404 |
}
|
402 |
|
405 |
|
403 |
void Preview::nextPressed()
|
406 |
void Preview::nextPressed()
|
404 |
{
|
407 |
{
|
405 |
LOGDEB2("Preview::nextPressed\n" );
|
408 |
LOGDEB2("Preview::nextPressed\n");
|
406 |
doSearch(searchTextCMB->currentText(), true, false);
|
409 |
doSearch(searchTextCMB->currentText(), true, false);
|
407 |
}
|
410 |
}
|
408 |
|
411 |
|
409 |
void Preview::prevPressed()
|
412 |
void Preview::prevPressed()
|
410 |
{
|
413 |
{
|
411 |
LOGDEB2("Preview::prevPressed\n" );
|
414 |
LOGDEB2("Preview::prevPressed\n");
|
412 |
doSearch(searchTextCMB->currentText(), true, true);
|
415 |
doSearch(searchTextCMB->currentText(), true, true);
|
413 |
}
|
416 |
}
|
414 |
|
417 |
|
415 |
// Called when user clicks on tab
|
418 |
// Called when user clicks on tab
|
416 |
void Preview::currentChanged(int index)
|
419 |
void Preview::currentChanged(int index)
|
417 |
{
|
420 |
{
|
418 |
LOGDEB2("PreviewTextEdit::currentChanged\n" );
|
421 |
LOGDEB2("PreviewTextEdit::currentChanged\n");
|
419 |
QWidget *tw = pvTab->widget(index);
|
422 |
QWidget *tw = pvTab->widget(index);
|
420 |
PreviewTextEdit *edit =
|
423 |
PreviewTextEdit *edit =
|
421 |
tw->findChild<PreviewTextEdit*>("pvEdit");
|
424 |
tw->findChild<PreviewTextEdit*>("pvEdit");
|
422 |
LOGDEB1("Preview::currentChanged(). Editor: " << (edit) << "\n" );
|
425 |
LOGDEB1("Preview::currentChanged(). Editor: " << edit << "\n");
|
423 |
|
426 |
|
424 |
if (edit == 0) {
|
427 |
if (edit == 0) {
|
425 |
LOGERR("Editor child not found\n" );
|
428 |
LOGERR("Editor child not found\n");
|
426 |
return;
|
429 |
return;
|
427 |
}
|
430 |
}
|
428 |
edit->setFocus();
|
431 |
edit->setFocus();
|
429 |
// Disconnect the print signal and reconnect it to the current editor
|
432 |
// Disconnect the print signal and reconnect it to the current editor
|
430 |
LOGDEB("Disconnecting reconnecting print signal\n" );
|
433 |
LOGDEB("Disconnecting reconnecting print signal\n");
|
431 |
disconnect(this, SIGNAL(printCurrentPreviewRequest()), 0, 0);
|
434 |
disconnect(this, SIGNAL(printCurrentPreviewRequest()), 0, 0);
|
432 |
connect(this, SIGNAL(printCurrentPreviewRequest()), edit, SLOT(print()));
|
435 |
connect(this, SIGNAL(printCurrentPreviewRequest()), edit, SLOT(print()));
|
433 |
edit->installEventFilter(this);
|
436 |
edit->installEventFilter(this);
|
434 |
edit->viewport()->installEventFilter(this);
|
437 |
edit->viewport()->installEventFilter(this);
|
435 |
searchTextCMB->installEventFilter(this);
|
438 |
searchTextCMB->installEventFilter(this);
|
436 |
emit(previewExposed(this, m_searchId, edit->m_docnum));
|
439 |
emit(previewExposed(this, m_searchId, edit->m_docnum));
|
437 |
}
|
440 |
}
|
438 |
|
441 |
|
439 |
void Preview::closeCurrentTab()
|
442 |
void Preview::closeCurrentTab()
|
440 |
{
|
443 |
{
|
441 |
LOGDEB1("Preview::closeCurrentTab: m_loading " << (m_loading) << "\n" );
|
444 |
LOGDEB1("Preview::closeCurrentTab: m_loading " << m_loading << "\n");
|
442 |
if (m_loading) {
|
445 |
if (m_loading) {
|
443 |
CancelCheck::instance().setCancel();
|
446 |
CancelCheck::instance().setCancel();
|
444 |
return;
|
447 |
return;
|
445 |
}
|
448 |
}
|
446 |
PreviewTextEdit *e = currentEditor();
|
449 |
PreviewTextEdit *e = currentEditor();
|
|
... |
|
... |
453 |
}
|
456 |
}
|
454 |
}
|
457 |
}
|
455 |
|
458 |
|
456 |
PreviewTextEdit *Preview::addEditorTab()
|
459 |
PreviewTextEdit *Preview::addEditorTab()
|
457 |
{
|
460 |
{
|
458 |
LOGDEB1("PreviewTextEdit::addEditorTab()\n" );
|
461 |
LOGDEB1("PreviewTextEdit::addEditorTab()\n");
|
459 |
QWidget *anon = new QWidget((QWidget *)pvTab);
|
462 |
QWidget *anon = new QWidget((QWidget *)pvTab);
|
460 |
QVBoxLayout *anonLayout = new QVBoxLayout(anon);
|
463 |
QVBoxLayout *anonLayout = new QVBoxLayout(anon);
|
461 |
PreviewTextEdit *editor = new PreviewTextEdit(anon, "pvEdit", this);
|
464 |
PreviewTextEdit *editor = new PreviewTextEdit(anon, "pvEdit", this);
|
462 |
editor->setReadOnly(true);
|
465 |
editor->setReadOnly(true);
|
463 |
editor->setUndoRedoEnabled(false );
|
466 |
editor->setUndoRedoEnabled(false );
|
|
... |
|
... |
467 |
return editor;
|
470 |
return editor;
|
468 |
}
|
471 |
}
|
469 |
|
472 |
|
470 |
void Preview::setCurTabProps(const Rcl::Doc &doc, int docnum)
|
473 |
void Preview::setCurTabProps(const Rcl::Doc &doc, int docnum)
|
471 |
{
|
474 |
{
|
472 |
LOGDEB1("Preview::setCurTabProps\n" );
|
475 |
LOGDEB1("Preview::setCurTabProps\n");
|
473 |
QString title;
|
476 |
QString title;
|
474 |
string ctitle;
|
477 |
string ctitle;
|
475 |
if (doc.getmeta(Rcl::Doc::keytt, &ctitle) && !ctitle.empty()) {
|
478 |
if (doc.getmeta(Rcl::Doc::keytt, &ctitle) && !ctitle.empty()) {
|
476 |
title = QString::fromUtf8(ctitle.c_str(), ctitle.length());
|
479 |
title = QString::fromUtf8(ctitle.c_str(), ctitle.length());
|
477 |
} else {
|
480 |
} else {
|
|
... |
|
... |
489 |
time_t mtime = doc.dmtime.empty() ?
|
492 |
time_t mtime = doc.dmtime.empty() ?
|
490 |
atoll(doc.fmtime.c_str()) : atoll(doc.dmtime.c_str());
|
493 |
atoll(doc.fmtime.c_str()) : atoll(doc.dmtime.c_str());
|
491 |
struct tm *tm = localtime(&mtime);
|
494 |
struct tm *tm = localtime(&mtime);
|
492 |
strftime(datebuf, 99, "%Y-%m-%d %H:%M:%S", tm);
|
495 |
strftime(datebuf, 99, "%Y-%m-%d %H:%M:%S", tm);
|
493 |
}
|
496 |
}
|
494 |
LOGDEB("Doc.url: [" << (doc.url) << "]\n" );
|
497 |
LOGDEB("Doc.url: [" << doc.url << "]\n");
|
495 |
string url;
|
498 |
string url;
|
496 |
printableUrl(theconfig->getDefCharset(), doc.url, url);
|
499 |
printableUrl(theconfig->getDefCharset(), doc.url, url);
|
497 |
string tiptxt = url + string("\n");
|
500 |
string tiptxt = url + string("\n");
|
498 |
tiptxt += doc.mimetype + " " + string(datebuf) + "\n";
|
501 |
tiptxt += doc.mimetype + " " + string(datebuf) + "\n";
|
499 |
if (!ctitle.empty())
|
502 |
if (!ctitle.empty())
|
|
... |
|
... |
509 |
}
|
512 |
}
|
510 |
}
|
513 |
}
|
511 |
|
514 |
|
512 |
bool Preview::makeDocCurrent(const Rcl::Doc& doc, int docnum, bool sametab)
|
515 |
bool Preview::makeDocCurrent(const Rcl::Doc& doc, int docnum, bool sametab)
|
513 |
{
|
516 |
{
|
514 |
LOGDEB("Preview::makeDocCurrent: " << (doc.url) << "\n" );
|
517 |
LOGDEB("Preview::makeDocCurrent: " << doc.url << "\n");
|
515 |
|
518 |
|
516 |
if (m_loading) {
|
519 |
if (m_loading) {
|
517 |
LOGERR("Already loading\n" );
|
520 |
LOGERR("Already loading\n");
|
518 |
return false;
|
521 |
return false;
|
519 |
}
|
522 |
}
|
520 |
|
523 |
|
521 |
/* Check if we already have this page */
|
524 |
/* Check if we already have this page */
|
522 |
for (int i = 0; i < pvTab->count(); i++) {
|
525 |
for (int i = 0; i < pvTab->count(); i++) {
|
|
... |
|
... |
601 |
~LoadGuard() {*m_bp = false; CancelCheck::instance().setCancel(false);}
|
604 |
~LoadGuard() {*m_bp = false; CancelCheck::instance().setCancel(false);}
|
602 |
};
|
605 |
};
|
603 |
|
606 |
|
604 |
bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum)
|
607 |
bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum)
|
605 |
{
|
608 |
{
|
606 |
LOGDEB1("Preview::loadDocInCurrentTab()\n" );
|
609 |
LOGDEB1("Preview::loadDocInCurrentTab()\n");
|
607 |
|
610 |
|
608 |
LoadGuard guard(&m_loading);
|
611 |
LoadGuard guard(&m_loading);
|
609 |
CancelCheck::instance().setCancel(false);
|
612 |
CancelCheck::instance().setCancel(false);
|
610 |
|
613 |
|
611 |
setCurTabProps(idoc, docnum);
|
614 |
setCurTabProps(idoc, docnum);
|
|
... |
|
... |
639 |
}
|
642 |
}
|
640 |
if (i == 1)
|
643 |
if (i == 1)
|
641 |
progress.show();
|
644 |
progress.show();
|
642 |
}
|
645 |
}
|
643 |
|
646 |
|
644 |
LOGDEB("loadDocInCurrentTab: after file load: cancel " << (CancelCheck::instance().cancelState()) << " status " << (lthr.status) << " text length " << (lthr.fdoc.text.length()) << "\n" );
|
647 |
LOGDEB("loadDocInCurrentTab: after file load: cancel " <<
|
|
|
648 |
CancelCheck::instance().cancelState() << " status " << lthr.status <<
|
|
|
649 |
" text length " << lthr.fdoc.text.length() << "\n");
|
645 |
|
650 |
|
646 |
if (CancelCheck::instance().cancelState())
|
651 |
if (CancelCheck::instance().cancelState())
|
647 |
return false;
|
652 |
return false;
|
648 |
if (lthr.status != 0) {
|
653 |
if (lthr.status != 0) {
|
649 |
progress.close();
|
654 |
progress.close();
|
|
... |
|
... |
701 |
|
706 |
|
702 |
editor->setHtml("");
|
707 |
editor->setHtml("");
|
703 |
editor->m_format = Qt::RichText;
|
708 |
editor->m_format = Qt::RichText;
|
704 |
bool inputishtml = !lthr.fdoc.mimetype.compare("text/html");
|
709 |
bool inputishtml = !lthr.fdoc.mimetype.compare("text/html");
|
705 |
QStringList qrichlst;
|
710 |
QStringList qrichlst;
|
|
|
711 |
editor->m_plaintorich->set_activatelinks(prefs.previewActiveLinks);
|
706 |
|
712 |
|
707 |
#if 1
|
713 |
#if 1
|
708 |
if (highlightTerms) {
|
714 |
if (highlightTerms) {
|
709 |
progress.setLabelText(tr("Creating preview text"));
|
715 |
progress.setLabelText(tr("Creating preview text"));
|
710 |
qApp->processEvents();
|
716 |
qApp->processEvents();
|
711 |
|
717 |
|
712 |
if (inputishtml) {
|
718 |
if (inputishtml) {
|
713 |
LOGDEB1("Preview: got html " << (lthr.fdoc.text) << "\n" );
|
719 |
LOGDEB1("Preview: got html " << lthr.fdoc.text << "\n");
|
714 |
editor->m_plaintorich->set_inputhtml(true);
|
720 |
editor->m_plaintorich->set_inputhtml(true);
|
715 |
} else {
|
721 |
} else {
|
716 |
LOGDEB1("Preview: got plain " << (lthr.fdoc.text) << "\n" );
|
722 |
LOGDEB1("Preview: got plain " << lthr.fdoc.text << "\n");
|
717 |
editor->m_plaintorich->set_inputhtml(false);
|
723 |
editor->m_plaintorich->set_inputhtml(false);
|
718 |
}
|
724 |
}
|
719 |
|
725 |
|
720 |
ToRichThread rthr(lthr.fdoc.text, m_hData, editor->m_plaintorich,
|
726 |
ToRichThread rthr(lthr.fdoc.text, m_hData, editor->m_plaintorich,
|
721 |
qrichlst, this);
|
727 |
qrichlst, this);
|
|
... |
|
... |
742 |
} else {
|
748 |
} else {
|
743 |
qrichlst.back() += "<b>Cancelled !</b>";
|
749 |
qrichlst.back() += "<b>Cancelled !</b>";
|
744 |
}
|
750 |
}
|
745 |
}
|
751 |
}
|
746 |
} else {
|
752 |
} else {
|
747 |
LOGDEB("Preview: no hilighting, loading " << (int(lthr.fdoc.text.size())) << " bytes\n" );
|
753 |
LOGDEB("Preview: no hilighting, loading " << lthr.fdoc.text.size() <<
|
|
|
754 |
" bytes\n");
|
748 |
// No plaintorich() call. In this case, either the text is
|
755 |
// No plaintorich() call. In this case, either the text is
|
749 |
// html and the html quoting is hopefully correct, or it's
|
756 |
// html and the html quoting is hopefully correct, or it's
|
750 |
// plain-text and there is no need to escape special
|
757 |
// plain-text and there is no need to escape special
|
751 |
// characters. We'd still want to split in chunks (so that the
|
758 |
// characters. We'd still want to split in chunks (so that the
|
752 |
// top is displayed faster), but we must not cut tags, and
|
759 |
// top is displayed faster), but we must not cut tags, and
|
|
... |
|
... |
792 |
// not do it consistently for us.
|
799 |
// not do it consistently for us.
|
793 |
editor->m_richtxt.append(*it);
|
800 |
editor->m_richtxt.append(*it);
|
794 |
|
801 |
|
795 |
if (progress.wasCanceled()) {
|
802 |
if (progress.wasCanceled()) {
|
796 |
editor->append("<b>Cancelled !</b>");
|
803 |
editor->append("<b>Cancelled !</b>");
|
797 |
LOGDEB("loadDocInCurrentTab: cancelled in editor load\n" );
|
804 |
LOGDEB("loadDocInCurrentTab: cancelled in editor load\n");
|
798 |
break;
|
805 |
break;
|
799 |
}
|
806 |
}
|
800 |
}
|
807 |
}
|
801 |
|
808 |
|
802 |
progress.close();
|
809 |
progress.close();
|
|
... |
|
... |
856 |
doSearch(searchTextCMB->currentText(), true, false);
|
863 |
doSearch(searchTextCMB->currentText(), true, false);
|
857 |
} else {
|
864 |
} else {
|
858 |
// Position to the first query term
|
865 |
// Position to the first query term
|
859 |
if (editor->m_plaintorich->haveAnchors()) {
|
866 |
if (editor->m_plaintorich->haveAnchors()) {
|
860 |
QString aname = editor->m_plaintorich->curAnchorName();
|
867 |
QString aname = editor->m_plaintorich->curAnchorName();
|
861 |
LOGDEB2("Call movetoanchor(" << ((const char *)aname.toUtf8()) << ")\n" );
|
868 |
LOGDEB2("Call movetoanchor(" << qs2utf8s(aname) << ")\n");
|
862 |
editor->scrollToAnchor(aname);
|
869 |
editor->scrollToAnchor(aname);
|
863 |
// Position the cursor approximately at the anchor (top of
|
870 |
// Position the cursor approximately at the anchor (top of
|
864 |
// viewport) so that searches start from here
|
871 |
// viewport) so that searches start from here
|
865 |
QTextCursor cursor = editor->cursorForPosition(QPoint(0, 0));
|
872 |
QTextCursor cursor = editor->cursorForPosition(QPoint(0, 0));
|
866 |
editor->setTextCursor(cursor);
|
873 |
editor->setTextCursor(cursor);
|
|
... |
|
... |
874 |
historyEnterDoc(g_dynconf, udi);
|
881 |
historyEnterDoc(g_dynconf, udi);
|
875 |
}
|
882 |
}
|
876 |
|
883 |
|
877 |
editor->setFocus();
|
884 |
editor->setFocus();
|
878 |
emit(previewExposed(this, m_searchId, docnum));
|
885 |
emit(previewExposed(this, m_searchId, docnum));
|
879 |
LOGDEB("loadDocInCurrentTab: returning true\n" );
|
886 |
LOGDEB("loadDocInCurrentTab: returning true\n");
|
880 |
return true;
|
887 |
return true;
|
881 |
}
|
888 |
}
|
882 |
|
889 |
|
883 |
PreviewTextEdit::PreviewTextEdit(QWidget* parent, const char* nm, Preview *pv)
|
890 |
PreviewTextEdit::PreviewTextEdit(QWidget* parent, const char* nm, Preview *pv)
|
884 |
: QTextBrowser(parent), m_preview(pv),
|
891 |
: QTextBrowser(parent), m_preview(pv),
|
|
... |
|
... |
887 |
{
|
894 |
{
|
888 |
setContextMenuPolicy(Qt::CustomContextMenu);
|
895 |
setContextMenuPolicy(Qt::CustomContextMenu);
|
889 |
setObjectName(nm);
|
896 |
setObjectName(nm);
|
890 |
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
|
897 |
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
|
891 |
this, SLOT(createPopupMenu(const QPoint&)));
|
898 |
this, SLOT(createPopupMenu(const QPoint&)));
|
|
|
899 |
connect(this, SIGNAL(anchorClicked(const QUrl &)),
|
|
|
900 |
this, SLOT(onAnchorClicked(const QUrl&)));
|
892 |
setOpenExternalLinks(false);
|
901 |
setOpenExternalLinks(false);
|
893 |
setOpenLinks(false);
|
902 |
setOpenLinks(false);
|
894 |
}
|
903 |
}
|
895 |
|
904 |
|
|
|
905 |
void PreviewTextEdit::onAnchorClicked(const QUrl& url)
|
|
|
906 |
{
|
|
|
907 |
LOGDEB("PreviewTextEdit::onAnchorClicked: " << qs2utf8s(url.toString())
|
|
|
908 |
<< std::endl);
|
|
|
909 |
if (prefs.previewActiveLinks && m_preview->m_rclmain) {
|
|
|
910 |
Rcl::Doc doc;
|
|
|
911 |
doc.url = qs2utf8s(url.toString()).c_str();
|
|
|
912 |
doc.mimetype = "text/html";
|
|
|
913 |
m_preview->m_rclmain->startNativeViewer(doc);
|
|
|
914 |
}
|
|
|
915 |
}
|
|
|
916 |
|
896 |
void PreviewTextEdit::createPopupMenu(const QPoint& pos)
|
917 |
void PreviewTextEdit::createPopupMenu(const QPoint& pos)
|
897 |
{
|
918 |
{
|
898 |
LOGDEB1("PreviewTextEdit::createPopupMenu()\n" );
|
919 |
LOGDEB1("PreviewTextEdit::createPopupMenu()\n");
|
899 |
QMenu *popup = new QMenu(this);
|
920 |
QMenu *popup = new QMenu(this);
|
900 |
switch (m_curdsp) {
|
921 |
switch (m_curdsp) {
|
901 |
case PTE_DSPTXT:
|
922 |
case PTE_DSPTXT:
|
902 |
popup->addAction(tr("Show fields"), this, SLOT(displayFields()));
|
923 |
popup->addAction(tr("Show fields"), this, SLOT(displayFields()));
|
903 |
if (!m_image.isNull())
|
924 |
if (!m_image.isNull())
|
|
... |
|
... |
932 |
}
|
953 |
}
|
933 |
|
954 |
|
934 |
// Display main text
|
955 |
// Display main text
|
935 |
void PreviewTextEdit::displayText()
|
956 |
void PreviewTextEdit::displayText()
|
936 |
{
|
957 |
{
|
937 |
LOGDEB1("PreviewTextEdit::displayText()\n" );
|
958 |
LOGDEB1("PreviewTextEdit::displayText()\n");
|
938 |
if (m_format == Qt::PlainText)
|
959 |
if (m_format == Qt::PlainText)
|
939 |
setPlainText(m_richtxt);
|
960 |
setPlainText(m_richtxt);
|
940 |
else
|
961 |
else
|
941 |
setHtml(m_richtxt);
|
962 |
setHtml(m_richtxt);
|
942 |
m_curdsp = PTE_DSPTXT;
|
963 |
m_curdsp = PTE_DSPTXT;
|
943 |
}
|
964 |
}
|
944 |
|
965 |
|
945 |
// Display field values
|
966 |
// Display field values
|
946 |
void PreviewTextEdit::displayFields()
|
967 |
void PreviewTextEdit::displayFields()
|
947 |
{
|
968 |
{
|
948 |
LOGDEB1("PreviewTextEdit::displayFields()\n" );
|
969 |
LOGDEB1("PreviewTextEdit::displayFields()\n");
|
949 |
|
970 |
|
950 |
QString txt = "<html><head></head><body>\n";
|
971 |
QString txt = "<html><head></head><body>\n";
|
951 |
txt += "<b>" + QString::fromLocal8Bit(m_url.c_str());
|
972 |
txt += "<b>" + QString::fromLocal8Bit(m_url.c_str());
|
952 |
if (!m_ipath.empty())
|
973 |
if (!m_ipath.empty())
|
953 |
txt += "|" + QString::fromUtf8(m_ipath.c_str());
|
974 |
txt += "|" + QString::fromUtf8(m_ipath.c_str());
|
|
... |
|
... |
965 |
m_curdsp = PTE_DSPFLDS;
|
986 |
m_curdsp = PTE_DSPFLDS;
|
966 |
}
|
987 |
}
|
967 |
|
988 |
|
968 |
void PreviewTextEdit::displayImage()
|
989 |
void PreviewTextEdit::displayImage()
|
969 |
{
|
990 |
{
|
970 |
LOGDEB1("PreviewTextEdit::displayImage()\n" );
|
991 |
LOGDEB1("PreviewTextEdit::displayImage()\n");
|
971 |
if (m_image.isNull())
|
992 |
if (m_image.isNull())
|
972 |
displayText();
|
993 |
displayText();
|
973 |
|
994 |
|
974 |
setPlainText("");
|
995 |
setPlainText("");
|
975 |
if (m_image.width() > width() ||
|
996 |
if (m_image.width() > width() ||
|
|
... |
|
... |
983 |
m_curdsp = PTE_DSPIMG;
|
1004 |
m_curdsp = PTE_DSPIMG;
|
984 |
}
|
1005 |
}
|
985 |
|
1006 |
|
986 |
void PreviewTextEdit::mouseDoubleClickEvent(QMouseEvent *event)
|
1007 |
void PreviewTextEdit::mouseDoubleClickEvent(QMouseEvent *event)
|
987 |
{
|
1008 |
{
|
988 |
LOGDEB2("PreviewTextEdit::mouseDoubleClickEvent\n" );
|
1009 |
LOGDEB2("PreviewTextEdit::mouseDoubleClickEvent\n");
|
989 |
QTextEdit::mouseDoubleClickEvent(event);
|
1010 |
QTextEdit::mouseDoubleClickEvent(event);
|
990 |
if (textCursor().hasSelection() && m_preview)
|
1011 |
if (textCursor().hasSelection() && m_preview)
|
991 |
m_preview->emitWordSelect(textCursor().selectedText());
|
1012 |
m_preview->emitWordSelect(textCursor().selectedText());
|
992 |
}
|
1013 |
}
|
993 |
|
1014 |
|
994 |
void PreviewTextEdit::print()
|
1015 |
void PreviewTextEdit::print()
|
995 |
{
|
1016 |
{
|
996 |
LOGDEB("PreviewTextEdit::print\n" );
|
1017 |
LOGDEB("PreviewTextEdit::print\n");
|
997 |
if (!m_preview)
|
1018 |
if (!m_preview)
|
998 |
return;
|
1019 |
return;
|
999 |
|
1020 |
|
1000 |
#ifndef QT_NO_PRINTER
|
1021 |
#ifndef QT_NO_PRINTER
|
1001 |
QPrinter printer;
|
1022 |
QPrinter printer;
|