summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2009-12-01 10:07:13 +0000
committerdeva <deva>2009-12-01 10:07:13 +0000
commit22db10eed86c90d05ed19446afd0fc007bec0d66 (patch)
treec46d509f88ec633a46baa031f7f23ce21091ecaf
parent40294e22bd61cf7cf851ec6d6c7a41fd78cbdcad (diff)
Hacky editor for changing sample names.
-rw-r--r--dgedit/Makefile.am2
-rw-r--r--dgedit/filelist.cc51
-rw-r--r--dgedit/filelist.h8
-rw-r--r--dgedit/itemeditor.cc40
-rw-r--r--dgedit/itemeditor.h49
5 files changed, 140 insertions, 10 deletions
diff --git a/dgedit/Makefile.am b/dgedit/Makefile.am
index 77f95fe..f054539 100644
--- a/dgedit/Makefile.am
+++ b/dgedit/Makefile.am
@@ -10,6 +10,7 @@ dgedit_SOURCES = $(shell ../tools/MocList cc ) \
audioextractor.cc \
canvas.cc \
filelist.cc \
+ itemeditor.cc \
mainwindow.cc \
samplesorter.cc
@@ -17,6 +18,7 @@ EXTRA_DIST = \
audioextractor.h \
canvas.h \
filelist.h \
+ itemeditor.h \
mainwindow.h \
samplesorter.h
diff --git a/dgedit/filelist.cc b/dgedit/filelist.cc
index c9798ef..29a12c2 100644
--- a/dgedit/filelist.cc
+++ b/dgedit/filelist.cc
@@ -30,6 +30,8 @@
#include <QFileInfo>
#include <QMenu>
+#include "itemeditor.h"
+
FileList::FileList()
{
setContextMenuPolicy(Qt::CustomContextMenu);
@@ -54,9 +56,9 @@ void FileList::addFiles()
QString name = fi.baseName();
QListWidgetItem *item = new QListWidgetItem();
- item->setText(file);
- item->setData(Qt::UserRole, name);
- item->setIcon(QPixmap("icons/file.png"));
+ setItemFile(item, file);
+ setItemName(item, name);
+ setItemMaster(item, false);
addItem(item);
emit fileAdded(file, name);
@@ -67,13 +69,13 @@ void FileList::addFiles()
void FileList::setMasterFile(QListWidgetItem *i)
{
- QString filename = i->text();
+ QString filename = itemFile(i);
for(int idx = 0; idx < count(); idx++) {
- item(idx)->setIcon(QPixmap("icons/file.png"));
+ setItemMaster(item(idx), false);
}
- i->setIcon(QPixmap("icons/master.png"));
+ setItemMaster(i, true);
emit masterFileChanged(filename);
}
@@ -115,8 +117,8 @@ void FileList::setMaster()
void FileList::removeFile()
{
- QString file = activeItem->text();
- QString name = activeItem->data(Qt::UserRole).toString();
+ QString file = itemFile(activeItem);
+ QString name = itemName(activeItem);
printf("Removing: %s\n", file.toStdString().c_str());
delete activeItem;//takeItem(row(activeItem));
@@ -128,4 +130,37 @@ void FileList::removeFile()
void FileList::editName()
{
+ ItemEditor *e = new ItemEditor(activeItem, itemName(activeItem));
+ connect(e, SIGNAL(updateItem(QListWidgetItem *, QString)),
+ this, SLOT(setItemName(QListWidgetItem *, QString)));
+}
+
+
+// Item utility functions.
+QString FileList::itemFile(QListWidgetItem *i)
+{
+ return i->data(Qt::ToolTipRole).toString();
+}
+
+void FileList::setItemFile(QListWidgetItem *i, QString file)
+{
+ i->setData(Qt::ToolTipRole, file);
+ i->setData(Qt::DisplayRole, itemName(i) + "\t" + file);
+}
+
+QString FileList::itemName(QListWidgetItem *i)
+{
+ return i->data(Qt::UserRole).toString();
+}
+
+void FileList::setItemName(QListWidgetItem *i, QString name)
+{
+ i->setData(Qt::UserRole, name);
+ i->setData(Qt::DisplayRole, name + "\t" + itemFile(i));
+}
+
+void FileList::setItemMaster(QListWidgetItem *i, bool master)
+{
+ if(master) i->setIcon(QPixmap("icons/master.png"));
+ else i->setIcon(QPixmap("icons/file.png"));
}
diff --git a/dgedit/filelist.h b/dgedit/filelist.h
index c43fde6..22b702d 100644
--- a/dgedit/filelist.h
+++ b/dgedit/filelist.h
@@ -51,8 +51,14 @@ private slots:
void setMaster();
void removeFile();
void editName();
+ void setItemName(QListWidgetItem *i, QString name);
private:
+ QString itemFile(QListWidgetItem *i);
+ QString itemName(QListWidgetItem *i);
+ void setItemFile(QListWidgetItem *i, QString file);
+ void setItemMaster(QListWidgetItem *i, bool master);
+
void setMasterFile(QListWidgetItem *i);
void createMenus();
@@ -64,6 +70,4 @@ private:
QListWidgetItem *activeItem;
};
-
-
#endif/*__DRUMGIZMO_FILELIST_H__*/
diff --git a/dgedit/itemeditor.cc b/dgedit/itemeditor.cc
new file mode 100644
index 0000000..1925048
--- /dev/null
+++ b/dgedit/itemeditor.cc
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * itemeditor.cc
+ *
+ * Tue Dec 1 11:01:40 CET 2009
+ * Copyright 2009 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "itemeditor.h"
+
+ItemEditor::ItemEditor(QListWidgetItem *i, QString v)
+{
+ this->i = i;
+ setText(v);
+ show();
+}
+
+void ItemEditor::focusOutEvent(QFocusEvent *)
+{
+ emit updateItem(i, text());
+ close();
+}
diff --git a/dgedit/itemeditor.h b/dgedit/itemeditor.h
new file mode 100644
index 0000000..b6b9e33
--- /dev/null
+++ b/dgedit/itemeditor.h
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * itemeditor.h
+ *
+ * Tue Dec 1 11:01:40 CET 2009
+ * Copyright 2009 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_ITEMEDITOR_H__
+#define __DRUMGIZMO_ITEMEDITOR_H__
+
+#include <QLineEdit>
+#include <QString>
+#include <QListWidgetItem>
+
+class ItemEditor : public QLineEdit {
+Q_OBJECT
+public:
+ ItemEditor(QListWidgetItem *i, QString v);
+
+protected:
+ void focusOutEvent(QFocusEvent *);
+
+signals:
+ void updateItem(QListWidgetItem *i, QString v);
+
+private:
+ QListWidgetItem *i;
+};
+
+#endif/*__DRUMGIZMO_ITEMEDITOR_H__*/