1.1 --- a/mapeditor.cpp Tue Jun 14 09:41:37 2005 +0000
1.2 +++ b/mapeditor.cpp Fri Jul 08 07:24:43 2005 +0000
1.3 @@ -15,6 +15,9 @@
1.4 #include <qbitmap.h>
1.5 #include <qprocess.h>
1.6 #include <qinputdialog.h>
1.7 +#include <qdragobject.h>
1.8 +#include <qurloperator.h>
1.9 +#include <qnetworkprotocol.h>
1.10
1.11 #include <iostream>
1.12 #include <cstdlib>
1.13 @@ -139,10 +142,12 @@
1.14 ///////////////////////////////////////////////////////////////////////
1.15 MapEditor::MapEditor(
1.16 QWidget* parent, bool interactive, const char* name, WFlags f) :
1.17 - QCanvasView(parent,name,f)
1.18 + QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
1.19 {
1.20 //cout << "Constructor ME "<<this<<endl;
1.21
1.22 + viewport()->setAcceptDrops(true);
1.23 +
1.24 mapCanvas = new QCanvas(1000,800);
1.25 mapCanvas->setAdvancePeriod(30);
1.26
1.27 @@ -368,6 +373,12 @@
1.28
1.29 MapEditor::~MapEditor()
1.30 {
1.31 + if (imageBuffer) delete imageBuffer;
1.32 + if (urlOperator) {
1.33 + urlOperator->stop();
1.34 + delete urlOperator;
1.35 + }
1.36 +
1.37 //cout <<"Destructor MapEditor\n";
1.38 if (isInteractive) delTmpDirs();
1.39
1.40 @@ -565,14 +576,33 @@
1.41
1.42 void MapEditor::saveState()
1.43 {
1.44 +<<<<<<< mapeditor.cpp
1.45 + saveState (CompleteMap,NULL,"");
1.46 +=======
1.47 saveState (CompleteMap,NULL,"");
1.48 }
1.49
1.50 void MapEditor::saveState(LinkableMapObj *undoSel)
1.51 {
1.52 saveState (PartOfMap,undoSel,"");
1.53 +>>>>>>> 1.16
1.54 }
1.55
1.56 +<<<<<<< mapeditor.cpp
1.57 +void MapEditor::saveState(LinkableMapObj *undoSel)
1.58 +=======
1.59 +void MapEditor::saveState(const QString & c)
1.60 +>>>>>>> 1.16
1.61 +{
1.62 +<<<<<<< mapeditor.cpp
1.63 + saveState (PartOfMap,undoSel,"");
1.64 +}
1.65 +=======
1.66 + saveState (UndoCommand,NULL,c);
1.67 +}
1.68 +>>>>>>> 1.16
1.69 +
1.70 +<<<<<<< mapeditor.cpp
1.71 void MapEditor::saveState(const QString & c)
1.72 {
1.73 saveState (UndoCommand,NULL,c);
1.74 @@ -586,6 +616,58 @@
1.75 backupXML="";
1.76 }
1.77 else if (savemode==PartOfMap && undoSel)
1.78 +=======
1.79 +void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom)
1.80 +{
1.81 + if (savemode==UndoCommand)
1.82 +>>>>>>> 1.16
1.83 + {
1.84 +<<<<<<< mapeditor.cpp
1.85 + undoCommand="undoPart (\""+undoSel->getSelectString()+"\")";
1.86 + backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
1.87 + } else
1.88 + {
1.89 + undoCommand="undoMap ()";
1.90 + backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
1.91 + }
1.92 + /* FIXME testing
1.93 + cout << "ME::saveState()\n";
1.94 + cout << " undoCom="<<undoCommand<<endl;
1.95 + */
1.96 +}
1.97 +
1.98 +void MapEditor::parseAtom(const QString &s)
1.99 +{
1.100 + API api;
1.101 + QString c,p,p0;
1.102 + api.parseCommand (s,c,p);
1.103 + api.getString(p,p0);
1.104 + /* FIXME testing
1.105 + cout <<"ME::parseAtom s="<<s<<endl;
1.106 + cout <<"ME::parseAtom c="<<c<<endl;
1.107 + cout <<"ME::parseAtom p="<<p<<endl;
1.108 + */
1.109 +
1.110 + // External commands
1.111 + if (c==QString("moveBranchUp"))
1.112 + moveBranchUp();
1.113 + else if (c=="moveBranchDown")
1.114 + moveBranchDown();
1.115 + else if (c=="setHeading")
1.116 + setHeading (p0);
1.117 + // Internal commands, used for undo etc.
1.118 + else if (c==QString("undoMap"))
1.119 + undoXML("");
1.120 + else if (c==QString("undoPart"))
1.121 + undoXML(p0);
1.122 + else if (c=="select")
1.123 + select (p0);
1.124 + else
1.125 +=======
1.126 + undoCommand=undoCom;
1.127 + backupXML="";
1.128 + }
1.129 + else if (savemode==PartOfMap && undoSel)
1.130 {
1.131 undoCommand="undoPart (\""+undoSel->getSelectString()+"\")";
1.132 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
1.133 @@ -627,6 +709,7 @@
1.134 else if (c=="select")
1.135 select (p0);
1.136 else
1.137 +>>>>>>> 1.16
1.138 {
1.139 cout << "MapEditor::parseAtom: Error!\n";
1.140 cout << " Command unknown: \""<<c<<"\""<<endl;
1.141 @@ -896,6 +979,7 @@
1.142 {
1.143 printer = new QPrinter;
1.144 printer->setColorMode (QPrinter::Color);
1.145 + printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
1.146 }
1.147
1.148 QRect totalBBox=mapCenter->getTotalBBox();
1.149 @@ -1013,6 +1097,9 @@
1.150 selection=oldselection;
1.151 selection->select();
1.152 }
1.153 +
1.154 + // Save settings in vymrc
1.155 + settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1.156 }
1.157 }
1.158
1.159 @@ -1288,7 +1375,6 @@
1.160
1.161 if (selection && fromLMO)
1.162 {
1.163 -
1.164 if (typeid(*fromLMO) == typeid(BranchObj) )
1.165 {
1.166 if (typeid(*selection) == typeid(MapCenterObj))
1.167 @@ -2436,12 +2522,21 @@
1.168
1.169 actionEditCopy->setEnabled (true);
1.170 actionEditCut->setEnabled (true);
1.171 +<<<<<<< mapeditor.cpp
1.172 + if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
1.173 + actionEditPaste->setEnabled (true);
1.174 + else
1.175 + actionEditPaste->setEnabled (false);
1.176 + for (a=actionListBranches.first();a;a=actionListBranches.next())
1.177 + a->setEnabled(true);
1.178 +=======
1.179 if (clipboardME->getMapCenter()->countBranches()>0)
1.180 actionEditPaste->setEnabled (true);
1.181 else
1.182 actionEditPaste->setEnabled (false);
1.183 for (a=actionListBranches.first();a;a=actionListBranches.next())
1.184 a->setEnabled(true);
1.185 +>>>>>>> 1.16
1.186 actionEditDelete->setEnabled (true);
1.187 actionEditToggleFloatExport->setEnabled (false);
1.188 switch (selection->getFrameType())
1.189 @@ -3374,3 +3469,114 @@
1.190 adjustCanvasSize();
1.191 }
1.192
1.193 +void
1.194 +MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
1.195 +{
1.196 + if (selection &&
1.197 + (typeid(*selection) == typeid(BranchObj)) ||
1.198 + (typeid(*selection) == typeid(MapCenterObj))) {
1.199 +
1.200 + // If QImageDrag can decode mime type
1.201 + if (QImageDrag::canDecode(event)) {
1.202 + event->accept();
1.203 + return;
1.204 + }
1.205 +
1.206 + // If image are drag from firefox
1.207 + if (event->provides("application/x-moz-file-promise-url") &&
1.208 + event->provides("application/x-moz-nativeimage")) {
1.209 + event->accept(true);
1.210 + return;
1.211 + }
1.212 + }
1.213 +
1.214 + event->ignore();
1.215 +}
1.216 +
1.217 +void
1.218 +MapEditor::contentsDropEvent(QDropEvent *event)
1.219 +{
1.220 +
1.221 + if (event->provides("image/png")) {
1.222 + QPixmap pix;
1.223 + if (QImageDrag::decode(event, pix)) {
1.224 + addFloatImage(pix);
1.225 + event->accept();
1.226 + } else
1.227 + event->ignore();
1.228 +
1.229 + } else if (event->provides("application/x-moz-file-promise-url") &&
1.230 + event->provides("application/x-moz-nativeimage")) {
1.231 +
1.232 + // Contains url to the img src in UTF-16
1.233 + QByteArray d = event->encodedData("application/x-moz-file-promise-url");
1.234 + QString url = QString((const QChar*)d.data(),d.size()/2);
1.235 + fetchImage(url);
1.236 + event->accept();
1.237 + }
1.238 +}
1.239 +
1.240 +void
1.241 +MapEditor::addFloatImage(const QPixmap &img)
1.242 +{
1.243 + if (selection &&
1.244 + (typeid(*selection) == typeid(BranchObj)) ||
1.245 + (typeid(*selection) == typeid(MapCenterObj)) )
1.246 + {
1.247 + BranchObj *bo=((BranchObj*)(selection));
1.248 + setChanged();
1.249 + saveState(selection);
1.250 + //QString fn=fd->selectedFile();
1.251 + //lastImageDir=fn.left(fn.findRev ("/"));
1.252 + bo->addFloatImage();
1.253 + // FIXME check if load was successful
1.254 + bo->getLastFloatImage()->load(img);
1.255 + //bo->getLastFloatImage()->setOriginalFilename(fn);
1.256 + mapCenter->reposition();
1.257 + adjustCanvasSize();
1.258 + canvas()->update();
1.259 + }
1.260 +}
1.261 +
1.262 +
1.263 +void
1.264 +MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
1.265 +{
1.266 + if (!imageBuffer) imageBuffer = new QBuffer();
1.267 + if (!imageBuffer->isOpen()) {
1.268 + imageBuffer->open(IO_WriteOnly | IO_Append);
1.269 + }
1.270 + imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
1.271 +}
1.272 +
1.273 +
1.274 +void
1.275 +MapEditor::imageDataFinished(QNetworkOperation *nop)
1.276 +{
1.277 + imageBuffer->close();
1.278 + if (nop->state()==QNetworkProtocol::StDone) {
1.279 + QPixmap img(imageBuffer->buffer());
1.280 + addFloatImage(img);
1.281 + }
1.282 +
1.283 + delete imageBuffer;
1.284 + imageBuffer = 0;
1.285 +}
1.286 +
1.287 +void
1.288 +MapEditor::fetchImage(const QString &url)
1.289 +{
1.290 + if (urlOperator) {
1.291 + urlOperator->stop();
1.292 + disconnect(urlOperator);
1.293 + delete urlOperator;
1.294 + }
1.295 +
1.296 + urlOperator = new QUrlOperator(url);
1.297 + connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
1.298 + this, SLOT(imageDataFinished(QNetworkOperation*)));
1.299 +
1.300 + connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
1.301 + this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));
1.302 + urlOperator->get();
1.303 +}