Browse Source

Optimize widgets inside of the search tab

Since we already have searchtab.ui, let's set up all the widgets there.
Additionally, save a bit of vertical space by putting results label in
a row with the filter widgets.
adaptive-webui-19844
Eugene Shalygin 9 years ago
parent
commit
b6b819a2a1
  1. 114
      src/gui/search/searchtab.cpp
  2. 13
      src/gui/search/searchtab.h
  3. 10
      src/gui/search/searchtab.ui

114
src/gui/search/searchtab.cpp

@ -48,6 +48,7 @@
#include "searchlistdelegate.h" #include "searchlistdelegate.h"
#include "searchwidget.h" #include "searchwidget.h"
#include "searchtab.h" #include "searchtab.h"
#include "ui_searchtab.h"
namespace namespace
{ {
@ -58,25 +59,20 @@ namespace
SearchTab::SearchTab(SearchWidget *parent) SearchTab::SearchTab(SearchWidget *parent)
: QWidget(parent) : QWidget(parent)
, m_ui(new Ui::SearchTab())
, m_parent(parent) , m_parent(parent)
{ {
setupUi(this); m_ui->setupUi(this);
retranslateUi(this);
m_box = static_cast<QVBoxLayout*>(this->layout());
m_resultsLbl = new QLabel(this);
m_resultsBrowser = new QTreeView(this);
#ifdef QBT_USES_QT5 #ifdef QBT_USES_QT5
// This hack fixes reordering of first column with Qt5. // This hack fixes reordering of first column with Qt5.
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777 // https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
QTableView unused; QTableView unused;
unused.setVerticalHeader(m_resultsBrowser->header()); unused.setVerticalHeader(m_ui->resultsBrowser->header());
m_resultsBrowser->header()->setParent(m_resultsBrowser); m_ui->resultsBrowser->header()->setParent(m_ui->resultsBrowser);
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal)); unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));
#endif #endif
m_resultsBrowser->setSelectionMode(QAbstractItemView::ExtendedSelection); m_ui->resultsBrowser->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_box->addWidget(m_resultsLbl);
m_box->addWidget(m_resultsBrowser);
// Set Search results list model // Set Search results list model
m_searchListModel = new QStandardItemModel(0, SearchSortModel::NB_SEARCH_COLUMNS, this); m_searchListModel = new QStandardItemModel(0, SearchSortModel::NB_SEARCH_COLUMNS, this);
@ -89,43 +85,48 @@ SearchTab::SearchTab(SearchWidget *parent)
m_proxyModel = new SearchSortModel(this); m_proxyModel = new SearchSortModel(this);
m_proxyModel->setDynamicSortFilter(true); m_proxyModel->setDynamicSortFilter(true);
m_proxyModel->setSourceModel(m_searchListModel); m_proxyModel->setSourceModel(m_searchListModel);
m_resultsBrowser->setModel(m_proxyModel); m_ui->resultsBrowser->setModel(m_proxyModel);
m_searchDelegate = new SearchListDelegate(this); m_searchDelegate = new SearchListDelegate(this);
m_resultsBrowser->setItemDelegate(m_searchDelegate); m_ui->resultsBrowser->setItemDelegate(m_searchDelegate);
m_resultsBrowser->hideColumn(SearchSortModel::DL_LINK); // Hide url column m_ui->resultsBrowser->hideColumn(SearchSortModel::DL_LINK); // Hide url column
m_resultsBrowser->hideColumn(SearchSortModel::DESC_LINK); m_ui->resultsBrowser->hideColumn(SearchSortModel::DESC_LINK);
m_resultsBrowser->setRootIsDecorated(false); m_ui->resultsBrowser->setRootIsDecorated(false);
m_resultsBrowser->setAllColumnsShowFocus(true); m_ui->resultsBrowser->setAllColumnsShowFocus(true);
m_resultsBrowser->setSortingEnabled(true); m_ui->resultsBrowser->setSortingEnabled(true);
// Connect signals to slots (search part) // Connect signals to slots (search part)
connect(m_resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadSelectedItem(const QModelIndex&))); connect(m_ui->resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadSelectedItem(const QModelIndex&)));
// Load last columns width for search results list // Load last columns width for search results list
if (!loadColWidthResultsList()) if (!loadColWidthResultsList())
m_resultsBrowser->header()->resizeSection(0, 275); m_ui->resultsBrowser->header()->resizeSection(0, 275);
// Sort by Seeds // Sort by Seeds
m_resultsBrowser->sortByColumn(SearchSortModel::SEEDS, Qt::DescendingOrder); m_ui->resultsBrowser->sortByColumn(SearchSortModel::SEEDS, Qt::DescendingOrder);
fillFilterComboBoxes(); fillFilterComboBoxes();
updateFilter(); updateFilter();
connect(filterMode, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFilter())); connect(m_ui->filterMode, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFilter()));
connect(minSeeds, SIGNAL(editingFinished()), this, SLOT(updateFilter())); connect(m_ui->minSeeds, SIGNAL(editingFinished()), this, SLOT(updateFilter()));
connect(minSeeds, SIGNAL(valueChanged(int)), this, SLOT(updateFilter())); connect(m_ui->minSeeds, SIGNAL(valueChanged(int)), this, SLOT(updateFilter()));
connect(maxSeeds, SIGNAL(editingFinished()), this, SLOT(updateFilter())); connect(m_ui->maxSeeds, SIGNAL(editingFinished()), this, SLOT(updateFilter()));
connect(maxSeeds, SIGNAL(valueChanged(int)), this, SLOT(updateFilter())); connect(m_ui->maxSeeds, SIGNAL(valueChanged(int)), this, SLOT(updateFilter()));
connect(minSize, SIGNAL(editingFinished()), this, SLOT(updateFilter())); connect(m_ui->minSize, SIGNAL(editingFinished()), this, SLOT(updateFilter()));
connect(minSize, SIGNAL(valueChanged(double)), this, SLOT(updateFilter())); connect(m_ui->minSize, SIGNAL(valueChanged(double)), this, SLOT(updateFilter()));
connect(maxSize, SIGNAL(editingFinished()), this, SLOT(updateFilter())); connect(m_ui->maxSize, SIGNAL(editingFinished()), this, SLOT(updateFilter()));
connect(maxSize, SIGNAL(valueChanged(double)), this, SLOT(updateFilter())); connect(m_ui->maxSize, SIGNAL(valueChanged(double)), this, SLOT(updateFilter()));
connect(minSizeUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFilter())); connect(m_ui->minSizeUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFilter()));
connect(maxSizeUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFilter())); connect(m_ui->maxSizeUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFilter()));
}
SearchTab::~SearchTab()
{
delete m_ui;
} }
void SearchTab::downloadSelectedItem(const QModelIndex &index) void SearchTab::downloadSelectedItem(const QModelIndex &index)
@ -137,7 +138,7 @@ void SearchTab::downloadSelectedItem(const QModelIndex &index)
QHeaderView* SearchTab::header() const QHeaderView* SearchTab::header() const
{ {
return m_resultsBrowser->header(); return m_ui->resultsBrowser->header();
} }
bool SearchTab::loadColWidthResultsList() bool SearchTab::loadColWidthResultsList()
@ -149,16 +150,15 @@ bool SearchTab::loadColWidthResultsList()
if (widthList.size() > m_searchListModel->columnCount()) if (widthList.size() > m_searchListModel->columnCount())
return false; return false;
unsigned int listSize = widthList.size(); for (int i = 0; i < widthList.size(); ++i)
for (unsigned int i = 0; i < listSize; ++i) m_ui->resultsBrowser->header()->resizeSection(i, widthList.at(i).toInt());
m_resultsBrowser->header()->resizeSection(i, widthList.at(i).toInt());
return true; return true;
} }
QTreeView* SearchTab::getCurrentTreeView() const QTreeView* SearchTab::getCurrentTreeView() const
{ {
return m_resultsBrowser; return m_ui->resultsBrowser;
} }
SearchSortModel* SearchTab::getCurrentSearchListProxy() const SearchSortModel* SearchTab::getCurrentSearchListProxy() const
@ -199,8 +199,8 @@ void SearchTab::updateResultsCount()
{ {
const int totalResults = getCurrentSearchListModel() ? getCurrentSearchListModel()->rowCount(QModelIndex()) : 0; const int totalResults = getCurrentSearchListModel() ? getCurrentSearchListModel()->rowCount(QModelIndex()) : 0;
const int filteredResults = getCurrentSearchListProxy() ? getCurrentSearchListProxy()->rowCount(QModelIndex()) : totalResults; const int filteredResults = getCurrentSearchListProxy() ? getCurrentSearchListProxy()->rowCount(QModelIndex()) : totalResults;
m_resultsLbl->setText(tr("Results (showing <i>%1</i> out of <i>%2</i>):", "i.e: Search results") m_ui->resultsLbl->setText(tr("Results (showing <i>%1</i> out of <i>%2</i>):", "i.e: Search results")
.arg(filteredResults).arg(totalResults)); .arg(filteredResults).arg(totalResults));
} }
void SearchTab::updateFilter() void SearchTab::updateFilter()
@ -209,14 +209,14 @@ void SearchTab::updateFilter()
SearchSortModel* filterModel = getCurrentSearchListProxy(); SearchSortModel* filterModel = getCurrentSearchListProxy();
filterModel->enableNameFilter(filteringMode() == OnlyNames); filterModel->enableNameFilter(filteringMode() == OnlyNames);
// we update size and seeds filter parameters in the model even if they are disabled // we update size and seeds filter parameters in the model even if they are disabled
// because we need to read them from the model when search tabs switch filterModel->setSeedsFilter(m_ui->minSeeds->value(), m_ui->maxSeeds->value());
filterModel->setSeedsFilter(minSeeds->value(), maxSeeds->value());
filterModel->setSizeFilter( filterModel->setSizeFilter(
sizeInBytes(minSize->value(), static_cast<SizeUnit>(minSizeUnit->currentIndex())), sizeInBytes(m_ui->minSize->value(), static_cast<SizeUnit>(m_ui->minSizeUnit->currentIndex())),
sizeInBytes(maxSize->value(), static_cast<SizeUnit>(maxSizeUnit->currentIndex()))); sizeInBytes(m_ui->maxSize->value(), static_cast<SizeUnit>(m_ui->maxSizeUnit->currentIndex())));
SettingsStorage::instance()->storeValue(KEY_FILTER_MODE_SETTING_NAME, SettingsStorage::instance()->storeValue(KEY_FILTER_MODE_SETTING_NAME,
filterMode->itemData(filterMode->currentIndex())); m_ui->filterMode->itemData(m_ui->filterMode->currentIndex()));
filterModel->invalidate(); filterModel->invalidate();
updateResultsCount(); updateResultsCount();
} }
@ -233,29 +233,29 @@ void SearchTab::fillFilterComboBoxes()
unitStrings.append(unitString(SizeUnit::PebiByte)); unitStrings.append(unitString(SizeUnit::PebiByte));
unitStrings.append(unitString(SizeUnit::ExbiByte)); unitStrings.append(unitString(SizeUnit::ExbiByte));
minSizeUnit->clear(); m_ui->minSizeUnit->clear();
maxSizeUnit->clear(); m_ui->maxSizeUnit->clear();
minSizeUnit->addItems(unitStrings); m_ui->minSizeUnit->addItems(unitStrings);
maxSizeUnit->addItems(unitStrings); m_ui->maxSizeUnit->addItems(unitStrings);
minSize->setValue(0); m_ui->minSize->setValue(0);
minSizeUnit->setCurrentIndex(static_cast<int>(SizeUnit::MebiByte)); m_ui->minSizeUnit->setCurrentIndex(static_cast<int>(SizeUnit::MebiByte));
maxSize->setValue(-1); m_ui->maxSize->setValue(-1);
maxSizeUnit->setCurrentIndex(static_cast<int>(SizeUnit::TebiByte)); m_ui->maxSizeUnit->setCurrentIndex(static_cast<int>(SizeUnit::TebiByte));
filterMode->clear(); m_ui->filterMode->clear();
QMetaEnum nameFilteringModeEnum = QMetaEnum nameFilteringModeEnum =
this->metaObject()->enumerator(this->metaObject()->indexOfEnumerator("NameFilteringMode")); this->metaObject()->enumerator(this->metaObject()->indexOfEnumerator("NameFilteringMode"));
filterMode->addItem(tr("Torrent names only"), nameFilteringModeEnum.valueToKey(OnlyNames)); m_ui->filterMode->addItem(tr("Torrent names only"), nameFilteringModeEnum.valueToKey(OnlyNames));
filterMode->addItem(tr("Everywhere"), nameFilteringModeEnum.valueToKey(Everywhere)); m_ui->filterMode->addItem(tr("Everywhere"), nameFilteringModeEnum.valueToKey(Everywhere));
QVariant selectedMode = SettingsStorage::instance()->loadValue( QVariant selectedMode = SettingsStorage::instance()->loadValue(
KEY_FILTER_MODE_SETTING_NAME, nameFilteringModeEnum.valueToKey(OnlyNames)); KEY_FILTER_MODE_SETTING_NAME, nameFilteringModeEnum.valueToKey(OnlyNames));
int index = filterMode->findData(selectedMode); int index = m_ui->filterMode->findData(selectedMode);
filterMode->setCurrentIndex(index == -1 ? 0 : index); m_ui->filterMode->setCurrentIndex(index == -1 ? 0 : index);
} }
QString SearchTab::statusText(SearchTab::Status st) QString SearchTab::statusText(SearchTab::Status st)
@ -298,5 +298,5 @@ SearchTab::NameFilteringMode SearchTab::filteringMode() const
{ {
QMetaEnum metaEnum = QMetaEnum metaEnum =
this->metaObject()->enumerator(this->metaObject()->indexOfEnumerator("NameFilteringMode")); this->metaObject()->enumerator(this->metaObject()->indexOfEnumerator("NameFilteringMode"));
return static_cast<NameFilteringMode>(metaEnum.keyToValue(filterMode->itemData(filterMode->currentIndex()).toByteArray())); return static_cast<NameFilteringMode>(metaEnum.keyToValue(m_ui->filterMode->itemData(m_ui->filterMode->currentIndex()).toByteArray()));
} }

13
src/gui/search/searchtab.h

@ -32,7 +32,7 @@
#define SEARCHTAB_H #define SEARCHTAB_H
#include <QVariant> // I don't know why <QMetaType> is not enought for Qt's 4.8.7 moc #include <QVariant> // I don't know why <QMetaType> is not enought for Qt's 4.8.7 moc
#include "ui_searchtab.h" #include <QWidget>
#define ENGINE_URL_COLUMN 4 #define ENGINE_URL_COLUMN 4
#define URL_COLUMN 5 #define URL_COLUMN 5
@ -48,7 +48,12 @@ class SearchSortModel;
class SearchListDelegate; class SearchListDelegate;
class SearchWidget; class SearchWidget;
class SearchTab: public QWidget, private Ui::SearchTab namespace Ui
{
class SearchTab;
}
class SearchTab: public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -63,6 +68,7 @@ public:
Q_ENUMS(NameFilteringMode) Q_ENUMS(NameFilteringMode)
explicit SearchTab(SearchWidget *parent); explicit SearchTab(SearchWidget *parent);
~SearchTab();
QStandardItemModel* getCurrentSearchListModel() const; QStandardItemModel* getCurrentSearchListModel() const;
SearchSortModel* getCurrentSearchListProxy() const; SearchSortModel* getCurrentSearchListProxy() const;
@ -96,8 +102,7 @@ private:
static QString statusText(Status st); static QString statusText(Status st);
static QString statusIconName(Status st); static QString statusIconName(Status st);
QVBoxLayout *m_box; Ui::SearchTab *m_ui;
QLabel *m_resultsLbl;
QTreeView *m_resultsBrowser; QTreeView *m_resultsBrowser;
QStandardItemModel *m_searchListModel; QStandardItemModel *m_searchListModel;
SearchSortModel *m_proxyModel; SearchSortModel *m_proxyModel;

10
src/gui/search/searchtab.ui

@ -16,6 +16,13 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="resultsLbl">
<property name="text">
<string>Results(xxx)</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
@ -233,6 +240,9 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QTreeView" name="resultsBrowser"/>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

Loading…
Cancel
Save