Improve the playlists-choose dialog
This commit is contained in:
parent
d93f2ee188
commit
4c7317f71d
8 changed files with 191 additions and 52 deletions
|
@ -35,20 +35,28 @@ PlaylistChooser::PlaylistChooser (QWidget *parent, XCollection *coll)
|
|||
|
||||
m_collection = coll;
|
||||
|
||||
// FIXME: implement creation of new Playlists
|
||||
// playlistCreateButton->setEnabled (false);
|
||||
// playlistRemoveButton->setEnabled (false);
|
||||
// the createButton will be enabled as soon as textEdit contains a name
|
||||
// that is not equal to an existing Playlist
|
||||
createButton->setEnabled (false);
|
||||
|
||||
// selectButton will be enabled when exactly one item is selected
|
||||
selectButton->setEnabled (false);
|
||||
|
||||
// fill the List with Playlistnames.
|
||||
// Sort out playlists that start with '_'
|
||||
QRegExp regex = QRegExp ("^[^_]");
|
||||
QStringList lists = coll->list ("Playlists").filter (regex);
|
||||
playlistsListWidget->setSortingEnabled (true);
|
||||
playlistsListWidget->addItems (lists);
|
||||
listWidget->setSortingEnabled (true);
|
||||
listWidget->addItems (lists);
|
||||
connect (coll, SIGNAL (collectionModified (QString, QString, int, QString)),
|
||||
this, SLOT (handle_playlists_modified (QString, QString, int,
|
||||
QString)));
|
||||
|
||||
// display active Playlist in bold Font
|
||||
QString activePls = coll->activePlaylist ();
|
||||
handle_active_pls_changed (activePls, "");
|
||||
connect (coll, SIGNAL (activePlaylistChanged (QString, QString)),
|
||||
this, SLOT (handle_active_pls_changed (QString, QString)));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -62,17 +70,21 @@ PlaylistChooser::handle_playlists_modified (QString name, QString ns,
|
|||
switch (type) {
|
||||
case XMMS_COLLECTION_CHANGED_ADD:
|
||||
if (!name.startsWith("_")) {
|
||||
playlistsListWidget->addItem(name);
|
||||
listWidget->addItem(name);
|
||||
}
|
||||
// if we created the playlist, make is the active playlist
|
||||
if (name == textEdit->text ()) {
|
||||
m_collection->setActivePlaylist (name);
|
||||
}
|
||||
break;
|
||||
case XMMS_COLLECTION_CHANGED_REMOVE: {
|
||||
QList<QListWidgetItem *> list
|
||||
= playlistsListWidget->findItems (name, Qt::MatchExactly);
|
||||
= listWidget->findItems (name, Qt::MatchExactly);
|
||||
if (!list.empty ()) {
|
||||
// we should only have one exatly matching String
|
||||
QListWidgetItem* item = list.first ();
|
||||
int idx = playlistsListWidget->row (item);
|
||||
item = playlistsListWidget->takeItem (idx);
|
||||
int idx = listWidget->row (item);
|
||||
item = listWidget->takeItem (idx);
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
@ -80,17 +92,17 @@ PlaylistChooser::handle_playlists_modified (QString name, QString ns,
|
|||
case XMMS_COLLECTION_CHANGED_RENAME: {
|
||||
// remove the old entry
|
||||
QList<QListWidgetItem *> list
|
||||
= playlistsListWidget->findItems (name, Qt::MatchExactly);
|
||||
= listWidget->findItems (name, Qt::MatchExactly);
|
||||
if (!list.empty ()) {
|
||||
// we should only have one exatly matching String
|
||||
QListWidgetItem* item = list.first ();
|
||||
int idx = playlistsListWidget->row (item);
|
||||
item = playlistsListWidget->takeItem (idx);
|
||||
int idx = listWidget->row (item);
|
||||
item = listWidget->takeItem (idx);
|
||||
delete item;
|
||||
}
|
||||
// and add the new one
|
||||
if (!newname.startsWith("_")) {
|
||||
playlistsListWidget->addItem(newname);
|
||||
listWidget->addItem(newname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -102,20 +114,51 @@ PlaylistChooser::handle_playlists_modified (QString name, QString ns,
|
|||
|
||||
|
||||
void
|
||||
PlaylistChooser::on_playlistCreateButton_clicked ()
|
||||
PlaylistChooser::handle_active_pls_changed (QString newActive,
|
||||
QString oldActive)
|
||||
{
|
||||
QString name = playlistTextEdit->text ();
|
||||
// only create new playlist, if it doesn't already exist
|
||||
if (m_collection->list ("Playlists").contains (name)) return;
|
||||
QListWidgetItem *item;
|
||||
QFont font;
|
||||
QList <QListWidgetItem *> list;
|
||||
|
||||
m_collection->addIdlist (name);
|
||||
// newActive and oldActive can match at most once each
|
||||
// paint former active Playlist no longer in bold
|
||||
list = listWidget->findItems (oldActive, Qt::MatchExactly);
|
||||
if (!list.empty ()) {
|
||||
item = list.first ();
|
||||
font = item->font ();
|
||||
font.setBold (false);
|
||||
item->setFont (font);
|
||||
}
|
||||
|
||||
// paint new active Playlist in bold
|
||||
list = listWidget->findItems (newActive, Qt::MatchExactly);
|
||||
if (!list.empty ()) {
|
||||
item = list.first ();
|
||||
font = item->font ();
|
||||
font.setBold (true);
|
||||
item->setFont (font);
|
||||
}
|
||||
|
||||
// update the activestate of the selectButton
|
||||
on_listWidget_itemSelectionChanged ();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PlaylistChooser::playlistExists (QString name) {
|
||||
// Use the information from m_collection, as listWidger
|
||||
// doesn't contain hidden Playlists
|
||||
return m_collection->list ("Playlists").contains (name);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistChooser::on_playlistRemoveButton_clicked ()
|
||||
PlaylistChooser::on_removeButton_clicked ()
|
||||
{
|
||||
QList<QListWidgetItem *> list = playlistsListWidget->selectedItems ();
|
||||
if (list.empty ()) return; // nothing to do
|
||||
QList<QListWidgetItem *> list = listWidget->selectedItems ();
|
||||
if (list.empty ())
|
||||
return; // nothing to do
|
||||
|
||||
// TODO: if we change the selectionmodel to multiselection,
|
||||
// change this tp remove more than one item
|
||||
|
@ -124,9 +167,58 @@ PlaylistChooser::on_playlistRemoveButton_clicked ()
|
|||
m_collection->remove (name, "Playlists");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistChooser::on_playlistsListWidget_itemDoubleClicked (QListWidgetItem* item)
|
||||
PlaylistChooser::on_createButton_clicked ()
|
||||
{
|
||||
QString name = textEdit->text ();
|
||||
// only create new playlist, if it doesn't already exist
|
||||
if (playlistExists (name)) return;
|
||||
|
||||
m_collection->addIdlist (name);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistChooser::on_selectButton_clicked ()
|
||||
{
|
||||
QList <QListWidgetItem *> list = listWidget->selectedItems ();
|
||||
if (list.size () == 1) {
|
||||
QListWidgetItem * item = list.first ();
|
||||
m_collection->setActivePlaylist (item->text ());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistChooser::on_listWidget_itemDoubleClicked (QListWidgetItem* item)
|
||||
{
|
||||
QString name = item->text ();
|
||||
m_collection->setActivePlaylist (name);
|
||||
}
|
||||
|
||||
void
|
||||
PlaylistChooser::on_listWidget_itemSelectionChanged ()
|
||||
{
|
||||
QList <QListWidgetItem *> list = listWidget->selectedItems ();
|
||||
// enable selectButton, if one item is selected and does not represent
|
||||
// the currently active playlist
|
||||
selectButton->setEnabled ((list.size () == 1)
|
||||
&& (list.first ()->text ()
|
||||
!= m_collection->activePlaylist ()));
|
||||
|
||||
// enable removeButton if more than one item is selected
|
||||
// or if the selected item is not the actice Playlist
|
||||
removeButton->setEnabled ((list.size () > 1) ||
|
||||
( (list.size () == 1) && (list.first ()->text ()
|
||||
!= m_collection->activePlaylist ())));
|
||||
}
|
||||
|
||||
void
|
||||
PlaylistChooser::on_textEdit_textChanged ()
|
||||
{
|
||||
// Enable createButton only, if no playlist with that name exists
|
||||
// and the textEdit is not empty
|
||||
createButton->setEnabled ((!playlistExists (textEdit->text ())
|
||||
&& (textEdit->text () != "")));
|
||||
}
|
||||
|
|
|
@ -32,14 +32,21 @@ class PlaylistChooser : public QDialog, private Ui::PlaylistChooser {
|
|||
|
||||
|
||||
private slots:
|
||||
// XCollection change handlers
|
||||
void handle_playlists_modified (QString, QString, int, QString);
|
||||
void handle_active_pls_changed (QString, QString);
|
||||
|
||||
void on_playlistCreateButton_clicked ();
|
||||
void on_playlistRemoveButton_clicked ();
|
||||
|
||||
void on_playlistsListWidget_itemDoubleClicked (QListWidgetItem* item);
|
||||
// autoconnect Slots
|
||||
void on_removeButton_clicked ();
|
||||
void on_createButton_clicked ();
|
||||
void on_selectButton_clicked ();
|
||||
void on_listWidget_itemDoubleClicked (QListWidgetItem* item);
|
||||
void on_listWidget_itemSelectionChanged ();
|
||||
void on_textEdit_textChanged ();
|
||||
|
||||
private:
|
||||
bool playlistExists (QString name);
|
||||
|
||||
XCollection* m_collection;
|
||||
};
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>260</width>
|
||||
<height>301</height>
|
||||
<width>266</width>
|
||||
<height>302</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
|
@ -16,10 +16,10 @@
|
|||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<item>
|
||||
<widget class="QLineEdit" name="playlistTextEdit" />
|
||||
<widget class="QLineEdit" name="textEdit" />
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="playlistCreateButton" >
|
||||
<widget class="QPushButton" name="createButton" >
|
||||
<property name="text" >
|
||||
<string>Create</string>
|
||||
</property>
|
||||
|
@ -28,7 +28,7 @@
|
|||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="playlistsListWidget" >
|
||||
<widget class="QListWidget" name="listWidget" >
|
||||
<property name="verticalScrollBarPolicy" >
|
||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||
</property>
|
||||
|
@ -40,7 +40,7 @@
|
|||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<item>
|
||||
<widget class="QPushButton" name="playlistRemoveButton" >
|
||||
<widget class="QPushButton" name="removeButton" >
|
||||
<property name="text" >
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
|
@ -59,6 +59,19 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="selectButton" >
|
||||
<property name="toolTip" >
|
||||
<string><html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Set the currently selected playlist as active playlist</p></body></html></string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Select</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="closeButton" >
|
||||
<property name="text" >
|
||||
|
@ -89,9 +102,9 @@
|
|||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>playlistsListWidget</sender>
|
||||
<sender>listWidget</sender>
|
||||
<signal>currentTextChanged(QString)</signal>
|
||||
<receiver>playlistTextEdit</receiver>
|
||||
<receiver>textEdit</receiver>
|
||||
<slot>setText(QString)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue