(qt) #5285 'Qt client's file tree should have a size column like the GTK+ client's': done.
This commit is contained in:
parent
90b95697e0
commit
4c3a869a88
|
@ -32,6 +32,7 @@ enum
|
||||||
{
|
{
|
||||||
COL_NAME,
|
COL_NAME,
|
||||||
FIRST_VISIBLE_COLUMN = COL_NAME,
|
FIRST_VISIBLE_COLUMN = COL_NAME,
|
||||||
|
COL_SIZE,
|
||||||
COL_PROGRESS,
|
COL_PROGRESS,
|
||||||
COL_WANTED,
|
COL_WANTED,
|
||||||
COL_PRIORITY,
|
COL_PRIORITY,
|
||||||
|
@ -121,19 +122,27 @@ FileTreeItem :: data (int column, int role) const
|
||||||
|
|
||||||
if (column == COL_FILE_INDEX)
|
if (column == COL_FILE_INDEX)
|
||||||
{
|
{
|
||||||
return myFileIndex;
|
value.setValue (myFileIndex);
|
||||||
}
|
}
|
||||||
else if (role == Qt::EditRole)
|
else if (role == Qt::EditRole)
|
||||||
{
|
{
|
||||||
if (column == 0)
|
if (column == 0)
|
||||||
value.setValue (name());
|
value.setValue (name());
|
||||||
}
|
}
|
||||||
|
else if ((role == Qt::TextAlignmentRole) && column == COL_SIZE)
|
||||||
|
{
|
||||||
|
value = Qt::AlignRight + Qt::AlignVCenter;
|
||||||
|
}
|
||||||
else if (role == Qt::DisplayRole)
|
else if (role == Qt::DisplayRole)
|
||||||
{
|
{
|
||||||
switch(column)
|
switch(column)
|
||||||
{
|
{
|
||||||
case COL_NAME:
|
case COL_NAME:
|
||||||
value.setValue (fileSizeName());
|
value.setValue (name());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case COL_SIZE:
|
||||||
|
value.setValue (sizeString() + " ");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COL_PROGRESS:
|
case COL_PROGRESS:
|
||||||
|
@ -180,17 +189,23 @@ FileTreeItem :: progress () const
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
FileTreeItem :: fileSizeName () const
|
FileTreeItem :: sizeString () const
|
||||||
{
|
{
|
||||||
uint64_t have = 0;
|
QString str;
|
||||||
uint64_t total = 0;
|
|
||||||
|
|
||||||
if (myChildren.isEmpty())
|
if (myChildren.isEmpty())
|
||||||
total = myTotalSize;
|
{
|
||||||
|
str = Formatter::sizeToString (myTotalSize);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
getSubtreeWantedSize (have, total);
|
{
|
||||||
|
uint64_t have = 0;
|
||||||
|
uint64_t total = 0;
|
||||||
|
getSubtreeWantedSize (have, total);
|
||||||
|
str = Formatter::sizeToString (total);
|
||||||
|
}
|
||||||
|
|
||||||
return QString("%1 (%2)").arg(name()).arg(Formatter::sizeToString(total));
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int,int>
|
std::pair<int,int>
|
||||||
|
@ -201,7 +216,7 @@ FileTreeItem :: update (const QString& name,
|
||||||
bool updateFields)
|
bool updateFields)
|
||||||
{
|
{
|
||||||
int changed_count = 0;
|
int changed_count = 0;
|
||||||
int changed_columns[3];
|
int changed_columns[4];
|
||||||
|
|
||||||
if (myName != name)
|
if (myName != name)
|
||||||
{
|
{
|
||||||
|
@ -212,11 +227,14 @@ FileTreeItem :: update (const QString& name,
|
||||||
changed_columns[changed_count++] = COL_NAME;
|
changed_columns[changed_count++] = COL_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (myHaveSize != haveSize)
|
||||||
|
{
|
||||||
|
myHaveSize = haveSize;
|
||||||
|
changed_columns[changed_count++] = COL_PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
if (fileIndex() != -1)
|
if (fileIndex() != -1)
|
||||||
{
|
{
|
||||||
if (myHaveSize != haveSize)
|
|
||||||
myHaveSize = haveSize;
|
|
||||||
|
|
||||||
if (updateFields)
|
if (updateFields)
|
||||||
{
|
{
|
||||||
if (myIsWanted != wanted)
|
if (myIsWanted != wanted)
|
||||||
|
@ -449,6 +467,10 @@ FileTreeModel :: headerData (int column, Qt::Orientation orientation, int role)
|
||||||
data.setValue (tr("File"));
|
data.setValue (tr("File"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case COL_SIZE:
|
||||||
|
data.setValue (tr("Size"));
|
||||||
|
break;
|
||||||
|
|
||||||
case COL_PROGRESS:
|
case COL_PROGRESS:
|
||||||
data.setValue (tr("Progress"));
|
data.setValue (tr("Progress"));
|
||||||
break;
|
break;
|
||||||
|
@ -694,9 +716,9 @@ FileTreeModel :: clicked (const QModelIndex& index)
|
||||||
emit wantedChanged (file_ids, want);
|
emit wantedChanged (file_ids, want);
|
||||||
|
|
||||||
// this changes the name column's parenthetical size-wanted string too...
|
// this changes the name column's parenthetical size-wanted string too...
|
||||||
QModelIndex nameSibling = index.sibling (index.row(), COL_NAME);
|
QModelIndex nameSibling = index.sibling (index.row(), COL_SIZE);
|
||||||
dataChanged (nameSibling, nameSibling);
|
dataChanged (nameSibling, nameSibling);
|
||||||
parentsChanged (nameSibling, COL_NAME);
|
parentsChanged (nameSibling, COL_SIZE);
|
||||||
|
|
||||||
dataChanged (index, index);
|
dataChanged (index, index);
|
||||||
parentsChanged (index, column);
|
parentsChanged (index, column);
|
||||||
|
@ -732,7 +754,6 @@ FileTreeDelegate :: sizeHint(const QStyleOptionViewItem& item, const QModelIndex
|
||||||
case COL_NAME:
|
case COL_NAME:
|
||||||
{
|
{
|
||||||
const QFontMetrics fm(item.font);
|
const QFontMetrics fm(item.font);
|
||||||
const QString text = index.data().toString();
|
|
||||||
const int iconSize = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
|
const int iconSize = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
|
||||||
size.rwidth() = HIG::PAD_SMALL + iconSize;
|
size.rwidth() = HIG::PAD_SMALL + iconSize;
|
||||||
size.rheight() = std::max(iconSize, fm.height());
|
size.rheight() = std::max(iconSize, fm.height());
|
||||||
|
@ -862,13 +883,11 @@ FileTreeView :: FileTreeView (QWidget * parent, bool isEditable):
|
||||||
sortByColumn (COL_NAME, Qt::AscendingOrder);
|
sortByColumn (COL_NAME, Qt::AscendingOrder);
|
||||||
installEventFilter (this);
|
installEventFilter (this);
|
||||||
|
|
||||||
for (int i=0; i<FIRST_VISIBLE_COLUMN; ++i)
|
for (int i=0; i<NUM_COLUMNS; ++i)
|
||||||
hideColumn (i);
|
{
|
||||||
for (int i=LAST_VISIBLE_COLUMN+1; i<NUM_COLUMNS; ++i)
|
setColumnHidden (i, (i<FIRST_VISIBLE_COLUMN) || (LAST_VISIBLE_COLUMN<i));
|
||||||
hideColumn (i);
|
header()->setResizeMode(i, QHeaderView::Interactive);
|
||||||
|
}
|
||||||
for (int i=FIRST_VISIBLE_COLUMN; i<=LAST_VISIBLE_COLUMN; ++i)
|
|
||||||
header()->setResizeMode(i, QHeaderView::Interactive);
|
|
||||||
|
|
||||||
connect (this, SIGNAL(clicked(const QModelIndex&)),
|
connect (this, SIGNAL(clicked(const QModelIndex&)),
|
||||||
this, SLOT(onClicked(const QModelIndex&)));
|
this, SLOT(onClicked(const QModelIndex&)));
|
||||||
|
@ -913,7 +932,12 @@ FileTreeView :: eventFilter (QObject * o, QEvent * event)
|
||||||
if (isColumnHidden (column))
|
if (isColumnHidden (column))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const QString header = myModel.headerData (column, Qt::Horizontal).toString() + " ";
|
QString header;
|
||||||
|
if (column == COL_SIZE)
|
||||||
|
header = "999.9 KiB";
|
||||||
|
else
|
||||||
|
header = myModel.headerData (column, Qt::Horizontal).toString();
|
||||||
|
header += " ";
|
||||||
const int width = fontMetrics.size (0, header).width();
|
const int width = fontMetrics.size (0, header).width();
|
||||||
setColumnWidth (column, width);
|
setColumnWidth (column, width);
|
||||||
left -= width;
|
left -= width;
|
||||||
|
|
|
@ -73,8 +73,8 @@ class FileTreeItem: public QObject
|
||||||
void setSubtreePriority (int priority, QSet<int>& fileIds);
|
void setSubtreePriority (int priority, QSet<int>& fileIds);
|
||||||
void setSubtreeWanted (bool, QSet<int>& fileIds);
|
void setSubtreeWanted (bool, QSet<int>& fileIds);
|
||||||
QString priorityString () const;
|
QString priorityString () const;
|
||||||
|
QString sizeString () const;
|
||||||
void getSubtreeWantedSize (uint64_t& have, uint64_t& total) const;
|
void getSubtreeWantedSize (uint64_t& have, uint64_t& total) const;
|
||||||
QString fileSizeName () const;
|
|
||||||
double progress () const;
|
double progress () const;
|
||||||
int priority () const;
|
int priority () const;
|
||||||
int isSubtreeWanted () const;
|
int isSubtreeWanted () const;
|
||||||
|
|
|
@ -82,10 +82,10 @@ FreespaceLabel :: onSessionExecuted (int64_t tag, const QString& result, struct
|
||||||
int64_t bytes = -1;
|
int64_t bytes = -1;
|
||||||
tr_variantDictFindInt (arguments, TR_KEY_size_bytes, &bytes);
|
tr_variantDictFindInt (arguments, TR_KEY_size_bytes, &bytes);
|
||||||
if (bytes < 0)
|
if (bytes < 0)
|
||||||
str = tr("Error: %1").arg(result);
|
str = tr("<i>Error: %1</i>").arg(result);
|
||||||
else
|
else
|
||||||
str = tr("%1 free").arg(Formatter::sizeToString (bytes));
|
str = tr("%1 free").arg(Formatter::sizeToString (bytes));
|
||||||
setText (QString("<i>%1</i>").arg(str));
|
setText (str);
|
||||||
|
|
||||||
// update the tooltip
|
// update the tooltip
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
|
@ -146,12 +146,12 @@ Options :: Options( Session& session, const Prefs& prefs, const AddData& addme,
|
||||||
|
|
||||||
l = myFreespaceLabel;
|
l = myFreespaceLabel;
|
||||||
layout->addWidget (l, ++row, 0, 1, 2, Qt::Alignment (Qt::AlignRight | Qt::AlignTop));
|
layout->addWidget (l, ++row, 0, 1, 2, Qt::Alignment (Qt::AlignRight | Qt::AlignTop));
|
||||||
layout->setRowMinimumHeight (row, l->height() + HIG::PAD);
|
layout->setRowMinimumHeight (row, l->height() + HIG::PAD_SMALL);
|
||||||
|
|
||||||
myTree = new FileTreeView (0, false);
|
myTree = new FileTreeView (0, false);
|
||||||
layout->addWidget( myTree, ++row, 0, 1, 2 );
|
layout->addWidget( myTree, ++row, 0, 1, 2 );
|
||||||
if( !session.isLocal( ) )
|
if( !session.isLocal( ) )
|
||||||
myTree->hideColumn( 1 ); // hide the % done, since we've no way of knowing
|
myTree->hideColumn( 2 ); // hide the % done, since we've no way of knowing
|
||||||
|
|
||||||
QComboBox * m = new QComboBox;
|
QComboBox * m = new QComboBox;
|
||||||
m->addItem( tr( "High" ), TR_PRI_HIGH );
|
m->addItem( tr( "High" ), TR_PRI_HIGH );
|
||||||
|
|
Loading…
Reference in New Issue