From 95bad033211b3f6b7bf91d39606331339b70907c Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Wed, 25 Jun 2008 19:52:39 +0000 Subject: [PATCH] - Fixed row color update - Code cleanup --- src/SearchTab.cpp | 5 ++--- src/SearchTab.h | 2 +- src/search.ui | 47 ++++++++++---------------------------------- src/searchEngine.cpp | 41 +++++++++++++++++++------------------- src/searchEngine.h | 2 +- 5 files changed, 35 insertions(+), 62 deletions(-) diff --git a/src/SearchTab.cpp b/src/SearchTab.cpp index cd7c484df..ef56555d8 100644 --- a/src/SearchTab.cpp +++ b/src/SearchTab.cpp @@ -37,7 +37,7 @@ #define SEARCH_ENGINE 4 QList* SearchTab::all_tab = new QList(); -SearchTab::SearchTab(QString &title,QTabWidget *tab_barWidget,SearchEngine *searchEngi) : QWidget() +SearchTab::SearchTab(SearchEngine *parent) : QWidget() { box=new QVBoxLayout(); results_lbl=new QLabel(); @@ -61,14 +61,13 @@ SearchTab::SearchTab(QString &title,QTabWidget *tab_barWidget,SearchEngine *sear resultsBrowser->header()->setSortIndicatorShown(true); // Connect signals to slots (search part) - connect(resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), searchEngi, SLOT(downloadSelectedItem(const QModelIndex&))); + connect(resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), parent, SLOT(downloadSelectedItem(const QModelIndex&))); connect(resultsBrowser->header(), SIGNAL(sectionPressed(int)), this, SLOT(sortSearchList(int))); // Load last columns width for search results list if(!loadColWidthSearchList()){ resultsBrowser->header()->resizeSection(0, 275); } - tab_barWidget->addTab(this, title); all_tab->append(this); } diff --git a/src/SearchTab.h b/src/SearchTab.h index 6ffd977fd..fa6619701 100644 --- a/src/SearchTab.h +++ b/src/SearchTab.h @@ -41,7 +41,7 @@ class SearchTab : public QWidget, public Ui::search_engine SearchListDelegate *SearchDelegate; public: static QList *all_tab; // To store all tabs - SearchTab(QString &title,QTabWidget *tab_barWidget, SearchEngine *searchEngi); + SearchTab(SearchEngine *parent); ~SearchTab(); bool loadColWidthSearchList(); QLabel * getCurrentLabel(); diff --git a/src/search.ui b/src/search.ui index a4da18bf2..e1495ab66 100644 --- a/src/search.ui +++ b/src/search.ui @@ -18,16 +18,7 @@ 6 - - 0 - - - 0 - - - 0 - - + 0 @@ -76,7 +67,8 @@ - :/Icons/edit_clear.png + + :/Icons/edit_clear.png:/Icons/edit_clear.png @@ -185,7 +177,7 @@ Qt::Horizontal - + 188 21 @@ -196,24 +188,14 @@ - - + 6 - - 0 - - - 0 - - - 0 - - + 0 @@ -221,16 +203,7 @@ 6 - - 0 - - - 0 - - - 0 - - + 0 @@ -244,12 +217,12 @@ - + false - Clear + Close tab @@ -258,7 +231,7 @@ Qt::Horizontal - + 601 20 diff --git a/src/searchEngine.cpp b/src/searchEngine.cpp index 8adc19cae..3a65f18a8 100644 --- a/src/searchEngine.cpp +++ b/src/searchEngine.cpp @@ -128,13 +128,15 @@ void SearchEngine::on_search_button_clicked(){ searchTimeout->stop(); } QString pattern = search_pattern->text().trimmed(); - //AJOUT TAB obligé de passé le widget en param sinon crash - tab_search=new SearchTab(pattern,tabWidget,this); // No search pattern entered if(pattern.isEmpty()){ QMessageBox::critical(0, tr("Empty search pattern"), tr("Please type a search pattern first")); return; } + // Tab Addition + tab_search=new SearchTab(this); + tabWidget->addTab(tab_search, pattern); + closeTab_button->setEnabled(true); // if the pattern is not in the pattern if(searchHistory.indexOf(pattern) == -1){ //update the searchHistory list @@ -187,7 +189,7 @@ void SearchEngine::downloadSelectedItem(const QModelIndex& index){ // Download from url BTSession->downloadFromUrl(url); // Set item color to RED - tab_search->setRowColor(row, "red"); + SearchTab::all_tab->at(tabWidget->currentIndex())->setRowColor(row, "red"); } // search Qprocess return output as soon as it gets new @@ -326,7 +328,6 @@ void SearchEngine::appendSearchResult(QString line){ no_search_results = false; ++nb_search_results; // Enable clear & download buttons - clear_button->setEnabled(true); download_button->setEnabled(true); } @@ -339,21 +340,21 @@ void SearchEngine::on_stop_search_button_clicked(){ } // Clear search results list -void SearchEngine::on_clear_button_clicked(){ - // Kill process - searchProcess->terminate(); - search_stopped = true; - searchTimeout->stop(); - searchResultsUrls.clear(); - tab_search->getCurrentSearchListModel()->removeRows(0, tab_search->getCurrentSearchListModel()->rowCount()); - // Disable clear & download buttons - clear_button->setEnabled(false); - download_button->setEnabled(false); - nb_search_results = 0; - tab_search->getCurrentLabel()->setText(tr("Results")+" (0):"); - // focus on search pattern - search_pattern->clear(); - search_pattern->setFocus(); +void SearchEngine::on_closeTab_button_clicked(){ + //// Kill process + //searchProcess->terminate(); + //search_stopped = true; + //searchTimeout->stop(); + //searchResultsUrls.clear(); + //tab_search->getCurrentSearchListModel()->removeRows(0, tab_search->getCurrentSearchListModel()->rowCount()); + //// Disable clear & download buttons + //clear_button->setEnabled(false); + //download_button->setEnabled(false); + //nb_search_results = 0; + //tab_search->getCurrentLabel()->setText(tr("Results")+" (0):"); + //// focus on search pattern + //search_pattern->clear(); + //search_pattern->setFocus(); } void SearchEngine::on_clearPatternButton_clicked() { @@ -371,7 +372,7 @@ void SearchEngine::on_download_button_clicked(){ // Get Item url QString url = searchResultsUrls.value(index.data().toString()); BTSession->downloadFromUrl(url); - tab_search->setRowColor(index.row(), "red"); + SearchTab::all_tab->at(tabWidget->currentIndex())->setRowColor(index.row(), "red"); } } } diff --git a/src/searchEngine.h b/src/searchEngine.h index 3e30e158f..34cf84dec 100644 --- a/src/searchEngine.h +++ b/src/searchEngine.h @@ -67,7 +67,7 @@ class SearchEngine : public QWidget, public Ui::search_engine{ // Search slots void on_search_button_clicked(); void on_stop_search_button_clicked(); - void on_clear_button_clicked(); + void on_closeTab_button_clicked(); void appendSearchResult(QString line); void searchFinished(int exitcode,QProcess::ExitStatus); void readSearchOutput();