diff --git a/lsim.kdevelop.pcs b/lsim.kdevelop.pcs index a70360a..29f2656 100644 Binary files a/lsim.kdevelop.pcs and b/lsim.kdevelop.pcs differ diff --git a/lsim.kdevses b/lsim.kdevses index 4dd1d24..6ad0765 100644 --- a/lsim.kdevses +++ b/lsim.kdevses @@ -1,40 +1,28 @@ - + - + - + - - - - - - - + + + + + + + - - + + - - + + - - - - - - - - - - - - @@ -53,7 +41,7 @@ - + diff --git a/src/fielditem.cpp b/src/fielditem.cpp index c71b07c..1235a62 100644 --- a/src/fielditem.cpp +++ b/src/fielditem.cpp @@ -20,6 +20,7 @@ #include "fielditem.h" #include "homoefielditem.h" #include "homobfielditem.h" +#include "stopperitem.h" #include "simulscene.h" #include #include @@ -47,6 +48,7 @@ bool FieldItem::isFieldItem(QGraphicsItem *item) { // ---- Definiert die FieldItem typen fieldItemTypes << HomoEFieldItem::Type; fieldItemTypes << HomoBFieldItem::Type; + fieldItemTypes << StopperItem::Type; // ---- for (int i=0; itype() == fieldItemTypes.at(i)) { diff --git a/src/graphicsellipseitem.cpp b/src/graphicsellipseitem.cpp index 156bd98..2d448ac 100644 --- a/src/graphicsellipseitem.cpp +++ b/src/graphicsellipseitem.cpp @@ -28,6 +28,7 @@ #include "probechargewidget.h" #include #include "constants.h" +#include GraphicsEllipseItem::GraphicsEllipseItem() { //setFlag(ItemIsMovable); @@ -106,17 +107,17 @@ void GraphicsEllipseItem::calculateProbePath(QPointF startPoint) { time_t timea = time(0); debugTime += difftime(timea,timeb); - double newspeedX = speedListX->at(i-1) + (powerX/myMasse * (timePerStep/1000.0)); - double newspeedY = speedListY->at(i-1) + (powerY/myMasse * (timePerStep/1000.0)); + double newspeedX = speedListX->at(i-1) + (powerX/myMasse * timePerStep); + double newspeedY = speedListY->at(i-1) + (powerY/myMasse * timePerStep); //double deltaDistXconst = speedListX->at(i-1) * (timePerStep/1000.0); //v0*t //double deltaDistYconst = speedListY->at(i-1) * (timePerStep/1000.0); - double deltaDistXconst = (speedListX->at(i-1) + newspeedX)/2.0 * (timePerStep/1000.0); //v0*t - double deltaDistYconst = (speedListY->at(i-1) + newspeedY)/2.0 * (timePerStep/1000.0); //mittel zw alt,neu um fehler zu mindern + double deltaDistXconst = (speedListX->at(i-1) + newspeedX)/2.0 * timePerStep; //v0*t + double deltaDistYconst = (speedListY->at(i-1) + newspeedY)/2.0 * timePerStep; //mittel zw alt,neu um fehler zu mindern - double deltaDistXaccel = 0.5 * (powerX/myMasse * (timePerStep/1000.0) * (timePerStep/1000.0)); // 1/2 * F/m * t*t - double deltaDistYaccel = 0.5 * (powerY/myMasse * (timePerStep/1000.0) * (timePerStep/1000.0)); + double deltaDistXaccel = 0.5 * (powerX/myMasse * timePerStep * timePerStep); // 1/2 * F/m * t*t + double deltaDistYaccel = 0.5 * (powerY/myMasse * timePerStep * timePerStep); double deltaDistX = (deltaDistXconst + deltaDistXaccel); double deltaDistY = (deltaDistYconst + deltaDistYaccel); @@ -131,7 +132,7 @@ void GraphicsEllipseItem::calculateProbePath(QPointF startPoint) { } qDebug()<< difftime(time(0),start_time); - qDebug()<< debugTime; + std::cout<< debugTime<ignore(); } + +bool HomoBFieldItem::contains(const QPointF point) { + mapFromScene (point); + return ( + (point.x() <= boundingRect().width()) && + (point.y() <= boundingRect().height()) && + (point.y() >=0) && + (point.x() >=0) + ); + +} diff --git a/src/homobfielditem.h b/src/homobfielditem.h index e90e728..fc14c07 100644 --- a/src/homobfielditem.h +++ b/src/homobfielditem.h @@ -41,6 +41,8 @@ class HomoBFieldItem : public FieldItem { virtual QRectF boundingRect() const; virtual QRectF getRectF() const; virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget); + virtual bool contains(const QPointF point); + int type() const; int getFieldLineDistance() const; diff --git a/src/homoefielditem.cpp b/src/homoefielditem.cpp index 7bc69b3..e0e51ff 100644 --- a/src/homoefielditem.cpp +++ b/src/homoefielditem.cpp @@ -136,3 +136,14 @@ void HomoEFieldItem::setOuterPenWidth ( double theValue ) { if (outerPenWidth == theValue) return; outerPenWidth = theValue; } + +bool HomoEFieldItem::contains(const QPointF point) { + mapFromScene (point); + return ( + (point.x() <= boundingRect().width()) && + (point.y() <= boundingRect().height()) && + (point.y() >=0) && + (point.x() >=0) + ); + +} \ No newline at end of file diff --git a/src/homoefielditem.h b/src/homoefielditem.h index f4ef301..8c0efa6 100644 --- a/src/homoefielditem.h +++ b/src/homoefielditem.h @@ -50,14 +50,17 @@ class HomoEFieldItem : public FieldItem { \param pixel der Abstand */ virtual void setFieldLineDistance(int pixel); + virtual bool contains(const QPointF point); double getFieldPower() const; + double getOuterPenWidth() const; + public slots: void setFieldPower (double fieldPower ); void setOuterPenWidth ( double theValue ); - double getOuterPenWidth() const; + signals: void fieldPowerChanged(double fieldPower); diff --git a/src/lsim.cpp b/src/lsim.cpp index 13efcf9..c1829b1 100644 --- a/src/lsim.cpp +++ b/src/lsim.cpp @@ -141,6 +141,12 @@ void lsim::createActions() { acts.insertBFieldItemAct->setCheckable(true); acts.insertBFieldItemAct->setData(QVariant(SimulScene::HomoBFieldItemInsert)); + acts.insertStopperItemAct = new QAction (tr ("Stopper"), this); + acts.insertStopperItemAct->setStatusTip (tr ("Stopteil Einfuegen")); + acts.insertStopperItemAct->setCheckable(true); + acts.insertStopperItemAct->setData(QVariant(SimulScene::StopperItemInsert)); + + acts.probeChargeItemPlaceAct = new QAction (tr ("Ladung setzen"), this); acts.probeChargeItemPlaceAct->setStatusTip (tr ("Probeladung neu platzieren")); acts.probeChargeItemPlaceAct->setCheckable(true); @@ -150,6 +156,7 @@ void lsim::createActions() { modeChangeActGroup->addAction(acts.itemEditModeAct); modeChangeActGroup->addAction(acts.insertEFieldItemAct); modeChangeActGroup->addAction(acts.insertBFieldItemAct); + modeChangeActGroup->addAction(acts.insertStopperItemAct); modeChangeActGroup->addAction(acts.probeChargeItemPlaceAct); connect (modeChangeActGroup, SIGNAL (triggered(QAction*)), this, SLOT (actModeSwitcher(QAction*))); connect (simulscene, SIGNAL(sceneModeChanged(int)) , this, SLOT(setSceneMode(int))); @@ -187,6 +194,7 @@ void lsim::createToolBars() { editToolBar->addAction(acts.itemEditModeAct); editToolBar->addAction(acts.insertEFieldItemAct); editToolBar->addAction(acts.insertBFieldItemAct); + editToolBar->addAction(acts.insertStopperItemAct); editToolBar->addAction(acts.probeChargeItemPlaceAct); upDownToolBar=addToolBar(tr("updown")); @@ -210,7 +218,7 @@ void lsim::createDocks() { //steps box QSpinBox *steps_box = new QSpinBox; - steps_box->setRange(1, 2e+6); + steps_box->setRange(1, 5e+6); steps_box->setKeyboardTracking(false); steps_box->setValue(simulscene->getSteps()); connect(steps_box, SIGNAL(valueChanged(int)),simulscene, SLOT(setSteps(int))); @@ -222,7 +230,7 @@ void lsim::createDocks() { time_step_box->setDecimals(100); time_step_box->setDisplayDecimals(3); time_step_box->setKeyboardTracking(false); - time_step_box->setSuffix(" ms"); + time_step_box->setSuffix(" s"); time_step_box->setValue(simulscene->getTimePerStep()); connect(time_step_box, SIGNAL(valueChanged(double)),simulscene, SLOT(setTimePerStep(double))); connect(simulscene, SIGNAL(timePerStepChanged(double)),time_step_box, SLOT(setValue( double ))); @@ -339,8 +347,8 @@ void lsim::setSceneMode(int mode) { default: gview->unsetCursor(); - } -*/ + }*/ + } @@ -358,7 +366,7 @@ void lsim::updateDockFieldWidget() { QLabel* currLabel = new QLabel(tr("Bitte ein Feld ausw\344hlen")); currLabel->setWordWrap(true); currLabel->setAlignment(Qt::AlignCenter); - QWidget *currDockWidget =simulscene->getFieldListWidget(); + QWidget *currDockWidget =currLabel;//simulscene->getFieldListWidget(); if(simulscene->selectedItems().count() == 1) { QGraphicsItem *currItem = simulscene->selectedItems().first(); if (FieldItem::isFieldItem(currItem)) { @@ -372,7 +380,24 @@ void lsim::updateDockFieldWidget() { void lsim::startCalculation() { if( qApp->focusWidget() !=0) qApp->focusWidget()->clearFocus(); + + if (simulscene->getMeterPerPx() == 0) { + QMessageBox::critical (this,tr("B\366ser Fehler!"),tr("Die Wegl\344nge pro Pixel darf nicht 0 sein!")); + return; + } + + if (simulscene->getProbeChargeItem()->getMasse(0) == 0) { + QMessageBox::critical (this,tr("B\366ser Fehler!"),tr("Die Masse der Probeladung darf nicht 0 sein!")); + return; + } + + statusBar()->showMessage(tr("Berechne Flugbahn. Bitte Warten ...")); + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + simulscene->startCalculation(); + + QApplication::restoreOverrideCursor(); + statusBar()->clearMessage(); } void lsim::startTimer() { if( qApp->focusWidget() !=0) qApp->focusWidget()->clearFocus(); diff --git a/src/lsim.h b/src/lsim.h index de30d3a..912805a 100644 --- a/src/lsim.h +++ b/src/lsim.h @@ -96,6 +96,7 @@ class lsim: public QMainWindow { QAction *itemEditModeAct; QAction *insertEFieldItemAct; QAction *insertBFieldItemAct; + QAction *insertStopperItemAct; QAction *probeChargeItemPlaceAct; }; Actions acts; diff --git a/src/probechargewidget.cpp b/src/probechargewidget.cpp index 400a90d..69699cf 100644 --- a/src/probechargewidget.cpp +++ b/src/probechargewidget.cpp @@ -25,6 +25,7 @@ #include #include #include +#include ProbeChargeWidget::ProbeChargeWidget ( QWidget* parent, Qt::WindowFlags f, GraphicsEllipseItem* ellipse ) : QWidget (parent, f ) { ellipseItem = ellipse; @@ -47,7 +48,7 @@ void ProbeChargeWidget::createWidget() ExpDoubleSpinBox *startSpeedYBox = new ExpDoubleSpinBox; startSpeedYBox->setDecimals(50); startSpeedYBox->setDisplayDecimals(3); - startSpeedYBox->setRange(-3e+8, 3e+8); + startSpeedYBox->setRange(-(SPEED_OF_LIGHT-pow(10,-100)), SPEED_OF_LIGHT-pow(10,-100)); startSpeedYBox->setSuffix(" m/s"); startSpeedYBox->setKeyboardTracking(false); connect(startSpeedYBox, SIGNAL(valueChanged(double)), ellipseItem, SLOT(setStartSpeedY(double)) ); @@ -56,7 +57,7 @@ void ProbeChargeWidget::createWidget() ExpDoubleSpinBox *startSpeedXBox = new ExpDoubleSpinBox; startSpeedXBox->setDecimals(50); startSpeedXBox->setDisplayDecimals(3); - startSpeedXBox->setRange(-3e+8, 3e+8); + startSpeedXBox->setRange(-(SPEED_OF_LIGHT-pow(10,-100)), SPEED_OF_LIGHT-pow(10,-100)); startSpeedXBox->setSuffix(" m/s"); startSpeedXBox->setKeyboardTracking(false); connect(startSpeedXBox, SIGNAL(valueChanged(double)), ellipseItem, SLOT(setStartSpeedX(double)) ); diff --git a/src/simulscene.cpp b/src/simulscene.cpp index 455c20a..fb7672e 100644 --- a/src/simulscene.cpp +++ b/src/simulscene.cpp @@ -26,6 +26,7 @@ #include "graphicsellipseitem.h" #include "homoefielditem.h" #include "homobfielditem.h" +#include "stopperitem.h" #include #include #include @@ -40,7 +41,7 @@ SimulScene::SimulScene ( QObject* parent ) : QGraphicsScene ( parent ) { //variablen initialisieren - setTimePerStep(1e-7); + setTimePerStep(1e-10); setSteps(300000); //setMeterPerPx(1/1000.0); setMeterPerPx(0.01); @@ -51,6 +52,8 @@ SimulScene::SimulScene ( QObject* parent ) : QGraphicsScene ( parent ) { currHomoEfieldEditItem = 0; currHomoBfieldInsertItem = 0; currHomoBfieldEditItem = 0; + currStopperInsertItem = 0; + currStopperEditItem = 0; ChargePlacementInProgress = false; createResizeRects(); @@ -61,7 +64,6 @@ SimulScene::SimulScene ( QObject* parent ) : QGraphicsScene ( parent ) { //pathItem1->setCacheMode(QGraphicsItem::DeviceCoordinateCache); setFlightPathVisible(); - addLine(0,-298,0,298,QPen(Qt::green, 1, Qt::SolidLine) )->setCacheMode(QGraphicsItem::DeviceCoordinateCache); addLine(-398,0,398,0,QPen(Qt::green, 1, Qt::SolidLine) )->setCacheMode(QGraphicsItem::DeviceCoordinateCache); @@ -124,6 +126,13 @@ void SimulScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) { addItem(currHomoEfieldInsertItem); QApplication::setOverrideCursor(QCursor(Qt::SizeFDiagCursor)); break; + case StopperItemInsert: + if (mouseEvent->button() != Qt::LeftButton) break; //benutze nur linke maustaste + currStopperInsertItem = new StopperItem(mouseEvent->scenePos() ,mouseEvent->scenePos()); + currStopperInsertItem->setZValue(getHighestZIndexFieldItems() + FieldZStep); //zValue setzen + addItem(currStopperInsertItem); + QApplication::setOverrideCursor(QCursor(Qt::SizeHorCursor)); + break; case HomoBFieldItemInsert: if (mouseEvent->button() != Qt::LeftButton) break; //benutze nur linke maustaste currHomoBfieldInsertItem = new HomoBFieldItem(QRectF(mouseEvent->scenePos(),mouseEvent->scenePos())); @@ -148,6 +157,10 @@ void SimulScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) { currHomoBfieldEditItem = qgraphicsitem_cast(selectedItems().first()); QApplication::setOverrideCursor(pressedResizeItem->cursor()); } + else if (selectedItems().first()->type() == StopperItem::Type) { + currStopperEditItem = qgraphicsitem_cast(selectedItems().first()); + QApplication::setOverrideCursor(pressedResizeItem->cursor()); + } } else { @@ -172,6 +185,17 @@ void SimulScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) { } } + if (currStopperInsertItem != 0) { + if (myMode == StopperItemInsert) { + QPointF point(currStopperInsertItem->getRectF().x(), currStopperInsertItem->getRectF().y()); + update(currStopperInsertItem->getRectF()); + if(point.x() <= mouseEvent->scenePos().x() && point.y() <= mouseEvent->scenePos().y()) { + currStopperInsertItem->setLine(QLineF(point, QPointF(mouseEvent->scenePos().x(),point.y() ))); + + } + + } + } else if (currHomoBfieldInsertItem != 0) { if (myMode == HomoBFieldItemInsert) { QPointF point(currHomoBfieldInsertItem->getRectF().x(), currHomoBfieldInsertItem->getRectF().y()); @@ -218,6 +242,47 @@ void SimulScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) { //resize rechtecke mitverschieben --> macht jetzt schon das Widget //if(mouseEvent->scenePos() != mouseEvent->lastScenePos()) displayResizeRects(true); + } + else if (currStopperEditItem != 0 ) { + + QGraphicsRectItem *pressedRectItem = qgraphicsitem_cast(pressedResizeItem); + QRectF currRect = currStopperEditItem->getRectF(); + QPointF pos = currStopperEditItem->pos(); + + //calculateItemResize(mouseEvent,pressedRectItem,currRect,newPos,StopperItem::MinimumWidth,StopperItem::Height); + qreal mouseDistanceX = mouseEvent->scenePos().x() - mouseEvent->lastScenePos().x(); + + + //aenderungen uebernehmen + if ( + pressedResizeItem == reRects.rightRezizeItem || + pressedResizeItem == reRects.rightTopResizeItem || + pressedResizeItem == reRects.rightBottomResizeItem + ) { + QPointF newPos = QPointF(pos.x()+currRect.width()+mouseDistanceX , pos.y()); + if (newPos.x() - pos.x() >= StopperItem::MinimumWidth) { + currRect.adjust(0,0, (mouseDistanceX),0); + currStopperEditItem->setRectF(currRect); + + //currStopperEditItem->setLine(QLineF(pos, newPos )); + } + } else if ( + pressedResizeItem == reRects.leftResizeItem || + pressedResizeItem == reRects.leftTopResizeItem || + pressedResizeItem == reRects.leftBottomResizeItem + ) { + if ( pos.x() - pos.x()+currRect.width()-mouseDistanceX >= StopperItem::MinimumWidth) { + currRect.adjust(0,0,-mouseDistanceX,0); + currStopperEditItem->setPos(pos.x()+mouseDistanceX,pos.y()); + currStopperEditItem->setRectF(currRect); + + //currStopperEditItem->setLine(QLineF(pos, newPos )); + } + + } + //resize rechtecke mitverschieben --> macht jetzt schon das Widget + //if(mouseEvent->scenePos() != mouseEvent->lastScenePos()) displayResizeRects(true); + } else if (ChargePlacementInProgress) { if (myMode == ProbeChargeItemPlace) { @@ -304,6 +369,41 @@ void SimulScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) { } update(); //moegliche darstellungsprobleme beseitigen QApplication::restoreOverrideCursor(); + } + else if (currStopperInsertItem != 0 && myMode == StopperItemInsert) { + if (currStopperInsertItem->getRectF().width() < StopperItem::MinimumWidth) { + //removeItem(currHomoEfieldInsertItem); //segmention fault in kombination mit delete? + delete currStopperInsertItem; //zu kleines feld loeschen + } else { + //setze Startpunkt des rechtecks auf 0,0, damit pos() richtig funktioniert + currStopperInsertItem->setVisible(false); //ausblenden, damit sich nix verschiebt + QRectF rect (currStopperInsertItem->getRectF()); + QPointF posPoint(rect.x(),rect.y()); + rect.setWidth(rect.width() - rect.x()); + rect.setHeight(rect.height() - rect.y()); + rect.setX(0); + rect.setY(0); + currStopperInsertItem->setRectF(rect); + currStopperInsertItem->setPos(posPoint); + currStopperInsertItem->setVisible(true); //und wieder einblenden + + + setSceneMode(FieldItemEdit); + //das neue item auswaehlen + clearSelection(); + currStopperInsertItem->setSelected(true); + + //die resize items aus und einblenden bei rotation + connect( currStopperInsertItem, SIGNAL(rotationChanged()), this, SLOT(displayResizeRects())); + //bei groesenanderung und verschieben resizerects mitverschieben + connect( currStopperInsertItem, SIGNAL(heightChanged(double)), this, SLOT(moveResizeRects())); + connect( currStopperInsertItem, SIGNAL(widthChanged(double)), this, SLOT(moveResizeRects())); + connect( currStopperInsertItem, SIGNAL(ScenePosChanged(QPointF)), this, SLOT(moveResizeRects())); + //item ueber sceneChange informieren + connect(this,SIGNAL(changed(QList)),currStopperInsertItem,SLOT(handleSceneChange(QList))); + } + update(); //moegliche darstellungsprobleme beseitigen + QApplication::restoreOverrideCursor(); } else if (currHomoEfieldEditItem != 0) { update(); @@ -313,6 +413,10 @@ void SimulScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) { update(); QApplication::restoreOverrideCursor(); } + else if (currStopperEditItem != 0) { + update(); + QApplication::restoreOverrideCursor(); + } else if (ChargePlacementInProgress) { ChargePlacementInProgress = false; setSceneMode(FieldItemEdit); @@ -322,6 +426,8 @@ void SimulScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) { currHomoBfieldInsertItem = 0; currHomoEfieldEditItem = 0; currHomoBfieldEditItem = 0; + currStopperInsertItem = 0; + currStopperEditItem = 0; QGraphicsScene::mouseReleaseEvent(mouseEvent); } @@ -916,4 +1022,8 @@ void SimulScene::moveSelectedFieldItemOnTop() { void SimulScene::moveSelectedFieldItemOnBottom() { if (selectedItems().isEmpty()) return; moveFieldItemOnBottom(selectedItems().first()); -} \ No newline at end of file +} + +GraphicsEllipseItem* SimulScene::getProbeChargeItem() { + return ellipse1; +} diff --git a/src/simulscene.h b/src/simulscene.h index cf8061e..5472899 100644 --- a/src/simulscene.h +++ b/src/simulscene.h @@ -21,18 +21,19 @@ #define SIMULSCENE_H #include +#include class QTimeLine; class HomoEFieldItem; class HomoBFieldItem; class QGraphicsRectItem; class QGraphicsItemGroup; -class GraphicsEllipseItem; class QGraphicsItemAnimation; class QGraphicsPathItem; class QPainterPath; class QListWidget; class FieldItem; +class StopperItem; /** @author Peter Dahlberg @@ -44,6 +45,7 @@ class SimulScene : public QGraphicsScene { HomoEFieldItemInsert, FieldItemEdit, HomoBFieldItemInsert, + StopperItemInsert, ProbeChargeItemPlace }; enum ItemType {ResizeRectItem}; @@ -74,6 +76,8 @@ class SimulScene : public QGraphicsScene { QList getItemsInZOrder(); QList getFieldItemsInZOrder(); + GraphicsEllipseItem* getProbeChargeItem(); + public slots: void setSceneMode(SceneMode mode); void startTimer(); @@ -115,7 +119,7 @@ class SimulScene : public QGraphicsScene { SceneMode myMode; - ///Zeit pro Step in ms + ///Zeit pro Step in sekunden double timePerStep; ///anzahl der Steps int steps; @@ -128,6 +132,9 @@ class SimulScene : public QGraphicsScene { HomoBFieldItem *currHomoBfieldInsertItem; //Aktuell erstelltes Item HomoBFieldItem *currHomoBfieldEditItem; + StopperItem *currStopperInsertItem; //Aktuell erstelltes Item + StopperItem *currStopperEditItem; + bool ChargePlacementInProgress; //ladung wird gerade platziert QGraphicsItem *pressedResizeItem; diff --git a/src/src.pro b/src/src.pro index 0dda31e..a506314 100644 --- a/src/src.pro +++ b/src/src.pro @@ -9,7 +9,9 @@ SOURCES += lsim.cpp \ homoefieldwidget.cpp \ probechargewidget.cpp \ homobfielditem.cpp \ - homobfieldwidget.cpp + homobfieldwidget.cpp \ + stopperitem.cpp \ + stopperwidget.cpp HEADERS += lsim.h \ graphicsview.h \ graphicsellipseitem.h \ @@ -21,7 +23,9 @@ HEADERS += lsim.h \ constants.h \ probechargewidget.h \ homobfielditem.h \ - homobfieldwidget.h + homobfieldwidget.h \ + stopperitem.h \ + stopperwidget.h TEMPLATE = app CONFIG += warn_on \ thread \ diff --git a/src/stopperitem.cpp b/src/stopperitem.cpp new file mode 100644 index 0000000..347c7c1 --- /dev/null +++ b/src/stopperitem.cpp @@ -0,0 +1,81 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ +#include "stopperitem.h" +#include +#include +#include +#include +#include +#include "stopperwidget.h" + + +StopperItem::StopperItem(QPointF start, QPointF end): FieldItem() { + setLine(QLineF(start,end)); + stopperWidget = new StopperWidget(0,0,this); + setOuterPenWidth (2); + setFlag(ItemIsMovable); + setFlag(ItemIsSelectable); + setFlag(ItemIsFocusable); +} + + +StopperItem::~StopperItem() { + +} + +QRectF StopperItem::boundingRect() const { + return QRectF(sizeRect.x() - outerPenWidth, sizeRect.y() - outerPenWidth, + sizeRect.width() + outerPenWidth, sizeRect.height() + outerPenWidth); +} + +void StopperItem::setOuterPenWidth ( double theValue ) { + outerPenWidth = theValue; +} + + +double StopperItem::getOuterPenWidth() const { + return outerPenWidth; +} + +void StopperItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + QColor linecolor(172,214,255); + painter->setPen(linecolor); + if (isSelected()) { + painter->setBrush(Qt::Dense6Pattern); //selection deutlich machen + painter->drawRect(sizeRect); + } + + linecolor.setAlpha(188); + painter->setBrush(QBrush(linecolor)); + + painter->drawRect(sizeRect); +} + +int StopperItem::type() const { + return Type; +} + +QWidget* StopperItem::getDockWidget() const { + return stopperWidget; +} + +void StopperItem::setLine(QLineF line) { + setRectF(QRectF(line.p1(), QPointF(line.p2().x(),line.p2().y()+Height))); +} \ No newline at end of file diff --git a/src/stopperitem.h b/src/stopperitem.h new file mode 100644 index 0000000..8b288a3 --- /dev/null +++ b/src/stopperitem.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * 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 STOPPERITEM_H +#define STOPPERITEM_H + +#include + +/** + @author Peter Dahlberg +*/ +class QWidget; +class QPainter; +class QLineF; +class StopperWidget; +class StopperItem : public FieldItem +{ +Q_OBJECT +public: + enum {Type = UserType + 3}; + enum {MinimumWidth = 20}; + enum {Height = 10}; + StopperItem(QPointF start, QPointF end); + virtual QRectF boundingRect() const; + virtual void paint ( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ); + int type() const; + ///pointer auf das zugehoerige einstellungs Widget + QWidget* getDockWidget() const; + void setLine (QLineF line); + + ~StopperItem(); + + double getOuterPenWidth() const; + +public slots: + void setOuterPenWidth ( double theValue ); + + +private: + double outerPenWidth; + StopperWidget *stopperWidget; + +}; + +#endif diff --git a/src/stopperwidget.cpp b/src/stopperwidget.cpp new file mode 100644 index 0000000..f1ade1b --- /dev/null +++ b/src/stopperwidget.cpp @@ -0,0 +1,105 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ +#include "stopperwidget.h" +#include "stopperitem.h" +#include "expdoublespinbox.h" +#include +#include +#include +#include +#include +#include + +StopperWidget::StopperWidget(QWidget* parent, Qt::WindowFlags f, StopperItem* stopperI): QWidget() { + stopperItem = stopperI; + createWidget(); +} + + +StopperWidget::~StopperWidget() { +} + + + +void StopperWidget::createWidget() +{ + + QDoubleSpinBox *widthBox = new QDoubleSpinBox; + widthBox->setRange(StopperItem::MinimumWidth, 5000); + widthBox->setKeyboardTracking(false); + connect(stopperItem ,SIGNAL(widthChanged(double)),widthBox, SLOT(setValue(double)) ); + connect(widthBox, SIGNAL(valueChanged(double)),stopperItem ,SLOT(setRectFWidth(double)) ); + + QLabel* xLabel = new QLabel(tr("x:")); + QLabel* yLabel = new QLabel(tr("y:")); + QLabel* widthLabel = new QLabel(tr("Breite:")); + QLabel* rotationLabel = new QLabel(tr("Rotation:")); + + QDoubleSpinBox *posXBox = new QDoubleSpinBox; + posXBox->setRange(-5000, 5000); + posXBox->setKeyboardTracking(false); + connect(stopperItem ,SIGNAL(ScenePosXChanged(double)),posXBox, SLOT(setValue(double)) ); + connect(posXBox, SIGNAL(valueChanged(double)),stopperItem ,SLOT(setScenePosX(double)) ); + + QDoubleSpinBox *posYBox = new QDoubleSpinBox; + posYBox->setRange(-5000, 5000); + posYBox->setKeyboardTracking(false); + connect(stopperItem ,SIGNAL(ScenePosYChanged(double)),posYBox, SLOT(setValue(double)) ); + connect(posYBox, SIGNAL(valueChanged(double)),stopperItem ,SLOT(setScenePosY(double)) ); + + QSpinBox* rotationBox = new QSpinBox; + rotationBox->setRange(0,359); + rotationBox->setSuffix("\260"); + rotationBox->setWrapping(true); + rotationBox->setKeyboardTracking(false); + + connect(rotationBox, SIGNAL(valueChanged(int)),stopperItem ,SLOT(setRotation(int)) ); + connect(stopperItem, SIGNAL(rotationChanged(int)),rotationBox ,SLOT(setValue(int)) ); + + + QGridLayout* geomGridLayout = new QGridLayout; + //geomGridLayout->setSizeConstraint(QLayout::SetFixedSize); + + geomGridLayout->addWidget(rotationBox,0,1); + geomGridLayout->addWidget(posYBox,2,1); + geomGridLayout->addWidget(posXBox,1,1); + geomGridLayout->addWidget(xLabel,1,0,Qt::AlignRight); + geomGridLayout->addWidget(yLabel,2,0,Qt::AlignRight); + geomGridLayout->addWidget(widthLabel,3,0,Qt::AlignRight); + geomGridLayout->addWidget(rotationLabel,0,0,Qt::AlignRight); + geomGridLayout->addWidget(widthBox,3,1); + //geomGridLayout->addWidget(rotationDial, 1,0,2,2); + + QGroupBox* geometryBox = new QGroupBox(tr("Geometrie")); + geometryBox->setLayout(geomGridLayout); + + + + + QVBoxLayout * mainLayout = new QVBoxLayout(this); + mainLayout -> addWidget(geometryBox); + mainLayout -> addStretch(); + + QWidget::setTabOrder (rotationBox, posXBox); + QWidget::setTabOrder (posXBox, posYBox); + QWidget::setTabOrder (posYBox, widthBox); + + this -> setLayout(mainLayout); +} diff --git a/src/stopperwidget.h b/src/stopperwidget.h new file mode 100644 index 0000000..0a91065 --- /dev/null +++ b/src/stopperwidget.h @@ -0,0 +1,57 @@ +/*************************************************************************** + * 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 STOPPERWIDGET_H +#define STOPPERWIDGET_H + +#include + +//! Dock Widget fuer die Eigenschaften von StopperItem +/** + auf diesem Widget befinden sich Steuerelemente, mit denen man + die Eigenschaften von einem StopperItem manipulieren kann. + + @author Peter Dahlberg +*/ + +class StopperItem; +class StopperWidget : public QWidget { + Q_OBJECT +public: + //! Erzeugt ein neues StopperWidget + /*! + \param parent Parent Widget, see Qt Documentaion + \param f Window Flags, see Qt Documentaion + \param eField StopperItem, zu dem das StopperWidget zugeordnet werden soll + */ + StopperWidget(QWidget* parent, Qt::WindowFlags f, StopperItem* stopperI); + + virtual ~StopperWidget(); + private: + //!enthält einen Zeiger auf das zugeordnete StopperItem + StopperItem* stopperItem; + //! Erstellt die Steuerelemente + /*! + Wird von Konstruktor aufgerufen, um die Steuerelemente zu erzeugen + */ + void createWidget(); + +}; + +#endif