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

10
src/gui/search/searchtab.ui

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

Loading…
Cancel
Save