diff options
Diffstat (limited to 'src/frontend/searchdialog')
26 files changed, 2799 insertions, 2893 deletions
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp b/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp index 7ce07e8..76483de 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp +++ b/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp @@ -23,62 +23,58 @@ namespace Search { -static const int DIALOG_HEIGHT=400; -static const int DIALOG_BORDER=30; +static const int DIALOG_HEIGHT = 400; +static const int DIALOG_BORDER = 30; CSearchAnalysisDialog::CSearchAnalysisDialog( QList<CSwordModuleInfo*> modules, QWidget* parentDialog ) - : QDialog(parentDialog) -{ - initView(); - m_analysis->reset(); - m_analysis->analyse(modules); - - // Set initial width based on the search data, but limit to the - // width of the desktop - int width = (int)( m_analysis->width()+DIALOG_BORDER ); - int desktopWidth = QApplication::desktop()->screenGeometry(this).width(); - if (width > desktopWidth) - width = desktopWidth; - resize(width, DIALOG_HEIGHT); + : QDialog(parentDialog) { + initView(); + m_analysis->reset(); + m_analysis->analyse(modules); + + // Set initial width based on the search data, but limit to the + // width of the desktop + int width = (int)( m_analysis->width() + DIALOG_BORDER ); + int desktopWidth = QApplication::desktop()->screenGeometry(this).width(); + if (width > desktopWidth) + width = desktopWidth; + resize(width, DIALOG_HEIGHT); } /** Initializes this dialog. */ -void CSearchAnalysisDialog::initView() -{ +void CSearchAnalysisDialog::initView() { - QVBoxLayout *vboxLayout = new QVBoxLayout(this); + QVBoxLayout *vboxLayout = new QVBoxLayout(this); - m_analysis = new CSearchAnalysisScene(this); - m_analysisView = new CSearchAnalysisView(m_analysis, this); + m_analysis = new CSearchAnalysisScene(this); + m_analysisView = new CSearchAnalysisView(m_analysis, this); //// m_analysisView->show(); - vboxLayout->addWidget(m_analysisView); - - m_buttonBox = new QDialogButtonBox(this); - m_buttonBox->setOrientation(Qt::Horizontal); - m_buttonBox->setStandardButtons(QDialogButtonBox::Close); - m_buttonBox->addButton(QDialogButtonBox::Save); - //tr("Save as HTML"), - util::prepareDialogBox(m_buttonBox); - vboxLayout->addWidget(m_buttonBox); - - bool ok = QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject())); - Q_ASSERT(ok); - ok = QObject::connect(m_buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); - Q_ASSERT(ok); + vboxLayout->addWidget(m_analysisView); + + m_buttonBox = new QDialogButtonBox(this); + m_buttonBox->setOrientation(Qt::Horizontal); + m_buttonBox->setStandardButtons(QDialogButtonBox::Close); + m_buttonBox->addButton(QDialogButtonBox::Save); + //tr("Save as HTML"), + util::prepareDialogBox(m_buttonBox); + vboxLayout->addWidget(m_buttonBox); + + bool ok = QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + Q_ASSERT(ok); + ok = QObject::connect(m_buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); + Q_ASSERT(ok); } -void CSearchAnalysisDialog::buttonClicked(QAbstractButton* button) -{ - if (m_buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { - m_analysis->saveAsHTML(); - } +void CSearchAnalysisDialog::buttonClicked(QAbstractButton* button) { + if (m_buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { + m_analysis->saveAsHTML(); + } } -void CSearchAnalysisDialog::resizeEvent(QResizeEvent* event) -{ - QDialog::resizeEvent(event); - m_analysis->resizeHeight(height()); +void CSearchAnalysisDialog::resizeEvent(QResizeEvent* event) { + QDialog::resizeEvent(event); + m_analysis->resizeHeight(height()); } } diff --git a/src/frontend/searchdialog/analysis/csearchanalysisdialog.h b/src/frontend/searchdialog/analysis/csearchanalysisdialog.h index c24c554..7c48c15 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisdialog.h +++ b/src/frontend/searchdialog/analysis/csearchanalysisdialog.h @@ -15,7 +15,7 @@ class CSwordModuleInfo; #include <QDialog> #include <QObject> - + class QAbstractButton; class QDialogButtonBox; @@ -29,28 +29,27 @@ class CSearchAnalysisScene; /** @author The BibleTime team <info@bibletime.info> */ -class CSearchAnalysisDialog : public QDialog -{ - Q_OBJECT - -public: - CSearchAnalysisDialog(QList<CSwordModuleInfo*> modules, QWidget* parentDialog); - ~CSearchAnalysisDialog() {} - -protected: // Protected methods - /** - * Initializes this dialog. - */ - void initView(); - void resizeEvent(QResizeEvent* event); - -private slots: - void buttonClicked(QAbstractButton* button); - -private: - CSearchAnalysisScene* m_analysis; - CSearchAnalysisView* m_analysisView; - QDialogButtonBox* m_buttonBox; +class CSearchAnalysisDialog : public QDialog { + Q_OBJECT + + public: + CSearchAnalysisDialog(QList<CSwordModuleInfo*> modules, QWidget* parentDialog); + ~CSearchAnalysisDialog() {} + + protected: // Protected methods + /** + * Initializes this dialog. + */ + void initView(); + void resizeEvent(QResizeEvent* event); + + private slots: + void buttonClicked(QAbstractButton* button); + + private: + CSearchAnalysisScene* m_analysis; + CSearchAnalysisView* m_analysisView; + QDialogButtonBox* m_buttonBox; }; } diff --git a/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp b/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp index 713a98b..fb3810d 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp +++ b/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp @@ -43,127 +43,125 @@ const int LEGEND_DELTAY = 4; const int LEGEND_WIDTH = 85; CSearchAnalysisItem::CSearchAnalysisItem(const int moduleCount, const QString &bookname, double *scaleFactor, QList<CSwordModuleInfo*>* modules) - : QGraphicsRectItem(), - m_moduleList( modules ), - m_scaleFactor(scaleFactor), - m_bookName(bookname), - m_moduleCount(moduleCount), - m_bufferPixmap(0) -{ - m_resultCountArray.resize(m_moduleCount); - int index = 0; - for (index = 0; index < m_moduleCount; ++index) m_resultCountArray[index] = 0; + : QGraphicsRectItem(), + m_moduleList( modules ), + m_scaleFactor(scaleFactor), + m_bookName(bookname), + m_moduleCount(moduleCount), + m_bufferPixmap(0) { + m_resultCountArray.resize(m_moduleCount); + int index = 0; + for (index = 0; index < m_moduleCount; ++index) m_resultCountArray[index] = 0; } -CSearchAnalysisItem::~CSearchAnalysisItem() -{ - delete m_bufferPixmap; +CSearchAnalysisItem::~CSearchAnalysisItem() { + delete m_bufferPixmap; } /** Sets the resultcount of this item for the given module */ void CSearchAnalysisItem::setCountForModule( const int moduleIndex, const int count) { - m_resultCountArray[moduleIndex] = count; + m_resultCountArray[moduleIndex] = count; } /** Returns the resultcount of this item for the given module */ int CSearchAnalysisItem::getCountForModule( const int moduleIndex) { - return m_resultCountArray[moduleIndex]; + return m_resultCountArray[moduleIndex]; } bool CSearchAnalysisItem::hasHitsInAnyModule() { - foreach (const int hits, m_resultCountArray){ - if (hits) return true; - } - return false; + foreach (const int hits, m_resultCountArray) { + if (hits) return true; + } + return false; } /** Reimplementation. Draws the content of this item. */ void CSearchAnalysisItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) { - QFont f = painter->font(); - f.setPointSize(ITEM_TEXT_SIZE); - painter->setFont(f); - - /** - * We have to paint so many bars as we have modules available (we use m_moduleCount) - * We paint inside the area which is given by height and width of this rectangle item - */ - int index = 0; - int drawn = 0; - int Value = 0; - - //find out the biggest value - for (index=0;index < m_moduleCount; index++) { - if (m_resultCountArray[index] > Value) { - Value = m_resultCountArray[index]; - } - }; - - while (drawn < m_moduleCount) { - for (index = 0; index < m_moduleCount; index++) { - if (m_resultCountArray[index] == Value) { - QPoint p1((int)rect().x() + (m_moduleCount-drawn-1)*BAR_DELTAX, - (int)rect().height() + (int)y() - BAR_LOWER_BORDER - (m_moduleCount-drawn)*BAR_DELTAY); - QPoint p2(p1.x() + BAR_WIDTH, - p1.y() - (int)( !m_resultCountArray[index] ? 0 : ((m_resultCountArray[index])*(*m_scaleFactor))) ); - QRect r(p1, p2); - painter->fillRect(r, QBrush(CSearchAnalysisScene::getColor(index)) ); - painter->drawRect(r); - drawn++; - } - } - //finds the next smaller value - int newValue = 0; - for (index=0;index < m_moduleCount; index++) - if (m_resultCountArray[index] < Value && m_resultCountArray[index] >= newValue) - newValue = m_resultCountArray[index]; - Value = newValue; - } - if (!m_bufferPixmap) { - m_bufferPixmap = new QPixmap(width(),BAR_LOWER_BORDER); - //m_bufferPixmap->resize(width(),BAR_LOWER_BORDER); - m_bufferPixmap->fill(); - QPainter p(m_bufferPixmap); - f = p.font(); - f.setPointSize(ITEM_TEXT_SIZE); - p.setFont(f); - p.rotate(90); - p.drawText(QPoint(5,0), m_bookName); - } - painter->drawPixmap(QPoint(int(rect().x()),int(rect().height()+y()-BAR_LOWER_BORDER)), *m_bufferPixmap); + QFont f = painter->font(); + f.setPointSize(ITEM_TEXT_SIZE); + painter->setFont(f); + + /** + * We have to paint so many bars as we have modules available (we use m_moduleCount) + * We paint inside the area which is given by height and width of this rectangle item + */ + int index = 0; + int drawn = 0; + int Value = 0; + + //find out the biggest value + for (index = 0;index < m_moduleCount; index++) { + if (m_resultCountArray[index] > Value) { + Value = m_resultCountArray[index]; + } + }; + + while (drawn < m_moduleCount) { + for (index = 0; index < m_moduleCount; index++) { + if (m_resultCountArray[index] == Value) { + QPoint p1((int)rect().x() + (m_moduleCount - drawn - 1)*BAR_DELTAX, + (int)rect().height() + (int)y() - BAR_LOWER_BORDER - (m_moduleCount - drawn)*BAR_DELTAY); + QPoint p2(p1.x() + BAR_WIDTH, + p1.y() - (int)( !m_resultCountArray[index] ? 0 : ((m_resultCountArray[index])*(*m_scaleFactor))) ); + QRect r(p1, p2); + painter->fillRect(r, QBrush(CSearchAnalysisScene::getColor(index)) ); + painter->drawRect(r); + drawn++; + } + } + //finds the next smaller value + int newValue = 0; + for (index = 0;index < m_moduleCount; index++) + if (m_resultCountArray[index] < Value && m_resultCountArray[index] >= newValue) + newValue = m_resultCountArray[index]; + Value = newValue; + } + if (!m_bufferPixmap) { + m_bufferPixmap = new QPixmap(width(), BAR_LOWER_BORDER); + //m_bufferPixmap->resize(width(),BAR_LOWER_BORDER); + m_bufferPixmap->fill(); + QPainter p(m_bufferPixmap); + f = p.font(); + f.setPointSize(ITEM_TEXT_SIZE); + p.setFont(f); + p.rotate(90); + p.drawText(QPoint(5, 0), m_bookName); + } + painter->drawPixmap(QPoint(int(rect().x()), int(rect().height() + y() - BAR_LOWER_BORDER)), *m_bufferPixmap); } /** Returns the width of this item. */ int CSearchAnalysisItem::width() { - return m_moduleCount*(m_moduleCount>1 ? BAR_DELTAX : 0) + BAR_WIDTH; + return m_moduleCount*(m_moduleCount > 1 ? BAR_DELTAX : 0) + BAR_WIDTH; } /** Returns the tooltip for this item. */ const QString CSearchAnalysisItem::getToolTip() { - QString toolTipString = QString("<center><b>%1</b></center><hr/>").arg(m_bookName); - toolTipString += "<table cellspacing=\"0\" cellpadding=\"3\" width=\"100%\" height=\"100%\" align=\"center\">"; - - //ToDo: Fix that loop - int i = 0; - QList<CSwordModuleInfo*>::iterator end_it = m_moduleList->end(); - - for (QList<CSwordModuleInfo*>::iterator it(m_moduleList->begin()); it != end_it; ++it) { - CSwordModuleInfo* info = (*it); - const QColor c = CSearchAnalysisScene::getColor(i); - - toolTipString.append( - QString("<tr bgcolor=\"white\"><td><b><font color=\"#%1\">%2</font></b></td><td>%3 (%4%)</td></tr>") - .arg(QString().sprintf("%02X%02X%02X",c.red(),c.green(),c.blue())) - .arg(info ? info->name() : QString::null) - .arg( m_resultCountArray[i] ) - .arg( (info && m_resultCountArray[i])? ((double)m_resultCountArray[i] / (double)info->searchResult().Count())*(double)100 : 0.0, 0, 'g', 2) - ); - ++i; - } - - toolTipString += "</table>"; - - return toolTipString; + QString toolTipString = QString("<center><b>%1</b></center><hr/>").arg(m_bookName); + toolTipString += "<table cellspacing=\"0\" cellpadding=\"3\" width=\"100%\" height=\"100%\" align=\"center\">"; + + //ToDo: Fix that loop + int i = 0; + QList<CSwordModuleInfo*>::iterator end_it = m_moduleList->end(); + + for (QList<CSwordModuleInfo*>::iterator it(m_moduleList->begin()); it != end_it; ++it) { + CSwordModuleInfo* info = (*it); + const QColor c = CSearchAnalysisScene::getColor(i); + + toolTipString.append( + QString("<tr bgcolor=\"white\"><td><b><font color=\"#%1\">%2</font></b></td><td>%3 (%4%)</td></tr>") + .arg(QString().sprintf("%02X%02X%02X", c.red(), c.green(), c.blue())) + .arg(info ? info->name() : QString::null) + .arg( m_resultCountArray[i] ) + .arg( (info && m_resultCountArray[i]) ? ((double)m_resultCountArray[i] / (double)info->searchResult().Count())*(double)100 : 0.0, 0, 'g', 2) + ); + ++i; + } + + toolTipString += "</table>"; + + return toolTipString; } } diff --git a/src/frontend/searchdialog/analysis/csearchanalysisitem.h b/src/frontend/searchdialog/analysis/csearchanalysisitem.h index 5926f43..30ba9a3 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisitem.h +++ b/src/frontend/searchdialog/analysis/csearchanalysisitem.h @@ -20,43 +20,42 @@ namespace Search { /** @author The BibleTime team <info@bibletime.info> */ -class CSearchAnalysisItem : public QGraphicsRectItem -{ -public: +class CSearchAnalysisItem : public QGraphicsRectItem { + public: - CSearchAnalysisItem(const int moduleCount, const QString& bookname, double *scaleFactor, QList<CSwordModuleInfo*>* modules); - ~CSearchAnalysisItem(); - /** - * Sets the resultcount of this item - */ - void setCountForModule( const int moduleIndex, const int count); + CSearchAnalysisItem(const int moduleCount, const QString& bookname, double *scaleFactor, QList<CSwordModuleInfo*>* modules); + ~CSearchAnalysisItem(); + /** + * Sets the resultcount of this item + */ + void setCountForModule( const int moduleIndex, const int count); - /** - * Returns the resultcount of this item - */ - int getCountForModule( const int moduleIndex); - /** - * Does one of the modules contain hits? - */ - bool hasHitsInAnyModule(); - /** - * Returns the width of this item. - */ - virtual int width(); - /** - * Returns the tooltip for this item. - */ - const QString getToolTip(); + /** + * Returns the resultcount of this item + */ + int getCountForModule( const int moduleIndex); + /** + * Does one of the modules contain hits? + */ + bool hasHitsInAnyModule(); + /** + * Returns the width of this item. + */ + virtual int width(); + /** + * Returns the tooltip for this item. + */ + const QString getToolTip(); -private: - virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*); + private: + virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*); - QList<CSwordModuleInfo*>* m_moduleList; - double *m_scaleFactor; - QString m_bookName; - int m_moduleCount; - QVector<int> m_resultCountArray; - QPixmap* m_bufferPixmap; + QList<CSwordModuleInfo*>* m_moduleList; + double *m_scaleFactor; + QString m_bookName; + int m_moduleCount; + QVector<int> m_resultCountArray; + QPixmap* m_bufferPixmap; }; diff --git a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp index 461e65a..cb25dab 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp +++ b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp @@ -40,44 +40,43 @@ const int LEGEND_WIDTH = 85; CSearchAnalysisLegendItem::CSearchAnalysisLegendItem(QList<CSwordModuleInfo*> *list ) - : QGraphicsRectItem() -{ - m_moduleList = list; + : QGraphicsRectItem() { + m_moduleList = list; } /** Reimplementation. Draws the content of this item. */ void CSearchAnalysisLegendItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) { - painter->save(); - - //the outer rectangle - QPoint p1( (int)(rect().x()), (int)(rect().y()) ); - QPoint p2( (int)(rect().x() + rect().width() ), (int)(rect().y() + rect().height())); - QRect r(p1, p2); - r = r.normalized(); - painter->drawRect(r); - - QFont f = painter->font(); - f.setPointSize(ITEM_TEXT_SIZE); - painter->setFont(f); - - // for (unsigned int index=0; index < m_moduleList->count(); index++){ - int moduleIndex = 0; - QList<CSwordModuleInfo*>::iterator end_it = m_moduleList->end(); - for (QList<CSwordModuleInfo*>::iterator it(m_moduleList->begin()); it != end_it; ++it) { - // the module color indicators - QPoint p1( (int)(rect().x()) + LEGEND_INNER_BORDER, (int)(rect().y()) + LEGEND_INNER_BORDER + moduleIndex*(LEGEND_DELTAY + ITEM_TEXT_SIZE) ); - QPoint p2(p1.x() + ITEM_TEXT_SIZE, p1.y() + ITEM_TEXT_SIZE); - QRect r(p1,p2); - painter->fillRect(r, QBrush(CSearchAnalysisScene::getColor(moduleIndex)) ); - r = r.normalized(); - painter->drawRect(r); - - QPoint p3( p2.x() + LEGEND_INNER_BORDER, p2.y() ); - painter->drawText(p3, (*it)->name() ); - - ++moduleIndex; - } - painter->restore(); + painter->save(); + + //the outer rectangle + QPoint p1( (int)(rect().x()), (int)(rect().y()) ); + QPoint p2( (int)(rect().x() + rect().width() ), (int)(rect().y() + rect().height())); + QRect r(p1, p2); + r = r.normalized(); + painter->drawRect(r); + + QFont f = painter->font(); + f.setPointSize(ITEM_TEXT_SIZE); + painter->setFont(f); + + // for (unsigned int index=0; index < m_moduleList->count(); index++){ + int moduleIndex = 0; + QList<CSwordModuleInfo*>::iterator end_it = m_moduleList->end(); + for (QList<CSwordModuleInfo*>::iterator it(m_moduleList->begin()); it != end_it; ++it) { + // the module color indicators + QPoint p1( (int)(rect().x()) + LEGEND_INNER_BORDER, (int)(rect().y()) + LEGEND_INNER_BORDER + moduleIndex*(LEGEND_DELTAY + ITEM_TEXT_SIZE) ); + QPoint p2(p1.x() + ITEM_TEXT_SIZE, p1.y() + ITEM_TEXT_SIZE); + QRect r(p1, p2); + painter->fillRect(r, QBrush(CSearchAnalysisScene::getColor(moduleIndex)) ); + r = r.normalized(); + painter->drawRect(r); + + QPoint p3( p2.x() + LEGEND_INNER_BORDER, p2.y() ); + painter->drawText(p3, (*it)->name() ); + + ++moduleIndex; + } + painter->restore(); } diff --git a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h index 879f239..a9eebc2 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h +++ b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h @@ -19,14 +19,13 @@ namespace Search { /** @author The BibleTime team <info@bibletime.info> */ -class CSearchAnalysisLegendItem : public QGraphicsRectItem -{ -public: - CSearchAnalysisLegendItem(QList<CSwordModuleInfo*>* list ); - -private: - virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*); - QList<CSwordModuleInfo*>* m_moduleList; +class CSearchAnalysisLegendItem : public QGraphicsRectItem { + public: + CSearchAnalysisLegendItem(QList<CSwordModuleInfo*>* list ); + + private: + virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*); + QList<CSwordModuleInfo*>* m_moduleList; }; diff --git a/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp b/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp index 7bc3ab2..ce093f7 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp +++ b/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp @@ -47,246 +47,243 @@ const int LEGEND_WIDTH = 85; CSearchAnalysisScene::CSearchAnalysisScene(QObject *parent ) - : QGraphicsScene(parent), - m_scaleFactor(0.0), - m_legend(0) -{ - setBackgroundBrush(QBrush(Qt::white)); - setSceneRect(0,0,1,1); + : QGraphicsScene(parent), + m_scaleFactor(0.0), + m_legend(0) { + setBackgroundBrush(QBrush(Qt::white)); + setSceneRect(0, 0, 1, 1); } QHash<QString, CSearchAnalysisItem*>* CSearchAnalysisScene::getSearchAnalysisItemList() { - // Returns pointer to the search analysis items - return &m_itemList; + // Returns pointer to the search analysis items + return &m_itemList; } /** Starts the analysis of the search result. This should be called only once because QCanvas handles the updates automatically. */ void CSearchAnalysisScene::analyse(QList<CSwordModuleInfo*> modules) { - /** - * Steps of analysing our search result; - * -Create the items for all available books ("Genesis" - "Revelation") - * -Iterate through all modules we analyse - * -Go through all books of this module - * -Find out how many times we found the book - * -Set the count to the items which belongs to the book - */ - setModules(modules); - - m_lastPosList.clear(); - const int numberOfModules = m_moduleList.count(); - if (!numberOfModules) - return; - m_legend = new CSearchAnalysisLegendItem(&m_moduleList); - addItem(m_legend); - m_legend->setRect(LEFT_BORDER, UPPER_BORDER, - LEGEND_WIDTH, LEGEND_INNER_BORDER*2 + ITEM_TEXT_SIZE*numberOfModules + LEGEND_DELTAY*(numberOfModules-1) ); - m_legend->show(); - - int xPos = (int)(LEFT_BORDER + m_legend->rect().width() + SPACE_BETWEEN_PARTS); - int moduleIndex = 0; - m_maxCount = 0; - int count = 0; - CSwordVerseKey key(0); - key.key("Genesis 1:1"); - - CSearchAnalysisItem* analysisItem = m_itemList[key.book()]; - bool ok = true; - while (ok && analysisItem) { - moduleIndex = 0; - QList<CSwordModuleInfo*>::iterator end_it = m_moduleList.end(); - for (QList<CSwordModuleInfo*>::iterator it(m_moduleList.begin()); it != end_it; ++it) { - qApp->processEvents( QEventLoop::AllEvents ); - if (!m_lastPosList.contains(*it)) { - m_lastPosList.insert(*it,0); - } - - analysisItem->setCountForModule(moduleIndex, (count = getCount(key.book(), *it))); - m_maxCount = (count > m_maxCount) ? count : m_maxCount; - - ++moduleIndex; - } - if (analysisItem->hasHitsInAnyModule()) - { - analysisItem->setRect(xPos, UPPER_BORDER, analysisItem->rect().width(), analysisItem->rect().height()); - QString tip = analysisItem->getToolTip(); - analysisItem->setToolTip(tip); - analysisItem->show(); - xPos += (int)analysisItem->width() + SPACE_BETWEEN_PARTS; - } - ok = key.next(CSwordVerseKey::UseBook); - analysisItem = m_itemList[key.book()]; - } - setSceneRect(0,0, xPos+BAR_WIDTH+(m_moduleList.count()-1)*BAR_DELTAX+RIGHT_BORDER, height() ); - slotResized(); + /** + * Steps of analysing our search result; + * -Create the items for all available books ("Genesis" - "Revelation") + * -Iterate through all modules we analyse + * -Go through all books of this module + * -Find out how many times we found the book + * -Set the count to the items which belongs to the book + */ + setModules(modules); + + m_lastPosList.clear(); + const int numberOfModules = m_moduleList.count(); + if (!numberOfModules) + return; + m_legend = new CSearchAnalysisLegendItem(&m_moduleList); + addItem(m_legend); + m_legend->setRect(LEFT_BORDER, UPPER_BORDER, + LEGEND_WIDTH, LEGEND_INNER_BORDER*2 + ITEM_TEXT_SIZE*numberOfModules + LEGEND_DELTAY*(numberOfModules - 1) ); + m_legend->show(); + + int xPos = (int)(LEFT_BORDER + m_legend->rect().width() + SPACE_BETWEEN_PARTS); + int moduleIndex = 0; + m_maxCount = 0; + int count = 0; + CSwordVerseKey key(0); + key.key("Genesis 1:1"); + + CSearchAnalysisItem* analysisItem = m_itemList[key.book()]; + bool ok = true; + while (ok && analysisItem) { + moduleIndex = 0; + QList<CSwordModuleInfo*>::iterator end_it = m_moduleList.end(); + for (QList<CSwordModuleInfo*>::iterator it(m_moduleList.begin()); it != end_it; ++it) { + qApp->processEvents( QEventLoop::AllEvents ); + if (!m_lastPosList.contains(*it)) { + m_lastPosList.insert(*it, 0); + } + + analysisItem->setCountForModule(moduleIndex, (count = getCount(key.book(), *it))); + m_maxCount = (count > m_maxCount) ? count : m_maxCount; + + ++moduleIndex; + } + if (analysisItem->hasHitsInAnyModule()) { + analysisItem->setRect(xPos, UPPER_BORDER, analysisItem->rect().width(), analysisItem->rect().height()); + QString tip = analysisItem->getToolTip(); + analysisItem->setToolTip(tip); + analysisItem->show(); + xPos += (int)analysisItem->width() + SPACE_BETWEEN_PARTS; + } + ok = key.next(CSwordVerseKey::UseBook); + analysisItem = m_itemList[key.book()]; + } + setSceneRect(0, 0, xPos + BAR_WIDTH + (m_moduleList.count() - 1)*BAR_DELTAX + RIGHT_BORDER, height() ); + slotResized(); } /** Sets the module list used for the analysis. */ void CSearchAnalysisScene::setModules(QList<CSwordModuleInfo*> modules) { - m_moduleList.clear(); - foreach (CSwordModuleInfo * mod, modules) { - if ( (mod->type() == CSwordModuleInfo::Bible) || (mod->type() == CSwordModuleInfo::Commentary) ) { //a Bible or an commentary - m_moduleList.append(mod); - } - } - - m_itemList.clear(); - CSearchAnalysisItem* analysisItem = 0; - CSwordVerseKey key(0); - key.key("Genesis 1:1"); - do { - analysisItem = new CSearchAnalysisItem(m_moduleList.count(), key.book(), &m_scaleFactor, &m_moduleList); - addItem(analysisItem); - analysisItem->hide(); - m_itemList.insert(key.book(), analysisItem); - } - while (key.next(CSwordVerseKey::UseBook)); - update(); + m_moduleList.clear(); + foreach (CSwordModuleInfo * mod, modules) { + if ( (mod->type() == CSwordModuleInfo::Bible) || (mod->type() == CSwordModuleInfo::Commentary) ) { //a Bible or an commentary + m_moduleList.append(mod); + } + } + + m_itemList.clear(); + CSearchAnalysisItem* analysisItem = 0; + CSwordVerseKey key(0); + key.key("Genesis 1:1"); + do { + analysisItem = new CSearchAnalysisItem(m_moduleList.count(), key.book(), &m_scaleFactor, &m_moduleList); + addItem(analysisItem); + analysisItem->hide(); + m_itemList.insert(key.book(), analysisItem); + } + while (key.next(CSwordVerseKey::UseBook)); + update(); } /** Sets back the items and deletes things to cleanup */ void CSearchAnalysisScene::reset() { - m_scaleFactor = 0.0; + m_scaleFactor = 0.0; - QHashIterator<QString, CSearchAnalysisItem*> it( m_itemList ); // iterator for items - while ( it.hasNext() ) { - it.next(); - if (it.value()) it.value()->hide(); - } - m_lastPosList.clear(); + QHashIterator<QString, CSearchAnalysisItem*> it( m_itemList ); // iterator for items + while ( it.hasNext() ) { + it.next(); + if (it.value()) it.value()->hide(); + } + m_lastPosList.clear(); - if (m_legend) m_legend->hide(); + if (m_legend) m_legend->hide(); - delete m_legend; - m_legend = 0; + delete m_legend; + m_legend = 0; - update(); + update(); } /** No descriptions */ void CSearchAnalysisScene::slotResized() { - m_scaleFactor = (double)( (double)(height()-UPPER_BORDER-LOWER_BORDER-BAR_LOWER_BORDER-100-(m_moduleList.count()-1)*BAR_DELTAY) - /(double)m_maxCount); - QHashIterator<QString, CSearchAnalysisItem*> it( m_itemList ); - while ( it.hasNext() ) { - it.next(); - if (it.value()) { - it.value()->setRect(it.value()->rect().x(), UPPER_BORDER, BAR_WIDTH + (m_moduleList.count()-1)*BAR_DELTAX, height()-LOWER_BORDER-BAR_LOWER_BORDER); - } - } - update(); + m_scaleFactor = (double)( (double)(height() - UPPER_BORDER - LOWER_BORDER - BAR_LOWER_BORDER - 100 - (m_moduleList.count() - 1) * BAR_DELTAY) + / (double)m_maxCount); + QHashIterator<QString, CSearchAnalysisItem*> it( m_itemList ); + while ( it.hasNext() ) { + it.next(); + if (it.value()) { + it.value()->setRect(it.value()->rect().x(), UPPER_BORDER, BAR_WIDTH + (m_moduleList.count() - 1)*BAR_DELTAX, height() - LOWER_BORDER - BAR_LOWER_BORDER); + } + } + update(); } /** This function returns a color for each module */ QColor CSearchAnalysisScene::getColor(int index) { - switch (index) { - case 0: - return Qt::red; - case 1: - return Qt::darkGreen; - case 2: - return Qt::blue; - case 3: - return Qt::cyan; - case 4: - return Qt::magenta; - case 5: - return Qt::darkRed; - case 6: - return Qt::darkGray; - case 7: - return Qt::black; - case 8: - return Qt::darkCyan; - case 9: - return Qt::darkMagenta; - default: - return Qt::red; - } + switch (index) { + case 0: + return Qt::red; + case 1: + return Qt::darkGreen; + case 2: + return Qt::blue; + case 3: + return Qt::cyan; + case 4: + return Qt::magenta; + case 5: + return Qt::darkRed; + case 6: + return Qt::darkGray; + case 7: + return Qt::black; + case 8: + return Qt::darkCyan; + case 9: + return Qt::darkMagenta; + default: + return Qt::red; + } } /** Returns the count of the book in the module */ unsigned int CSearchAnalysisScene::getCount( const QString book, CSwordModuleInfo* module ) { - sword::ListKey& result = module->searchResult(); - const int length = book.length(); - unsigned int i = m_lastPosList[module]; - unsigned int count = 0; - const unsigned int resultCount = result.Count(); - while (i < resultCount) { - if ( strncmp(book.toUtf8(), (const char*)*result.GetElement(i), length) ) - break; - i++; - ++count; - } - m_lastPosList.insert(module,i); - return count; + sword::ListKey& result = module->searchResult(); + const int length = book.length(); + unsigned int i = m_lastPosList[module]; + unsigned int count = 0; + const unsigned int resultCount = result.Count(); + while (i < resultCount) { + if ( strncmp(book.toUtf8(), (const char*)*result.GetElement(i), length) ) + break; + i++; + ++count; + } + m_lastPosList.insert(module, i); + return count; } void CSearchAnalysisScene::saveAsHTML() { - const QString fileName = QFileDialog::getSaveFileName(0, tr("Save Search Analysis"), QString::null, tr("HTML files (*.html;*.HTML;*.HTM;*.htm)") ); - if (fileName.isEmpty()) return; - - int count = 0; - QString countStr = ""; - QString m_searchAnalysisHTML = ""; - QString tableTitle = ""; - QString tableTotals = ""; - QString VerseRange = ""; - const QString txtCSS = QString("<style type=\"text/css\">\ntd {border:1px solid black;}\nth {font-size: 130%; text-align:left; vertical-align:top;}\n</style>\n"); - const QString metaEncoding = QString("<META http-equiv=Content-Type content=\"text/html; charset=utf-8\">"); - CSwordVerseKey key(0); - sword::ListKey searchResult; - - key.key("Genesis 1:1"); - - CSearchAnalysisItem* analysisItem = m_itemList.value( key.book() ); - - QString text = "<html>\n<head>\n<title>" + tr("BibleTime Search Analysis") + "</title>\n" + txtCSS + metaEncoding + "</head>\n<body>\n"; - text += "<table>\n<tr><th>" + tr("Search text :") + "</th><th>" + CSearchDialog::getSearchDialog()->searchText() + "</th></tr>\n"; - - tableTitle = "<tr><th align=\"left\">" + tr("Book") + "</th>"; - tableTotals = "<tr><td align=\"left\">" + tr("Total hits") + "</td>"; - - foreach (CSwordModuleInfo* mod, m_moduleList) { - tableTitle += QString("<th align=\"left\">") + mod->name() + QString("</th>"); - searchResult = mod->searchResult(); - countStr.setNum(searchResult.Count()); - - tableTotals += QString("<td align=\"right\">") + countStr + QString("</td>"); - } - tableTitle += QString("</tr>\n"); - tableTotals += QString("</tr>\n"); - - m_searchAnalysisHTML = ""; - bool ok = true; - while (ok) { - m_searchAnalysisHTML += QString("<tr><td>") + key.book() + QString("</td>"); - analysisItem = m_itemList.value( key.book() ); - - int moduleIndex = 0; - QList<CSwordModuleInfo*>::iterator end_it = m_moduleList.end(); - for (QList<CSwordModuleInfo*>::iterator it(m_moduleList.begin()); it != end_it; ++it) { - count = analysisItem->getCountForModule(moduleIndex); - countStr.setNum(count); - m_searchAnalysisHTML += QString("<td align=\"right\">") + countStr + QString("</td>"); - - ++moduleIndex; - } - m_searchAnalysisHTML += QString("</tr>\n"); - ok = key.next(CSwordVerseKey::UseBook); - } - - text += QString("<table>\n") + tableTitle + tableTotals + m_searchAnalysisHTML + QString("</table>\n"); - text += QString("<center>") + tr("Created by <a href=\"http://www.bibletime.info/\">BibleTime</a>") + QString("</center>"); - text += QString("</body></html>"); - - CToolClass::savePlainFile(fileName, text, false, QTextCodec::codecForName("UTF8")); + const QString fileName = QFileDialog::getSaveFileName(0, tr("Save Search Analysis"), QString::null, tr("HTML files (*.html;*.HTML;*.HTM;*.htm)") ); + if (fileName.isEmpty()) return; + + int count = 0; + QString countStr = ""; + QString m_searchAnalysisHTML = ""; + QString tableTitle = ""; + QString tableTotals = ""; + QString VerseRange = ""; + const QString txtCSS = QString("<style type=\"text/css\">\ntd {border:1px solid black;}\nth {font-size: 130%; text-align:left; vertical-align:top;}\n</style>\n"); + const QString metaEncoding = QString("<META http-equiv=Content-Type content=\"text/html; charset=utf-8\">"); + CSwordVerseKey key(0); + sword::ListKey searchResult; + + key.key("Genesis 1:1"); + + CSearchAnalysisItem* analysisItem = m_itemList.value( key.book() ); + + QString text = "<html>\n<head>\n<title>" + tr("BibleTime Search Analysis") + "</title>\n" + txtCSS + metaEncoding + "</head>\n<body>\n"; + text += "<table>\n<tr><th>" + tr("Search text :") + "</th><th>" + CSearchDialog::getSearchDialog()->searchText() + "</th></tr>\n"; + + tableTitle = "<tr><th align=\"left\">" + tr("Book") + "</th>"; + tableTotals = "<tr><td align=\"left\">" + tr("Total hits") + "</td>"; + + foreach (CSwordModuleInfo* mod, m_moduleList) { + tableTitle += QString("<th align=\"left\">") + mod->name() + QString("</th>"); + searchResult = mod->searchResult(); + countStr.setNum(searchResult.Count()); + + tableTotals += QString("<td align=\"right\">") + countStr + QString("</td>"); + } + tableTitle += QString("</tr>\n"); + tableTotals += QString("</tr>\n"); + + m_searchAnalysisHTML = ""; + bool ok = true; + while (ok) { + m_searchAnalysisHTML += QString("<tr><td>") + key.book() + QString("</td>"); + analysisItem = m_itemList.value( key.book() ); + + int moduleIndex = 0; + QList<CSwordModuleInfo*>::iterator end_it = m_moduleList.end(); + for (QList<CSwordModuleInfo*>::iterator it(m_moduleList.begin()); it != end_it; ++it) { + count = analysisItem->getCountForModule(moduleIndex); + countStr.setNum(count); + m_searchAnalysisHTML += QString("<td align=\"right\">") + countStr + QString("</td>"); + + ++moduleIndex; + } + m_searchAnalysisHTML += QString("</tr>\n"); + ok = key.next(CSwordVerseKey::UseBook); + } + + text += QString("<table>\n") + tableTitle + tableTotals + m_searchAnalysisHTML + QString("</table>\n"); + text += QString("<center>") + tr("Created by <a href=\"http://www.bibletime.info/\">BibleTime</a>") + QString("</center>"); + text += QString("</body></html>"); + + CToolClass::savePlainFile(fileName, text, false, QTextCodec::codecForName("UTF8")); } -void CSearchAnalysisScene::resizeHeight(int height) -{ - setSceneRect(0,0, sceneRect().width(), height); - slotResized(); +void CSearchAnalysisScene::resizeHeight(int height) { + setSceneRect(0, 0, sceneRect().width(), height); + slotResized(); } } diff --git a/src/frontend/searchdialog/analysis/csearchanalysisscene.h b/src/frontend/searchdialog/analysis/csearchanalysisscene.h index 755dacf..63abdb9 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisscene.h +++ b/src/frontend/searchdialog/analysis/csearchanalysisscene.h @@ -28,57 +28,57 @@ class CSearchAnalysisLegendItem; @author The BibleTime team <info@bibletime.info> */ class CSearchAnalysisScene : public QGraphicsScene { - Q_OBJECT -public: - CSearchAnalysisScene(QObject* parent); - - virtual ~CSearchAnalysisScene() {} - - /** - * Starts the analysis of the search result. - * This should be called only once because - * QCanvas handles the updates automatically. - */ - void analyse(QList<CSwordModuleInfo*> modules); - /** - * This function returns a color for each module - * @return The color at position index in the list - */ - static QColor getColor(int index); - /** - * This function returns a pointer to the list of AnalysisItems - */ - QHash<QString, CSearchAnalysisItem*>* getSearchAnalysisItemList(); - void reset(); - /** - * resize the height of the scene - */ - void resizeHeight(int height); - -public slots: - void saveAsHTML(); - -protected slots: // Protected slots - /** - * No descriptions - */ - void slotResized(); - -protected: - void setModules(QList<CSwordModuleInfo*> modules); - -private: - /** - * Returns the count of the book in the module - */ - unsigned int getCount( const QString book, CSwordModuleInfo* module ); - - QList<CSwordModuleInfo*> m_moduleList; - QHash<QString, CSearchAnalysisItem*> m_itemList; - QMap<CSwordModuleInfo*,unsigned int> m_lastPosList; - int m_maxCount; - double m_scaleFactor; - CSearchAnalysisLegendItem* m_legend; + Q_OBJECT + public: + CSearchAnalysisScene(QObject* parent); + + virtual ~CSearchAnalysisScene() {} + + /** + * Starts the analysis of the search result. + * This should be called only once because + * QCanvas handles the updates automatically. + */ + void analyse(QList<CSwordModuleInfo*> modules); + /** + * This function returns a color for each module + * @return The color at position index in the list + */ + static QColor getColor(int index); + /** + * This function returns a pointer to the list of AnalysisItems + */ + QHash<QString, CSearchAnalysisItem*>* getSearchAnalysisItemList(); + void reset(); + /** + * resize the height of the scene + */ + void resizeHeight(int height); + + public slots: + void saveAsHTML(); + + protected slots: // Protected slots + /** + * No descriptions + */ + void slotResized(); + + protected: + void setModules(QList<CSwordModuleInfo*> modules); + + private: + /** + * Returns the count of the book in the module + */ + unsigned int getCount( const QString book, CSwordModuleInfo* module ); + + QList<CSwordModuleInfo*> m_moduleList; + QHash<QString, CSearchAnalysisItem*> m_itemList; + QMap<CSwordModuleInfo*, unsigned int> m_lastPosList; + int m_maxCount; + double m_scaleFactor; + CSearchAnalysisLegendItem* m_legend; }; diff --git a/src/frontend/searchdialog/analysis/csearchanalysisview.cpp b/src/frontend/searchdialog/analysis/csearchanalysisview.cpp index 0d58c78..f43f133 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisview.cpp +++ b/src/frontend/searchdialog/analysis/csearchanalysisview.cpp @@ -18,23 +18,22 @@ namespace Search { CSearchAnalysisView::CSearchAnalysisView(CSearchAnalysisScene* scene, QWidget* parent) - : QGraphicsView(scene, parent) -{ - setFocusPolicy(Qt::WheelFocus); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - resize(sizeHint()); + : QGraphicsView(scene, parent) { + setFocusPolicy(Qt::WheelFocus); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + resize(sizeHint()); } /** Returns the sizeHint for this view */ QSize CSearchAnalysisView::sizeHint() const { - return QGraphicsView::sizeHint(); + return QGraphicsView::sizeHint(); } /** No descriptions */ void CSearchAnalysisView::resizeEvent( QResizeEvent* e) { - QGraphicsView::resizeEvent(e); - scene()->setSceneRect(0,0, scene()->sceneRect().width(), viewport()->height() ); + QGraphicsView::resizeEvent(e); + scene()->setSceneRect(0, 0, scene()->sceneRect().width(), viewport()->height() ); } diff --git a/src/frontend/searchdialog/analysis/csearchanalysisview.h b/src/frontend/searchdialog/analysis/csearchanalysisview.h index 35c4419..6b75dfa 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisview.h +++ b/src/frontend/searchdialog/analysis/csearchanalysisview.h @@ -22,30 +22,29 @@ class CSearchAnalysisScene; /** @author The BibleTime team <info@bibletime.info> */ -class CSearchAnalysisView : public QGraphicsView -{ -public: - CSearchAnalysisView(CSearchAnalysisScene* scene, QWidget* parent); - - ~CSearchAnalysisView() {} - -/** - * Returns the sizeHint for this view - * We give back the size of the parent widgetas default. - * This is a reimplementation from QCanvasView::sizeHint(). - */ - virtual QSize sizeHint() const; - - /** - * Returns the item at position p or 0 if there is no item. - */ - //CSearchAnalysisItem* itemAt( const QPoint& p ); - -protected: - /** - * Reimplementation. - */ - virtual void resizeEvent(QResizeEvent* e); +class CSearchAnalysisView : public QGraphicsView { + public: + CSearchAnalysisView(CSearchAnalysisScene* scene, QWidget* parent); + + ~CSearchAnalysisView() {} + + /** + * Returns the sizeHint for this view + * We give back the size of the parent widgetas default. + * This is a reimplementation from QCanvasView::sizeHint(). + */ + virtual QSize sizeHint() const; + + /** + * Returns the item at position p or 0 if there is no item. + */ + //CSearchAnalysisItem* itemAt( const QPoint& p ); + + protected: + /** + * Reimplementation. + */ + virtual void resizeEvent(QResizeEvent* e); }; diff --git a/src/frontend/searchdialog/btsearchoptionsarea.cpp b/src/frontend/searchdialog/btsearchoptionsarea.cpp index a4dbfd4..d6c3b4f 100644 --- a/src/frontend/searchdialog/btsearchoptionsarea.cpp +++ b/src/frontend/searchdialog/btsearchoptionsarea.cpp @@ -34,469 +34,461 @@ namespace Search { BtSearchOptionsArea::BtSearchOptionsArea(QWidget *parent ) - : QWidget(parent) -{ - initView(); - initConnections(); - readSettings(); + : QWidget(parent) { + initView(); + initConnections(); + readSettings(); } BtSearchOptionsArea::~BtSearchOptionsArea() { - saveSettings(); + saveSettings(); } QString BtSearchOptionsArea::searchText() const { - return m_searchTextCombo->currentText(); + return m_searchTextCombo->currentText(); } -BtSearchOptionsArea::SearchType BtSearchOptionsArea::searchType() -{ - if (m_typeAndButton->isChecked()) { - return BtSearchOptionsArea::AndType; - } - if (m_typeOrButton->isChecked()) { - return BtSearchOptionsArea::OrType; - } - return BtSearchOptionsArea::FullType; +BtSearchOptionsArea::SearchType BtSearchOptionsArea::searchType() { + if (m_typeAndButton->isChecked()) { + return BtSearchOptionsArea::AndType; + } + if (m_typeOrButton->isChecked()) { + return BtSearchOptionsArea::OrType; + } + return BtSearchOptionsArea::FullType; } QPushButton* BtSearchOptionsArea::searchButton() const { - return m_searchButton; + return m_searchButton; } void BtSearchOptionsArea::setSearchText(const QString& text) { - bool found = false; - int i = 0; - for (i = 0; !found && i < m_searchTextCombo->count(); ++i) { - if (m_searchTextCombo->itemText(i) == text) { - found = true; - } - } - // This is needed because in the for loop i is incremented before the comparison (++i) - // As a result the index i is actually one greater than expected. - i--; - if (!found) { - i = 0; - m_searchTextCombo->insertItem(0, text ); - } - - m_searchTextCombo->setCurrentIndex(i); - m_searchTextCombo->setFocus(); + bool found = false; + int i = 0; + for (i = 0; !found && i < m_searchTextCombo->count(); ++i) { + if (m_searchTextCombo->itemText(i) == text) { + found = true; + } + } + // This is needed because in the for loop i is incremented before the comparison (++i) + // As a result the index i is actually one greater than expected. + i--; + if (!found) { + i = 0; + m_searchTextCombo->insertItem(0, text ); + } + + m_searchTextCombo->setCurrentIndex(i); + m_searchTextCombo->setFocus(); } -void BtSearchOptionsArea::initView() -{ - QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - this->setSizePolicy(sizePolicy); - hboxLayout = new QHBoxLayout(this); +void BtSearchOptionsArea::initView() { + QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + this->setSizePolicy(sizePolicy); + hboxLayout = new QHBoxLayout(this); - searchGroupBox = new QGroupBox(this); + searchGroupBox = new QGroupBox(this); - gridLayout = new QGridLayout(searchGroupBox); + gridLayout = new QGridLayout(searchGroupBox); - gridLayout->setHorizontalSpacing(3); + gridLayout->setHorizontalSpacing(3); - // ******** label for search text editor*********** + // ******** label for search text editor*********** m_searchTextLabel = new QLabel(tr("Search for:"), searchGroupBox); - m_searchTextLabel->setWordWrap(false); - gridLayout->addWidget(m_searchTextLabel, 0, 0); - - // **********Buttons****************** - - m_searchButton = new QPushButton(this); - m_searchButton->setText(tr("&Search")); - m_searchButton->setIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::icon)); - m_searchButton->setToolTip(tr("Start to search the text in the chosen works")); - gridLayout->addWidget(m_searchButton, 0, 2); - - m_chooseModulesButton = new QPushButton(tr("Ch&oose..."), searchGroupBox); - m_chooseModulesButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::chooseworks_icon)); - m_chooseModulesButton->setToolTip( tr("Choose works for the search")); - gridLayout->addWidget(m_chooseModulesButton, 2, 2); - - m_chooseRangeButton = new QPushButton(tr("S&etup..."), searchGroupBox); - m_chooseRangeButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::setupscope_icon)); - m_chooseRangeButton->setToolTip(tr("Configure predefined scopes for search")); - gridLayout->addWidget(m_chooseRangeButton, 3, 2); - - // ************* Search type (AND/OR) selector *************************************** - QHBoxLayout* typeSelectorLayout = new QHBoxLayout(); - int tsLeft, tsTop, tsRight, tsBottom; - // Added space looks nicer and enhances readability - typeSelectorLayout->getContentsMargins(&tsLeft, &tsTop, &tsRight, &tsBottom); - typeSelectorLayout->setContentsMargins(tsLeft, 0, tsRight, tsBottom + CToolClass::mWidth(this,1) ); - typeSelectorLayout->setSpacing(typeSelectorLayout->spacing()+CToolClass::mWidth(this,1)); - QHBoxLayout* fullButtonLayout = new QHBoxLayout(); - fullButtonLayout->setSpacing(CToolClass::mWidth(this,1)/2); - m_typeAndButton = new QRadioButton(tr("All words")); - m_typeAndButton->setChecked(true); - m_typeOrButton = new QRadioButton(tr("Some words")); - m_typeFreeButton = new QRadioButton(tr("Free")); - - m_typeAndButton->setToolTip(tr("All of the words (AND is added between the words)")); - m_typeOrButton->setToolTip(tr("Some of the words (OR is added between the words)")); - m_typeFreeButton->setToolTip(tr("Full lucene syntax")); - - m_helpLabel = new QLabel(tr(" (<a href='syntax_help'>full syntax</a>)")); - m_helpLabel->setToolTip(tr("Click the link to get help for search syntax")); - - typeSelectorLayout->addWidget(m_typeAndButton); - typeSelectorLayout->addWidget(m_typeOrButton); - fullButtonLayout->addWidget(m_typeFreeButton); - fullButtonLayout->addWidget(m_helpLabel); - typeSelectorLayout->addLayout(fullButtonLayout); - gridLayout->addLayout(typeSelectorLayout, 1,1, 1,-1, Qt::AlignLeft|Qt::AlignTop); - - // ************* Label for search range/scope selector ************* - m_searchScopeLabel = new QLabel(tr("Scope:"), searchGroupBox); - m_searchScopeLabel->setWordWrap(false); - gridLayout->addWidget(m_searchScopeLabel, 3, 0); - - // ***********Range/scope selector combo box*********** - m_rangeChooserCombo = new QComboBox(searchGroupBox); - QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Fixed); - sizePolicy2.setHorizontalStretch(0); - sizePolicy2.setVerticalStretch(0); - sizePolicy2.setHeightForWidth(m_rangeChooserCombo->sizePolicy().hasHeightForWidth()); - m_rangeChooserCombo->setSizePolicy(sizePolicy2); - m_rangeChooserCombo->setToolTip(tr("Choose the scope (books/chapters/verses to search in).<br />Applicable for Bibles and commentaries.")); - gridLayout->addWidget(m_rangeChooserCombo, 3, 1); - - // ************* Search text combo box ******************* - m_searchTextCombo = new CHistoryComboBox(searchGroupBox); - sizePolicy2.setHeightForWidth(m_searchTextCombo->sizePolicy().hasHeightForWidth()); - m_searchTextCombo->setSizePolicy(sizePolicy2); - m_searchTextCombo->setFocusPolicy(Qt::WheelFocus); - m_searchTextCombo->setProperty("sizeLimit", QVariant(25)); - m_searchTextCombo->setProperty("duplicatesEnabled", QVariant(false)); - m_searchTextCombo->setToolTip(tr("The text you want to search for")); - m_searchTextCombo->setInsertPolicy(QComboBox::NoInsert); - gridLayout->addWidget(m_searchTextCombo, 0, 1); - - m_modulesLabel = new QLabel(tr("Works:"), searchGroupBox); - gridLayout->addWidget(m_modulesLabel, 2, 0); - - m_modulesCombo = new QComboBox(searchGroupBox); - m_modulesCombo->setDuplicatesEnabled(false); - gridLayout->addWidget(m_modulesCombo, 2, 1); - - hboxLayout->addWidget(searchGroupBox); - - // Set the minimum size before the widgets are populated with data. - // Otherwise we will get problems with sizing. - setMinimumSize(minimumSizeHint()); - - refreshRanges(); - //set the initial focus - m_searchTextCombo->setFocus(); - // event filter to prevent the Return/Enter presses in the combo box doing something - // in the parent widget - m_searchTextCombo->installEventFilter(this); + m_searchTextLabel->setWordWrap(false); + gridLayout->addWidget(m_searchTextLabel, 0, 0); + + // **********Buttons****************** + + m_searchButton = new QPushButton(this); + m_searchButton->setText(tr("&Search")); + m_searchButton->setIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::icon)); + m_searchButton->setToolTip(tr("Start to search the text in the chosen works")); + gridLayout->addWidget(m_searchButton, 0, 2); + + m_chooseModulesButton = new QPushButton(tr("Ch&oose..."), searchGroupBox); + m_chooseModulesButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::chooseworks_icon)); + m_chooseModulesButton->setToolTip( tr("Choose works for the search")); + gridLayout->addWidget(m_chooseModulesButton, 2, 2); + + m_chooseRangeButton = new QPushButton(tr("S&etup..."), searchGroupBox); + m_chooseRangeButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::setupscope_icon)); + m_chooseRangeButton->setToolTip(tr("Configure predefined scopes for search")); + gridLayout->addWidget(m_chooseRangeButton, 3, 2); + + // ************* Search type (AND/OR) selector *************************************** + QHBoxLayout* typeSelectorLayout = new QHBoxLayout(); + int tsLeft, tsTop, tsRight, tsBottom; + // Added space looks nicer and enhances readability + typeSelectorLayout->getContentsMargins(&tsLeft, &tsTop, &tsRight, &tsBottom); + typeSelectorLayout->setContentsMargins(tsLeft, 0, tsRight, tsBottom + CToolClass::mWidth(this, 1) ); + typeSelectorLayout->setSpacing(typeSelectorLayout->spacing() + CToolClass::mWidth(this, 1)); + QHBoxLayout* fullButtonLayout = new QHBoxLayout(); + fullButtonLayout->setSpacing(CToolClass::mWidth(this, 1) / 2); + m_typeAndButton = new QRadioButton(tr("All words")); + m_typeAndButton->setChecked(true); + m_typeOrButton = new QRadioButton(tr("Some words")); + m_typeFreeButton = new QRadioButton(tr("Free")); + + m_typeAndButton->setToolTip(tr("All of the words (AND is added between the words)")); + m_typeOrButton->setToolTip(tr("Some of the words (OR is added between the words)")); + m_typeFreeButton->setToolTip(tr("Full lucene syntax")); + + m_helpLabel = new QLabel(tr(" (<a href='syntax_help'>full syntax</a>)")); + m_helpLabel->setToolTip(tr("Click the link to get help for search syntax")); + + typeSelectorLayout->addWidget(m_typeAndButton); + typeSelectorLayout->addWidget(m_typeOrButton); + fullButtonLayout->addWidget(m_typeFreeButton); + fullButtonLayout->addWidget(m_helpLabel); + typeSelectorLayout->addLayout(fullButtonLayout); + gridLayout->addLayout(typeSelectorLayout, 1, 1, 1, -1, Qt::AlignLeft | Qt::AlignTop); + + // ************* Label for search range/scope selector ************* + m_searchScopeLabel = new QLabel(tr("Scope:"), searchGroupBox); + m_searchScopeLabel->setWordWrap(false); + gridLayout->addWidget(m_searchScopeLabel, 3, 0); + + // ***********Range/scope selector combo box*********** + m_rangeChooserCombo = new QComboBox(searchGroupBox); + QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Fixed); + sizePolicy2.setHorizontalStretch(0); + sizePolicy2.setVerticalStretch(0); + sizePolicy2.setHeightForWidth(m_rangeChooserCombo->sizePolicy().hasHeightForWidth()); + m_rangeChooserCombo->setSizePolicy(sizePolicy2); + m_rangeChooserCombo->setToolTip(tr("Choose the scope (books/chapters/verses to search in).<br />Applicable for Bibles and commentaries.")); + gridLayout->addWidget(m_rangeChooserCombo, 3, 1); + + // ************* Search text combo box ******************* + m_searchTextCombo = new CHistoryComboBox(searchGroupBox); + sizePolicy2.setHeightForWidth(m_searchTextCombo->sizePolicy().hasHeightForWidth()); + m_searchTextCombo->setSizePolicy(sizePolicy2); + m_searchTextCombo->setFocusPolicy(Qt::WheelFocus); + m_searchTextCombo->setProperty("sizeLimit", QVariant(25)); + m_searchTextCombo->setProperty("duplicatesEnabled", QVariant(false)); + m_searchTextCombo->setToolTip(tr("The text you want to search for")); + m_searchTextCombo->setInsertPolicy(QComboBox::NoInsert); + gridLayout->addWidget(m_searchTextCombo, 0, 1); + + m_modulesLabel = new QLabel(tr("Works:"), searchGroupBox); + gridLayout->addWidget(m_modulesLabel, 2, 0); + + m_modulesCombo = new QComboBox(searchGroupBox); + m_modulesCombo->setDuplicatesEnabled(false); + gridLayout->addWidget(m_modulesCombo, 2, 1); + + hboxLayout->addWidget(searchGroupBox); + + // Set the minimum size before the widgets are populated with data. + // Otherwise we will get problems with sizing. + setMinimumSize(minimumSizeHint()); + + refreshRanges(); + //set the initial focus + m_searchTextCombo->setFocus(); + // event filter to prevent the Return/Enter presses in the combo box doing something + // in the parent widget + m_searchTextCombo->installEventFilter(this); } -void BtSearchOptionsArea::initConnections() -{ - QObject::connect( m_searchTextCombo->lineEdit(), SIGNAL(returnPressed ()), - this, SLOT( slotSearchTextEditReturnPressed() ) - ); - connect(m_chooseModulesButton, SIGNAL(clicked()), this, SLOT(chooseModules())); - connect(m_chooseRangeButton, SIGNAL(clicked()), this, SLOT(setupRanges())); - connect(m_modulesCombo, SIGNAL(activated(int)), this, SLOT(moduleListTextSelected(int) ) ); - connect(m_helpLabel, SIGNAL(linkActivated(QString)), this, SLOT(syntaxHelp())); - connect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&))); +void BtSearchOptionsArea::initConnections() { + QObject::connect( m_searchTextCombo->lineEdit(), SIGNAL(returnPressed ()), + this, SLOT( slotSearchTextEditReturnPressed() ) + ); + connect(m_chooseModulesButton, SIGNAL(clicked()), this, SLOT(chooseModules())); + connect(m_chooseRangeButton, SIGNAL(clicked()), this, SLOT(setupRanges())); + connect(m_modulesCombo, SIGNAL(activated(int)), this, SLOT(moduleListTextSelected(int) ) ); + connect(m_helpLabel, SIGNAL(linkActivated(QString)), this, SLOT(syntaxHelp())); + connect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&))); } /** Sets the modules used by the search. */ -void BtSearchOptionsArea::setModules( QList<CSwordModuleInfo*> modules ) -{ - qDebug("BtSearchOptionsArea::setModules"); - qDebug() << modules; - QString t; - - m_modules.clear(); //remove old modules - QList<CSwordModuleInfo*>::iterator end_it = modules.end(); - - for (QList<CSwordModuleInfo*>::iterator it(modules.begin()); it != end_it; ++it) { - //ToDo: Check for containsRef compat - if (*it == 0) { //don't operate on null modules. - continue; - } - qDebug() << "new module:" << (*it)->name(); - if ( !m_modules.contains(*it) ) { - m_modules.append( *it ); - t.append( (*it)->name() ); - if (*it != modules.last()) { - t += QString::fromLatin1(", "); // so that it will become a readable list (WLC, LXX, GerLut...) - } - } - }; - //m_modulesLabel->setText(t); - int existingIndex = m_modulesCombo->findText(t); - qDebug() << "index of the module list string which already exists in combobox:" << existingIndex; - if (existingIndex >= 0) { - m_modulesCombo->removeItem(existingIndex); - } - if (m_modulesCombo->count() > 10) { - m_modulesCombo->removeItem(m_modulesCombo->count()-1); - } - m_modulesCombo->insertItem(0, t); - m_modulesCombo->setItemData(0, t, Qt::ToolTipRole); - m_modulesCombo->setCurrentIndex(0); - m_modulesCombo->setToolTip(t); - //Save the list in config here, not when deleting, because the history may be used - // elsewhere while the dialog is still open - QStringList historyList; - for (int i = 0; i < m_modulesCombo->count(); ++i) { - historyList.append(m_modulesCombo->itemText(i)); - } - CBTConfig::set(CBTConfig::searchModulesHistory, historyList); - emit( sigSetSearchButtonStatus( (modules.count() != 0) ) ); +void BtSearchOptionsArea::setModules( QList<CSwordModuleInfo*> modules ) { + qDebug("BtSearchOptionsArea::setModules"); + qDebug() << modules; + QString t; + + m_modules.clear(); //remove old modules + QList<CSwordModuleInfo*>::iterator end_it = modules.end(); + + for (QList<CSwordModuleInfo*>::iterator it(modules.begin()); it != end_it; ++it) { + //ToDo: Check for containsRef compat + if (*it == 0) { //don't operate on null modules. + continue; + } + qDebug() << "new module:" << (*it)->name(); + if ( !m_modules.contains(*it) ) { + m_modules.append( *it ); + t.append( (*it)->name() ); + if (*it != modules.last()) { + t += QString::fromLatin1(", "); // so that it will become a readable list (WLC, LXX, GerLut...) + } + } + }; + //m_modulesLabel->setText(t); + int existingIndex = m_modulesCombo->findText(t); + qDebug() << "index of the module list string which already exists in combobox:" << existingIndex; + if (existingIndex >= 0) { + m_modulesCombo->removeItem(existingIndex); + } + if (m_modulesCombo->count() > 10) { + m_modulesCombo->removeItem(m_modulesCombo->count() - 1); + } + m_modulesCombo->insertItem(0, t); + m_modulesCombo->setItemData(0, t, Qt::ToolTipRole); + m_modulesCombo->setCurrentIndex(0); + m_modulesCombo->setToolTip(t); + //Save the list in config here, not when deleting, because the history may be used + // elsewhere while the dialog is still open + QStringList historyList; + for (int i = 0; i < m_modulesCombo->count(); ++i) { + historyList.append(m_modulesCombo->itemText(i)); + } + CBTConfig::set(CBTConfig::searchModulesHistory, historyList); + emit( sigSetSearchButtonStatus( (modules.count() != 0) ) ); } // Catch activated signal of module selector combobox -void BtSearchOptionsArea::moduleListTextSelected(int index) -{ - qDebug("BtSearchOptionsArea::moduleListTextSelected"); - //create the module list - QString text = m_modulesCombo->itemText(index); - qDebug() << text; - QStringList moduleNamesList = text.split(", "); - QList<CSwordModuleInfo*> moduleList; - foreach(QString name, moduleNamesList) { - moduleList.append(CPointers::backend()->findModuleByName(name)); - } - //set the list and the combobox list and text - setModules(moduleList); +void BtSearchOptionsArea::moduleListTextSelected(int index) { + qDebug("BtSearchOptionsArea::moduleListTextSelected"); + //create the module list + QString text = m_modulesCombo->itemText(index); + qDebug() << text; + QStringList moduleNamesList = text.split(", "); + QList<CSwordModuleInfo*> moduleList; + foreach(QString name, moduleNamesList) { + moduleList.append(CPointers::backend()->findModuleByName(name)); + } + //set the list and the combobox list and text + setModules(moduleList); } void BtSearchOptionsArea::chooseModules() { - QString title(tr("Works to Search in")); - QString label(tr("Select the works which should be searched.")); - CSearchModuleChooserDialog* dlg = new CSearchModuleChooserDialog(this, title, label, modules()); - connect(dlg, SIGNAL(modulesChanged(QList<CSwordModuleInfo*>, QTreeWidget*)), this, SLOT(setModules(QList<CSwordModuleInfo*>))); - dlg->exec(); + QString title(tr("Works to Search in")); + QString label(tr("Select the works which should be searched.")); + CSearchModuleChooserDialog* dlg = new CSearchModuleChooserDialog(this, title, label, modules()); + connect(dlg, SIGNAL(modulesChanged(QList<CSwordModuleInfo*>, QTreeWidget*)), this, SLOT(setModules(QList<CSwordModuleInfo*>))); + dlg->exec(); } QList<CSwordModuleInfo*> BtSearchOptionsArea::modules() const { - return m_modules; + return m_modules; } void BtSearchOptionsArea::reset() { - m_rangeChooserCombo->setCurrentIndex(0); - m_searchTextCombo->clearEditText(); + m_rangeChooserCombo->setCurrentIndex(0); + m_searchTextCombo->clearEditText(); } void BtSearchOptionsArea::saveSettings() { - CBTConfig::set(CBTConfig::searchTexts, m_searchTextCombo->historyItems()); - SearchType t = FullType; - if (m_typeAndButton->isChecked()) { - t = AndType; - } - if (m_typeOrButton->isChecked()) { - t = OrType; - } - CBTConfig::set(CBTConfig::searchType, t); + CBTConfig::set(CBTConfig::searchTexts, m_searchTextCombo->historyItems()); + SearchType t = FullType; + if (m_typeAndButton->isChecked()) { + t = AndType; + } + if (m_typeOrButton->isChecked()) { + t = OrType; + } + CBTConfig::set(CBTConfig::searchType, t); } void BtSearchOptionsArea::readSettings() { - QStringList texts = CBTConfig::get(CBTConfig::searchTexts); - //for some reason the slot was called when setting the upmost item - disconnect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&))); - for (int i=0; i<texts.size(); i++) - { - if (texts.at(i).size() > 0) - m_searchTextCombo->addItem(texts.at(i)); - } - connect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&))); - - m_modulesCombo->insertItems(0, CBTConfig::get(CBTConfig::searchModulesHistory)); - for (int i = 0; i < m_modulesCombo->count(); ++i) { - m_modulesCombo->setItemData(i, m_modulesCombo->itemText(i), Qt::ToolTipRole); - } - - int stype = CBTConfig::get(CBTConfig::searchType); - switch (stype) { - case AndType: m_typeAndButton->setChecked(true); - break; - case OrType: m_typeOrButton->setChecked(true); - break; - default: m_typeFreeButton->setChecked(true); - } + QStringList texts = CBTConfig::get(CBTConfig::searchTexts); + //for some reason the slot was called when setting the upmost item + disconnect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&))); + for (int i = 0; i < texts.size(); i++) { + if (texts.at(i).size() > 0) + m_searchTextCombo->addItem(texts.at(i)); + } + connect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&))); + + m_modulesCombo->insertItems(0, CBTConfig::get(CBTConfig::searchModulesHistory)); + for (int i = 0; i < m_modulesCombo->count(); ++i) { + m_modulesCombo->setItemData(i, m_modulesCombo->itemText(i), Qt::ToolTipRole); + } + + int stype = CBTConfig::get(CBTConfig::searchType); + switch (stype) { + case AndType: + m_typeAndButton->setChecked(true); + break; + case OrType: + m_typeOrButton->setChecked(true); + break; + default: + m_typeFreeButton->setChecked(true); + } } void BtSearchOptionsArea::aboutToShow() { - m_searchTextCombo->setFocus(); + m_searchTextCombo->setFocus(); } void BtSearchOptionsArea::setupRanges() { - CRangeChooserDialog* chooser = new CRangeChooserDialog(this); - chooser->exec(); + CRangeChooserDialog* chooser = new CRangeChooserDialog(this); + chooser->exec(); - refreshRanges(); + refreshRanges(); } void BtSearchOptionsArea::syntaxHelp() { - QString style = QString( - "<style type='text/css'>" - "h1 a {font-size: medium}" - "table {margin-left: 20px}" - "td {" - " border-width: 3px 3px 3px 3px;" - " border-style: solid solid solid solid;" - " border-color: white white white white;" - " background-color: #faf0e6;" - "}" - "p#links {margin-left: 20px}" - "</style>"); - - //: Don't translate words inside <> tags! - //: Translate 'All words' etc. indentically to the Search dialog options. - QString intro = tr( - "<p>" - "This help is mainly for 'Full syntax' option. 'All words' and 'Some words' options " "have more limited syntax; <a href='#wildcards'>wildcards</a> and <a " "href='#fields'>text fields</a> are supported for them. Some other syntax features " "may give strange or wrong results with All words/Some words." - "</p>"); - - QString links = tr( - "<p id='links'>" - "<A href='#allsome'>Which words to find</A><br />" - "<A href='#grouping'>Grouping and order</A><br />" - "<A href='#wildcards'>Wildcards (partial words)</A><br />" - "<A href='#fields'>Text fields (different parts of text)</A><br/>" - "<A href='#lucene'>Other syntax features</A><br/>" - "</p>"); - - //: Syntax words (AND, OR...) must not be translated. - QString whichwords = tr( - "<h1><A name='allsome'>Which words to find</A></h1>" - "<p>Search terms are separated by spaces. <strong>AND</strong> (all words), " "<strong>OR</strong> (some words) and <strong>NOT</strong> (not the following word) " "can be added between the words. If none is added explicitly OR is used " "automatically. '<strong>+</strong>word' means the word must be in the results, " "'<strong>-</strong>word' means it must not be in the results.</p>"); - - //: In examples words to be searched for may be translated, but syntax words (AND, OR...) must not be translated. - QString whichwordstable = tr( - "<p><table><tr>" - "<td>jesus AND god</td><td>Finds verses with both 'Jesus' and 'God'</td>" - "</tr><tr>" - "<td>jesus OR god</td><td>Finds verses with 'Jesus' or 'God' or both</td>" - "</tr><tr>" - "<td>jesus NOT god</td><td>Finds verses with 'Jesus' but with no 'God'</td>" - "</tr><tr>" - "<td>+jesus -god</td><td>Finds verses with 'Jesus' but with no 'God'</td>" - "</tr></table></p>"); - - QString grouping = tr( - "<h1><A name='grouping'>Grouping and order</A></h1>" - "<p>Words can be grouped with <strong>parenthesis</strong>. " - "Strict word order can be defined with <strong>quotes</strong>.</p>"); - - QString groupingtable = tr( - "<p><table><tr>" - "<td>(a AND b) OR c</td><td>Finds verses with both 'a' AND 'b', and verses with 'c'</td>" - "</tr><tr>" - "<td>\"says lord\"</td><td>Finds e.g. '...Isaiah says, \"Lord...' but not '...says the LORD'</td>" - "</tr><tr>" - "<td>\"says the lord\"</td><td>Finds all verses with 'says the LORD'</td>" - "</tr></table></p>"); - - QString wildcards = tr( - "<h1><A name='wildcards'>Wildcards (partial words)</A></h1>" - "<p>'<strong>*</strong>' matches any sequence of 0 or more characters, while '<strong>?</strong>' matches any single character. A wildcard can not be used in the beginning of a word.</p>"); - - QString wildcardstable = tr( - "<p><table><tr>" - "<td>a*</td><td>All words beginning with 'a'</td>" - "</tr><tr>" - "<td>a*a</td><td>'Assyria', 'aroma', 'abba' etc.</td>" - "</tr><tr>" - "<td>a?</td><td>'at' and 'an'</td>" - "</tr><tr>" - "<td>a??a</td><td>'abba', 'area', 'Asia' etc.</td>" - "</tr></table></p>"); - - QString fields = tr( - "<h1><A name='fields'>Text fields (different parts of text)</A></h1>" - "<p>Available text fields:<br /><table>" - "<tr><td>heading:</td><td>Searches headings</td></tr>" - "<tr><td>footnote:</td><td>Searches footnotes</td></tr>" - "<tr><td>strong:</td><td>Searches Strong's numbers</td></tr>" - "<tr><td>morph:</td><td>Searches morphology codes</td></tr></table></p>"); - - QString fieldstable = tr( - "<p>Examples:<br /><table>" - "<tr><td>heading:Jesus</td><td>Finds headings with 'Jesus'</td></tr>" - "<tr><td>footnote:Jesus AND footnote:said</td><td>Finds footnotes with 'Jesus' and 'said'</td></tr>" - "<tr><td>strong:G846</td><td>Finds verses with Strong's Greek number 846</td></tr>" - "<tr><td>morph:\"N-NSF\"</td><td>Finds verses with morphology code 'N-NSF'</td>" - "</tr></table></p>"); - - QString lucene = tr( - "<h1><A name='lucene'>Other syntax features</A></h1>" - "<p>BibleTime uses the CLucene search engine. You can read more on the <a href='http://lucene.apache.org/java/1_4_3/queryparsersyntax.html'>lucene syntax web page</a> (in external browser).</p>"); - - QString syntax = style + intro + links + whichwords + whichwordstable + - grouping + groupingtable + wildcards + wildcardstable + - fields + fieldstable + lucene; - - BtTabHtmlDialog* dlg = new BtTabHtmlDialog(tr("Search Syntax Help"), 0, this); - dlg->setHtml(syntax); - dlg->show(); + QString style = QString( + "<style type='text/css'>" + "h1 a {font-size: medium}" + "table {margin-left: 20px}" + "td {" + " border-width: 3px 3px 3px 3px;" + " border-style: solid solid solid solid;" + " border-color: white white white white;" + " background-color: #faf0e6;" + "}" + "p#links {margin-left: 20px}" + "</style>"); + + //: Don't translate words inside <> tags! + //: Translate 'All words' etc. indentically to the Search dialog options. + QString intro = tr( + "<p>" + "This help is mainly for 'Full syntax' option. 'All words' and 'Some words' options " "have more limited syntax; <a href='#wildcards'>wildcards</a> and <a " "href='#fields'>text fields</a> are supported for them. Some other syntax features " "may give strange or wrong results with All words/Some words." + "</p>"); + + QString links = tr( + "<p id='links'>" + "<A href='#allsome'>Which words to find</A><br />" + "<A href='#grouping'>Grouping and order</A><br />" + "<A href='#wildcards'>Wildcards (partial words)</A><br />" + "<A href='#fields'>Text fields (different parts of text)</A><br/>" + "<A href='#lucene'>Other syntax features</A><br/>" + "</p>"); + + //: Syntax words (AND, OR...) must not be translated. + QString whichwords = tr( + "<h1><A name='allsome'>Which words to find</A></h1>" + "<p>Search terms are separated by spaces. <strong>AND</strong> (all words), " "<strong>OR</strong> (some words) and <strong>NOT</strong> (not the following word) " "can be added between the words. If none is added explicitly OR is used " "automatically. '<strong>+</strong>word' means the word must be in the results, " "'<strong>-</strong>word' means it must not be in the results.</p>"); + + //: In examples words to be searched for may be translated, but syntax words (AND, OR...) must not be translated. + QString whichwordstable = tr( + "<p><table><tr>" + "<td>jesus AND god</td><td>Finds verses with both 'Jesus' and 'God'</td>" + "</tr><tr>" + "<td>jesus OR god</td><td>Finds verses with 'Jesus' or 'God' or both</td>" + "</tr><tr>" + "<td>jesus NOT god</td><td>Finds verses with 'Jesus' but with no 'God'</td>" + "</tr><tr>" + "<td>+jesus -god</td><td>Finds verses with 'Jesus' but with no 'God'</td>" + "</tr></table></p>"); + + QString grouping = tr( + "<h1><A name='grouping'>Grouping and order</A></h1>" + "<p>Words can be grouped with <strong>parenthesis</strong>. " + "Strict word order can be defined with <strong>quotes</strong>.</p>"); + + QString groupingtable = tr( + "<p><table><tr>" + "<td>(a AND b) OR c</td><td>Finds verses with both 'a' AND 'b', and verses with 'c'</td>" + "</tr><tr>" + "<td>\"says lord\"</td><td>Finds e.g. '...Isaiah says, \"Lord...' but not '...says the LORD'</td>" + "</tr><tr>" + "<td>\"says the lord\"</td><td>Finds all verses with 'says the LORD'</td>" + "</tr></table></p>"); + + QString wildcards = tr( + "<h1><A name='wildcards'>Wildcards (partial words)</A></h1>" + "<p>'<strong>*</strong>' matches any sequence of 0 or more characters, while '<strong>?</strong>' matches any single character. A wildcard can not be used in the beginning of a word.</p>"); + + QString wildcardstable = tr( + "<p><table><tr>" + "<td>a*</td><td>All words beginning with 'a'</td>" + "</tr><tr>" + "<td>a*a</td><td>'Assyria', 'aroma', 'abba' etc.</td>" + "</tr><tr>" + "<td>a?</td><td>'at' and 'an'</td>" + "</tr><tr>" + "<td>a??a</td><td>'abba', 'area', 'Asia' etc.</td>" + "</tr></table></p>"); + + QString fields = tr( + "<h1><A name='fields'>Text fields (different parts of text)</A></h1>" + "<p>Available text fields:<br /><table>" + "<tr><td>heading:</td><td>Searches headings</td></tr>" + "<tr><td>footnote:</td><td>Searches footnotes</td></tr>" + "<tr><td>strong:</td><td>Searches Strong's numbers</td></tr>" + "<tr><td>morph:</td><td>Searches morphology codes</td></tr></table></p>"); + + QString fieldstable = tr( + "<p>Examples:<br /><table>" + "<tr><td>heading:Jesus</td><td>Finds headings with 'Jesus'</td></tr>" + "<tr><td>footnote:Jesus AND footnote:said</td><td>Finds footnotes with 'Jesus' and 'said'</td></tr>" + "<tr><td>strong:G846</td><td>Finds verses with Strong's Greek number 846</td></tr>" + "<tr><td>morph:\"N-NSF\"</td><td>Finds verses with morphology code 'N-NSF'</td>" + "</tr></table></p>"); + + QString lucene = tr( + "<h1><A name='lucene'>Other syntax features</A></h1>" + "<p>BibleTime uses the CLucene search engine. You can read more on the <a href='http://lucene.apache.org/java/1_4_3/queryparsersyntax.html'>lucene syntax web page</a> (in external browser).</p>"); + + QString syntax = style + intro + links + whichwords + whichwordstable + + grouping + groupingtable + wildcards + wildcardstable + + fields + fieldstable + lucene; + + BtTabHtmlDialog* dlg = new BtTabHtmlDialog(tr("Search Syntax Help"), 0, this); + dlg->setHtml(syntax); + dlg->show(); } void BtSearchOptionsArea::refreshRanges() { - //the first option is fixed, the others can be edited using the "Setup ranges" button. - m_rangeChooserCombo->clear(); - m_rangeChooserCombo->insertItem(0, QString("[") + tr("No search scope") + QString("]")); - //TODO: what about this? - //m_rangeChooserCombo->insertItem(tr("Last search result")); + //the first option is fixed, the others can be edited using the "Setup ranges" button. + m_rangeChooserCombo->clear(); + m_rangeChooserCombo->insertItem(0, QString("[") + tr("No search scope") + QString("]")); + //TODO: what about this? + //m_rangeChooserCombo->insertItem(tr("Last search result")); - //insert the user-defined ranges - m_rangeChooserCombo->insertItems(1, CBTConfig::get(CBTConfig::searchScopes).keys()); + //insert the user-defined ranges + m_rangeChooserCombo->insertItems(1, CBTConfig::get(CBTConfig::searchScopes).keys()); } sword::ListKey BtSearchOptionsArea::searchScope() { - if (m_rangeChooserCombo->currentIndex() > 0) { //is not "no scope" - CBTConfig::StringMap map = CBTConfig::get(CBTConfig::searchScopes); - QString scope = map[ m_rangeChooserCombo->currentText() ]; - if (!scope.isEmpty()) { - return sword::VerseKey().ParseVerseList( (const char*)scope.toUtf8(), "Genesis 1:1", true); - } - } - return sword::ListKey(); + if (m_rangeChooserCombo->currentIndex() > 0) { //is not "no scope" + CBTConfig::StringMap map = CBTConfig::get(CBTConfig::searchScopes); + QString scope = map[ m_rangeChooserCombo->currentText() ]; + if (!scope.isEmpty()) { + return sword::VerseKey().ParseVerseList( (const char*)scope.toUtf8(), "Genesis 1:1", true); + } + } + return sword::ListKey(); } bool BtSearchOptionsArea::hasSearchScope() { - return (searchScope().Count() > 0); + return (searchScope().Count() > 0); } -void BtSearchOptionsArea::addToHistory(const QString& text) -{ - m_searchTextCombo->addToHistory(text); +void BtSearchOptionsArea::addToHistory(const QString& text) { + m_searchTextCombo->addToHistory(text); } -void BtSearchOptionsArea::slotSearchTextEditReturnPressed() -{ - qDebug("BtSearchOptionsArea::slotSearchTextEditReturnPressed"); - m_searchTextCombo->addToHistory( m_searchTextCombo->currentText() ); - emit sigStartSearch(); +void BtSearchOptionsArea::slotSearchTextEditReturnPressed() { + qDebug("BtSearchOptionsArea::slotSearchTextEditReturnPressed"); + m_searchTextCombo->addToHistory( m_searchTextCombo->currentText() ); + emit sigStartSearch(); } -bool BtSearchOptionsArea::eventFilter(QObject* obj, QEvent* event) -{ - if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) { - //qDebug() << "BtSearchOptionsArea::eventFilter" << obj << event; - if (obj == m_searchTextCombo->view() || obj == m_searchTextCombo || obj == m_searchTextCombo->lineEdit()) { - //qDebug() << "BtSearchOptionsArea::eventFilter" << obj << event; - obj->event(event); - // don't handle this event in parent - event->accept(); - return true; - } - } - return QWidget::eventFilter(obj, event); +bool BtSearchOptionsArea::eventFilter(QObject* obj, QEvent* event) { + if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) { + //qDebug() << "BtSearchOptionsArea::eventFilter" << obj << event; + if (obj == m_searchTextCombo->view() || obj == m_searchTextCombo || obj == m_searchTextCombo->lineEdit()) { + //qDebug() << "BtSearchOptionsArea::eventFilter" << obj << event; + obj->event(event); + // don't handle this event in parent + event->accept(); + return true; + } + } + return QWidget::eventFilter(obj, event); } -void BtSearchOptionsArea::slotValidateText(const QString& /*newText*/) -{ +void BtSearchOptionsArea::slotValidateText(const QString& /*newText*/) { // static const QRegExp re("\\b(AND|OR)\\b"); // qDebug() << "new text:" << newText; // qDebug() << "contains:" << (newText.contains(re)); diff --git a/src/frontend/searchdialog/btsearchoptionsarea.h b/src/frontend/searchdialog/btsearchoptionsarea.h index 30f6654..38bba54 100644 --- a/src/frontend/searchdialog/btsearchoptionsarea.h +++ b/src/frontend/searchdialog/btsearchoptionsarea.h @@ -31,117 +31,116 @@ class QEvent; namespace Search { -class BtSearchOptionsArea : public QWidget -{ - Q_OBJECT -public: - - enum SearchType {AndType, OrType, FullType}; - - friend class CSearchDialog; - - BtSearchOptionsArea(QWidget *parent=0); - ~BtSearchOptionsArea(); - /* - * Add text to search combox box history - */ - void addToHistory(const QString& text); - /** - * Sets the search text used in the page. - */ - void setSearchText(const QString& text); - /** - * Returns the search text set in this page. - */ - QString searchText() const; - - SearchType searchType(); - - QPushButton* searchButton() const; - - /** - * Returns the list of used modules. - */ - QList<CSwordModuleInfo*> modules() const; - - /** - * Sets all options back to the default. - */ - void reset(); - /** - * Returns the selected search scope if a search scope was selected. - */ - sword::ListKey searchScope(); - - bool hasSearchScope(); - - -protected: - /** - * Initializes this page. - */ - void initView(); - void initConnections(); - /** - * Reads the settings of the last searchdialog session. - */ - void readSettings(); - /** - * Reads the settings for the searchdialog from disk. - */ - void saveSettings(); - bool eventFilter(QObject* obj, QEvent* event); -public slots: - /** - * Sets the modules used by the search. - */ - void setModules( QList<CSwordModuleInfo*> modules ); - - /** Sets the modules when user selects them from the combobox.*/ - void moduleListTextSelected(int index); - - /** - * Reimplementation. - */ - void aboutToShow(); - /** - * Refreshes the list of ranges and the range combobox. - */ - void refreshRanges(); - /** - * Opens the modules chooser dialog. - */ - void chooseModules(); - -protected slots: - void setupRanges(); - void syntaxHelp(); - void slotSearchTextEditReturnPressed(); - void slotValidateText(const QString& newText); - -signals: - void sigSetSearchButtonStatus(bool); - void sigStartSearch(); - -private: - QList<CSwordModuleInfo*> m_modules; - - QHBoxLayout *hboxLayout; - QGroupBox *searchGroupBox; - QGridLayout *gridLayout; - QLabel *m_searchTextLabel; - QPushButton* m_searchButton; - QLabel* m_helpLabel; - QRadioButton* m_typeAndButton; - QRadioButton* m_typeOrButton; - QRadioButton* m_typeFreeButton; - QPushButton *m_chooseModulesButton; - QPushButton *m_chooseRangeButton; - QLabel *m_searchScopeLabel; - QComboBox *m_rangeChooserCombo; - CHistoryComboBox *m_searchTextCombo; - QLabel *m_modulesLabel; - QComboBox* m_modulesCombo; +class BtSearchOptionsArea : public QWidget { + Q_OBJECT + public: + + enum SearchType {AndType, OrType, FullType}; + + friend class CSearchDialog; + + BtSearchOptionsArea(QWidget *parent = 0); + ~BtSearchOptionsArea(); + /* + * Add text to search combox box history + */ + void addToHistory(const QString& text); + /** + * Sets the search text used in the page. + */ + void setSearchText(const QString& text); + /** + * Returns the search text set in this page. + */ + QString searchText() const; + + SearchType searchType(); + + QPushButton* searchButton() const; + + /** + * Returns the list of used modules. + */ + QList<CSwordModuleInfo*> modules() const; + + /** + * Sets all options back to the default. + */ + void reset(); + /** + * Returns the selected search scope if a search scope was selected. + */ + sword::ListKey searchScope(); + + bool hasSearchScope(); + + + protected: + /** + * Initializes this page. + */ + void initView(); + void initConnections(); + /** + * Reads the settings of the last searchdialog session. + */ + void readSettings(); + /** + * Reads the settings for the searchdialog from disk. + */ + void saveSettings(); + bool eventFilter(QObject* obj, QEvent* event); + public slots: + /** + * Sets the modules used by the search. + */ + void setModules( QList<CSwordModuleInfo*> modules ); + + /** Sets the modules when user selects them from the combobox.*/ + void moduleListTextSelected(int index); + + /** + * Reimplementation. + */ + void aboutToShow(); + /** + * Refreshes the list of ranges and the range combobox. + */ + void refreshRanges(); + /** + * Opens the modules chooser dialog. + */ + void chooseModules(); + + protected slots: + void setupRanges(); + void syntaxHelp(); + void slotSearchTextEditReturnPressed(); + void slotValidateText(const QString& newText); + + signals: + void sigSetSearchButtonStatus(bool); + void sigStartSearch(); + + private: + QList<CSwordModuleInfo*> m_modules; + + QHBoxLayout *hboxLayout; + QGroupBox *searchGroupBox; + QGridLayout *gridLayout; + QLabel *m_searchTextLabel; + QPushButton* m_searchButton; + QLabel* m_helpLabel; + QRadioButton* m_typeAndButton; + QRadioButton* m_typeOrButton; + QRadioButton* m_typeFreeButton; + QPushButton *m_chooseModulesButton; + QPushButton *m_chooseRangeButton; + QLabel *m_searchScopeLabel; + QComboBox *m_rangeChooserCombo; + CHistoryComboBox *m_searchTextCombo; + QLabel *m_modulesLabel; + QComboBox* m_modulesCombo; }; diff --git a/src/frontend/searchdialog/btsearchresultarea.cpp b/src/frontend/searchdialog/btsearchresultarea.cpp index 585d5d3..04e0415 100644 --- a/src/frontend/searchdialog/btsearchresultarea.cpp +++ b/src/frontend/searchdialog/btsearchresultarea.cpp @@ -34,517 +34,506 @@ namespace Search { BtSearchResultArea::BtSearchResultArea(QWidget *parent) - : QWidget(parent) -{ - qDebug("BtSearchResultArea::BtSearchResultArea"); - initView(); - initConnections(); - qDebug("BtSearchResultArea::BtSearchResultArea end"); + : QWidget(parent) { + qDebug("BtSearchResultArea::BtSearchResultArea"); + initView(); + initConnections(); + qDebug("BtSearchResultArea::BtSearchResultArea end"); } -BtSearchResultArea::~BtSearchResultArea() -{ - saveDialogSettings(); +BtSearchResultArea::~BtSearchResultArea() { + saveDialogSettings(); } -void BtSearchResultArea::initView() -{ - QVBoxLayout *mainLayout; - QWidget *resultListsWidget; - QVBoxLayout *resultListsWidgetLayout; - - //Size is calculated from the font rather than set in pixels, - // maybe this is better in different kinds of displays? - int mWidth = CToolClass::mWidth(this, 1); - this->setMinimumSize(QSize(mWidth*40, mWidth*15)); - mainLayout = new QVBoxLayout(this); - mainSplitter = new QSplitter(this); - mainSplitter->setOrientation(Qt::Horizontal); - - resultListsWidget = new QWidget(mainSplitter); - - resultListsWidgetLayout = new QVBoxLayout(resultListsWidget); - resultListsWidgetLayout->setContentsMargins(0, 0, 0, 0); - - //Splitter for two result lists - resultListSplitter = new QSplitter(resultListsWidget); - resultListSplitter->setOrientation(Qt::Vertical); - m_moduleListBox = new CModuleResultView(resultListSplitter); - resultListSplitter->addWidget(m_moduleListBox); - m_resultListBox = new CSearchResultView(resultListSplitter); - resultListSplitter->addWidget(m_resultListBox); - resultListsWidgetLayout->addWidget(resultListSplitter); - - mainSplitter->addWidget(resultListsWidget); - - //Preview ("info") area - m_displayFrame = new QFrame(mainSplitter); - m_displayFrame->setFrameShape(QFrame::NoFrame); - m_displayFrame->setFrameShadow(QFrame::Plain); - mainSplitter->addWidget(m_displayFrame); - - mainLayout->addWidget(mainSplitter); - - QVBoxLayout* frameLayout = new QVBoxLayout(m_displayFrame); - frameLayout->setContentsMargins(0,0,0,0); - m_previewDisplay = CDisplay::createReadInstance(0, m_displayFrame); - m_previewDisplay->view()->setToolTip(tr("Text of the selected search result item")); - frameLayout->addWidget(m_previewDisplay->view()); - - loadDialogSettings(); +void BtSearchResultArea::initView() { + QVBoxLayout *mainLayout; + QWidget *resultListsWidget; + QVBoxLayout *resultListsWidgetLayout; + + //Size is calculated from the font rather than set in pixels, + // maybe this is better in different kinds of displays? + int mWidth = CToolClass::mWidth(this, 1); + this->setMinimumSize(QSize(mWidth*40, mWidth*15)); + mainLayout = new QVBoxLayout(this); + mainSplitter = new QSplitter(this); + mainSplitter->setOrientation(Qt::Horizontal); + + resultListsWidget = new QWidget(mainSplitter); + + resultListsWidgetLayout = new QVBoxLayout(resultListsWidget); + resultListsWidgetLayout->setContentsMargins(0, 0, 0, 0); + + //Splitter for two result lists + resultListSplitter = new QSplitter(resultListsWidget); + resultListSplitter->setOrientation(Qt::Vertical); + m_moduleListBox = new CModuleResultView(resultListSplitter); + resultListSplitter->addWidget(m_moduleListBox); + m_resultListBox = new CSearchResultView(resultListSplitter); + resultListSplitter->addWidget(m_resultListBox); + resultListsWidgetLayout->addWidget(resultListSplitter); + + mainSplitter->addWidget(resultListsWidget); + + //Preview ("info") area + m_displayFrame = new QFrame(mainSplitter); + m_displayFrame->setFrameShape(QFrame::NoFrame); + m_displayFrame->setFrameShadow(QFrame::Plain); + mainSplitter->addWidget(m_displayFrame); + + mainLayout->addWidget(mainSplitter); + + QVBoxLayout* frameLayout = new QVBoxLayout(m_displayFrame); + frameLayout->setContentsMargins(0, 0, 0, 0); + m_previewDisplay = CDisplay::createReadInstance(0, m_displayFrame); + m_previewDisplay->view()->setToolTip(tr("Text of the selected search result item")); + frameLayout->addWidget(m_previewDisplay->view()); + + loadDialogSettings(); } -void BtSearchResultArea::setSearchResult(QList<CSwordModuleInfo*> modules) -{ - const QString searchedText = CSearchDialog::getSearchDialog()->searchText(); - reset(); //clear current modules +void BtSearchResultArea::setSearchResult(QList<CSwordModuleInfo*> modules) { + const QString searchedText = CSearchDialog::getSearchDialog()->searchText(); + reset(); //clear current modules - m_modules = modules; - //pre-select the first module in the list - //this will pre-select and display the first hit of that module - m_moduleListBox->setupTree(modules, searchedText); - m_moduleListBox->setCurrentItem(m_moduleListBox->topLevelItem(0), 0); + m_modules = modules; + //pre-select the first module in the list + //this will pre-select and display the first hit of that module + m_moduleListBox->setupTree(modules, searchedText); + m_moduleListBox->setCurrentItem(m_moduleListBox->topLevelItem(0), 0); - qobject_cast<CSearchDialog*>(parent())->m_analyseButton->setEnabled(true); + qobject_cast<CSearchDialog*>(parent())->m_analyseButton->setEnabled(true); } -void BtSearchResultArea::reset() -{ - m_moduleListBox->clear(); - m_resultListBox->clear(); - m_previewDisplay->setText("<html><head/><body></body></html>"); - qobject_cast<CSearchDialog*>(parent())->m_analyseButton->setEnabled(false); - m_modules.clear(); +void BtSearchResultArea::reset() { + m_moduleListBox->clear(); + m_resultListBox->clear(); + m_previewDisplay->setText("<html><head/><body></body></html>"); + qobject_cast<CSearchDialog*>(parent())->m_analyseButton->setEnabled(false); + m_modules.clear(); } -void BtSearchResultArea::clearPreview(){ - m_previewDisplay->setText("<html><head/><body></body></html>"); +void BtSearchResultArea::clearPreview() { + m_previewDisplay->setText("<html><head/><body></body></html>"); } -void BtSearchResultArea::updatePreview(const QString& key) -{ - using namespace Rendering; - - CSwordModuleInfo* module = m_moduleListBox->activeModule(); - if ( module ) { - const QString searchedText = CSearchDialog::getSearchDialog()->searchText(); - - QString text; - CDisplayRendering render; - - QList<CSwordModuleInfo*> modules; - modules.append(module); - - CTextRendering::KeyTreeItem::Settings settings; - - //for bibles render 5 context verses - if (module->type() == CSwordModuleInfo::Bible) { - CSwordVerseKey vk(module); - vk.Headings(1); - vk.key(key); - - ((sword::VerseKey*)(module->module()->getKey()))->Headings(1); //HACK: enable headings for VerseKeys - - //first go back and then go forward the keys to be in context - vk.previous(CSwordVerseKey::UseVerse); - vk.previous(CSwordVerseKey::UseVerse); - - //include Headings in display, they are indexed and searched too - if (vk.Verse() == 1){ - if (vk.Chapter() == 1){ - vk.Chapter(0); - } - vk.Verse(0); - } - - const QString startKey = vk.key(); - - vk.key(key); - - vk.next(CSwordVerseKey::UseVerse); - vk.next(CSwordVerseKey::UseVerse); - const QString endKey = vk.key(); - - settings.keyRenderingFace = CTextRendering::KeyTreeItem::Settings::CompleteShort; - text = render.renderKeyRange(startKey, endKey, modules, key, settings); - } - //for commentaries only one verse, but with heading - else if (module->type() == CSwordModuleInfo::Commentary) { - CSwordVerseKey vk(module); - vk.Headings(1); - vk.key(key); - - ((sword::VerseKey*)(module->module()->getKey()))->Headings(1); //HACK: enable headings for VerseKeys - - //include Headings in display, they are indexed and searched too - if (vk.Verse() == 1){ - if (vk.Chapter() == 1){ - vk.Chapter(0); - } - vk.Verse(0); - } - const QString startKey = vk.key(); - - vk.key(key); - const QString endKey = vk.key(); - - settings.keyRenderingFace = CTextRendering::KeyTreeItem::Settings::NoKey; - text = render.renderKeyRange(startKey, endKey, modules, key, settings); - } - else { - text = render.renderSingleKey(key, modules, settings); - } - - m_previewDisplay->setText( highlightSearchedText(text, searchedText) ); - m_previewDisplay->moveToAnchor( CDisplayRendering::keyToHTMLAnchor(key) ); - } +void BtSearchResultArea::updatePreview(const QString& key) { + using namespace Rendering; + + CSwordModuleInfo* module = m_moduleListBox->activeModule(); + if ( module ) { + const QString searchedText = CSearchDialog::getSearchDialog()->searchText(); + + QString text; + CDisplayRendering render; + + QList<CSwordModuleInfo*> modules; + modules.append(module); + + CTextRendering::KeyTreeItem::Settings settings; + + //for bibles render 5 context verses + if (module->type() == CSwordModuleInfo::Bible) { + CSwordVerseKey vk(module); + vk.Headings(1); + vk.key(key); + + ((sword::VerseKey*)(module->module()->getKey()))->Headings(1); //HACK: enable headings for VerseKeys + + //first go back and then go forward the keys to be in context + vk.previous(CSwordVerseKey::UseVerse); + vk.previous(CSwordVerseKey::UseVerse); + + //include Headings in display, they are indexed and searched too + if (vk.Verse() == 1) { + if (vk.Chapter() == 1) { + vk.Chapter(0); + } + vk.Verse(0); + } + + const QString startKey = vk.key(); + + vk.key(key); + + vk.next(CSwordVerseKey::UseVerse); + vk.next(CSwordVerseKey::UseVerse); + const QString endKey = vk.key(); + + settings.keyRenderingFace = CTextRendering::KeyTreeItem::Settings::CompleteShort; + text = render.renderKeyRange(startKey, endKey, modules, key, settings); + } + //for commentaries only one verse, but with heading + else if (module->type() == CSwordModuleInfo::Commentary) { + CSwordVerseKey vk(module); + vk.Headings(1); + vk.key(key); + + ((sword::VerseKey*)(module->module()->getKey()))->Headings(1); //HACK: enable headings for VerseKeys + + //include Headings in display, they are indexed and searched too + if (vk.Verse() == 1) { + if (vk.Chapter() == 1) { + vk.Chapter(0); + } + vk.Verse(0); + } + const QString startKey = vk.key(); + + vk.key(key); + const QString endKey = vk.key(); + + settings.keyRenderingFace = CTextRendering::KeyTreeItem::Settings::NoKey; + text = render.renderKeyRange(startKey, endKey, modules, key, settings); + } + else { + text = render.renderSingleKey(key, modules, settings); + } + + m_previewDisplay->setText( highlightSearchedText(text, searchedText) ); + m_previewDisplay->moveToAnchor( CDisplayRendering::keyToHTMLAnchor(key) ); + } } QStringList BtSearchResultArea::QueryParser(const QString& queryString) { - QString token; - QStringList tokenList; - int cnt, pos; - - token = ""; - cnt = 0; - while(cnt < queryString.length()) { - // add to token - if ((queryString[cnt]).isLetterOrNumber() || (queryString[cnt] == '*')) { - token = token + queryString[cnt]; - cnt++; - } - // token break - else if (queryString[cnt] == ' ') { - token = token.simplified(); - if ((token != "*") && (token != "")) - tokenList.append(token); - token = ""; - cnt++; - } - // clucene appears to ignore quoted strings in the sence - // that it treats all the words within quoted strings as - // regular tokens and not as a single token. - else if (queryString[cnt] == '"') { - cnt++; - } - // wild card - treat as a special token break - //else if (queryString[cnt] == '*') { - // token = token + queryString[cnt]; - // token = token.simplified(); - // if ((token != "*") && (token != "")) - // tokenList.append(token); - // // start next token with wildcard (kin*m -> kin* *m) - // token = "*"; - // cnt++; - //} - // the ! token is also a token break - else if (queryString[cnt] == '!') { - // store away current token - token = token.simplified(); - if ((token != "*") && (token != "")) - tokenList.append(token); - // add the ! token - tokenList.append("!"); - token = ""; - cnt++; - } - // the - token is also a token break - else if (queryString[cnt] == '-') { - // store away current token - token = token.simplified(); - if ((token != "*") && (token != "")) - tokenList.append(token); - // add the ! token - tokenList.append("-"); - token = ""; - cnt++; - } - // the + token is also a token break - else if (queryString[cnt] == '+') { - // store away current token - token = token.simplified(); - if ((token != "*") && (token != "")) - tokenList.append(token); - // add the + token - tokenList.append("+"); - token = ""; - cnt++; - } - // the || token is also a token break - else if ((queryString[cnt] == '|') && (queryString[cnt+1] == '|')) { - // store away current token - token = token.simplified(); - if ((token != "*") && (token != "")) - tokenList.append(token); - // add the || token - tokenList.append("||"); - token = ""; - cnt += 2; - } - // the && token is also a token break - else if ((queryString[cnt] == '&') && (queryString[cnt+1] == '&')) { - // store away current token - token = token.simplified(); - if ((token != "*") && (token != "")) - tokenList.append(token); - // add the || token - tokenList.append("&&"); - token = ""; - cnt += 2; - } - else cnt++; - } - token = token.simplified(); - if ((token != "*") && (token != "")) - tokenList.append(token); - - cnt = 0; - QStringList::iterator it; - for ( it = tokenList.begin(); it != tokenList.end(); it++ ) { - //----------------------------------------------------------- - // remove all the NOT(!) tokens - these do not need to be - // highlighted in the highlighter - //----------------------------------------------------------- - if (((*it) == "!") || ((*it) == "NOT") || ((*it) == "-")) { - it = tokenList.erase(it); - if (it == tokenList.end()) - break; - it = tokenList.erase(it); - if (it == tokenList.end()) - break; - it--; - } - //----------------------------------------------------------- - // remove all the operator tokens - these do not need to be - // highlighted in the highlighter - //----------------------------------------------------------- - else if ( ((*it) == "||") || ((*it) == "OR") || ((*it) == "+") || - ((*it) == "AND") || ((*it) == "&&") ) - { - it = tokenList.erase(it); - if (it == tokenList.end()) - break; - it--; - } - // if the token contains a ^ then trim the remainder of the - // token from the ^ - //What??? error: invalid conversion from ‘const void*’ to ‘int’ - // and how come "contains" returns bool but is used as int? - //else if ( (pos = (*it).contains("^")) >= 0 ) { - else if ( (pos = (*it).indexOf("^") ) >= 0 ) { - (*it) = (*it).left(pos - 1); - } - // if the token contains a ~ then trim the remainder of the - // token from the ~ - else if ( (pos = (*it).indexOf("~") ) >= 0 ) { - (*it) = (*it).left(pos - 2) + "*"; - } - } - return(tokenList); + QString token; + QStringList tokenList; + int cnt, pos; + + token = ""; + cnt = 0; + while (cnt < queryString.length()) { + // add to token + if ((queryString[cnt]).isLetterOrNumber() || (queryString[cnt] == '*')) { + token = token + queryString[cnt]; + cnt++; + } + // token break + else if (queryString[cnt] == ' ') { + token = token.simplified(); + if ((token != "*") && (token != "")) + tokenList.append(token); + token = ""; + cnt++; + } + // clucene appears to ignore quoted strings in the sence + // that it treats all the words within quoted strings as + // regular tokens and not as a single token. + else if (queryString[cnt] == '"') { + cnt++; + } + // wild card - treat as a special token break + //else if (queryString[cnt] == '*') { + // token = token + queryString[cnt]; + // token = token.simplified(); + // if ((token != "*") && (token != "")) + // tokenList.append(token); + // // start next token with wildcard (kin*m -> kin* *m) + // token = "*"; + // cnt++; + //} + // the ! token is also a token break + else if (queryString[cnt] == '!') { + // store away current token + token = token.simplified(); + if ((token != "*") && (token != "")) + tokenList.append(token); + // add the ! token + tokenList.append("!"); + token = ""; + cnt++; + } + // the - token is also a token break + else if (queryString[cnt] == '-') { + // store away current token + token = token.simplified(); + if ((token != "*") && (token != "")) + tokenList.append(token); + // add the ! token + tokenList.append("-"); + token = ""; + cnt++; + } + // the + token is also a token break + else if (queryString[cnt] == '+') { + // store away current token + token = token.simplified(); + if ((token != "*") && (token != "")) + tokenList.append(token); + // add the + token + tokenList.append("+"); + token = ""; + cnt++; + } + // the || token is also a token break + else if ((queryString[cnt] == '|') && (queryString[cnt+1] == '|')) { + // store away current token + token = token.simplified(); + if ((token != "*") && (token != "")) + tokenList.append(token); + // add the || token + tokenList.append("||"); + token = ""; + cnt += 2; + } + // the && token is also a token break + else if ((queryString[cnt] == '&') && (queryString[cnt+1] == '&')) { + // store away current token + token = token.simplified(); + if ((token != "*") && (token != "")) + tokenList.append(token); + // add the || token + tokenList.append("&&"); + token = ""; + cnt += 2; + } + else cnt++; + } + token = token.simplified(); + if ((token != "*") && (token != "")) + tokenList.append(token); + + cnt = 0; + QStringList::iterator it; + for ( it = tokenList.begin(); it != tokenList.end(); it++ ) { + //----------------------------------------------------------- + // remove all the NOT(!) tokens - these do not need to be + // highlighted in the highlighter + //----------------------------------------------------------- + if (((*it) == "!") || ((*it) == "NOT") || ((*it) == "-")) { + it = tokenList.erase(it); + if (it == tokenList.end()) + break; + it = tokenList.erase(it); + if (it == tokenList.end()) + break; + it--; + } + //----------------------------------------------------------- + // remove all the operator tokens - these do not need to be + // highlighted in the highlighter + //----------------------------------------------------------- + else if ( ((*it) == "||") || ((*it) == "OR") || ((*it) == "+") || + ((*it) == "AND") || ((*it) == "&&") ) { + it = tokenList.erase(it); + if (it == tokenList.end()) + break; + it--; + } + // if the token contains a ^ then trim the remainder of the + // token from the ^ + //What??? error: invalid conversion from ‘const void*’ to ‘int’ + // and how come "contains" returns bool but is used as int? + //else if ( (pos = (*it).contains("^")) >= 0 ) { + else if ( (pos = (*it).indexOf("^") ) >= 0 ) { + (*it) = (*it).left(pos - 1); + } + // if the token contains a ~ then trim the remainder of the + // token from the ~ + else if ( (pos = (*it).indexOf("~") ) >= 0 ) { + (*it) = (*it).left(pos - 2) + "*"; + } + } + return(tokenList); } QString BtSearchResultArea::highlightSearchedText(const QString& content, const QString& searchedText) { - QString ret = content; - - const Qt::CaseSensitivity cs = Qt::CaseInsensitive; - - // int index = 0; - int index = ret.indexOf("<body", 0); - int matchLen = 0; - int length = searchedText.length(); - - // Highlighting constants - - // TODO: We need to make the highlight color configurable. - const QString rep1("<span style=\"background-color:#FFFF66;\">"); - const QString rep2("</span>"); - const unsigned int repLength = rep1.length() + rep1.length(); - const QString rep3("style=\"background-color:#FFFF66;\" "); - const unsigned int rep3Length = rep3.length(); - - - QString newSearchText; - - newSearchText = searchedText; - - // find the strongs search lemma and highlight it - // search the searched text for "strong:" until it is not found anymore - QStringList list; - - // split the search string - some possibilities are "\\s|\\|", "\\s|\\+", or "\\s|\\|\\+" - // TODO: find all possible seperators - QString regExp = "\\s"; - list = searchedText.split(QRegExp(regExp)); - foreach (QString newSearchText, list) { - int sstIndex; // strong search text index for finding "strong:" - int idx1, idx2; - QString sNumber, lemmaText; - - sstIndex = newSearchText.indexOf("strong:"); - if (sstIndex == -1) - continue; - - // set the start index to the start of <body> - int strongIndex = index; - - // Get the strongs number from the search text. - // First, find the first space after "strong:" - sstIndex = sstIndex + 7; - // get the strongs number -> the text following "strong:" to the end of the string. - sNumber = newSearchText.mid(sstIndex, -1); - // find all the "lemma=" inside the the content - while((strongIndex = ret.indexOf("lemma=", strongIndex, cs)) != -1) { - // get the strongs number after the lemma and compare it with the - // strongs number we are looking for - idx1 = ret.indexOf("\"", strongIndex) + 1; - idx2 = ret.indexOf("\"", idx1 + 1); - lemmaText = ret.mid(idx1, idx2 - idx1); - - // this is interesting because we could have a strongs number like: G3218|G300 - // To handle this we will use some extra cpu cycles and do a partial match against - // the lemmaText - if (lemmaText.contains(sNumber)) { - // strongs number is found now we need to highlight it - // I believe the easiest way is to insert rep3 just before "lemma=" - ret = ret.insert(strongIndex, rep3); - strongIndex += rep3Length; - } - strongIndex += 6; // 6 is the length of "lemma=" - } - } - //--------------------------------------------------------------------- - // now that the strong: stuff is out of the way continue with - // other search options - //--------------------------------------------------------------------- - - // try to figure out how to use the lucene query parser - - //using namespace lucene::queryParser; - //using namespace lucene::search; - //using namespace lucene::analysis; - //using namespace lucene::util; - - //wchar_t *buf; - //char buf8[1000]; - //standard::WhitespaceAnalyzer analyzer; - //lucene_utf8towcs(m_wcharBuffer, searchedText.utf8(), MAX_CONV_SIZE); - //boost::scoped_ptr<Query> q( QueryParser::parse(m_wcharBuffer, _T("content"), &analyzer) ); - //StringReader reader(m_wcharBuffer); - //TokenStream* tokenStream = analyzer.tokenStream( _T("field"), &reader); - //Token token; - //while(tokenStream->next(&token) != 0) { - // lucene_wcstoutf8(buf8, token.termText(), 1000); - // printf("%s\n", buf8); - //} - - //=========================================================== - // since I could not figure out the lucene query parser, I - // made a simple parser. - //=========================================================== - QStringList words = QueryParser(newSearchText); - foreach (QString word, words) { //search for every word in the list - QRegExp findExp; - if (word.contains("*")) { - length = word.length() - 1; - word.replace('*', "\\S*"); //match within a word - findExp = QRegExp(word); - findExp.setMinimal(TRUE); - } - else { - length = word.length(); - findExp = QRegExp("\\b" + word + "\\b"); - } - - // index = 0; //for every word start at the beginning - index = ret.indexOf("<body", 0); - findExp.setCaseSensitivity(cs); - //while ( (index = ret.find(findExp, index)) != -1 ) { //while we found the word - while ( (index = findExp.indexIn(ret, index)) != -1 ) { //while we found the word - matchLen = findExp.matchedLength(); - if (!CToolClass::inHTMLTag(index, ret)) { - length = matchLen; - ret = ret.insert( index+length, rep2 ); - ret = ret.insert( index, rep1 ); - index += repLength; - } - index += length; - } - } - //qWarning("\n\n\n%s", ret.latin1()); - return ret; + QString ret = content; + + const Qt::CaseSensitivity cs = Qt::CaseInsensitive; + + // int index = 0; + int index = ret.indexOf("<body", 0); + int matchLen = 0; + int length = searchedText.length(); + + // Highlighting constants - + // TODO: We need to make the highlight color configurable. + const QString rep1("<span style=\"background-color:#FFFF66;\">"); + const QString rep2("</span>"); + const unsigned int repLength = rep1.length() + rep1.length(); + const QString rep3("style=\"background-color:#FFFF66;\" "); + const unsigned int rep3Length = rep3.length(); + + + QString newSearchText; + + newSearchText = searchedText; + + // find the strongs search lemma and highlight it + // search the searched text for "strong:" until it is not found anymore + QStringList list; + + // split the search string - some possibilities are "\\s|\\|", "\\s|\\+", or "\\s|\\|\\+" + // TODO: find all possible seperators + QString regExp = "\\s"; + list = searchedText.split(QRegExp(regExp)); + foreach (QString newSearchText, list) { + int sstIndex; // strong search text index for finding "strong:" + int idx1, idx2; + QString sNumber, lemmaText; + + sstIndex = newSearchText.indexOf("strong:"); + if (sstIndex == -1) + continue; + + // set the start index to the start of <body> + int strongIndex = index; + + // Get the strongs number from the search text. + // First, find the first space after "strong:" + sstIndex = sstIndex + 7; + // get the strongs number -> the text following "strong:" to the end of the string. + sNumber = newSearchText.mid(sstIndex, -1); + // find all the "lemma=" inside the the content + while ((strongIndex = ret.indexOf("lemma=", strongIndex, cs)) != -1) { + // get the strongs number after the lemma and compare it with the + // strongs number we are looking for + idx1 = ret.indexOf("\"", strongIndex) + 1; + idx2 = ret.indexOf("\"", idx1 + 1); + lemmaText = ret.mid(idx1, idx2 - idx1); + + // this is interesting because we could have a strongs number like: G3218|G300 + // To handle this we will use some extra cpu cycles and do a partial match against + // the lemmaText + if (lemmaText.contains(sNumber)) { + // strongs number is found now we need to highlight it + // I believe the easiest way is to insert rep3 just before "lemma=" + ret = ret.insert(strongIndex, rep3); + strongIndex += rep3Length; + } + strongIndex += 6; // 6 is the length of "lemma=" + } + } + //--------------------------------------------------------------------- + // now that the strong: stuff is out of the way continue with + // other search options + //--------------------------------------------------------------------- + + // try to figure out how to use the lucene query parser + + //using namespace lucene::queryParser; + //using namespace lucene::search; + //using namespace lucene::analysis; + //using namespace lucene::util; + + //wchar_t *buf; + //char buf8[1000]; + //standard::WhitespaceAnalyzer analyzer; + //lucene_utf8towcs(m_wcharBuffer, searchedText.utf8(), MAX_CONV_SIZE); + //boost::scoped_ptr<Query> q( QueryParser::parse(m_wcharBuffer, _T("content"), &analyzer) ); + //StringReader reader(m_wcharBuffer); + //TokenStream* tokenStream = analyzer.tokenStream( _T("field"), &reader); + //Token token; + //while(tokenStream->next(&token) != 0) { + // lucene_wcstoutf8(buf8, token.termText(), 1000); + // printf("%s\n", buf8); + //} + + //=========================================================== + // since I could not figure out the lucene query parser, I + // made a simple parser. + //=========================================================== + QStringList words = QueryParser(newSearchText); + foreach (QString word, words) { //search for every word in the list + QRegExp findExp; + if (word.contains("*")) { + length = word.length() - 1; + word.replace('*', "\\S*"); //match within a word + findExp = QRegExp(word); + findExp.setMinimal(TRUE); + } + else { + length = word.length(); + findExp = QRegExp("\\b" + word + "\\b"); + } + + // index = 0; //for every word start at the beginning + index = ret.indexOf("<body", 0); + findExp.setCaseSensitivity(cs); + //while ( (index = ret.find(findExp, index)) != -1 ) { //while we found the word + while ( (index = findExp.indexIn(ret, index)) != -1 ) { //while we found the word + matchLen = findExp.matchedLength(); + if (!CToolClass::inHTMLTag(index, ret)) { + length = matchLen; + ret = ret.insert( index + length, rep2 ); + ret = ret.insert( index, rep1 ); + index += repLength; + } + index += length; + } + } + //qWarning("\n\n\n%s", ret.latin1()); + return ret; } /** Initializes the signal slot conections of the child widgets, */ -void BtSearchResultArea::initConnections() -{ - connect(m_resultListBox, SIGNAL(keySelected(const QString&)), this, SLOT(updatePreview(const QString&))); - connect(m_resultListBox, SIGNAL(keyDeselected()), this, SLOT(clearPreview())); - connect(m_moduleListBox, SIGNAL(moduleSelected(CSwordModuleInfo*)), m_resultListBox, SLOT(setupTree(CSwordModuleInfo*))); - connect(m_moduleListBox, SIGNAL(moduleChanged()), m_previewDisplay->connectionsProxy(), SLOT(clear())); - - // connect the strongs list - connect(m_moduleListBox, SIGNAL(strongsSelected(CSwordModuleInfo*, QStringList*)), - m_resultListBox, SLOT(setupStrongsTree(CSwordModuleInfo*, QStringList*))); +void BtSearchResultArea::initConnections() { + connect(m_resultListBox, SIGNAL(keySelected(const QString&)), this, SLOT(updatePreview(const QString&))); + connect(m_resultListBox, SIGNAL(keyDeselected()), this, SLOT(clearPreview())); + connect(m_moduleListBox, SIGNAL(moduleSelected(CSwordModuleInfo*)), m_resultListBox, SLOT(setupTree(CSwordModuleInfo*))); + connect(m_moduleListBox, SIGNAL(moduleChanged()), m_previewDisplay->connectionsProxy(), SLOT(clear())); + + // connect the strongs list + connect(m_moduleListBox, SIGNAL(strongsSelected(CSwordModuleInfo*, QStringList*)), + m_resultListBox, SLOT(setupStrongsTree(CSwordModuleInfo*, QStringList*))); } /** Shows a dialog with the search analysis of the current search. */ void BtSearchResultArea::showAnalysis() { - CSearchAnalysisDialog dlg(m_modules, this); - dlg.exec(); + CSearchAnalysisDialog dlg(m_modules, this); + dlg.exec(); } /** * Load the settings from the resource file */ -void BtSearchResultArea::loadDialogSettings() -{ - QList<int> mainSplitterSizes = CBTConfig::get(CBTConfig::searchMainSplitterSizes); - if (mainSplitterSizes.count() > 0) { - mainSplitter->setSizes(mainSplitterSizes); - } else { - int w = this->size().width(); - int w2 = m_moduleListBox->sizeHint().width(); - mainSplitterSizes << w2 << w - w2; - mainSplitter->setSizes(mainSplitterSizes); - } - QList<int> resultSplitterSizes = CBTConfig::get(CBTConfig::searchResultSplitterSizes); - if (resultSplitterSizes.count() > 0) resultListSplitter->setSizes(resultSplitterSizes); +void BtSearchResultArea::loadDialogSettings() { + QList<int> mainSplitterSizes = CBTConfig::get(CBTConfig::searchMainSplitterSizes); + if (mainSplitterSizes.count() > 0) { + mainSplitter->setSizes(mainSplitterSizes); + } + else { + int w = this->size().width(); + int w2 = m_moduleListBox->sizeHint().width(); + mainSplitterSizes << w2 << w - w2; + mainSplitter->setSizes(mainSplitterSizes); + } + QList<int> resultSplitterSizes = CBTConfig::get(CBTConfig::searchResultSplitterSizes); + if (resultSplitterSizes.count() > 0) resultListSplitter->setSizes(resultSplitterSizes); } /** * Save the settings to the resource file */ -void BtSearchResultArea::saveDialogSettings() -{ - CBTConfig::set(CBTConfig::searchMainSplitterSizes, mainSplitter->sizes()); - CBTConfig::set(CBTConfig::searchResultSplitterSizes, resultListSplitter->sizes()); +void BtSearchResultArea::saveDialogSettings() { + CBTConfig::set(CBTConfig::searchMainSplitterSizes, mainSplitter->sizes()); + CBTConfig::set(CBTConfig::searchResultSplitterSizes, resultListSplitter->sizes()); } -StrongsResult::StrongsResult() -{ +StrongsResult::StrongsResult() { } StrongsResult::StrongsResult(const QString& text, const QString &keyName) - : text(text) -{ - //keyNameList.clear(); - keyNameList.append(keyName); + : text(text) { + //keyNameList.clear(); + keyNameList.append(keyName); } QString StrongsResult::keyText() const { - return text; + return text; } int StrongsResult::keyCount() const { - return keyNameList.count(); + return keyNameList.count(); } void StrongsResult::addKeyName(const QString& keyName) { - if (keyNameList.indexOf(keyName) == -1) - keyNameList.append(keyName); + if (keyNameList.indexOf(keyName) == -1) + keyNameList.append(keyName); } QStringList* StrongsResult::getKeyList() { - return & keyNameList; + return & keyNameList; } @@ -552,106 +541,102 @@ QStringList* StrongsResult::getKeyList() { /******************************************** ************ StrongsResultClass ************* ********************************************/ -void StrongsResultClass::initStrongsResults(void) -{ - using namespace Rendering; - - CDisplayRendering render; - QList<CSwordModuleInfo*> modules; - CTextRendering::KeyTreeItem::Settings settings; - QString rText, lText, key; - bool found; - int sIndex; - int count; - int index; - QString text; - - modules.append(srModule); - sword::ListKey& result = srModule->searchResult(); - - count = result.Count(); - if (!count) - return; - qApp->processEvents( QEventLoop::AllEvents, 1 ); //1 ms only - srList.clear(); - // for whatever reason the text "Parsing...translations." does not appear. - // this is not critical but the text is necessary to get the dialog box - // to be wide enough. - QProgressDialog* progress = new QProgressDialog(QObject::tr("Parsing Strong's Numbers"), 0, 0, count); - //0, "progressDialog", tr("Parsing Strong's Numbers"), tr("Parsing Strong's numbers for translations."), true); - - //progress->setAllowCancel(false); - //progress->setMinimumDuration(0); - progress->show(); - progress->raise(); - for (index = 0; index < count; index++){ - progress->setValue( index ); - qApp->processEvents(QEventLoop::AllEvents, 1 ); //1 ms only - - key = QString::fromUtf8(result.GetElement(index)->getText()); - text = render.renderSingleKey(key, modules, settings); - sIndex = 0; - while ((rText = getStrongsNumberText(text, &sIndex)) != "") - { - StrongsResultList::iterator it; - found = FALSE; - for ( it = srList.begin(); it != srList.end(); ++it ) - { - lText = (*it).keyText(); - if (lText == rText) - { - found = TRUE; - (*it).addKeyName(key); - break; - } - } - if (found == FALSE) - srList.append( StrongsResult(rText, key) ); - } - } - delete progress; - progress = 0; - //qHeapSort(srList); +void StrongsResultClass::initStrongsResults(void) { + using namespace Rendering; + + CDisplayRendering render; + QList<CSwordModuleInfo*> modules; + CTextRendering::KeyTreeItem::Settings settings; + QString rText, lText, key; + bool found; + int sIndex; + int count; + int index; + QString text; + + modules.append(srModule); + sword::ListKey& result = srModule->searchResult(); + + count = result.Count(); + if (!count) + return; + qApp->processEvents( QEventLoop::AllEvents, 1 ); //1 ms only + srList.clear(); + // for whatever reason the text "Parsing...translations." does not appear. + // this is not critical but the text is necessary to get the dialog box + // to be wide enough. + QProgressDialog* progress = new QProgressDialog(QObject::tr("Parsing Strong's Numbers"), 0, 0, count); + //0, "progressDialog", tr("Parsing Strong's Numbers"), tr("Parsing Strong's numbers for translations."), true); + + //progress->setAllowCancel(false); + //progress->setMinimumDuration(0); + progress->show(); + progress->raise(); + for (index = 0; index < count; index++) { + progress->setValue( index ); + qApp->processEvents(QEventLoop::AllEvents, 1 ); //1 ms only + + key = QString::fromUtf8(result.GetElement(index)->getText()); + text = render.renderSingleKey(key, modules, settings); + sIndex = 0; + while ((rText = getStrongsNumberText(text, &sIndex)) != "") { + StrongsResultList::iterator it; + found = FALSE; + for ( it = srList.begin(); it != srList.end(); ++it ) { + lText = (*it).keyText(); + if (lText == rText) { + found = TRUE; + (*it).addKeyName(key); + break; + } + } + if (found == FALSE) + srList.append( StrongsResult(rText, key) ); + } + } + delete progress; + progress = 0; + //qHeapSort(srList); } QString StrongsResultClass::getStrongsNumberText(const QString& verseContent, int *startIndex) { - // get the strongs text - int idx1, idx2, index; - QString sNumber, strongsText; - //const bool cs = CSwordModuleSearch::caseSensitive; - const Qt::CaseSensitivity cs = Qt::CaseInsensitive; - - if (*startIndex == 0) { - index = verseContent.indexOf("<body"); - } - else { - index = *startIndex; - } - - // find all the "lemma=" inside the the content - while((index = verseContent.indexOf("lemma=", index, cs)) != -1) { - // get the strongs number after the lemma and compare it with the - // strongs number we are looking for - idx1 = verseContent.indexOf("\"", index) + 1; - idx2 = verseContent.indexOf("\"", idx1 + 1); - sNumber = verseContent.mid(idx1, idx2 - idx1); - if (sNumber == lemmaText) { - // strongs number is found now we need to get the text of this node - // search right until the ">" is found. Get the text from here to - // the next "<". - index = verseContent.indexOf(">", index, cs) + 1; - idx2 = verseContent.indexOf("<", index, cs); - strongsText = verseContent.mid(index, idx2 - index); - index = idx2; - *startIndex = index; - - return(strongsText); - } - else { - index += 6; // 6 is the length of "lemma=" - } - } - return QString::null; + // get the strongs text + int idx1, idx2, index; + QString sNumber, strongsText; + //const bool cs = CSwordModuleSearch::caseSensitive; + const Qt::CaseSensitivity cs = Qt::CaseInsensitive; + + if (*startIndex == 0) { + index = verseContent.indexOf("<body"); + } + else { + index = *startIndex; + } + + // find all the "lemma=" inside the the content + while ((index = verseContent.indexOf("lemma=", index, cs)) != -1) { + // get the strongs number after the lemma and compare it with the + // strongs number we are looking for + idx1 = verseContent.indexOf("\"", index) + 1; + idx2 = verseContent.indexOf("\"", idx1 + 1); + sNumber = verseContent.mid(idx1, idx2 - idx1); + if (sNumber == lemmaText) { + // strongs number is found now we need to get the text of this node + // search right until the ">" is found. Get the text from here to + // the next "<". + index = verseContent.indexOf(">", index, cs) + 1; + idx2 = verseContent.indexOf("<", index, cs); + strongsText = verseContent.mid(index, idx2 - index); + index = idx2; + *startIndex = index; + + return(strongsText); + } + else { + index += 6; // 6 is the length of "lemma=" + } + } + return QString::null; } diff --git a/src/frontend/searchdialog/btsearchresultarea.h b/src/frontend/searchdialog/btsearchresultarea.h index 82eb2d4..cc87126 100644 --- a/src/frontend/searchdialog/btsearchresultarea.h +++ b/src/frontend/searchdialog/btsearchresultarea.h @@ -23,8 +23,8 @@ class CReadDisplay; class CSwordModuleInfo; namespace Search { - class CModuleResultView; - class CSearchResultView; +class CModuleResultView; +class CSearchResultView; } class QHBoxLayout; @@ -47,28 +47,28 @@ namespace Search { * To add a new verse to a strongs text result use addKeyName. */ class StrongsResult { -public: - StrongsResult(); - StrongsResult(const QString& text, const QString &keyName); - - QString keyText() const; - int keyCount() const; - void addKeyName(const QString& keyName); - QStringList* getKeyList(); - - /* ???? - bool operator==(const StrongsResult &l, const StrongsResult &r) - { return (l.keyText() == r.keyText()); } - - bool operator<(const StrongsResult &l, const StrongsResult &r) - { return (l->keyText() < r->keyText()); } - - bool operator>(const StrongsResult &l, const StrongsResult &r) - { return (l->keyText() > r->keyText()); } - */ -private: - QString text; - QStringList keyNameList; + public: + StrongsResult(); + StrongsResult(const QString& text, const QString &keyName); + + QString keyText() const; + int keyCount() const; + void addKeyName(const QString& keyName); + QStringList* getKeyList(); + + /* ???? + bool operator==(const StrongsResult &l, const StrongsResult &r) + { return (l.keyText() == r.keyText()); } + + bool operator<(const StrongsResult &l, const StrongsResult &r) + { return (l->keyText() < r->keyText()); } + + bool operator>(const StrongsResult &l, const StrongsResult &r) + { return (l->keyText() > r->keyText()); } + */ + private: + QString text; + QStringList keyNameList; }; typedef QList<StrongsResult> StrongsResultList; @@ -88,112 +88,114 @@ typedef QList<StrongsResult> StrongsResultList; * To add a new verse to a strongs text result use addKeyName. */ class StrongsResultClass { -public: - StrongsResultClass(CSwordModuleInfo* module, const QString& strongsNumber) - : srModule(module), lemmaText(strongsNumber) - { - initStrongsResults(); - } - - QString keyText(int index) const { - return srList[index].keyText(); - } - int keyCount(int index) const { - return srList[index].keyCount(); - } - QStringList* getKeyList(int index) { - return srList[index].getKeyList(); - } - int Count() const { - return srList.count(); - } - -private: - void initStrongsResults(void); - QString getStrongsNumberText(const QString& verseContent, int *startIndex); - - StrongsResultList srList; - CSwordModuleInfo* srModule; - QString lemmaText; + public: + StrongsResultClass(CSwordModuleInfo* module, const QString& strongsNumber) + : srModule(module), lemmaText(strongsNumber) { + initStrongsResults(); + } + + QString keyText(int index) const { + return srList[index].keyText(); + } + int keyCount(int index) const { + return srList[index].keyCount(); + } + QStringList* getKeyList(int index) { + return srList[index].getKeyList(); + } + int Count() const { + return srList.count(); + } + + private: + void initStrongsResults(void); + QString getStrongsNumberText(const QString& verseContent, int *startIndex); + + StrongsResultList srList; + CSwordModuleInfo* srModule; + QString lemmaText; }; /** The page of the search dialog which contains the search result part. * @author The BibleTime team */ -class BtSearchResultArea : public QWidget -{ - Q_OBJECT -public: - BtSearchResultArea(QWidget *parent=0); - ~BtSearchResultArea(); - /** - * Sets the modules which contain the result of each. - */ - void setSearchResult(QList<CSwordModuleInfo*> modules); - - QSize sizeHint() const { return baseSize(); } - QSize minimumSizeHint() const { return minimumSize(); } - -public slots: - /** - * Resets the current list of modules and the displayed list of found entries. - */ - void reset(); - -protected: - /** - * Initializes the view of this widget. - */ - void initView(); - /** - * Initializes the signal slot conections of the child widgets - */ - void initConnections(); - /** - * This function breakes the queryString into clucene tokens - */ - QStringList QueryParser(const QString& queryString); - /** - * This function highlights the searched text in the content using the search type given by search flags - */ - QString highlightSearchedText(const QString& content, const QString& searchedText); - - /** - * Load the settings from the resource file - */ - void loadDialogSettings(); - /** - * Save the settings to the resource file - */ - void saveDialogSettings(); - -protected slots: - /** - * Update the preview of the selected key. - */ - void updatePreview(const QString& key); - /** - * Clear the preview of the selected key. - */ - void clearPreview(); - /** - * Shows a dialog with the search analysis of the current search. - */ - void showAnalysis(); - -private: - - CModuleResultView* m_moduleListBox; - CSearchResultView* m_resultListBox; - - QFrame *m_displayFrame; - CReadDisplay* m_previewDisplay; - - QList<CSwordModuleInfo*> m_modules; - - QSplitter *mainSplitter; - QSplitter *resultListSplitter; +class BtSearchResultArea : public QWidget { + Q_OBJECT + public: + BtSearchResultArea(QWidget *parent = 0); + ~BtSearchResultArea(); + /** + * Sets the modules which contain the result of each. + */ + void setSearchResult(QList<CSwordModuleInfo*> modules); + + QSize sizeHint() const { + return baseSize(); + } + QSize minimumSizeHint() const { + return minimumSize(); + } + + public slots: + /** + * Resets the current list of modules and the displayed list of found entries. + */ + void reset(); + + protected: + /** + * Initializes the view of this widget. + */ + void initView(); + /** + * Initializes the signal slot conections of the child widgets + */ + void initConnections(); + /** + * This function breakes the queryString into clucene tokens + */ + QStringList QueryParser(const QString& queryString); + /** + * This function highlights the searched text in the content using the search type given by search flags + */ + QString highlightSearchedText(const QString& content, const QString& searchedText); + + /** + * Load the settings from the resource file + */ + void loadDialogSettings(); + /** + * Save the settings to the resource file + */ + void saveDialogSettings(); + + protected slots: + /** + * Update the preview of the selected key. + */ + void updatePreview(const QString& key); + /** + * Clear the preview of the selected key. + */ + void clearPreview(); + /** + * Shows a dialog with the search analysis of the current search. + */ + void showAnalysis(); + + private: + + CModuleResultView* m_moduleListBox; + CSearchResultView* m_resultListBox; + + QFrame *m_displayFrame; + CReadDisplay* m_previewDisplay; + + QList<CSwordModuleInfo*> m_modules; + + QSplitter *mainSplitter; + QSplitter *resultListSplitter; }; } //namespace Search diff --git a/src/frontend/searchdialog/chistorycombobox.cpp b/src/frontend/searchdialog/chistorycombobox.cpp index 953d9f3..ea854dc 100644 --- a/src/frontend/searchdialog/chistorycombobox.cpp +++ b/src/frontend/searchdialog/chistorycombobox.cpp @@ -14,35 +14,30 @@ namespace Search { CHistoryComboBox::CHistoryComboBox( QWidget* parent) - : QComboBox(parent) -{ - setEditable(true); - completer()->setCompletionMode(QCompleter::PopupCompletion); + : QComboBox(parent) { + setEditable(true); + completer()->setCompletionMode(QCompleter::PopupCompletion); } -CHistoryComboBox::~CHistoryComboBox() -{ +CHistoryComboBox::~CHistoryComboBox() { } -void CHistoryComboBox::addToHistory(const QString& text) -{ - int index = findText(text); - if ( index >= 0) - removeItem(index); - insertItem(1, text); - setCurrentIndex(1); +void CHistoryComboBox::addToHistory(const QString& text) { + int index = findText(text); + if ( index >= 0) + removeItem(index); + insertItem(1, text); + setCurrentIndex(1); } -QStringList CHistoryComboBox::historyItems() const -{ - QStringList items; - for (int i=0; i<count(); i++) - { - QString text = itemText(i); - if (text.size() > 0) - items << text; - } - return items; +QStringList CHistoryComboBox::historyItems() const { + QStringList items; + for (int i = 0; i < count(); i++) { + QString text = itemText(i); + if (text.size() > 0) + items << text; + } + return items; } } //end of namespace Search diff --git a/src/frontend/searchdialog/chistorycombobox.h b/src/frontend/searchdialog/chistorycombobox.h index 967c045..d2828d8 100644 --- a/src/frontend/searchdialog/chistorycombobox.h +++ b/src/frontend/searchdialog/chistorycombobox.h @@ -14,18 +14,17 @@ namespace Search { -class CHistoryComboBox : public QComboBox -{ - Q_OBJECT -public: - CHistoryComboBox(QWidget* parent = 0); - ~CHistoryComboBox(); - void addToHistory(const QString& item); - QStringList historyItems() const; - -protected: - -private: +class CHistoryComboBox : public QComboBox { + Q_OBJECT + public: + CHistoryComboBox(QWidget* parent = 0); + ~CHistoryComboBox(); + void addToHistory(const QString& item); + QStringList historyItems() const; + + protected: + + private: }; } //end of namespace Search diff --git a/src/frontend/searchdialog/cmoduleresultview.cpp b/src/frontend/searchdialog/cmoduleresultview.cpp index 6c3053f..f243a61 100644 --- a/src/frontend/searchdialog/cmoduleresultview.cpp +++ b/src/frontend/searchdialog/cmoduleresultview.cpp @@ -34,262 +34,248 @@ namespace Search { ************ ModuleResultList ************** ********************************************/ -CModuleResultView::CModuleResultView(QWidget* parent) - : QTreeWidget(parent), - strongsResults(0) -{ - initView(); - initConnections(); +CModuleResultView::CModuleResultView(QWidget* parent) + : QTreeWidget(parent), + strongsResults(0) { + initView(); + initConnections(); } -CModuleResultView::~CModuleResultView() -{} +CModuleResultView::~CModuleResultView() {} /** Initializes this widget. */ -void CModuleResultView::initView() -{ - // see also csearchresultview.cpp - setToolTip(tr("Works chosen for the search and the number of the hits in each work")); - setHeaderLabels( QStringList(tr("Work")) << tr("Hits") ); - - setColumnWidth(0, CToolClass::mWidth(this, 8)); - setColumnWidth(1, CToolClass::mWidth(this, 4)); - QSize sz(CToolClass::mWidth(this, 13), CToolClass::mWidth(this, 5)); - //setMinimumSize(sz); - m_size = sz; - //TODO: sorting - //setSorting(0, true); - //setSorting(1, true); - - //setup the popup menu - m_popup = new QMenu(this); - - m_actions.copyMenu = new QMenu(tr("Copy..."), m_popup); - m_actions.copyMenu->setIcon(util::filesystem::DirectoryUtil::getIcon( CResMgr::searchdialog::result::moduleList::copyMenu::icon) ); - m_actions.copy.result = new QAction(tr("Reference only"), this); - QObject::connect(m_actions.copy.result, SIGNAL(triggered()), this, SLOT(copyResult()) ); - m_actions.copyMenu->addAction(m_actions.copy.result); - m_actions.copy.resultWithText = new QAction(tr("Reference with text"), this); - QObject::connect(m_actions.copy.resultWithText, SIGNAL(triggered()), this, SLOT(copyResultWithText()) ); - m_actions.copyMenu->addAction(m_actions.copy.resultWithText); - m_popup->addMenu(m_actions.copyMenu); - - m_actions.saveMenu = new QMenu(tr("Save..."), m_popup); - m_actions.saveMenu->setIcon(util::filesystem::DirectoryUtil::getIcon( CResMgr::searchdialog::result::moduleList::saveMenu::icon) ); - m_actions.save.result = new QAction(tr("Reference only"), this); - QObject::connect(m_actions.save.result, SIGNAL(triggered()), this, SLOT(saveResult()) ); - m_actions.saveMenu->addAction(m_actions.save.result); - m_actions.save.resultWithText = new QAction(tr("Reference with text"), this); - QObject::connect(m_actions.save.resultWithText, SIGNAL(triggered()), this, SLOT(saveResultWithText()) ); - m_actions.saveMenu->addAction(m_actions.save.resultWithText); - m_popup->addMenu(m_actions.saveMenu); - - m_actions.printMenu = new QMenu(tr("Print..."), m_popup); - m_actions.printMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::result::moduleList::printMenu::icon)); - m_actions.print.result = new QAction(tr("Reference with text"), this); - QObject::connect(m_actions.print.result, SIGNAL(triggered()), this, SLOT(printResult()) ); - m_actions.printMenu->addAction(m_actions.print.result); - m_popup->addMenu(m_actions.printMenu); +void CModuleResultView::initView() { + // see also csearchresultview.cpp + setToolTip(tr("Works chosen for the search and the number of the hits in each work")); + setHeaderLabels( QStringList(tr("Work")) << tr("Hits") ); + + setColumnWidth(0, CToolClass::mWidth(this, 8)); + setColumnWidth(1, CToolClass::mWidth(this, 4)); + QSize sz(CToolClass::mWidth(this, 13), CToolClass::mWidth(this, 5)); + //setMinimumSize(sz); + m_size = sz; + //TODO: sorting + //setSorting(0, true); + //setSorting(1, true); + + //setup the popup menu + m_popup = new QMenu(this); + + m_actions.copyMenu = new QMenu(tr("Copy..."), m_popup); + m_actions.copyMenu->setIcon(util::filesystem::DirectoryUtil::getIcon( CResMgr::searchdialog::result::moduleList::copyMenu::icon) ); + m_actions.copy.result = new QAction(tr("Reference only"), this); + QObject::connect(m_actions.copy.result, SIGNAL(triggered()), this, SLOT(copyResult()) ); + m_actions.copyMenu->addAction(m_actions.copy.result); + m_actions.copy.resultWithText = new QAction(tr("Reference with text"), this); + QObject::connect(m_actions.copy.resultWithText, SIGNAL(triggered()), this, SLOT(copyResultWithText()) ); + m_actions.copyMenu->addAction(m_actions.copy.resultWithText); + m_popup->addMenu(m_actions.copyMenu); + + m_actions.saveMenu = new QMenu(tr("Save..."), m_popup); + m_actions.saveMenu->setIcon(util::filesystem::DirectoryUtil::getIcon( CResMgr::searchdialog::result::moduleList::saveMenu::icon) ); + m_actions.save.result = new QAction(tr("Reference only"), this); + QObject::connect(m_actions.save.result, SIGNAL(triggered()), this, SLOT(saveResult()) ); + m_actions.saveMenu->addAction(m_actions.save.result); + m_actions.save.resultWithText = new QAction(tr("Reference with text"), this); + QObject::connect(m_actions.save.resultWithText, SIGNAL(triggered()), this, SLOT(saveResultWithText()) ); + m_actions.saveMenu->addAction(m_actions.save.resultWithText); + m_popup->addMenu(m_actions.saveMenu); + + m_actions.printMenu = new QMenu(tr("Print..."), m_popup); + m_actions.printMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::result::moduleList::printMenu::icon)); + m_actions.print.result = new QAction(tr("Reference with text"), this); + QObject::connect(m_actions.print.result, SIGNAL(triggered()), this, SLOT(printResult()) ); + m_actions.printMenu->addAction(m_actions.print.result); + m_popup->addMenu(m_actions.printMenu); } /** Initializes the connections of this widget, */ -void CModuleResultView::initConnections() -{ - //TODO: - connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), - this, SLOT(executed(QTreeWidgetItem*, QTreeWidgetItem*))); +void CModuleResultView::initConnections() { + //TODO: + connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), + this, SLOT(executed(QTreeWidgetItem*, QTreeWidgetItem*))); } /** Setups the tree using the given list of modules. */ -void CModuleResultView::setupTree( QList<CSwordModuleInfo*> modules, const QString& searchedText ) -{ - clear(); - //TODO: this class is for sorting - //util::CSortListViewItem* item = 0; - //util::CSortListViewItem* oldItem = 0; - QTreeWidgetItem* item = 0; - QTreeWidgetItem* oldItem = 0; - - sword::ListKey result; - - if (strongsResults) { - delete strongsResults; - strongsResults = 0; - } - - bool strongsAvailable = false; - - QList<CSwordModuleInfo*>::iterator end_it = modules.end(); - for (QList<CSwordModuleInfo*>::iterator it(modules.begin()); it != end_it; ++it) { - // for (modules.first(); modules.current(); modules.next()) { - result = (*it)->searchResult(); - - item = new QTreeWidgetItem(this, QStringList((*it)->name()) << QString::number(result.Count()) ); - //TODO: item->setColumnSorting(1, util::CSortListViewItem::Number); - - item->setIcon(0,CToolClass::getIconForModule(*it) ); - oldItem = item; - //---------------------------------------------------------------------- - // we need to make a decision here. Either don't show any Strong's - // number translations, or show the first one in the search text, or - // figure out how to show them all. - // I choose option number 2 at this time. - //---------------------------------------------------------------------- - int sstIndex, sTokenIndex; // strong search text index for finding "strong:" - if ((sstIndex = searchedText.indexOf("strong:", 0)) != -1) { - QString sNumber; - //-------------------------------------------------- - // get the strongs number from the search text - //-------------------------------------------------- - // first find the first space after "strong:" - // this should indicate a change in search token - sstIndex = sstIndex + 7; - sTokenIndex = searchedText.indexOf(" ", sstIndex); - sNumber = searchedText.mid(sstIndex, sTokenIndex - sstIndex); - - setupStrongsResults((*it), item, sNumber); - - //TODO: item->setOpen(true); - strongsAvailable = true; - } - }; - - //Allow to hide the module strongs if there are any available - setRootIsDecorated( strongsAvailable ); +void CModuleResultView::setupTree( QList<CSwordModuleInfo*> modules, const QString& searchedText ) { + clear(); + //TODO: this class is for sorting + //util::CSortListViewItem* item = 0; + //util::CSortListViewItem* oldItem = 0; + QTreeWidgetItem* item = 0; + QTreeWidgetItem* oldItem = 0; + + sword::ListKey result; + + if (strongsResults) { + delete strongsResults; + strongsResults = 0; + } + + bool strongsAvailable = false; + + QList<CSwordModuleInfo*>::iterator end_it = modules.end(); + for (QList<CSwordModuleInfo*>::iterator it(modules.begin()); it != end_it; ++it) { + // for (modules.first(); modules.current(); modules.next()) { + result = (*it)->searchResult(); + + item = new QTreeWidgetItem(this, QStringList((*it)->name()) << QString::number(result.Count()) ); + //TODO: item->setColumnSorting(1, util::CSortListViewItem::Number); + + item->setIcon(0, CToolClass::getIconForModule(*it) ); + oldItem = item; + //---------------------------------------------------------------------- + // we need to make a decision here. Either don't show any Strong's + // number translations, or show the first one in the search text, or + // figure out how to show them all. + // I choose option number 2 at this time. + //---------------------------------------------------------------------- + int sstIndex, sTokenIndex; // strong search text index for finding "strong:" + if ((sstIndex = searchedText.indexOf("strong:", 0)) != -1) { + QString sNumber; + //-------------------------------------------------- + // get the strongs number from the search text + //-------------------------------------------------- + // first find the first space after "strong:" + // this should indicate a change in search token + sstIndex = sstIndex + 7; + sTokenIndex = searchedText.indexOf(" ", sstIndex); + sNumber = searchedText.mid(sstIndex, sTokenIndex - sstIndex); + + setupStrongsResults((*it), item, sNumber); + + //TODO: item->setOpen(true); + strongsAvailable = true; + } + }; + + //Allow to hide the module strongs if there are any available + setRootIsDecorated( strongsAvailable ); } void CModuleResultView::setupStrongsResults(CSwordModuleInfo* module, QTreeWidgetItem* parent, - const QString& sNumber) -{ - QString lText; - //TODO: - //util::CSortListViewItem* item = 0; - QTreeWidgetItem* item = 0; - - strongsResults = new StrongsResultClass(module, sNumber); - - for (int cnt = 0; cnt < strongsResults->Count(); ++cnt) { - lText = strongsResults->keyText(cnt); - - item = new QTreeWidgetItem(parent, QStringList(lText) << QString::number(strongsResults->keyCount(cnt))); - //TODO: - //item->setColumnSorting(1, util::CSortListViewItem::Number); - } + const QString& sNumber) { + QString lText; + //TODO: + //util::CSortListViewItem* item = 0; + QTreeWidgetItem* item = 0; + + strongsResults = new StrongsResultClass(module, sNumber); + + for (int cnt = 0; cnt < strongsResults->Count(); ++cnt) { + lText = strongsResults->keyText(cnt); + + item = new QTreeWidgetItem(parent, QStringList(lText) << QString::number(strongsResults->keyCount(cnt))); + //TODO: + //item->setColumnSorting(1, util::CSortListViewItem::Number); + } } //TODO: /** Is executed when an item was selected in the list. */ -void CModuleResultView::executed( QTreeWidgetItem* i, QTreeWidgetItem*) -{ +void CModuleResultView::executed( QTreeWidgetItem* i, QTreeWidgetItem*) { QString itemText, lText; - - if (!i){ - //Clear list - emit moduleChanged(); - return; - } - if (CSwordModuleInfo* m = CPointers::backend()->findModuleByName(i->text(0))) { - emit moduleChanged(); - emit moduleSelected(m); - return; - } - - if (!strongsResults) { - return; - } - - itemText = i->text(0); - for (int cnt = 0; cnt < strongsResults->Count(); cnt++) { - lText = strongsResults->keyText(cnt); - if (lText == itemText) { - //clear the verses list - emit moduleChanged(); - emit strongsSelected(activeModule(), strongsResults->getKeyList(cnt)); - return; - } - } + + if (!i) { + //Clear list + emit moduleChanged(); + return; + } + if (CSwordModuleInfo* m = CPointers::backend()->findModuleByName(i->text(0))) { + emit moduleChanged(); + emit moduleSelected(m); + return; + } + + if (!strongsResults) { + return; + } + + itemText = i->text(0); + for (int cnt = 0; cnt < strongsResults->Count(); cnt++) { + lText = strongsResults->keyText(cnt); + if (lText == itemText) { + //clear the verses list + emit moduleChanged(); + emit strongsSelected(activeModule(), strongsResults->getKeyList(cnt)); + return; + } + } } /** Returns the currently active module. */ -CSwordModuleInfo* CModuleResultView::activeModule() -{ - Q_ASSERT(currentItem()); - - QTreeWidgetItem* item = currentItem(); - if (!item) { - return 0; - } - - // we need to find the parent most node because that is the node - // that is the module name. - while (item->parent()) { - item = item->parent(); - } - - if (item) { - return CPointers::backend()->findModuleByName(item->text(0)); - } - - return 0; +CSwordModuleInfo* CModuleResultView::activeModule() { + Q_ASSERT(currentItem()); + + QTreeWidgetItem* item = currentItem(); + if (!item) { + return 0; + } + + // we need to find the parent most node because that is the node + // that is the module name. + while (item->parent()) { + item = item->parent(); + } + + if (item) { + return CPointers::backend()->findModuleByName(item->text(0)); + } + + return 0; } /** Reimplementation from QWidget. */ -void CModuleResultView::contextMenuEvent( QContextMenuEvent * event ) -{ - qDebug("CModuleResultView::showPopup"); - //make sure that all entries have the correct status - m_popup->exec(event->globalPos()); +void CModuleResultView::contextMenuEvent( QContextMenuEvent * event ) { + qDebug("CModuleResultView::showPopup"); + //make sure that all entries have the correct status + m_popup->exec(event->globalPos()); } /** Copies the whole search result into the clipboard. */ -void CModuleResultView::copyResult() -{ - if (CSwordModuleInfo* m = activeModule()) { - sword::ListKey result = m->searchResult(); - CExportManager mgr(tr("Copy search result..."), true, tr("Copying search result")); - mgr.copyKeyList(&result,m,CExportManager::Text,false); - }; +void CModuleResultView::copyResult() { + if (CSwordModuleInfo* m = activeModule()) { + sword::ListKey result = m->searchResult(); + CExportManager mgr(tr("Copy search result..."), true, tr("Copying search result")); + mgr.copyKeyList(&result, m, CExportManager::Text, false); + }; } /** Copies the whole search result with the text into the clipboard. */ -void CModuleResultView::copyResultWithText() -{ - if (CSwordModuleInfo* m = activeModule()) { - sword::ListKey result = m->searchResult(); - CExportManager mgr(tr("Copy search result..."), true, tr("Copying search result")); - mgr.copyKeyList(&result,m,CExportManager::Text,true); - }; +void CModuleResultView::copyResultWithText() { + if (CSwordModuleInfo* m = activeModule()) { + sword::ListKey result = m->searchResult(); + CExportManager mgr(tr("Copy search result..."), true, tr("Copying search result")); + mgr.copyKeyList(&result, m, CExportManager::Text, true); + }; } /** Saves the search result keys. */ -void CModuleResultView::saveResult() -{ - if (CSwordModuleInfo* m = activeModule()) { - sword::ListKey result = m->searchResult(); - CExportManager mgr(tr("Save search result..."), true, tr("Saving search result")); - mgr.saveKeyList(&result,m,CExportManager::Text,false); - }; +void CModuleResultView::saveResult() { + if (CSwordModuleInfo* m = activeModule()) { + sword::ListKey result = m->searchResult(); + CExportManager mgr(tr("Save search result..."), true, tr("Saving search result")); + mgr.saveKeyList(&result, m, CExportManager::Text, false); + }; } /** Saves the search result with it's text. */ -void CModuleResultView::saveResultWithText() -{ - if (CSwordModuleInfo* m = activeModule()) { - sword::ListKey result = m->searchResult(); - CExportManager mgr(tr("Save search result..."), true, tr("Saving search result")); - mgr.saveKeyList(&result,m,CExportManager::Text,true); - }; +void CModuleResultView::saveResultWithText() { + if (CSwordModuleInfo* m = activeModule()) { + sword::ListKey result = m->searchResult(); + CExportManager mgr(tr("Save search result..."), true, tr("Saving search result")); + mgr.saveKeyList(&result, m, CExportManager::Text, true); + }; } /** Appends the whole search result to the printer queue. */ -void CModuleResultView::printResult() -{ - if (CSwordModuleInfo* m = activeModule()) { - sword::ListKey result = m->searchResult(); - CExportManager mgr(tr("Print search result..."), true, tr("Printing search result")); - mgr.printKeyList(&result,m,CBTConfig::getDisplayOptionDefaults(), CBTConfig::getFilterOptionDefaults()); - }; +void CModuleResultView::printResult() { + if (CSwordModuleInfo* m = activeModule()) { + sword::ListKey result = m->searchResult(); + CExportManager mgr(tr("Print search result..."), true, tr("Printing search result")); + mgr.printKeyList(&result, m, CBTConfig::getDisplayOptionDefaults(), CBTConfig::getFilterOptionDefaults()); + }; } diff --git a/src/frontend/searchdialog/cmoduleresultview.h b/src/frontend/searchdialog/cmoduleresultview.h index c23d254..4295f82 100644 --- a/src/frontend/searchdialog/cmoduleresultview.h +++ b/src/frontend/searchdialog/cmoduleresultview.h @@ -36,98 +36,100 @@ namespace Search { class CModuleResultView : public QTreeWidget { - Q_OBJECT -public: - CModuleResultView(QWidget* parent); - ~CModuleResultView(); - - /** - * Setups the tree using the given list of modules. - */ - void setupTree( QList<CSwordModuleInfo*> modules, const QString& searchedText ); - /** - * Returns the currently active module. - */ - CSwordModuleInfo* activeModule(); - - virtual QSize sizeHint() {return m_size;} - -protected: - /** - * Initializes this widget. - */ - void initView(); - /** - * Initializes the connections of this widget - */ - void initConnections(); - - - void setupStrongsResults(CSwordModuleInfo* module, QTreeWidgetItem* parent, const QString& searchedText); - -protected slots: - /** - * Is executed when an item was selected in the list. - */ - void executed(QTreeWidgetItem*, QTreeWidgetItem*); - /** - * Copies the whole search result with the text into the clipboard. - */ - void copyResultWithText(); - /** - * Copies the whole search result into the clipboard. - */ - void copyResult(); - /** - * This event handler (reimplemented from QWidget) opens the popup menu at the given position. - */ - void contextMenuEvent( QContextMenuEvent * event ); - /** - * Appends the whole search result to the printer queue. - */ - void printResult(); - /** - * Saves the search result with it's text. - */ - void saveResultWithText(); - /** - * Saves the search result keys. - */ - void saveResult(); - -signals: - void moduleSelected(CSwordModuleInfo*); - void moduleChanged(); - void strongsSelected(CSwordModuleInfo*, QStringList*); - -private: - struct { - QMenu* saveMenu; - struct { - QAction* result; - QAction* resultWithText; - } - save; - - QMenu* printMenu; - struct { - QAction* result; - } - print; - - QMenu* copyMenu; - struct { - QAction* result; - QAction* resultWithText; - } - copy; - - } m_actions; - - QMenu* m_popup; - - StrongsResultClass* strongsResults; - QSize m_size; + Q_OBJECT + public: + CModuleResultView(QWidget* parent); + ~CModuleResultView(); + + /** + * Setups the tree using the given list of modules. + */ + void setupTree( QList<CSwordModuleInfo*> modules, const QString& searchedText ); + /** + * Returns the currently active module. + */ + CSwordModuleInfo* activeModule(); + + virtual QSize sizeHint() { + return m_size; + } + + protected: + /** + * Initializes this widget. + */ + void initView(); + /** + * Initializes the connections of this widget + */ + void initConnections(); + + + void setupStrongsResults(CSwordModuleInfo* module, QTreeWidgetItem* parent, const QString& searchedText); + + protected slots: + /** + * Is executed when an item was selected in the list. + */ + void executed(QTreeWidgetItem*, QTreeWidgetItem*); + /** + * Copies the whole search result with the text into the clipboard. + */ + void copyResultWithText(); + /** + * Copies the whole search result into the clipboard. + */ + void copyResult(); + /** + * This event handler (reimplemented from QWidget) opens the popup menu at the given position. + */ + void contextMenuEvent( QContextMenuEvent * event ); + /** + * Appends the whole search result to the printer queue. + */ + void printResult(); + /** + * Saves the search result with it's text. + */ + void saveResultWithText(); + /** + * Saves the search result keys. + */ + void saveResult(); + + signals: + void moduleSelected(CSwordModuleInfo*); + void moduleChanged(); + void strongsSelected(CSwordModuleInfo*, QStringList*); + + private: + struct { + QMenu* saveMenu; + struct { + QAction* result; + QAction* resultWithText; + } + save; + + QMenu* printMenu; + struct { + QAction* result; + } + print; + + QMenu* copyMenu; + struct { + QAction* result; + QAction* resultWithText; + } + copy; + + } m_actions; + + QMenu* m_popup; + + StrongsResultClass* strongsResults; + QSize m_size; }; diff --git a/src/frontend/searchdialog/crangechooserdialog.cpp b/src/frontend/searchdialog/crangechooserdialog.cpp index 92a8dc0..58175f9 100644 --- a/src/frontend/searchdialog/crangechooserdialog.cpp +++ b/src/frontend/searchdialog/crangechooserdialog.cpp @@ -37,123 +37,119 @@ namespace Search { /********** RangeItem ******************/ -CRangeChooserDialog::RangeItem::RangeItem(QListWidget* view, QListWidgetItem* /*afterThis*/, const QString caption, const QString range) - : QListWidgetItem(view) -{ - setCaption(caption); - setRange(range); +CRangeChooserDialog::RangeItem::RangeItem(QListWidget* view, QListWidgetItem* /*afterThis*/, const QString caption, const QString range) + : QListWidgetItem(view) { + setCaption(caption); + setRange(range); } CRangeChooserDialog::RangeItem::~RangeItem() {} -const QString& CRangeChooserDialog::RangeItem::range() const -{ - // qWarning("range is %s", (const char*)m_range.utf8()); - return m_range; +const QString& CRangeChooserDialog::RangeItem::range() const { + // qWarning("range is %s", (const char*)m_range.utf8()); + return m_range; } void CRangeChooserDialog::RangeItem::setRange(QString newRange) { - m_range = newRange; + m_range = newRange; } QString CRangeChooserDialog::RangeItem::caption() const { - return text(); + return text(); } void CRangeChooserDialog::RangeItem::setCaption(const QString newCaption) { - setText(newCaption); + setText(newCaption); } /*********** Dialog ***************/ CRangeChooserDialog::CRangeChooserDialog( QWidget* parentDialog ) - : QDialog(parentDialog) -{ - //Set the flag to destroy when closed - otherwise eats memory - setAttribute(Qt::WA_DeleteOnClose); - initView(); - initConnections(); - - //add the existing scopes - CBTConfig::StringMap map = CBTConfig::get - (CBTConfig::searchScopes); - CBTConfig::StringMap::Iterator it; - for (it = map.begin(); it != map.end(); ++it) { - new RangeItem(m_rangeList, 0, it.key(), it.value()); - }; - - editRange(0); - if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem()) - ) { - nameChanged(i->caption()); - } + : QDialog(parentDialog) { + //Set the flag to destroy when closed - otherwise eats memory + setAttribute(Qt::WA_DeleteOnClose); + initView(); + initConnections(); + + //add the existing scopes + CBTConfig::StringMap map = CBTConfig::get + (CBTConfig::searchScopes); + CBTConfig::StringMap::Iterator it; + for (it = map.begin(); it != map.end(); ++it) { + new RangeItem(m_rangeList, 0, it.key(), it.value()); + }; + + editRange(0); + if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem()) + ) { + nameChanged(i->caption()); + } } /** Initializes the view of this object. */ -void CRangeChooserDialog::initView() -{ - setWindowTitle(tr("Setup Search Scopes")); +void CRangeChooserDialog::initView() { + setWindowTitle(tr("Setup Search Scopes")); - QVBoxLayout* vboxLayout = new QVBoxLayout(this); + QVBoxLayout* vboxLayout = new QVBoxLayout(this); - QHBoxLayout* hboxLayout = new QHBoxLayout(); - QVBoxLayout* vboxLayout1 = new QVBoxLayout(); - QLabel* rangeListLabel = new QLabel(tr("S&earch range:"), this); - vboxLayout1->addWidget(rangeListLabel); + QHBoxLayout* hboxLayout = new QHBoxLayout(); + QVBoxLayout* vboxLayout1 = new QVBoxLayout(); + QLabel* rangeListLabel = new QLabel(tr("S&earch range:"), this); + vboxLayout1->addWidget(rangeListLabel); - m_rangeList = new QListWidget(this); - m_rangeList->setToolTip(tr("Select a scope from the list to edit the search ranges")); - vboxLayout1->addWidget(m_rangeList); + m_rangeList = new QListWidget(this); + m_rangeList->setToolTip(tr("Select a scope from the list to edit the search ranges")); + vboxLayout1->addWidget(m_rangeList); - QHBoxLayout* hboxLayout1 = new QHBoxLayout(); - m_newRangeButton = new QPushButton(tr("&Add new scope"), this); - m_newRangeButton->setToolTip(tr("Add a new search scope. First enter an appropriate name, then edit the search ranges.")); - hboxLayout1->addWidget(m_newRangeButton); - m_deleteRangeButton = new QPushButton(tr("Delete current &scope"), this); - m_deleteRangeButton->setToolTip(tr("Delete the selected search scope")); - hboxLayout1->addWidget(m_deleteRangeButton); + QHBoxLayout* hboxLayout1 = new QHBoxLayout(); + m_newRangeButton = new QPushButton(tr("&Add new scope"), this); + m_newRangeButton->setToolTip(tr("Add a new search scope. First enter an appropriate name, then edit the search ranges.")); + hboxLayout1->addWidget(m_newRangeButton); + m_deleteRangeButton = new QPushButton(tr("Delete current &scope"), this); + m_deleteRangeButton->setToolTip(tr("Delete the selected search scope")); + hboxLayout1->addWidget(m_deleteRangeButton); - vboxLayout1->addLayout(hboxLayout1); - hboxLayout->addLayout(vboxLayout1); + vboxLayout1->addLayout(hboxLayout1); + hboxLayout->addLayout(vboxLayout1); - QVBoxLayout* vboxLayout2 = new QVBoxLayout(); - QHBoxLayout* hboxLayout2 = new QHBoxLayout(); - QLabel* nameEditLabel = new QLabel(tr("&Name:"), this); - hboxLayout2->addWidget(nameEditLabel); + QVBoxLayout* vboxLayout2 = new QVBoxLayout(); + QHBoxLayout* hboxLayout2 = new QHBoxLayout(); + QLabel* nameEditLabel = new QLabel(tr("&Name:"), this); + hboxLayout2->addWidget(nameEditLabel); - m_nameEdit = new QLineEdit(this); - m_nameEdit->setToolTip(tr("Change the name of the selected search scope")); - hboxLayout2->addWidget(m_nameEdit); - vboxLayout2->addLayout(hboxLayout2); + m_nameEdit = new QLineEdit(this); + m_nameEdit->setToolTip(tr("Change the name of the selected search scope")); + hboxLayout2->addWidget(m_nameEdit); + vboxLayout2->addLayout(hboxLayout2); - QLabel* rangeEditLabel = new QLabel(tr("Edi&t current range:"), this); - vboxLayout2->addWidget(rangeEditLabel); + QLabel* rangeEditLabel = new QLabel(tr("Edi&t current range:"), this); + vboxLayout2->addWidget(rangeEditLabel); - m_rangeEdit = new QTextEdit(this); - m_rangeEdit->setToolTip(tr("Change the search ranges of the selected search scope item. Have a look at the predefined search scopes to see how search ranges are constructed.")); + m_rangeEdit = new QTextEdit(this); + m_rangeEdit->setToolTip(tr("Change the search ranges of the selected search scope item. Have a look at the predefined search scopes to see how search ranges are constructed.")); - vboxLayout2->addWidget(m_rangeEdit); + vboxLayout2->addWidget(m_rangeEdit); - QLabel* resultListLabel = new QLabel(tr("Parsed search range:"), this); + QLabel* resultListLabel = new QLabel(tr("Parsed search range:"), this); vboxLayout2->addWidget(resultListLabel); - m_resultList = new QListWidget(this); - m_resultList->setToolTip(tr("The search ranges which will be used for the search, parsed to the canonical form")); - vboxLayout2->addWidget(m_resultList); + m_resultList = new QListWidget(this); + m_resultList->setToolTip(tr("The search ranges which will be used for the search, parsed to the canonical form")); + vboxLayout2->addWidget(m_resultList); - hboxLayout->addLayout(vboxLayout2); - vboxLayout->addLayout(hboxLayout); + hboxLayout->addLayout(vboxLayout2); + vboxLayout->addLayout(hboxLayout); - QFrame* line = new QFrame(this); - line->setFrameShape(QFrame::HLine); - line->setFrameShadow(QFrame::Sunken); - vboxLayout->addWidget(line); + QFrame* line = new QFrame(this); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + vboxLayout->addWidget(line); m_buttonBox = new QDialogButtonBox(this); m_buttonBox->setOrientation(Qt::Horizontal); - m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults); - util::prepareDialogBox(m_buttonBox); + m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::NoButton | QDialogButtonBox::Ok | QDialogButtonBox::RestoreDefaults); + util::prepareDialogBox(m_buttonBox); vboxLayout->addWidget(m_buttonBox); rangeListLabel->setBuddy(m_rangeList); @@ -164,165 +160,156 @@ void CRangeChooserDialog::initView() -void CRangeChooserDialog::initConnections() -{ - // Signals from text/list widgets - QObject::connect(m_rangeList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), - this, SLOT(editRange(QListWidgetItem*))); +void CRangeChooserDialog::initConnections() { + // Signals from text/list widgets + QObject::connect(m_rangeList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), + this, SLOT(editRange(QListWidgetItem*))); - QObject::connect(m_rangeEdit, SIGNAL(textChanged()), - this, SLOT(parseRange())); - QObject::connect(m_rangeEdit, SIGNAL(textChanged()), - this, SLOT(rangeChanged())); + QObject::connect(m_rangeEdit, SIGNAL(textChanged()), + this, SLOT(parseRange())); + QObject::connect(m_rangeEdit, SIGNAL(textChanged()), + this, SLOT(rangeChanged())); - QObject::connect(m_nameEdit, SIGNAL(textChanged(const QString&)), - this, SLOT(nameChanged(const QString&))); + QObject::connect(m_nameEdit, SIGNAL(textChanged(const QString&)), + this, SLOT(nameChanged(const QString&))); - // Buttons - QObject::connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(slotOk())); - QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(close())); - QObject::connect(m_newRangeButton, SIGNAL(clicked()), this, SLOT(addNewRange())); - QObject::connect(m_deleteRangeButton, SIGNAL(clicked()), this, SLOT(deleteCurrentRange())); - //restore defaults! - QPushButton* defaultsButton = m_buttonBox->button(QDialogButtonBox::RestoreDefaults); - QObject::connect(defaultsButton, SIGNAL(clicked()), this, SLOT(slotDefault())); + // Buttons + QObject::connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(slotOk())); + QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(close())); + QObject::connect(m_newRangeButton, SIGNAL(clicked()), this, SLOT(addNewRange())); + QObject::connect(m_deleteRangeButton, SIGNAL(clicked()), this, SLOT(deleteCurrentRange())); + //restore defaults! + QPushButton* defaultsButton = m_buttonBox->button(QDialogButtonBox::RestoreDefaults); + QObject::connect(defaultsButton, SIGNAL(clicked()), this, SLOT(slotDefault())); } /** Adds a new range to the list. */ -void CRangeChooserDialog::addNewRange() -{ - //qDebug("CRangeChooserDialog::addNewRange"); - //RangeItem* i = new RangeItem(m_rangeList, m_rangeList->lastItem(), tr("New range")); - RangeItem* i = new RangeItem(m_rangeList, 0, tr("New range")); - //use just setCurrentItem... m_rangeList->setSelected(i, true); - m_rangeList->setCurrentItem(i); - editRange(i); - - m_nameEdit->setFocus(); +void CRangeChooserDialog::addNewRange() { + //qDebug("CRangeChooserDialog::addNewRange"); + //RangeItem* i = new RangeItem(m_rangeList, m_rangeList->lastItem(), tr("New range")); + RangeItem* i = new RangeItem(m_rangeList, 0, tr("New range")); + //use just setCurrentItem... m_rangeList->setSelected(i, true); + m_rangeList->setCurrentItem(i); + editRange(i); + + m_nameEdit->setFocus(); } /** No descriptions */ -void CRangeChooserDialog::editRange(QListWidgetItem* item) -{ - //qDebug("CRangeChooserDialog::editRange"); - RangeItem* const range = dynamic_cast<RangeItem*>(item); - - m_nameEdit->setEnabled( range ); //only if an item is selected enable the edit part - m_rangeEdit->setEnabled( range ); - m_resultList->setEnabled( range ); - m_deleteRangeButton->setEnabled( range ); - - if (range) { - m_nameEdit->setText(range->caption()); - m_rangeEdit->setText(range->range()); - } +void CRangeChooserDialog::editRange(QListWidgetItem* item) { + //qDebug("CRangeChooserDialog::editRange"); + RangeItem* const range = dynamic_cast<RangeItem*>(item); + + m_nameEdit->setEnabled( range ); //only if an item is selected enable the edit part + m_rangeEdit->setEnabled( range ); + m_resultList->setEnabled( range ); + m_deleteRangeButton->setEnabled( range ); + + if (range) { + m_nameEdit->setText(range->caption()); + m_rangeEdit->setText(range->range()); + } } /** Parses the entered text and prints out the result in the list box below the edit area. */ -void CRangeChooserDialog::parseRange() -{ - //qDebug("CRangeChooserDialog::parseRange"); - m_resultList->clear(); - - //TODO: remove this hack: - //HACK: repair range to work with Sword 1.5.6 - QString range( m_rangeEdit->toPlainText() ); - range.replace(QRegExp("\\s{0,}-\\s{0,}"), "-" ); - - sword::VerseKey key; - sword::ListKey verses = key.ParseVerseList((const char*)range.toUtf8(), "Genesis 1:1", true); - for (int i = 0; i < verses.Count(); ++i) { - new QListWidgetItem(QString::fromUtf8(verses.GetElement(i)->getRangeText()), m_resultList ); - // qWarning("range=%s, text=%s",verses.GetElement(i)->getRangeText(), verses.GetElement(i)->getText() ); - } +void CRangeChooserDialog::parseRange() { + //qDebug("CRangeChooserDialog::parseRange"); + m_resultList->clear(); + + //TODO: remove this hack: + //HACK: repair range to work with Sword 1.5.6 + QString range( m_rangeEdit->toPlainText() ); + range.replace(QRegExp("\\s{0,}-\\s{0,}"), "-" ); + + sword::VerseKey key; + sword::ListKey verses = key.ParseVerseList((const char*)range.toUtf8(), "Genesis 1:1", true); + for (int i = 0; i < verses.Count(); ++i) { + new QListWidgetItem(QString::fromUtf8(verses.GetElement(i)->getRangeText()), m_resultList ); + // qWarning("range=%s, text=%s",verses.GetElement(i)->getRangeText(), verses.GetElement(i)->getText() ); + } } /** No descriptions */ -void CRangeChooserDialog::rangeChanged() -{ - //qDebug("CRangeChooserDialog::rangeChanged"); - if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem()) - ) { - QString range( m_rangeEdit->toPlainText() ); - //TODO: remove this hack: - //HACK: repair range to work with Sword 1.5.6 - range.replace(QRegExp("\\s{0,}-\\s{0,}"), "-" ); - i->setRange(range); - }; +void CRangeChooserDialog::rangeChanged() { + //qDebug("CRangeChooserDialog::rangeChanged"); + if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem()) + ) { + QString range( m_rangeEdit->toPlainText() ); + //TODO: remove this hack: + //HACK: repair range to work with Sword 1.5.6 + range.replace(QRegExp("\\s{0,}-\\s{0,}"), "-" ); + i->setRange(range); + }; } /** No descriptions */ -void CRangeChooserDialog::nameChanged(const QString& newCaption) -{ - //qDebug("CRangeChooserDialog::nameChanged"); - m_rangeEdit->setEnabled(!newCaption.isEmpty()); - m_resultList->setEnabled(!newCaption.isEmpty()); - //m_resultList->header()->setEnabled(!newCaption.isEmpty()); - - if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem()) - ) { - if (!newCaption.isEmpty()) { - //enable some items (see "else" below) - m_newRangeButton->setEnabled(true); - m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); - m_rangeList->setDisabled(false); - i->setCaption(newCaption); - } - else { //invalid name - i->setCaption(tr("<invalid name of search range>")); - //disable some items to prevent saving invalid range - m_newRangeButton->setEnabled(false); - m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); - m_rangeList->setDisabled(true); - }; - }; +void CRangeChooserDialog::nameChanged(const QString& newCaption) { + //qDebug("CRangeChooserDialog::nameChanged"); + m_rangeEdit->setEnabled(!newCaption.isEmpty()); + m_resultList->setEnabled(!newCaption.isEmpty()); + //m_resultList->header()->setEnabled(!newCaption.isEmpty()); + + if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem()) + ) { + if (!newCaption.isEmpty()) { + //enable some items (see "else" below) + m_newRangeButton->setEnabled(true); + m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + m_rangeList->setDisabled(false); + i->setCaption(newCaption); + } + else { //invalid name + i->setCaption(tr("<invalid name of search range>")); + //disable some items to prevent saving invalid range + m_newRangeButton->setEnabled(false); + m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + m_rangeList->setDisabled(true); + }; + }; } /** Deletes the selected range. */ -void CRangeChooserDialog::deleteCurrentRange() -{ - //qDebug("CRangeChooserDialog::deleteCurrentRange"); - if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem()) ) { - int row = m_rangeList->row(i); - m_rangeList->takeItem(row); - delete i; - } - editRange(m_rangeList->currentItem()); +void CRangeChooserDialog::deleteCurrentRange() { + //qDebug("CRangeChooserDialog::deleteCurrentRange"); + if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem()) ) { + int row = m_rangeList->row(i); + m_rangeList->takeItem(row); + delete i; + } + editRange(m_rangeList->currentItem()); } -void CRangeChooserDialog::slotOk() -{ - m_rangeList->sortItems(); //sorted first because the order will be saved - //save the new map of search scopes - CBTConfig::StringMap map; - for (int i = 0; i < m_rangeList->count(); i++){ - if ( RangeItem* item = dynamic_cast<RangeItem*>(m_rangeList->item(i)) ) { - map[item->caption()] = item->range(); - }; - } - CBTConfig::set - (CBTConfig::searchScopes, map); - - QDialog::accept(); +void CRangeChooserDialog::slotOk() { + m_rangeList->sortItems(); //sorted first because the order will be saved + //save the new map of search scopes + CBTConfig::StringMap map; + for (int i = 0; i < m_rangeList->count(); i++) { + if ( RangeItem* item = dynamic_cast<RangeItem*>(m_rangeList->item(i)) ) { + map[item->caption()] = item->range(); + }; + } + CBTConfig::set + (CBTConfig::searchScopes, map); + + QDialog::accept(); } -void CRangeChooserDialog::slotDefault() -{ - //qDebug("CRangeChooserDialog::slotDefault"); - m_rangeList->clear(); - CBTConfig::StringMap map = CBTConfig::getDefault(CBTConfig::searchScopes); - CBTConfig::StringMap::Iterator it; - for (it = map.begin(); it != map.end(); ++it) { - new RangeItem(m_rangeList, 0, it.key(), it.value()); - }; - m_rangeList->setCurrentItem(0); - - editRange(0); - if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem()) - ) { - nameChanged(i->caption()); - } +void CRangeChooserDialog::slotDefault() { + //qDebug("CRangeChooserDialog::slotDefault"); + m_rangeList->clear(); + CBTConfig::StringMap map = CBTConfig::getDefault(CBTConfig::searchScopes); + CBTConfig::StringMap::Iterator it; + for (it = map.begin(); it != map.end(); ++it) { + new RangeItem(m_rangeList, 0, it.key(), it.value()); + }; + m_rangeList->setCurrentItem(0); + + editRange(0); + if (RangeItem* i = dynamic_cast<RangeItem*>(m_rangeList->currentItem()) + ) { + nameChanged(i->caption()); + } } diff --git a/src/frontend/searchdialog/crangechooserdialog.h b/src/frontend/searchdialog/crangechooserdialog.h index 4859b15..8711eab 100644 --- a/src/frontend/searchdialog/crangechooserdialog.h +++ b/src/frontend/searchdialog/crangechooserdialog.h @@ -24,62 +24,61 @@ class QDialogButtonBox; namespace Search { -class CRangeChooserDialog : public QDialog -{ - Q_OBJECT -public: - CRangeChooserDialog(QWidget* parentDialog); - ~CRangeChooserDialog(){}; - -protected: // Protected methods -class RangeItem : public QListWidgetItem { -public: - RangeItem(QListWidget*, QListWidgetItem* afterThis = 0, const QString caption = QString::null, const QString range = QString::null); - ~RangeItem(); - const QString& range() const; - QString caption() const; - void setRange(QString range); - void setCaption(const QString); -private: - QString m_range; - }; - - /** - * Initializes the connections of this widget. - */ - void initConnections(); - /** - * Initializes the view of this object. - */ - void initView(); - -protected slots: // Protected slots - /** - * Adds a new range to the list. - */ - void addNewRange(); - void editRange(QListWidgetItem*); - /** - * Parses the entered text and prints out the result in the list box below the edit area. - */ - void parseRange(); - void nameChanged(const QString&); - void rangeChanged(); - /** - * Deletes the selected range. - */ - void deleteCurrentRange(); - virtual void slotDefault(); - virtual void slotOk(); - -private: - QListWidget* m_rangeList; - QListWidget* m_resultList; - QLineEdit* m_nameEdit; - QTextEdit* m_rangeEdit; - QPushButton* m_newRangeButton; - QPushButton* m_deleteRangeButton; - QDialogButtonBox* m_buttonBox; +class CRangeChooserDialog : public QDialog { + Q_OBJECT + public: + CRangeChooserDialog(QWidget* parentDialog); + ~CRangeChooserDialog() {}; + + protected: // Protected methods + class RangeItem : public QListWidgetItem { + public: + RangeItem(QListWidget*, QListWidgetItem* afterThis = 0, const QString caption = QString::null, const QString range = QString::null); + ~RangeItem(); + const QString& range() const; + QString caption() const; + void setRange(QString range); + void setCaption(const QString); + private: + QString m_range; + }; + + /** + * Initializes the connections of this widget. + */ + void initConnections(); + /** + * Initializes the view of this object. + */ + void initView(); + + protected slots: // Protected slots + /** + * Adds a new range to the list. + */ + void addNewRange(); + void editRange(QListWidgetItem*); + /** + * Parses the entered text and prints out the result in the list box below the edit area. + */ + void parseRange(); + void nameChanged(const QString&); + void rangeChanged(); + /** + * Deletes the selected range. + */ + void deleteCurrentRange(); + virtual void slotDefault(); + virtual void slotOk(); + + private: + QListWidget* m_rangeList; + QListWidget* m_resultList; + QLineEdit* m_nameEdit; + QTextEdit* m_rangeEdit; + QPushButton* m_newRangeButton; + QPushButton* m_deleteRangeButton; + QDialogButtonBox* m_buttonBox; }; diff --git a/src/frontend/searchdialog/csearchdialog.cpp b/src/frontend/searchdialog/csearchdialog.cpp index 5fd590e..221be09 100644 --- a/src/frontend/searchdialog/csearchdialog.cpp +++ b/src/frontend/searchdialog/csearchdialog.cpp @@ -37,267 +37,252 @@ namespace Search { static CSearchDialog* m_staticDialog = 0; -void CSearchDialog::openDialog(const QList<CSwordModuleInfo*> modules, const QString& searchText, QWidget* parentDialog) -{ - if (!m_staticDialog) { - m_staticDialog = new CSearchDialog(parentDialog); - }; - m_staticDialog->reset(); - - if (modules.count()) { - m_staticDialog->setModules(modules); - } - else { - m_staticDialog->showModulesSelector(); - } - - m_staticDialog->setSearchText(searchText); - if (m_staticDialog->isHidden()) { - m_staticDialog->show(); - } - - if (modules.count() && !searchText.isEmpty()) { - m_staticDialog->startSearch(); - } - // moved these to after the startSearch() because - // the progress dialog caused them to loose focus. - m_staticDialog->raise(); - m_staticDialog->activateWindow(); +void CSearchDialog::openDialog(const QList<CSwordModuleInfo*> modules, const QString& searchText, QWidget* parentDialog) { + if (!m_staticDialog) { + m_staticDialog = new CSearchDialog(parentDialog); + }; + m_staticDialog->reset(); + + if (modules.count()) { + m_staticDialog->setModules(modules); + } + else { + m_staticDialog->showModulesSelector(); + } + + m_staticDialog->setSearchText(searchText); + if (m_staticDialog->isHidden()) { + m_staticDialog->show(); + } + + if (modules.count() && !searchText.isEmpty()) { + m_staticDialog->startSearch(); + } + // moved these to after the startSearch() because + // the progress dialog caused them to loose focus. + m_staticDialog->raise(); + m_staticDialog->activateWindow(); } -CSearchDialog* CSearchDialog::getSearchDialog() -{ - Q_ASSERT(m_staticDialog); - return m_staticDialog; +CSearchDialog* CSearchDialog::getSearchDialog() { + Q_ASSERT(m_staticDialog); + return m_staticDialog; } CSearchDialog::CSearchDialog(QWidget *parent) - :QDialog(parent), /*m_searchButton(0),*/ m_closeButton(0), - m_searchResultArea(0), m_searchOptionsArea(0) -{ - setWindowIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::icon) ); - setWindowTitle(tr("Search")); - setAttribute(Qt::WA_DeleteOnClose); - m_searcher.connectFinished( this, SLOT(searchFinished())); - initView(); - initConnections(); + : QDialog(parent), /*m_searchButton(0),*/ m_closeButton(0), + m_searchResultArea(0), m_searchOptionsArea(0) { + setWindowIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::icon) ); + setWindowTitle(tr("Search")); + setAttribute(Qt::WA_DeleteOnClose); + m_searcher.connectFinished( this, SLOT(searchFinished())); + initView(); + initConnections(); } -CSearchDialog::~CSearchDialog() -{ - saveDialogSettings(); - m_staticDialog = 0; +CSearchDialog::~CSearchDialog() { + saveDialogSettings(); + m_staticDialog = 0; } /** Starts the search with the set modules and the set search text. */ -void CSearchDialog::startSearch() -{ - QString originalSearchText(m_searchOptionsArea->searchText()); - QString searchText(""); - - if (originalSearchText.isEmpty()) { - return; - } - - searchText = prepareSearchText(originalSearchText); - - // Insert search text into history list of combobox - m_searchOptionsArea->addToHistory(originalSearchText); - - // check that we have the indices we need for searching - if (!m_searcher.modulesHaveIndices( modules() ) ) { - int result = QMessageBox::question(this, tr("Missing indices"), - tr("One or more works need indexing before they can be searched.\n" - "This could take a long time. Proceed with indexing?"), - QMessageBox::Yes | QMessageBox::Default, - QMessageBox::No | QMessageBox::Escape); - // In SuSE 10.0 the result is the logical or of the button type, just like it is - // inputed into the QMessageBox. - if ( (result == (QMessageBox::Yes | QMessageBox::Default)) || - (result == QMessageBox::Yes) || (result == QMessageBox::Default) ) { - CModuleIndexDialog* dlg = CModuleIndexDialog::getInstance(); - dlg->indexUnindexedModules( modules() ); - } - else { - return; - } - } - - if (m_searchOptionsArea->hasSearchScope()) { - m_searcher.setSearchScope( m_searchOptionsArea->searchScope() ); - } - else { - m_searcher.resetSearchScope(); - } - - m_searcher.setModules( modules() ); - m_searcher.setSearchedText(searchText); - - - //Just to be sure that it can't be clicked again, if the search happens to be a bit slow. - m_searchOptionsArea->searchButton()->setEnabled(false); - m_searchOptionsArea->m_searchTextCombo->setEnabled(false); - - m_searcher.startSearch(); - - m_searchOptionsArea->searchButton()->setEnabled(true); - m_searchOptionsArea->m_searchTextCombo->setEnabled(true); - m_searchOptionsArea->m_searchTextCombo->setFocus(); +void CSearchDialog::startSearch() { + QString originalSearchText(m_searchOptionsArea->searchText()); + QString searchText(""); + + if (originalSearchText.isEmpty()) { + return; + } + + searchText = prepareSearchText(originalSearchText); + + // Insert search text into history list of combobox + m_searchOptionsArea->addToHistory(originalSearchText); + + // check that we have the indices we need for searching + if (!m_searcher.modulesHaveIndices( modules() ) ) { + int result = QMessageBox::question(this, tr("Missing indices"), + tr("One or more works need indexing before they can be searched.\n" + "This could take a long time. Proceed with indexing?"), + QMessageBox::Yes | QMessageBox::Default, + QMessageBox::No | QMessageBox::Escape); + // In SuSE 10.0 the result is the logical or of the button type, just like it is + // inputed into the QMessageBox. + if ( (result == (QMessageBox::Yes | QMessageBox::Default)) || + (result == QMessageBox::Yes) || (result == QMessageBox::Default) ) { + CModuleIndexDialog* dlg = CModuleIndexDialog::getInstance(); + dlg->indexUnindexedModules( modules() ); + } + else { + return; + } + } + + if (m_searchOptionsArea->hasSearchScope()) { + m_searcher.setSearchScope( m_searchOptionsArea->searchScope() ); + } + else { + m_searcher.resetSearchScope(); + } + + m_searcher.setModules( modules() ); + m_searcher.setSearchedText(searchText); + + + //Just to be sure that it can't be clicked again, if the search happens to be a bit slow. + m_searchOptionsArea->searchButton()->setEnabled(false); + m_searchOptionsArea->m_searchTextCombo->setEnabled(false); + + m_searcher.startSearch(); + + m_searchOptionsArea->searchButton()->setEnabled(true); + m_searchOptionsArea->m_searchTextCombo->setEnabled(true); + m_searchOptionsArea->m_searchTextCombo->setFocus(); } -QString CSearchDialog::prepareSearchText(const QString& orig) -{ - qDebug() << "Original search text:" << orig; - static const QRegExp syntaxCharacters("[+\\-()!\"~]"); - static const QRegExp andWords("\\band\\b", Qt::CaseInsensitive); - static const QRegExp orWords("\\bor\\b", Qt::CaseInsensitive); - QString text(""); - if (m_searchOptionsArea->searchType() == BtSearchOptionsArea::AndType) { - qDebug() << "AND type"; - text = orig.simplified(); - text.remove(syntaxCharacters); - qDebug() << "After syntax characters removed:" << text; - text.replace(andWords, "\"and\""); - text.replace(orWords, "\"or\""); - qDebug() << "After andor repclaced:" << text; - text.replace(" ", " AND "); - } - if (m_searchOptionsArea->searchType() == BtSearchOptionsArea::OrType) { - text = orig.simplified(); - text.remove(syntaxCharacters); - text.replace(andWords, "\"and\""); - text.replace(orWords, "\"or\""); - } - if (m_searchOptionsArea->searchType() == BtSearchOptionsArea::FullType) { - text = orig; - } - qDebug() << "The final search string:" << text; - return text; +QString CSearchDialog::prepareSearchText(const QString& orig) { + qDebug() << "Original search text:" << orig; + static const QRegExp syntaxCharacters("[+\\-()!\"~]"); + static const QRegExp andWords("\\band\\b", Qt::CaseInsensitive); + static const QRegExp orWords("\\bor\\b", Qt::CaseInsensitive); + QString text(""); + if (m_searchOptionsArea->searchType() == BtSearchOptionsArea::AndType) { + qDebug() << "AND type"; + text = orig.simplified(); + text.remove(syntaxCharacters); + qDebug() << "After syntax characters removed:" << text; + text.replace(andWords, "\"and\""); + text.replace(orWords, "\"or\""); + qDebug() << "After andor repclaced:" << text; + text.replace(" ", " AND "); + } + if (m_searchOptionsArea->searchType() == BtSearchOptionsArea::OrType) { + text = orig.simplified(); + text.remove(syntaxCharacters); + text.replace(andWords, "\"and\""); + text.replace(orWords, "\"or\""); + } + if (m_searchOptionsArea->searchType() == BtSearchOptionsArea::FullType) { + text = orig; + } + qDebug() << "The final search string:" << text; + return text; } /** Starts the search with the given module list and given search text. */ -void CSearchDialog::startSearch( const QList<CSwordModuleInfo*> modules, const QString& searchText) -{ - m_searchResultArea->reset(); - m_searchOptionsArea->reset(); - setModules(modules); - setSearchText(searchText); - - startSearch(); +void CSearchDialog::startSearch( const QList<CSwordModuleInfo*> modules, const QString& searchText) { + m_searchResultArea->reset(); + m_searchOptionsArea->reset(); + setModules(modules); + setSearchText(searchText); + + startSearch(); } /** Returns the list of used modules. */ -QList<CSwordModuleInfo*> CSearchDialog::modules() const -{ - return m_searchOptionsArea->modules(); +QList<CSwordModuleInfo*> CSearchDialog::modules() const { + return m_searchOptionsArea->modules(); } /** Sets the list of modules for the search. */ -void CSearchDialog::setModules( const QList<CSwordModuleInfo*> modules ) -{ - m_searchOptionsArea->setModules(modules); +void CSearchDialog::setModules( const QList<CSwordModuleInfo*> modules ) { + m_searchOptionsArea->setModules(modules); } /** Returns the search text which is set currently. */ -QString CSearchDialog::searchText() const -{ - return m_searchOptionsArea->searchText(); +QString CSearchDialog::searchText() const { + return m_searchOptionsArea->searchText(); } -sword::ListKey CSearchDialog::searchScope() -{ - return m_searchOptionsArea->searchScope(); +sword::ListKey CSearchDialog::searchScope() { + return m_searchOptionsArea->searchScope(); } /** Sets the search text which is used for the search. */ -void CSearchDialog::setSearchText( const QString searchText ) -{ - m_searchOptionsArea->setSearchText(searchText); +void CSearchDialog::setSearchText( const QString searchText ) { + m_searchOptionsArea->setSearchText(searchText); } /** Initializes this object. */ -void CSearchDialog::initView() -{ - QVBoxLayout* verticalLayout = new QVBoxLayout(this); - setLayout(verticalLayout); +void CSearchDialog::initView() { + QVBoxLayout* verticalLayout = new QVBoxLayout(this); + setLayout(verticalLayout); + + m_searchOptionsArea = new BtSearchOptionsArea(this); + verticalLayout->addWidget(m_searchOptionsArea); - m_searchOptionsArea = new BtSearchOptionsArea(this); - verticalLayout->addWidget(m_searchOptionsArea); + m_searchResultArea = new BtSearchResultArea(this); + verticalLayout->addWidget(m_searchResultArea); - m_searchResultArea = new BtSearchResultArea(this); - verticalLayout->addWidget(m_searchResultArea); - - QHBoxLayout* horizontalLayout = new QHBoxLayout(); + QHBoxLayout* horizontalLayout = new QHBoxLayout(); - m_analyseButton = new QPushButton(tr("&Analyze results..."), 0); - m_analyseButton->setToolTip(tr("Show a graphical analyzis of the search result")); - QSpacerItem* spacerItem = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum); - horizontalLayout->addWidget(m_analyseButton); - horizontalLayout->addItem(spacerItem); + m_analyseButton = new QPushButton(tr("&Analyze results..."), 0); + m_analyseButton->setToolTip(tr("Show a graphical analyzis of the search result")); + QSpacerItem* spacerItem = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum); + horizontalLayout->addWidget(m_analyseButton); + horizontalLayout->addItem(spacerItem); - m_closeButton = new QPushButton(this); - m_closeButton->setText(tr("&Close")); - m_closeButton->setIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::close_icon)); - horizontalLayout->addWidget(m_closeButton); + m_closeButton = new QPushButton(this); + m_closeButton->setText(tr("&Close")); + m_closeButton->setIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::close_icon)); + horizontalLayout->addWidget(m_closeButton); - verticalLayout->addLayout(horizontalLayout); + verticalLayout->addLayout(horizontalLayout); - loadDialogSettings(); + loadDialogSettings(); } void CSearchDialog::searchFinished() { - if ( m_searcher.foundItems() ) { - m_searchResultArea->setSearchResult(modules()); - } - else { - m_searchResultArea->reset(); - } - m_staticDialog->raise(); - m_staticDialog->activateWindow(); + if ( m_searcher.foundItems() ) { + m_searchResultArea->setSearchResult(modules()); + } + else { + m_searchResultArea->reset(); + } + m_staticDialog->raise(); + m_staticDialog->activateWindow(); } void CSearchDialog::showModulesSelector() { - m_searchOptionsArea->chooseModules(); + m_searchOptionsArea->chooseModules(); } /** Initializes the signal slot connections */ void CSearchDialog::initConnections() { - // Search button is clicked - bool ok = connect(m_searchOptionsArea->searchButton(), SIGNAL(clicked()),this, SLOT(startSearch())); - Q_ASSERT(ok); - // Return/Enter is pressed in the search text field - ok = connect(m_searchOptionsArea, SIGNAL(sigStartSearch()), this, SLOT(startSearch()) ); - Q_ASSERT(ok); + // Search button is clicked + bool ok = connect(m_searchOptionsArea->searchButton(), SIGNAL(clicked()), this, SLOT(startSearch())); + Q_ASSERT(ok); + // Return/Enter is pressed in the search text field + ok = connect(m_searchOptionsArea, SIGNAL(sigStartSearch()), this, SLOT(startSearch()) ); + Q_ASSERT(ok); ok = connect(m_closeButton, SIGNAL(clicked()), this, SLOT(closeButtonClicked())); - Q_ASSERT(ok); + Q_ASSERT(ok); - connect(m_analyseButton, SIGNAL(clicked()), m_searchResultArea, SLOT(showAnalysis())); + connect(m_analyseButton, SIGNAL(clicked()), m_searchResultArea, SLOT(showAnalysis())); } /** Resets the parts to the default. */ void CSearchDialog::reset() { - m_searchOptionsArea->reset(); - m_searchResultArea->reset(); + m_searchOptionsArea->reset(); + m_searchResultArea->reset(); } void CSearchDialog::closeButtonClicked() { - // With Qt::WA_DeleteOnClose set, the dialog will be deleted now - m_staticDialog->close(); + // With Qt::WA_DeleteOnClose set, the dialog will be deleted now + m_staticDialog->close(); } -void CSearchDialog::loadDialogSettings() -{ - resize(CBTConfig::get(CBTConfig::searchDialogWidth), CBTConfig::get(CBTConfig::searchDialogHeight)); - move(CBTConfig::get(CBTConfig::searchDialogX), CBTConfig::get(CBTConfig::searchDialogY)); +void CSearchDialog::loadDialogSettings() { + resize(CBTConfig::get(CBTConfig::searchDialogWidth), CBTConfig::get(CBTConfig::searchDialogHeight)); + move(CBTConfig::get(CBTConfig::searchDialogX), CBTConfig::get(CBTConfig::searchDialogY)); } -void CSearchDialog::saveDialogSettings() -{ - CBTConfig::set(CBTConfig::searchDialogWidth, size().width()); - CBTConfig::set(CBTConfig::searchDialogHeight, size().height()); - CBTConfig::set(CBTConfig::searchDialogX, x()); - CBTConfig::set(CBTConfig::searchDialogY, y()); +void CSearchDialog::saveDialogSettings() { + CBTConfig::set(CBTConfig::searchDialogWidth, size().width()); + CBTConfig::set(CBTConfig::searchDialogHeight, size().height()); + CBTConfig::set(CBTConfig::searchDialogX, x()); + CBTConfig::set(CBTConfig::searchDialogY, y()); } diff --git a/src/frontend/searchdialog/csearchdialog.h b/src/frontend/searchdialog/csearchdialog.h index de46ad3..a250bc7 100644 --- a/src/frontend/searchdialog/csearchdialog.h +++ b/src/frontend/searchdialog/csearchdialog.h @@ -23,8 +23,8 @@ //forward declarations namespace Search { - class BtSearchResultArea; - class BtSearchOptionsArea; +class BtSearchResultArea; +class BtSearchOptionsArea; } class QWidget; @@ -37,95 +37,95 @@ namespace Search { *@author The BibleTime team */ class CSearchDialog : public QDialog { - Q_OBJECT - -public: - static void openDialog(const QList<CSwordModuleInfo*> modules, const QString& searchText = QString::null, QWidget* parentDialog = 0); - -protected: - friend class CSearchAnalysisScene; - friend class CSearchResultArea; - friend class BtSearchResultArea; - friend class BibleTime; - - /** - * Only interesting for the class members! Useful to get the searched text etc. - */ - static CSearchDialog* getSearchDialog(); - - /** - * The constructor of the dialog. It's protected because you should use the static public function openDialog. - * The dialog destroys itself if it was closed. - */ - CSearchDialog(QWidget *parent); - ~CSearchDialog(); - - /** - * Initializes this object. - */ - void initView(); - /** - * Starts the search with the given module list and given search text. - * Doesn't wait for the start button press, starts immediately - */ - void startSearch( const QList<CSwordModuleInfo*> modules, const QString& searchText); - /**Prepares the search string given by user for a specific search type */ - QString prepareSearchText(const QString& orig); - /** - * Sets the list of modules for the search. - */ - void setModules( const QList<CSwordModuleInfo*> modules ); - /** - * Returns the list of used modules. - */ - QList<CSwordModuleInfo*> modules() const; - /** - * Sets the search text which is used for the search. - */ - void setSearchText( const QString searchText ); - /** - * Returns the search text which is set currently. - */ - QString searchText() const; - /** - * Returns the used search scope as a list key - */ - sword::ListKey searchScope(); - - /** - * Resets the parts to the default. - */ - void reset(); - /** - * Load the settings from the resource file - */ - void loadDialogSettings(); - /** - * Save the settings to the resource file - */ - void saveDialogSettings(); - -protected slots: - /** - * Starts the search with the set modules and the set search text. - */ - void startSearch(); - void searchFinished(); - void showModulesSelector(); - /** - * Initializes the signal slot connections - */ - void initConnections(); - - void closeButtonClicked(); - -private: - QPushButton* m_analyseButton; - QPushButton* m_closeButton; - BtSearchResultArea* m_searchResultArea; - BtSearchOptionsArea* m_searchOptionsArea; - - CSwordModuleSearch m_searcher; + Q_OBJECT + + public: + static void openDialog(const QList<CSwordModuleInfo*> modules, const QString& searchText = QString::null, QWidget* parentDialog = 0); + + protected: + friend class CSearchAnalysisScene; + friend class CSearchResultArea; + friend class BtSearchResultArea; + friend class BibleTime; + + /** + * Only interesting for the class members! Useful to get the searched text etc. + */ + static CSearchDialog* getSearchDialog(); + + /** + * The constructor of the dialog. It's protected because you should use the static public function openDialog. + * The dialog destroys itself if it was closed. + */ + CSearchDialog(QWidget *parent); + ~CSearchDialog(); + + /** + * Initializes this object. + */ + void initView(); + /** + * Starts the search with the given module list and given search text. + * Doesn't wait for the start button press, starts immediately + */ + void startSearch( const QList<CSwordModuleInfo*> modules, const QString& searchText); + /**Prepares the search string given by user for a specific search type */ + QString prepareSearchText(const QString& orig); + /** + * Sets the list of modules for the search. + */ + void setModules( const QList<CSwordModuleInfo*> modules ); + /** + * Returns the list of used modules. + */ + QList<CSwordModuleInfo*> modules() const; + /** + * Sets the search text which is used for the search. + */ + void setSearchText( const QString searchText ); + /** + * Returns the search text which is set currently. + */ + QString searchText() const; + /** + * Returns the used search scope as a list key + */ + sword::ListKey searchScope(); + + /** + * Resets the parts to the default. + */ + void reset(); + /** + * Load the settings from the resource file + */ + void loadDialogSettings(); + /** + * Save the settings to the resource file + */ + void saveDialogSettings(); + + protected slots: + /** + * Starts the search with the set modules and the set search text. + */ + void startSearch(); + void searchFinished(); + void showModulesSelector(); + /** + * Initializes the signal slot connections + */ + void initConnections(); + + void closeButtonClicked(); + + private: + QPushButton* m_analyseButton; + QPushButton* m_closeButton; + BtSearchResultArea* m_searchResultArea; + BtSearchOptionsArea* m_searchOptionsArea; + + CSwordModuleSearch m_searcher; }; diff --git a/src/frontend/searchdialog/csearchmodulechooserdialog.cpp b/src/frontend/searchdialog/csearchmodulechooserdialog.cpp index cf68f6e..6c183ca 100644 --- a/src/frontend/searchdialog/csearchmodulechooserdialog.cpp +++ b/src/frontend/searchdialog/csearchmodulechooserdialog.cpp @@ -32,30 +32,27 @@ namespace Search { CSearchModuleChooserDialog::CSearchModuleChooserDialog( QWidget* parent, QString title, QString label, - QList<CSwordModuleInfo*> selectedModules) - : CModuleChooserDialog(parent, title, label), - m_selectedModules(selectedModules) -{ - m_hiddenFilter = new BTModuleTreeItem::HiddenOff(); - QList<BTModuleTreeItem::Filter*> filters; - filters.append(m_hiddenFilter); - setFilters(filters); - init(); + QList<CSwordModuleInfo*> selectedModules) + : CModuleChooserDialog(parent, title, label), + m_selectedModules(selectedModules) { + m_hiddenFilter = new BTModuleTreeItem::HiddenOff(); + QList<BTModuleTreeItem::Filter*> filters; + filters.append(m_hiddenFilter); + setFilters(filters); + init(); } -CSearchModuleChooserDialog::~CSearchModuleChooserDialog() -{ - //see the ctor - delete m_hiddenFilter; +CSearchModuleChooserDialog::~CSearchModuleChooserDialog() { + //see the ctor + delete m_hiddenFilter; } -void CSearchModuleChooserDialog::initModuleItem(BTModuleTreeItem* btItem, QTreeWidgetItem* widgetItem) -{ - widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); - if (m_selectedModules.contains(btItem->moduleInfo())) - widgetItem->setCheckState(0, Qt::Checked); - else - widgetItem->setCheckState(0, Qt::Unchecked); +void CSearchModuleChooserDialog::initModuleItem(BTModuleTreeItem* btItem, QTreeWidgetItem* widgetItem) { + widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); + if (m_selectedModules.contains(btItem->moduleInfo())) + widgetItem->setCheckState(0, Qt::Checked); + else + widgetItem->setCheckState(0, Qt::Unchecked); } } //end of namespace Search diff --git a/src/frontend/searchdialog/csearchmodulechooserdialog.h b/src/frontend/searchdialog/csearchmodulechooserdialog.h index 8d5e32c..ab9f5cc 100644 --- a/src/frontend/searchdialog/csearchmodulechooserdialog.h +++ b/src/frontend/searchdialog/csearchmodulechooserdialog.h @@ -1,7 +1,7 @@ // // C++ Interface: cmodulechooserdialog // -// Description: +// Description: // // // Author: The BibleTime team <info@bibletime.info>, (C) 2007 @@ -24,19 +24,18 @@ class BTModuleTreeItem; namespace Search { -class CSearchModuleChooserDialog : public CModuleChooserDialog -{ - Q_OBJECT -public: - CSearchModuleChooserDialog(QWidget* parent, QString title, QString label, QList<CSwordModuleInfo*> selectedModules); - ~CSearchModuleChooserDialog(); +class CSearchModuleChooserDialog : public CModuleChooserDialog { + Q_OBJECT + public: + CSearchModuleChooserDialog(QWidget* parent, QString title, QString label, QList<CSwordModuleInfo*> selectedModules); + ~CSearchModuleChooserDialog(); -protected: // Protected methods - virtual void initModuleItem(BTModuleTreeItem* btItem, QTreeWidgetItem* widgetItem); + protected: // Protected methods + virtual void initModuleItem(BTModuleTreeItem* btItem, QTreeWidgetItem* widgetItem); -private: - QList<CSwordModuleInfo*> m_selectedModules; - BTModuleTreeItem::HiddenOff* m_hiddenFilter; + private: + QList<CSwordModuleInfo*> m_selectedModules; + BTModuleTreeItem::HiddenOff* m_hiddenFilter; }; } //end of namespace Search diff --git a/src/frontend/searchdialog/csearchresultview.cpp b/src/frontend/searchdialog/csearchresultview.cpp index 74561d6..f13b9d2 100644 --- a/src/frontend/searchdialog/csearchresultview.cpp +++ b/src/frontend/searchdialog/csearchresultview.cpp @@ -30,265 +30,259 @@ namespace Search { CSearchResultView::CSearchResultView(QWidget* parent) - : QTreeWidget(parent), - m_module(0) -{ - initView(); - initConnections(); + : QTreeWidget(parent), + m_module(0) { + initView(); + initConnections(); } CSearchResultView::~CSearchResultView() {} /** Initializes the view of this widget. */ -void CSearchResultView::initView() -{ - setToolTip(tr("Search result of the selected work")); - setHeaderLabel(tr("Results")); - setDragEnabled(true); - setRootIsDecorated( false ); - setSelectionMode(QAbstractItemView::ExtendedSelection); - - //setup the popup menu - m_popup = new QMenu(this); - - m_actions.copyMenu = new QMenu(tr("Copy..."), m_popup); - m_actions.copyMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::result::foundItems::copyMenu::icon)); - - m_actions.copy.result = new QAction(tr("Reference only"), this); - QObject::connect(m_actions.copy.result, SIGNAL(triggered()), this, SLOT(copyItems()) ); - m_actions.copyMenu->addAction(m_actions.copy.result); - - m_actions.copy.resultWithText = new QAction(tr("Reference with text"), this); - QObject::connect(m_actions.copy.resultWithText, SIGNAL(triggered()), - this, SLOT(copyItemsWithText())); - m_actions.copyMenu->addAction(m_actions.copy.resultWithText); - - m_popup->addMenu(m_actions.copyMenu); - - m_actions.saveMenu = new QMenu(tr("Save..."), m_popup); - m_actions.saveMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::result::foundItems::saveMenu::icon)); - - m_actions.save.result = new QAction(tr("Reference only"), this); - QObject::connect(m_actions.save.result, SIGNAL(triggered()), this, SLOT(saveItems()) ); - m_actions.saveMenu->addAction(m_actions.save.result); - - m_actions.save.resultWithText = new QAction(tr("Reference with text"), this); - m_actions.saveMenu->addAction(m_actions.save.resultWithText); - QObject::connect(m_actions.save.resultWithText, SIGNAL(triggered()), this, SLOT(saveItemsWithText())); - m_popup->addMenu(m_actions.saveMenu); - - m_actions.printMenu = new QMenu(tr("Print..."), m_popup); - m_actions.printMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::result::foundItems::printMenu::icon)); - - m_actions.print.result = new QAction(tr("Reference with text"), this); - QObject::connect(m_actions.print.result, SIGNAL(triggered()), this, SLOT(printItems()) ); - m_actions.printMenu->addAction(m_actions.print.result); - m_popup->addMenu(m_actions.printMenu); +void CSearchResultView::initView() { + setToolTip(tr("Search result of the selected work")); + setHeaderLabel(tr("Results")); + setDragEnabled(true); + setRootIsDecorated( false ); + setSelectionMode(QAbstractItemView::ExtendedSelection); + + //setup the popup menu + m_popup = new QMenu(this); + + m_actions.copyMenu = new QMenu(tr("Copy..."), m_popup); + m_actions.copyMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::result::foundItems::copyMenu::icon)); + + m_actions.copy.result = new QAction(tr("Reference only"), this); + QObject::connect(m_actions.copy.result, SIGNAL(triggered()), this, SLOT(copyItems()) ); + m_actions.copyMenu->addAction(m_actions.copy.result); + + m_actions.copy.resultWithText = new QAction(tr("Reference with text"), this); + QObject::connect(m_actions.copy.resultWithText, SIGNAL(triggered()), + this, SLOT(copyItemsWithText())); + m_actions.copyMenu->addAction(m_actions.copy.resultWithText); + + m_popup->addMenu(m_actions.copyMenu); + + m_actions.saveMenu = new QMenu(tr("Save..."), m_popup); + m_actions.saveMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::result::foundItems::saveMenu::icon)); + + m_actions.save.result = new QAction(tr("Reference only"), this); + QObject::connect(m_actions.save.result, SIGNAL(triggered()), this, SLOT(saveItems()) ); + m_actions.saveMenu->addAction(m_actions.save.result); + + m_actions.save.resultWithText = new QAction(tr("Reference with text"), this); + m_actions.saveMenu->addAction(m_actions.save.resultWithText); + QObject::connect(m_actions.save.resultWithText, SIGNAL(triggered()), this, SLOT(saveItemsWithText())); + m_popup->addMenu(m_actions.saveMenu); + + m_actions.printMenu = new QMenu(tr("Print..."), m_popup); + m_actions.printMenu->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::result::foundItems::printMenu::icon)); + + m_actions.print.result = new QAction(tr("Reference with text"), this); + QObject::connect(m_actions.print.result, SIGNAL(triggered()), this, SLOT(printItems()) ); + m_actions.printMenu->addAction(m_actions.print.result); + m_popup->addMenu(m_actions.printMenu); } /** No descriptions */ void CSearchResultView::initConnections() { - // connect(this, SIGNAL(executed(QListViewItem*)), - // this, SLOT(executed(QListViewItem*))); - //TODO: are these right after porting? - //items: current, previous - connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), - this, SLOT(executed(QTreeWidgetItem*, QTreeWidgetItem*))); + // connect(this, SIGNAL(executed(QListViewItem*)), + // this, SLOT(executed(QListViewItem*))); + //TODO: are these right after porting? + //items: current, previous + connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), + this, SLOT(executed(QTreeWidgetItem*, QTreeWidgetItem*))); } /** Setups the list with the given module. */ void CSearchResultView::setupTree(CSwordModuleInfo* m) { - clear(); - - if (!m) return; - - m_module = m; - sword::ListKey& result = m->searchResult(); - const int count = result.Count(); - if (!count) return; - - setUpdatesEnabled(false); - - QTreeWidgetItem* oldItem = 0; - QTreeWidgetItem* item = 0; - for (int index = 0; index < count; index++) { - item = new QTreeWidgetItem(this, oldItem); - item->setText(0, QString::fromUtf8(result.GetElement(index)->getText())); - oldItem = item; - } - - setUpdatesEnabled(true); - //pre-select the first item - this->setCurrentItem(this->topLevelItem(0), 0); + clear(); + + if (!m) return; + + m_module = m; + sword::ListKey& result = m->searchResult(); + const int count = result.Count(); + if (!count) return; + + setUpdatesEnabled(false); + + QTreeWidgetItem* oldItem = 0; + QTreeWidgetItem* item = 0; + for (int index = 0; index < count; index++) { + item = new QTreeWidgetItem(this, oldItem); + item->setText(0, QString::fromUtf8(result.GetElement(index)->getText())); + oldItem = item; + } + + setUpdatesEnabled(true); + //pre-select the first item + this->setCurrentItem(this->topLevelItem(0), 0); } -void CSearchResultView::setupStrongsTree(CSwordModuleInfo* m, QStringList* vList) -{ - clear(); - if (!m) { - return; - } +void CSearchResultView::setupStrongsTree(CSwordModuleInfo* m, QStringList* vList) { + clear(); + if (!m) { + return; + } - m_module = m; + m_module = m; - if (vList->count() <= 0) { - return; - } + if (vList->count() <= 0) { + return; + } - setUpdatesEnabled(false); + setUpdatesEnabled(false); - QTreeWidgetItem* oldItem = 0; - QTreeWidgetItem* item = 0; + QTreeWidgetItem* oldItem = 0; + QTreeWidgetItem* item = 0; - foreach (QString s, *vList) { - item = new QTreeWidgetItem(this, oldItem); - item->setText(0, (s)); - oldItem = item; - } + foreach (QString s, *vList) { + item = new QTreeWidgetItem(this, oldItem); + item->setText(0, (s)); + oldItem = item; + } - setUpdatesEnabled(true); + setUpdatesEnabled(true); - //TODO:select the first item - //setSelected(firstChild(), true); - //executed(currentItem()); + //TODO:select the first item + //setSelected(firstChild(), true); + //executed(currentItem()); } //TODO: is this still valid? /** Is connected to the signal executed, which is emitted when a mew item was chosen. */ void CSearchResultView::executed(QTreeWidgetItem* current, QTreeWidgetItem*) { - if (current){ - emit keySelected(current->text(0)); - } - else{ - emit keyDeselected(); - } + if (current) { + emit keySelected(current->text(0)); + } + else { + emit keyDeselected(); + } } //TODO: another function? /** Reimplementation to show the popup menu. */ -void CSearchResultView::contextMenuEvent(QContextMenuEvent* event) -{ - qDebug("CSearchResultView::showPopup"); - m_popup->exec(event->globalPos()); +void CSearchResultView::contextMenuEvent(QContextMenuEvent* event) { + qDebug("CSearchResultView::showPopup"); + m_popup->exec(event->globalPos()); } void CSearchResultView::printItems() { - QList<QTreeWidgetItem*> items = selectedItems(); - CExportManager mgr(tr("Print search result..."), true, tr("Printing search result")); - - QStringList list; - foreach (QTreeWidgetItem* k, items) { - list.append( k->text(0) ); - } - mgr.printKeyList( list, module(), CBTConfig::getDisplayOptionDefaults(), CBTConfig::getFilterOptionDefaults() ); + QList<QTreeWidgetItem*> items = selectedItems(); + CExportManager mgr(tr("Print search result..."), true, tr("Printing search result")); + + QStringList list; + foreach (QTreeWidgetItem* k, items) { + list.append( k->text(0) ); + } + mgr.printKeyList( list, module(), CBTConfig::getDisplayOptionDefaults(), CBTConfig::getFilterOptionDefaults() ); } void CSearchResultView::saveItems() { - CExportManager mgr(tr("Save search result..."), true, tr("Saving search result")); - - CSwordModuleInfo* m = module(); - CSwordKey* k = 0; - QList<QTreeWidgetItem*> items = selectedItems(); - QList<CSwordKey*> keys; - foreach (QTreeWidgetItem* i, items) { - k = CSwordKey::createInstance( m ); - k->key(i->text(0)); - keys.append( k ); - } - mgr.saveKeyList( keys, CExportManager::Text, false); - - qDeleteAll(keys); - keys.clear(); //delete all the keys we created + CExportManager mgr(tr("Save search result..."), true, tr("Saving search result")); + + CSwordModuleInfo* m = module(); + CSwordKey* k = 0; + QList<QTreeWidgetItem*> items = selectedItems(); + QList<CSwordKey*> keys; + foreach (QTreeWidgetItem* i, items) { + k = CSwordKey::createInstance( m ); + k->key(i->text(0)); + keys.append( k ); + } + mgr.saveKeyList( keys, CExportManager::Text, false); + + qDeleteAll(keys); + keys.clear(); //delete all the keys we created } void CSearchResultView::saveItemsWithText() { - CExportManager mgr(tr("Save search result..."), true, tr("Saving search result")); - - CSwordModuleInfo* m = module(); - CSwordKey* k = 0; - QList<QTreeWidgetItem*> items = selectedItems(); - QList<CSwordKey*> keys; - foreach (QTreeWidgetItem* i, items) { - k = CSwordKey::createInstance( m ); - k->key(i->text(0)); - keys.append( k ); - }; - mgr.saveKeyList( keys, CExportManager::Text, true); - - qDeleteAll(keys); - keys.clear(); //delete all the keys we created + CExportManager mgr(tr("Save search result..."), true, tr("Saving search result")); + + CSwordModuleInfo* m = module(); + CSwordKey* k = 0; + QList<QTreeWidgetItem*> items = selectedItems(); + QList<CSwordKey*> keys; + foreach (QTreeWidgetItem* i, items) { + k = CSwordKey::createInstance( m ); + k->key(i->text(0)); + keys.append( k ); + }; + mgr.saveKeyList( keys, CExportManager::Text, true); + + qDeleteAll(keys); + keys.clear(); //delete all the keys we created } void CSearchResultView::copyItems() { - CExportManager mgr(tr("Copy search result..."), true, tr("Copying search result")); - - CSwordModuleInfo* m = module(); - CSwordKey* k = 0; - QList<QTreeWidgetItem*> items = selectedItems(); - QList<CSwordKey*> keys; - foreach (QTreeWidgetItem* i, items) { - k = CSwordKey::createInstance( m ); - k->key(i->text(0)); - keys.append( k ); - }; - mgr.copyKeyList( keys, CExportManager::Text, false); - - qDeleteAll(keys); - keys.clear(); //delete all the keys we created + CExportManager mgr(tr("Copy search result..."), true, tr("Copying search result")); + + CSwordModuleInfo* m = module(); + CSwordKey* k = 0; + QList<QTreeWidgetItem*> items = selectedItems(); + QList<CSwordKey*> keys; + foreach (QTreeWidgetItem* i, items) { + k = CSwordKey::createInstance( m ); + k->key(i->text(0)); + keys.append( k ); + }; + mgr.copyKeyList( keys, CExportManager::Text, false); + + qDeleteAll(keys); + keys.clear(); //delete all the keys we created } void CSearchResultView::copyItemsWithText() { - CExportManager mgr(tr("Copy search result..."), true, tr("Copying search result")); - - CSwordModuleInfo* m = module(); - CSwordKey* k = 0; - QList<QTreeWidgetItem*> items = selectedItems(); - QList<CSwordKey*> keys; - foreach (QTreeWidgetItem* i, items) { - k = CSwordKey::createInstance( m ); - k->key(i->text(0)); - keys.append( k ); - }; - mgr.copyKeyList( keys, CExportManager::Text, true); - - qDeleteAll(keys); - keys.clear(); //delete all the keys we created + CExportManager mgr(tr("Copy search result..."), true, tr("Copying search result")); + + CSwordModuleInfo* m = module(); + CSwordKey* k = 0; + QList<QTreeWidgetItem*> items = selectedItems(); + QList<CSwordKey*> keys; + foreach (QTreeWidgetItem* i, items) { + k = CSwordKey::createInstance( m ); + k->key(i->text(0)); + keys.append( k ); + }; + mgr.copyKeyList( keys, CExportManager::Text, true); + + qDeleteAll(keys); + keys.clear(); //delete all the keys we created } CSwordModuleInfo* CSearchResultView::module() { - return m_module; + return m_module; } //TODO: port this to the new d'n'd // Q3DragObject* CSearchResultView::dragObject() { // //return a valid DragObject to make DnD possible! -// +// // /* // * First get all selected items and fill with them the dndItems list. The return the QDragObject we got from CDRagDropMgr // */ // CDragDropMgr::ItemList dndItems; -// +// // Q3PtrList<Q3ListViewItem> items = selectedItems(); // for (items.first(); items.current(); items.next()) { // dndItems.append( CDragDropMgr::Item(m_module->name(), items.current()->text(0), QString::null) ); //no description // }; -// +// // return CDragDropMgr::dragObject(dndItems, viewport()); // } -QMimeData * CSearchResultView::mimeData ( const QList<QTreeWidgetItem *> items ) const -{ - BTMimeData* mdata = new BTMimeData(m_module->name(), items.first()->text(0), QString::null); - foreach (QTreeWidgetItem* i, items) { - mdata->appendBookmark(m_module->name(), i->text(0), QString::null); - } - return mdata; +QMimeData * CSearchResultView::mimeData ( const QList<QTreeWidgetItem *> items ) const { + BTMimeData* mdata = new BTMimeData(m_module->name(), items.first()->text(0), QString::null); + foreach (QTreeWidgetItem* i, items) { + mdata->appendBookmark(m_module->name(), i->text(0), QString::null); + } + return mdata; } -QStringList CSearchResultView::mimeTypes () const -{ - return QStringList("BibleTime/Bookmark"); +QStringList CSearchResultView::mimeTypes () const { + return QStringList("BibleTime/Bookmark"); } } //end of namespace diff --git a/src/frontend/searchdialog/csearchresultview.h b/src/frontend/searchdialog/csearchresultview.h index 4d43bbf..071ccac 100644 --- a/src/frontend/searchdialog/csearchresultview.h +++ b/src/frontend/searchdialog/csearchresultview.h @@ -22,77 +22,77 @@ class CReadDisplay; namespace Search { class CSearchResultView : public QTreeWidget { - Q_OBJECT -public: - CSearchResultView(QWidget* parent); - virtual ~CSearchResultView(); - /** Returns the module which is currently used. */ - CSwordModuleInfo* module(); - -protected: // Protected methods - /** - * Initializes the view of this widget. - */ - void initView(); - void initConnections(); - - //from QTreeWidget - virtual QMimeData * mimeData ( const QList<QTreeWidgetItem *> items ) const; - virtual QStringList mimeTypes () const; - -public slots: // Public slots - void saveItems(); - /** - * Setups the list with the given module. - */ - void setupTree(CSwordModuleInfo*); - void setupStrongsTree(CSwordModuleInfo*, QStringList*); - void copyItemsWithText(); - void copyItems(); - void saveItemsWithText(); - /** - * Reimplementation to show the popup menu. - */ - virtual void contextMenuEvent(QContextMenuEvent* event); - -protected slots: // Protected slots - void printItems(); - - /** - * Is connected to the signal which is emitted when a new item was chosen. - */ - void executed(QTreeWidgetItem* current, QTreeWidgetItem*); - -private: - struct { - QMenu* saveMenu; - struct { - QAction* result; - QAction* resultWithText; - } - save; - - QMenu* printMenu; - struct { - QAction* result; - } - print; - - QMenu* copyMenu; - struct { - QAction* result; - QAction* resultWithText; - } - copy; - } - m_actions; - - QMenu* m_popup; - CSwordModuleInfo* m_module; - -signals: // Signals - void keySelected(const QString&); - void keyDeselected(); + Q_OBJECT + public: + CSearchResultView(QWidget* parent); + virtual ~CSearchResultView(); + /** Returns the module which is currently used. */ + CSwordModuleInfo* module(); + + protected: // Protected methods + /** + * Initializes the view of this widget. + */ + void initView(); + void initConnections(); + + //from QTreeWidget + virtual QMimeData * mimeData ( const QList<QTreeWidgetItem *> items ) const; + virtual QStringList mimeTypes () const; + + public slots: // Public slots + void saveItems(); + /** + * Setups the list with the given module. + */ + void setupTree(CSwordModuleInfo*); + void setupStrongsTree(CSwordModuleInfo*, QStringList*); + void copyItemsWithText(); + void copyItems(); + void saveItemsWithText(); + /** + * Reimplementation to show the popup menu. + */ + virtual void contextMenuEvent(QContextMenuEvent* event); + + protected slots: // Protected slots + void printItems(); + + /** + * Is connected to the signal which is emitted when a new item was chosen. + */ + void executed(QTreeWidgetItem* current, QTreeWidgetItem*); + + private: + struct { + QMenu* saveMenu; + struct { + QAction* result; + QAction* resultWithText; + } + save; + + QMenu* printMenu; + struct { + QAction* result; + } + print; + + QMenu* copyMenu; + struct { + QAction* result; + QAction* resultWithText; + } + copy; + } + m_actions; + + QMenu* m_popup; + CSwordModuleInfo* m_module; + + signals: // Signals + void keySelected(const QString&); + void keyDeselected(); }; } //end of namespace Search |