1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-22 22:20:39 +00:00
transmission/qt/filterbar.h
Mike Gelfand 06fa457bd9 Improve filter bar look (Qt client)
Use normal but semi-transparent color instead of 'disabled' color for
counts drawing.
Do not leave empty space for icon when selected item doesn't have one.
Use null pixmaps/icons instead of non-null blank ones.
Implement our own sizeHint and minimumSizeHint to make sure both combos
have the same height.
Make activity combo width fixed, tracker combo width to fit its content
and line edit to occupy the rest.
Add 'Search...' placeholder to line edit.
2015-01-11 15:01:13 +00:00

124 lines
2.8 KiB
C++

/*
* This file Copyright (C) 2010-2014 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_FILTERBAR_H
#define QTR_FILTERBAR_H
#include <QComboBox>
#include <QItemDelegate>
#include <QLineEdit>
#include <QWidget>
class QLabel;
class QLineEdit;
class QPaintEvent;
class QStandardItemModel;
class QTimer;
class QToolButton;
class Prefs;
class TorrentFilter;
class TorrentModel;
class FilterBarComboBoxDelegate: public QItemDelegate
{
Q_OBJECT
public:
FilterBarComboBoxDelegate (QObject * parent, QComboBox * combo);
public:
static bool isSeparator (const QModelIndex &index);
static void setSeparator (QAbstractItemModel * model, const QModelIndex& index);
protected:
virtual void paint (QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const;
virtual QSize sizeHint (const QStyleOptionViewItem&, const QModelIndex&) const;
private:
QComboBox * myCombo;
};
class FilterBarComboBox: public QComboBox
{
Q_OBJECT
public:
FilterBarComboBox (QWidget * parent = 0);
int currentCount () const;
virtual QSize minimumSizeHint () const;
virtual QSize sizeHint () const;
protected:
virtual void paintEvent (QPaintEvent * e);
private:
QSize calculateSize (const QSize& textSize, const QSize& countSize) const;
};
class FilterBarLineEdit: public QLineEdit
{
Q_OBJECT
public:
FilterBarLineEdit (QWidget * parent = 0);
protected:
virtual void resizeEvent (QResizeEvent * event);
private slots:
void updateClearButtonVisibility ();
private:
QToolButton * myClearButton;
};
class FilterBar: public QWidget
{
Q_OBJECT
public:
FilterBar (Prefs& prefs, TorrentModel& torrents, TorrentFilter& filter, QWidget * parent = 0);
~FilterBar ();
private:
FilterBarComboBox * createTrackerCombo (QStandardItemModel * );
FilterBarComboBox * createActivityCombo ();
void recountSoon ();
void refreshTrackers ();
QString getCountString (int n) const;
private:
Prefs& myPrefs;
TorrentModel& myTorrents;
TorrentFilter& myFilter;
FilterBarComboBox * myActivityCombo;
FilterBarComboBox * myTrackerCombo;
QLabel * myCountLabel;
QStandardItemModel * myTrackerModel;
QTimer * myRecountTimer;
bool myIsBootstrapping;
FilterBarLineEdit * myLineEdit;
private slots:
void recount ();
void refreshPref (int key);
void refreshCountLabel ();
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&);
};
#endif