*graphicsview.h,
*graphicsview.cpp.
---
GScribo/GScribo.pro | 2 +
GScribo/GScribo.pro.user | 32 +++++++---------
GScribo/Rendering/backgroundtexture.h | 12 ++++++
GScribo/Rendering/graphicsview.cpp | 68 +++++++++++++++++++++++++++++++++
GScribo/Rendering/graphicsview.h | 26 ++++++++++++
GScribo/mainwindow.h | 1 +
6 files changed, 123 insertions(+), 18 deletions(-)
create mode 100644 GScribo/Rendering/backgroundtexture.h
create mode 100644 GScribo/Rendering/graphicsview.cpp
create mode 100644 GScribo/Rendering/graphicsview.h
diff --git a/GScribo/GScribo.pro b/GScribo/GScribo.pro
index d845d32..c5613f6 100644
--- a/GScribo/GScribo.pro
+++ b/GScribo/GScribo.pro
@@ -17,6 +17,7 @@ SOURCES += main.cpp \
Rendering/scene.cpp \
Rendering/selection.cpp \
Rendering/regionitem.cpp \
+ Rendering/graphicsview.cpp \
PagesWidget/pageswidget.cpp \
PagesWidget/pagesmodel.cpp \
PagesWidget/pagesdelegate.cpp \
@@ -42,6 +43,7 @@ HEADERS += mainwindow.h \
Rendering/scene.h \
Rendering/selection.h \
Rendering/regionitem.h \
+ Rendering/graphicsview.h \
PagesWidget/pageswidget.h \
PagesWidget/pagesmodel.h \
Preferences/segmentationoptions.h \
diff --git a/GScribo/GScribo.pro.user b/GScribo/GScribo.pro.user
index ab03cea..0274cef 100644
--- a/GScribo/GScribo.pro.user
+++ b/GScribo/GScribo.pro.user
@@ -76,7 +76,7 @@
<valuemap type="QVariantMap">
<value key="ProjectExplorer.BuildConfiguration.DisplayName"
type="QString">Debug</value>
<valuelist key="abstractProcess.Environment"
type="QVariantList">
- <value
type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-bUeJ6Q6yr3,guid=f61c0677e7161026c52fc89400064242</value>
+ <value
type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-MYegNG7MAz,guid=fddbeed997eaec30b39f769300000038</value>
<value type="QString">DESKTOP_SESSION=fluxbox</value>
<value type="QString">DISPLAY=:0.0</value>
<value type="QString">GDMSESSION=fluxbox</value>
@@ -87,26 +87,24 @@
<value type="QString">LANG=fr_FR.UTF-8</value>
<value
type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value>
<value type="QString">LOGNAME=froger_a</value>
- <value
type="QString">OLDPWD=/lrde/home/stage/froger_a/qt</value>
<value
type="QString">PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/games</value>
<value
type="QString">PWD=/lrde/home/stage/froger_a/qt/GScribo</value>
<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=29535</value>
- <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-PCwYf29482/agent.29482</value>
+ <value type="QString">SSH_AGENT_PID=2086</value>
+ <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-hPSRAn2025/agent.2025</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=10485796</value>
- <value type="QString">WINDOWPATH=7:8:8:8:8:8</value>
- <value type="QString">XAUTHORITY=/tmp/.gdmQ6NBSW</value>
+ <value type="QString">WINDOWID=16777240</value>
+ <value type="QString">WINDOWPATH=7</value>
+ <value type="QString">XAUTHORITY=/tmp/.gdmC10ASW</value>
<value
type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value>
- <value
type="QString">XDG_SESSION_COOKIE=9a5c41ad78622411b8e25b00459a554f-1360655387.142140-2081338543</value>
+ <value
type="QString">XDG_SESSION_COOKIE=9a5c41ad78622411b8e25b00459a554f-1360774468.168232-1277165267</value>
<value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value>
<value type="QString">XTERM_SHELL=/bin/bash</value>
<value type="QString">XTERM_VERSION=XTerm(261)</value>
- <value type="QString">_=/usr/bin/qtcreator</value>
</valuelist>
<valuelist key="abstractProcess.arguments"
type="QVariantList">
<value
type="QString">/amd/nfs/volume1/home/stage/froger_a/qt/GScribo/GScribo.pro</value>
@@ -125,7 +123,7 @@
<valuemap type="QVariantMap">
<value key="ProjectExplorer.BuildConfiguration.DisplayName"
type="QString">Debug</value>
<valuelist key="abstractProcess.Environment"
type="QVariantList">
- <value
type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-bUeJ6Q6yr3,guid=f61c0677e7161026c52fc89400064242</value>
+ <value
type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-MYegNG7MAz,guid=fddbeed997eaec30b39f769300000038</value>
<value type="QString">DESKTOP_SESSION=fluxbox</value>
<value type="QString">DISPLAY=:0.0</value>
<value type="QString">GDMSESSION=fluxbox</value>
@@ -136,26 +134,24 @@
<value type="QString">LANG=fr_FR.UTF-8</value>
<value
type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value>
<value type="QString">LOGNAME=froger_a</value>
- <value
type="QString">OLDPWD=/lrde/home/stage/froger_a/qt</value>
<value
type="QString">PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/games</value>
<value
type="QString">PWD=/lrde/home/stage/froger_a/qt/GScribo</value>
<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=29535</value>
- <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-PCwYf29482/agent.29482</value>
+ <value type="QString">SSH_AGENT_PID=2086</value>
+ <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-hPSRAn2025/agent.2025</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=10485796</value>
- <value type="QString">WINDOWPATH=7:8:8:8:8:8</value>
- <value type="QString">XAUTHORITY=/tmp/.gdmQ6NBSW</value>
+ <value type="QString">WINDOWID=16777240</value>
+ <value type="QString">WINDOWPATH=7</value>
+ <value type="QString">XAUTHORITY=/tmp/.gdmC10ASW</value>
<value
type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value>
- <value
type="QString">XDG_SESSION_COOKIE=9a5c41ad78622411b8e25b00459a554f-1360655387.142140-2081338543</value>
+ <value
type="QString">XDG_SESSION_COOKIE=9a5c41ad78622411b8e25b00459a554f-1360774468.168232-1277165267</value>
<value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value>
<value type="QString">XTERM_SHELL=/bin/bash</value>
<value type="QString">XTERM_VERSION=XTerm(261)</value>
- <value type="QString">_=/usr/bin/qtcreator</value>
</valuelist>
<value key="abstractProcess.IgnoreReturnValue"
type="bool">false</value>
<valuelist key="abstractProcess.arguments"
type="QVariantList">
diff --git a/GScribo/Rendering/backgroundtexture.h
b/GScribo/Rendering/backgroundtexture.h
new file mode 100644
index 0000000..22c8d0c
--- /dev/null
+++ b/GScribo/Rendering/backgroundtexture.h
@@ -0,0 +1,12 @@
+#ifndef BACKGROUNDTEXTURE_H
+#define BACKGROUNDTEXTURE_H
+
+#include <QPixmap>
+
+class BackgroundTexture : public QPixmap
+{
+ public:
+ explicit BackgroundTexture(const QPixmap& );
+};
+
+#endif // BACKGROUNDTEXTURE_H
diff --git a/GScribo/Rendering/graphicsview.cpp b/GScribo/Rendering/graphicsview.cpp
new file mode 100644
index 0000000..0068bfd
--- /dev/null
+++ b/GScribo/Rendering/graphicsview.cpp
@@ -0,0 +1,68 @@
+#include "graphicsview.h"
+
+GraphicsView::GraphicsView(QWidget *parent) :
+ QGraphicsView(parent)
+{
+ scaleRatio_ = 1;
+}
+
+GraphicsView::GraphicsView(QGraphicsScene *scene, QWidget *parent) :
+ QGraphicsView(scene, parent)
+{
+ scaleRatio_ = 1;
+}
+
+void GraphicsView::wheelEvent(QWheelEvent *event)
+{
+ // Current wheel have an angle of 15 degrees by steps with a delta of + or - 120. A
good scale is +- 0.1 in that case.
+ // So we have to adapt for wheel whith better precision.
+
+ if((event->delta() > 0 && scaleRatio_ < 1.6) || (event->delta()
< 0 && scaleRatio_ > 1))
+ {
+ qreal degrees = static_cast<qreal>(event->delta()) / 1200;
+ scaleRatio_ += degrees;
+ degrees += 1;
+ scale(degrees, degrees);
+ }
+
+ QGraphicsView::wheelEvent(event);
+}
+
+void GraphicsView::keyPressEvent(QKeyEvent* event)
+{
+ // Bitwise AND to check if at least CTRL is pushed.
+ if(event->modifiers() & Qt::ControlModifier)
+ {
+ if(event->key() == Qt::Key_Plus && scaleRatio_ < 1.5)
+ {
+ scaleRatio_ += 0.2;
+ scale(1.2, 1.2);
+ }
+
+ else if(event->key() == Qt::Key_Minus && scaleRatio_ > 1)
+ {
+ scaleRatio_ -= 0.2;
+ scale(0.8, 0.8);
+ }
+ }
+
+ QGraphicsView::keyPressEvent(event);
+}
+
+void GraphicsView::fitInView(const QGraphicsItem *item, Qt::AspectRatioMode
aspectRadioMode)
+{
+ scaleRatio_ = 1;
+ QGraphicsView::fitInView(item, aspectRadioMode);
+}
+
+void GraphicsView::fitInView(const QRectF& rect, Qt::AspectRatioMode
aspectRadioMode)
+{
+ scaleRatio_ = 1;
+ QGraphicsView::fitInView(rect, aspectRadioMode);
+}
+
+void GraphicsView::fitInView(qreal x, qreal y, qreal w, qreal h, Qt::AspectRatioMode
aspectRadioMode)
+{
+ scaleRatio_ = 1;
+ QGraphicsView::fitInView(x, y, w, h, aspectRadioMode);
+}
diff --git a/GScribo/Rendering/graphicsview.h b/GScribo/Rendering/graphicsview.h
new file mode 100644
index 0000000..51f18dc
--- /dev/null
+++ b/GScribo/Rendering/graphicsview.h
@@ -0,0 +1,26 @@
+#ifndef GRAPHICSVIEW_H
+#define GRAPHICSVIEW_H
+
+#include <QGraphicsView>
+#include <QWheelEvent>
+
+class GraphicsView :
+ public QGraphicsView
+{
+ public:
+ explicit GraphicsView(QWidget *parent = 0);
+ explicit GraphicsView(QGraphicsScene *scene, QWidget *parent = 0);
+
+ void fitInView(const QGraphicsItem *item, Qt::AspectRatioMode aspectRadioMode);
+ void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode);
+ void fitInView(qreal x, qreal y, qreal w, qreal h, Qt::AspectRatioMode
aspectRadioMode);
+
+ protected:
+ void wheelEvent(QWheelEvent *event);
+ void keyPressEvent(QKeyEvent *event);
+
+ private:
+ qreal scaleRatio_;
+};
+
+#endif // GRAPHICSVIEW_H
diff --git a/GScribo/mainwindow.h b/GScribo/mainwindow.h
index efe6b81..c6cd1d7 100644
--- a/GScribo/mainwindow.h
+++ b/GScribo/mainwindow.h
@@ -12,6 +12,7 @@
#include "Preferences/preferencesdialog.h"
#include "Processing/progressdialog.h"
#include "PagesWidget/pageswidget.h"
+#include "Rendering/graphicsview.h"
#include "XmlWidget/xmlwidget.h"
//#include "Processing/runner.h"
#include "Rendering/scene.h"
--
1.7.2.5