Commit 3922d9aa authored by Scott Wheeler's avatar Scott Wheeler

Split the SearchWidget up into two parts, one of which remains the

SearchWidget, but it also contains a SearchLine.

SearchLine operates on a PlaylistSearch::Component in the same way that
SearchWidget operates on PlaylistSearch, so this adheres to that method
of splitting things up.

I can also reuse the SearchLine in my implementation of the more advanced
search widget which I comitted the first parts of last night.

svn path=/trunk/kdemultimedia/juk/; revision=240319
parent cfb6b16f
......@@ -453,7 +453,7 @@ void PlaylistSplitter::setupLayout()
// Create the search widget -- this must be done after the CollectionList is created.
m_searchWidget = new SearchWidget(editorSplitter, CollectionList::instance(), "searchWidget");
m_searchWidget = new SearchWidget(editorSplitter, "searchWidget");
editorSplitter->moveToFirst(m_searchWidget);
connect(m_searchWidget, SIGNAL(signalQueryChanged()), this, SLOT(slotShowSearchResults()));
connect(CollectionList::instance(), SIGNAL(signalVisibleColumnsChanged()),
......@@ -766,10 +766,9 @@ void PlaylistSplitter::slotShowSearchResults()
void PlaylistSplitter::slotVisibleColumnsChanged()
{
m_searchWidget->slotUpdateColumns();
m_searchWidget->slotQueryChanged();
if(m_searchWidget->searchedColumns(0).count() > 1)
slotShowSearchResults();
m_searchWidget->updateColumns();
// if(m_searchWidget->searchedColumns(0).count() > 1)
slotShowSearchResults();
}
void PlaylistSplitter::slotCreateSearchList(const PlaylistSearch &search,
......
......@@ -26,133 +26,148 @@
#include <qpushbutton.h>
#include "searchwidget.h"
#include "playlist.h"
#include "collectionlist.h"
////////////////////////////////////////////////////////////////////////////////
// public methods
// SearchLine public methods
////////////////////////////////////////////////////////////////////////////////
SearchWidget::SearchWidget(QWidget *parent, const Playlist *playlist, const char *name)
: QWidget(parent, name),
m_playlist(playlist)
{
setupLayout();
slotUpdateColumns();
}
SearchWidget::~SearchWidget()
SearchLine::SearchLine(QWidget *parent, const char *name) : QHBox(parent, name)
{
setSpacing(5);
}
QString SearchWidget::query() const
{
return m_lineEdit->text();
}
m_searchFieldsBox = new KComboBox(this, "searchFields");
connect(m_searchFieldsBox, SIGNAL(activated(int)),
this, SIGNAL(signalQueryChanged()));
bool SearchWidget::caseSensitive() const
{
return m_caseSensitive->currentItem() == CaseSensitive;
}
m_lineEdit = new KLineEdit(this, "searchLineEdit");
connect(m_lineEdit, SIGNAL(textChanged(const QString &)),
this, SIGNAL(signalQueryChanged()));
bool SearchWidget::regExp() const
{
return m_caseSensitive->currentItem() == Pattern;
m_caseSensitive = new KComboBox(this);
m_caseSensitive->insertItem(i18n("Normal Matching"), 0);
m_caseSensitive->insertItem(i18n("Case Sensitive"), 1);
m_caseSensitive->insertItem(i18n("Pattern Matching"), 2);
connect(m_caseSensitive, SIGNAL(activated(int)),
this, SIGNAL(signalQueryChanged()));
}
void SearchWidget::setSearch(const PlaylistSearch &search)
PlaylistSearch::Component SearchLine::searchComponent() const
{
PlaylistSearch::ComponentList components = search.components();
QString query = m_lineEdit->text();
bool caseSensitive = m_caseSensitive->currentItem() == CaseSensitive;
// This is intentionally written so that when multiple search lines are
// supported that it can be easily updated.
Playlist *playlist = CollectionList::instance();
PlaylistSearch::ComponentList::ConstIterator it = components.begin();
QValueList<int> searchedColumns;
if(it == components.end()) {
clear();
return;
if(m_searchFieldsBox->currentItem() == 0) {
for(int i = 0; i < playlist->columns(); i++) {
if(playlist->isColumnVisible(i) && !playlist->columnText(i).isEmpty())
searchedColumns.append(i);
}
}
else
searchedColumns.append(m_searchFieldsBox->currentItem() - 1);
if(!(*it).isPatternSearch()) {
m_lineEdit->setText((*it).query());
m_caseSensitive->setCurrentItem((*it).isCaseSensitive() ? CaseSensitive : Default);
return PlaylistSearch::Component(query, caseSensitive, searchedColumns);
}
void SearchLine::setSearchComponent(const PlaylistSearch::Component &component)
{
if(!component.isPatternSearch()) {
m_lineEdit->setText(component.query());
m_caseSensitive->setCurrentItem(component.isCaseSensitive() ? CaseSensitive : Default);
}
else {
m_lineEdit->setText((*it).pattern().pattern());
m_lineEdit->setText(component.pattern().pattern());
m_caseSensitive->setCurrentItem(Pattern);
}
}
PlaylistSearch SearchWidget::search(const PlaylistList &playlists) const
void SearchLine::clear()
{
PlaylistSearch::ComponentList components;
PlaylistSearch::Component c;
// We don't want to emit the signal if it's already empty.
if(!m_lineEdit->text().isEmpty())
m_lineEdit->clear();
}
if(m_caseSensitive->currentItem() != Pattern)
c = PlaylistSearch::Component(query(), caseSensitive(), searchedColumns());
else
c = PlaylistSearch::Component(QRegExp(query()), searchedColumns());
void SearchLine::updateColumns()
{
QString currentText = m_searchFieldsBox->currentText();
m_searchFieldsBox->clear();
QStringList columnHeaders;
columnHeaders.append(QString("<%1>").arg(i18n("All Visible")));
components.append(c);
PlaylistSearch s(playlists, components);
Playlist *playlist = CollectionList::instance();
int selection = -1;
for(int i = 0; i < playlist->columns(); i++) {
if(playlist->isColumnVisible(i) && !playlist->columnText(i).isEmpty()) {
QString text = playlist->columnText(i);
columnHeaders.append(text);
if(currentText == text)
selection = i;
}
}
return s;
m_searchFieldsBox->insertStringList(columnHeaders);
m_searchFieldsBox->setCurrentItem(selection + 1);
}
////////////////////////////////////////////////////////////////////////////////
// public slots
// SearchWidget public methods
////////////////////////////////////////////////////////////////////////////////
void SearchWidget::clear()
SearchWidget::SearchWidget(QWidget *parent, const char *name) : QWidget(parent, name)
{
// We don't want to emit the signal if it's already empty.
if(!m_lineEdit->text().isEmpty())
m_lineEdit->clear();
setupLayout();
updateColumns();
}
void SearchWidget::slotQueryChanged(int)
SearchWidget::~SearchWidget()
{
m_searchedColumns[0].clear();
if(m_searchFieldsBox->currentItem() == 0) {
for(int i = 0; i < m_playlist->columns(); i++) {
if(m_playlist->isColumnVisible(i) && !m_playlist->columnText(i).isEmpty())
m_searchedColumns[0].append(i);
}
}
void SearchWidget::setSearch(const PlaylistSearch &search)
{
PlaylistSearch::ComponentList components = search.components();
if(components.isEmpty()) {
clear();
return;
}
else
m_searchedColumns[0].append(m_searchFieldsBox->currentItem() - 1);
emit signalQueryChanged();
m_searchLine->setSearchComponent(*components.begin());
}
void SearchWidget::slotUpdateColumns()
PlaylistSearch SearchWidget::search(const PlaylistList &playlists) const
{
QString currentText = m_searchFieldsBox->currentText();
m_searchFieldsBox->clear();
m_columnHeaders.clear();
m_columnHeaders.append(QString("<%1>").arg(i18n("All Visible")));
PlaylistSearch::ComponentList components;
components.append(m_searchLine->searchComponent());
return PlaylistSearch(playlists, components);
}
int selection = -1;
void SearchWidget::updateColumns()
{
m_searchLine->updateColumns();
}
for(int i = 0; i < m_playlist->columns(); i++) {
if(m_playlist->isColumnVisible(i) && !m_playlist->columnText(i).isEmpty()) {
QString text = m_playlist->columnText(i);
m_columnHeaders.append(text);
if(currentText == text)
selection = i;
}
}
////////////////////////////////////////////////////////////////////////////////
// SearchWidget public slots
////////////////////////////////////////////////////////////////////////////////
m_searchFieldsBox->insertStringList(m_columnHeaders);
m_searchFieldsBox->setCurrentItem(selection + 1);
void SearchWidget::clear()
{
m_searchLine->clear();
}
////////////////////////////////////////////////////////////////////////////////
// private methods
// SearchWidget private methods
////////////////////////////////////////////////////////////////////////////////
void SearchWidget::setupLayout()
......@@ -162,20 +177,11 @@ void SearchWidget::setupLayout()
new QLabel(i18n("Search:"), this);
m_searchFieldsBox = new KComboBox(this, "searchFields");
connect(m_searchFieldsBox, SIGNAL(activated(int)), this, SLOT(slotQueryChanged()));
m_lineEdit = new KLineEdit(this, "searchLineEdit");
m_caseSensitive = new KComboBox(this);
m_caseSensitive->insertItem(i18n("Normal Matching"), 0);
m_caseSensitive->insertItem(i18n("Case Sensitive"), 1);
m_caseSensitive->insertItem(i18n("Pattern Matching"), 2);
connect(m_caseSensitive, SIGNAL(activated(int)), this, SLOT(slotQueryChanged()));
m_searchLine = new SearchLine(this);
connect(m_searchLine, SIGNAL(signalQueryChanged()), this, SIGNAL(signalQueryChanged()));
QPushButton *button = new QPushButton(i18n("Clear"), this);
connect(button, SIGNAL(clicked()), this, SLOT(clear()));
connect(m_lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(slotQueryChanged()));
setFixedHeight(minimumSizeHint().height());
}
......
......@@ -19,6 +19,7 @@
#define SEARCHWIDGET_H
#include <qwidget.h>
#include <qhbox.h>
#include "playlistsearch.h"
......@@ -29,35 +30,53 @@ class KComboBox;
class Playlist;
class SearchWidget : public QWidget
class SearchLine : public QHBox
{
Q_OBJECT
public:
enum Mode { Default = 0, CaseSensitive = 1, Pattern = 2 };
SearchLine(QWidget *parent, const char *name = 0);
virtual ~SearchLine() {}
PlaylistSearch::Component searchComponent() const;
void setSearchComponent(const PlaylistSearch::Component &component);
void updateColumns();
void clear();
signals:
void signalQueryChanged();
private:
KLineEdit *m_lineEdit;
KComboBox *m_searchFieldsBox;
KComboBox *m_caseSensitive;
};
class SearchWidget : public QWidget
{
Q_OBJECT
public:
/**
* Note that playlist here is just a playlist to get the columns from and
* has nothing to do with the results of a search.
*/
SearchWidget(QWidget *parent, const Playlist *playlist, const char *name);
SearchWidget(QWidget *parent, const char *name = 0);
virtual ~SearchWidget();
/**
* Returns a list of searched columns for the given search row.
*/
QValueList<int> searchedColumns(int searchLine = 0) const { return m_searchedColumns[searchLine]; }
QString query() const;
bool caseSensitive() const;
bool regExp() const;
PlaylistSearch search(const PlaylistList &playlists) const;
void setSearch(const PlaylistSearch &search);
void updateColumns();
public slots:
void clear();
void slotUpdateColumns();
void slotQueryChanged(int = 0);
signals:
void signalQueryChanged();
......@@ -66,12 +85,8 @@ private:
void setupLayout();
private:
const Playlist *m_playlist;
KLineEdit *m_lineEdit;
KComboBox *m_searchFieldsBox;
KComboBox *m_caseSensitive;
SearchLine *m_searchLine;
QStringList m_columnHeaders;
QValueList< QValueList<int> > m_searchedColumns;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment