108 lines
3.8 KiB
C++
108 lines
3.8 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 "homobfielditem.h"
|
||
|
|
#include <cmath>
|
||
|
|
#include <QPainter>
|
||
|
|
|
||
|
|
HomoBFieldItem::HomoBFieldItem(QRectF sizeRect): FieldItem() {
|
||
|
|
setFieldLineDistance(10);
|
||
|
|
setFlag(ItemIsMovable);
|
||
|
|
setFlag(ItemIsSelectable);
|
||
|
|
setFlag(ItemIsFocusable);
|
||
|
|
setOuterPenWidth (2);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
HomoBFieldItem::~HomoBFieldItem()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
QRectF HomoBFieldItem::boundingRect() const {
|
||
|
|
return QRectF(sizeRect.x() - outerPenWidth, sizeRect.y() - outerPenWidth,
|
||
|
|
sizeRect.width() + outerPenWidth, sizeRect.height() + outerPenWidth);
|
||
|
|
}
|
||
|
|
|
||
|
|
QRectF HomoBFieldItem::getRectF() const
|
||
|
|
{
|
||
|
|
return FieldItem::getRectF();
|
||
|
|
}
|
||
|
|
|
||
|
|
void HomoBFieldItem::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 HomoBFieldItem::type() const {
|
||
|
|
return Type;
|
||
|
|
}
|
||
|
|
|
||
|
|
int HomoBFieldItem::getFieldLineDistance() const {
|
||
|
|
return fieldLineDistance;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void HomoBFieldItem::setFieldLineDistance ( int theValue ) {
|
||
|
|
if(fieldLineDistance == theValue) return;
|
||
|
|
fieldLineDistance = theValue;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
double HomoBFieldItem::getOuterPenWidth() const {
|
||
|
|
return outerPenWidth;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void HomoBFieldItem::setOuterPenWidth ( double theValue ) {
|
||
|
|
outerPenWidth = theValue;
|
||
|
|
}
|