StopperItem fertig, wird aber noch nicht in berechnung einbezogen

git-svn-id: http://svn.lsim.tuxzone.org/trunk@20 4bec179b-ab65-46ed-a5f8-55b8b5c735d0
This commit is contained in:
catdog2
2008-11-21 23:56:10 +00:00
parent f01d249e27
commit cabf7af527
18 changed files with 519 additions and 49 deletions

View File

@@ -20,6 +20,7 @@
#include "fielditem.h"
#include "homoefielditem.h"
#include "homobfielditem.h"
#include "stopperitem.h"
#include "simulscene.h"
#include <QGraphicsSceneWheelEvent>
#include <QDebug>
@@ -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; i<fieldItemTypes.count();++i) {
if (item->type() == fieldItemTypes.at(i)) {

View File

@@ -28,6 +28,7 @@
#include "probechargewidget.h"
#include <cmath>
#include "constants.h"
#include <iostream>
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<<std::endl;
//qDebug()<< "Probe Path: " <<*currProbePath;

View File

@@ -201,3 +201,14 @@ void HomoBFieldItem::wheelEvent ( QGraphicsSceneWheelEvent * event )
{
event->ignore();
}
bool HomoBFieldItem::contains(const QPointF point) {
mapFromScene (point);
return (
(point.x() <= boundingRect().width()) &&
(point.y() <= boundingRect().height()) &&
(point.y() >=0) &&
(point.x() >=0)
);
}

View File

@@ -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;

View File

@@ -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)
);
}

View File

@@ -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);

View File

@@ -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();

View File

@@ -96,6 +96,7 @@ class lsim: public QMainWindow {
QAction *itemEditModeAct;
QAction *insertEFieldItemAct;
QAction *insertBFieldItemAct;
QAction *insertStopperItemAct;
QAction *probeChargeItemPlaceAct;
};
Actions acts;

View File

@@ -25,6 +25,7 @@
#include <QDial>
#include <QGroupBox>
#include <QLabel>
#include <constants.h>
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)) );

View File

@@ -26,6 +26,7 @@
#include "graphicsellipseitem.h"
#include "homoefielditem.h"
#include "homobfielditem.h"
#include "stopperitem.h"
#include <QRectF>
#include <QGraphicsSceneMouseEvent>
#include <QtDebug>
@@ -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<HomoBFieldItem *>(selectedItems().first());
QApplication::setOverrideCursor(pressedResizeItem->cursor());
}
else if (selectedItems().first()->type() == StopperItem::Type) {
currStopperEditItem = qgraphicsitem_cast<StopperItem *>(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<QGraphicsRectItem *>(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<QRectF>)),currStopperInsertItem,SLOT(handleSceneChange(QList<QRectF>)));
}
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());
}
}
GraphicsEllipseItem* SimulScene::getProbeChargeItem() {
return ellipse1;
}

View File

@@ -21,18 +21,19 @@
#define SIMULSCENE_H
#include <QGraphicsScene>
#include <graphicsellipseitem.h>
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 <pdahlberg@gmail.com>
@@ -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<QGraphicsItem*> getItemsInZOrder();
QList<QGraphicsItem*> 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;

View File

@@ -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 \

81
src/stopperitem.cpp Normal file
View File

@@ -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 <QWidget>
#include <QPainter>
#include <cmath>
#include <QPointF>
#include <QColor>
#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)));
}

61
src/stopperitem.h Normal file
View File

@@ -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 <fielditem.h>
/**
@author Peter Dahlberg <pdahlberg@gmail.com>
*/
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

105
src/stopperwidget.cpp Normal file
View File

@@ -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 <QVBoxLayout>
#include <QtDebug>
#include <QDial>
#include <QGroupBox>
#include <QLabel>
#include <QDoubleSpinBox>
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);
}

57
src/stopperwidget.h Normal file
View File

@@ -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 <QWidget>
//! 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 <pdahlberg@gmail.com>
*/
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&auml;lt einen Zeiger auf das zugeordnete StopperItem
StopperItem* stopperItem;
//! Erstellt die Steuerelemente
/*!
Wird von Konstruktor aufgerufen, um die Steuerelemente zu erzeugen
*/
void createWidget();
};
#endif