
--- Test2/Test2.pro | 8 +++++- Test2/Test2.pro.user | 32 ++++++++++++++-------------- Test2/picture.cpp | 57 ++++--------------------------------------------- Test2/picture.h | 10 +------- Test2/test2.cpp | 18 ++++++++-------- Test2/test2.h | 2 + Test2/test2.ui | 10 -------- 7 files changed, 40 insertions(+), 97 deletions(-) diff --git a/Test2/Test2.pro b/Test2/Test2.pro index 2b4afbb..3c20cfe 100644 --- a/Test2/Test2.pro +++ b/Test2/Test2.pro @@ -5,7 +5,11 @@ TARGET = Test2 TEMPLATE = app SOURCES += main.cpp \ test2.cpp \ - picture.cpp + picture.cpp \ + customgraphicsview.cpp \ + xml.cpp HEADERS += test2.h \ - picture.h + picture.h \ + customgraphicsview.h \ + xml.h FORMS += test2.ui diff --git a/Test2/Test2.pro.user b/Test2/Test2.pro.user index 0d52de4..373596f 100644 --- a/Test2/Test2.pro.user +++ b/Test2/Test2.pro.user @@ -118,14 +118,14 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Qt dans le PATH Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-e3k9D0Tv71,guid=99188e811458388b1144721a005572c8</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-paONMmMzu5,guid=50af68fe79cb2c7af74bdeaf0056c626</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> <value type="QString">GDM_LANG=fr_FR.UTF-8</value> <value type="QString">GDM_XSERVER_LOCATION=local</value> - <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-2ZyR97</value> - <value type="QString">GNOME_KEYRING_PID=2693</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-b0p70j</value> + <value type="QString">GNOME_KEYRING_PID=438</value> <value type="QString">GTK_MODULES=canberra-gtk-module</value> <value type="QString">HOME=/lrde/home/stage/froger_a</value> <value type="QString">LANG=fr_FR.UTF-8</value> @@ -137,16 +137,16 @@ <value type="QString">QTDIR=/usr/share/qt4</value> <value type="QString">SHELL=/bin/bash</value> <value type="QString">SHLVL=2</value> - <value type="QString">SSH_AGENT_PID=2775</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-FajlDG2702/agent.2702</value> + <value type="QString">SSH_AGENT_PID=513</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-oHzmzjh447/agent.447</value> <value type="QString">TERM=xterm</value> <value type="QString">USER=froger_a</value> <value type="QString">USERNAME=froger_a</value> <value type="QString">WINDOWID=16777252</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdmD2V5PW</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdmGH9MQW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1357647755.876395-1204336646</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1357734634.5267-1601039943</value> <value type="QString">XPSERVERLIST=:64 </value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> @@ -170,14 +170,14 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Qt dans le PATH Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-e3k9D0Tv71,guid=99188e811458388b1144721a005572c8</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-paONMmMzu5,guid=50af68fe79cb2c7af74bdeaf0056c626</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> <value type="QString">GDM_LANG=fr_FR.UTF-8</value> <value type="QString">GDM_XSERVER_LOCATION=local</value> - <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-2ZyR97</value> - <value type="QString">GNOME_KEYRING_PID=2693</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-b0p70j</value> + <value type="QString">GNOME_KEYRING_PID=438</value> <value type="QString">GTK_MODULES=canberra-gtk-module</value> <value type="QString">HOME=/lrde/home/stage/froger_a</value> <value type="QString">LANG=fr_FR.UTF-8</value> @@ -189,16 +189,16 @@ <value type="QString">QTDIR=/usr/share/qt4</value> <value type="QString">SHELL=/bin/bash</value> <value type="QString">SHLVL=2</value> - <value type="QString">SSH_AGENT_PID=2775</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-FajlDG2702/agent.2702</value> + <value type="QString">SSH_AGENT_PID=513</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-oHzmzjh447/agent.447</value> <value type="QString">TERM=xterm</value> <value type="QString">USER=froger_a</value> <value type="QString">USERNAME=froger_a</value> <value type="QString">WINDOWID=16777252</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdmD2V5PW</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdmGH9MQW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1357647755.876395-1204336646</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1357734634.5267-1601039943</value> <value type="QString">XPSERVERLIST=:64 </value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> diff --git a/Test2/picture.cpp b/Test2/picture.cpp index a3d1dfb..8d121cc 100644 --- a/Test2/picture.cpp +++ b/Test2/picture.cpp @@ -1,21 +1,9 @@ #include "picture.h" -Picture::Picture(QTextEdit *textEdit) +Picture::Picture() { setPos(0, 0); - isPush = false; - painter = new QPainter(&pixmap()); - this->textEdit = textEdit; -} - -Picture::Picture(const QString &filename, QTextEdit *textEdit) -{ - setAcceptedMouseButtons(Qt::LeftButton); - setPos(0, 0); - isPush = false; - load(filename); - painter = new QPainter(&pixmap()); - this->textEdit = textEdit; + isPress = false; } void Picture::load(const QString &filename) @@ -25,23 +13,12 @@ void Picture::load(const QString &filename) setPixmap(image); } -QString Picture::pressPosition() -{ - return "Mouse Press Position : " + QString::number(pressPos.x()) + ", " + QString::number(pressPos.y()); -} - -QString Picture::releasePosition() -{ - return "Mouse Release Position : " + QString::number(releasePos.x()) + ", " + QString::number(releasePos.y()); -} - void Picture::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if(event->button() == Qt::LeftButton && !isPush) + if(event->button() == Qt::LeftButton && !isPress) { pressPos = event->pos(); - textEdit->setText(pressPosition()); - isPush = true; + isPress = true; } } @@ -50,30 +27,6 @@ void Picture::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if(event->button() == Qt::LeftButton) { releasePos = event->pos(); - textEdit->setText(releasePosition()); - QRectF rectangle; - if (pressPos.x() < releasePos.x()) - { - rectangle.setX(pressPos.x()); - rectangle.setWidth(releasePos.x() - pressPos.x()); - } - else - { - rectangle.setX(releasePos.x()); - rectangle.setWidth(pressPos.x() - releasePos.x()); - } - if (pressPos.y() < releasePos.y()) - { - rectangle.setY(pressPos.y()); - rectangle.setHeight(releasePos.y() - pressPos.y()); - } - else - { - rectangle.setY(releasePos.y()); - rectangle.setHeight(pressPos.y() - releasePos.y()); - } - painter->drawRoundedRect(rectangle, 20.0, 15.0); - - isPush = false; + isPress = false; } } diff --git a/Test2/picture.h b/Test2/picture.h index a0c308e..f21f44d 100644 --- a/Test2/picture.h +++ b/Test2/picture.h @@ -12,8 +12,7 @@ class Picture : public QGraphicsPixmapItem { public: - Picture(QTextEdit *textEdit); - Picture(const QString &filename, QTextEdit *textEdit); + Picture(); void load(const QString &filename); protected: @@ -21,14 +20,9 @@ class Picture : void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); private: - QString pressPosition(); - QString releasePosition(); - - QTextEdit *textEdit; - QPainter *painter; QPointF pressPos; QPointF releasePos; - bool isPush; + bool isPress; }; #endif // PICTURE_H diff --git a/Test2/test2.cpp b/Test2/test2.cpp index b918a42..5b14207 100644 --- a/Test2/test2.cpp +++ b/Test2/test2.cpp @@ -1,14 +1,13 @@ #include <QFileDialog> #include <QScrollBar> -#include <QTextEdit> #include <QShortcut> #include <QGraphicsView> #include <QGraphicsScene> #include <QGraphicsPixmapItem> -#include <QMouseEvent> #include "test2.h" #include "picture.h" #include "ui_test2.h" +#include "customgraphicsview.h" Test2::Test2(QWidget *parent) : QMainWindow(parent), @@ -16,15 +15,17 @@ Test2::Test2(QWidget *parent) : { ui->setupUi(this); scaleFactor = 1.0; + graphicsView = new CustomGraphicsView(ui->textEdit); + graphicsView->setParent(ui->scrollArea); QGraphicsScene *scene = new QGraphicsScene(ui->scrollArea); - ui->graphicsView->setScene(scene); - ui->graphicsView->setGeometry(0, 0, ui->scrollArea->width(), ui->scrollArea->height()); + graphicsView->setScene(scene); + graphicsView->setGeometry(0, 0, ui->scrollArea->width(), ui->scrollArea->height()); shortcutZoomIn = new QShortcut(QKeySequence("Ctrl++"), this); shortcutZoomOut = new QShortcut(QKeySequence("Ctrl+-"), this); connect(shortcutZoomOut, SIGNAL(activated()), this, SLOT(on_actionZoomOut_triggered())); connect(shortcutZoomIn, SIGNAL(activated()), this, SLOT(on_actionZoomIn_triggered())); - picture = new Picture(ui->textEdit); - ui->graphicsView->scene()->addItem(picture); + picture = new Picture(); + graphicsView->scene()->addItem(picture); } Test2::~Test2() @@ -53,8 +54,7 @@ void Test2::adjustScrollBar(QScrollBar *scrollBar, double factor) void Test2::scaleImage(double factor) { scaleFactor *= factor; - ui->textEdit->clear(); - ui->graphicsView->scale(factor, factor); + graphicsView->scale(factor, factor); adjustScrollBar(ui->scrollArea->horizontalScrollBar(), factor); adjustScrollBar(ui->scrollArea->verticalScrollBar(), factor); } @@ -62,7 +62,7 @@ void Test2::scaleImage(double factor) void Test2::on_actionOpen_triggered() { QString filename = QFileDialog::getOpenFileName(this); - ui->textEdit->setText(filename); + ui->textEdit->setText("FilePath : " + filename); picture->load(filename); } diff --git a/Test2/test2.h b/Test2/test2.h index 7163fc8..19bf875 100644 --- a/Test2/test2.h +++ b/Test2/test2.h @@ -6,6 +6,7 @@ #include <QMainWindow> #include <QShortcut> #include "picture.h" +#include "customgraphicsview.h" namespace Ui { @@ -27,6 +28,7 @@ private: Ui::Test2 *ui; Picture *picture; + CustomGraphicsView *graphicsView; QScrollArea *scrollArea; double scaleFactor; diff --git a/Test2/test2.ui b/Test2/test2.ui index d09472c..8b630f8 100644 --- a/Test2/test2.ui +++ b/Test2/test2.ui @@ -45,16 +45,6 @@ <height>317</height> </rect> </property> - <widget class="QGraphicsView" name="graphicsView"> - <property name="geometry"> - <rect> - <x>100</x> - <y>40</y> - <width>281</width> - <height>201</height> - </rect> - </property> - </widget> </widget> </widget> </widget> -- 1.7.2.5