Commit c31d9c29 authored by Scott Wheeler's avatar Scott Wheeler

Edit actions should now work everywhere. The next step is cleaning up the

RMB menus.

svn path=/trunk/kdemultimedia/juk/; revision=206998
parent b135e38d
......@@ -87,22 +87,28 @@ CollectionList::~CollectionList()
}
void CollectionList::contentsDropEvent(QDropEvent *e)
void CollectionList::decode(QMimeSource *s)
{
if(e->source() != this) {
KURL::List urls;
KURL::List urls;
if(!KURLDrag::decode(s, urls) || urls.isEmpty())
return;
if(KURLDrag::decode(e, urls) && !urls.isEmpty()) {
QStringList files;
for(KURL::List::Iterator it = urls.begin(); it != urls.end(); it++)
files.append((*it).path());
if(playlistSplitter())
playlistSplitter()->add(files, this);
}
}
QStringList files;
for(KURL::List::Iterator it = urls.begin(); it != urls.end(); it++)
files.append((*it).path());
if(playlistSplitter())
playlistSplitter()->add(files, this);
}
void CollectionList::contentsDropEvent(QDropEvent *e)
{
if(e->source() == this)
return;
}
void CollectionList::contentsDragMoveEvent(QDragMoveEvent *e)
......
......@@ -58,6 +58,7 @@ protected:
CollectionList(PlaylistSplitter *s, QWidget *parent);
virtual ~CollectionList();
virtual void decode(QMimeSource *s);
virtual void contentsDropEvent(QDropEvent *e);
virtual void contentsDragMoveEvent(QDragMoveEvent *e);
......
......@@ -27,6 +27,8 @@
#include <qlistview.h>
#include <qinputdialog.h>
#include <qslider.h>
#include <qstrlist.h>
#include <qmetaobject.h>
#include "juk.h"
#include "slideraction.h"
......@@ -108,9 +110,10 @@ void JuK::setupActions()
// edit menu
KStdAction::cut(this, SLOT(cut()), actionCollection());
KStdAction::copy(splitter, SLOT(copy()), actionCollection());
KStdAction::paste(splitter, SLOT(paste()), actionCollection());
KStdAction::selectAll(splitter, SLOT(selectAll()), actionCollection());
KStdAction::copy(this, SLOT(copy()), actionCollection());
KStdAction::paste(this, SLOT(paste()), actionCollection());
new KAction(i18n("Clear"), "editclear", 0, this, SLOT(clear()), actionCollection(), "clear");
KStdAction::selectAll(this, SLOT(selectAll()), actionCollection());
// view menu
showEditorAction = new KToggleAction(i18n("Show Tag Editor"), "edit", 0, actionCollection(), "showEditor");
......@@ -305,6 +308,24 @@ bool JuK::queryClose()
return true;
}
void JuK::invokeEditSlot( const char *slotName, const char *slot )
{
QObject *object = focusWidget();
if(!object || !slotName || !slot)
return;
QMetaObject *meta = object->metaObject();
QStrList l = meta->slotNames(true);
if(l.find(slotName) == -1)
return;
connect(this, SIGNAL( editSignal() ), object, slot);
emit editSignal();
disconnect(this, SIGNAL(editSignal()), object, slot);
}
////////////////////////////////////////////////////////////////////////////////
// private slot definitions
////////////////////////////////////////////////////////////////////////////////
......@@ -332,6 +353,35 @@ void JuK::updatePlaylistInfo()
statusLabel->setPlaylistInfo(splitter->selectedPlaylistName(), splitter->selectedPlaylistCount());
}
////////////////////////////////////////////////////////////////////////////////
// edit menu
////////////////////////////////////////////////////////////////////////////////
void JuK::cut()
{
invokeEditSlot("cut()", SLOT(cut()));
}
void JuK::copy()
{
invokeEditSlot("copy()", SLOT(copy()));
}
void JuK::paste()
{
invokeEditSlot("paste()", SLOT(paste()));
}
void JuK::clear()
{
invokeEditSlot("clear()", SLOT(clear()));
}
void JuK::selectAll()
{
invokeEditSlot("selectAll()", SLOT(selectAll()));
}
////////////////////////////////////////////////////////////////////////////////
// player menu
////////////////////////////////////////////////////////////////////////////////
......
......@@ -46,6 +46,9 @@ public:
JuK(QWidget* parent = 0, const char *name = 0);
virtual ~JuK();
signals:
void editSignal();
private:
// private methods
void setupLayout();
......@@ -65,12 +68,20 @@ private:
virtual bool queryClose();
void invokeEditSlot(const char *slotName, const char *slot);
private slots:
void playlistChanged();
void updatePlaylistInfo();
// edit menu
void cut() { splitter->copy(); splitter->clear(); }
void cut();
void copy();
void paste();
void clear();
void selectAll();
private slots:
// player menu
void play();
......
......@@ -21,6 +21,9 @@
<Action name="file_quit"/>
</Menu>
<Menu name="edit"><text>&amp;Edit</text>
<Action name="clear"/>
</Menu>
<Menu name="view" noMerge="1"><text>&amp;View</text>
<Action name="showEditor"/>
......
......@@ -31,6 +31,7 @@
#include <qtimer.h>
#include <qapplication.h>
#include <qptrlist.h>
#include <qclipboard.h>
#include <stdlib.h>
#include <time.h>
......@@ -269,11 +270,26 @@ void Playlist::setName(const QString &n)
emit(nameChanged(playlistName));
}
void Playlist::copy()
{
kapp->clipboard()->setData(dragObject(0), QClipboard::Clipboard);
}
void Playlist::paste()
{
decode(kapp->clipboard()->data());
}
void Playlist::clear()
{
clearItems(selectedItems());
}
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////
QDragObject *Playlist::dragObject()
QDragObject *Playlist::dragObject(QWidget *parent)
{
PlaylistItemList items = selectedItems();
KURL::List urls;
......@@ -283,12 +299,33 @@ QDragObject *Playlist::dragObject()
urls.append(url);
}
KURLDrag *drag = new KURLDrag(urls, this, "Playlist Items");
KURLDrag *drag = new KURLDrag(urls, parent, "Playlist Items");
drag->setPixmap(SmallIcon("sound"));
return drag;
}
QDragObject *Playlist::dragObject()
{
return dragObject(this);
}
void Playlist::decode(QMimeSource *s)
{
KURL::List urls;
if(!KURLDrag::decode(s, urls) || urls.isEmpty())
return;
QStringList fileList;
for(KURL::List::Iterator it = urls.begin(); it != urls.end(); it++)
fileList.append((*it).path());
if(splitter)
splitter->add(fileList, this);
}
void Playlist::contentsDropEvent(QDropEvent *e)
{
QListViewItem *moveAfter = itemAt(e->pos());
......@@ -306,20 +343,8 @@ void Playlist::contentsDropEvent(QDropEvent *e)
moveAfter = *it;
}
}
else {
KURL::List urls;
if(KURLDrag::decode(e, urls) && !urls.isEmpty()) {
QStringList fileList;
for(KURL::List::Iterator it = urls.begin(); it != urls.end(); it++)
fileList.append((*it).path());
if(splitter)
splitter->add(fileList, this);
}
}
else
decode(e);
}
void Playlist::contentsDragMoveEvent(QDragMoveEvent *e)
......
......@@ -126,8 +126,16 @@ public slots:
*/
void removeSelectedItems() { remove(selectedItems()); };
void copy();
void clear();
void cut() { copy(); clear(); }
void paste();
void selectAll() { KListView::selectAll(true); }
protected:
virtual QDragObject *dragObject(QWidget *parent);
virtual QDragObject *dragObject();
virtual void decode(QMimeSource *s);
virtual void contentsDropEvent(QDropEvent *e);
virtual void contentsDragMoveEvent(QDragMoveEvent *e);
PlaylistSplitter *playlistSplitter() const { return splitter; }
......
......@@ -19,11 +19,13 @@
#include <kurldrag.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <kapplication.h>
#include <kdebug.h>
#include <qfile.h>
#include <qdrawutil.h>
#include <qinputdialog.h>
#include <qclipboard.h>
#include "playlist.h"
#include "playlistbox.h"
......@@ -186,6 +188,12 @@ void PlaylistBox::deleteItem(PlaylistBoxItem *item)
delete item;
}
void PlaylistBox::paste()
{
PlaylistBoxItem *i = static_cast<PlaylistBoxItem *>(selectedItem());
decode(kapp->clipboard()->data(), i);
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox private methods
////////////////////////////////////////////////////////////////////////////////
......@@ -197,24 +205,30 @@ void PlaylistBox::resizeEvent(QResizeEvent *e)
KListBox::resizeEvent(e);
}
void PlaylistBox::dropEvent(QDropEvent *e)
void PlaylistBox::decode(QMimeSource *s, PlaylistBoxItem *item)
{
if(!s || !item || !item->playlist())
return;
KURL::List urls;
if(KURLDrag::decode(e, urls) && !urls.isEmpty()) {
if(KURLDrag::decode(s, urls) && !urls.isEmpty()) {
QStringList files;
for(KURL::List::Iterator it = urls.begin(); it != urls.end(); it++)
files.append((*it).path());
PlaylistBoxItem *i = static_cast<PlaylistBoxItem *>(itemAt(e->pos()));
if(i && i->playlist())
splitter->add(files, i->playlist());
splitter->add(files, item->playlist());
}
}
void PlaylistBox::dropEvent(QDropEvent *e)
{
PlaylistBoxItem *i = static_cast<PlaylistBoxItem *>(itemAt(e->pos()));
decode(e, i);
}
void PlaylistBox::dragMoveEvent(QDragMoveEvent *e)
{
// If we can decode the input source, there is a non-null item at the "move"
......
......@@ -60,12 +60,16 @@ public slots:
void deleteItem();
void deleteItem(PlaylistBoxItem *item);
void paste();
void clear() {}
signals:
void currentChanged(PlaylistBoxItem *);
void doubleClicked();
private:
virtual void resizeEvent(QResizeEvent *e);
virtual void decode(QMimeSource *s, PlaylistBoxItem *item);
virtual void dropEvent(QDropEvent *e);
virtual void dragMoveEvent(QDragMoveEvent *e);
virtual void mousePressEvent(QMouseEvent *e);
......
......@@ -175,12 +175,6 @@ public slots:
*/
void saveItem() { editor->save(); }
// Edit slots
void copy() {}
void paste() {}
void clear() { clearSelectedItems(); }
// Playlist slots
/**
......@@ -217,11 +211,6 @@ public slots:
*/
void clearSelectedItems();
/**
* Select (or deselect) all of the items in the currently visible playlist.
*/
void selectAll(bool select = true) { visiblePlaylist()->selectAll(select); }
/**
* Show or hide the editor.
*/
......
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