# HG changeset patch # User insilmaril # Date 1120807483 0 # Node ID 0f183befd9af728bb873435542273cf9a7d8ac0b # Parent d18eb6939d17d8bfa62234ef52318391662719bf changes for 1.6.9 diff -r d18eb6939d17 -r 0f183befd9af mapeditor.cpp --- a/mapeditor.cpp Fri Jul 08 07:24:43 2005 +0000 +++ b/mapeditor.cpp Fri Jul 08 07:24:43 2005 +0000 @@ -15,6 +15,9 @@ #include #include #include +#include +#include +#include #include #include @@ -139,10 +142,12 @@ /////////////////////////////////////////////////////////////////////// MapEditor::MapEditor( QWidget* parent, bool interactive, const char* name, WFlags f) : - QCanvasView(parent,name,f) + QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0) { //cout << "Constructor ME "<setAcceptDrops(true); + mapCanvas = new QCanvas(1000,800); mapCanvas->setAdvancePeriod(30); @@ -368,6 +373,12 @@ MapEditor::~MapEditor() { + if (imageBuffer) delete imageBuffer; + if (urlOperator) { + urlOperator->stop(); + delete urlOperator; + } + //cout <<"Destructor MapEditor\n"; if (isInteractive) delTmpDirs(); @@ -565,14 +576,33 @@ void MapEditor::saveState() { +<<<<<<< mapeditor.cpp + saveState (CompleteMap,NULL,""); +======= saveState (CompleteMap,NULL,""); } void MapEditor::saveState(LinkableMapObj *undoSel) { saveState (PartOfMap,undoSel,""); +>>>>>>> 1.16 } +<<<<<<< mapeditor.cpp +void MapEditor::saveState(LinkableMapObj *undoSel) +======= +void MapEditor::saveState(const QString & c) +>>>>>>> 1.16 +{ +<<<<<<< mapeditor.cpp + saveState (PartOfMap,undoSel,""); +} +======= + saveState (UndoCommand,NULL,c); +} +>>>>>>> 1.16 + +<<<<<<< mapeditor.cpp void MapEditor::saveState(const QString & c) { saveState (UndoCommand,NULL,c); @@ -586,6 +616,58 @@ backupXML=""; } else if (savemode==PartOfMap && undoSel) +======= +void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom) +{ + if (savemode==UndoCommand) +>>>>>>> 1.16 + { +<<<<<<< mapeditor.cpp + undoCommand="undoPart (\""+undoSel->getSelectString()+"\")"; + backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel); + } else + { + undoCommand="undoMap ()"; + backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL); + } + /* FIXME testing + cout << "ME::saveState()\n"; + cout << " undoCom="<getSelectString()+"\")"; backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel); @@ -627,6 +709,7 @@ else if (c=="select") select (p0); else +>>>>>>> 1.16 { cout << "MapEditor::parseAtom: Error!\n"; cout << " Command unknown: \""<setColorMode (QPrinter::Color); + printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName())); } QRect totalBBox=mapCenter->getTotalBBox(); @@ -1013,6 +1097,9 @@ selection=oldselection; selection->select(); } + + // Save settings in vymrc + settings.writeEntry("/vym/mainwindow/printerName",printer->printerName()); } } @@ -1288,7 +1375,6 @@ if (selection && fromLMO) { - if (typeid(*fromLMO) == typeid(BranchObj) ) { if (typeid(*selection) == typeid(MapCenterObj)) @@ -2436,12 +2522,21 @@ actionEditCopy->setEnabled (true); actionEditCut->setEnabled (true); +<<<<<<< mapeditor.cpp + if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0) + actionEditPaste->setEnabled (true); + else + actionEditPaste->setEnabled (false); + for (a=actionListBranches.first();a;a=actionListBranches.next()) + a->setEnabled(true); +======= if (clipboardME->getMapCenter()->countBranches()>0) actionEditPaste->setEnabled (true); else actionEditPaste->setEnabled (false); for (a=actionListBranches.first();a;a=actionListBranches.next()) a->setEnabled(true); +>>>>>>> 1.16 actionEditDelete->setEnabled (true); actionEditToggleFloatExport->setEnabled (false); switch (selection->getFrameType()) @@ -3374,3 +3469,114 @@ adjustCanvasSize(); } +void +MapEditor::contentsDragEnterEvent(QDragEnterEvent *event) +{ + if (selection && + (typeid(*selection) == typeid(BranchObj)) || + (typeid(*selection) == typeid(MapCenterObj))) { + + // If QImageDrag can decode mime type + if (QImageDrag::canDecode(event)) { + event->accept(); + return; + } + + // If image are drag from firefox + if (event->provides("application/x-moz-file-promise-url") && + event->provides("application/x-moz-nativeimage")) { + event->accept(true); + return; + } + } + + event->ignore(); +} + +void +MapEditor::contentsDropEvent(QDropEvent *event) +{ + + if (event->provides("image/png")) { + QPixmap pix; + if (QImageDrag::decode(event, pix)) { + addFloatImage(pix); + event->accept(); + } else + event->ignore(); + + } else if (event->provides("application/x-moz-file-promise-url") && + event->provides("application/x-moz-nativeimage")) { + + // Contains url to the img src in UTF-16 + QByteArray d = event->encodedData("application/x-moz-file-promise-url"); + QString url = QString((const QChar*)d.data(),d.size()/2); + fetchImage(url); + event->accept(); + } +} + +void +MapEditor::addFloatImage(const QPixmap &img) +{ + if (selection && + (typeid(*selection) == typeid(BranchObj)) || + (typeid(*selection) == typeid(MapCenterObj)) ) + { + BranchObj *bo=((BranchObj*)(selection)); + setChanged(); + saveState(selection); + //QString fn=fd->selectedFile(); + //lastImageDir=fn.left(fn.findRev ("/")); + bo->addFloatImage(); + // FIXME check if load was successful + bo->getLastFloatImage()->load(img); + //bo->getLastFloatImage()->setOriginalFilename(fn); + mapCenter->reposition(); + adjustCanvasSize(); + canvas()->update(); + } +} + + +void +MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/) +{ + if (!imageBuffer) imageBuffer = new QBuffer(); + if (!imageBuffer->isOpen()) { + imageBuffer->open(IO_WriteOnly | IO_Append); + } + imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a)); +} + + +void +MapEditor::imageDataFinished(QNetworkOperation *nop) +{ + imageBuffer->close(); + if (nop->state()==QNetworkProtocol::StDone) { + QPixmap img(imageBuffer->buffer()); + addFloatImage(img); + } + + delete imageBuffer; + imageBuffer = 0; +} + +void +MapEditor::fetchImage(const QString &url) +{ + if (urlOperator) { + urlOperator->stop(); + disconnect(urlOperator); + delete urlOperator; + } + + urlOperator = new QUrlOperator(url); + connect(urlOperator, SIGNAL(finished(QNetworkOperation *)), + this, SLOT(imageDataFinished(QNetworkOperation*))); + + connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)), + this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *))); + urlOperator->get(); +} diff -r d18eb6939d17 -r 0f183befd9af mapeditor.h --- a/mapeditor.h Fri Jul 08 07:24:43 2005 +0000 +++ b/mapeditor.h Fri Jul 08 07:24:43 2005 +0000 @@ -7,10 +7,14 @@ #include #include #include +#include #include "mapcenterobj.h" #include "misc.h" +class QNetworkOperation; +class QUrlOperator; + class MapEditor : public QCanvasView , public xmlObj { Q_OBJECT @@ -31,13 +35,25 @@ // create subdirs in dir QString saveToDir(const QString&,const QString &,bool, const QPoint &,LinkableMapObj*); void saveState(); // save actual state to backup +<<<<<<< mapeditor.h void saveState(LinkableMapObj *); void saveState(const QString &); void saveState(const SaveMode&, LinkableMapObj *, const QString &); void parseAtom(const QString &); -private slots: + void addFloatImage(const QPixmap &img); +======= + void saveState(LinkableMapObj *); + void saveState(const QString &); + void saveState(const SaveMode&, LinkableMapObj *, const QString &); + void parseAtom(const QString &); +>>>>>>> 1.10 + + private slots: void finishedLineEditNoSave(); + void fetchImage(const QString &img); + void imageDataFetched(const QByteArray &, QNetworkOperation *); + void imageDataFinished(QNetworkOperation *); public: bool isDefault(); // false, if map was changed once @@ -153,6 +169,8 @@ virtual void contentsMouseDoubleClickEvent(QMouseEvent*); virtual void contentsMouseMoveEvent(QMouseEvent*); + virtual void contentsDragEnterEvent(QDragEnterEvent *event); + virtual void contentsDropEvent(QDropEvent *event); private: QCanvas* mapCanvas; MapCenterObj* mapCenter; @@ -212,6 +230,11 @@ QPoint exportOffset; // set before export, used in save void resizeEvent( QResizeEvent * ); + + QUrlOperator *urlOperator; + QDataStream *imageData; + QBuffer *imageBuffer; + }; #endif