Make the clear button a part of the search textbox. Fixes issue #1071
This commit is contained in:
parent
515167506f
commit
05a1bf6e37
|
@ -45,7 +45,6 @@ LibraryFilterWidget::LibraryFilterWidget(QWidget *parent)
|
|||
filter_delay_->setSingleShot(true);
|
||||
|
||||
// Icons
|
||||
ui_->clear->setIcon(IconLoader::Load("edit-clear-locationbar-ltr"));
|
||||
ui_->options->setIcon(IconLoader::Load("configure"));
|
||||
|
||||
// Filter by age
|
||||
|
@ -74,7 +73,6 @@ LibraryFilterWidget::LibraryFilterWidget(QWidget *parent)
|
|||
connect(ui_->filter_age_month, SIGNAL(triggered()), filter_age_mapper_, SLOT(map()));
|
||||
connect(ui_->filter_age_three_months, SIGNAL(triggered()), filter_age_mapper_, SLOT(map()));
|
||||
connect(ui_->filter_age_year, SIGNAL(triggered()), filter_age_mapper_, SLOT(map()));
|
||||
connect(ui_->clear, SIGNAL(clicked()), SLOT(ClearFilter()));
|
||||
|
||||
// "Group by ..."
|
||||
ui_->group_by_artist->setProperty("group_by", QVariant::fromValue(
|
||||
|
@ -116,7 +114,6 @@ LibraryFilterWidget::LibraryFilterWidget(QWidget *parent)
|
|||
MacLineEdit* lineedit = new MacLineEdit(this);
|
||||
ui_->horizontalLayout->insertWidget(1, lineedit);
|
||||
filter_ = lineedit;
|
||||
ui_->clear->setHidden(true);
|
||||
#else
|
||||
filter_ = ui_->filter;
|
||||
#endif
|
||||
|
@ -191,13 +188,8 @@ void LibraryFilterWidget::GroupingChanged(const LibraryModel::Grouping& g) {
|
|||
ui_->group_by_advanced->setChecked(true);
|
||||
}
|
||||
|
||||
void LibraryFilterWidget::ClearFilter() {
|
||||
filter_->clear();
|
||||
filter_->setFocus();
|
||||
}
|
||||
|
||||
void LibraryFilterWidget::SetFilterHint(const QString& hint) {
|
||||
filter_->SetHint(hint);
|
||||
filter_->set_hint(hint);
|
||||
}
|
||||
|
||||
void LibraryFilterWidget::SetAgeFilterEnabled(bool enabled) {
|
||||
|
|
|
@ -64,7 +64,6 @@ class LibraryFilterWidget : public QWidget {
|
|||
private slots:
|
||||
void GroupingChanged(const LibraryModel::Grouping& g);
|
||||
void GroupByClicked(QAction* action);
|
||||
void ClearFilter();
|
||||
|
||||
void FilterTextChanged(const QString& text);
|
||||
void FilterDelayTimeout();
|
||||
|
|
|
@ -20,19 +20,6 @@
|
|||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolButton" name="clear">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="LineEdit" name="filter">
|
||||
<property name="hint" stdset="0">
|
||||
|
|
|
@ -67,9 +67,6 @@ PlaylistContainer::PlaylistContainer(QWidget *parent)
|
|||
|
||||
settings_.beginGroup(kSettingsGroup);
|
||||
|
||||
// Icons
|
||||
ui_->clear->setIcon(IconLoader::Load("edit-clear-locationbar-ltr"));
|
||||
|
||||
// Tab bar
|
||||
ui_->tab_bar->setExpanding(false);
|
||||
ui_->tab_bar->setMovable(true);
|
||||
|
@ -78,7 +75,6 @@ PlaylistContainer::PlaylistContainer(QWidget *parent)
|
|||
ui_->tab_bar->setMaximumHeight(0);
|
||||
|
||||
// Connections
|
||||
connect(ui_->clear, SIGNAL(clicked()), SLOT(ClearFilter()));
|
||||
connect(ui_->tab_bar, SIGNAL(currentChanged(int)), SLOT(Save()));
|
||||
connect(ui_->tab_bar, SIGNAL(Save(int)), SLOT(SavePlaylist(int)));
|
||||
|
||||
|
@ -120,11 +116,6 @@ void PlaylistContainer::SetActions(
|
|||
connect(load_playlist, SIGNAL(triggered()), SLOT(LoadPlaylist()));
|
||||
}
|
||||
|
||||
void PlaylistContainer::ClearFilter() {
|
||||
filter_->clear();
|
||||
filter_->setFocus();
|
||||
}
|
||||
|
||||
void PlaylistContainer::SetManager(PlaylistManager *manager) {
|
||||
manager_ = manager;
|
||||
ui_->tab_bar->SetManager(manager);
|
||||
|
|
|
@ -59,7 +59,6 @@ protected:
|
|||
void resizeEvent(QResizeEvent *);
|
||||
|
||||
private slots:
|
||||
void ClearFilter();
|
||||
void NewPlaylist();
|
||||
void LoadPlaylist();
|
||||
void SavePlaylist() { SavePlaylist(-1); }
|
||||
|
|
|
@ -111,19 +111,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="clear">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="LineEdit" name="filter">
|
||||
<property name="hint" stdset="0">
|
||||
|
|
|
@ -70,7 +70,6 @@ AlbumCoverManager::AlbumCoverManager(LibraryBackend* backend, QWidget* parent,
|
|||
ui_->action_choose_manual->setIcon(IconLoader::Load("document-open"));
|
||||
ui_->action_show_fullsize->setIcon(IconLoader::Load("zoom-in"));
|
||||
ui_->action_unset_cover->setIcon(IconLoader::Load("list-remove"));
|
||||
ui_->clear->setIcon(IconLoader::Load("edit-clear-locationbar-ltr"));
|
||||
ui_->view->setIcon(IconLoader::Load("view-choose"));
|
||||
ui_->fetch->setIcon(IconLoader::Load("download"));
|
||||
ui_->action_search_manual->setIcon(IconLoader::Load("download"));
|
||||
|
|
|
@ -57,19 +57,6 @@
|
|||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolButton" name="clear">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="LineEdit" name="filter">
|
||||
<property name="hint" stdset="0">
|
||||
|
@ -214,7 +201,6 @@
|
|||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>artists</tabstop>
|
||||
<tabstop>clear</tabstop>
|
||||
<tabstop>filter</tabstop>
|
||||
<tabstop>view</tabstop>
|
||||
<tabstop>fetch</tabstop>
|
||||
|
@ -223,22 +209,5 @@
|
|||
<resources>
|
||||
<include location="../../data/data.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>clear</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>filter</receiver>
|
||||
<slot>clear()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>352</x>
|
||||
<y>19</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>397</x>
|
||||
<y>15</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -85,9 +85,9 @@ bool EditTagDialog::SetSongs(const SongList &s) {
|
|||
|
||||
ui_->filename->setText(QDir::toNativeSeparators(song.filename()));
|
||||
|
||||
ui_->artist->ClearHint();
|
||||
ui_->album->ClearHint();
|
||||
ui_->genre->ClearHint();
|
||||
ui_->artist->clear_hint();
|
||||
ui_->album->clear_hint();
|
||||
ui_->genre->clear_hint();
|
||||
} else {
|
||||
// Find any fields that are common to all items
|
||||
|
||||
|
@ -98,17 +98,17 @@ bool EditTagDialog::SetSongs(const SongList &s) {
|
|||
foreach (const Song& song, songs) {
|
||||
if (common_artist_ != song.artist()) {
|
||||
common_artist_ = QString::null;
|
||||
ui_->artist->SetHint(kHintText);
|
||||
ui_->artist->set_hint(kHintText);
|
||||
}
|
||||
|
||||
if (common_album_ != song.album()) {
|
||||
common_album_ = QString::null;
|
||||
ui_->album->SetHint(kHintText);
|
||||
ui_->album->set_hint(kHintText);
|
||||
}
|
||||
|
||||
if (common_genre_ != song.genre()) {
|
||||
common_genre_ = QString::null;
|
||||
ui_->genre->SetHint(kHintText);
|
||||
ui_->genre->set_hint(kHintText);
|
||||
}
|
||||
|
||||
if (common_year_ != song.year())
|
||||
|
|
|
@ -16,25 +16,57 @@
|
|||
*/
|
||||
|
||||
#include "lineedit.h"
|
||||
#include "ui/iconloader.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
#include <QStyle>
|
||||
#include <QToolButton>
|
||||
|
||||
LineEdit::LineEdit(QWidget* parent)
|
||||
: QLineEdit(parent),
|
||||
LineEditInterface(this)
|
||||
LineEditInterface(this),
|
||||
has_clear_button_(true),
|
||||
clear_button_(new QToolButton(this))
|
||||
{
|
||||
clear_button_->setIcon(IconLoader::Load("edit-clear-locationbar-ltr"));
|
||||
clear_button_->setIconSize(QSize(16, 16));
|
||||
clear_button_->setCursor(Qt::ArrowCursor);
|
||||
clear_button_->setStyleSheet("QToolButton { border: none; padding: 0px; }");
|
||||
set_clear_button(true);
|
||||
|
||||
connect(clear_button_, SIGNAL(clicked()), SLOT(clear()));
|
||||
connect(clear_button_, SIGNAL(clicked()), SLOT(setFocus()));
|
||||
}
|
||||
|
||||
void LineEdit::SetHint(const QString& hint) {
|
||||
void LineEdit::set_hint(const QString& hint) {
|
||||
hint_ = hint;
|
||||
update();
|
||||
}
|
||||
|
||||
void LineEdit::set_clear_button(bool visible) {
|
||||
has_clear_button_ = visible;
|
||||
clear_button_->setVisible(visible);
|
||||
|
||||
if (visible) {
|
||||
const int frame_width = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||
setStyleSheet(QString("QLineEdit { padding-left: %1px; } ").arg(
|
||||
clear_button_->sizeHint().width() + frame_width + 1));
|
||||
|
||||
QSize msz = minimumSizeHint();
|
||||
setMinimumSize(qMax(msz.width(), clear_button_->sizeHint().height() + frame_width * 2 + 2),
|
||||
qMax(msz.height(), clear_button_->sizeHint().height() + frame_width * 2 + 2));
|
||||
} else {
|
||||
setStyleSheet(QString());
|
||||
}
|
||||
}
|
||||
|
||||
void LineEdit::paintEvent(QPaintEvent* e) {
|
||||
QLineEdit::paintEvent(e);
|
||||
|
||||
if (!hasFocus() && displayText().isEmpty() && !hint_.isEmpty()) {
|
||||
clear_button_->hide();
|
||||
|
||||
QPainter p(this);
|
||||
|
||||
QFont font;
|
||||
|
@ -50,5 +82,13 @@ void LineEdit::paintEvent(QPaintEvent* e) {
|
|||
QRect r(rect().topLeft() + QPoint(kBorder + 5, kBorder),
|
||||
rect().bottomRight() - QPoint(kBorder, kBorder));
|
||||
p.drawText(r, Qt::AlignLeft | Qt::AlignVCenter, hint_);
|
||||
} else {
|
||||
clear_button_->setVisible(has_clear_button_);
|
||||
}
|
||||
}
|
||||
|
||||
void LineEdit::resizeEvent(QResizeEvent*) {
|
||||
const QSize sz = clear_button_->sizeHint();
|
||||
const int frame_width = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||
clear_button_->move(frame_width, (rect().height() - sz.height()) / 2);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
#include <QLineEdit>
|
||||
|
||||
class QToolButton;
|
||||
|
||||
class LineEditInterface {
|
||||
public:
|
||||
LineEditInterface(QObject* object) : object_(object) {}
|
||||
|
@ -28,7 +30,7 @@ class LineEditInterface {
|
|||
virtual void setFocus() = 0;
|
||||
virtual void setText(const QString&) = 0;
|
||||
virtual QString text() const = 0;
|
||||
virtual void SetHint(const QString&) = 0;
|
||||
virtual void set_hint(const QString&) = 0;
|
||||
|
||||
QObject* object() const { return object_; }
|
||||
|
||||
|
@ -36,27 +38,35 @@ class LineEditInterface {
|
|||
QObject* object_;
|
||||
};
|
||||
|
||||
// Remove in Qt 4.7: QLineEdit has placeholderText
|
||||
class LineEdit : public QLineEdit, public LineEditInterface {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString hint READ GetHint WRITE SetHint);
|
||||
Q_PROPERTY(QString hint READ hint WRITE set_hint);
|
||||
Q_PROPERTY(bool has_clear_button READ has_clear_button WRITE set_clear_button);
|
||||
|
||||
public:
|
||||
LineEdit(QWidget* parent = 0);
|
||||
|
||||
QString GetHint() const { return hint_; }
|
||||
void SetHint(const QString& hint);
|
||||
void ClearHint() { SetHint(QString()); }
|
||||
QString hint() const { return hint_; }
|
||||
void set_hint(const QString& hint);
|
||||
void clear_hint() { set_hint(QString()); }
|
||||
|
||||
void paintEvent(QPaintEvent* e);
|
||||
bool has_clear_button() const { return has_clear_button_; }
|
||||
void set_clear_button(bool visible);
|
||||
|
||||
void clear() { QLineEdit::clear(); }
|
||||
void setFocus() { QLineEdit::setFocus(); }
|
||||
void setText(const QString& t) { QLineEdit::setText(t); }
|
||||
QString text() const { return QLineEdit::text(); }
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* e);
|
||||
void resizeEvent(QResizeEvent*);
|
||||
|
||||
private:
|
||||
QString hint_;
|
||||
|
||||
bool has_clear_button_;
|
||||
QToolButton* clear_button_;
|
||||
};
|
||||
|
||||
#endif // LINEEDIT_H
|
||||
|
|
Loading…
Reference in New Issue