small cleanups in gui modules couplings

This commit is contained in:
Jean-Francois Dockes 2010-12-17 16:32:41 +01:00
parent 61348a7731
commit 23222e752e
6 changed files with 90 additions and 102 deletions

View File

@ -108,12 +108,6 @@ void RclMain::init()
// Set the focus to the search terms entry:
sSearch->queryText->setFocus();
// Set result list font according to user preferences.
if (prefs.reslistfontfamily.length()) {
QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize);
resList->setFont(nfont);
}
// Stemming language menu
g_stringNoStem = tr("(no stemming)");
g_stringAllStem = tr("(all languages)");
@ -152,7 +146,6 @@ void RclMain::init()
QShortcut *sc = new QShortcut(seq, this);
connect(sc, SIGNAL (activated()), this, SLOT (focusToSearch()));
// Toolbar+combobox version of the category selector
QComboBox *catgCMB = 0;
if (prefs.catgToolBar) {
@ -173,7 +166,6 @@ void RclMain::init()
int bgrpid = 0;
bgrp->addButton(allRDB, bgrpid++);
connect(bgrp, SIGNAL(buttonClicked(int)), this, SLOT(catgFilter(int)));
allRDB->setChecked(true);
list<string> cats;
rclconfig->getMimeCategories(cats);
@ -195,9 +187,10 @@ void RclMain::init()
if (prefs.catgToolBar)
catgBGRP->hide();
// Connections
connect(sSearch, SIGNAL(startSearch(RefCntr<Rcl::SearchData>)),
this, SLOT(startSearch(RefCntr<Rcl::SearchData>)));
this, SLOT(startSearch(RefCntr<Rcl::SearchData>)));
sSearch->queryText->installEventFilter(this);
connect(preferencesMenu, SIGNAL(triggered(QAction*)),
@ -213,22 +206,23 @@ void RclMain::init()
connect(nextPageAction, SIGNAL(activated()),
resList, SLOT(resPageDownOrNext()));
connect(resList, SIGNAL(docExpand(int)), this, SLOT(docExpand(int)));
connect(resList, SIGNAL(docExpand(Rcl::Doc)),
this, SLOT(docExpand(Rcl::Doc)));
connect(resList, SIGNAL(wordSelect(QString)),
this, SLOT(ssearchAddTerm(QString)));
sSearch, SLOT(addTerm(QString)));
connect(resList, SIGNAL(nextPageAvailable(bool)),
this, SLOT(enableNextPage(bool)));
connect(resList, SIGNAL(prevPageAvailable(bool)),
this, SLOT(enablePrevPage(bool)));
connect(resList, SIGNAL(docEditClicked(int)),
this, SLOT(startNativeViewer(int)));
connect(resList, SIGNAL(docSaveToFileClicked(int)),
this, SLOT(saveDocToFile(int)));
connect(resList, SIGNAL(docEditClicked(Rcl::Doc)),
this, SLOT(startNativeViewer(Rcl::Doc)));
connect(resList, SIGNAL(docSaveToFileClicked(Rcl::Doc)),
this, SLOT(saveDocToFile(Rcl::Doc)));
connect(resList, SIGNAL(editRequested(Rcl::Doc)),
this, SLOT(startNativeViewer(Rcl::Doc)));
connect(resList, SIGNAL(docPreviewClicked(int, int)),
this, SLOT(startPreview(int, int)));
connect(resList, SIGNAL(docPreviewClicked(int, Rcl::Doc, int)),
this, SLOT(startPreview(int, Rcl::Doc, int)));
connect(resList, SIGNAL(previewRequested(Rcl::Doc)),
this, SLOT(startPreview(Rcl::Doc)));
@ -248,8 +242,8 @@ void RclMain::init()
this, SLOT(showAdvSearchDialog()));
connect(toolsSpellAction, SIGNAL(activated()),
this, SLOT(showSpellDialog()));
connect(indexConfigAction, SIGNAL(activated()), this, SLOT(showIndexConfig()));
connect(indexConfigAction, SIGNAL(activated()),
this, SLOT(showIndexConfig()));
connect(queryPrefsAction, SIGNAL(activated()), this, SLOT(showUIPrefs()));
connect(extIdxAction, SIGNAL(activated()), this, SLOT(showExtIdxDialog()));
if (prefs.catgToolBar && catgCMB)
@ -591,7 +585,7 @@ void RclMain::showSpellDialog()
if (spellform == 0) {
spellform = new SpellW(0);
connect(spellform, SIGNAL(wordSelect(QString)),
this, SLOT(ssearchAddTerm(QString)));
sSearch, SLOT(addTerm(QString)));
spellform->show();
} else {
// Close and reopen, in hope that makes us visible...
@ -683,15 +677,9 @@ void RclMain::previewClosed(Preview *w)
* @param docnum db query index
* @param mod keyboards modifiers like ControlButton, ShiftButton
*/
void RclMain::startPreview(int docnum, int mod)
void RclMain::startPreview(int docnum, Rcl::Doc doc, int mod)
{
Rcl::Doc doc;
if (!resList->getDoc(docnum, doc)) {
QMessageBox::warning(0, "Recoll", tr("Cannot retrieve document info"
" from database"));
return;
}
LOGDEB(("startPreview(%d, doc, %d)\n", docnum, mod));
if (mod & Qt::ShiftModifier) {
// User wants new preview window
curPreview = 0;
@ -710,7 +698,7 @@ void RclMain::startPreview(int docnum, int mod)
connect(curPreview, SIGNAL(previewClosed(Preview *)),
this, SLOT(previewClosed(Preview *)));
connect(curPreview, SIGNAL(wordSelect(QString)),
this, SLOT(ssearchAddTerm(QString)));
sSearch, SLOT(addTerm(QString)));
connect(curPreview, SIGNAL(showNext(Preview *, int, int)),
this, SLOT(previewNextInTab(Preview *, int, int)));
connect(curPreview, SIGNAL(showPrev(Preview *, int, int)),
@ -741,7 +729,7 @@ void RclMain::startPreview(Rcl::Doc doc)
return;
}
connect(preview, SIGNAL(wordSelect(QString)),
this, SLOT(ssearchAddTerm(QString)));
sSearch, SLOT(addTerm(QString)));
preview->show();
preview->makeDocCurrent(doc, 0);
}
@ -851,43 +839,8 @@ void RclMain::on_actionSortByDateDesc_toggled(bool on)
onSortDataChanged();
}
// Add term to simple search. Term comes out of double-click in
// 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 format is explicit richtext
// instead of auto as for preview, needed because it's built by
// fragments?).
static const char* punct = " \t()<>\"'[]{}!^*.,:;\n\r";
void RclMain::ssearchAddTerm(QString term)
void RclMain::saveDocToFile(Rcl::Doc doc)
{
LOGDEB(("RclMain::ssearchAddTerm: [%s]\n", (const char *)term.toUtf8()));
string t = (const char *)term.toUtf8();
string::size_type pos = t.find_last_not_of(punct);
if (pos == string::npos)
return;
t = t.substr(0, pos+1);
pos = t.find_first_not_of(punct);
if (pos != string::npos)
t = t.substr(pos);
if (t.empty())
return;
term = QString::fromUtf8(t.c_str());
QString text = sSearch->queryText->currentText();
text += QString::fromLatin1(" ") + term;
sSearch->queryText->setEditText(text);
}
void RclMain::saveDocToFile(int docnum)
{
Rcl::Doc doc;
if (!resList->getDoc(docnum, doc)) {
QMessageBox::warning(0, "Recoll",
tr("Cannot retrieve document info"
" from database"));
return;
}
QString s =
QFileDialog::getSaveFileName(this, //parent
tr("Save file"), // caption
@ -926,17 +879,6 @@ static bool lookForHtmlBrowser(string &exefile)
return false;
}
void RclMain::startNativeViewer(int docnum)
{
Rcl::Doc doc;
if (!resList->getDoc(docnum, doc)) {
QMessageBox::warning(0, "Recoll", tr("Cannot retrieve document info"
" from database"));
return;
}
startNativeViewer(doc);
}
// Convert to file path if url is like file://
static string fileurltolocalpath(string url)
{
@ -1171,13 +1113,10 @@ void RclMain::startManual(const string& index)
// Search for document 'like' the selected one. We ask rcldb/xapian to find
// significant terms, and add them to the simple search entry.
void RclMain::docExpand(int docnum)
void RclMain::docExpand(Rcl::Doc doc)
{
if (!rcldb)
return;
Rcl::Doc doc;
if (!resList->getDoc(docnum, doc))
return;
list<string> terms;
terms = resList->expand(doc);
if (terms.empty())

View File

@ -75,13 +75,11 @@ public slots:
virtual void setUIPrefs();
virtual void enableNextPage(bool);
virtual void enablePrevPage(bool);
virtual void docExpand(int);
virtual void ssearchAddTerm(QString);
virtual void startPreview(int docnum, int);
virtual void startPreview(Rcl::Doc doc);
virtual void startNativeViewer(int docnum);
virtual void startNativeViewer(Rcl::Doc doc);
virtual void saveDocToFile(int docnum);
virtual void docExpand(Rcl::Doc);
virtual void startPreview(int doc, Rcl::Doc doc, int keymods);
virtual void startPreview(Rcl::Doc);
virtual void startNativeViewer(Rcl::Doc);
virtual void saveDocToFile(Rcl::Doc);
virtual void previewNextInTab(Preview *, int sid, int docnum);
virtual void previewPrevInTab(Preview *, int sid, int docnum);
virtual void previewExposed(Preview *, int sid, int docnum);

View File

@ -233,6 +233,10 @@ ResList::ResList(QWidget* parent, const char* name)
m_listId = 0;
m_pager = new QtGuiResListPager(this, prefs.respagesize);
m_pager->setHighLighter(&g_hiliter);
if (prefs.reslistfontfamily.length()) {
QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize);
setFont(nfont);
}
}
ResList::~ResList()
@ -625,6 +629,7 @@ void ResList::linkWasClicked(const QUrl &url)
QString s = url.toString();
const char *ascurl = s.toAscii();
LOGDEB(("ResList::linkWasClicked: [%s]\n", ascurl));
int i = atoi(ascurl+1) - 1;
int what = ascurl[0];
switch (what) {
@ -632,18 +637,28 @@ void ResList::linkWasClicked(const QUrl &url)
emit headerClicked();
break;
case 'P':
emit docPreviewClicked(i, m_lstClckMod);
break;
case 'E':
emit docEditClicked(i);
break;
{
Rcl::Doc doc;
if (!getDoc(i, doc)) {
LOGERR(("ResList::linkWasClicked: can't get doc for %d\n", i));
return;
}
if (what == 'P')
emit docPreviewClicked(i, doc, m_lstClckMod);
else
emit docEditClicked(doc);
}
break;
case 'n':
resultPageNext();
break;
case 'p':
resultPageBack();
break;
default: break;// ??
default:
LOGERR(("ResList::linkWasClicked: bad link [%s]\n", ascurl));
break;// ??
}
}
@ -677,11 +692,15 @@ void ResList::createPopupMenu(const QPoint& pos)
void ResList::menuPreview()
{
emit docPreviewClicked(m_popDoc, 0);
Rcl::Doc doc;
if (getDoc(m_popDoc, doc))
emit docPreviewClicked(m_popDoc, doc, 0);
}
void ResList::menuSaveToFile()
{
emit docSaveToFileClicked(m_popDoc);
Rcl::Doc doc;
if (getDoc(m_popDoc, doc))
emit docSaveToFileClicked(doc);
}
void ResList::menuPreviewParent()
@ -720,7 +739,9 @@ void ResList::menuOpenParent()
void ResList::menuEdit()
{
emit docEditClicked(m_popDoc);
Rcl::Doc doc;
if (getDoc(m_popDoc, doc))
emit docEditClicked(doc);
}
void ResList::menuCopyFN()
{
@ -755,7 +776,9 @@ void ResList::menuCopyURL()
void ResList::menuExpand()
{
emit docExpand(m_popDoc);
Rcl::Doc doc;
if (getDoc(m_popDoc, doc))
emit docExpand(doc);
}
QString ResList::getDescription()

View File

@ -82,13 +82,13 @@ class ResList : public QTextBrowser
signals:
void nextPageAvailable(bool);
void prevPageAvailable(bool);
void docEditClicked(int);
void docPreviewClicked(int, int);
void docSaveToFileClicked(int);
void docEditClicked(Rcl::Doc);
void docPreviewClicked(int, Rcl::Doc, int);
void docSaveToFileClicked(Rcl::Doc);
void previewRequested(Rcl::Doc);
void editRequested(Rcl::Doc);
void headerClicked();
void docExpand(int);
void docExpand(Rcl::Doc);
void wordSelect(QString);
void linkClicked(const QString&, int); // See emitLinkClicked()
void hasResults(int);

View File

@ -216,6 +216,34 @@ bool SSearch::hasSearchString()
return !queryText->lineEdit()->text().isEmpty();
}
// Add term to simple search. Term comes out of double-click in
// 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 format is explicit richtext
// instead of auto as for preview, needed because it's built by
// fragments?).
static const char* punct = " \t()<>\"'[]{}!^*.,:;\n\r";
void SSearch::addTerm(QString term)
{
LOGDEB(("SSearch::AddTerm: [%s]\n", (const char *)term.toUtf8()));
string t = (const char *)term.toUtf8();
string::size_type pos = t.find_last_not_of(punct);
if (pos == string::npos)
return;
t = t.substr(0, pos+1);
pos = t.find_first_not_of(punct);
if (pos != string::npos)
t = t.substr(pos);
if (t.empty())
return;
term = QString::fromUtf8(t.c_str());
QString text = queryText->currentText();
text += QString::fromLatin1(" ") + term;
queryText->setEditText(text);
}
void SSearch::setAnyTermMode()
{
searchTypCMB->setCurrentIndex(SST_ANY);

View File

@ -46,12 +46,12 @@ public:
virtual void completion();
virtual bool eventFilter(QObject *target, QEvent *event);
virtual bool hasSearchString();
public slots:
virtual void searchTextChanged(const QString & text);
virtual void searchTypeChanged(int);
virtual void setSearchString(const QString& text);
virtual void startSimpleSearch();
virtual void addTerm(QString);
signals:
void startSearch(RefCntr<Rcl::SearchData>);