]> granicus.if.org Git - transmission/commitdiff
(qt) #5285 'Qt client's file tree should have a size column like the GTK+ client...
authorJordan Lee <jordan@transmissionbt.com>
Sat, 9 Feb 2013 20:51:17 +0000 (20:51 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sat, 9 Feb 2013 20:51:17 +0000 (20:51 +0000)
qt/file-tree.cc
qt/file-tree.h
qt/freespace-label.cc
qt/options.cc

index 4b89d987db160ffbdf04c0b7e7953d2132233cb6..cc32cea0a05775af62d047a1f32a38f7e2bfd715 100644 (file)
@@ -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
 {
-  uint64_t have = 0;
-  uint64_t total = 0;
+  QString str; 
 
   if (myChildren.isEmpty())
-    total = myTotalSize;
+    {
+      str = Formatter::sizeToString (myTotalSize);
+    }
   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>
@@ -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 (fileIndex() != -1)
+  if (myHaveSize != haveSize)
     {
-      if (myHaveSize != haveSize)
-        myHaveSize = haveSize;
+      myHaveSize = haveSize;
+      changed_columns[changed_count++] = COL_PROGRESS;
+    }
 
+  if (fileIndex() != -1)
+    {
       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)
-    header()->setResizeMode(i, QHeaderView::Interactive);
+  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;
index 216be089013cbb15b6d46107efcbe5d7ab5e8e69..c65000953ba15d4aa51a086e8010961a3d34ad01 100644 (file)
@@ -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;
index bffda4d53b9b07e0ff40cab5070f31b06d3c8624..816d376151874b41c49a8cde54aaf17c396fdfd0 100644 (file)
@@ -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;
index d97ab32750a8a74a346210e646cc64570f8df119..f4fb5e853f772314b625e76ccb269daefa04a86a 100644 (file)
@@ -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 );