Changeset 13937


Ignore:
Timestamp:
Feb 2, 2013, 10:29:14 PM (8 years ago)
Author:
jordan
Message:

(qt) #4076 'free space indicator': try a different approach to the visible torrent count

Location:
trunk/qt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/filterbar.cc

    r13927 r13937  
    3232enum
    3333{
    34     TorrentCountRole = Qt::UserRole + 1,
    35     ActivityRole,
    36     TrackerRole
     34  TorrentCountRole = Qt::UserRole + 1,
     35  TorrentCountStringRole,
     36  ActivityRole,
     37  TrackerRole
    3738};
    3839
     
    99100      boundingBox.setLeft (decorationRect.right () + hmargin);
    100101
    101       QRect countRect  = rect (option, index, TorrentCountRole);
     102      QRect countRect  = rect (option, index, TorrentCountStringRole);
    102103      countRect = QStyle::alignedRect (Qt::LeftToRight,
    103104                                       Qt::AlignRight|Qt::AlignVCenter,
     
    111112      drawDecoration (painter, option, decorationRect, decoration (option2,index.data (Qt::DecorationRole)));
    112113      drawDisplay (painter, option, displayRect, index.data (Qt::DisplayRole).toString ());
    113       drawDisplay (painter, disabledOption, countRect, index.data (TorrentCountRole).toString ());
     114      drawDisplay (painter, disabledOption, countRect, index.data (TorrentCountStringRole).toString ());
    114115      drawFocus (painter, option, displayRect|countRect);
    115116    }
     
    133134      size.setHeight (qMax (size.height (), myCombo->iconSize ().height () + 6));
    134135      size.rwidth () += s->pixelMetric (QStyle::PM_FocusFrameHMargin, 0, myCombo);
    135       size.rwidth () += rect (option,index,TorrentCountRole).width ();
     136      size.rwidth () += rect (option,index,TorrentCountStringRole).width ();
    136137      size.rwidth () += hmargin * 4;
    137138      return size;
     
    146147  QComboBox (parent)
    147148{
     149}
     150
     151int
     152FilterBarComboBox :: currentCount () const
     153{
     154  int count = 0;
     155
     156  const QModelIndex modelIndex = model ()->index (currentIndex (), 0, rootModelIndex ());
     157  if (modelIndex.isValid ())
     158    count = modelIndex.data (TorrentCountRole).toInt ();
     159
     160  return count;
    148161}
    149162
     
    186199
    187200      // draw the count
    188       QString text = modelIndex.data (TorrentCountRole).toString ();
     201      QString text = modelIndex.data (TorrentCountStringRole).toString ();
    189202      if (!text.isEmpty ())
    190203        {
     
    210223****/
    211224
    212 QComboBox*
     225FilterBarComboBox *
    213226FilterBar :: createActivityCombo ()
    214227{
    215   QComboBox * c = new FilterBarComboBox (this);
     228  FilterBarComboBox * c = new FilterBarComboBox (this);
    216229  FilterBarComboBoxDelegate * delegate = new FilterBarComboBoxDelegate (0, c);
    217230  c->setItemDelegate (delegate);
     
    319332
    320333  // update the "All" row
    321   myTrackerModel->setData (myTrackerModel->index (0,0), getCountString (myTorrents.rowCount ()), TorrentCountRole);
     334  myTrackerModel->setData (myTrackerModel->index (0,0), myTorrents.rowCount (), TorrentCountRole);
     335  myTrackerModel->setData (myTrackerModel->index (0,0), getCountString (myTorrents.rowCount ()), TorrentCountStringRole);
    322336
    323337  // rows to update
     
    326340      const QString name = readableHostName (host);
    327341      QStandardItem * row = myTrackerModel->findItems (name).front ();
    328       row->setData (getCountString (torrentsPerHost[name]), TorrentCountRole);
     342      const int count = torrentsPerHost[name];
     343      row->setData (count, TorrentCountRole);
     344      row->setData (getCountString (count), TorrentCountStringRole);
    329345      row->setData (favicons.findFromHost (host), Qt::DecorationRole);
    330346    }
     
    359375      // add the row
    360376      QStandardItem * row = new QStandardItem (favicons.findFromHost (host), name);
    361       row->setData (getCountString (torrentsPerHost[host]), TorrentCountRole);
     377      const int count = torrentsPerHost[host];
     378      row->setData (count, TorrentCountRole);
     379      row->setData (getCountString (count), TorrentCountStringRole);
    362380      row->setData (favicons.findFromHost (host), Qt::DecorationRole);
    363381      row->setData (host, TrackerRole);
     
    371389
    372390
    373 QComboBox*
     391FilterBarComboBox *
    374392FilterBar :: createTrackerCombo (QStandardItemModel * model)
    375393{
    376   QComboBox * c = new FilterBarComboBox (this);
     394  FilterBarComboBox * c = new FilterBarComboBox (this);
    377395  FilterBarComboBoxDelegate * delegate = new FilterBarComboBoxDelegate (0, c);
    378396  c->setItemDelegate (delegate);
     
    380398  QStandardItem * row = new QStandardItem (tr ("All"));
    381399  row->setData ("", TrackerRole);
    382   row->setData (getCountString (myTorrents.rowCount ()), TorrentCountRole);
     400  const int count = myTorrents.rowCount ();
     401  row->setData (count, TorrentCountRole);
     402  row->setData (getCountString (count), TorrentCountStringRole);
    383403  model->appendRow (row);
    384404
     
    572592      QModelIndex index = model->index (row, 0);
    573593      const int mode = index.data (ActivityRole).toInt ();
    574       model->setData (index, getCountString (torrentsPerMode[mode]), TorrentCountRole);
     594      const int count = torrentsPerMode [mode];
     595      model->setData (index, count, TorrentCountRole);
     596      model->setData (index, getCountString (count), TorrentCountStringRole);
    575597    }
    576598
    577599  refreshTrackers ();
     600  refreshCountLabel ();
    578601}
    579602
     
    588611{
    589612  const int visibleCount = myFilter.rowCount ();
    590   const int torrentCount = visibleCount + myFilter.hiddenRowCount ();
    591 
    592   if (visibleCount == torrentCount)
     613  const int trackerCount = myTrackerCombo->currentCount ();
     614  const int activityCount = myActivityCombo->currentCount ();
     615
     616  if ((visibleCount == activityCount) || (visibleCount == trackerCount))
    593617    myCountLabel->setText (tr("Show:"));
    594618  else
    595     myCountLabel->setText (tr("Show %Ln:", 0, visibleCount));
    596 }
     619    myCountLabel->setText (tr("Show %Ln of:", 0, visibleCount));
     620}
  • trunk/qt/filterbar.h

    r13927 r13937  
    5454  public:
    5555    FilterBarComboBox (QWidget * parent = 0);
     56    int currentCount () const;
    5657
    5758  protected:
     
    6970
    7071  private:
    71     QComboBox * createTrackerCombo (QStandardItemModel * );
    72     QComboBox * createActivityCombo ();
     72    FilterBarComboBox * createTrackerCombo (QStandardItemModel * );
     73    FilterBarComboBox * createActivityCombo ();
    7374    void recountSoon ();
    7475    void refreshTrackers ();
     
    7980    TorrentModel& myTorrents;
    8081    TorrentFilter& myFilter;
    81     QComboBox * myActivityCombo;
    82     QComboBox * myTrackerCombo;
     82    FilterBarComboBox * myActivityCombo;
     83    FilterBarComboBox * myTrackerCombo;
    8384    QLabel * myCountLabel;
    8485    QStandardItemModel * myTrackerModel;
Note: See TracChangeset for help on using the changeset viewer.