From 0bbc2140c46fe314aebd8e1eebd6625f0b6c1687 Mon Sep 17 00:00:00 2001 From: Werner Schweer Date: Tue, 14 Nov 2006 19:10:08 +0000 Subject: listedit stuff --- muse/muse/ctrl.h | 3 +- muse/muse/liste/CMakeLists.txt | 1 + muse/muse/liste/ctrllistedit.cpp | 56 +++++++++++++- muse/muse/liste/ctrllistedit.h | 7 +- muse/muse/liste/listedit.cpp | 161 ++++++++++++++++++++++++++++++--------- muse/muse/liste/listedit.h | 43 ++++++++++- muse/muse/muse.cpp | 2 +- muse/muse/song.cpp | 17 ++++- muse/muse/song.h | 1 + muse/muse/songfile.cpp | 10 +-- muse/muse/track.h | 2 +- 11 files changed, 249 insertions(+), 54 deletions(-) diff --git a/muse/muse/ctrl.h b/muse/muse/ctrl.h index 6a3705f0..3a45bc97 100644 --- a/muse/muse/ctrl.h +++ b/muse/muse/ctrl.h @@ -136,12 +136,11 @@ class CtrlRecList : public std::list { }; typedef CtrlRecList::iterator iCtrlRec; -typedef QMap CTRL; +typedef QMap CTRL; typedef CTRL::iterator iCtrlVal; typedef CTRL::const_iterator ciCtrlVal; - //--------------------------------------------------------- // Ctrl // this is a controller list diff --git a/muse/muse/liste/CMakeLists.txt b/muse/muse/liste/CMakeLists.txt index dc5e769e..a8e5187c 100644 --- a/muse/muse/liste/CMakeLists.txt +++ b/muse/muse/liste/CMakeLists.txt @@ -24,6 +24,7 @@ QT4_WRAP_CPP ( liste_mocs ) QT4_WRAP_UI ( liste_ui_headers + ctrllistedit.ui ) add_library ( liste STATIC diff --git a/muse/muse/liste/ctrllistedit.cpp b/muse/muse/liste/ctrllistedit.cpp index 05563bcf..8fcc34fe 100644 --- a/muse/muse/liste/ctrllistedit.cpp +++ b/muse/muse/liste/ctrllistedit.cpp @@ -19,13 +19,67 @@ //============================================================================= #include "ctrllistedit.h" +#include "ctrl.h" //--------------------------------------------------------- // CtrlListEditor //--------------------------------------------------------- CtrlListEditor::CtrlListEditor(QWidget* parent) - : QWidget(parent) + : ListWidget(parent) { + QWidget* cew = new QWidget; + le.setupUi(cew); + QVBoxLayout* layout = new QVBoxLayout; + layout->addWidget(cew); + setLayout(layout); + le.minValue->setRange(-10000000.0, 100000000.0); + le.maxValue->setRange(-10000000.0, 100000000.0); + le.defaultValue->setRange(-10000000.0, 100000000.0); + le.minValue->setSingleStep(1.0); + le.maxValue->setSingleStep(1.0); + le.defaultValue->setSingleStep(1.0); + } + +//--------------------------------------------------------- +// setup +//--------------------------------------------------------- + +void CtrlListEditor::setup(const ListType& lt) + { + Ctrl* c = lt.ctrl; + le.controllerName->setText(c->name()); + le.discreteCheckBox->setChecked(c->type() & Ctrl::DISCRETE); + le.logarithmicCheckBox->setChecked(c->type() & Ctrl::LOG); + le.floatCheckBox->setChecked(!(c->type() & Ctrl::INT)); + if (c->type() & Ctrl::INT) { + le.minValue->setDecimals(0); + le.minValue->setValue(c->minVal().i); + le.maxValue->setDecimals(0); + le.maxValue->setValue(c->maxVal().i); + le.defaultValue->setDecimals(0); + le.defaultValue->setValue(c->getDefault().i); + } + else { + le.minValue->setDecimals(1); + le.minValue->setValue(c->minVal().f); + le.maxValue->setDecimals(1); + le.maxValue->setValue(c->maxVal().f); + le.defaultValue->setDecimals(1); + le.defaultValue->setValue(c->getDefault().f); + } + le.ctrlList->clear(); + int idx = 0; + for (iCtrlVal i = c->begin(); i != c->end(); ++i, ++idx) { + CVal v = i.value(); + QTreeWidgetItem* item = new QTreeWidgetItem; + item->setText(0, QString("%1").arg(i.key())); + item->setText(1, QString("%1").arg(i.key())); + if (c->type() & Ctrl::INT) + item->setText(2, QString("%1").arg(v.i)); + else + item->setText(2, QString("%1").arg(v.f)); + le.ctrlList->insertTopLevelItem(idx, item); + } } diff --git a/muse/muse/liste/ctrllistedit.h b/muse/muse/liste/ctrllistedit.h index 0966735d..57fd5eac 100644 --- a/muse/muse/liste/ctrllistedit.h +++ b/muse/muse/liste/ctrllistedit.h @@ -21,16 +21,21 @@ #ifndef __CTRLLISTEDIT_H__ #define __CTRLLISTEDIT_H__ +#include "listedit.h" +#include "ui_ctrllistedit.h" //--------------------------------------------------------- // CtrlListEditor //--------------------------------------------------------- -class CtrlListEditor : public QWidget { +class CtrlListEditor : public ListWidget { Q_OBJECT + Ui::CtrlListEdit le; + public: CtrlListEditor(QWidget* parent = 0); + virtual void setup(const ListType&); }; diff --git a/muse/muse/liste/listedit.cpp b/muse/muse/liste/listedit.cpp index 9c06d375..52d8a757 100644 --- a/muse/muse/liste/listedit.cpp +++ b/muse/muse/liste/listedit.cpp @@ -25,21 +25,24 @@ #include "part.h" #include "ctrl.h" +bool ListType::operator==(const ListType& t) const + { + return id == t.id && track == t.track + && part == t.part && ctrl->id() == t.ctrl->id(); + } + //--------------------------------------------------------- // ListEdit //--------------------------------------------------------- ListEdit::ListEdit(QWidget*) - : QWidget(0) + : TopWin() { setWindowTitle(tr("MusE: List Edit")); - QHBoxLayout* hbox = new QHBoxLayout; - setLayout(hbox); - QSplitter* split = new QSplitter; split->setOpaqueResize(true); - hbox->addWidget(split); + setCentralWidget(split); list = new QTreeWidget; list->setColumnCount(1); @@ -82,35 +85,18 @@ void ListEdit::itemChanged(QTreeWidgetItem* i, QTreeWidgetItem*) { if (i == 0) return; - QWidget* ew = ctrlPanel; -#if 0 - Element* el = ((ElementItem*)i)->element(); - setWindowTitle(QString("MuseScore: List Edit: ") + el->name()); - ShowElementBase* ew = 0; - switch (el->type()) { - case PAGE: ew = pagePanel; break; - case SYSTEM: ew = systemPanel; break; - case MEASURE: ew = measurePanel; break; - case CHORD: ew = chordPanel; break; - case NOTE: ew = notePanel; break; - case REST: ew = restPanel; break; - case CLEF: ew = clefPanel; break; - case TIMESIG: ew = timesigPanel; break; - case KEYSIG: ew = keysigPanel; break; - case SEGMENT: ew = segmentView; break; - case HAIRPIN: ew = hairpinView; break; - case BAR_LINE: ew = barLineView; break; - case FINGERING: - case TEXT: - ew = textView; + ListWidget* ew = ctrlPanel; + lt = i->data(0, Qt::UserRole).value(); + switch(lt.id) { + case LIST_TRACK: + break; + case LIST_PART: break; - case ACCIDENTAL: - default: - ew = elementView; + case LIST_CTRL: + ew = ctrlPanel; break; } - ew->setElement(el); -#endif + ew->setup(lt); stack->setCurrentWidget(ew); } @@ -123,37 +109,86 @@ void ListEdit::buildList() list->clear(); TrackList* tl = song->tracks(); int idx = 0; + ListType lt; + for (iTrack i = tl->begin(); i != tl->end(); ++i,++idx) { Track* t = *i; + lt.track = t; QTreeWidgetItem* item = new QTreeWidgetItem; item->setText(0, t->name()); + lt.id = LIST_TRACK; + item->setData(0, Qt::UserRole, QVariant::fromValue(lt)); list->insertTopLevelItem(idx, item); PartList* pl = t->parts(); if (!pl->empty()) { QTreeWidgetItem* pitem = new QTreeWidgetItem(item); + pitem->setFlags(pitem->flags() & ~Qt::ItemIsSelectable); pitem->setText(0, tr("Parts")); - for (iPart i = pl->begin(); i != pl->end(); ++i) { + for (iPart pi = pl->begin(); pi != pl->end(); ++pi) { + lt.id = LIST_PART; + lt.part = pi->second; QTreeWidgetItem* ppitem = new QTreeWidgetItem(pitem); - ppitem->setText(0, i->second->name()); + ppitem->setData(0, Qt::UserRole, QVariant::fromValue(lt)); + ppitem->setText(0, pi->second->name()); } } CtrlList* cl = t->controller(); + lt.part = 0; if (!cl->empty()) { QTreeWidgetItem* citem = new QTreeWidgetItem(item); citem->setText(0, tr("Controller")); - for (iCtrl i = cl->begin(); i != cl->end(); ++i) { + citem->setFlags(citem->flags() & ~Qt::ItemIsSelectable); + for (iCtrl ci = cl->begin(); ci != cl->end(); ++ci) { QTreeWidgetItem* ccitem = new QTreeWidgetItem(citem); - ccitem->setText(0, i->second->name()); + ccitem->setText(0, ci->second->name()); + lt.id = LIST_CTRL; + lt.ctrl = ci->second; + ccitem->setData(0, Qt::UserRole, QVariant::fromValue(lt)); } } } } +//--------------------------------------------------------- +// findItem +//--------------------------------------------------------- + +QTreeWidgetItem* ListEdit::findItem(const ListType& lt, QTreeWidgetItem* item) + { + if (item->flags() & Qt::ItemIsSelectable) { + if (lt == item->data(0, Qt::UserRole).value()) + return item; + } + for (int n = 0; n < item->childCount(); ++n) { + QTreeWidgetItem* i = findItem(lt, item->child(n)); + if (i) + return i; + } + return 0; + } + //--------------------------------------------------------- // selectItem //--------------------------------------------------------- -void ListEdit::selectItem(const AL::Pos&, Track* track, Ctrl*) +void ListEdit::selectItem(const AL::Pos&, Track* track, Part* part, Ctrl* ctrl) + { + stack->setCurrentWidget(ctrlPanel); + if (ctrl) + lt.id = LIST_CTRL; + else if (part) + lt.id = LIST_PART; + else if (track) + lt.id = LIST_TRACK; + else + return; + lt.track = track; + lt.part = part; + lt.ctrl = ctrl; + selectItem(lt); + } + +void ListEdit::selectItem(const ListType& l) { stack->setCurrentWidget(ctrlPanel); buildList(); @@ -163,7 +198,8 @@ void ListEdit::selectItem(const AL::Pos&, Track* track, Ctrl*) printf("MusE::ListEdit: Element not found\n"); break; } - if (item->text(0) == track->name()) { + item = findItem(lt, item); + if (item) { list->setItemExpanded(item, true); list->setCurrentItem(item); list->scrollToItem(item); @@ -172,3 +208,54 @@ void ListEdit::selectItem(const AL::Pos&, Track* track, Ctrl*) } } +//--------------------------------------------------------- +// readStatus +//--------------------------------------------------------- + +void ListEdit::read(QDomNode node) + { + QString trackName; + Track* track = 0; + Part* part = 0; + Ctrl* ctrl = 0; + + for (node = node.firstChild(); !node.isNull(); node = node.nextSibling()) { + QDomElement e = node.toElement(); + QString tag(e.tagName()); + if (tag == "Track") { + track = song->findTrack(e.text()); + if (track == 0) { + printf("MusE::ListEdit::read: track not found\n"); + } + } + else if (tag == "Ctrl") { + int ctrlId = e.text().toInt(); + ctrl = track->getController(ctrlId); + if (ctrl == 0) { + printf("MusE::ListEdit::read: controller not found: track %p\n", track); + printf("MusE::ListEdit::read: controller %d not found\n", ctrlId); + return; + } + } + else + AL::readProperties(this, node); + } + selectItem(AL::Pos(), track, part, ctrl); + } + +//--------------------------------------------------------- +// write +//--------------------------------------------------------- + +void ListEdit::write(Xml& xml) const + { + xml.tag(metaObject()->className()); + xml.writeProperties(this); + + xml.strTag("Track", lt.track->name()); + if (lt.ctrl) { + xml.intTag("Ctrl", lt.ctrl->id()); + } + xml.etag(metaObject()->className()); + } + diff --git a/muse/muse/liste/listedit.h b/muse/muse/liste/listedit.h index e44b3019..e386f49b 100644 --- a/muse/muse/liste/listedit.h +++ b/muse/muse/liste/listedit.h @@ -21,26 +21,63 @@ #ifndef __LISTEDIT_H__ #define __LISTEDIT_H__ +#include "cobject.h" + namespace AL { class Pos; }; class Track; +class Part; class Ctrl; class CtrlListEditor; +//--------------------------------------------------------- +// ListType +//--------------------------------------------------------- + +enum { LIST_TRACK, LIST_PART, LIST_CTRL }; + +struct ListType { + int id; + Track* track; + Part* part; + Ctrl* ctrl; + + bool operator==(const ListType& t) const; + }; + +Q_DECLARE_METATYPE(struct ListType); + +//--------------------------------------------------------- +// ListWidget +// interface class +//--------------------------------------------------------- + +class ListWidget : public QWidget { + Q_OBJECT; + + public: + ListWidget(QWidget* = 0) {} + virtual void setup(const ListType&) = 0; + }; + //--------------------------------------------------------- // ListEdit //--------------------------------------------------------- -class ListEdit : public QWidget { +class ListEdit : public TopWin { Q_OBJECT; + ListType lt; + QStackedWidget* stack; QTreeWidget* list; CtrlListEditor* ctrlPanel; void buildList(); + QTreeWidgetItem* findItem(const ListType& lt, QTreeWidgetItem* item); + void selectItem(const ListType& lt); private slots: void itemChanged(QTreeWidgetItem*, QTreeWidgetItem*); @@ -48,7 +85,9 @@ class ListEdit : public QWidget { public: ListEdit(QWidget* parent = 0); - void selectItem(const AL::Pos&, Track*, Ctrl*); + void selectItem(const AL::Pos&, Track*, Part*, Ctrl*); + virtual void read(QDomNode); + virtual void write(Xml& xml) const; }; #endif diff --git a/muse/muse/muse.cpp b/muse/muse/muse.cpp index e5135990..31fcdc5b 100644 --- a/muse/muse/muse.cpp +++ b/muse/muse/muse.cpp @@ -1562,7 +1562,7 @@ void MusE::showListEditor(const Pos& pos, Track* track, Ctrl* ctrl) { if (listEditor == 0) listEditor = new ListEdit(this); - listEditor->selectItem(pos, track, ctrl); + listEditor->selectItem(pos, track, 0, ctrl); listEditor->show(); } diff --git a/muse/muse/song.cpp b/muse/muse/song.cpp index d74b1f3b..a051d978 100644 --- a/muse/muse/song.cpp +++ b/muse/muse/song.cpp @@ -2230,11 +2230,20 @@ void Song::changeTrackName(Track* t, const QString& s) bool Song::trackExists(Track* t) const { - for (ciTrack it = _tracks.begin(); it != _tracks.end(); ++it) { - if (*it == t) - return true; + return findTrack(t->name()) != 0; + } + +//--------------------------------------------------------- +// findTrack +//--------------------------------------------------------- + +Track* Song::findTrack(const QString& name) const + { + for (int i = 0; i < _tracks.size(); ++i) { + if (_tracks[i]->name() == name) + return _tracks[i]; } - return false; + return 0; } //--------------------------------------------------------- diff --git a/muse/muse/song.h b/muse/muse/song.h index af2e426b..29a5a433 100644 --- a/muse/muse/song.h +++ b/muse/muse/song.h @@ -309,6 +309,7 @@ class Song : public QObject { MidiInPortList* midiInPorts() { return &_midiInPorts; } bool trackExists(Track*) const; + Track* findTrack(const QString& name) const; void removeTrack(Track* track); void removeTrack1(Track* track); diff --git a/muse/muse/songfile.cpp b/muse/muse/songfile.cpp index c8f89e7b..07c6be18 100644 --- a/muse/muse/songfile.cpp +++ b/muse/muse/songfile.cpp @@ -40,6 +40,7 @@ #include "marker/markerview.h" #include "midioutport.h" #include "midiinport.h" +#include "liste/listedit.h" //--------------------------------------------------------- // readPart @@ -101,11 +102,10 @@ void MusE::readToplevels(QDomNode node) drumEditor->show(); pl = new PartList; } - else if (tag == "ListEditor") { -// ListEdit* listEditor = new ListEdit(0, pl); -// listEditor->show(); -// listEditor->readStatus(node.firstChild()); - pl = new PartList; + else if (tag == "ListEdit") { + listEditor = new ListEdit(0); + listEditor->show(); + listEditor->read(node); } else if (tag == "MasterEdit") { MasterEdit* masterEditor = new MasterEdit(); diff --git a/muse/muse/track.h b/muse/muse/track.h index 1953e5a6..84afe3df 100644 --- a/muse/muse/track.h +++ b/muse/muse/track.h @@ -227,7 +227,7 @@ class Track : public QObject { bool locked() const { return _locked; } void setLocked(bool b) { _locked = b; } - const QString name() const { return _name; } + QString name() const { return _name; } virtual void setName(const QString& s); virtual TrackType type() const = 0; -- cgit v1.2.3