2010-07-30 22:31:31 +00:00
|
|
|
/*
|
2014-01-18 20:56:57 +00:00
|
|
|
* This file Copyright (C) 2010-2014 Mnemosyne LLC
|
2010-07-30 22:31:31 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2010-07-30 22:31:31 +00:00
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QTR_FILTERBAR_H
|
|
|
|
#define QTR_FILTERBAR_H
|
|
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QItemDelegate>
|
2014-12-21 15:34:52 +00:00
|
|
|
#include <QLineEdit>
|
2010-07-30 22:31:31 +00:00
|
|
|
#include <QWidget>
|
|
|
|
|
2013-02-01 20:58:55 +00:00
|
|
|
class QLabel;
|
2010-07-30 22:31:31 +00:00
|
|
|
class QLineEdit;
|
|
|
|
class QPaintEvent;
|
|
|
|
class QStandardItemModel;
|
|
|
|
class QTimer;
|
2014-12-28 00:20:43 +00:00
|
|
|
class QToolButton;
|
2010-07-30 22:31:31 +00:00
|
|
|
|
|
|
|
class Prefs;
|
|
|
|
class TorrentFilter;
|
|
|
|
class TorrentModel;
|
|
|
|
|
|
|
|
class FilterBarComboBoxDelegate: public QItemDelegate
|
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
Q_OBJECT
|
2010-07-30 22:31:31 +00:00
|
|
|
|
2013-01-26 01:19:54 +00:00
|
|
|
public:
|
|
|
|
FilterBarComboBoxDelegate (QObject * parent, QComboBox * combo);
|
2010-07-30 22:31:31 +00:00
|
|
|
|
2013-01-26 01:19:54 +00:00
|
|
|
public:
|
|
|
|
static bool isSeparator (const QModelIndex &index);
|
|
|
|
static void setSeparator (QAbstractItemModel * model, const QModelIndex& index);
|
2010-07-30 22:31:31 +00:00
|
|
|
|
2013-01-26 01:19:54 +00:00
|
|
|
protected:
|
|
|
|
virtual void paint (QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const;
|
|
|
|
virtual QSize sizeHint (const QStyleOptionViewItem&, const QModelIndex&) const;
|
2010-07-30 22:31:31 +00:00
|
|
|
|
2013-01-26 01:19:54 +00:00
|
|
|
private:
|
|
|
|
QComboBox * myCombo;
|
2010-07-30 22:31:31 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class FilterBarComboBox: public QComboBox
|
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
Q_OBJECT
|
2010-07-30 22:31:31 +00:00
|
|
|
|
2013-01-26 01:19:54 +00:00
|
|
|
public:
|
|
|
|
FilterBarComboBox (QWidget * parent = 0);
|
2013-02-02 22:29:14 +00:00
|
|
|
int currentCount () const;
|
2010-07-30 22:31:31 +00:00
|
|
|
|
2015-01-11 15:01:13 +00:00
|
|
|
virtual QSize minimumSizeHint () const;
|
|
|
|
virtual QSize sizeHint () const;
|
|
|
|
|
2013-01-26 01:19:54 +00:00
|
|
|
protected:
|
|
|
|
virtual void paintEvent (QPaintEvent * e);
|
2015-01-11 15:01:13 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QSize calculateSize (const QSize& textSize, const QSize& countSize) const;
|
2010-07-30 22:31:31 +00:00
|
|
|
};
|
|
|
|
|
2014-12-21 15:34:52 +00:00
|
|
|
class FilterBarLineEdit: public QLineEdit
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
FilterBarLineEdit (QWidget * parent = 0);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void resizeEvent (QResizeEvent * event);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void updateClearButtonVisibility ();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QToolButton * myClearButton;
|
|
|
|
};
|
2010-07-30 22:31:31 +00:00
|
|
|
|
|
|
|
class FilterBar: public QWidget
|
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2015-01-29 22:44:43 +00:00
|
|
|
FilterBar (Prefs& prefs, const TorrentModel& torrents, const TorrentFilter& filter, QWidget * parent = 0);
|
2013-01-26 01:19:54 +00:00
|
|
|
~FilterBar ();
|
|
|
|
|
|
|
|
private:
|
2013-02-02 22:29:14 +00:00
|
|
|
FilterBarComboBox * createTrackerCombo (QStandardItemModel * );
|
|
|
|
FilterBarComboBox * createActivityCombo ();
|
2013-01-26 01:19:54 +00:00
|
|
|
void recountSoon ();
|
|
|
|
void refreshTrackers ();
|
|
|
|
QString getCountString (int n) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Prefs& myPrefs;
|
2015-01-29 22:44:43 +00:00
|
|
|
const TorrentModel& myTorrents;
|
|
|
|
const TorrentFilter& myFilter;
|
2013-02-02 22:29:14 +00:00
|
|
|
FilterBarComboBox * myActivityCombo;
|
|
|
|
FilterBarComboBox * myTrackerCombo;
|
2013-02-01 20:58:55 +00:00
|
|
|
QLabel * myCountLabel;
|
2013-01-26 01:19:54 +00:00
|
|
|
QStandardItemModel * myTrackerModel;
|
|
|
|
QTimer * myRecountTimer;
|
|
|
|
bool myIsBootstrapping;
|
2014-12-21 15:34:52 +00:00
|
|
|
FilterBarLineEdit * myLineEdit;
|
2013-01-26 01:19:54 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void recount ();
|
|
|
|
void refreshPref (int key);
|
2013-02-01 20:58:55 +00:00
|
|
|
void refreshCountLabel ();
|
2013-01-26 01:19:54 +00:00
|
|
|
void onActivityIndexChanged (int index);
|
|
|
|
void onTrackerIndexChanged (int index);
|
|
|
|
void onTorrentModelReset ();
|
|
|
|
void onTorrentModelRowsInserted (const QModelIndex&, int, int);
|
|
|
|
void onTorrentModelRowsRemoved (const QModelIndex&, int, int);
|
|
|
|
void onTorrentModelDataChanged (const QModelIndex&, const QModelIndex&);
|
|
|
|
void onTextChanged (const QString&);
|
2010-07-30 22:31:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|