125 lines
4.0 KiB
C++
125 lines
4.0 KiB
C++
|
|
/***************************************************************************
|
||
|
|
* 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 "homoefielditem.h"
|
||
|
|
#include "homoefieldwidget.h"
|
||
|
|
#include <QPainter>
|
||
|
|
#include <cmath>
|
||
|
|
#include <QtDebug>
|
||
|
|
#include <QRectF>
|
||
|
|
|
||
|
|
HomoEFieldItem::HomoEFieldItem(QRectF sizeRect)
|
||
|
|
: FieldItem() {
|
||
|
|
setRectF(sizeRect);
|
||
|
|
dockWidget = new HomoEFieldWidget(0,0,this);
|
||
|
|
setFieldPower(2.8e+3);
|
||
|
|
setFieldLineDistance(10);
|
||
|
|
setFlag(ItemIsMovable);
|
||
|
|
setFlag(ItemIsSelectable);
|
||
|
|
setFlag(ItemIsFocusable);
|
||
|
|
outerPenWidth = 2;
|
||
|
|
//rotateslot(66);
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void HomoEFieldItem::setFieldLineDistance(int pixel) {
|
||
|
|
fieldLineDistance = pixel;
|
||
|
|
}
|
||
|
|
|
||
|
|
QRectF HomoEFieldItem::boundingRect() const {
|
||
|
|
return QRectF(sizeRect.x() - outerPenWidth, sizeRect.y() - outerPenWidth,
|
||
|
|
sizeRect.width() + outerPenWidth, sizeRect.height() + outerPenWidth);
|
||
|
|
}
|
||
|
|
|
||
|
|
void HomoEFieldItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
|
||
|
|
Qt::GlobalColor linecolor = Qt::blue;
|
||
|
|
painter->setPen(linecolor);
|
||
|
|
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 top_bottom_space = 10;
|
||
|
|
const int arrow_height = 8; //pfeilhoehe
|
||
|
|
const int arrow_width_half = 3; //Halbe pfeilbreite
|
||
|
|
|
||
|
|
if ((i*fieldLineDistance)+arrow_width_half >= sizeRect.width() -2) break; //rechts ueberstehen verhindern
|
||
|
|
if (sizeRect.height() < top_bottom_space + arrow_height) break;//nur zeichnen, wenn sizeRect hoch genug
|
||
|
|
|
||
|
|
//Feldlinien zeichnen
|
||
|
|
painter->drawLine(
|
||
|
|
sizeRect.x() + (i*fieldLineDistance) ,
|
||
|
|
sizeRect.y() +top_bottom_space ,
|
||
|
|
sizeRect.x() + (i*fieldLineDistance) ,
|
||
|
|
sizeRect.y() + sizeRect.height() - top_bottom_space
|
||
|
|
);
|
||
|
|
|
||
|
|
|
||
|
|
//Pfeile Zeichnen
|
||
|
|
QPointF arrows[3] = {
|
||
|
|
QPointF(sizeRect.x()+(i*fieldLineDistance), sizeRect.y()+sizeRect.height()-top_bottom_space),
|
||
|
|
QPointF(sizeRect.x()+(i*fieldLineDistance)-arrow_width_half,sizeRect.y()+sizeRect.height()-top_bottom_space-arrow_height),
|
||
|
|
QPointF(sizeRect.x()+(i*fieldLineDistance)+arrow_width_half,sizeRect.y()+sizeRect.height()-top_bottom_space-arrow_height),
|
||
|
|
};
|
||
|
|
painter->setBrush(linecolor);
|
||
|
|
painter->drawPolygon(arrows,3);
|
||
|
|
painter->setBrush(Qt::NoBrush);
|
||
|
|
|
||
|
|
//qDebug() << pos();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
int HomoEFieldItem::type() const {
|
||
|
|
return Type;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
HomoEFieldItem::~HomoEFieldItem() {
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/*!
|
||
|
|
\fn HomoEFieldItem::getDockWidget()
|
||
|
|
*/
|
||
|
|
QWidget * HomoEFieldItem::getDockWidget() const
|
||
|
|
{
|
||
|
|
return dockWidget;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
double HomoEFieldItem::getFieldPower() const {
|
||
|
|
return fieldPower;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void HomoEFieldItem::setFieldPower (double fieldPower ) {
|
||
|
|
//if (this->fieldPower == fieldPower) return;
|
||
|
|
this->fieldPower = fieldPower;
|
||
|
|
emit fieldPowerChanged(fieldPower);
|
||
|
|
}
|