diff --git a/src/qtgui/plaintorich.cpp b/src/qtgui/plaintorich.cpp index def91a2c..f28f2384 100644 --- a/src/qtgui/plaintorich.cpp +++ b/src/qtgui/plaintorich.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.23 2007-06-12 10:32:43 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.24 2007-06-12 13:31:38 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -317,7 +317,7 @@ string termAnchorName(int i) // http://unicode.org/faq/char_combmark.html#17 // We are counting on the fact that a sequence of two such chars should be // extremely unlikely in normal text and not affecting the display. -const char *firstTermBeacon = "\xcd\x8f\xcd\x8f"; +const char *firstTermBeacon = " \xcd\x8f\xcd\x8f "; #endif static string termBeacon(int i) diff --git a/src/qtgui/preview_w.cpp b/src/qtgui/preview_w.cpp index a7a57305..c8012658 100644 --- a/src/qtgui/preview_w.cpp +++ b/src/qtgui/preview_w.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.19 2007-06-01 05:44:40 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.20 2007-06-12 13:31:38 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -47,7 +47,8 @@ using std::pair; #include #include #include -#include "qapplication.h" +#include +#include #include "debuglog.h" #include "pathut.h" @@ -88,8 +89,6 @@ void Preview::init() this, SLOT(currentChanged(QWidget *))); connect(bt, SIGNAL(clicked()), this, SLOT(closeCurrentTab())); - searchTextLine->installEventFilter(this); - pvEdit->installEventFilter(this); dynSearchActive = false; canBeep = true; tabData.push_back(TabData(pvTab->currentPage())); @@ -98,6 +97,7 @@ void Preview::init() resize(prefs.pvwidth, prefs.pvheight); } m_loading = false; + currentChanged(pvTab->currentPage()); } void Preview::destroy() @@ -116,7 +116,7 @@ void Preview::closeEvent(QCloseEvent *e) bool Preview::eventFilter(QObject *target, QEvent *event) { if (event->type() != QEvent::KeyPress) - return QWidget::eventFilter(target, event); + return false; LOGDEB1(("Preview::eventFilter: keyEvent\n")); QKeyEvent *keyEvent = (QKeyEvent *)event; @@ -174,7 +174,7 @@ bool Preview::eventFilter(QObject *target, QEvent *event) } } - return QWidget::eventFilter(target, event); + return false; } void Preview::searchTextLine_textChanged(const QString & text) @@ -295,20 +295,60 @@ void Preview::currentChanged(QWidget * tw) if (edit == 0) { LOGERR(("Editor child not found\n")); - } else { - tw->installEventFilter(this); - edit->installEventFilter(this); - edit->setFocus(); - connect(edit, SIGNAL(doubleClicked(int, int)), - this, SLOT(textDoubleClicked(int, int))); - TabData *d = tabDataForCurrent(); - if (d) - emit(previewExposed(m_searchId, d->docnum)); + return; + } + edit->setFocus(); + // Connect doubleclick but cleanup first just in case this was + // already connected. + disconnect(edit, SIGNAL(doubleClicked(int, int)), this, 0); + connect(edit, SIGNAL(doubleClicked(int, int)), + this, SLOT(textDoubleClicked(int, int))); +#if (QT_VERSION >= 0x040000) + connect(edit, SIGNAL(selectionChanged()), this, SLOT(selecChanged())); +#endif + tw->installEventFilter(this); + edit->installEventFilter(this); + TabData *d = tabDataForCurrent(); + if (d) + emit(previewExposed(m_searchId, d->docnum)); +} + +#if (QT_VERSION >= 0x040000) +// I have absolutely no idea why this nonsense is needed to get +// q3textedit to copy to x11 primary selection when text is +// selected. This used to be automatic, and, looking at the code, it +// should happen inside q3textedit (the code here is copied from the +// private copyToClipboard method). To be checked again with a later +// qt version. +void Preview::selecChanged() +{ + LOGDEB1(("Selection changed\n")); + if (!currentW) + return; + QTextEdit *edit = (QTextEdit *)currentW->child("pvEdit"); + if (edit == 0) { + LOGERR(("Editor child not found\n")); + return; + } + QClipboard *clipboard = QApplication::clipboard(); + if (edit->hasSelectedText()) { + LOGDEB1(("Copying [%s] to primary selection.Clipboard sel supp: %d\n", + (const char *)edit->selectedText().ascii(), + clipboard->supportsSelection())); + disconnect(QApplication::clipboard(), SIGNAL(selectionChanged()), + edit, 0); + clipboard->setText(edit->selectedText(), QClipboard::Selection); + connect(QApplication::clipboard(), SIGNAL(selectionChanged()), + edit, SLOT(clipboardChanged())); } } +#else +void Preview::selecChanged(){} +#endif void Preview::textDoubleClicked(int, int) { + LOGDEB2(("Preview::textDoubleClicked\n")); if (!currentW) return; QTextEdit *edit = (QTextEdit *)currentW->child("pvEdit"); diff --git a/src/qtgui/preview_w.h b/src/qtgui/preview_w.h index aeddfd3c..2ded8b04 100644 --- a/src/qtgui/preview_w.h +++ b/src/qtgui/preview_w.h @@ -1,6 +1,6 @@ #ifndef _PREVIEW_W_H_INCLUDED_ #define _PREVIEW_W_H_INCLUDED_ -/* @(#$Id: preview_w.h,v 1.10 2007-05-23 09:19:48 dockes Exp $ (C) 2006 J.F.Dockes */ +/* @(#$Id: preview_w.h,v 1.11 2007-06-12 13:31:38 dockes Exp $ (C) 2006 J.F.Dockes */ /* * 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 @@ -95,6 +95,9 @@ public slots: int docnum); virtual void textDoubleClicked(int, int); + virtual void selecChanged(); + + signals: void previewClosed(QWidget *); void wordSelect(QString); diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index eba9ca54..e7e34e66 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.28 2007-06-12 08:50:19 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.29 2007-06-12 13:31:38 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -600,25 +600,24 @@ void RclMain::previewExposed(int sid, int docnum) } // Add term to simple search. Term comes out of double-click in -// reslist or preview. The cleanup code is really horrible. Selection -// out of the reslist will typically look like -// sometext +// reslist or preview. // It would probably be better to cleanup in preview.ui.h and // reslist.cpp and do the proper html stuff in the latter case -// (which is different because it's format is explicit richtext +// (which is different because it format is explicit richtext // instead of auto as for preview, needed because it's built by // fragments?). -static const char* punct = " \t()<>\"'[]{}!^*,\n\r"; +static const char* punct = " \t()<>\"'[]{}!^*.,:;\n\r"; void RclMain::ssearchAddTerm(QString term) { + LOGDEB(("RclMain::ssearchAddTerm: [%s]\n", (const char *)term.utf8())); string t = (const char *)term.utf8(); string::size_type pos = t.find_last_not_of(punct); if (pos == string::npos) return; t = t.substr(0, pos+1); - pos = t.find_last_of(punct); + pos = t.find_first_not_of(punct); if (pos != string::npos) - t = t.substr(pos+1); + t = t.substr(pos); if (t.empty()) return; term = QString::fromUtf8(t.c_str()); diff --git a/src/qtgui/reslist.cpp b/src/qtgui/reslist.cpp index 3b6e275d..d96df46f 100644 --- a/src/qtgui/reslist.cpp +++ b/src/qtgui/reslist.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: reslist.cpp,v 1.24 2007-05-30 12:29:38 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: reslist.cpp,v 1.25 2007-06-12 13:31:38 dockes Exp $ (C) 2005 J.F.Dockes"; #endif #include @@ -51,7 +51,6 @@ ResList::ResList(QWidget* parent, const char* name) { if (!name) setName("resList"); - setTextFormat(Qt::RichText); setReadOnly(TRUE); setUndoRedoEnabled(FALSE); languageChange(); @@ -59,12 +58,14 @@ ResList::ResList(QWidget* parent, const char* name) setTabChangesFocus(true); // signals and slots connections - connect(this, SIGNAL(clicked(int, int)), this, SLOT(clicked(int,int))); connect(this, SIGNAL(linkClicked(const QString &, int)), this, SLOT(linkWasClicked(const QString &, int))); connect(this, SIGNAL(headerClicked()), this, SLOT(showQueryDetails())); connect(this, SIGNAL(doubleClicked(int,int)), this, SLOT(doubleClicked(int, int))); +#if (QT_VERSION >= 0x040000) + connect(this, SIGNAL(selectionChanged()), this, SLOT(selecChanged())); +#endif m_winfirst = -1; m_curPvDoc = -1; m_lstClckMod = 0; @@ -85,7 +86,7 @@ void ResList::resetSearch() // following helps making sure that the textedit is really // blank. Else, there are often icons or text left around clear(); - append("."); + QTEXTBROWSER::append("."); clear(); #if (QT_VERSION < 0x040000) XFlush(qt_xdisplay()); @@ -553,25 +554,6 @@ void ResList::resultPageNext() ensureCursorVisible(); } -// Single click in result list use this for document selection, if no -// text selection active: -void ResList::clicked(int par, int) -{ - LOGDEB2(("ResList::clicked\n")); - - // It's very ennoying, textBrowser always has selected text. This - // is bound to change with qt releases! - if (hasSelectedText()&& selectedText().compare("")) { - // Give priority to text selection, do nothing - LOGDEB2(("%s\n", (const char *)(selectedText().ascii()))); - return; - } - LOGDEB(("click at par %d (with %s %s)\n", par, - (m_lstClckMod & Qt::ControlButton) ? "Ctrl" : "", - (m_lstClckMod & Qt::ShiftButton) ? "Shft" : "")); - -} - // Color paragraph (if any) of currently visible preview void ResList::previewExposed(int docnum) { @@ -598,6 +580,32 @@ void ResList::previewExposed(int docnum) setParagraphBackgroundColor(par, color); } +// SELECTION BEWARE: these emit simple text if the list format is +// Auto. If we get back to using Rich for some reason, there will be +// need to extract the simple text here. + +#if (QT_VERSION >= 0x040000) +// I have absolutely no idea why this nonsense is needed to get +// q3textedit to copy to x11 primary selection when text is +// selected. This used to be automatic, and, looking at the code, it +// should happen inside q3textedit (the code here is copied from the +// private copyToClipboard method). To be checked again with a later +// qt version. Seems to be needed at least up to 4.2.3 +void ResList::selecChanged() +{ + QClipboard *clipboard = QApplication::clipboard(); + if (hasSelectedText()) { + disconnect(QApplication::clipboard(), SIGNAL(selectionChanged()), + this, 0); + clipboard->setText(selectedText(), QClipboard::Selection); + connect(QApplication::clipboard(), SIGNAL(selectionChanged()), + this, SLOT(clipboardChanged())); + } +} +#else +void ResList::selecChanged(){} +#endif + // Double click in res list: add selection to simple search void ResList::doubleClicked(int, int) { diff --git a/src/qtgui/reslist.h b/src/qtgui/reslist.h index e6a9fca1..d0bdb808 100644 --- a/src/qtgui/reslist.h +++ b/src/qtgui/reslist.h @@ -1,6 +1,6 @@ #ifndef _RESLIST_H_INCLUDED_ #define _RESLIST_H_INCLUDED_ -/* @(#$Id: reslist.h,v 1.10 2007-05-30 12:29:38 dockes Exp $ (C) 2005 J.F.Dockes */ +/* @(#$Id: reslist.h,v 1.11 2007-06-12 13:31:38 dockes Exp $ (C) 2005 J.F.Dockes */ #include @@ -44,7 +44,6 @@ class ResList : public QTEXTBROWSER public slots: virtual void resetSearch(); - virtual void clicked(int, int); virtual void doubleClicked(int, int); virtual void resPageUpOrBack(); // Page up pressed virtual void resPageDownOrNext(); // Page down pressed @@ -58,6 +57,8 @@ class ResList : public QTEXTBROWSER virtual void menuSeeParent(); virtual void previewExposed(int); virtual void append(const QString &text); + // Only used for qt ver >=4 but seems we cant undef it + virtual void selecChanged(); signals: void nextPageAvailable(bool);