From 4b0165545965ee34c9962120f738ff83480d676a Mon Sep 17 00:00:00 2001 From: catdog2 Date: Tue, 14 Oct 2008 21:22:24 +0000 Subject: [PATCH] HomoBFieldItem wird richtig als B-Feld gezeichnet git-svn-id: http://svn.lsim.tuxzone.org/trunk@6 4bec179b-ab65-46ed-a5f8-55b8b5c735d0 --- src/homobfielditem.cpp | 66 ++++++++++++++++++++++++++++++++++++++++-- src/homobfielditem.h | 10 +++++-- src/src.pro | 1 - 3 files changed, 72 insertions(+), 5 deletions(-) diff --git a/src/homobfielditem.cpp b/src/homobfielditem.cpp index 4a599f0..35a2445 100644 --- a/src/homobfielditem.cpp +++ b/src/homobfielditem.cpp @@ -21,6 +21,7 @@ #include #include #include +#include HomoBFieldItem::HomoBFieldItem(QRectF sizeRect): FieldItem() { setRectF(sizeRect); @@ -29,6 +30,7 @@ HomoBFieldItem::HomoBFieldItem(QRectF sizeRect): FieldItem() { setFlag(ItemIsSelectable); setFlag(ItemIsFocusable); setOuterPenWidth (2); + setIsDirectionIntoPlane(true); } @@ -53,7 +55,55 @@ void HomoBFieldItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* op if (isSelected()) painter->setBrush(Qt::Dense6Pattern); //selection deutlich machen painter->drawRect(sizeRect); - for (int i = 1; i <= floor(sizeRect.width()/(qreal)fieldLineDistance); ++i) { + const int x_arrow_width = 8; //laenge und breite des Pfeils + const int circle_arrow_width = 12; //laenge u. breite des kreispfeiles + + int arrow_width; + if (getIsDirectionIntoPlane()) arrow_width = x_arrow_width; + else arrow_width = circle_arrow_width; //arrow width an das jeweilige anpassen + for (int y = 1; y <= floor(sizeRect.height()/(qreal)(getFieldLineDistance()+arrow_width)); ++y ) { + //unten ueberstehen verhindern + if (-abs(sizeRect.y()) + y*getFieldLineDistance() + y*arrow_width >= sizeRect.height()-4 ) break; + for (int x = 1; x <= floor(sizeRect.width()/(qreal)(getFieldLineDistance()+arrow_width)); ++x ) { + //rechts ueberstehen verhindern + if (-abs(sizeRect.x()) + x*getFieldLineDistance() + x*arrow_width >= sizeRect.width()-4 ) break; + if (getIsDirectionIntoPlane()) { + painter->drawLine( + sizeRect.x() + x*getFieldLineDistance() + (x-1)*arrow_width, + sizeRect.y() + y*getFieldLineDistance() + (y-1)*arrow_width, + sizeRect.x() + x*getFieldLineDistance() + arrow_width + (x-1)*arrow_width, + sizeRect.y() + y*getFieldLineDistance() + arrow_width + (y-1)*arrow_width + ); + painter->drawLine( + sizeRect.x() + x*getFieldLineDistance() + arrow_width + (x-1)*arrow_width, + sizeRect.y() + y*getFieldLineDistance() + (y-1)*arrow_width, + sizeRect.x() + x*getFieldLineDistance() + (x-1)*arrow_width, + sizeRect.y() + y*getFieldLineDistance() + arrow_width + (y-1)*arrow_width + ); + } + else { + painter->drawEllipse( + sizeRect.x() + x*getFieldLineDistance() + (x-1)*arrow_width, + sizeRect.y() + y*getFieldLineDistance() + (y-1)*arrow_width, + arrow_width, + arrow_width + ); + painter->setBrush(linecolor); + painter->drawEllipse( + QPoint( + sizeRect.x() + x*getFieldLineDistance() + (x-1)*arrow_width + arrow_width/2.0, + sizeRect.y() + y*getFieldLineDistance() + (y-1)*arrow_width + arrow_width/2.0 + ), + 1, + 1 + ); + painter->setBrush(Qt::NoBrush); + } + } + } + + + /*for (int i = 1; i <= floor(sizeRect.width()/(qreal)fieldLineDistance); ++i) { const int top_bottom_space = 10; const int arrow_height = 8; //pfeilhoehe const int arrow_width_half = 3; //Halbe pfeilbreite @@ -81,7 +131,7 @@ void HomoBFieldItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* op painter->setBrush(Qt::NoBrush); //qDebug() << pos(); - } + }*/ } int HomoBFieldItem::type() const { @@ -111,3 +161,15 @@ void HomoBFieldItem::setOuterPenWidth ( double theValue ) { QWidget* HomoBFieldItem::getDockWidget() const { return new QWidget(); } + + +bool HomoBFieldItem::getIsDirectionIntoPlane() const { + return isDirectionIntoPlane; +} + + +void HomoBFieldItem::setIsDirectionIntoPlane ( bool theValue ) { + if(isDirectionIntoPlane == theValue) return; + isDirectionIntoPlane = theValue; + emit directionChanged(theValue); +} diff --git a/src/homobfielditem.h b/src/homobfielditem.h index 0cc0771..cdea010 100644 --- a/src/homobfielditem.h +++ b/src/homobfielditem.h @@ -46,17 +46,23 @@ class HomoBFieldItem : public FieldItem { QWidget* getDockWidget() const; double getOuterPenWidth() const; + bool getIsDirectionIntoPlane() const; public slots: void setOuterPenWidth ( double theValue ); void setFieldLineDistance ( int theValue ); - - + void setIsDirectionIntoPlane ( bool theValue ); + signals: + void directionChanged(bool theValue); private: //! Abstand der Feldlinien in der Zeichnung int fieldLineDistance; + double outerPenWidth; + //! Gibt an, ob das Feld in die Ebene Zeigt oder heraus (true == in die Ebene) + bool isDirectionIntoPlane; + }; #endif diff --git a/src/src.pro b/src/src.pro index b4f87bf..ecd1261 100644 --- a/src/src.pro +++ b/src/src.pro @@ -16,7 +16,6 @@ HEADERS += lsim.h \ homoefielditem.h \ simulscene.h \ expdoublespinbox.h \ - lsim_interface.h \ homoefieldwidget.h \ constants.h \ probechargewidget.h \