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