Switch to unified view

a/src/qtgui/preview_w.cpp b/src/qtgui/preview_w.cpp
...
...
33
#include <qvariant.h>
33
#include <qvariant.h>
34
#include <qpushbutton.h>
34
#include <qpushbutton.h>
35
#include <qtabwidget.h>
35
#include <qtabwidget.h>
36
#if (QT_VERSION < 0x040000)
36
#if (QT_VERSION < 0x040000)
37
#include <qtextedit.h>
37
#include <qtextedit.h>
38
#include <qpopupmenu.h>
38
#include <qprogressdialog.h>
39
#include <qprogressdialog.h>
39
#define THRFINISHED finished
40
#define THRFINISHED finished
40
#else
41
#else
42
#include <q3popupmenu.h>
41
#include <q3textedit.h>
43
#include <q3textedit.h>
42
#include <q3progressdialog.h>
44
#include <q3progressdialog.h>
43
#include <q3stylesheet.h>
45
#include <q3stylesheet.h>
44
#define THRFINISHED isFinished
46
#define THRFINISHED isFinished
45
#endif
47
#endif
...
...
91
// qtextedit::find() does, instead. This ones actually moves the
93
// qtextedit::find() does, instead. This ones actually moves the
92
// cursor, which is probably not necessary, but does what we need.
94
// cursor, which is probably not necessary, but does what we need.
93
//
95
//
94
// Problem is, it uses the sem-private qrichtext_p.h, which is not
96
// Problem is, it uses the sem-private qrichtext_p.h, which is not
95
// even installed under qt4. We use a local copy, which is not nice.
97
// even installed under qt4. We use a local copy, which is not nice.
96
void QTextEditFixed::moveToAnchor(const QString& name)
98
void PreviewTextEdit::moveToAnchor(const QString& name)
97
{
99
{
98
    if (name.isEmpty())
100
    if (name.isEmpty())
99
    return;
101
    return;
100
    sync();
102
    sync();
101
    QTEXTCURSOR l_cursor(document());
103
    QTEXTCURSOR l_cursor(document());
...
...
133
    // Create the first tab. Should be possible to use addEditorTab
135
    // Create the first tab. Should be possible to use addEditorTab
134
    // but this causes a pb with the sizeing
136
    // but this causes a pb with the sizeing
135
    QWidget *unnamed = new QWidget(pvTab, "unnamed");
137
    QWidget *unnamed = new QWidget(pvTab, "unnamed");
136
    QVBoxLayout *unnamedLayout = 
138
    QVBoxLayout *unnamedLayout = 
137
    new QVBoxLayout(unnamed, 0, 6, "unnamedLayout"); 
139
    new QVBoxLayout(unnamed, 0, 6, "unnamedLayout"); 
138
    QTextEditFixed *pvEdit = new QTextEditFixed(unnamed, "pvEdit");
140
    PreviewTextEdit *pvEdit = new PreviewTextEdit(unnamed, "pvEdit", this);
139
    pvEdit->setReadOnly(TRUE);
141
    pvEdit->setReadOnly(TRUE);
140
    pvEdit->setUndoRedoEnabled(FALSE);
142
    pvEdit->setUndoRedoEnabled(FALSE);
141
    unnamedLayout->addWidget(pvEdit);
143
    unnamedLayout->addWidget(pvEdit);
142
    pvTab->insertTab(unnamed, QString::fromLatin1(""));
144
    pvTab->insertTab(unnamed, QString::fromLatin1(""));
143
    m_tabData.push_back(TabData(pvTab->currentPage()));
145
    m_tabData.push_back(TabData(pvTab->currentPage()));
...
...
265
    }
267
    }
266
    if (target != searchTextLine)
268
    if (target != searchTextLine)
267
        return QApplication::sendEvent(searchTextLine, event);
269
        return QApplication::sendEvent(searchTextLine, event);
268
    } else {
270
    } else {
269
    QWidget *tw = pvTab->currentPage();
271
    QWidget *tw = pvTab->currentPage();
270
  QTextEditFixed *e = 0;
272
  PreviewTextEdit *e = 0;
271
    if (tw)
273
    if (tw)
272
        e = (QTextEditFixed *)tw->child("pvEdit");
274
        e = (PreviewTextEdit *)tw->child("pvEdit");
273
    LOGDEB1(("Widget: %p, edit %p, target %p\n", tw, e, target));
275
    LOGDEB1(("Widget: %p, edit %p, target %p\n", tw, e, target));
274
    if (e && target == e) {
276
    if (e && target == e) {
275
        if (keyEvent->key() == Qt::Key_Slash) {
277
        if (keyEvent->key() == Qt::Key_Slash) {
276
        searchTextLine->setFocus();
278
        searchTextLine->setFocus();
277
        m_dynSearchActive = true;
279
        m_dynSearchActive = true;
...
...
309
#if (QT_VERSION >= 0x040000)
311
#if (QT_VERSION >= 0x040000)
310
#define QProgressDialog Q3ProgressDialog
312
#define QProgressDialog Q3ProgressDialog
311
#define QStyleSheetItem Q3StyleSheetItem
313
#define QStyleSheetItem Q3StyleSheetItem
312
#endif
314
#endif
313
315
314
QTextEditFixed *Preview::getCurrentEditor()
316
PreviewTextEdit *Preview::getCurrentEditor()
315
{
317
{
316
    QWidget *tw = pvTab->currentPage();
318
    QWidget *tw = pvTab->currentPage();
317
    QTextEditFixed *edit = 0;
319
    PreviewTextEdit *edit = 0;
318
    if (tw) {
320
    if (tw) {
319
    edit = (QTextEditFixed*)tw->child("pvEdit");
321
    edit = (PreviewTextEdit*)tw->child("pvEdit");
320
    }
322
    }
321
    return edit;
323
    return edit;
322
}
324
}
323
325
324
// Perform text search. If next is true, we look for the next match of the
326
// Perform text search. If next is true, we look for the next match of the
...
...
332
        (const char *)_text.utf8(), _text.length(), int(next), 
334
        (const char *)_text.utf8(), _text.length(), int(next), 
333
        int(reverse), int(wordOnly)));
335
        int(reverse), int(wordOnly)));
334
    QString text = _text;
336
    QString text = _text;
335
337
336
    bool matchCase = matchCheck->isChecked();
338
    bool matchCase = matchCheck->isChecked();
337
    QTextEditFixed *edit = getCurrentEditor();
339
    PreviewTextEdit *edit = getCurrentEditor();
338
    if (edit == 0) {
340
    if (edit == 0) {
339
    // ??
341
    // ??
340
    return;
342
    return;
341
    }
343
    }
342
344
...
...
451
void Preview::selecChanged()
453
void Preview::selecChanged()
452
{
454
{
453
    LOGDEB1(("Selection changed\n"));
455
    LOGDEB1(("Selection changed\n"));
454
    if (!m_currentW)
456
    if (!m_currentW)
455
    return;
457
    return;
456
    QTextEditFixed *edit = (QTextEditFixed*)m_currentW->child("pvEdit");
458
    PreviewTextEdit *edit = (PreviewTextEdit*)m_currentW->child("pvEdit");
457
    if (edit == 0) {
459
    if (edit == 0) {
458
    LOGERR(("Editor child not found\n"));
460
    LOGERR(("Editor child not found\n"));
459
    return;
461
    return;
460
    }
462
    }
461
    QClipboard *clipboard = QApplication::clipboard();
463
    QClipboard *clipboard = QApplication::clipboard();
...
...
477
void Preview::textDoubleClicked(int, int)
479
void Preview::textDoubleClicked(int, int)
478
{
480
{
479
    LOGDEB2(("Preview::textDoubleClicked\n"));
481
    LOGDEB2(("Preview::textDoubleClicked\n"));
480
    if (!m_currentW)
482
    if (!m_currentW)
481
    return;
483
    return;
482
    QTextEditFixed *edit = (QTextEditFixed *)m_currentW->child("pvEdit");
484
    PreviewTextEdit *edit = (PreviewTextEdit *)m_currentW->child("pvEdit");
483
    if (edit == 0) {
485
    if (edit == 0) {
484
    LOGERR(("Editor child not found\n"));
486
    LOGERR(("Editor child not found\n"));
485
    return;
487
    return;
486
    }
488
    }
487
    if (edit->hasSelectedText())
489
    if (edit->hasSelectedText())
...
...
511
    } else {
513
    } else {
512
    close();
514
    close();
513
    }
515
    }
514
}
516
}
515
517
516
QTextEditFixed *Preview::addEditorTab()
518
PreviewTextEdit *Preview::addEditorTab()
517
{
519
{
518
    QWidget *anon = new QWidget((QWidget *)pvTab);
520
    QWidget *anon = new QWidget((QWidget *)pvTab);
519
    QVBoxLayout *anonLayout = new QVBoxLayout(anon, 1, 1, "anonLayout"); 
521
    QVBoxLayout *anonLayout = new QVBoxLayout(anon, 1, 1, "anonLayout"); 
520
    QTextEditFixed *editor = new QTextEditFixed(anon, "pvEdit");
522
    PreviewTextEdit *editor = new PreviewTextEdit(anon, "pvEdit", this);
521
    editor->setReadOnly(TRUE);
523
    editor->setReadOnly(TRUE);
522
    editor->setUndoRedoEnabled(FALSE );
524
    editor->setUndoRedoEnabled(FALSE );
523
    anonLayout->addWidget(editor);
525
    anonLayout->addWidget(editor);
524
    pvTab->addTab(anon, "Tab");
526
    pvTab->addTab(anon, "Tab");
525
    pvTab->showPage(anon);
527
    pvTab->showPage(anon);
...
...
557
    tiptxt += doc.mimetype + " " + string(datebuf) + "\n";
559
    tiptxt += doc.mimetype + " " + string(datebuf) + "\n";
558
    if (meta_it != doc.meta.end() && !meta_it->second.empty())
560
    if (meta_it != doc.meta.end() && !meta_it->second.empty())
559
    tiptxt += meta_it->second + "\n";
561
    tiptxt += meta_it->second + "\n";
560
    pvTab->setTabToolTip(w,QString::fromUtf8(tiptxt.c_str(), tiptxt.length()));
562
    pvTab->setTabToolTip(w,QString::fromUtf8(tiptxt.c_str(), tiptxt.length()));
561
563
562
    for (list<TabData>::iterator it = m_tabData.begin(); 
564
    TabData *d = tabDataForCurrent();
563
   it != m_tabData.end(); it++) {
565
    if (d) {
564
  if (it->w == w) {
565
        it->fn = fn;
566
    d->fn = fn;
566
        it->ipath = doc.ipath;
567
    d->ipath = doc.ipath;
567
        it->docnum = docnum;
568
    d->docnum = docnum;
568
      break;
569
  }
570
    }
569
    }
571
}
570
}
572
571
573
TabData *Preview::tabDataForCurrent()
572
TabData *Preview::tabDataForCurrent()
574
{
573
{
...
...
895
        }
894
        }
896
    }
895
    }
897
    }
896
    }
898
        
897
        
899
    // Load into editor
898
    // Load into editor
900
    QTextEditFixed *editor = getCurrentEditor();
899
    PreviewTextEdit *editor = getCurrentEditor();
901
    editor->setText("");
900
    editor->setText("");
902
    if (highlightTerms) {
901
    if (highlightTerms) {
903
    QStyleSheetItem *item = 
902
    QStyleSheetItem *item = 
904
        new QStyleSheetItem(editor->styleSheet(), "termtag" );
903
        new QStyleSheetItem(editor->styleSheet(), "termtag" );
905
    item->setColor(prefs.qtermcolor);
904
    item->setColor(prefs.qtermcolor);
...
...
929
        break;
928
        break;
930
    }
929
    }
931
    }
930
    }
932
931
933
    progress.close();
932
    progress.close();
934
933
    TabData *d = tabDataForCurrent();
934
    if (d) {
935
  fdoc.text.clear();
936
  d->fdoc = fdoc;
937
    }
935
    m_haveAnchors = m_plaintorich.lastanchor != 0;
938
    m_haveAnchors = m_plaintorich.lastanchor != 0;
936
    if (searchTextLine->text().length() != 0) {
939
    if (searchTextLine->text().length() != 0) {
937
    // If there is a current search string, perform the search
940
    // If there is a current search string, perform the search
938
    m_canBeep = true;
941
    m_canBeep = true;
939
    doSearch(searchTextLine->text(), true, false);
942
    doSearch(searchTextLine->text(), true, false);
...
...
954
    editor->setFocus();
957
    editor->setFocus();
955
    emit(previewExposed(this, m_searchId, docnum));
958
    emit(previewExposed(this, m_searchId, docnum));
956
    LOGDEB(("LoadFileInCurrentTab: returning true\n"));
959
    LOGDEB(("LoadFileInCurrentTab: returning true\n"));
957
    return true;
960
    return true;
958
}
961
}
962
963
964
RCLPOPUP *PreviewTextEdit::createPopupMenu(const QPoint&)
965
{
966
    RCLPOPUP *popup = new RCLPOPUP(this);
967
    if (m_savedText.isEmpty()) {
968
  popup->insertItem(tr("Show fields"), this, SLOT(menuToggleFields()));
969
    } else {
970
  popup->insertItem(tr("Show main text"), this, SLOT(menuToggleFields()));
971
    }
972
    return popup;
973
}
974
975
void PreviewTextEdit::menuToggleFields()
976
{
977
    if (!m_savedText.isEmpty()) {
978
  setText(m_savedText);
979
  m_savedText = "";
980
  return;
981
    }
982
    TabData *d = m_preview->tabDataForCurrent();
983
    if (!d) 
984
  return;
985
    QString txt = "<html><head></head><body>\n";
986
    txt += "<b>" + QString::fromLocal8Bit(d->fn.c_str());
987
    if (!d->ipath.empty())
988
  txt += "|" + QString::fromUtf8(d->ipath.c_str());
989
    txt += "</b><br><br>";
990
    txt += "<dl>\n";
991
    for (map<string,string>::const_iterator it = d->fdoc.meta.begin();
992
   it != d->fdoc.meta.end(); it++) {
993
  txt += "<dt>" + QString::fromUtf8(it->first.c_str()) + "</dt> " 
994
      + "<dd>" + QString::fromUtf8(it->second.c_str()) + "</dd>\n";
995
    }
996
    txt += "</dl></body></html>";
997
    m_savedText = text();
998
    setText(txt);
999
}