/*************************************************************************** * Copyright (C) 2008 by Peter Dahlberg * * pdahlberg@gmail.com * * * * This program 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. * * * * This program 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 this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef SIMULSCENE_H #define SIMULSCENE_H #include class QTimeLine; class HomoEFieldItem; class QGraphicsRectItem; class QGraphicsItemGroup; class GraphicsEllipseItem; class QGraphicsItemAnimation; /** @author Peter Dahlberg */ class SimulScene : public QGraphicsScene { Q_OBJECT public: enum SceneMode {HomoEFieldItemInsert, FieldItemEdit }; enum ItemType {ResizeRectItem}; SimulScene ( QObject* parent = 0); qreal getHighestZIndexVisible(); //hoechsten z-index der sichtbaren items ausgeben ~SimulScene(); double getTimePerStep(); int getSteps(); //! gibt die Wirkende Kraft zurück (in Newton) /*! \param point der Punkt der abgeprüft werden soll \param charge Die Ladung, auf die die Kraft ausgeübt wird \param xy x oder y-Richtung */ double getPowerAt(QPointF point, double charge, char xy); QWidget* getProbeDockWidget() const; public slots: void setSceneMode(SceneMode mode); void startTimer(); void deleteSelectedFieldItems(); void setTimePerStep(double time); ///starte die Berechnung der teilchenbahn(en) void startCalculation(); void setSteps(int steps); void setMeterPerPx ( double theValue ); double getMeterPerPx() const; private slots: void displayResizeRects(bool move = false); ///does the same as displayResizeRects(true) void moveResizeRects(); signals: void sceneModeChanged(int mode); void stepsChanged(int steps); void timePerStepChanged(double timePerStep); void meterPerPxChanged(double meterPerPx); private: QTimeLine *timer; SceneMode myMode; ///Zeit pro Step in ms double timePerStep; ///anzahl der Steps int steps; ///ein Pixel entspricht so viel meter double meterPerPx; HomoEFieldItem *currHomoEfieldInsertItem; //Aktuell erstelltes Item HomoEFieldItem *currHomoEfieldEditItem; QGraphicsItem *pressedResizeItem; GraphicsEllipseItem *ellipse1; QGraphicsItemAnimation *ani; //rechtecke zur groesenaenderung struct resizeRects { QGraphicsRectItem *leftTopResizeItem; QGraphicsRectItem *leftResizeItem; QGraphicsRectItem *leftBottomResizeItem; QGraphicsRectItem *bottomResizeItem; QGraphicsRectItem *rightBottomResizeItem; QGraphicsRectItem *rightRezizeItem; QGraphicsRectItem *rightTopResizeItem; QGraphicsRectItem *topResizeItem; }; resizeRects reRects; void createResizeRects(); void calculateItemResize( QGraphicsSceneMouseEvent *mouseEvent, QGraphicsRectItem *pressedRectItem, QRectF &currRect, QPointF &newPos, qreal minWidth, qreal minHeight ); protected: void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent); void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent); void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent); void keyPressEvent ( QKeyEvent * keyEvent ); }; #endif