mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-21 08:09:35 +08:00
Make it scroll horizontally when necessary.
This commit is contained in:
parent
ecc19ff23e
commit
9c88959651
@ -122,11 +122,21 @@ QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const
|
||||
value = Utils::Fs::toNativePath(pathData->watchPath);
|
||||
break;
|
||||
case DOWNLOAD:
|
||||
if (role == Qt::DisplayRole) {
|
||||
if (role == Qt::UserRole) {
|
||||
value = pathData->downloadType;
|
||||
}
|
||||
else if ((role == Qt::UserRole) && (pathData->downloadType == CUSTOM_LOCATION)) {
|
||||
value = pathData->downloadPath;
|
||||
else if (role == Qt::DisplayRole) {
|
||||
switch (pathData->downloadType) {
|
||||
case DOWNLOAD_IN_WATCH_FOLDER:
|
||||
value = tr("Watch Folder");
|
||||
break;
|
||||
case DEFAULT_LOCATION:
|
||||
value = tr("Default Folder");
|
||||
break;
|
||||
case CUSTOM_LOCATION:
|
||||
value = pathData->downloadPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -178,7 +188,7 @@ bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
|| (index.column() != DOWNLOAD))
|
||||
return false;
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
if (role == Qt::UserRole) {
|
||||
PathType type = static_cast<PathType>(value.toInt());
|
||||
if (type == CUSTOM_LOCATION)
|
||||
return false;
|
||||
@ -187,7 +197,7 @@ bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
m_pathList[index.row()]->downloadPath.clear();
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
else if (role == Qt::UserRole) {
|
||||
else if (role == Qt::DisplayRole) {
|
||||
QString path = value.toString();
|
||||
if (path.isEmpty()) // means we didn't pass CUSTOM_LOCATION type
|
||||
return false;
|
||||
|
@ -745,6 +745,9 @@
|
||||
<attribute name="headerDefaultSectionSize">
|
||||
<number>80</number>
|
||||
</attribute>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -2724,7 +2727,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>89</width>
|
||||
<width>98</width>
|
||||
<height>28</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -46,50 +46,14 @@ ScanFoldersDelegate::ScanFoldersDelegate(QObject *parent, QTreeView *foldersView
|
||||
{
|
||||
}
|
||||
|
||||
void ScanFoldersDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
painter->save();
|
||||
|
||||
switch(index.column()) {
|
||||
case ScanFoldersModel::WATCH:
|
||||
QItemDelegate::paint(painter, option, index);
|
||||
break;
|
||||
|
||||
case ScanFoldersModel::DOWNLOAD: {
|
||||
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
|
||||
QItemDelegate::drawBackground(painter, opt, index);
|
||||
QString text;
|
||||
|
||||
switch (index.data().toInt()) {
|
||||
case ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER:
|
||||
text = tr("Watch Folder");
|
||||
break;
|
||||
case ScanFoldersModel::DEFAULT_LOCATION:
|
||||
text = tr("Default Folder");
|
||||
break;
|
||||
case ScanFoldersModel::CUSTOM_LOCATION:
|
||||
text = index.data(Qt::UserRole).toString();
|
||||
break;
|
||||
}
|
||||
QItemDelegate::drawDisplay(painter, opt, option.rect, text);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void ScanFoldersDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||
{
|
||||
QComboBox *combobox = static_cast<QComboBox*>(editor);
|
||||
// Set combobox index
|
||||
if (index.data().toInt() == ScanFoldersModel::CUSTOM_LOCATION)
|
||||
if (index.data(Qt::UserRole).toInt() == ScanFoldersModel::CUSTOM_LOCATION)
|
||||
combobox->setCurrentIndex(4); // '4' is the index of the item after the separator in the QComboBox menu
|
||||
else
|
||||
combobox->setCurrentIndex(index.data().toInt());
|
||||
combobox->setCurrentIndex(index.data(Qt::UserRole).toInt());
|
||||
}
|
||||
|
||||
QWidget *ScanFoldersDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
|
||||
@ -102,9 +66,9 @@ QWidget *ScanFoldersDelegate::createEditor(QWidget *parent, const QStyleOptionVi
|
||||
editor->addItem(tr("Watch Folder"));
|
||||
editor->addItem(tr("Default Folder"));
|
||||
editor->addItem(tr("Browse..."));
|
||||
if (index.data().toInt() == ScanFoldersModel::CUSTOM_LOCATION) {
|
||||
if (index.data(Qt::UserRole).toInt() == ScanFoldersModel::CUSTOM_LOCATION) {
|
||||
editor->insertSeparator(3);
|
||||
editor->addItem(index.data(Qt::UserRole).toString());
|
||||
editor->addItem(index.data().toString());
|
||||
}
|
||||
|
||||
connect(editor, SIGNAL(currentIndexChanged(int)), this, SLOT(comboboxIndexChanged(int)));
|
||||
@ -128,7 +92,7 @@ void ScanFoldersDelegate::setModelData(QWidget *editor, QAbstractItemModel *mode
|
||||
switch (value) {
|
||||
case ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER:
|
||||
case ScanFoldersModel::DEFAULT_LOCATION:
|
||||
model->setData(index, value, Qt::DisplayRole);
|
||||
model->setData(index, value, Qt::UserRole);
|
||||
break;
|
||||
|
||||
case ScanFoldersModel::CUSTOM_LOCATION:
|
||||
@ -136,10 +100,10 @@ void ScanFoldersDelegate::setModelData(QWidget *editor, QAbstractItemModel *mode
|
||||
index,
|
||||
QFileDialog::getExistingDirectory(
|
||||
0, tr("Choose save path"),
|
||||
index.data().toInt() == ScanFoldersModel::CUSTOM_LOCATION ?
|
||||
index.data(Qt::UserRole).toString() :
|
||||
index.data(Qt::UserRole).toInt() == ScanFoldersModel::CUSTOM_LOCATION ?
|
||||
index.data().toString() :
|
||||
Preferences::instance()->getSavePath()),
|
||||
Qt::UserRole);
|
||||
Qt::DisplayRole);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -53,7 +53,6 @@ private slots:
|
||||
private:
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
||||
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const;
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user