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.
227 lines
8.2 KiB
227 lines
8.2 KiB
18 years ago
|
/*
|
||
|
* Bittorrent Client using Qt4 and libtorrent.
|
||
18 years ago
|
* Copyright (C) 2006 Christophe Dumez
|
||
18 years ago
|
*
|
||
18 years ago
|
* 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.
|
||
18 years ago
|
*
|
||
|
* 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
|
||
18 years ago
|
* 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.
|
||
|
*
|
||
18 years ago
|
* Contact : chris@qbittorrent.org
|
||
18 years ago
|
*/
|
||
|
|
||
|
#ifndef PROPLISTDELEGATE_H
|
||
|
#define PROPLISTDELEGATE_H
|
||
|
|
||
18 years ago
|
#include <QItemDelegate>
|
||
18 years ago
|
#include <QStyleOptionProgressBarV2>
|
||
18 years ago
|
#include <QStyleOptionViewItemV2>
|
||
18 years ago
|
#include <QStyleOptionComboBox>
|
||
|
#include <QComboBox>
|
||
18 years ago
|
#include <QModelIndex>
|
||
|
#include <QPainter>
|
||
|
#include <QProgressBar>
|
||
|
#include <QApplication>
|
||
|
#include "misc.h"
|
||
|
|
||
|
// Defines for properties list columns
|
||
15 years ago
|
enum PropColumn {NAME, SIZE, PROGRESS, PRIORITY};
|
||
15 years ago
|
enum PropPriority {IGNORED=0, NORMAL=1, HIGH=2, MAXIMUM=7};
|
||
18 years ago
|
|
||
18 years ago
|
class PropListDelegate: public QItemDelegate {
|
||
18 years ago
|
Q_OBJECT
|
||
|
|
||
15 years ago
|
signals:
|
||
|
void filteredFilesChanged() const;
|
||
18 years ago
|
|
||
15 years ago
|
public:
|
||
|
PropListDelegate(QObject *parent=0) : QItemDelegate(parent){
|
||
|
}
|
||
18 years ago
|
|
||
15 years ago
|
~PropListDelegate(){}
|
||
18 years ago
|
|
||
15 years ago
|
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
|
||
|
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
|
||
|
switch(index.column()){
|
||
18 years ago
|
case SIZE:
|
||
15 years ago
|
QItemDelegate::drawBackground(painter, opt, index);
|
||
|
QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong()));
|
||
|
break;
|
||
18 years ago
|
case PROGRESS:{
|
||
15 years ago
|
QStyleOptionProgressBarV2 newopt;
|
||
|
float progress = index.data().toDouble()*100.;
|
||
|
newopt.rect = opt.rect;
|
||
|
newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%");
|
||
|
newopt.progress = (int)progress;
|
||
|
newopt.maximum = 100;
|
||
|
newopt.minimum = 0;
|
||
|
newopt.state |= QStyle::State_Enabled;
|
||
|
newopt.textVisible = true;
|
||
|
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
|
||
|
break;
|
||
|
}
|
||
18 years ago
|
case PRIORITY:{
|
||
15 years ago
|
QStyleOptionComboBox newopt;
|
||
|
newopt.rect = opt.rect;
|
||
|
switch(index.data().toInt()){
|
||
18 years ago
|
case IGNORED:
|
||
|
newopt.currentText = tr("Ignored");
|
||
|
break;
|
||
|
case NORMAL:
|
||
|
newopt.currentText = tr("Normal", "Normal (priority)");
|
||
|
break;
|
||
|
case HIGH:
|
||
|
newopt.currentText = tr("High", "High (priority)");
|
||
|
break;
|
||
|
case MAXIMUM:
|
||
|
newopt.currentText = tr("Maximum", "Maximum (priority)");
|
||
|
break;
|
||
|
default:
|
||
|
qDebug("Unhandled priority, setting NORMAL");
|
||
|
newopt.currentText = tr("Normal", "Normal (priority)");
|
||
15 years ago
|
}
|
||
15 years ago
|
//newopt.state |= QStyle::State_Enabled;
|
||
|
//newopt.subControls = QStyle::SC_All;
|
||
15 years ago
|
//painter->translate(QPoint(opt.rect.x()*-1,opt.rect.y()*-1));
|
||
|
//QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &newopt, painter);
|
||
|
//painter->translate(QPoint(opt.rect.x(),opt.rect.y()));
|
||
15 years ago
|
//QApplication::style()->drawControl(QStyle::CE_ComboBoxLabel, &newopt, painter);
|
||
|
QItemDelegate::drawBackground(painter, opt, index);
|
||
|
QItemDelegate::drawDisplay(painter, opt, option.rect, newopt.currentText);
|
||
15 years ago
|
break;
|
||
18 years ago
|
}
|
||
|
default:
|
||
18 years ago
|
QItemDelegate::paint(painter, option, index);
|
||
15 years ago
|
}
|
||
|
}
|
||
18 years ago
|
|
||
15 years ago
|
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex & index) const {
|
||
|
qDebug("CreateEditor called");
|
||
|
if(index.column() != PRIORITY) return 0;
|
||
|
QComboBox* editor = new QComboBox(parent);
|
||
|
editor->setFocusPolicy(Qt::StrongFocus);
|
||
|
editor->addItem(tr("Ignored"));
|
||
|
editor->addItem(tr("Normal", "Normal (priority)"));
|
||
|
editor->addItem(tr("High", "High (priority)"));
|
||
|
editor->addItem(tr("Maximum", "Maximum (priority)"));
|
||
|
return editor;
|
||
|
}
|
||
18 years ago
|
|
||
15 years ago
|
void setEditorData(QWidget *editor, const QModelIndex &index) const {
|
||
|
qDebug("setEditorData called");
|
||
|
unsigned short val = index.model()->data(index, Qt::DisplayRole).toInt();
|
||
|
QComboBox *combobox = static_cast<QComboBox*>(editor);
|
||
|
qDebug("Set Editor data: Prio is %d", val);
|
||
|
switch(val){
|
||
18 years ago
|
case IGNORED:
|
||
15 years ago
|
combobox->setCurrentIndex(0);
|
||
|
break;
|
||
18 years ago
|
case NORMAL:
|
||
15 years ago
|
combobox->setCurrentIndex(1);
|
||
|
break;
|
||
18 years ago
|
case HIGH:
|
||
15 years ago
|
combobox->setCurrentIndex(2);
|
||
|
break;
|
||
18 years ago
|
case MAXIMUM:
|
||
15 years ago
|
combobox->setCurrentIndex(3);
|
||
|
break;
|
||
18 years ago
|
default:
|
||
15 years ago
|
qDebug("Unhandled priority, setting to NORMAL");
|
||
|
combobox->setCurrentIndex(1);
|
||
18 years ago
|
}
|
||
15 years ago
|
}
|
||
18 years ago
|
|
||
15 years ago
|
QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const{
|
||
|
QVariant value = index.data(Qt::FontRole);
|
||
|
QFont fnt = value.isValid() ? qvariant_cast<QFont>(value) : option.font;
|
||
|
QFontMetrics fontMetrics(fnt);
|
||
|
const QString text = index.data(Qt::DisplayRole).toString();
|
||
|
QRect textRect = QRect(0, 0, 0, fontMetrics.lineSpacing() * (text.count(QLatin1Char('\n')) + 1));
|
||
15 years ago
|
textRect.setHeight(textRect.height()+4);
|
||
15 years ago
|
return textRect.size();
|
||
|
}
|
||
18 years ago
|
|
||
|
public slots:
|
||
15 years ago
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
|
||
|
QComboBox *combobox = static_cast<QComboBox*>(editor);
|
||
|
int value = combobox->currentIndex();
|
||
|
qDebug("Setting combobox value in index: %d", value);
|
||
|
unsigned short old_val = index.model()->data(index, Qt::DisplayRole).toInt();
|
||
|
switch(value){
|
||
18 years ago
|
case 0:
|
||
15 years ago
|
if(old_val != IGNORED){
|
||
|
model->setData(index, QVariant(IGNORED));
|
||
|
emit filteredFilesChanged();
|
||
|
} else {
|
||
|
// XXX: hack to force the model to send the itemChanged() signal
|
||
|
model->setData(index, QVariant(NORMAL));
|
||
|
model->setData(index, QVariant(IGNORED));
|
||
|
}
|
||
|
break;
|
||
18 years ago
|
case 1:
|
||
15 years ago
|
// if(old_val != NORMAL){
|
||
|
// model->setData(index, QVariant(NORMAL));
|
||
|
// if(filteredFilesChanged != 0)
|
||
|
// *filteredFilesChanged = true;
|
||
|
// } else {
|
||
|
model->setData(index, QVariant(HIGH));
|
||
|
model->setData(index, QVariant(NORMAL));
|
||
|
emit filteredFilesChanged();
|
||
|
// }
|
||
|
break;
|
||
18 years ago
|
case 2:
|
||
15 years ago
|
if(old_val != HIGH){
|
||
|
model->setData(index, QVariant(HIGH));
|
||
|
emit filteredFilesChanged();
|
||
|
} else {
|
||
|
model->setData(index, QVariant(NORMAL));
|
||
|
model->setData(index, QVariant(HIGH));
|
||
|
}
|
||
|
break;
|
||
18 years ago
|
case 3:
|
||
15 years ago
|
if(old_val != MAXIMUM){
|
||
|
model->setData(index, QVariant(MAXIMUM));
|
||
|
emit filteredFilesChanged();
|
||
|
} else {
|
||
|
model->setData(index, QVariant(HIGH));
|
||
|
model->setData(index, QVariant(MAXIMUM));
|
||
|
}
|
||
|
break;
|
||
18 years ago
|
default:
|
||
15 years ago
|
if(old_val != NORMAL){
|
||
|
model->setData(index, QVariant(NORMAL));
|
||
|
emit filteredFilesChanged();
|
||
|
} else {
|
||
|
model->setData(index, QVariant(HIGH));
|
||
|
model->setData(index, QVariant(NORMAL));
|
||
18 years ago
|
}
|
||
18 years ago
|
}
|
||
15 years ago
|
}
|
||
18 years ago
|
|
||
15 years ago
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const {
|
||
|
qDebug("UpdateEditor Geometry called");
|
||
|
editor->setGeometry(option.rect);
|
||
|
}
|
||
17 years ago
|
|
||
18 years ago
|
};
|
||
|
|
||
|
#endif
|