mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-08 14:49:58 +01:00
Element editor : start work for change how draw primitive (work in progress)
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3451 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
103
sources/editor/esevent/eseventaddline.cpp
Normal file
103
sources/editor/esevent/eseventaddline.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
Copyright 2006-2014 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QObject>
|
||||
|
||||
#include "eseventaddline.h"
|
||||
#include "elementscene.h"
|
||||
#include "qetelementeditor.h"
|
||||
#include "partline.h"
|
||||
#include "editorcommands.h"
|
||||
|
||||
/**
|
||||
* @brief ESEventAddLine::ESEventAddLine
|
||||
* Constructor
|
||||
* @param scene : scene where we operate this action
|
||||
*/
|
||||
ESEventAddLine::ESEventAddLine(ElementScene *scene) :
|
||||
ESEventInterface (scene),
|
||||
m_line (nullptr)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddLine::~ESEventAddLine
|
||||
* destructor
|
||||
*/
|
||||
ESEventAddLine::~ESEventAddLine() {
|
||||
if (m_running || m_abort)
|
||||
delete m_line;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddLine::mousePressEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddLine::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
|
||||
if (event -> button() == Qt::LeftButton) {
|
||||
|
||||
if (! m_running) m_running = true;
|
||||
QPointF pos = m_scene -> snapToGrid(event -> scenePos());
|
||||
|
||||
//Create new line
|
||||
if (!m_line) {
|
||||
m_line = new PartLine(m_editor, 0, m_scene);
|
||||
m_line -> setLine(QLineF(pos, pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
//Add new line to scene
|
||||
m_line -> setLine(QLineF(m_line->line().p1(), pos));
|
||||
m_scene -> undoStack().push(new AddPartCommand(QObject::tr("ligne"), m_scene, m_line));
|
||||
|
||||
//Set m_line to nullptr for create new line at next mouse press
|
||||
m_line = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//Remove the current line if exist
|
||||
//or finish if no line
|
||||
if (event -> button() == Qt::RightButton) {
|
||||
if (m_line) {
|
||||
delete m_line; m_line = nullptr;
|
||||
}
|
||||
else {
|
||||
m_running = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddLine::mouseMoveEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddLine::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
updateHelpCross (event -> scenePos());
|
||||
|
||||
if (!m_line) return false;
|
||||
|
||||
QPointF pos = m_scene -> snapToGrid(event -> scenePos());
|
||||
m_line -> setLine(QLineF(m_line->line().p1(), pos));
|
||||
return true;
|
||||
}
|
||||
40
sources/editor/esevent/eseventaddline.h
Normal file
40
sources/editor/esevent/eseventaddline.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright 2006-2014 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef ESEVENTADDLINE_H
|
||||
#define ESEVENTADDLINE_H
|
||||
|
||||
#include "eseventinterface.h"
|
||||
|
||||
class ElementScene;
|
||||
class PartLine;
|
||||
class QGraphicsSceneMouseEvent;
|
||||
|
||||
class ESEventAddLine : public ESEventInterface
|
||||
{
|
||||
public:
|
||||
ESEventAddLine(ElementScene *scene);
|
||||
virtual ~ESEventAddLine();
|
||||
|
||||
virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual bool mouseMoveEvent (QGraphicsSceneMouseEvent *event);
|
||||
|
||||
private:
|
||||
PartLine *m_line;
|
||||
};
|
||||
|
||||
#endif // ESEVENTADDLINE_H
|
||||
117
sources/editor/esevent/eseventinterface.cpp
Normal file
117
sources/editor/esevent/eseventinterface.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
Copyright 2006-2014 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "eseventinterface.h"
|
||||
#include "elementscene.h"
|
||||
#include "qetelementeditor.h"
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
ESEventInterface::ESEventInterface(ElementScene *scene) :
|
||||
m_scene (scene),
|
||||
m_editor (scene->editor()),
|
||||
m_help_horiz (nullptr),
|
||||
m_help_verti (nullptr),
|
||||
m_running (false),
|
||||
m_abort (false)
|
||||
{
|
||||
foreach (QGraphicsView *qgv, m_scene->views())
|
||||
qgv->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
}
|
||||
|
||||
ESEventInterface::~ESEventInterface() {
|
||||
delete m_help_horiz;
|
||||
delete m_help_verti;
|
||||
|
||||
foreach (QGraphicsView *qgv, m_scene->views())
|
||||
qgv->setContextMenuPolicy(Qt::DefaultContextMenu);
|
||||
}
|
||||
|
||||
bool ESEventInterface::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
|
||||
Q_UNUSED (event);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESEventInterface::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
Q_UNUSED (event);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESEventInterface::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
Q_UNUSED (event);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESEventInterface::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
Q_UNUSED (event);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESEventInterface::wheelEvent(QGraphicsSceneWheelEvent *event) {
|
||||
Q_UNUSED (event);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventInterface::keyPressEvent
|
||||
* By default, press escape key abort the curent action
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventInterface::keyPressEvent(QKeyEvent *event) {
|
||||
if (event->key() == Qt::Key_Escape) {
|
||||
m_running = false;
|
||||
m_abort = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESEventInterface::KeyReleaseEvent(QKeyEvent *event) {
|
||||
Q_UNUSED (event);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ESEventInterface::isRunning() const {
|
||||
return m_running;
|
||||
}
|
||||
|
||||
bool ESEventInterface::isFinish() const {
|
||||
return !m_running;
|
||||
}
|
||||
|
||||
void ESEventInterface::updateHelpCross(const QPointF &p) {
|
||||
//If line isn't created yet, we create it.
|
||||
if (!m_help_horiz || !m_help_verti) {
|
||||
QPen pen;
|
||||
pen.setColor(Qt::darkBlue);
|
||||
if (!m_help_horiz) {
|
||||
m_help_horiz = new QGraphicsLineItem(-10000, 0, 10000, 0, 0, m_scene);
|
||||
m_help_horiz -> setPen(pen);
|
||||
}
|
||||
if (!m_help_verti) {
|
||||
m_help_verti = new QGraphicsLineItem(0, -10000, 0, 10000, 0, m_scene);
|
||||
m_help_verti -> setPen(pen);
|
||||
}
|
||||
}
|
||||
|
||||
//Update the position of the cross
|
||||
QPointF point = m_scene -> snapToGrid(p);
|
||||
|
||||
m_help_horiz -> setY(point.y());
|
||||
m_help_verti -> setX(point.x());
|
||||
|
||||
}
|
||||
55
sources/editor/esevent/eseventinterface.h
Normal file
55
sources/editor/esevent/eseventinterface.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright 2006-2014 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef ESEVENTINTERFACE_H
|
||||
#define ESEVENTINTERFACE_H
|
||||
|
||||
class QGraphicsSceneMouseEvent;
|
||||
class QGraphicsSceneWheelEvent;
|
||||
class QKeyEvent;
|
||||
class ElementScene;
|
||||
class QETElementEditor;
|
||||
class QGraphicsLineItem;
|
||||
class QPointF;
|
||||
|
||||
class ESEventInterface
|
||||
{
|
||||
public:
|
||||
ESEventInterface(ElementScene *scene);
|
||||
virtual ~ESEventInterface();
|
||||
|
||||
virtual bool mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event);
|
||||
virtual bool mousePressEvent (QGraphicsSceneMouseEvent *event);
|
||||
virtual bool mouseMoveEvent (QGraphicsSceneMouseEvent *event);
|
||||
virtual bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
|
||||
virtual bool wheelEvent (QGraphicsSceneWheelEvent *event);
|
||||
virtual bool keyPressEvent (QKeyEvent *event);
|
||||
virtual bool KeyReleaseEvent (QKeyEvent *event);
|
||||
virtual bool isRunning () const;
|
||||
virtual bool isFinish () const;
|
||||
|
||||
protected:
|
||||
void updateHelpCross (const QPointF &p);
|
||||
|
||||
protected:
|
||||
ElementScene *m_scene;
|
||||
QETElementEditor *m_editor;
|
||||
QGraphicsLineItem *m_help_horiz, *m_help_verti;
|
||||
bool m_running, m_abort;
|
||||
};
|
||||
|
||||
#endif // ESEVENTINTERFACE_H
|
||||
Reference in New Issue
Block a user