summaryrefslogtreecommitdiffstats
path: root/interactioncanvas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'interactioncanvas.cpp')
-rw-r--r--interactioncanvas.cpp73
1 files changed, 71 insertions, 2 deletions
diff --git a/interactioncanvas.cpp b/interactioncanvas.cpp
index c289c40..2c2b81b 100644
--- a/interactioncanvas.cpp
+++ b/interactioncanvas.cpp
@@ -4,33 +4,85 @@ InteractionCanvas::InteractionCanvas()
{
setFocusPolicy(Qt::StrongFocus);
setMouseTracking(true);
+ m_Line = NULL;
}
InteractionCanvas::~InteractionCanvas()
{
-
+ delete tempPainter;
+ tempPainter = NULL;
+ delete normalPainter;
+ normalPainter = NULL;
}
void InteractionCanvas::mouseMoveEvent(QMouseEvent *mouseEvent)
{
qDebug() << "InteractionCanvas:" << mouseEvent->pos();
+ m_LastMousePosition = mouseEvent->pos();
+
+ if (m_Line)
+ {
+ m_Line->setP2(m_LastMousePosition);
+ update();
+ }
}
void InteractionCanvas::mousePressEvent(QMouseEvent *mouseEvent)
{
qDebug() << "InteractionCanvas: Mouse: pressed:" << mouseEvent->button();
+
+ if (mouseEvent->button() == Qt::LeftButton)
+ {
+ if (m_Line)
+ {
+ delete m_Line;
+ m_Line = NULL;
+ }
+
+ m_Line = new Line();
+ m_MousePressPoint = mouseEvent->pos();
+ m_LastMousePosition = m_MousePressPoint;
+ m_Line->setP1(m_MousePressPoint);
+ m_Line->setP2(m_LastMousePosition);
+ }
+
+ if (mouseEvent->button() == Qt::RightButton)
+ {
+ for(int i = 0; i < m_Lines.size(); i++)
+ {
+ m_Lines[i].setSelected(m_Lines[i].isHit(mouseEvent->pos()));
+ }
+ }
}
void InteractionCanvas::mouseReleaseEvent(QMouseEvent *mouseEvent)
{
- qDebug() << "InteractionCanvas: Mouse: released:"<< mouseEvent->button();
+ qDebug() << "InteractionCanvas: Mouse: released:" << mouseEvent->button();
+
+ if (mouseEvent->button() == Qt::LeftButton)
+ {
+
+ m_MouseReleasePoint = mouseEvent->pos();
+ m_Line->setP2(m_MouseReleasePoint);
+ m_Line->setSelected(false);
+ m_Lines.append(*m_Line);
+ m_Line = NULL;
+ }
+
+ update();
}
void InteractionCanvas::keyPressEvent(QKeyEvent *keyEvent)
{
qDebug() << "InteractionCanvas: Key: pressed:" << keyEvent->key() << "(" <<
keyEvent->text() << ")" << (keyEvent->isAutoRepeat() ? "druck" : "");
+
+ if(!m_Lines.isEmpty() && keyEvent->key() == Qt::Key_Z && keyEvent->modifiers() == Qt::ControlModifier)
+ {
+ m_Lines.removeLast();
+ update();
+ }
}
void InteractionCanvas::keyReleaseEvent(QKeyEvent *keyEvent)
@@ -38,3 +90,20 @@ void InteractionCanvas::keyReleaseEvent(QKeyEvent *keyEvent)
qDebug() << "InteractionCanvas: Key: released:" << keyEvent->key() << "(" <<
keyEvent->text() << ")" << (keyEvent->isAutoRepeat() ? "druck" : "");
}
+
+
+void InteractionCanvas::paintEvent(QPaintEvent *paintEvent)
+{
+ // Setup the Painters
+ QPainter painter(this);
+
+ if (m_Line)
+ {
+ m_Line->draw(&painter);
+ }
+
+ foreach (Line line, m_Lines)
+ {
+ line.draw(&painter);
+ }
+}