Some work about adaptive color scheme for Web UI (PR #19901)
http://[316:c51a:62a3:8b9::4]/d4708/qBittorrent/src/branch/adaptive-webui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
5.3 KiB
158 lines
5.3 KiB
17 years ago
|
/*
|
||
|
* Bittorrent Client using Qt4 and libtorrent.
|
||
|
* Copyright (C) 2006 Christophe Dumez
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU General Public License
|
||
|
* as published by the Free Software Foundation; either version 2
|
||
|
* of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*
|
||
16 years ago
|
* In addition, as a special exception, the copyright holders give permission to
|
||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
||
|
* and distribute the linked executables. You must obey the GNU General Public
|
||
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
||
|
* modify file(s), you may extend this exception to your version of the file(s),
|
||
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||
|
* exception statement from your version.
|
||
|
*
|
||
17 years ago
|
* Contact : chris@qbittorrent.org
|
||
|
*/
|
||
|
|
||
|
#include <QDir>
|
||
|
#include <QTreeView>
|
||
|
#include <QStandardItemModel>
|
||
|
#include <QHeaderView>
|
||
15 years ago
|
#include <QSortFilterProxyModel>
|
||
17 years ago
|
|
||
15 years ago
|
#include "searchtab.h"
|
||
|
#include "searchlistdelegate.h"
|
||
17 years ago
|
#include "misc.h"
|
||
15 years ago
|
#include "searchengine.h"
|
||
15 years ago
|
#include "qinisettings.h"
|
||
17 years ago
|
|
||
|
#define SEARCH_NAME 0
|
||
|
#define SEARCH_SIZE 1
|
||
|
#define SEARCH_SEEDERS 2
|
||
|
#define SEARCH_LEECHERS 3
|
||
|
#define SEARCH_ENGINE 4
|
||
|
|
||
15 years ago
|
SearchTab::SearchTab(SearchEngine *parent) : QWidget(), parent(parent)
|
||
17 years ago
|
{
|
||
15 years ago
|
box=new QVBoxLayout();
|
||
|
results_lbl=new QLabel();
|
||
|
resultsBrowser = new QTreeView();
|
||
|
resultsBrowser->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||
|
box->addWidget(results_lbl);
|
||
|
box->addWidget(resultsBrowser);
|
||
|
|
||
|
setLayout(box);
|
||
|
// Set Search results list model
|
||
|
SearchListModel = new QStandardItemModel(0,6);
|
||
|
SearchListModel->setHeaderData(SEARCH_NAME, Qt::Horizontal, tr("Name", "i.e: file name"));
|
||
|
SearchListModel->setHeaderData(SEARCH_SIZE, Qt::Horizontal, tr("Size", "i.e: file size"));
|
||
|
SearchListModel->setHeaderData(SEARCH_SEEDERS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources"));
|
||
|
SearchListModel->setHeaderData(SEARCH_LEECHERS, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources"));
|
||
|
SearchListModel->setHeaderData(SEARCH_ENGINE, Qt::Horizontal, tr("Search engine"));
|
||
|
|
||
|
proxyModel = new QSortFilterProxyModel();
|
||
|
proxyModel->setDynamicSortFilter(true);
|
||
|
proxyModel->setSourceModel(SearchListModel);
|
||
|
resultsBrowser->setModel(proxyModel);
|
||
|
|
||
|
SearchDelegate = new SearchListDelegate();
|
||
|
resultsBrowser->setItemDelegate(SearchDelegate);
|
||
|
|
||
15 years ago
|
resultsBrowser->hideColumn(URL_COLUMN); // Hide url column
|
||
|
|
||
15 years ago
|
resultsBrowser->setRootIsDecorated(false);
|
||
|
resultsBrowser->setAllColumnsShowFocus(true);
|
||
|
resultsBrowser->setSortingEnabled(true);
|
||
|
|
||
|
// Connect signals to slots (search part)
|
||
|
connect(resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadSelectedItem(const QModelIndex&)));
|
||
|
|
||
|
// Load last columns width for search results list
|
||
|
if(!loadColWidthResultsList()){
|
||
|
resultsBrowser->header()->resizeSection(0, 275);
|
||
|
}
|
||
15 years ago
|
|
||
|
// Sort by Seeds
|
||
|
resultsBrowser->sortByColumn(SEEDERS, Qt::DescendingOrder);
|
||
15 years ago
|
}
|
||
|
|
||
|
void SearchTab::downloadSelectedItem(const QModelIndex& index) {
|
||
|
QString engine_url = proxyModel->data(proxyModel->index(index.row(), ENGINE_URL_COLUMN)).toString();
|
||
|
QString torrent_url = proxyModel->data(proxyModel->index(index.row(), URL_COLUMN)).toString();
|
||
|
setRowColor(index.row(), "red");
|
||
|
parent->downloadTorrent(engine_url, torrent_url);
|
||
17 years ago
|
}
|
||
|
|
||
16 years ago
|
SearchTab::~SearchTab() {
|
||
15 years ago
|
delete box;
|
||
|
delete results_lbl;
|
||
|
delete resultsBrowser;
|
||
|
delete SearchListModel;
|
||
|
delete proxyModel;
|
||
|
delete SearchDelegate;
|
||
17 years ago
|
}
|
||
|
|
||
16 years ago
|
QHeaderView* SearchTab::header() const {
|
||
|
return resultsBrowser->header();
|
||
|
}
|
||
|
|
||
|
bool SearchTab::loadColWidthResultsList() {
|
||
15 years ago
|
QIniSettings settings("qBittorrent", "qBittorrent");
|
||
16 years ago
|
QString line = settings.value("SearchResultsColsWidth", QString()).toString();
|
||
|
if(line.isEmpty())
|
||
|
return false;
|
||
|
QStringList width_list = line.split(' ');
|
||
|
if(width_list.size() < SearchListModel->columnCount())
|
||
|
return false;
|
||
|
unsigned int listSize = width_list.size();
|
||
|
for(unsigned int i=0; i<listSize; ++i){
|
||
15 years ago
|
resultsBrowser->header()->resizeSection(i, width_list.at(i).toInt());
|
||
16 years ago
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
17 years ago
|
QLabel* SearchTab::getCurrentLabel()
|
||
|
{
|
||
15 years ago
|
return results_lbl;
|
||
17 years ago
|
}
|
||
|
|
||
|
QTreeView* SearchTab::getCurrentTreeView()
|
||
|
{
|
||
15 years ago
|
return resultsBrowser;
|
||
17 years ago
|
}
|
||
|
|
||
15 years ago
|
QSortFilterProxyModel* SearchTab::getCurrentSearchListProxy() const
|
||
|
{
|
||
|
return proxyModel;
|
||
|
}
|
||
|
|
||
|
QStandardItemModel* SearchTab::getCurrentSearchListModel() const
|
||
17 years ago
|
{
|
||
15 years ago
|
return SearchListModel;
|
||
17 years ago
|
}
|
||
|
|
||
|
// Set the color of a row in data model
|
||
|
void SearchTab::setRowColor(int row, QString color){
|
||
15 years ago
|
proxyModel->setDynamicSortFilter(false);
|
||
15 years ago
|
for(int i=0; i<proxyModel->columnCount(); ++i){
|
||
|
proxyModel->setData(proxyModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole);
|
||
17 years ago
|
}
|
||
15 years ago
|
proxyModel->setDynamicSortFilter(true);
|
||
17 years ago
|
}
|
||
|
|
||
|
|