]> granicus.if.org Git - transmission/commitdiff
Show notice on top of filtered torrents list
authorMike Gelfand <mikedld@mikedld.com>
Mon, 19 Oct 2015 20:30:26 +0000 (20:30 +0000)
committerMike Gelfand <mikedld@mikedld.com>
Mon, 19 Oct 2015 20:30:26 +0000 (20:30 +0000)
This has a couple of benefits: 1) it is clearly visible to the user that
the list is filtered (doesn't display all the torrents) even when filter
bar is hidden, 2) doesn't lead to filter bar controls being shifted to
the left/right as when "Show:" label text changes.

qt/CMakeLists.txt
qt/FilterBar.cc
qt/FilterBar.h
qt/MainWindow.cc
qt/MainWindow.h
qt/MainWindow.ui
qt/TorrentView.cc [new file with mode: 0644]
qt/TorrentView.h [new file with mode: 0644]
qt/qtr.pro
qt/translations/transmission_en.ts

index 3bc789c5d0433f31d22092e2783cceb02dbb6513..624589242185a3410573d71db4aef2e08770dd94 100644 (file)
@@ -62,6 +62,7 @@ set(${PROJECT_NAME}_SOURCES
     TorrentDelegateMin.cc
     TorrentFilter.cc
     TorrentModel.cc
+    TorrentView.cc
     TrackerDelegate.cc
     TrackerModel.cc
     TrackerModelFilter.cc
@@ -110,6 +111,7 @@ set(${PROJECT_NAME}_HEADERS
     TorrentDelegateMin.h
     TorrentFilter.h
     TorrentModel.h
+    TorrentView.h
     TrackerDelegate.h
     TrackerModel.h
     TrackerModelFilter.h
index bfcee7924652bb3f7c4450e5bb32e0a53cdd5e16..251390cc5e83ab00472185ffd116040bfb6340da 100644 (file)
@@ -230,7 +230,7 @@ FilterBar::FilterBar (Prefs& prefs, const TorrentModel& torrents, const TorrentF
   QHBoxLayout * h = new QHBoxLayout (this);
   h->setContentsMargins (3, 3, 3, 3);
 
-  myCountLabel = new QLabel (this);
+  myCountLabel = new QLabel (tr ("Show:"), this);
   h->addWidget (myCountLabel);
 
   myActivityCombo = createActivityCombo ();
@@ -249,8 +249,6 @@ FilterBar::FilterBar (Prefs& prefs, const TorrentModel& torrents, const TorrentF
   connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (refreshPref (int)));
   connect (myActivityCombo, SIGNAL (currentIndexChanged (int)), this, SLOT (onActivityIndexChanged (int)));
   connect (myTrackerCombo, SIGNAL (currentIndexChanged (int)), this, SLOT (onTrackerIndexChanged (int)));
-  connect (&myFilter, SIGNAL (rowsInserted (QModelIndex, int, int)), this, SLOT (refreshCountLabel ()));
-  connect (&myFilter, SIGNAL (rowsRemoved (QModelIndex, int, int)), this, SLOT (refreshCountLabel ()));
   connect (&myTorrents, SIGNAL (modelReset ()), this, SLOT (recountSoon ()));
   connect (&myTorrents, SIGNAL (rowsInserted (QModelIndex, int, int)), this, SLOT (recountSoon ()));
   connect (&myTorrents, SIGNAL (rowsRemoved (QModelIndex, int, int)), this, SLOT (recountSoon ()));
@@ -259,7 +257,6 @@ FilterBar::FilterBar (Prefs& prefs, const TorrentModel& torrents, const TorrentF
 
   recountSoon ();
   refreshTrackers ();
-  refreshCountLabel ();
   myIsBootstrapping = false;
 
   // initialize our state
@@ -383,7 +380,6 @@ FilterBar::recount ()
     }
 
   refreshTrackers ();
-  refreshCountLabel ();
 }
 
 QString
@@ -391,16 +387,3 @@ FilterBar::getCountString (int n) const
 {
   return QString::fromLatin1 ("%L1").arg (n);
 }
-
-void
-FilterBar::refreshCountLabel ()
-{
-  const int visibleCount = myFilter.rowCount ();
-  const int trackerCount = myTrackerCombo->currentCount ();
-  const int activityCount = myActivityCombo->currentCount ();
-
-  if ((visibleCount == activityCount) || (visibleCount == trackerCount))
-    myCountLabel->setText (tr("Show:"));
-  else
-    myCountLabel->setText (tr("Show %Ln of:", 0, visibleCount));
-}
index 025d188c4461793697b1bf5b4df3a48dfaa2da15..4dffe72fdc0d08f36505d70ef6aad9c09576bd64 100644 (file)
@@ -40,7 +40,6 @@ class FilterBar: public QWidget
     void recountSoon ();
     void recount ();
     void refreshPref (int key);
-    void refreshCountLabel ();
     void onActivityIndexChanged (int index);
     void onTrackerIndexChanged (int index);
     void onTextChanged (const QString&);
index 6d0be0ffbc026eb5dffc9b2c14eb5b239193f49f..5732c3a94282bb4893934da674199752f8973e93 100644 (file)
@@ -254,6 +254,11 @@ MainWindow::MainWindow (Session& session, Prefs& prefs, TorrentModel& model, boo
   initStatusBar ();
   ui.verticalLayout->insertWidget (0, myFilterBar = new FilterBar (myPrefs, myModel, myFilterModel));
 
+  connect (&myModel, SIGNAL (rowsInserted (QModelIndex, int, int)), SLOT (refreshTorrentViewHeader ()));
+  connect (&myModel, SIGNAL (rowsRemoved (QModelIndex, int, int)), SLOT (refreshTorrentViewHeader ()));
+  connect (&myFilterModel, SIGNAL (rowsInserted (QModelIndex, int, int)), SLOT (refreshTorrentViewHeader ()));
+  connect (&myFilterModel, SIGNAL (rowsRemoved (QModelIndex, int, int)), SLOT (refreshTorrentViewHeader ()));
+
   QList<int> initKeys;
   initKeys << Prefs::MAIN_WINDOW_X
            << Prefs::SHOW_TRAY_ICON
@@ -300,6 +305,7 @@ MainWindow::MainWindow (Session& session, Prefs& prefs, TorrentModel& model, boo
   refreshTrayIconSoon ();
   refreshStatusBar ();
   refreshTitle ();
+  refreshTorrentViewHeader ();
 }
 
 MainWindow::~MainWindow ()
@@ -726,7 +732,17 @@ MainWindow::refreshStatusBar ()
   ui.statsLabel->setText (str);
 }
 
+void
+MainWindow::refreshTorrentViewHeader ()
+{
+  const int totalCount = myModel.rowCount ();
+  const int visibleCount = myFilterModel.rowCount ();
 
+  if (visibleCount == totalCount)
+    ui.listView->setHeaderText (QString ());
+  else
+    ui.listView->setHeaderText (tr ("Showing %L1 of %Ln torrent(s)", 0, totalCount).arg (visibleCount));
+}
 
 void
 MainWindow::refreshActionSensitivitySoon ()
index 4dcb620c47fc47d1bdc33415500617defcb51eee..eada6bf6edd9e7a4fcc608c63d9f8d70ade35717 100644 (file)
@@ -110,6 +110,7 @@ class MainWindow: public QMainWindow
     void refreshStatusBar ();
     void refreshTrayIcon ();
     void refreshTrayIconSoon ();
+    void refreshTorrentViewHeader ();
     void openTorrent ();
     void openURL ();
     void newTorrent ();
index 94fde720f4f514cd72d14ba8fe8d6ab69b63d452..bd4426780f0bdac18301dd3779d84b7fbc901621 100644 (file)
@@ -25,7 +25,7 @@
      <number>0</number>
     </property>
     <item>
-     <widget class="QListView" name="listView">
+     <widget class="TorrentView" name="listView">
       <property name="sizePolicy">
        <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
         <horstretch>0</horstretch>
    <extends>QToolButton</extends>
    <header>IconToolButton.h</header>
   </customwidget>
+  <customwidget>
+   <class>TorrentView</class>
+   <extends>QListView</extends>
+   <header>TorrentView.h</header>
+  </customwidget>
  </customwidgets>
  <resources>
   <include location="application.qrc"/>
diff --git a/qt/TorrentView.cc b/qt/TorrentView.cc
new file mode 100644 (file)
index 0000000..be1b186
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * This file Copyright (C) 2015 Mnemosyne LLC
+ *
+ * It may be used under the GNU GPL versions 2 or 3
+ * or any future license endorsed by Mnemosyne LLC.
+ *
+ * $Id$
+ */
+
+#include <QApplication>
+#include <QStyleOptionHeader>
+#include <QStylePainter>
+
+#include "TorrentView.h"
+
+class TorrentView::HeaderWidget: public QWidget
+{
+  public:
+    HeaderWidget (QWidget * parent):
+      QWidget (parent),
+      myText ()
+    {
+      setFont (qApp->font ("QMiniFont"));
+    }
+
+    void setText (const QString& text)
+    {
+      myText = text;
+      update ();
+    }
+
+    // QWidget
+    virtual QSize sizeHint () const
+    {
+      QStyleOptionHeader option;
+      option.rect = QRect (0, 0, 100, 100);
+
+      const QRect labelRect = style ()->subElementRect (QStyle::SE_HeaderLabel, &option, this);
+
+      return QSize (100, fontMetrics ().height () + (option.rect.height () - labelRect.height ()));
+    }
+
+  protected:
+    // QWidget
+    virtual void paintEvent (QPaintEvent * /*event*/)
+    {
+      QStyleOptionHeader option;
+      option.initFrom (this);
+      option.state = QStyle::State_Enabled;
+      option.position = QStyleOptionHeader::OnlyOneSection;
+
+      QStylePainter painter (this);
+      painter.drawControl (QStyle::CE_HeaderSection, option);
+
+      option.rect = style ()->subElementRect (QStyle::SE_HeaderLabel, &option, this);
+      painter.drawItemText (option.rect, Qt::AlignCenter, option.palette, true, myText, QPalette::ButtonText);
+    }
+
+  private:
+    QString myText;
+};
+
+TorrentView::TorrentView (QWidget * parent):
+  QListView (parent),
+  myHeaderWidget (new HeaderWidget (this))
+{
+}
+
+void
+TorrentView::setHeaderText (const QString& text)
+{
+  const bool headerVisible = !text.isEmpty ();
+
+  myHeaderWidget->setText (text);
+  myHeaderWidget->setVisible (headerVisible);
+
+  if (headerVisible)
+    adjustHeaderPosition ();
+
+  setViewportMargins (0, headerVisible ? myHeaderWidget->height () : 0, 0, 0);
+}
+
+void
+TorrentView::resizeEvent (QResizeEvent * event)
+{
+  QListView::resizeEvent (event);
+
+  if (myHeaderWidget->isVisible ())
+    adjustHeaderPosition ();
+}
+
+void
+TorrentView::adjustHeaderPosition ()
+{
+  QRect headerWidgetRect = contentsRect ();
+  headerWidgetRect.setWidth (viewport ()->width ());
+  headerWidgetRect.setHeight (myHeaderWidget->sizeHint ().height ());
+  myHeaderWidget->setGeometry (headerWidgetRect);
+}
diff --git a/qt/TorrentView.h b/qt/TorrentView.h
new file mode 100644 (file)
index 0000000..cda3eb0
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * This file Copyright (C) 2015 Mnemosyne LLC
+ *
+ * It may be used under the GNU GPL versions 2 or 3
+ * or any future license endorsed by Mnemosyne LLC.
+ *
+ * $Id$
+ */
+
+#ifndef QTR_TORRENT_VIEW_H
+#define QTR_TORRENT_VIEW_H
+
+#include <QListView>
+
+class TorrentView: public QListView
+{
+    Q_OBJECT
+
+  public:
+    TorrentView (QWidget * parent = nullptr);
+
+  public slots:
+    void setHeaderText (const QString& text);
+
+  protected:
+    virtual void resizeEvent (QResizeEvent * event);
+
+  private:
+    class HeaderWidget;
+
+  private:
+    void adjustHeaderPosition ();
+
+  private:
+    HeaderWidget * const myHeaderWidget;
+};
+
+#endif // QTR_TORRENT_VIEW_H
index 6868725890645421cf4258a4a3f47e74ea6e276c..384c7a1b87d4b960c3e9f36e5d71f53c49088069 100644 (file)
@@ -105,6 +105,7 @@ SOURCES += AboutDialog.cc \
            TorrentDelegateMin.cc \
            TorrentFilter.cc \
            TorrentModel.cc \
+           TorrentView.cc \
            TrackerDelegate.cc \
            TrackerModel.cc \
            TrackerModelFilter.cc \
index c38bf5ccbd9aa75343e9fd7ff2cc2f532ae124b0..847e23bf8f2611c48f900ac3da33097f2f609dd5 100644 (file)
@@ -43,7 +43,7 @@
 <context>
     <name>Application</name>
     <message>
-        <location filename="../Application.cc" line="+300"/>
+        <location filename="../Application.cc" line="+304"/>
         <source>&lt;b&gt;Transmission is a file sharing program.&lt;/b&gt;</source>
         <translation type="unfinished"></translation>
     </message>
 <context>
     <name>FileTreeItem</name>
     <message>
-        <location filename="../FileTreeItem.cc" line="+256"/>
-        <location filename="../FileTreeView.cc" line="+110"/>
-        <location line="+263"/>
+        <location filename="../FileTreeItem.cc" line="+271"/>
+        <location filename="../FileTreeView.cc" line="+105"/>
+        <location line="+257"/>
         <source>Low</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
         <location line="+1"/>
-        <location filename="../FileTreeView.cc" line="-262"/>
-        <location line="+260"/>
+        <location filename="../FileTreeView.cc" line="-256"/>
+        <location line="+254"/>
         <source>High</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
         <location line="+1"/>
-        <location filename="../FileTreeView.cc" line="-261"/>
-        <location line="+262"/>
+        <location filename="../FileTreeView.cc" line="-255"/>
+        <location line="+256"/>
         <source>Normal</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
         <location line="+1"/>
-        <location filename="../FileTreeView.cc" line="-261"/>
+        <location filename="../FileTreeView.cc" line="-255"/>
         <source>Mixed</source>
         <translation type="unfinished"></translation>
     </message>
 <context>
     <name>FileTreeView</name>
     <message>
-        <location filename="../FileTreeView.cc" line="+253"/>
-        <source>Check selected</source>
+        <location filename="../FileTreeView.cc" line="+247"/>
+        <source>Check Selected</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
         <location line="+1"/>
-        <source>Uncheck selected</source>
+        <source>Uncheck Selected</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
         <location line="+1"/>
-        <source>Only check selected</source>
+        <source>Only Check Selected</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
         <source>Finished</source>
         <translation type="unfinished"></translation>
     </message>
-    <message numerus="yes">
-        <location line="+326"/>
-        <source>Show %Ln of:</source>
-        <translation type="unfinished">
-            <numerusform></numerusform>
-            <numerusform></numerusform>
-        </translation>
-    </message>
     <message>
-        <location line="-322"/>
+        <location line="+4"/>
         <source>Verifying</source>
         <translation type="unfinished"></translation>
     </message>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location line="+316"/>
+        <location line="+141"/>
         <source>Show:</source>
         <translation type="unfinished"></translation>
     </message>
     </message>
     <message>
         <location line="-161"/>
-        <location filename="../MainWindow.cc" line="+1442"/>
         <source>Queue</source>
         <translation type="unfinished"></translation>
     </message>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../MainWindow.cc" line="-1015"/>
+        <location filename="../MainWindow.cc" line="+433"/>
         <source>Limit Download Speed</source>
         <translation type="unfinished"></translation>
     </message>
     </message>
     <message>
         <location line="+6"/>
-        <location line="+615"/>
+        <location line="+641"/>
         <location line="+8"/>
         <source>Limited at %1</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location line="-573"/>
+        <location line="-599"/>
         <source>Limit Upload Speed</source>
         <translation type="unfinished"></translation>
     </message>
     </message>
     <message>
         <location line="+6"/>
-        <location line="+601"/>
+        <location line="+627"/>
         <source>Stop at Ratio (%1)</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location line="-378"/>
+        <location line="-393"/>
         <source> - %1:%2</source>
         <extracomment>Second (optional) part of main window title &quot;Transmission - host:port&quot; (added when connected to remote session); notice that leading space (before the dash) is included here</extracomment>
         <translation type="unfinished"></translation>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location line="+406"/>
+        <location line="+421"/>
         <source>Torrent Files (*.torrent);;All Files (*.*)</source>
         <translation type="unfinished"></translation>
     </message>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location line="-885"/>
+        <location line="-917"/>
         <source>Speed Limits</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location line="+431"/>
+        <location line="+448"/>
         <source>Network Error</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location line="+418"/>
+        <location line="+433"/>
         <source>Click to disable Temporary Speed Limits
  (%1 down, %2 up)</source>
         <translation type="unfinished"></translation>
         </translation>
     </message>
     <message numerus="yes">
-        <location line="+6"/>
+        <location line="-499"/>
+        <source>Showing %L1 of %Ln torrent(s)</source>
+        <translation type="unfinished">
+            <numerusform>Showing %L1 of %Ln torrent</numerusform>
+            <numerusform>Showing %L1 of %Ln torrents</numerusform>
+        </translation>
+    </message>
+    <message numerus="yes">
+        <location line="+505"/>
         <source>Delete these %Ln torrent(s)&apos; downloaded files?</source>
         <translation>
             <numerusform>Delete this %Ln torrent&apos;s downloaded files?</numerusform>