Switch to unified view

a/src/qtgui/preview_w.cpp b/src/qtgui/preview_w.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.1 2006-09-04 15:13:01 dockes Exp $ (C) 2005 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.2 2006-09-12 10:11:36 dockes Exp $ (C) 2005 J.F.Dockes";
3
#endif
3
#endif
4
/*
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
5
 *   This program is free software; you can redistribute it and/or modify
6
 *   it under the terms of the GNU General Public License as published by
6
 *   it under the terms of the GNU General Public License as published by
7
 *   the Free Software Foundation; either version 2 of the License, or
7
 *   the Free Software Foundation; either version 2 of the License, or
...
...
53
53
54
#if (QT_VERSION < 0x030300)
54
#if (QT_VERSION < 0x030300)
55
#define wasCanceled wasCancelled
55
#define wasCanceled wasCancelled
56
#endif
56
#endif
57
57
58
// We keep a list of data associated to each tab
59
class TabData {
60
 public:
61
    string fn; // filename for this tab
62
    string ipath; // Internal doc path inside file
63
    QWidget *w; // widget for setCurrent
64
    TabData(QWidget *wi) : w(wi) {}
65
};
66
67
#define TABDATA ((list<TabData> *)tabData)
68
69
void Preview::init()
58
void Preview::init()
70
{
59
{
71
    // signals and slots connections
60
    // signals and slots connections
72
    connect(searchTextLine, SIGNAL(textChanged(const QString&)), 
61
    connect(searchTextLine, SIGNAL(textChanged(const QString&)), 
73
        this, SLOT(searchTextLine_textChanged(const QString&)));
62
        this, SLOT(searchTextLine_textChanged(const QString&)));
...
...
78
        this, SLOT(currentChanged(QWidget *)));
67
        this, SLOT(currentChanged(QWidget *)));
79
68
80
    searchTextLine->installEventFilter(this);
69
    searchTextLine->installEventFilter(this);
81
    dynSearchActive = false;
70
    dynSearchActive = false;
82
    canBeep = true;
71
    canBeep = true;
83
    tabData = new list<TabData>;
84
    TABDATA->push_back(TabData(pvTab->currentPage()));
72
    tabData.push_back(TabData(pvTab->currentPage()));
85
    currentW = 0;
73
    currentW = 0;
86
}
74
}
87
75
88
void Preview::destroy()
76
void Preview::destroy()
89
{
77
{
90
    delete TABDATA;
91
}
78
}
92
79
93
void Preview::closeEvent(QCloseEvent *e)
80
void Preview::closeEvent(QCloseEvent *e)
94
{
81
{
95
    emit previewClosed((QWidget *)this);
82
    emit previewClosed((QWidget *)this);
...
...
106
    if (keyEvent->key() == Key_Q && (keyEvent->state() & ControlButton)) {
93
    if (keyEvent->key() == Key_Q && (keyEvent->state() & ControlButton)) {
107
    recollNeedsExit = 1;
94
    recollNeedsExit = 1;
108
    return true;
95
    return true;
109
    } else if (keyEvent->key() == Key_Escape) {
96
    } else if (keyEvent->key() == Key_Escape) {
110
    close();
97
    close();
98
  return true;
99
    } else if (keyEvent->key() == Qt::Key_Down &&
100
         (keyEvent->state() & ShiftButton)) {
101
  // LOGDEB(("Preview::eventFilter: got Shift-Up\n"));
102
  TabData *d = tabDataForCurrent();
103
  if (d) 
104
      emit(showNext(m_searchId, d->docnum));
105
  return true;
106
    } else if (keyEvent->key() == Qt::Key_Up &&
107
         (keyEvent->state() & ShiftButton)) {
108
  // LOGDEB(("Preview::eventFilter: got Shift-Down\n"));
109
  TabData *d = tabDataForCurrent();
110
  if (d) 
111
      emit(showPrev(m_searchId, d->docnum));
111
    return true;
112
    return true;
112
    } else if (keyEvent->key() == Key_W &&
113
    } else if (keyEvent->key() == Key_W &&
113
           (keyEvent->state() & ControlButton)) {
114
           (keyEvent->state() & ControlButton)) {
114
    // LOGDEB(("Preview::eventFilter: got ^W\n"));
115
    // LOGDEB(("Preview::eventFilter: got ^W\n"));
115
    closeCurrentTab();
116
    closeCurrentTab();
...
...
152
    clearPB->setEnabled(true);
153
    clearPB->setEnabled(true);
153
    doSearch(text, false, false);
154
    doSearch(text, false, false);
154
    }
155
    }
155
}
156
}
156
157
157
QTextEdit * Preview::getCurrentEditor()
158
QTextEdit *Preview::getCurrentEditor()
158
{
159
{
159
    QWidget *tw = pvTab->currentPage();
160
    QWidget *tw = pvTab->currentPage();
160
    QTextEdit *edit = 0;
161
    QTextEdit *edit = 0;
161
    if (tw) {
162
    if (tw) {
162
    edit = (QTextEdit*)tw->child("pvEdit");
163
    edit = (QTextEdit*)tw->child("pvEdit");
...
...
233
void Preview::prevPressed()
234
void Preview::prevPressed()
234
{
235
{
235
    doSearch(searchTextLine->text(), true, true);
236
    doSearch(searchTextLine->text(), true, true);
236
}
237
}
237
238
238
239
// Called when user clicks on tab
239
void Preview::currentChanged(QWidget * tw)
240
void Preview::currentChanged(QWidget * tw)
240
{
241
{
241
    QWidget *edit = (QWidget *)tw->child("pvEdit");
242
    QWidget *edit = (QWidget *)tw->child("pvEdit");
242
    currentW = tw;
243
    currentW = tw;
243
    LOGDEB1(("Preview::currentChanged(). Editor: %p\n", edit));
244
    LOGDEB1(("Preview::currentChanged(). Editor: %p\n", edit));
...
...
272
    QWidget *tw = pvTab->currentPage();
273
    QWidget *tw = pvTab->currentPage();
273
    if (!tw) 
274
    if (!tw) 
274
        return;
275
        return;
275
    pvTab->removePage(tw);
276
    pvTab->removePage(tw);
276
    // Have to remove from tab data list
277
    // Have to remove from tab data list
277
  if (tabData == 0)
278
      return;
279
    for (list<TabData>::iterator it = TABDATA->begin(); 
278
    for (list<TabData>::iterator it = tabData.begin(); 
280
         it != TABDATA->end(); it++) {
279
         it != tabData.end(); it++) {
281
        if (it->w == tw) {
280
        if (it->w == tw) {
282
      TABDATA->erase(it);
281
      tabData.erase(it);
283
        return;
282
        return;
284
        }
283
        }
285
    }
284
    }
286
    } else {
285
    } else {
287
    close();
286
    close();
...
...
297
    editor->setReadOnly(TRUE);
296
    editor->setReadOnly(TRUE);
298
    editor->setUndoRedoEnabled(FALSE );
297
    editor->setUndoRedoEnabled(FALSE );
299
    anonLayout->addWidget(editor);
298
    anonLayout->addWidget(editor);
300
    pvTab->addTab(anon, "Tab");
299
    pvTab->addTab(anon, "Tab");
301
    pvTab->showPage(anon);
300
    pvTab->showPage(anon);
302
    if (tabData)
301
    tabData.push_back(TabData(anon));
303
  TABDATA->push_back(TabData(anon));
304
    return editor;
302
    return editor;
305
}
303
}
306
304
307
void Preview::setCurTabProps(const string &fn, const Rcl::Doc &doc)
305
void Preview::setCurTabProps(const string &fn, const Rcl::Doc &doc,
306
               int docnum)
308
{
307
{
309
    QString title = QString::fromUtf8(doc.title.c_str(), 
308
    QString title = QString::fromUtf8(doc.title.c_str(), 
310
                      doc.title.length());
309
                      doc.title.length());
311
    if (title.length() > 20) {
310
    if (title.length() > 20) {
312
    title = title.left(10) + "..." + title.right(10);
311
    title = title.left(10) + "..." + title.right(10);
...
...
326
    tiptxt += doc.mimetype + " " + string(datebuf) + "\n";
325
    tiptxt += doc.mimetype + " " + string(datebuf) + "\n";
327
    if (!doc.title.empty())
326
    if (!doc.title.empty())
328
    tiptxt += doc.title + "\n";
327
    tiptxt += doc.title + "\n";
329
    pvTab->setTabToolTip(w,QString::fromUtf8(tiptxt.c_str(), tiptxt.length()));
328
    pvTab->setTabToolTip(w,QString::fromUtf8(tiptxt.c_str(), tiptxt.length()));
330
329
331
    for (list<TabData>::iterator it = TABDATA->begin(); 
330
    for (list<TabData>::iterator it = tabData.begin(); 
332
     it != TABDATA->end(); it++) {
331
     it != tabData.end(); it++) {
333
    if (it->w == w) {
332
    if (it->w == w) {
334
        it->fn = fn;
333
        it->fn = fn;
335
        it->ipath = doc.ipath;
334
        it->ipath = doc.ipath;
335
      it->docnum = docnum;
336
        break;
336
        break;
337
    }
337
    }
338
    }
338
    }
339
}
339
}
340
340
341
TabData *Preview::tabDataForCurrent()
342
{
343
    QWidget *w = pvTab->currentPage();
344
    if (w == 0)
345
  return 0;
346
    for (list<TabData>::iterator it = tabData.begin(); 
347
   it != tabData.end(); it++) {
348
  if (it->w == w) {
349
      return &(*it);
350
  }
351
    }
352
    return 0;
353
}
354
341
bool Preview::makeDocCurrent(const string &fn, const Rcl::Doc &doc)
355
bool Preview::makeDocCurrent(const string &fn, const Rcl::Doc &doc)
342
{
356
{
343
    LOGDEB(("Preview::makeFileCurrent: %s\n", fn.c_str()));
357
    LOGDEB(("Preview::makeFileCurrent: %s\n", fn.c_str()));
344
    for (list<TabData>::iterator it = TABDATA->begin(); 
358
    for (list<TabData>::iterator it = tabData.begin(); 
345
     it != TABDATA->end(); it++) {
359
     it != tabData.end(); it++) {
346
    LOGDEB2(("Preview::makeFileCurrent: compare to w %p, file %s\n", 
360
    LOGDEB2(("Preview::makeFileCurrent: compare to w %p, file %s\n", 
347
         it->w, it->fn.c_str()));
361
         it->w, it->fn.c_str()));
348
    if (!it->fn.compare(fn) && !it->ipath.compare(doc.ipath)) {
362
    if (!it->fn.compare(fn) && !it->ipath.compare(doc.ipath)) {
349
        pvTab->showPage(it->w);
363
        pvTab->showPage(it->w);
350
        return true;
364
        return true;
...
...
455
#define CHUNKL 50*1000
469
#define CHUNKL 50*1000
456
#ifndef MIN
470
#ifndef MIN
457
#define MIN(A,B) ((A)<(B)?(A):(B))
471
#define MIN(A,B) ((A)<(B)?(A):(B))
458
#endif
472
#endif
459
473
460
bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
474
bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
475
                 int docnum)
461
{
476
{
462
    Rcl::Doc doc = idoc;
477
    Rcl::Doc doc = idoc;
463
    bool cancel = false;
478
    bool cancel = false;
464
479
465
    if (doc.title.empty()) 
480
    if (doc.title.empty()) 
466
    doc.title = path_getsimple(doc.url);
481
    doc.title = path_getsimple(doc.url);
467
482
468
    setCurTabProps(fn, doc);
483
    setCurTabProps(fn, doc, docnum);
469
484
470
    char csz[20];
485
    char csz[20];
471
    sprintf(csz, "%lu", (unsigned long)sz);
486
    sprintf(csz, "%lu", (unsigned long)sz);
472
    QString msg = QString("Loading: %1 (size %2 bytes)")
487
    QString msg = QString("Loading: %1 (size %2 bytes)")
473
    .arg(QString::fromLocal8Bit(fn.c_str()))
488
    .arg(QString::fromLocal8Bit(fn.c_str()))
...
...
551
    }
566
    }
552
567
553
    // Load into editor
568
    // Load into editor
554
    // Do it in several chunks 
569
    // Do it in several chunks 
555
    QTextEdit *editor = getCurrentEditor();
570
    QTextEdit *editor = getCurrentEditor();
571
    editor->setText("");
556
    if (highlightTerms) {
572
    if (highlightTerms) {
557
    QStyleSheetItem *item = 
573
    QStyleSheetItem *item = 
558
        new QStyleSheetItem(editor->styleSheet(), "termtag" );
574
        new QStyleSheetItem(editor->styleSheet(), "termtag" );
559
    item->setColor("blue");
575
    item->setColor("blue");
560
    item->setFontWeight(QFont::Bold);
576
    item->setFontWeight(QFont::Bold);
...
...
590
        LOGDEB(("Cancelled\n"));
606
        LOGDEB(("Cancelled\n"));
591
        break;
607
        break;
592
    }
608
    }
593
    }
609
    }
594
610
611
    if (searchTextLine->text().length() != 0) {
612
  canBeep = true;
613
  doSearch(searchTextLine->text(), true, false);
614
    } else {
595
    if (!firstTerm.empty()) {
615
  if (!firstTerm.empty()) {
596
    bool wasC = matchCheck->isChecked();
616
        bool wasC = matchCheck->isChecked();
597
    matchCheck->setChecked(false);
617
        matchCheck->setChecked(false);
598
    doSearch(QString::fromUtf8(terms.begin()->c_str()), true, false);
618
        doSearch(QString::fromUtf8(terms.begin()->c_str()), true, false);
599
    matchCheck->setChecked(wasC);
619
        matchCheck->setChecked(wasC);
620
  }
600
    }
621
    }
601
    return true;
622
    return true;
602
}
623
}
603
624