Changeset 14387


Ignore:
Timestamp:
Dec 14, 2014, 6:12:21 PM (8 years ago)
Author:
mikedld
Message:

Rework torrent details dialog in Qt client to load from .ui

Make squeeze labels (used for values on Information tab) display tooltip
on hover if their text doesn't fit. Make selective labels (same as in
GTK+ client) text selectable with keyboard in addition to mouse.
Prevent dialog width growth occured before to fit long error texts.

Location:
trunk/qt
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/CMakeLists.txt

    r14350 r14387  
    102102
    103103tr_qt_wrap_ui(${PROJECT_NAME}_UI_SOURCES
     104    details.ui
    104105    mainwin.ui
    105106)
  • trunk/qt/details.cc

    r14386 r14387  
    1212#include <ctime>
    1313
    14 #include <QCheckBox>
    15 #include <QComboBox>
    1614#include <QDateTime>
    1715#include <QDesktopServices>
    18 #include <QDialogButtonBox>
    19 #include <QDoubleSpinBox>
    2016#include <QEvent>
    2117#include <QFont>
    2218#include <QFontMetrics>
    23 #include <QHBoxLayout>
    24 #include <QHBoxLayout>
    2519#include <QHeaderView>
    2620#include <QHostAddress>
     
    3125#include <QMap>
    3226#include <QMessageBox>
    33 #include <QPushButton>
    34 #include <QRadioButton>
    3527#include <QResizeEvent>
    36 #include <QSpinBox>
    3728#include <QStringList>
    3829#include <QStyle>
    39 #include <QTabWidget>
    40 #include <QTextBrowser>
    41 #include <QTreeView>
    42 #include <QTreeWidget>
    4330#include <QTreeWidgetItem>
    44 #include <QVBoxLayout>
    4531
    4632#include <libtransmission/transmission.h>
     
    5945#include "tracker-model.h"
    6046#include "tracker-model-filter.h"
     47#include "utils.h"
    6148
    6249class Prefs;
     
    8471    N_COLUMNS
    8572  };
     73
     74  int
     75  measureViewItem (QAbstractItemView * view, const QString& text)
     76  {
     77    QStyleOptionViewItemV4 option;
     78    option.features = QStyleOptionViewItemV2::HasDisplay;
     79    option.text = text;
     80    return view->style ()->sizeFromContents (QStyle::CT_ItemViewItem, &option,
     81      QSize (QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), view).width ();
     82  }
    8683}
    8784
     
    185182  myHavePendingRefresh (false)
    186183{
    187   QVBoxLayout * layout = new QVBoxLayout (this);
    188 
    189   setWindowTitle (tr ("Torrent Properties"));
    190 
    191   QTabWidget * t = new QTabWidget (this);
    192   QWidget * w;
    193   t->addTab (w = createInfoTab (),      tr ("Information"));
    194   myWidgets << w;
    195   t->addTab (w = createPeersTab (),     tr ("Peers"));
    196   myWidgets << w;
    197   t->addTab (w = createTrackerTab (),   tr ("Tracker"));
    198   myWidgets << w;
    199   t->addTab (w = createFilesTab (),     tr ("Files"));
    200   myWidgets << w;
    201   t->addTab (w = createOptionsTab (),   tr ("Options"));
    202   myWidgets << w;
    203   layout->addWidget (t);
    204 
    205   QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Close, Qt::Horizontal, this);
    206   connect (buttons, SIGNAL (rejected ()), this, SLOT (close ()));
    207   layout->addWidget (buttons);
    208   QWidget::setAttribute (Qt::WA_DeleteOnClose, true);
     184  ui.setupUi(this);
     185
     186  initInfoTab ();
     187  initPeersTab ();
     188  initTrackerTab ();
     189  initFilesTab ();
     190  initOptionsTab ();
     191
     192  adjustSize ();
     193  ui.commentBrowser->setMaximumHeight (QWIDGETSIZE_MAX);
     194
     195  setAttribute (Qt::WA_DeleteOnClose, true);
    209196
    210197  QList<int> initKeys;
     
    245232    }
    246233
    247   myFileTreeView->clear ();
     234  ui.filesView->clear ();
    248235  myIds = ids;
    249236  myTrackerModel->refresh (myModel, myIds);
     
    257244    }
    258245
    259   foreach (QWidget * w, myWidgets)
    260     w->setEnabled (false);
     246  for (int i = 0; i < ui.tabs->count (); ++i)
     247    ui.tabs->widget (i)->setEnabled (false);
    261248
    262249  onTimer ();
     
    272259      case Prefs::SHOW_TRACKER_SCRAPES:
    273260        {
    274           QItemSelectionModel * selectionModel (myTrackerView->selectionModel ());
     261          QItemSelectionModel * selectionModel (ui.trackersView->selectionModel ());
    275262          const QItemSelection selection (selectionModel->selection ());
    276263          const QModelIndex currentIndex (selectionModel->currentIndex ());
    277264          myTrackerDelegate->setShowMore (myPrefs.getBool (key));
    278265          selectionModel->clear ();
    279           myTrackerView->reset ();
     266          ui.trackersView->reset ();
    280267          selectionModel->select (selection, QItemSelectionModel::Select);
    281268          selectionModel->setCurrentIndex (currentIndex, QItemSelectionModel::NoUpdate);
     
    430417        string = torrents[0]->activityString ();
    431418    }
    432   myStateLabel->setText (string);
     419  ui.stateValueLabel->setText (string);
    433420  const QString stateString = string;
    434421
     
    488475        }
    489476    }
    490   myHaveLabel->setText (string);
     477  ui.haveValueLabel->setText (string);
    491478
    492479  // myAvailabilityLabel
     
    497484  else
    498485    string = QString ("%1%").arg (Formatter::percentToString ( (100.0 * available) / sizeWhenDone));
    499   myAvailabilityLabel->setText (string);
     486  ui.availabilityValueLabel->setText (string);
    500487
    501488  // myDownloadedLabel
     
    520507        string = dstr;
    521508    }
    522   myDownloadedLabel->setText (string);
     509  ui.downloadedValueLabel->setText (string);
    523510
    524511  //  myUploadedLabel
     
    540527                 .arg (Formatter::ratioToString (tr_getRatio (u, d)));
    541528    }
    542   myUploadedLabel->setText (string);
     529  ui.uploadedValueLabel->setText (string);
    543530
    544531  const QDateTime qdt_now = QDateTime::currentDateTime ();
     
    568555        string = Formatter::timeToString (baseline.secsTo (qdt_now));
    569556    }
    570   myRunTimeLabel->setText (string);
     557  ui.runningTimeValueLabel->setText (string);
    571558
    572559
     
    597584       }
    598585    }
    599   myETALabel->setText (string);
     586  ui.remainingTimeValueLabel->setText (string);
    600587
    601588
     
    623610        string = tr ("%1 ago").arg (Formatter::timeToString (seconds));
    624611    }
    625   myLastActivityLabel->setText (string);
     612  ui.lastActivityValueLabel->setText (string);
    626613
    627614
     
    644631  if (string.isEmpty ())
    645632    string = none;
    646   myErrorLabel->setText (string);
     633  ui.errorValueLabel->setText (string);
    647634
    648635
     
    679666                   .arg (Formatter::sizeToString (size));
    680667    }
    681   mySizeLabel->setText (string);
     668  ui.sizeValueLabel->setText (string);
    682669
    683670  // myHashLabel
     
    695682        }
    696683    }
    697   myHashLabel->setText (string);
     684  ui.hashValueLabel->setText (string);
    698685
    699686  // myPrivacyLabel
     
    713700        }
    714701    }
    715   myPrivacyLabel->setText (string);
     702  ui.privacyValueLabel->setText (string);
    716703
    717704  // myCommentBrowser
    718705  string = none;
     706  bool isCommentMixed = false;
    719707  if (!torrents.empty ())
    720708    {
     
    725713            {
    726714              string = mixed;
     715              isCommentMixed = true;
    727716              break;
    728717            }
    729718        }
    730719    }
    731   if (myCommentBrowser->toPlainText() != string)
    732     {
    733       myCommentBrowser->setText (string);
    734       myCommentBrowser->setMaximumHeight (QWIDGETSIZE_MAX);
    735     }
     720  if (ui.commentBrowser->toPlainText() != string)
     721    {
     722      ui.commentBrowser->setText (string);
     723    }
     724  ui.commentBrowser->setEnabled (!isCommentMixed && !string.isEmpty ());
    736725
    737726  // myOriginLabel
     
    759748        string = tr ("Created by %1 on %2").arg (creator).arg (date);
    760749    }
    761   myOriginLabel->setText (string);
     750  ui.originValueLabel->setText (string);
    762751
    763752  // myLocationLabel
     
    775764        }
    776765    }
    777   myLocationLabel->setText (string);
     766  ui.locationValueLabel->setText (string);
    778767
    779768
     
    795784      baselineFlag = baseline->honorsSessionLimits ();
    796785      foreach (tor, torrents) if (baselineFlag != tor->honorsSessionLimits ()) { uniform = false; break; }
    797       mySessionLimitCheck->setChecked (uniform && baselineFlag);
     786      ui.sessionLimitCheck->setChecked (uniform && baselineFlag);
    798787
    799788      // mySingleDownCheck
     
    801790      baselineFlag = baseline->downloadIsLimited ();
    802791      foreach (tor, torrents) if (baselineFlag != tor->downloadIsLimited ()) { uniform = false; break; }
    803       mySingleDownCheck->setChecked (uniform && baselineFlag);
     792      ui.singleDownCheck->setChecked (uniform && baselineFlag);
    804793
    805794      // mySingleUpCheck
     
    807796      baselineFlag = baseline->uploadIsLimited ();
    808797      foreach (tor, torrents) if (baselineFlag != tor->uploadIsLimited ()) { uniform = false; break; }
    809       mySingleUpCheck->setChecked (uniform && baselineFlag);
     798      ui.singleUpCheck->setChecked (uniform && baselineFlag);
    810799
    811800      // myBandwidthPriorityCombo
     
    814803      foreach (tor, torrents) if (baselineInt != tor->getBandwidthPriority ()) { uniform = false; break; }
    815804      if (uniform)
    816         i = myBandwidthPriorityCombo->findData (baselineInt);
     805        i = ui.bandwidthPriorityCombo->findData (baselineInt);
    817806      else
    818807        i = -1;
    819       setIfIdle (myBandwidthPriorityCombo, i);
    820 
    821       setIfIdle (mySingleDownSpin, int (tor->downloadLimit ().KBps ()));
    822       setIfIdle (mySingleUpSpin, int (tor->uploadLimit ().KBps ()));
    823       setIfIdle (myPeerLimitSpin, tor->peerLimit ());
     808      setIfIdle (ui.bandwidthPriorityCombo, i);
     809
     810      setIfIdle (ui.singleDownSpin, int (tor->downloadLimit ().KBps ()));
     811      setIfIdle (ui.singleUpSpin, int (tor->uploadLimit ().KBps ()));
     812      setIfIdle (ui.peerLimitSpin, tor->peerLimit ());
    824813    }
    825814
     
    833822      foreach (tor, torrents) if (baselineInt != tor->seedRatioMode ()) { uniform = false; break; }
    834823
    835       setIfIdle (myRatioCombo, uniform ? myRatioCombo->findData (baselineInt) : -1);
    836       myRatioSpin->setVisible (uniform && (baselineInt == TR_RATIOLIMIT_SINGLE));
    837 
    838       setIfIdle (myRatioSpin, tor->seedRatioLimit ());
     824      setIfIdle (ui.ratioCombo, uniform ? ui.ratioCombo->findData (baselineInt) : -1);
     825      ui.ratioSpin->setVisible (uniform && (baselineInt == TR_RATIOLIMIT_SINGLE));
     826
     827      setIfIdle (ui.ratioSpin, tor->seedRatioLimit ());
    839828
    840829      // idle
     
    843832      foreach (tor, torrents) if (baselineInt != tor->seedIdleMode ()) { uniform = false; break; }
    844833
    845       setIfIdle (myIdleCombo, uniform ? myIdleCombo->findData (baselineInt) : -1);
    846       myIdleSpin->setVisible (uniform && (baselineInt == TR_RATIOLIMIT_SINGLE));
    847 
    848       setIfIdle (myIdleSpin, tor->seedIdleLimit ());
     834      setIfIdle (ui.idleCombo, uniform ? ui.idleCombo->findData (baselineInt) : -1);
     835      ui.idleSpin->setVisible (uniform && (baselineInt == TR_RATIOLIMIT_SINGLE));
     836
     837      setIfIdle (ui.idleSpin, tor->seedIdleLimit ());
    849838    }
    850839
     
    927916    }
    928917
    929   myPeerTree->addTopLevelItems (newItems);
     918  ui.peersView->addTopLevelItems (newItems);
    930919  foreach (QString key, myPeers.keys ())
    931920    {
     
    933922        {
    934923          QTreeWidgetItem * item = myPeers.value (key, 0);
    935           myPeerTree->takeTopLevelItem (myPeerTree->indexOfTopLevelItem (item));
     924          ui.peersView->takeTopLevelItem (ui.peersView->indexOfTopLevelItem (item));
    936925          delete item;
    937926        }
     
    940929
    941930  if (!single)
    942     myFileTreeView->clear ();
     931    ui.filesView->clear ();
    943932  if (single)
    944     myFileTreeView->update (torrents[0]->files (), myChangedTorrents);
     933    ui.filesView->update (torrents[0]->files (), myChangedTorrents);
    945934
    946935  myChangedTorrents = false;
    947936  myHavePendingRefresh = false;
    948   foreach (QWidget * w, myWidgets)
    949     w->setEnabled (true);
    950 }
    951 
    952 void
    953 Details::enableWhenChecked (QCheckBox * box, QWidget * w)
    954 {
    955   connect (box, SIGNAL (toggled (bool)), w, SLOT (setEnabled (bool)));
    956   w->setEnabled (box->isChecked ());
    957 }
    958 
     937  for (int i = 0; i < ui.tabs->count (); ++i)
     938    ui.tabs->widget (i)->setEnabled (true);
     939}
    959940
    960941/***
     
    962943***/
    963944
    964 QWidget *
    965 Details::createInfoTab ()
    966 {
    967   HIG * hig = new HIG (this);
    968 
    969   hig->addSectionTitle (tr ("Activity"));
    970   hig->addRow (tr ("Have:"), myHaveLabel = new SqueezeLabel);
    971   hig->addRow (tr ("Availability:"), myAvailabilityLabel = new SqueezeLabel);
    972   hig->addRow (tr ("Uploaded:"), myUploadedLabel = new SqueezeLabel);
    973   hig->addRow (tr ("Downloaded:"), myDownloadedLabel = new SqueezeLabel);
    974   hig->addRow (tr ("State:"), myStateLabel = new SqueezeLabel);
    975   hig->addRow (tr ("Running time:"), myRunTimeLabel = new SqueezeLabel);
    976   hig->addRow (tr ("Remaining time:"), myETALabel = new SqueezeLabel);
    977   hig->addRow (tr ("Last activity:"), myLastActivityLabel = new SqueezeLabel);
    978   hig->addRow (tr ("Error:"), myErrorLabel = new SqueezeLabel);
    979   hig->addSectionDivider ();
    980 
    981   hig->addSectionDivider ();
    982   hig->addSectionTitle (tr ("Details"));
    983   hig->addRow (tr ("Size:"), mySizeLabel = new SqueezeLabel);
    984   hig->addRow (tr ("Location:"), myLocationLabel = new SqueezeLabel);
    985   hig->addRow (tr ("Hash:"), myHashLabel = new SqueezeLabel);
    986   hig->addRow (tr ("Privacy:"), myPrivacyLabel = new SqueezeLabel);
    987   hig->addRow (tr ("Origin:"), myOriginLabel = new SqueezeLabel);
    988   myOriginLabel->setMinimumWidth (325); // stop long origin strings from resizing the widgit
    989   hig->addRow (tr ("Comment:"), myCommentBrowser = new QTextBrowser);
    990   const int h = QFontMetrics (myCommentBrowser->font ()).lineSpacing () * 4;
    991   myCommentBrowser->setFixedHeight (h);
    992 
    993   hig->finish ();
    994 
    995   return hig;
     945void
     946Details::initInfoTab ()
     947{
     948  const int h = QFontMetrics (ui.commentBrowser->font ()).lineSpacing () * 4;
     949  ui.commentBrowser->setFixedHeight (h);
    996950}
    997951
     
    10471001Details::onIdleModeChanged (int index)
    10481002{
    1049   const int val = myIdleCombo->itemData (index).toInt ();
     1003  const int val = ui.idleCombo->itemData (index).toInt ();
    10501004  mySession.torrentSet (myIds, TR_KEY_seedIdleMode, val);
    10511005  getNewData ();
     
    10551009Details::onRatioModeChanged (int index)
    10561010{
    1057   const int val = myRatioCombo->itemData (index).toInt ();
     1011  const int val = ui.ratioCombo->itemData (index).toInt ();
    10581012  mySession.torrentSet (myIds, TR_KEY_seedRatioMode, val);
    10591013}
     
    10641018  if (index != -1)
    10651019    {
    1066       const int priority = myBandwidthPriorityCombo->itemData (index).toInt ();
     1020      const int priority = ui.bandwidthPriorityCombo->itemData (index).toInt ();
    10671021      mySession.torrentSet (myIds, TR_KEY_bandwidthPriority, priority);
    10681022      getNewData ();
     
    10731027Details::onTrackerSelectionChanged ()
    10741028{
    1075   const int selectionCount = myTrackerView->selectionModel ()->selectedRows ().size ();
    1076   myEditTrackerButton->setEnabled (selectionCount == 1);
    1077   myRemoveTrackerButton->setEnabled (selectionCount > 0);
     1029  const int selectionCount = ui.trackersView->selectionModel ()->selectedRows ().size ();
     1030  ui.editTrackerButton->setEnabled (selectionCount == 1);
     1031  ui.removeTrackerButton->setEnabled (selectionCount > 0);
    10781032}
    10791033
     
    11191073Details::onEditTrackerClicked ()
    11201074{
    1121   QItemSelectionModel * selectionModel = myTrackerView->selectionModel ();
     1075  QItemSelectionModel * selectionModel = ui.trackersView->selectionModel ();
    11221076  QModelIndexList selectedRows = selectionModel->selectedRows ();
    11231077  assert (selectedRows.size () == 1);
    11241078  QModelIndex i = selectionModel->currentIndex ();
    1125   const TrackerInfo trackerInfo = myTrackerView->model ()->data (i, TrackerModel::TrackerRole).value<TrackerInfo> ();
     1079  const TrackerInfo trackerInfo = ui.trackersView->model ()->data (i, TrackerModel::TrackerRole).value<TrackerInfo> ();
    11261080
    11271081  bool ok = false;
     
    11561110{
    11571111  // make a map of torrentIds to announce URLs to remove
    1158   QItemSelectionModel * selectionModel = myTrackerView->selectionModel ();
     1112  QItemSelectionModel * selectionModel = ui.trackersView->selectionModel ();
    11591113  QModelIndexList selectedRows = selectionModel->selectedRows ();
    11601114  QMap<int,int> torrentId_to_trackerIds;
    11611115  foreach (QModelIndex i, selectedRows)
    11621116    {
    1163       const TrackerInfo inf = myTrackerView->model ()->data (i, TrackerModel::TrackerRole).value<TrackerInfo> ();
     1117      const TrackerInfo inf = ui.trackersView->model ()->data (i, TrackerModel::TrackerRole).value<TrackerInfo> ();
    11641118      torrentId_to_trackerIds.insertMulti (inf.torrentId, inf.st.id);
    11651119    }
     
    11771131}
    11781132
    1179 QWidget *
    1180 Details::createOptionsTab ()
    1181 {
    1182   QSpinBox * s;
    1183   QCheckBox * c;
    1184   QComboBox * m;
    1185   QHBoxLayout * h;
    1186   QDoubleSpinBox * ds;
     1133void
     1134Details::initOptionsTab ()
     1135{
    11871136  const QString speed_K_str = Formatter::unitStr (Formatter::SPEED, Formatter::KB);
    11881137
    1189   HIG * hig = new HIG (this);
    1190   hig->addSectionTitle (tr ("Speed"));
    1191 
    1192   c = new QCheckBox (tr ("Honor global &limits"));
    1193   mySessionLimitCheck = c;
    1194   hig->addWideControl (c);
    1195   connect (c, SIGNAL (clicked (bool)), this, SLOT (onHonorsSessionLimitsToggled (bool)));
    1196 
    1197   c = new QCheckBox (tr ("Limit &download speed (%1):").arg (speed_K_str));
    1198   mySingleDownCheck = c;
    1199   s = new QSpinBox ();
    1200   s->setProperty (PREF_KEY, TR_KEY_downloadLimit);
    1201   s->setSingleStep (5);
    1202   s->setRange (0, INT_MAX);
    1203   mySingleDownSpin = s;
    1204   hig->addRow (c, s);
    1205   enableWhenChecked (c, s);
    1206   connect (c, SIGNAL (clicked (bool)), this, SLOT (onDownloadLimitedToggled (bool)));
    1207   connect (s, SIGNAL (editingFinished ()), this, SLOT (onSpinBoxEditingFinished ()));
    1208 
    1209   c = new QCheckBox (tr ("Limit &upload speed (%1):").arg (speed_K_str));
    1210   mySingleUpCheck = c;
    1211   s = new QSpinBox ();
    1212   s->setSingleStep (5);
    1213   s->setRange (0, INT_MAX);
    1214   s->setProperty (PREF_KEY, TR_KEY_uploadLimit);
    1215   mySingleUpSpin = s;
    1216   hig->addRow (c, s);
    1217   enableWhenChecked (c, s);
    1218   connect (c, SIGNAL (clicked (bool)), this, SLOT (onUploadLimitedToggled (bool)));
    1219   connect (s, SIGNAL (editingFinished ()), this, SLOT (onSpinBoxEditingFinished ()));
    1220 
    1221   m = new QComboBox;
    1222   m->addItem (tr ("High"),   TR_PRI_HIGH);
    1223   m->addItem (tr ("Normal"), TR_PRI_NORMAL);
    1224   m->addItem (tr ("Low"),    TR_PRI_LOW);
    1225   connect (m, SIGNAL (currentIndexChanged (int)), this, SLOT (onBandwidthPriorityChanged (int)));
    1226   hig->addRow (tr ("Torrent &priority:"), m);
    1227   myBandwidthPriorityCombo = m;
    1228 
    1229   hig->addSectionDivider ();
    1230   hig->addSectionTitle (tr ("Seeding Limits"));
    1231 
    1232   h = new QHBoxLayout ();
    1233   h->setSpacing (HIG::PAD);
    1234   m = new QComboBox;
    1235   m->addItem (tr ("Use Global Settings"),      TR_RATIOLIMIT_GLOBAL);
    1236   m->addItem (tr ("Seed regardless of ratio"), TR_RATIOLIMIT_UNLIMITED);
    1237   m->addItem (tr ("Stop seeding at ratio:"),   TR_RATIOLIMIT_SINGLE);
    1238   connect (m, SIGNAL (currentIndexChanged (int)), this, SLOT (onRatioModeChanged (int)));
    1239   h->addWidget (myRatioCombo = m);
    1240   ds = new QDoubleSpinBox ();
    1241   ds->setRange (0.5, INT_MAX);
    1242   ds->setProperty (PREF_KEY, TR_KEY_seedRatioLimit);
    1243   connect (ds, SIGNAL (editingFinished ()), this, SLOT (onSpinBoxEditingFinished ()));
    1244   h->addWidget (myRatioSpin = ds);
    1245   hig->addRow (tr ("&Ratio:"), h, m);
    1246 
    1247   h = new QHBoxLayout ();
    1248   h->setSpacing (HIG::PAD);
    1249   m = new QComboBox;
    1250   m->addItem (tr ("Use Global Settings"),                 TR_IDLELIMIT_GLOBAL);
    1251   m->addItem (tr ("Seed regardless of activity"),         TR_IDLELIMIT_UNLIMITED);
    1252   m->addItem (tr ("Stop seeding if idle for N minutes:"), TR_IDLELIMIT_SINGLE);
    1253   connect (m, SIGNAL (currentIndexChanged (int)), this, SLOT (onIdleModeChanged (int)));
    1254   h->addWidget (myIdleCombo = m);
    1255   s = new QSpinBox ();
    1256   s->setSingleStep (5);
    1257   s->setRange (1, 9999);
    1258   s->setProperty (PREF_KEY, TR_KEY_seedIdleLimit);
    1259   connect (s, SIGNAL (editingFinished ()), this, SLOT (onSpinBoxEditingFinished ()));
    1260   h->addWidget (myIdleSpin = s);
    1261   hig->addRow (tr ("&Idle:"), h, m);
    1262 
    1263 
    1264   hig->addSectionDivider ();
    1265   hig->addSectionTitle (tr ("Peer Connections"));
    1266 
    1267   s = new QSpinBox ();
    1268   s->setSingleStep (5);
    1269   s->setRange (1, 300);
    1270   s->setProperty (PREF_KEY, TR_KEY_peer_limit);
    1271   connect (s, SIGNAL (editingFinished ()), this, SLOT (onSpinBoxEditingFinished ()));
    1272   myPeerLimitSpin = s;
    1273   hig->addRow (tr ("&Maximum peers:"), s);
    1274 
    1275   hig->finish ();
    1276 
    1277   return hig;
     1138  ui.singleDownCheck->setText (ui.singleDownCheck->text ().arg(speed_K_str));
     1139  ui.singleUpCheck->setText (ui.singleUpCheck->text ().arg(speed_K_str));
     1140
     1141  ui.singleDownSpin->setProperty (PREF_KEY, TR_KEY_downloadLimit);
     1142  ui.singleUpSpin->setProperty (PREF_KEY, TR_KEY_uploadLimit);
     1143  ui.ratioSpin->setProperty (PREF_KEY, TR_KEY_seedRatioLimit);
     1144  ui.idleSpin->setProperty (PREF_KEY, TR_KEY_seedIdleLimit);
     1145  ui.peerLimitSpin->setProperty (PREF_KEY, TR_KEY_peer_limit);
     1146
     1147  ui.bandwidthPriorityCombo->addItem (tr ("High"),   TR_PRI_HIGH);
     1148  ui.bandwidthPriorityCombo->addItem (tr ("Normal"), TR_PRI_NORMAL);
     1149  ui.bandwidthPriorityCombo->addItem (tr ("Low"),    TR_PRI_LOW);
     1150
     1151  ui.ratioCombo->addItem (tr ("Use Global Settings"),      TR_RATIOLIMIT_GLOBAL);
     1152  ui.ratioCombo->addItem (tr ("Seed regardless of ratio"), TR_RATIOLIMIT_UNLIMITED);
     1153  ui.ratioCombo->addItem (tr ("Stop seeding at ratio:"),   TR_RATIOLIMIT_SINGLE);
     1154
     1155  ui.idleCombo->addItem (tr ("Use Global Settings"),                 TR_IDLELIMIT_GLOBAL);
     1156  ui.idleCombo->addItem (tr ("Seed regardless of activity"),         TR_IDLELIMIT_UNLIMITED);
     1157  ui.idleCombo->addItem (tr ("Stop seeding if idle for N minutes:"), TR_IDLELIMIT_SINGLE);
     1158
     1159  connect (ui.sessionLimitCheck, SIGNAL (clicked (bool)), SLOT (onHonorsSessionLimitsToggled (bool)));
     1160  connect (ui.singleDownCheck, SIGNAL (clicked (bool)), SLOT (onDownloadLimitedToggled (bool)));
     1161  connect (ui.singleDownSpin, SIGNAL (editingFinished ()), SLOT (onSpinBoxEditingFinished ()));
     1162  connect (ui.singleUpCheck, SIGNAL (clicked (bool)), SLOT (onUploadLimitedToggled (bool)));
     1163  connect (ui.singleUpSpin, SIGNAL (editingFinished ()), SLOT (onSpinBoxEditingFinished ()));
     1164  connect (ui.bandwidthPriorityCombo, SIGNAL (currentIndexChanged (int)), SLOT (onBandwidthPriorityChanged (int)));
     1165  connect (ui.ratioCombo, SIGNAL (currentIndexChanged (int)), SLOT (onRatioModeChanged (int)));
     1166  connect (ui.ratioSpin, SIGNAL (editingFinished ()), SLOT (onSpinBoxEditingFinished ()));
     1167  connect (ui.idleCombo, SIGNAL (currentIndexChanged (int)), SLOT (onIdleModeChanged (int)));
     1168  connect (ui.idleSpin, SIGNAL (editingFinished ()), SLOT (onSpinBoxEditingFinished ()));
     1169  connect (ui.peerLimitSpin, SIGNAL (editingFinished ()), SLOT (onSpinBoxEditingFinished ()));
    12781170}
    12791171
     
    12821174***/
    12831175
    1284 QWidget *
    1285 Details::createTrackerTab ()
    1286 {
    1287   QCheckBox * c;
    1288   QPushButton * p;
    1289   QWidget * top = new QWidget;
    1290   QVBoxLayout * v = new QVBoxLayout (top);
    1291   QHBoxLayout * h = new QHBoxLayout ();
    1292   QVBoxLayout * v2 = new QVBoxLayout ();
    1293 
    1294   v->setSpacing (HIG::PAD_BIG);
    1295   v->setContentsMargins (HIG::PAD_BIG, HIG::PAD_BIG, HIG::PAD_BIG, HIG::PAD_BIG);
    1296 
    1297   h->setSpacing (HIG::PAD);
    1298   h->setContentsMargins (HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL);
    1299 
    1300   v2->setSpacing (HIG::PAD);
    1301 
    1302   myTrackerModel = new TrackerModel;
    1303   myTrackerFilter = new TrackerModelFilter;
     1176void
     1177Details::initTrackerTab ()
     1178{
     1179  myTrackerModel = new TrackerModel ();
     1180  myTrackerFilter = new TrackerModelFilter ();
    13041181  myTrackerFilter->setSourceModel (myTrackerModel);
    1305   myTrackerView = new QTreeView;
    1306   myTrackerView->setModel (myTrackerFilter);
    1307   myTrackerView->setHeaderHidden (true);
    1308   myTrackerView->setSelectionMode (QTreeWidget::ExtendedSelection);
    1309   myTrackerView->setRootIsDecorated (false);
    1310   myTrackerView->setIndentation (2);
    1311   myTrackerView->setItemsExpandable (false);
    1312   myTrackerView->setAlternatingRowColors (true);
    1313   myTrackerView->setItemDelegate (myTrackerDelegate = new TrackerDelegate ());
    1314   connect (myTrackerView->selectionModel (), SIGNAL (selectionChanged (QItemSelection, QItemSelection)), this, SLOT (onTrackerSelectionChanged ()));
    1315   h->addWidget (myTrackerView, 1);
    1316 
    1317   p = new QPushButton ();
    1318   p->setIcon (getStockIcon ("list-add", QStyle::SP_DialogOpenButton));
    1319   p->setToolTip (tr ("Add Tracker"));
    1320   myAddTrackerButton = p;
    1321   v2->addWidget (p, 1);
    1322   connect (p, SIGNAL (clicked (bool)), this, SLOT (onAddTrackerClicked ()));
    1323 
    1324   p = new QPushButton ();
    1325   p->setIcon (getStockIcon ("document-properties", QStyle::SP_DesktopIcon));
    1326   p->setToolTip (tr ("Edit Tracker"));
    1327   myAddTrackerButton = p;
    1328   p->setEnabled (false);
    1329   myEditTrackerButton = p;
    1330   v2->addWidget (p, 1);
    1331   connect (p, SIGNAL (clicked (bool)), this, SLOT (onEditTrackerClicked ()));
    1332 
    1333   p = new QPushButton ();
    1334   p->setIcon (getStockIcon ("list-remove", QStyle::SP_TrashIcon));
    1335   p->setToolTip (tr ("Remove Trackers"));
    1336   p->setEnabled (false);
    1337   myRemoveTrackerButton = p;
    1338   v2->addWidget (p, 1);
    1339   connect (p, SIGNAL (clicked (bool)), this, SLOT (onRemoveTrackerClicked ()));
    1340 
    1341   v2->addStretch (1);
    1342 
    1343   h->addLayout (v2, 1);
    1344   h->setStretch (1, 0);
    1345 
    1346   v->addLayout (h, 1);
    1347 
    1348   c = new QCheckBox (tr ("Show &more details"));
    1349   c->setChecked (myPrefs.getBool (Prefs::SHOW_TRACKER_SCRAPES));
    1350   myShowTrackerScrapesCheck = c;
    1351   v->addWidget (c, 1);
    1352   connect (c, SIGNAL (clicked (bool)), this, SLOT (onShowTrackerScrapesToggled (bool)));
    1353 
    1354   c = new QCheckBox (tr ("Show &backup trackers"));
    1355   c->setChecked (myPrefs.getBool (Prefs::SHOW_BACKUP_TRACKERS));
    1356   myShowBackupTrackersCheck = c;
    1357   v->addWidget (c, 1);
    1358   connect (c, SIGNAL (clicked (bool)), this, SLOT (onShowBackupTrackersToggled (bool)));
    1359 
    1360   return top;
     1182  myTrackerDelegate = new TrackerDelegate ();
     1183
     1184  ui.trackersView->setModel (myTrackerFilter);
     1185  ui.trackersView->setItemDelegate (myTrackerDelegate);
     1186
     1187  ui.addTrackerButton->setIcon (getStockIcon ("list-add", QStyle::SP_DialogOpenButton));
     1188  ui.editTrackerButton->setIcon (getStockIcon ("document-properties", QStyle::SP_DesktopIcon));
     1189  ui.removeTrackerButton->setIcon (getStockIcon ("list-remove", QStyle::SP_TrashIcon));
     1190
     1191  ui.showTrackerScrapesCheck->setChecked (myPrefs.getBool (Prefs::SHOW_TRACKER_SCRAPES));
     1192  ui.showBackupTrackersCheck->setChecked (myPrefs.getBool (Prefs::SHOW_BACKUP_TRACKERS));
     1193
     1194  connect (ui.trackersView->selectionModel (), SIGNAL (selectionChanged (QItemSelection, QItemSelection)),
     1195    SLOT (onTrackerSelectionChanged ()));
     1196  connect (ui.addTrackerButton, SIGNAL (clicked ()), SLOT (onAddTrackerClicked ()));
     1197  connect (ui.editTrackerButton, SIGNAL (clicked ()), SLOT (onEditTrackerClicked ()));
     1198  connect (ui.removeTrackerButton, SIGNAL (clicked ()), SLOT (onRemoveTrackerClicked ()));
     1199  connect (ui.showTrackerScrapesCheck, SIGNAL (clicked (bool)), SLOT (onShowTrackerScrapesToggled (bool)));
     1200  connect (ui.showBackupTrackersCheck, SIGNAL (clicked (bool)), SLOT (onShowBackupTrackersToggled (bool)));
     1201
     1202  onTrackerSelectionChanged ();
    13611203}
    13621204
     
    13651207***/
    13661208
    1367 QWidget *
    1368 Details::createPeersTab ()
    1369 {
    1370   QWidget * top = new QWidget;
    1371   QVBoxLayout * v = new QVBoxLayout (top);
    1372   v->setSpacing (HIG::PAD_BIG);
    1373   v->setContentsMargins (HIG::PAD_BIG, HIG::PAD_BIG, HIG::PAD_BIG, HIG::PAD_BIG);
    1374 
     1209void
     1210Details::initPeersTab ()
     1211{
    13751212  QStringList headers;
    13761213  headers << QString () << tr ("Up") << tr ("Down") << tr ("%") << tr ("Status") << tr ("Address") << tr ("Client");
    1377   myPeerTree = new QTreeWidget;
    1378   myPeerTree->setUniformRowHeights (true);
    1379   myPeerTree->setHeaderLabels (headers);
    1380   myPeerTree->setColumnWidth (0, 20);
    1381   myPeerTree->setSortingEnabled (true);
    1382   myPeerTree->sortByColumn (COL_ADDRESS, Qt::AscendingOrder);
    1383   myPeerTree->setRootIsDecorated (false);
    1384   myPeerTree->setTextElideMode (Qt::ElideRight);
    1385   v->addWidget (myPeerTree, 1);
    1386 
    1387   const QFontMetrics m (font ());
    1388   QSize size = m.size (0, "1024 MiB/s");
    1389   myPeerTree->setColumnWidth (COL_UP, size.width ());
    1390   myPeerTree->setColumnWidth (COL_DOWN, size.width ());
    1391   size = m.size (0, " 100% ");
    1392   myPeerTree->setColumnWidth (COL_PERCENT, size.width ());
    1393   size = m.size (0, "ODUK?EXI");
    1394   myPeerTree->setColumnWidth (COL_STATUS, size.width ());
    1395   size = m.size (0, "888.888.888.888");
    1396   myPeerTree->setColumnWidth (COL_ADDRESS, size.width ());
    1397   size = m.size (0, "Some BitTorrent Client");
    1398   myPeerTree->setColumnWidth (COL_CLIENT, size.width ());
    1399   myPeerTree->setAlternatingRowColors (true);
    1400 
    1401   return top;
     1214
     1215  ui.peersView->setHeaderLabels (headers);
     1216  ui.peersView->sortByColumn (COL_ADDRESS, Qt::AscendingOrder);
     1217
     1218  ui.peersView->setColumnWidth (COL_LOCK, 20);
     1219  ui.peersView->setColumnWidth (COL_UP, measureViewItem (ui.peersView, "1024 MiB/s"));
     1220  ui.peersView->setColumnWidth (COL_DOWN, measureViewItem (ui.peersView, "1024 MiB/s"));
     1221  ui.peersView->setColumnWidth (COL_PERCENT, measureViewItem (ui.peersView, "100%"));
     1222  ui.peersView->setColumnWidth (COL_STATUS, measureViewItem (ui.peersView, "ODUK?EXI"));
     1223  ui.peersView->setColumnWidth (COL_ADDRESS, measureViewItem (ui.peersView, "888.888.888.888"));
    14021224}
    14031225
     
    14061228***/
    14071229
    1408 QWidget *
    1409 Details::createFilesTab ()
    1410 {
    1411   myFileTreeView = new FileTreeView ();
    1412 
    1413   connect (myFileTreeView, SIGNAL (     priorityChanged (QSet<int>, int)),
    1414            this,           SLOT ( onFilePriorityChanged (QSet<int>, int)));
    1415 
    1416   connect (myFileTreeView, SIGNAL (     wantedChanged (QSet<int>, bool)),
    1417            this,           SLOT ( onFileWantedChanged (QSet<int>, bool)));
    1418 
    1419   connect (myFileTreeView, SIGNAL (pathEdited (QString, QString)),
    1420            this,           SLOT (onPathEdited (QString, QString)));
    1421 
    1422   connect (myFileTreeView, SIGNAL (openRequested (QString)),
    1423            this,           SLOT (onOpenRequested (QString)));
    1424 
    1425   return myFileTreeView;
     1230void
     1231Details::initFilesTab ()
     1232{
     1233  connect (ui.filesView, SIGNAL (priorityChanged (QSet<int>, int)), SLOT (onFilePriorityChanged (QSet<int>, int)));
     1234  connect (ui.filesView, SIGNAL (wantedChanged (QSet<int>, bool)), SLOT (onFileWantedChanged (QSet<int>, bool)));
     1235  connect (ui.filesView, SIGNAL (pathEdited (QString, QString)), SLOT (onPathEdited (QString, QString)));
     1236  connect (ui.filesView, SIGNAL (openRequested (QString)), SLOT (onOpenRequested (QString)));
    14261237}
    14271238
  • trunk/qt/details.h

    r14241 r14387  
    1616#include <QSet>
    1717#include <QTimer>
    18 #include <QWidgetList>
    1918
    2019#include "prefs.h"
    2120
    22 class FileTreeView;
    23 class QTreeView;
    24 class QComboBox;
    25 class QCheckBox;
    26 class QDoubleSpinBox;
    27 class QLabel;
    28 class QRadioButton;
    29 class QSpinBox;
    30 class QTextBrowser;
    31 class QTreeWidget;
     21#include "ui_details.h"
     22
    3223class QTreeWidgetItem;
    3324class Session;
     
    5647
    5748  private:
    58     QWidget * createPeersTab ();
    59     QWidget * createTrackerTab ();
    60     QWidget * createInfoTab ();
    61     QWidget * createFilesTab ();
    62     QWidget * createOptionsTab ();
     49    void initPeersTab ();
     50    void initTrackerTab ();
     51    void initInfoTab ();
     52    void initFilesTab ();
     53    void initOptionsTab ();
    6354
    6455  private:
     
    6657    QString timeToStringRounded (int seconds);
    6758    QString trimToDesiredWidth (const QString& str);
    68     void enableWhenChecked (QCheckBox *, QWidget *);
    6959
    7060  private:
     
    7767    bool myHavePendingRefresh;
    7868
    79     QLabel * myStateLabel;
    80     QLabel * myHaveLabel;
    81     QLabel * myAvailabilityLabel;
    82     QLabel * myDownloadedLabel;
    83     QLabel * myUploadedLabel;
    84     QLabel * myErrorLabel;
    85     QLabel * myRunTimeLabel;
    86     QLabel * myETALabel;
    87     QLabel * myLastActivityLabel;
    88 
    89     QCheckBox * mySessionLimitCheck;
    90     QCheckBox * mySingleDownCheck;
    91     QCheckBox * mySingleUpCheck;
    92     QCheckBox * myShowTrackerScrapesCheck;
    93     QCheckBox * myShowBackupTrackersCheck;
    94     QPushButton * myAddTrackerButton;
    95     QPushButton * myEditTrackerButton;
    96     QPushButton * myRemoveTrackerButton;
    97     QSpinBox * mySingleDownSpin;
    98     QSpinBox * mySingleUpSpin;
    99     QComboBox * myRatioCombo;
    100     QDoubleSpinBox * myRatioSpin;
    101     QComboBox * myIdleCombo;
    102     QSpinBox * myIdleSpin;
    103     QSpinBox * myPeerLimitSpin;
    104     QComboBox * myBandwidthPriorityCombo;
    105 
    106     QLabel * mySizeLabel;
    107     QLabel * myHashLabel;
    108     QLabel * myPrivacyLabel;
    109     QLabel * myOriginLabel;
    110     QLabel * myLocationLabel;
    111     QTextBrowser * myCommentBrowser;
    112 
    113     QLabel * myTrackerLabel;
    114     QLabel * myScrapeTimePrevLabel;
    115     QLabel * myScrapeTimeNextLabel;
    116     QLabel * myScrapeResponseLabel;
    117     QLabel * myAnnounceTimePrevLabel;
    118     QLabel * myAnnounceTimeNextLabel;
    119     QLabel * myAnnounceResponseLabel;
    120     QLabel * myAnnounceManualLabel;
     69    Ui::DetailsDialog ui;
    12170
    12271    TrackerModel * myTrackerModel;
    12372    TrackerModelFilter * myTrackerFilter;
    12473    TrackerDelegate * myTrackerDelegate;
    125     QTreeView * myTrackerView;
    126     //QMap<QString,QTreeWidgetItem*> myTrackerTiers;
    127     //QMap<QString,QTreeWidgetItem*> myTrackerItems;
    12874
    129     QTreeWidget * myPeerTree;
    13075    QMap<QString,QTreeWidgetItem*> myPeers;
    131 
    132     QWidgetList myWidgets;
    133 
    134     FileTreeView * myFileTreeView;
    13576
    13677  private slots:
  • trunk/qt/qtr.pro

    r14346 r14387  
    4747                translations/transmission_uk.ts
    4848
    49 FORMS += mainwin.ui
     49FORMS += details.ui \
     50         mainwin.ui
    5051RESOURCES += application.qrc
    5152SOURCES += about.cc \
  • trunk/qt/squeezelabel.cc

    r14377 r14387  
    4141
    4242#include <QPainter>
    43 #include <QResizeEvent>
    4443#include <QStyle>
    4544#include <QStyleOption>
     
    4746#include "squeezelabel.h"
    4847
    49 void
    50 SqueezeLabel::init ()
    51 {
    52   setTextInteractionFlags(Qt::TextSelectableByMouse);
    53 }
    54 
    5548SqueezeLabel::SqueezeLabel (const QString& text, QWidget * parent):
    5649  QLabel (text, parent)
    5750{
    58   init();
    5951}
    6052
     
    6254  QLabel (parent)
    6355{
    64   init();
    6556}
    6657
     
    6859SqueezeLabel::paintEvent (QPaintEvent * paintEvent)
    6960{
    70   Q_UNUSED (paintEvent);
     61  if (hasFocus () && (textInteractionFlags () & (Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse)))
     62    return QLabel::paintEvent (paintEvent);
    7163
    7264  QPainter painter (this);
     
    7466  QStyleOption opt;
    7567  opt.initFrom (this);
    76   const QString elidedText = fm.elidedText (text(), Qt::ElideMiddle, width());
     68  const QString fullText = text ();
     69  const QString elidedText = fm.elidedText (fullText, Qt::ElideRight, width());
    7770  style()->drawItemText (&painter,
    7871                         contentsRect(),
     
    8275                         elidedText,
    8376                         foregroundRole());
     77
     78#ifndef QT_NO_TOOLTIP
     79  setToolTip (fullText != elidedText ? fullText : QString ());
     80#endif
    8481}
  • trunk/qt/squeezelabel.h

    r14204 r14387  
    5454
    5555  protected:
    56     void init ();
    5756    void paintEvent (QPaintEvent* paintEvent);
    5857};
Note: See TracChangeset for help on using the changeset viewer.