diff options
author | Tim E. Real <termtech@rogers.com> | 2010-12-04 01:43:20 +0000 |
---|---|---|
committer | Tim E. Real <termtech@rogers.com> | 2010-12-04 01:43:20 +0000 |
commit | 6154806a2ceb84ef5b14d763afa0c48da085f8ec (patch) | |
tree | 297a7787ffc71b6760dba80593c044854e9e69b0 /muse2/muse | |
parent | cac5fa2640723963b5a4ec7649cdc5dc8fd966ec (diff) |
Ported all copy/paste/drag/drop coding. Fixed arranger menu cut/copy enable.
Diffstat (limited to 'muse2/muse')
-rw-r--r-- | muse2/muse/app.cpp | 51 | ||||
-rw-r--r-- | muse2/muse/arranger/arranger.h | 1 | ||||
-rw-r--r-- | muse2/muse/arranger/pcanvas.cpp | 312 | ||||
-rw-r--r-- | muse2/muse/globals.cpp | 3 | ||||
-rw-r--r-- | muse2/muse/globals.h | 3 | ||||
-rw-r--r-- | muse2/muse/midiedit/dcanvas.cpp | 90 | ||||
-rw-r--r-- | muse2/muse/midiedit/dcanvas.h | 5 | ||||
-rw-r--r-- | muse2/muse/midiedit/drumedit.cpp | 12 | ||||
-rw-r--r-- | muse2/muse/midiedit/ecanvas.cpp | 185 | ||||
-rw-r--r-- | muse2/muse/midiedit/ecanvas.h | 8 | ||||
-rw-r--r-- | muse2/muse/midiedit/pianoroll.cpp | 18 | ||||
-rw-r--r-- | muse2/muse/midiedit/prcanvas.cpp | 110 | ||||
-rw-r--r-- | muse2/muse/midiedit/prcanvas.h | 5 | ||||
-rw-r--r-- | muse2/muse/mixer/rack.cpp | 104 | ||||
-rw-r--r-- | muse2/muse/mixer/rack.h | 1 |
15 files changed, 593 insertions, 315 deletions
diff --git a/muse2/muse/app.cpp b/muse2/muse/app.cpp index 5cc131b8..e589e855 100644 --- a/muse2/muse/app.cpp +++ b/muse2/muse/app.cpp @@ -3546,15 +3546,19 @@ class MuseApplication : public QApplication { bool flag = QApplication::notify(receiver, event); if (event->type() == QEvent::KeyPress) { QKeyEvent* ke = (QKeyEvent*)event; - globalKeyState = ke->stateAfter(); + ///globalKeyState = ke->stateAfter(); + globalKeyState = ke->modifiers(); bool accepted = ke->isAccepted(); if (!accepted) { int key = ke->key(); - if (ke->state() & Qt::ShiftModifier) + ///if (ke->state() & Qt::ShiftModifier) + if (globalKeyState & Qt::ShiftModifier) key += Qt::SHIFT; - if (ke->state() & Qt::AltModifier) + ///if (ke->state() & Qt::AltModifier) + if (globalKeyState & Qt::AltModifier) key += Qt::ALT; - if (ke->state() & Qt::ControlModifier) + ///if (ke->state() & Qt::ControlModifier) + if (globalKeyState & Qt::ControlModifier) key+= Qt::CTRL; muse->kbAccel(key); return true; @@ -3562,7 +3566,8 @@ class MuseApplication : public QApplication { } if (event->type() == QEvent::KeyRelease) { QKeyEvent* ke = (QKeyEvent*)event; - globalKeyState = ke->stateAfter(); + ///globalKeyState = ke->stateAfter(); + globalKeyState = ke->modifiers(); } return flag; @@ -3892,8 +3897,8 @@ int main(int argc, char* argv[]) initIcons(); initMetronome(); - //QApplication::clipboard()->setSelectionMode(false); ddskrjo - + + //QApplication::clipboard()->setSelectionMode(false); ddskrjo obsolete even in Qt3 QApplication::addLibraryPath(museGlobalLib + "/qtplugins"); if (debugMsg) { @@ -4101,6 +4106,7 @@ void MusE::cmd(int cmd) void MusE::clipboardChanged() { +/* //Q3CString subtype("partlist"); //QString subtype("partlist"); QMimeSource* ms = QApplication::clipboard()->data(QClipboard::Clipboard); @@ -4117,11 +4123,25 @@ void MusE::clipboardChanged() break; } } - menuEdit->setItemEnabled(CMD_PASTE, flag); - menuEdit->setItemEnabled(CMD_INSERT, flag); - menuEdit->setItemEnabled(CMD_PASTE_CLONE, flag); - menuEdit->setItemEnabled(CMD_PASTE_TO_TRACK, flag); - menuEdit->setItemEnabled(CMD_PASTE_CLONE_TO_TRACK, flag); +*/ + + bool flag = false; + if(QApplication::clipboard()->mimeData()->hasFormat(QString("text/x-muse-midipartlist")) || + QApplication::clipboard()->mimeData()->hasFormat(QString("text/x-muse-wavepartlist")) || + QApplication::clipboard()->mimeData()->hasFormat(QString("text/x-muse-mixedpartlist"))) + flag = true; + + //bool flag = false; + //if(!QApplication::clipboard()->text(QString("x-muse-midipartlist"), QClipboard::Clipboard).isEmpty() || + // !QApplication::clipboard()->text(QString("x-muse-wavepartlist"), QClipboard::Clipboard).isEmpty() || + // !QApplication::clipboard()->text(QString("x-muse-mixedpartlist"), QClipboard::Clipboard).isEmpty()) + // flag = true; + + editPasteAction->setEnabled(flag); + editInsertAction->setEnabled(flag); + editPasteCloneAction->setEnabled(flag); + editPaste2TrackAction->setEnabled(flag); + editPasteC2TAction->setEnabled(flag); } //--------------------------------------------------------- @@ -4130,9 +4150,10 @@ void MusE::clipboardChanged() void MusE::selectionChanged() { - bool flag = arranger->isSingleSelection(); - menuEdit->setItemEnabled(CMD_CUT, flag); - //menuEdit->setItemEnabled(CMD_COPY, flag); // Now possible + //bool flag = arranger->isSingleSelection(); // -- Hmm, why only single? + bool flag = arranger->selectionSize() > 0; // -- Test OK cut and copy. For muse2. Tim. + editCutAction->setEnabled(flag); + editCopyAction->setEnabled(flag); } //--------------------------------------------------------- diff --git a/muse2/muse/arranger/arranger.h b/muse2/muse/arranger/arranger.h index f8c0bd3b..439f55fc 100644 --- a/muse2/muse/arranger/arranger.h +++ b/muse2/muse/arranger/arranger.h @@ -204,6 +204,7 @@ class Arranger : public QWidget { Track* curTrack() const { return selected; } void cmd(int); bool isSingleSelection() { return canvas->isSingleSelection(); } + int selectionSize() { return canvas->selectionSize(); } void setGlobalTempo(int); void clear(); diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index 6fbc32af..49d756d9 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -19,10 +19,12 @@ #include <qpoint.h> #include <qlineedit.h> #include <qmessagebox.h> -#include <q3dragobject.h> -#include <q3popupmenu.h> -#include <q3url.h> #include <qmenudata.h> + +#include <QByteArray> +#include <QMimeData> +#include <QDrag> + //Added by qt3to4: #include <QDragLeaveEvent> #include <QMouseEvent> @@ -31,7 +33,6 @@ #include <QEvent> #include <QDropEvent> #include <QDragMoveEvent> -#include <Q3CString> #include "widgets/tools.h" #include "pcanvas.h" @@ -753,8 +754,8 @@ QMenu* PartCanvas::genItemPopup(CItem* item) partPopup->addMenu(colorPopup); // part color selection - const QFontMetrics& fm = colorPopup->fontMetrics(); - int h = fm.lineSpacing(); + //const QFontMetrics& fm = colorPopup->fontMetrics(); + //int h = fm.lineSpacing(); for (int i = 0; i < NUM_PARTCOLORS; ++i) { //ColorListItem* item = new ColorListItem(config.partColors[i], h, fontMetrics().height(), partColorNames[i]); //ddskrjo @@ -1837,19 +1838,22 @@ void PartCanvas::copy(PartList* pl) char* fbuf = (char*)mmap(0, n+1, PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(tmp), 0); fbuf[n] = 0; - Q3TextDrag* drag = new Q3TextDrag(QString(fbuf)); - // Changed by T356. Support mixed .mpt files. - //drag->setSubtype(QCString(isWave ? "wavepartlist" : "midipartlist")); + + QByteArray data(fbuf); + QMimeData* md = new QMimeData(); + + if(midi && wave) - drag->setSubtype(Q3CString("mixedpartlist")); + md->setData("text/x-muse-mixedpartlist", data); // By T356. Support mixed .mpt files. else if(midi) - drag->setSubtype(Q3CString("midipartlist")); + md->setData("text/x-muse-midipartlist", data); else if(wave) - drag->setSubtype(Q3CString("wavepartlist")); + md->setData("text/x-muse-wavepartlist", data); - QApplication::clipboard()->setData(drag, QClipboard::Clipboard); + QApplication::clipboard()->setMimeData(md, QClipboard::Clipboard); + munmap(fbuf, n); fclose(tmp); } @@ -2382,53 +2386,56 @@ void PartCanvas::paste(bool clone, bool toTrack, bool doInsert) } QClipboard* cb = QApplication::clipboard(); - QMimeSource* ms = cb->data(QClipboard::Clipboard); - - bool midiPart = false; - bool wavePart = false; - - // If we want to paste to a selected track... - if(toTrack) + const QMimeData* md = cb->mimeData(QClipboard::Clipboard); + + QString pfx("text/"); + QString mdpl("x-muse-midipartlist"); + QString wvpl("x-muse-wavepartlist"); + QString mxpl("x-muse-mixedpartlist"); + QString txt; + + if(md->hasFormat(pfx + mdpl)) { - for (int i = 0; const char* format = ms->format(i); ++i) { - format = ms->format(i); - if (strcmp(format, "text/midipartlist") == 0) { - if (!track->isMidiTrack()) { - QMessageBox::critical(this, QString("MusE"), - tr("Can only paste to midi/drum track")); - return; - } - midiPart = true; - } - else if (strcmp(format, "text/wavepartlist") == 0) { - if (track->type() != Track::WAVE) { - QMessageBox::critical(this, QString("MusE"), - tr("Can only paste to wave track")); - return; - } - wavePart = true; - } - // Added by T356. Support mixed .mpt files. - else if (strcmp(format, "text/mixedpartlist") == 0) { - if (!track->isMidiTrack() && track->type() != Track::WAVE) { - QMessageBox::critical(this, QString("MusE"), - tr("Can only paste to midi or wave track")); - return; - } - midiPart = true; - wavePart = true; - } - } - - if (!(midiPart || wavePart)) { - QMessageBox::critical(this, QString("MusE"), - tr("Cannot paste: wrong data type")); - return; - } - } - - QString subtype = 0; - QString txt = cb->text(subtype); + // If we want to paste to a selected track... + if(toTrack && !track->isMidiTrack()) + { + QMessageBox::critical(this, QString("MusE"), + tr("Can only paste to midi/drum track")); + return; + } + txt = cb->text(mdpl, QClipboard::Clipboard); + } + else + if(md->hasFormat(pfx + wvpl)) + { + // If we want to paste to a selected track... + if(toTrack && track->type() != Track::WAVE) + { + QMessageBox::critical(this, QString("MusE"), + tr("Can only paste to wave track")); + return; + } + txt = cb->text(wvpl, QClipboard::Clipboard); + } + else + if(md->hasFormat(pfx + mxpl)) + { + // If we want to paste to a selected track... + if(toTrack && !track->isMidiTrack() && track->type() != Track::WAVE) + { + QMessageBox::critical(this, QString("MusE"), + tr("Can only paste to midi or wave track")); + return; + } + txt = cb->text(mxpl, QClipboard::Clipboard); + } + else + { + QMessageBox::critical(this, QString("MusE"), + tr("Cannot paste: wrong data type")); + return; + } + int endPos=0; int startPos=song->vcpos(); if (!txt.isEmpty()) @@ -2439,7 +2446,6 @@ void PartCanvas::paste(bool clone, bool toTrack, bool doInsert) song->setPos(0, p); if (!doInsert) song->endUndo(SC_PART_INSERTED); - } if (doInsert) { @@ -2524,12 +2530,23 @@ void PartCanvas::startDrag(CItem* item, DragType t) char* fbuf = (char*)mmap(0, n, PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(tmp), 0); fbuf[n] = 0; - Q3TextDrag* drag = new Q3TextDrag(QString(fbuf), this); - drag->setSubtype("partlist"); + + QByteArray data(fbuf); + QMimeData* md = new QMimeData(); + + md->setData("text/x-muse-partlist", data); + + // "Note that setMimeData() assigns ownership of the QMimeData object to the QDrag object. + // The QDrag must be constructed on the heap with a parent QWidget to ensure that Qt can + // clean up after the drag and drop operation has been completed. " + QDrag* drag = new QDrag(this); + drag->setMimeData(md); + if (t == MOVE_COPY || t == MOVE_CLONE) - drag->dragCopy(); + drag->exec(Qt::CopyAction); else - drag->dragMove(); + drag->exec(Qt::MoveAction); + munmap(fbuf, n); fclose(tmp); } @@ -2540,7 +2557,8 @@ void PartCanvas::startDrag(CItem* item, DragType t) void PartCanvas::dragEnterEvent(QDragEnterEvent* event) { - event->accept(Q3TextDrag::canDecode(event)); + ///event->accept(Q3TextDrag::canDecode(event)); + event->acceptProposedAction(); // TODO CHECK Tim. } //--------------------------------------------------------- @@ -2550,6 +2568,7 @@ void PartCanvas::dragEnterEvent(QDragEnterEvent* event) void PartCanvas::dragMoveEvent(QDragMoveEvent*) { // printf("drag move %x\n", this); + //event->acceptProposedAction(); } //--------------------------------------------------------- @@ -2559,6 +2578,7 @@ void PartCanvas::dragMoveEvent(QDragMoveEvent*) void PartCanvas::dragLeaveEvent(QDragLeaveEvent*) { // printf("drag leave\n"); + //event->acceptProposedAction(); } //--------------------------------------------------------- @@ -2569,30 +2589,26 @@ void PartCanvas::viewDropEvent(QDropEvent* event) { //printf("void PartCanvas::viewDropEvent(QDropEvent* event)\n"); if (event->source() == this) { - printf("no local DROP\n"); + printf("local DROP\n"); // REMOVE Tim + //event->ignore(); // TODO CHECK Tim. return; } int type = 0; // 0 = unknown, 1 = partlist, 2 = uri-list QString text; - for (int i = 0; ; ++i) { - const char* p= event->format(i); - if (p == 0) - break; - if (strncmp(p, "text/partlist", 13) == 0) { - type = 1; - break; - } - else if (strcmp(p, "text/uri-list") == 0) { - type = 2; - break; - } - else { - if (debugMsg) - printf("unknown drop format <%s>\n", p); - } - } - if (type == 0) - return; + + if(event->mimeData()->hasFormat("text/partlist")) + type = 1; + else + //if(event->mimeData()->hasFormat("text/uri-list")) + if(event->mimeData()->hasUrls()) + type = 2; + else + { + if(debugMsg && event->mimeData()->formats().size() != 0) + printf("Drop with unknown format. First format:<%s>\n", event->mimeData()->formats()[0].toLatin1().data()); + //event->ignore(); // TODO CHECK Tim. + return; + } // Make a backup of the current clone list, to retain any 'copy' items, // so that pasting works properly after. @@ -2601,66 +2617,70 @@ void PartCanvas::viewDropEvent(QDropEvent* event) // current non-original parts. cloneList.clear(); - if (Q3TextDrag::decode(event, text)) { - if (type == 1) { - int x = sigmap.raster(event->pos().x(), *_raster); - if (x < 0) - x = 0; - unsigned trackNo = y2pitch(event->pos().y()); - Track* track = 0; - if (trackNo < tracks->size()) - track = tracks->index(trackNo); - if (track) { - song->startUndo(); - pasteAt(text, track, x); - song->endUndo(SC_PART_INSERTED); - } - } - else if (type == 2) { - text = text.stripWhiteSpace(); - if (text.endsWith(".wav",false) || text.endsWith(".ogg",false) || text.endsWith(".mpt", false) ) - { - int x = sigmap.raster(event->pos().x(), *_raster); - if (x < 0) - x = 0; - unsigned trackNo = y2pitch(event->pos().y()); - Track* track = 0; - if (trackNo < tracks->size()) - track = tracks->index(trackNo); - if (track) - { - Q3Url url(text); - QString newPath = url.path(); - if (track->type() == Track::WAVE && (text.endsWith(".wav", false) || (text.endsWith(".ogg", false)))) - { - unsigned tick = x; - muse->importWaveToTrack(newPath, tick, track); - } - // Changed by T356. Support mixed .mpt files. - //else if ((track->type() == Track::MIDI || track->type() == Track::DRUM) && text.endsWith(".mpt", false)) - else if ((track->isMidiTrack() || track->type() == Track::WAVE) && text.endsWith(".mpt", false)) - { - unsigned tick = x; - muse->importPartToTrack(newPath, tick, track); - } - } - } - else if(text.endsWith(".med",false)) - { - Q3Url url(text); - emit dropSongFile(url.path()); - } - else if(text.endsWith(".mid",false)) - { - Q3Url url(text); - emit dropMidiFile(url.path()); - } - else - { - printf("dropped... something... no hable...\n"); - } - } + if (type == 1) + { + text = QString(event->mimeData()->data("text/partlist")); + + int x = sigmap.raster(event->pos().x(), *_raster); + if (x < 0) + x = 0; + unsigned trackNo = y2pitch(event->pos().y()); + Track* track = 0; + if (trackNo < tracks->size()) + track = tracks->index(trackNo); + if (track) { + song->startUndo(); + pasteAt(text, track, x); + song->endUndo(SC_PART_INSERTED); + } + } + else if (type == 2) + { + // Multiple urls not supported here. Grab the first one. + text = event->mimeData()->urls()[0].path(); + + if (text.endsWith(".wav",Qt::CaseInsensitive) || + text.endsWith(".ogg",Qt::CaseInsensitive) || + text.endsWith(".mpt", Qt::CaseInsensitive) ) + { + int x = sigmap.raster(event->pos().x(), *_raster); + if (x < 0) + x = 0; + unsigned trackNo = y2pitch(event->pos().y()); + Track* track = 0; + if (trackNo < tracks->size()) + track = tracks->index(trackNo); + if (track) + { + if (track->type() == Track::WAVE && + (text.endsWith(".wav", Qt::CaseInsensitive) || + (text.endsWith(".ogg", Qt::CaseInsensitive)))) + { + unsigned tick = x; + muse->importWaveToTrack(text, tick, track); + } + // Changed by T356. Support mixed .mpt files. + else if ((track->isMidiTrack() || track->type() == Track::WAVE) && text.endsWith(".mpt", Qt::CaseInsensitive)) + { + unsigned tick = x; + muse->importPartToTrack(text, tick, track); + } + } } + else if(text.endsWith(".med",Qt::CaseInsensitive)) + { + emit dropSongFile(text); + } + else if(text.endsWith(".mid",Qt::CaseInsensitive)) + { + emit dropMidiFile(text); + } + else + { + printf("dropped... something... no hable...\n"); + } + } + // Restore backup of the clone list, to retain any 'copy' items, // so that pasting works properly after. cloneList.clear(); @@ -2766,7 +2786,7 @@ void PartCanvas::drawCanvas(QPainter& p, const QRect& rect) // drawAudioTrack //--------------------------------------------------------- -void PartCanvas::drawAudioTrack(QPainter& p, const QRect& r, AudioTrack *t) +void PartCanvas::drawAudioTrack(QPainter& p, const QRect& r, AudioTrack* /* t */) { p.setPen(QPen(Qt::black, 2, Qt::SolidLine)); p.setBrush(Qt::gray); @@ -2860,7 +2880,7 @@ void PartCanvas::drawAutomation(QPainter& p, const QRect& r, AudioTrack *t) } -void PartCanvas::controllerChanged(Track *t) +void PartCanvas::controllerChanged(Track* /* t */) { redraw(); } diff --git a/muse2/muse/globals.cpp b/muse2/muse/globals.cpp index 0f89f801..72dd00fb 100644 --- a/muse2/muse/globals.cpp +++ b/muse2/muse/globals.cpp @@ -289,7 +289,8 @@ const QStringList audio_file_pattern = QString("Binary (*.bin);;") + QString("All Files (*)")) ); -Qt::ButtonState globalKeyState; +///Qt::ButtonState globalKeyState; +Qt::KeyboardModifiers globalKeyState; // Midi Filter Parameter int midiInputPorts = 0; // receive from all devices diff --git a/muse2/muse/globals.h b/muse2/muse/globals.h index 3901226a..648af514 100644 --- a/muse2/muse/globals.h +++ b/muse2/muse/globals.h @@ -104,7 +104,8 @@ extern const QStringList drum_map_file_pattern; extern const QStringList drum_map_file_save_pattern; extern const QStringList audio_file_pattern; -extern Qt::ButtonState globalKeyState; +///extern Qt::ButtonState globalKeyState; +extern Qt::KeyboardModifiers globalKeyState; extern int midiInputPorts; //!< receive from all devices extern int midiInputChannel; //!< receive all channel diff --git a/muse2/muse/midiedit/dcanvas.cpp b/muse2/muse/midiedit/dcanvas.cpp index 9ad99b0e..17a4ac88 100644 --- a/muse2/muse/midiedit/dcanvas.cpp +++ b/muse2/muse/midiedit/dcanvas.cpp @@ -5,14 +5,14 @@ // (C) Copyright 1999 Werner Schweer (ws@seh.de) //========================================================= -#include <qpainter.h> -#include <qapplication.h> -#include <qclipboard.h> -#include <q3dragobject.h> +#include <QPainter> +#include <QApplication> +#include <QClipboard> +#include <QDrag> + //Added by qt3to4: #include <QDragLeaveEvent> #include <Q3PointArray> -#include <Q3CString> #include <QDragEnterEvent> #include <QDragMoveEvent> #include <QDropEvent> @@ -21,8 +21,8 @@ #include <stdio.h> #include <values.h> #include <errno.h> -#include <sys/stat.h> -#include <sys/mman.h> +//#include <sys/stat.h> +//#include <sys/mman.h> #include "dcanvas.h" #include "midieditor.h" @@ -814,6 +814,7 @@ void DrumCanvas::cmd(int cmd) redraw(); } +/* //--------------------------------------------------------- // getTextDrag //--------------------------------------------------------- @@ -874,6 +875,7 @@ Q3TextDrag* DrumCanvas::getTextDrag(QWidget* parent) fclose(tmp); return drag; } +*/ //--------------------------------------------------------- // copy @@ -882,11 +884,14 @@ Q3TextDrag* DrumCanvas::getTextDrag(QWidget* parent) void DrumCanvas::copy() { - Q3TextDrag* drag = getTextDrag(0); - if (drag) - QApplication::clipboard()->setData(drag, QClipboard::Clipboard); + //QDrag* drag = getTextDrag(); + QMimeData* md = getTextDrag(); + + if (md) + QApplication::clipboard()->setMimeData(md, QClipboard::Clipboard); } +/* //--------------------------------------------------------- // paste //--------------------------------------------------------- @@ -906,7 +911,6 @@ int DrumCanvas::pasteAt(const QString& pt, int pos) switch (token) { case Xml::Error: case Xml::End: - //song->endUndo(SC_EVENT_INSERTED); By T356 song->endUndo(modified); return pos; case Xml::TagStart: @@ -928,7 +932,6 @@ int DrumCanvas::pasteAt(const QString& pt, int pos) Part* newPart = curPart->clone(); newPart->setLenTick(newPart->lenTick()+diff); // Indicate no undo, and do port controller values but not clone parts. - //audio->msgChangePart(curPart, newPart,false); audio->msgChangePart(curPart, newPart, false, true, false); modified=modified|SC_PART_MODIFIED; @@ -936,11 +939,9 @@ int DrumCanvas::pasteAt(const QString& pt, int pos) } // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgAddEvent(e, curPart, false); audio->msgAddEvent(e, curPart, false, false, false); } else - //xml.unknown("EventCanvas::paste"); By T356 xml.unknown("DCanvas::pasteAt"); break; case Xml::TagEnd: @@ -949,6 +950,7 @@ int DrumCanvas::pasteAt(const QString& pt, int pos) } } } +*/ //--------------------------------------------------------- // paste @@ -957,6 +959,7 @@ int DrumCanvas::pasteAt(const QString& pt, int pos) void DrumCanvas::paste() { +/* // Q3CString subtype("eventlist"); // ddskrjo QString subtype("eventlist"); QMimeSource* ms = QApplication::clipboard()->data(); @@ -966,6 +969,13 @@ void DrumCanvas::paste() return; } pasteAt(pt, song->cpos()); +*/ + QString stype("x-muse-eventlist"); + + //QString s = QApplication::clipboard()->text(stype, QClipboard::Selection); + QString s = QApplication::clipboard()->text(stype, QClipboard::Clipboard); // TODO CHECK Tim. + + pasteAt(s, song->cpos()); } //--------------------------------------------------------- @@ -974,14 +984,24 @@ void DrumCanvas::paste() void DrumCanvas::startDrag(CItem* /* item*/, bool copymode) { - Q3TextDrag* drag = getTextDrag(this); - if (drag) { -// QApplication::clipboard()->setData(drag, QClipboard::Clipboard); - + QMimeData* md = getTextDrag(); + //QDrag* drag = getTextDrag(); + + if (md) { +// QApplication::clipboard()->setData(drag, QClipboard::Clipboard); // This line NOT enabled in muse-1 + //QApplication::clipboard()->setMimeData(md); // TODO CHECK Tim. + //QApplication::clipboard()->setMimeData(drag->mimeData()); // + + // "Note that setMimeData() assigns ownership of the QMimeData object to the QDrag object. + // The QDrag must be constructed on the heap with a parent QWidget to ensure that Qt can + // clean up after the drag and drop operation has been completed. " + QDrag* drag = new QDrag(this); + drag->setMimeData(md); + if (copymode) - drag->dragCopy(); + drag->exec(Qt::CopyAction); else - drag->dragMove(); + drag->exec(Qt::MoveAction); } } @@ -991,7 +1011,8 @@ void DrumCanvas::startDrag(CItem* /* item*/, bool copymode) void DrumCanvas::dragEnterEvent(QDragEnterEvent* event) { - event->accept(Q3TextDrag::canDecode(event)); + ///event->accept(Q3TextDrag::canDecode(event)); + event->acceptProposedAction(); // TODO CHECK Tim. } //--------------------------------------------------------- @@ -1000,7 +1021,8 @@ void DrumCanvas::dragEnterEvent(QDragEnterEvent* event) void DrumCanvas::dragMoveEvent(QDragMoveEvent*) { -// printf("drag move %x\n", this); + //printf("drag move %x\n", this); // REMOVE Tim + //event->acceptProposedAction(); } //--------------------------------------------------------- @@ -1009,9 +1031,11 @@ void DrumCanvas::dragMoveEvent(QDragMoveEvent*) void DrumCanvas::dragLeaveEvent(QDragLeaveEvent*) { -// printf("drag leave\n"); + //printf("drag leave\n"); // REMOVE Tim + //event->acceptProposedAction(); } +/* //--------------------------------------------------------- // dropEvent //--------------------------------------------------------- @@ -1020,17 +1044,31 @@ void DrumCanvas::viewDropEvent(QDropEvent* event) { QString text; if (event->source() == this) { - printf("local DROP\n"); + printf("local DROP\n"); // REMOVE Tim + //event->acceptProposedAction(); + //event->ignore(); // TODO CHECK Tim. return; } - if (Q3TextDrag::decode(event, text)) { + //if (event->mimeData()->hasText()) { + if (event->mimeData()->hasFormat("text/x-muse-eventlist")) { + + //text = event->mimeData()->text(); + text = QString(event->mimeData()->data("text/x-muse-eventlist")); + // printf("drop <%s>\n", text.ascii()); int x = editor->rasterVal(event->pos().x()); if (x < 0) x = 0; pasteAt(text, x); + //event->accept(); // TODO + } + else { + printf("cannot decode drop\n"); + //event->acceptProposedAction(); + //event->ignore(); // TODO CHECK Tim. } } +*/ //--------------------------------------------------------- // keyPressed @@ -1286,6 +1324,6 @@ void DrumCanvas::modifySelected(NoteInfo::ValType type, int delta) void DrumCanvas::curPartChanged() { - editor->setCaption(getCaption()); + editor->setWindowTitle(getCaption()); } diff --git a/muse2/muse/midiedit/dcanvas.h b/muse2/muse/midiedit/dcanvas.h index 7f5034fc..2b93ddae 100644 --- a/muse2/muse/midiedit/dcanvas.h +++ b/muse2/muse/midiedit/dcanvas.h @@ -10,7 +10,6 @@ #include "ecanvas.h" #include "song.h" -//Added by qt3to4: #include <QResizeEvent> #include <QDragEnterEvent> #include <QDropEvent> @@ -33,7 +32,6 @@ class DEvent : public CItem { class ScrollScale; class PianoRoll; -class Q3TextDrag; //--------------------------------------------------------- // DrumCanvas @@ -56,15 +54,12 @@ class DrumCanvas : public EventCanvas { int y2pitch(int y) const; int pitch2y(int pitch) const; - Q3TextDrag* getTextDrag(QWidget* parent); void copy(); - int pasteAt(const QString& pt, int pos); void paste(); void startDrag(CItem*, bool copymode); void dragEnterEvent(QDragEnterEvent* event); void dragMoveEvent(QDragMoveEvent*); void dragLeaveEvent(QDragLeaveEvent*); - void viewDropEvent(QDropEvent* event); virtual void addItem(Part*, Event&); virtual void resizeEvent(QResizeEvent*); virtual void curPartChanged(); diff --git a/muse2/muse/midiedit/drumedit.cpp b/muse2/muse/midiedit/drumedit.cpp index b623f56f..44a6682e 100644 --- a/muse2/muse/midiedit/drumedit.cpp +++ b/muse2/muse/midiedit/drumedit.cpp @@ -881,11 +881,7 @@ void DrumEdit::cmd(int cmd) void DrumEdit::clipboardChanged() { - QMimeSource* ms = QApplication::clipboard()->data(QClipboard::Clipboard); - if (ms && ms->format(0)) { - bool flag = strcmp(ms->format(0), "text/eventlist;charset=UTF-8") == 0; - menuEdit->setItemEnabled(DrumCanvas::CMD_PASTE, flag); - } + pasteAction->setEnabled(QApplication::clipboard()->mimeData()->hasFormat(QString("text/x-muse-eventlist"))); } //--------------------------------------------------------- @@ -895,9 +891,9 @@ void DrumEdit::clipboardChanged() void DrumEdit::selectionChanged() { bool flag = canvas->selectionSize() > 0; - menuEdit->setItemEnabled(DrumCanvas::CMD_CUT, flag); - menuEdit->setItemEnabled(DrumCanvas::CMD_COPY, flag); - menuEdit->setItemEnabled(DrumCanvas::CMD_DEL, flag); + cutAction->setEnabled(flag); + copyAction->setEnabled(flag); + deleteAction->setEnabled(flag); } //--------------------------------------------------------- diff --git a/muse2/muse/midiedit/ecanvas.cpp b/muse2/muse/midiedit/ecanvas.cpp index 7fc7002d..c790d8c0 100644 --- a/muse2/muse/midiedit/ecanvas.cpp +++ b/muse2/muse/midiedit/ecanvas.cpp @@ -6,15 +6,23 @@ //========================================================= #include <values.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/mman.h> +#include <QKeyEvent> +#include <QDropEvent> +#include <QEvent> +#include <QMimeData> +#include <QByteArray> +#include <QDrag> +#include "xml.h" #include "midieditor.h" #include "ecanvas.h" #include "song.h" #include "event.h" #include "shortcuts.h" -//Added by qt3to4: -#include <QKeyEvent> -#include <QEvent> +#include "audio.h" //--------------------------------------------------------- // EventCanvas @@ -253,11 +261,14 @@ MidiTrack* EventCanvas::track() const void EventCanvas::keyPress(QKeyEvent* event) { int key = event->key(); - if (event->state() & Qt::ShiftButton) + ///if (event->state() & Qt::ShiftButton) + if (event->modifiers() & Qt::ShiftButton) key += Qt::SHIFT; - if (event->state() & Qt::AltButton) + ///if (event->state() & Qt::AltButton) + if (event->modifiers() & Qt::AltButton) key += Qt::ALT; - if (event->state() & Qt::ControlButton) + ///if (event->state() & Qt::ControlButton) + if (event->modifiers() & Qt::ControlButton) key+= Qt::CTRL; // @@ -361,3 +372,165 @@ void EventCanvas::keyPress(QKeyEvent* event) else event->ignore(); } + +//--------------------------------------------------------- +// getTextDrag +//--------------------------------------------------------- + +//QDrag* EventCanvas::getTextDrag(QWidget* parent) +QMimeData* EventCanvas::getTextDrag() + { + //--------------------------------------------------- + // generate event list from selected events + //--------------------------------------------------- + + EventList el; + unsigned startTick = MAXINT; + for (iCItem i = items.begin(); i != items.end(); ++i) { + if (!i->second->isSelected()) + continue; + ///NEvent* ne = (NEvent*)(i->second); + CItem* ne = i->second; + Event e = ne->event(); + if (startTick == MAXINT) + startTick = e.tick(); + el.add(e); + } + + //--------------------------------------------------- + // write events as XML into tmp file + //--------------------------------------------------- + + FILE* tmp = tmpfile(); + if (tmp == 0) { + fprintf(stderr, "EventCanvas::getTextDrag() fopen failed: %s\n", + strerror(errno)); + return 0; + } + Xml xml(tmp); + + int level = 0; + xml.tag(level++, "eventlist"); + for (ciEvent e = el.begin(); e != el.end(); ++e) + e->second.write(level, xml, -startTick); + xml.etag(--level, "eventlist"); + + //--------------------------------------------------- + // read tmp file into drag Object + //--------------------------------------------------- + + fflush(tmp); + struct stat f_stat; + if (fstat(fileno(tmp), &f_stat) == -1) { + fprintf(stderr, "PianoCanvas::copy() fstat failes:<%s>\n", + strerror(errno)); + fclose(tmp); + return 0; + } + int n = f_stat.st_size; + char* fbuf = (char*)mmap(0, n+1, PROT_READ|PROT_WRITE, + MAP_PRIVATE, fileno(tmp), 0); + fbuf[n] = 0; + + QByteArray data(fbuf); + QMimeData* md = new QMimeData(); + //QDrag* drag = new QDrag(parent); + + md->setData("text/x-muse-eventlist", data); + //drag->setMimeData(md); + + munmap(fbuf, n); + fclose(tmp); + + //return drag; + return md; + } + +//--------------------------------------------------------- +// pasteAt +//--------------------------------------------------------- + +void EventCanvas::pasteAt(const QString& pt, int pos) + { + const char* p = pt.latin1(); + Xml xml(p); + for (;;) { + Xml::Token token = xml.parse(); + const QString& tag = xml.s1(); + switch (token) { + case Xml::Error: + case Xml::End: + return; + case Xml::TagStart: + if (tag == "eventlist") { + song->startUndo(); + EventList* el = new EventList(); + el->read(xml, "eventlist", true); + int modified = SC_EVENT_INSERTED; + for (iEvent i = el->begin(); i != el->end(); ++i) { + Event e = i->second; + int tick = e.tick() + pos - curPart->tick(); + if (tick<0) { + printf("ERROR: trying to add event before current part!\n"); + song->endUndo(SC_EVENT_INSERTED); + delete el; + return; + } + + e.setTick(tick); + int diff = e.endTick()-curPart->lenTick(); + if (diff > 0) {// too short part? extend it + Part* newPart = curPart->clone(); + newPart->setLenTick(newPart->lenTick()+diff); + // Indicate no undo, and do port controller values but not clone parts. + audio->msgChangePart(curPart, newPart, false, true, false); + modified=modified|SC_PART_MODIFIED; + curPart = newPart; // reassign + } + // Indicate no undo, and do not do port controller values and clone parts. + audio->msgAddEvent(e, curPart, false, false, false); + } + song->endUndo(modified); + delete el; + return; + } + else + xml.unknown("pasteAt"); + break; + case Xml::Attribut: + case Xml::TagEnd: + default: + break; + } + } + } + +//--------------------------------------------------------- +// dropEvent +//--------------------------------------------------------- + +void EventCanvas::viewDropEvent(QDropEvent* event) + { + QString text; + if (event->source() == this) { + printf("local DROP\n"); // REMOVE Tim + //event->acceptProposedAction(); + //event->ignore(); // TODO CHECK Tim. + return; + } + if (event->mimeData()->hasFormat("text/x-muse-eventlist")) { + text = QString(event->mimeData()->data("text/x-muse-eventlist")); + + int x = editor->rasterVal(event->pos().x()); + if (x < 0) + x = 0; + pasteAt(text, x); + //event->accept(); // TODO + } + else { + printf("cannot decode drop\n"); + //event->acceptProposedAction(); + //event->ignore(); // TODO CHECK Tim. + } + } + diff --git a/muse2/muse/midiedit/ecanvas.h b/muse2/muse/midiedit/ecanvas.h index 224bd317..461a717a 100644 --- a/muse2/muse/midiedit/ecanvas.h +++ b/muse2/muse/midiedit/ecanvas.h @@ -17,6 +17,10 @@ class MidiPart; class MidiTrack; class MidiEditor; class Part; +class QMimeData; +class QDrag; +class QString; +class QDropEvent; struct PartToChange { @@ -78,6 +82,10 @@ class EventCanvas : public Canvas { void range(int* s, int* e) const { *s = start_tick; *e = end_tick; } void playEvents(bool flag) { _playEvents = flag; } void selectAtTick(unsigned int tick); + //QDrag* getTextDrag(QWidget* parent); + QMimeData* getTextDrag(); + void pasteAt(const QString& pt, int pos); + void viewDropEvent(QDropEvent* event); virtual void modifySelected(NoteInfo::ValType, int) {} virtual void keyPress(QKeyEvent*); }; diff --git a/muse2/muse/midiedit/pianoroll.cpp b/muse2/muse/midiedit/pianoroll.cpp index f4b88e64..2dc1cbde 100644 --- a/muse2/muse/midiedit/pianoroll.cpp +++ b/muse2/muse/midiedit/pianoroll.cpp @@ -1135,23 +1135,7 @@ void PianoRoll::setEventColorMode(int mode) void PianoRoll::clipboardChanged() { - const QMimeData* ms = QApplication::clipboard()->mimeData(QClipboard::Clipboard); - bool flag = false; - if (ms) { - /* - for (int i = 0;; ++i) { - if (ms->format(i) == 0) - break; -// printf("clipboard changed %s\n", ms->format(i)); - flag = strcmp(ms->format(i), "text/eventlist;charset=UTF-8") == 0; - if (flag) - break; - } - */ - - flag = ms->hasFormat("text/eventlist;charset=UTF-8"); - } - editPasteAction->setEnabled(flag); + editPasteAction->setEnabled(QApplication::clipboard()->mimeData()->hasFormat(QString("text/x-muse-eventlist"))); } //--------------------------------------------------------- diff --git a/muse2/muse/midiedit/prcanvas.cpp b/muse2/muse/midiedit/prcanvas.cpp index b9116628..38544f97 100644 --- a/muse2/muse/midiedit/prcanvas.cpp +++ b/muse2/muse/midiedit/prcanvas.cpp @@ -5,14 +5,11 @@ // (C) Copyright 1999-2004 Werner Schweer (ws@seh.de) //========================================================= -#include <qapplication.h> -#include <qclipboard.h> -#include <qpainter.h> -#include <q3dragobject.h> -#include <qmessagebox.h> -//Added by qt3to4: +#include <QApplication> +#include <QClipboard> +#include <QPainter> +#include <QDrag> #include <QDragLeaveEvent> -#include <Q3CString> #include <QDragEnterEvent> #include <QDragMoveEvent> #include <QDropEvent> @@ -22,12 +19,11 @@ #include <stdio.h> #include <math.h> #include <errno.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <fcntl.h> -#include <dirent.h> +//#include <sys/stat.h> +//#include <sys/types.h> +//#include <sys/mman.h> +//#include <fcntl.h> +//#include <dirent.h> #include "xml.h" #include "prcanvas.h" @@ -145,7 +141,7 @@ void PianoCanvas::drawItem(QPainter& p, const CItem* item, QRect r = item->bbox(); if(!virt()) r.moveCenter(map(item->pos())); - r = r.intersect(rect); + r = r.intersected(rect); if(!r.isValid()) return; p.setPen(Qt::black); @@ -226,7 +222,7 @@ void PianoCanvas::drawMoving(QPainter& p, const CItem* item, const QRect& rect) //if(!item->isMoving()) // return; QRect mr = QRect(item->mp().x(), item->mp().y() - item->height()/2, item->width(), item->height()); - mr = mr.intersect(rect); + mr = mr.intersected(rect); if(!mr.isValid()) return; p.setPen(Qt::black); @@ -804,7 +800,8 @@ void drawTickRaster(QPainter& p, int x, int y, int w, int h, int raster) p.drawLine(x, y, x, y2); int z, n; sigmap.timesig(x, z, n); - int q = p.xForm(QPoint(raster, 0)).x() - p.xForm(QPoint(0, 0)).x(); + ///int q = p.xForm(QPoint(raster, 0)).x() - p.xForm(QPoint(0, 0)).x(); + int q = p.combinedTransform().map(QPoint(raster, 0)).x() - p.combinedTransform().map(QPoint(0, 0)).x(); int qq = raster; if (q < 8) // grid too dense qq *= 2; @@ -1265,18 +1262,18 @@ void PianoCanvas::midiNote(int pitch, int velo) if (_midiin && _steprec && curPart && !audio->isPlaying() && velo && pos[0] >= start_tick && pos[0] < end_tick - && !(globalKeyState & Qt::AltButton)) { + && !(globalKeyState & Qt::AltModifier)) { unsigned int len = editor->quant();//prevent compiler warning: comparison singed/unsigned unsigned tick = pos[0]; //CDW unsigned starttick = tick; - if (globalKeyState & Qt::ShiftButton) + if (globalKeyState & Qt::ShiftModifier) tick -= editor->rasterStep(tick); // // extend len of last note? // EventList* events = curPart->events(); - if (globalKeyState & Qt::ControlButton) { + if (globalKeyState & Qt::ControlModifier) { for (iEvent i = events->begin(); i != events->end(); ++i) { Event ev = i->second; if (!ev.isNote()) @@ -1307,7 +1304,7 @@ void PianoCanvas::midiNote(int pitch, int velo) // Indicate do undo, and do not do port controller values and clone parts. //audio->msgDeleteEvent(ev, curPart); audio->msgDeleteEvent(ev, curPart, true, false, false); - if (globalKeyState & Qt::ShiftButton) + if (globalKeyState & Qt::ShiftModifier) tick += editor->rasterStep(tick); return; } @@ -1328,6 +1325,7 @@ void PianoCanvas::midiNote(int pitch, int velo) } } +/* //--------------------------------------------------------- // getTextDrag //--------------------------------------------------------- @@ -1390,6 +1388,7 @@ Q3TextDrag* PianoCanvas::getTextDrag(QWidget* parent) fclose(tmp); return drag; } +*/ //--------------------------------------------------------- // copy @@ -1398,13 +1397,16 @@ Q3TextDrag* PianoCanvas::getTextDrag(QWidget* parent) void PianoCanvas::copy() { - Q3TextDrag* drag = getTextDrag(0); + //QDrag* drag = getTextDrag(); + QMimeData* drag = getTextDrag(); + if (drag) - QApplication::clipboard()->setData(drag, QClipboard::Clipboard); + QApplication::clipboard()->setMimeData(drag, QClipboard::Clipboard); } +/* //--------------------------------------------------------- -// paste +// pasteAt //--------------------------------------------------------- void PianoCanvas::pasteAt(const QString& pt, int pos) @@ -1440,13 +1442,11 @@ void PianoCanvas::pasteAt(const QString& pt, int pos) Part* newPart = curPart->clone(); newPart->setLenTick(newPart->lenTick()+diff); // Indicate no undo, and do port controller values but not clone parts. - //audio->msgChangePart(curPart, newPart,false); audio->msgChangePart(curPart, newPart, false, true, false); modified=modified|SC_PART_MODIFIED; curPart = newPart; // reassign } // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgAddEvent(e, curPart, false); audio->msgAddEvent(e, curPart, false, false, false); } song->endUndo(modified); @@ -1463,6 +1463,8 @@ void PianoCanvas::pasteAt(const QString& pt, int pos) } } } +*/ + //--------------------------------------------------------- // paste // paste events @@ -1470,6 +1472,7 @@ void PianoCanvas::pasteAt(const QString& pt, int pos) void PianoCanvas::paste() { +/* //Q3CString subtype("eventlist"); ddskrjo QString subtype("eventlist"); QMimeSource* ms = QApplication::clipboard()->data(QClipboard::Clipboard); @@ -1479,6 +1482,13 @@ void PianoCanvas::paste() return; } pasteAt(pt, song->cpos()); +*/ + QString stype("x-muse-eventlist"); + + //QString s = QApplication::clipboard()->text(stype, QClipboard::Selection); + QString s = QApplication::clipboard()->text(stype, QClipboard::Clipboard); // TODO CHECK Tim. + + pasteAt(s, song->cpos()); } //--------------------------------------------------------- @@ -1487,14 +1497,24 @@ void PianoCanvas::paste() void PianoCanvas::startDrag(CItem* /* item*/, bool copymode) { - Q3TextDrag* drag = getTextDrag(this); - if (drag) { -// QApplication::clipboard()->setData(drag, QClipboard::Clipboard); - + QMimeData* md = getTextDrag(); + //QDrag* drag = getTextDrag(); + + if (md) { +// QApplication::clipboard()->setData(drag, QClipboard::Clipboard); // This line NOT enabled in muse-1 + //QApplication::clipboard()->setMimeData(md); // TODO CHECK Tim. + //QApplication::clipboard()->setMimeData(drag->mimeData()); // + + // "Note that setMimeData() assigns ownership of the QMimeData object to the QDrag object. + // The QDrag must be constructed on the heap with a parent QWidget to ensure that Qt can + // clean up after the drag and drop operation has been completed. " + QDrag* drag = new QDrag(this); + drag->setMimeData(md); + if (copymode) - drag->dragCopy(); + drag->exec(Qt::CopyAction); else - drag->dragMove(); + drag->exec(Qt::MoveAction); } } @@ -1504,7 +1524,8 @@ void PianoCanvas::startDrag(CItem* /* item*/, bool copymode) void PianoCanvas::dragEnterEvent(QDragEnterEvent* event) { - event->accept(Q3TextDrag::canDecode(event)); + ///event->accept(Q3TextDrag::canDecode(event)); + event->acceptProposedAction(); // TODO CHECK Tim. } //--------------------------------------------------------- @@ -1513,7 +1534,8 @@ void PianoCanvas::dragEnterEvent(QDragEnterEvent* event) void PianoCanvas::dragMoveEvent(QDragMoveEvent*) { -// printf("drag move %x\n", this); + //printf("drag move %x\n", this); + //event->acceptProposedAction(); } //--------------------------------------------------------- @@ -1522,9 +1544,11 @@ void PianoCanvas::dragMoveEvent(QDragMoveEvent*) void PianoCanvas::dragLeaveEvent(QDragLeaveEvent*) { -// printf("drag leave\n"); + //printf("drag leave\n"); + //event->acceptProposedAction(); } +/* //--------------------------------------------------------- // dropEvent //--------------------------------------------------------- @@ -1533,19 +1557,31 @@ void PianoCanvas::viewDropEvent(QDropEvent* event) { QString text; if (event->source() == this) { - printf("local DROP\n"); + printf("local DROP\n"); // REMOVE Tim + //event->acceptProposedAction(); + //event->ignore(); // TODO CHECK Tim. return; } - if (Q3TextDrag::decode(event, text)) { + ///if (Q3TextDrag::decode(event, text)) { + //if (event->mimeData()->hasText()) { + if (event->mimeData()->hasFormat("text/x-muse-eventlist")) { + + //text = event->mimeData()->text(); + text = QString(event->mimeData()->data("text/x-muse-eventlist")); + int x = editor->rasterVal(event->pos().x()); if (x < 0) x = 0; pasteAt(text, x); + //event->accept(); // TODO } else { printf("cannot decode drop\n"); + //event->acceptProposedAction(); + //event->ignore(); // TODO CHECK Tim. } } +*/ //--------------------------------------------------------- // itemPressed @@ -1614,7 +1650,7 @@ void PianoCanvas::itemMoved(const CItem* item, const QPoint& pos) void PianoCanvas::curPartChanged() { - editor->setCaption(getCaption()); + editor->setWindowTitle(getCaption()); } //--------------------------------------------------------- diff --git a/muse2/muse/midiedit/prcanvas.h b/muse2/muse/midiedit/prcanvas.h index 2f50be2e..3a16ef10 100644 --- a/muse2/muse/midiedit/prcanvas.h +++ b/muse2/muse/midiedit/prcanvas.h @@ -10,7 +10,6 @@ #include "ecanvas.h" #include "pianoroll.h" -//Added by qt3to4: #include <QDragEnterEvent> #include <QDropEvent> #include <QMouseEvent> @@ -31,7 +30,6 @@ class NEvent : public CItem { class ScrollScale; class PianoRoll; -class Q3TextDrag; class QRect; //--------------------------------------------------------- @@ -59,7 +57,6 @@ class PianoCanvas : public EventCanvas { virtual void dragEnterEvent(QDragEnterEvent* event); virtual void dragMoveEvent(QDragMoveEvent*); virtual void dragLeaveEvent(QDragLeaveEvent*); - virtual void viewDropEvent(QDropEvent* event); virtual void addItem(Part*, Event&); int y2pitch(int) const; @@ -68,8 +65,6 @@ class PianoCanvas : public EventCanvas { void quantize(int, int, bool); void copy(); void paste(); - void pasteAt(const QString& pt, int pos); - Q3TextDrag* getTextDrag(QWidget*); virtual void itemPressed(const CItem*); virtual void itemReleased(const CItem*, const QPoint&); virtual void itemMoved(const CItem*, const QPoint&); diff --git a/muse2/muse/mixer/rack.cpp b/muse2/muse/mixer/rack.cpp index b59b9439..ead97ae1 100644 --- a/muse2/muse/mixer/rack.cpp +++ b/muse2/muse/mixer/rack.cpp @@ -11,10 +11,11 @@ #include <qpalette.h> #include <qpainter.h> #include <q3popupmenu.h> -#include <q3dragobject.h> #include <qmessagebox.h> -#include <q3url.h> -//Added by qt3to4: + +#include <QByteArray> +#include <QMimeData> +#include <QDrag> #include <QDropEvent> #include <QMouseEvent> #include <QDragEnterEvent> @@ -379,9 +380,16 @@ void EffectRack::startDrag(int idx) QString xmlconf; xml.dump(xmlconf); - Q3TextDrag *drag = new Q3TextDrag(xmlconf, this); - drag->setSubtype("x-muse-plugin"); - drag->drag(); + + QByteArray data(xmlconf.toLatin1().data()); + QMimeData* md = new QMimeData(); + + md->setData("text/x-muse-plugin", data); + + QDrag* drag = new QDrag(this); + drag->setMimeData(md); + + drag->exec(Qt::CopyAction); } void EffectRack::contentsDropEvent(QDropEvent * /*event*/)// prevent of compiler warning: unsued variable @@ -395,7 +403,8 @@ void EffectRack::dropEvent(QDropEvent *event) int idx = index(i); Pipeline* pipe = track->efxPipe(); - if (pipe) { + if (pipe) + { if ((*pipe)[idx] != NULL) { QWidget *sw = event->source(); if(sw) @@ -413,59 +422,58 @@ void EffectRack::dropEvent(QDropEvent *event) return; } } - if(!QMessageBox::question(this, tr("Replace effect"),tr("Do you really want to replace the effect %1?").arg(pipe->name(idx)), - tr("&Yes"), tr("&No"), - QString::null, 0, 1 )) + if(QMessageBox::question(this, tr("Replace effect"),tr("Do you really want to replace the effect %1?").arg(pipe->name(idx)), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { - audio->msgAddPlugin(track, idx, 0); - song->update(SC_RACK); + audio->msgAddPlugin(track, idx, 0); + song->update(SC_RACK); } else { return; } } - if(Q3TextDrag::decode(event, text)) - { - text = text.stripWhiteSpace(); - // Changed by T356. - //if (text.endsWith(".pre", false)) - if (text.endsWith(".pre", false) || text.endsWith(".pre.gz", false) || text.endsWith(".pre.bz2", false)) - { - Q3Url url(text); - QString newPath = url.path(); - - //bool popenFlag = false; - bool popenFlag; - FILE* fp = fileOpen(this, newPath, ".pre", "r", popenFlag, false, false); - - if (fp) { - Xml xml(fp); - initPlugin(xml, idx); - - // Added by T356. - if (popenFlag) - pclose(fp); - else - fclose(fp); - } - } - else if (event->provides("text/x-muse-plugin")) - { - QString outxml; - Q3TextDrag::decode(event, outxml); - Xml xml(outxml); - initPlugin(xml, idx); - } - } - } + + if(event->mimeData()->hasFormat("text/x-muse-plugin")) + { + QString outxml; + Xml xml(event->mimeData()->data("text/x-muse-plugin").data()); + initPlugin(xml, idx); + } + else + if (event->mimeData()->hasUrls()) + { + // Multiple urls not supported here. Grab the first one. + text = event->mimeData()->urls()[0].path(); + + if (text.endsWith(".pre", Qt::CaseInsensitive) || + text.endsWith(".pre.gz", Qt::CaseInsensitive) || + text.endsWith(".pre.bz2", Qt::CaseInsensitive)) + { + //bool popenFlag = false; + bool popenFlag; + FILE* fp = fileOpen(this, text, ".pre", "r", popenFlag, false, false); + if (fp) + { + Xml xml(fp); + initPlugin(xml, idx); + + // Added by T356. + if (popenFlag) + pclose(fp); + else + fclose(fp); + } + } + } + } } void EffectRack::dragEnterEvent(QDragEnterEvent *event) { - event->accept(Q3TextDrag::canDecode(event)); + ///event->accept(Q3TextDrag::canDecode(event)); + event->acceptProposedAction(); // TODO CHECK Tim. } - void EffectRack::contentsDragEnterEvent(QDragEnterEvent * /*event*/)// prevent of compiler warning: unused parameter { } diff --git a/muse2/muse/mixer/rack.h b/muse2/muse/mixer/rack.h index 438bbdb6..f04ce2ed 100644 --- a/muse2/muse/mixer/rack.h +++ b/muse2/muse/mixer/rack.h @@ -10,6 +10,7 @@ #define __RACK_H__ #include <q3listbox.h> +#include <QDragLeaveEvent> //Added by qt3to4: #include <QMouseEvent> #include <QDropEvent> |