diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index 3bc789c5d..624589242 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -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 diff --git a/qt/FilterBar.cc b/qt/FilterBar.cc index bfcee7924..251390cc5 100644 --- a/qt/FilterBar.cc +++ b/qt/FilterBar.cc @@ -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)); -} diff --git a/qt/FilterBar.h b/qt/FilterBar.h index 025d188c4..4dffe72fd 100644 --- a/qt/FilterBar.h +++ b/qt/FilterBar.h @@ -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&); diff --git a/qt/MainWindow.cc b/qt/MainWindow.cc index 6d0be0ffb..5732c3a94 100644 --- a/qt/MainWindow.cc +++ b/qt/MainWindow.cc @@ -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 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 () diff --git a/qt/MainWindow.h b/qt/MainWindow.h index 4dcb620c4..eada6bf6e 100644 --- a/qt/MainWindow.h +++ b/qt/MainWindow.h @@ -110,6 +110,7 @@ class MainWindow: public QMainWindow void refreshStatusBar (); void refreshTrayIcon (); void refreshTrayIconSoon (); + void refreshTorrentViewHeader (); void openTorrent (); void openURL (); void newTorrent (); diff --git a/qt/MainWindow.ui b/qt/MainWindow.ui index 94fde720f..bd4426780 100644 --- a/qt/MainWindow.ui +++ b/qt/MainWindow.ui @@ -25,7 +25,7 @@ 0 - + 0 @@ -779,6 +779,11 @@ QToolButton
IconToolButton.h
+ + TorrentView + QListView +
TorrentView.h
+
diff --git a/qt/TorrentView.cc b/qt/TorrentView.cc new file mode 100644 index 000000000..be1b186bc --- /dev/null +++ b/qt/TorrentView.cc @@ -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 +#include +#include + +#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 index 000000000..cda3eb0d9 --- /dev/null +++ b/qt/TorrentView.h @@ -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 + +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 diff --git a/qt/qtr.pro b/qt/qtr.pro index 686872589..384c7a1b8 100644 --- a/qt/qtr.pro +++ b/qt/qtr.pro @@ -105,6 +105,7 @@ SOURCES += AboutDialog.cc \ TorrentDelegateMin.cc \ TorrentFilter.cc \ TorrentModel.cc \ + TorrentView.cc \ TrackerDelegate.cc \ TrackerModel.cc \ TrackerModelFilter.cc \ diff --git a/qt/translations/transmission_en.ts b/qt/translations/transmission_en.ts index c38bf5ccb..847e23bf8 100644 --- a/qt/translations/transmission_en.ts +++ b/qt/translations/transmission_en.ts @@ -43,7 +43,7 @@ Application - + <b>Transmission is a file sharing program.</b> @@ -571,29 +571,29 @@ FileTreeItem - - - + + + Low - - + + High - - + + Normal - + Mixed @@ -629,18 +629,18 @@ FileTreeView - - Check selected + + Check Selected - Uncheck selected + Uncheck Selected - Only check selected + Only Check Selected @@ -692,16 +692,8 @@ Finished - - - Show %Ln of: - - - - - - + Verifying @@ -711,7 +703,7 @@ - + Show: @@ -935,7 +927,6 @@ - Queue @@ -1257,7 +1248,7 @@ - + Limit Download Speed @@ -1268,13 +1259,13 @@ - + Limited at %1 - + Limit Upload Speed @@ -1290,12 +1281,12 @@ - + Stop at Ratio (%1) - + - %1:%2 Second (optional) part of main window title "Transmission - host:port" (added when connected to remote session); notice that leading space (before the dash) is included here @@ -1318,7 +1309,7 @@ - + Torrent Files (*.torrent);;All Files (*.*) @@ -1333,17 +1324,17 @@ - + Speed Limits - + Network Error - + Click to disable Temporary Speed Limits (%1 down, %2 up) @@ -1373,7 +1364,15 @@ - + + Showing %L1 of %Ln torrent(s) + + Showing %L1 of %Ln torrent + Showing %L1 of %Ln torrents + + + + Delete these %Ln torrent(s)' downloaded files? Delete this %Ln torrent's downloaded files?