[qet] [2313] Added Cyril patch for import image |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2313
Author: scorpio810
Date: 2013-06-21 09:59:08 +0200 (Fri, 21 Jun 2013)
Log Message:
-----------
Added Cyril patch for import image
Modified Paths:
--------------
branches/0.4/sources/diagramview.cpp
branches/0.4/sources/diagramview.h
Modified: branches/0.4/sources/diagramview.cpp
===================================================================
--- branches/0.4/sources/diagramview.cpp 2013-06-20 23:12:36 UTC (rev 2312)
+++ branches/0.4/sources/diagramview.cpp 2013-06-21 07:59:08 UTC (rev 2313)
@@ -422,6 +422,10 @@
addDiagramTextAtPos(mapToScene(e -> pos()));
is_adding_text = false;
}
+ if (is_adding_image && e -> buttons() == Qt::LeftButton) {
+ addDiagramImageAtPos(mapToScene(e -> pos()));
+ is_adding_image = false;
+ }
}
// workaround for drag view with hold wheel click and drag mouse
// see also mouseMoveEvent() and mouseReleaseEvent()
@@ -1202,6 +1206,8 @@
void DiagramView::addText() {
if (scene -> isReadOnly()) return;
is_adding_text = true;
+ //Debug CYRIL
+ is_adding_image = true;
}
@@ -1225,7 +1231,49 @@
else texts_to_edit.at(0)->edit();
}
+
/**
+* @brief DiagramView::addImage
+*/
+void DiagramView::addImage() {
+ if (scene -> isReadOnly()) return;
+
+ QString pathPictures = QDesktopServices::storageLocation ( QDesktopServices::PicturesLocation );
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Selectionner une image..."), pathPictures.toStdString().c_str(), tr("Image Files (*.png *.jpg *.bmp)"));
+ if(fileName.isEmpty())return;
+
+ int ret = image_to_add_.load(fileName);
+ if(!ret){
+ QMessageBox::critical(this, tr("Erreur"), tr("Impossible de charger l'image...D\351soler :("));
+ return;
+ }
+}
+/**
+* @brief DiagramView::addDiagramImageAtPos
+* @param pos
+* @return
+*/
+IndependentTextItem *DiagramView::addDiagramImageAtPos(const QPointF &pos) {
+
+ if (!isInteractive() || scene -> isReadOnly()) return(0);
+
+ addImage();
+ QGraphicsPixmapItem *pixItem = new QGraphicsPixmapItem( QPixmap::fromImage(image_to_add_) );
+ scene ->addItem( pixItem );
+
+/*// cree un nouveau champ de texte
+IndependentTextItem *iti = new IndependentTextItem("_");
+
+// le place a la position pos en gerant l'annulation
+scene -> undoStack().push(new AddTextCommand(scene, iti, pos));
+ adjustSceneRect();
+
+ // emet le signal textAdded
+emit(textAdded(false));
+ return(iti);*/
+}
+
+/**
Cree un nouveau champ de texte et le place a la position pos
en gerant l'annulation ; enfin, le signal textAdded est emis.
@param pos Position du champ de texte ajoute
Modified: branches/0.4/sources/diagramview.h
===================================================================
--- branches/0.4/sources/diagramview.h 2013-06-20 23:12:36 UTC (rev 2312)
+++ branches/0.4/sources/diagramview.h 2013-06-21 07:59:08 UTC (rev 2313)
@@ -48,12 +48,14 @@
QAction *find_element_;
QPoint paste_here_pos;
bool is_adding_text;
+ bool is_adding_image;
bool is_moving_view_; ///< Indicate whether the visualisation mode has been enabled due to mouse/keyboard interactions
bool fresh_focus_in_; ///< Indicate the focus was freshly gained
ElementsLocation next_location_;
QPoint next_position_;
QPointF reference_view_;
QPointF center_view_;
+ QImage image_to_add_;
// methods
public:
@@ -71,7 +73,9 @@
bool hasDeletableItems();
void addText();
void editText();
+ void addImage();
IndependentTextItem *addDiagramTextAtPos(const QPointF &);
+ IndependentTextItem *addDiagramImageAtPos(const QPointF &);
protected:
virtual void mouseDoubleClickEvent(QMouseEvent *);