[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdeedu/step/step
From: Sebastian Voecking <kde () voecking ! net>
Date: 2011-02-04 11:29:21
Message-ID: 20110204112921.59507AC8C5 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1218770 by voecking:
Correctly create a SoftBody object
M +57 -1 softbodygraphics.cc
M +20 -2 softbodygraphics.h
M +1 -1 worldfactory.cc
--- trunk/KDE/kdeedu/step/step/softbodygraphics.cc #1218769:1218770
@@ -38,6 +38,55 @@
#include <float.h>
+void SoftBodyCreator::start()
+{
+ showMessage(MessageFrame::Information,
+ i18n("Click on the scene to create a %1", classNameTr()));
+}
+
+bool SoftBodyCreator::sceneEvent(QEvent* event)
+{
+ QGraphicsSceneMouseEvent* mouseEvent = \
static_cast<QGraphicsSceneMouseEvent*>(event); +
+ if (event->type() == QEvent::GraphicsSceneMousePress &&
+ mouseEvent->button() == Qt::LeftButton) {
+ QPointF pos = mouseEvent->scenePos();
+ StepCore::Vector2d position = WorldGraphicsItem::pointToVector(pos);
+
+ _worldModel->simulationPause();
+ _worldModel->beginMacro(i18n("Create %1",
+ _worldModel->newItemName(_className)));
+
+ showMessage(MessageFrame::Information,
+ i18n("Please fill in the parameters for %1", classNameTr()));
+
+ _item = _worldModel->createItem(_className); Q_ASSERT(_item != 0);
+
+ SoftBodyMenuHandler* menuHandler =
+ new SoftBodyMenuHandler(_item, _worldModel, 0);
+ menuHandler->createSoftBodyItems(position);
+ menuHandler->deleteLater();
+
+ _worldModel->endMacro();
+
+ if (menuHandler->applied()) {
+ showMessage(MessageFrame::Information,
+ i18n("%1 named '%2' created", classNameTr(), _item->name()),
+ MessageFrame::CloseButton | MessageFrame::CloseTimer);
+ }
+ else {
+ delete _item;
+ _item = 0;
+ }
+
+ setFinished();
+
+ return true;
+ }
+
+ return false;
+}
+
void SoftBodyMenuHandler::populateMenu(QMenu* menu)
{
_createSoftBodyItemsUi = 0;
@@ -61,7 +110,7 @@
// _worldModel->simulationPause();
}
-void SoftBodyMenuHandler::createSoftBodyItems()
+void SoftBodyMenuHandler::createSoftBodyItems(const StepCore::Vector2d& pos)
{
if(_worldModel->isSimulationActive())
_worldModel->simulationStop();
@@ -77,6 +126,7 @@
_createSoftBodyItemsUi->lineEditPosition->setValidator(
new \
QRegExpValidator(QRegExp("^\\([+-]?\\d+(\\.\\d*)?([eE]\\d*)?,[+-]?\\d+(\\.\\d*)?([eE]\\d*)?\\)$"),
_createSoftBodyItemsUi->lineEditPosition));
+ _createSoftBodyItemsUi->lineEditPosition->setText(StepCore::typeToString(pos));
_createSoftBodyItemsUi->lineEditSize->setValidator(
new \
QRegExpValidator(QRegExp("^\\([+-]?\\d+(\\.\\d*)?([eE]\\d*)?,[+-]?\\d+(\\.\\d*)?([eE]\\d*)?\\)$"),
_createSoftBodyItemsUi->lineEditSize));
@@ -120,6 +170,10 @@
StepCore::ItemList items =
softBody()->createSoftBodyItems(position, size, split, bodyMass, \
youngModulus, bodyDamping);
+ _worldModel->addItem(softBody());
+ _worldModel->selectionModel()->setCurrentIndex(_worldModel->objectIndex(softBody()),
+ \
QItemSelectionModel::ClearAndSelect); +
const StepCore::ItemList::const_iterator end = items.end();
for(StepCore::ItemList::const_iterator it = items.begin(); it != end; ++it) {
(*it)->setName(_worldModel->getUniqueName((*it)->metaObject()->className()));
@@ -127,6 +181,8 @@
}
_worldModel->endMacro();
+
+ _applied = true;
}
/////////////////////////////////////////////////
--- trunk/KDE/kdeedu/step/step/softbodygraphics.h #1218769:1218770
@@ -31,6 +31,19 @@
class SoftBody;
}
+class SoftBodyCreator: public ItemCreator
+{
+public:
+ SoftBodyCreator(const QString& className, WorldModel* worldModel, WorldScene* \
worldScene) + : ItemCreator(className, worldModel, worldScene) {}
+
+ bool sceneEvent(QEvent* event);
+ void start();
+
+public:
+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW
+};
+
class KDialog;
class SoftBodyMenuHandler: public ItemMenuHandler
{
@@ -38,12 +51,16 @@
public:
SoftBodyMenuHandler(StepCore::Object* object, WorldModel* worldModel, QObject* \
parent)
- : ItemMenuHandler(object, worldModel, parent) {}
+ : ItemMenuHandler(object, worldModel, parent), _applied(false) {}
void populateMenu(QMenu* menu);
+ bool applied() const { return _applied; }
+
+public slots:
+ void createSoftBodyItems(const StepCore::Vector2d& pos);
+
protected slots:
- void createSoftBodyItems();
void createSoftBodyItemsApply();
void clearSoftBody();
@@ -51,6 +68,7 @@
StepCore::SoftBody* softBody() const;
Ui::WidgetCreateSoftBodyItems* _createSoftBodyItemsUi;
KDialog* _createSoftBodyItemsDialog;
+ bool _applied;
// bool _confChanged;
};
--- trunk/KDE/kdeedu/step/step/worldfactory.cc #1218769:1218770
@@ -127,7 +127,7 @@
__REGISTER_EXT(SoftBodySpring, SpringCreator, SoftBodySpringGraphicsItem, \
ItemMenuHandler);
__REGISTER_EXT(SoftBodyParticle, ItemCreator, SoftBodyParticleGraphicsItem, \
ItemMenuHandler);
- __REGISTER_EXT(SoftBody, ItemCreator, SoftBodyGraphicsItem, \
SoftBodyMenuHandler); + __REGISTER_EXT(SoftBody, SoftBodyCreator, \
SoftBodyGraphicsItem, SoftBodyMenuHandler);
__REGISTER_EXT_E(Spring, SpringCreator, SpringGraphicsItem, ItemMenuHandler);
__REGISTER_EXT(LinearMotor, LinearMotorCreator, LinearMotorGraphicsItem, \
ItemMenuHandler);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic