|
From: Darius S. <dst...@us...> - 2001-07-24 11:29:10
|
Update of /cvsroot/kuml/kuml/kuml_gui/src/ige/common/views
In directory usw-pr-cvs1:/tmp/cvs-serv14475
Added Files:
SimpleLineView.h SimpleLineView.cpp
Log Message:
Added file
--- NEW FILE ---
/***************************************************************************
SimpleLineView.h - description
-------------------
begin : Tue July 24 2001
copyright : (C) 2001 by the kUML Team
author : Darius Stachow
email : sta...@in...
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef SIMPLELINEVIEW_H
#define SIMPLELINEVIEW_H
#include "LineView.h"
class SimpleLineView : public LineView {
public:
SimpleLineView(Viewer * viewer, View * parent = 0);
virtual ~SimpleLineView();
virtual QPoint& getStartPoint();
virtual void setStartPoint(const QPoint& startPoint);
virtual QPoint& getEndPoint();
virtual void setEndPoint(const QPoint& endPoint);
virtual QRect bounds();
virtual bool intersects(const QPoint & mousePos);
virtual QPoint getCenter();
virtual void setCenter(const QPoint& p);
virtual void move(const QPoint& delta);
virtual ViewManipulator* createManipulator();
protected:
virtual void paintContents(QPainter * painter);
public:
private:
QPoint startPoint;
QPoint endPoint;
};
#endif //SIMPLELINEVIEW_H
--- NEW FILE ---
/***************************************************************************
SimpleLineView.cpp - description
-------------------
begin : Tue July 24 2001
copyright : (C) 2001 by the kUML Team
author : Darius Stachow
email : sta...@in...
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "SimpleLineView.h"
#include "ige/common/MathUtility.h"
#include "ige/common/manipulators/LineViewResizer.h"
#include <qpainter.h>
void SimpleLineView::move(const QPoint& delta){
setStartPoint(getStartPoint() + delta);
setEndPoint(getEndPoint() + delta);
}
void SimpleLineView::setCenter(const QPoint& p){
qDebug("SimpleLineView::setCenter() not implemented!");
// rectangle.moveCenter(p);
}
QPoint SimpleLineView::getCenter(){
QRect rect(getStartPoint(), getEndPoint());
rect = rect.normalize();
return rect.center();
}
bool SimpleLineView::intersects(const QPoint &mousePos){
double r;
double r_distance, deg;
int x;
int y;
QPoint p1 = getStartPoint();
QPoint p2 = getEndPoint();
MathUtility::convertKartToPolar(p1.x() - p2.x(), p2.y() - p1.y(), r_distance, deg);
double r_touchRect;
double deg_touchRect;
QRect touchRect;
// This is the first touch rectangle in chain of rects
touchRect.setWidth(10);
touchRect.setHeight(10);
touchRect.moveCenter(p1);
// We want to know the distance from left bottom to the center of the touch rect
MathUtility::convertKartToPolar(touchRect.width(), touchRect.height(), r_touchRect, deg_touchRect);
r = r_touchRect;
r_touchRect /= 2;
while(r < r_distance) {
MathUtility::convertPolarToKart(r, deg, x, y);
touchRect.moveCenter(QPoint(p1.x()-x, p1.y()-y));
if(touchRect.contains(QPoint(mousePos.x(), mousePos.y()))) {
return true;
}
r += r_touchRect;
}
return false;
}
QRect SimpleLineView::bounds() {
QRect boundingRect(getStartPoint(), getEndPoint());
boundingRect = boundingRect.normalize();
return boundingRect;
}
void SimpleLineView::paintContents(QPainter * painter) {
painter->drawLine(getStartPoint(), getEndPoint());
}
void SimpleLineView::setEndPoint(const QPoint& endPoint){
this->endPoint = endPoint;
}
QPoint& SimpleLineView::getEndPoint(){
return endPoint;
}
void SimpleLineView::setStartPoint(const QPoint& startPoint){
this->startPoint = startPoint;
}
QPoint& SimpleLineView::getStartPoint(){
return startPoint;
}
SimpleLineView::~SimpleLineView(){
}
SimpleLineView::SimpleLineView(Viewer * viewer, View * parent) : LineView(viewer, parent) {
}
ViewManipulator* SimpleLineView::createManipulator() {
// qDebug("RectangleView::createManipulator() executed");
manipulator = new LineViewResizer(this);
return manipulator;
}
|