diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-05-16 23:41:43 +0200 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-05-16 23:41:43 +0200 |
| commit | 1faecafbc6cc74daa8d0a781c0b54f2c778b04b0 (patch) | |
| tree | 75e3915d245ead47b0e03ef6b544c714b4145cef /interactioncanvas.cpp | |
| parent | 1f1550f77e33bf32eb715eb62dd68751c07f9c0e (diff) | |
| download | GUI_SS2015-1faecafbc6cc74daa8d0a781c0b54f2c778b04b0.tar.gz GUI_SS2015-1faecafbc6cc74daa8d0a781c0b54f2c778b04b0.zip | |
Add 2d drawing for lines.
Diffstat (limited to 'interactioncanvas.cpp')
| -rw-r--r-- | interactioncanvas.cpp | 73 |
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); + } +} |
