void SearchResultWidget::filterResults(const QString &text) { QString str = QGanjoorDbBrowser::cleanString(text); if (str.isEmpty()) { resultList = copyResultList; emit searchFiltered(phrase); showSearchResult(0); return; }//searchTable->setItemDelegateForColumn(2, new SaagharItemDelegate()); //SaagharItemDelegate *itemDelegate = searchTable->itemDelegateForColumn(2); //itemDelegate-> emit searchFiltered(phrase + " " + str); //QMap<int, QString> tmpList; resultList.clear(); QMap<int, QString>::const_iterator it = copyResultList.constBegin(); const QMap<int, QString>::const_iterator endIterator = copyResultList.constEnd(); while (it != endIterator) { QString value = it.value(); value = QGanjoorDbBrowser::cleanString(value); if (value.contains(str, Qt::CaseInsensitive)) { resultList.insertMulti(it.key(), it.value()); } ++it; } if (resultList.isEmpty()) { pageLabel->setText(tr("Nothing found!")); searchPreviousPage->setEnabled(false); searchNextPage->setEnabled(false); searchTable->clear(); searchTable->setRowCount(0); } else { showSearchResult(0); } }
void FontFilter::processRowFilter() { m_accepted_indexes.clear(); m_search_result_count = 0; int source_row_count = totalFontCount(); for(int i=0; i<source_row_count; i++) { if (filterAcceptsRow(i)) m_accepted_indexes.append(i); } if (searchFiltered()) emit searchResultsChanged(m_search_result_count); else emit searchResultsChanged(-1); reset(); }
void SearchResultWidget::setupUi(QMainWindow* qmw, const QString &iconThemePath) { searchResultWidget = new QDockWidget(qmw); searchResultWidget->setObjectName(QString::fromUtf8("searchResultWidget_new"));//object name for created instance, it renames to 'searchResultWidget_old' //searchResultWidget->setLayoutDirection(Qt::RightToLeft); searchResultWidget->setFeatures(QDockWidget::AllDockWidgetFeatures); searchResultWidget->setAttribute(Qt::WA_DeleteOnClose, true); searchResultWidget->setStyleSheet("QDockWidget::title { background: transparent; text-align: left; padding: 0 10 0 10;}" "QDockWidget::close-button, QDockWidget::float-button { background: transparent;}"); QGridLayout* searchGridLayout = new QGridLayout(searchResultContents); searchGridLayout->setSpacing(6); searchGridLayout->setContentsMargins(11, 11, 11, 11); searchGridLayout->setObjectName(QString::fromUtf8("searchGridLayout")); QHBoxLayout* horizontalLayout = new QHBoxLayout(); horizontalLayout->setSpacing(6); horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); QGridLayout* searchTableGridLayout = new QGridLayout(); searchTableGridLayout->setSpacing(6); searchTableGridLayout->setObjectName(QString::fromUtf8("searchTableGridLayout")); //create filter lable and lineEdit and layout QHBoxLayout* filterHorizontalLayout = new QHBoxLayout(); filterHorizontalLayout->setSpacing(6); filterHorizontalLayout->setObjectName(QString::fromUtf8("filterHorizontalLayout")); QLabel* filterLabel = new QLabel(searchResultContents); filterLabel->setObjectName(QString::fromUtf8("filterLabel")); filterLabel->setText(tr("Filter:")); filterHorizontalLayout->addWidget(filterLabel, 0, Qt::AlignRight | Qt::AlignCenter); QString clearIconPath = iconThemePath + "/clear-left.png"; if (searchResultContents->layoutDirection() == Qt::RightToLeft) { clearIconPath = iconThemePath + "/clear-right.png"; } filterLineEdit = new QSearchLineEdit(searchResultContents, clearIconPath, iconThemePath + "/filter.png"); filterLineEdit->setObjectName(QString::fromUtf8("filterLineEdit")); #if QT_VERSION >= 0x040700 filterLineEdit->setPlaceholderText(tr("Filter")); #endif connect(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterResults(QString))); filterHorizontalLayout->addWidget(filterLineEdit); QSpacerItem* filterHorizSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); filterHorizontalLayout->addItem(filterHorizSpacer); pageLabel = new QLabel(searchResultContents); pageLabel->setObjectName(QString::fromUtf8("pageLabel")); // filterHorizontalLayout->addWidget(pageLabel, 0, Qt::AlignRight|Qt::AlignCenter); //searchTableGridLayout->addLayout(filterHorizontalLayout, 1, 0, 1, 1); //create QTableWidget searchTable = new QTableWidget(searchResultContents); searchTable->setObjectName(QString::fromUtf8("searchTable")); searchTable->setColumnCount(3); searchTable->setLayoutDirection(Qt::RightToLeft); searchTable->setAlternatingRowColors(true); searchTable->setSelectionMode(QAbstractItemView::NoSelection /*SingleSelection*/); searchTable->setSelectionBehavior(QAbstractItemView::SelectRows); searchTable->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); searchTable->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); searchTable->verticalHeader()->setVisible(false); //searchTable->horizontalHeader()->setVisible(false); searchTable->horizontalHeader()->setHighlightSections(false); searchTable->horizontalHeader()->setStretchLastSection(true); connect(searchTable, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(currentRowColumnChanged(int,int,int,int))); //install delagate on third column SaagharItemDelegate* searchDelegate = new SaagharItemDelegate(searchTable, searchTable->style(), phrase); searchTable->setItemDelegateForColumn(2, searchDelegate); connect(this, SIGNAL(searchFiltered(QString)), searchDelegate, SLOT(keywordChanged(QString))); //searchTable->setItemDelegateForColumn(2, new SaagharItemDelegate(searchTable, searchTable->style(), phrase)); searchTableGridLayout->addWidget(searchTable, 0, 0, 1, 1); // QVBoxLayout *searchNavVerticalLayout = new QVBoxLayout(); // searchNavVerticalLayout->setSpacing(6); // searchNavVerticalLayout->setObjectName(QString::fromUtf8("searchNavVerticalLayout")); searchNextPage = new QToolButton(searchResultContents); searchNextPage->setObjectName(QString::fromUtf8("searchNextPage")); searchNextPage->setStyleSheet("QToolButton { border: none; padding: 0px; }"); actSearchNextPage = new QAction(searchResultContents); searchNextPage->setDefaultAction(actSearchNextPage); connect(searchNextPage, SIGNAL(triggered(QAction*)), this, SLOT(searchPageNavigationClicked(QAction*))); searchNextPage->setEnabled(false); searchNextPage->hide(); //searchNavVerticalLayout->addWidget(searchNextPage); searchPreviousPage = new QToolButton(searchResultContents); searchPreviousPage->setObjectName(QString::fromUtf8("searchPreviousPage")); searchPreviousPage->setStyleSheet("QToolButton { border: none; padding: 0px; }"); actSearchPreviousPage = new QAction(searchResultContents); searchPreviousPage->setDefaultAction(actSearchPreviousPage); if (qmw->layoutDirection() == Qt::LeftToRight) { actSearchPreviousPage->setIcon(QIcon(iconThemePath + "/previous.png")); actSearchNextPage->setIcon(QIcon(iconThemePath + "/next.png")); } else { actSearchPreviousPage->setIcon(QIcon(iconThemePath + "/next.png")); actSearchNextPage->setIcon(QIcon(iconThemePath + "/previous.png")); } connect(searchPreviousPage, SIGNAL(triggered(QAction*)), this, SLOT(searchPageNavigationClicked(QAction*))); searchPreviousPage->setEnabled(false); searchPreviousPage->hide(); // searchNavVerticalLayout->addWidget(searchPreviousPage); //QSpacerItem *searchNavVerticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); //searchNavVerticalLayout->addItem(searchNavVerticalSpacer); // if (moreThanOnePage) // horizontalLayout->addLayout(searchNavVerticalLayout); filterHorizontalLayout->addWidget(searchPreviousPage); filterHorizontalLayout->addWidget(searchNextPage); filterHorizontalLayout->addWidget(pageLabel, 0, Qt::AlignRight | Qt::AlignCenter); searchTableGridLayout->addLayout(filterHorizontalLayout, 1, 0, 1, 1); horizontalLayout->addLayout(searchTableGridLayout); searchGridLayout->addLayout(horizontalLayout, 0, 0, 1, 1); /****************************/ QDockWidget* tmpDockWidget = 0; QObjectList mainWindowChildren = qmw->children(); for (int i = 0; i < mainWindowChildren.size(); ++i) { tmpDockWidget = qobject_cast<QDockWidget*>(mainWindowChildren.at(i)); if (tmpDockWidget) { if (mainWindowChildren.at(i)->objectName() == "searchResultWidget_old") { break; } } } /****************************************/ searchResultWidget->setWidget(searchResultContents); qmw->addDockWidget(Qt::BottomDockWidgetArea, searchResultWidget); if (tmpDockWidget && tmpDockWidget->objectName() == "searchResultWidget_old") { //there is another search results dock-widget present qmw->tabifyDockWidget(tmpDockWidget, searchResultWidget); } searchResultWidget->setObjectName("searchResultWidget_old"); searchResultWidget->show(); searchResultWidget->raise(); }