Skip to content

Commit

Permalink
Added the code to resize the components.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6976 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Nov 12, 2010
1 parent f81e029 commit 7c823c0
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 51 deletions.
25 changes: 12 additions & 13 deletions OMEdit/OMEditGUI/Component.cpp
Expand Up @@ -331,19 +331,19 @@ void Component::createSelectionBox()

mpTopLeftCornerItem = new CornerItem(x1, y2, Qt::TopLeftCorner, this);
connect(mpTopLeftCornerItem, SIGNAL(iconSelected()), this, SLOT(showSelectionBox()));
connect(mpTopLeftCornerItem, SIGNAL(iconResized(qreal, qreal)), this, SLOT(resizeIcon(qreal, qreal)));
connect(mpTopLeftCornerItem, SIGNAL(iconResized(qreal, qreal)), this, SLOT(resizeComponent(qreal, qreal)));
// create top right selection box
mpTopRightCornerItem = new CornerItem(x2, y2, Qt::TopRightCorner, this);
connect(mpTopRightCornerItem, SIGNAL(iconSelected()), this, SLOT(showSelectionBox()));
connect(mpTopRightCornerItem, SIGNAL(iconResized(qreal, qreal)), this, SLOT(resizeIcon(qreal, qreal)));
connect(mpTopRightCornerItem, SIGNAL(iconResized(qreal, qreal)), this, SLOT(resizeComponent(qreal, qreal)));
// create bottom left selection box
mpBottomLeftCornerItem = new CornerItem(x1, y1, Qt::BottomLeftCorner, this);
connect(mpBottomLeftCornerItem, SIGNAL(iconSelected()), this, SLOT(showSelectionBox()));
connect(mpBottomLeftCornerItem, SIGNAL(iconResized(qreal, qreal)), this, SLOT(resizeIcon(qreal, qreal)));
connect(mpBottomLeftCornerItem, SIGNAL(iconResized(qreal, qreal)), this, SLOT(resizeComponent(qreal, qreal)));
// create bottom right selection box
mpBottomRightCornerItem = new CornerItem(x2, y1, Qt::BottomRightCorner, this);
connect(mpBottomRightCornerItem, SIGNAL(iconSelected()), this, SLOT(showSelectionBox()));
connect(mpBottomRightCornerItem, SIGNAL(iconResized(qreal, qreal)), this, SLOT(resizeIcon(qreal, qreal)));
connect(mpBottomRightCornerItem, SIGNAL(iconResized(qreal, qreal)), this, SLOT(resizeComponent(qreal, qreal)));
}

void Component::createActions()
Expand Down Expand Up @@ -459,10 +459,6 @@ QVariant Component::itemChange(GraphicsItemChange change, const QVariant &value)
emit componentRotated(true);
updateSelectionBox();
}
else if (change == QGraphicsItem::ItemScaleHasChanged)
{
emit componentScaled();
}
return value;
}

Expand Down Expand Up @@ -499,6 +495,8 @@ void Component::updateSelectionBox()
{
qreal x1, y1, x2, y2;
boundingRect().getCoords(&x1, &y1, &x2, &y2);


if (rotation() == 0)
{
mpBottomLeftCornerItem->updateCornerItem(x1, y1, Qt::BottomLeftCorner);
Expand Down Expand Up @@ -559,6 +557,9 @@ void Component::addConnector(Connector *item)

connect(this, SIGNAL(componentRotated(bool)), item, SLOT(drawConnector(bool)));
connect(this, SIGNAL(componentRotated(bool)), item, SLOT(updateConnectionAnnotationString()));

connect(this, SIGNAL(componentScaled()), item, SLOT(drawConnector()));
connect(this, SIGNAL(componentScaled()), item, SLOT(updateConnectionAnnotationString()));
}

void Component::updateAnnotationString()
Expand Down Expand Up @@ -594,14 +595,12 @@ void Component::updateAnnotationString()
annotationString);
}

void Component::resizeIcon(qreal resizeFactorX, qreal resizeFactorY)
void Component::resizeComponent(qreal resizeFactorX, qreal resizeFactorY)
{
if (resizeFactorX > 0 && resizeFactorY > 0)
{
prepareGeometryChange();
//this->scale(resizeFactorX, resizeFactorY);
update();
//updateSelectionBox();
this->scale(resizeFactorX, resizeFactorY);
emit componentScaled();
}
}

Expand Down
3 changes: 1 addition & 2 deletions OMEdit/OMEditGUI/Component.h
Expand Up @@ -143,8 +143,7 @@ class Component : public ShapeAnnotation
public slots:
void updateAnnotationString();
void showSelectionBox();
void resizeIcon(qreal resizeFactorX, qreal resizeFactorY);
//void renameIcon();
void resizeComponent(qreal resizeFactorX, qreal resizeFactorY);
void deleteMe();
void moveUp();
void moveDown();
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/ConnectorWidget.cpp
Expand Up @@ -493,7 +493,7 @@ ConnectorLine::ConnectorLine(qreal x1, qreal y1, qreal x2, qreal y2, int lineNum
this->mParentConnectorEndComponentConnected = false;
this->mActivePen = QPen(Qt::red);
this->mPassivePen = QPen(Qt::black);
this->mHoverPen = QPen(Qt::darkRed, 6.9);
this->mHoverPen = QPen(Qt::darkRed, 7);
}

//! Reimplementation of paint function. Removes the ugly dotted selection box.
Expand Down
49 changes: 26 additions & 23 deletions OMEdit/OMEditGUI/CornerItem.cpp
Expand Up @@ -154,18 +154,18 @@ void CornerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (this->mItemClicked)
{
static qreal resizeFactorX = 1.0;
static qreal resizeFactorY = 1.0;
qreal resizeFactorX = 1.0;
qreal resizeFactorY = 1.0;
switch (this->mCorner)
{
case Qt::TopLeftCorner:
{
if ((this->mClickPos.x() < event->pos().x()) or (this->mClickPos.y() > event->pos().y()))
if ((this->mClickPos.x() < event->pos().x()) and (this->mClickPos.y() > event->pos().y()))
{
resizeFactorX = this->mScaleDecrementBy;
resizeFactorY = this->mScaleDecrementBy;
}
else if ((this->mClickPos.x() > event->pos().x()) or (this->mClickPos.y() < event->pos().y()))
else if ((this->mClickPos.x() > event->pos().x()) and (this->mClickPos.y() < event->pos().y()))
{
resizeFactorX = this->mScaleIncrementBy;
resizeFactorY = this->mScaleIncrementBy;
Expand All @@ -174,41 +174,44 @@ void CornerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}
case Qt::TopRightCorner:
{
if (this->mClickPos.x() < event->pos().x())
resizeFactorX = this->mScaleIncrementBy;
else if (this->mClickPos.x() > event->pos().x())
if ((this->mClickPos.x() > event->pos().x()) and (this->mClickPos.y() > event->pos().y()))
{
resizeFactorX = this->mScaleDecrementBy;

if (this->mClickPos.y() < event->pos().y())
resizeFactorY = this->mScaleIncrementBy;
else if (this->mClickPos.y() > event->pos().y())
resizeFactorY = this->mScaleDecrementBy;
}
else if ((this->mClickPos.x() < event->pos().x()) and (this->mClickPos.y() < event->pos().y()))
{
resizeFactorX = this->mScaleIncrementBy;
resizeFactorY = this->mScaleIncrementBy;
}
break;
}
case Qt::BottomLeftCorner:
{
if (this->mClickPos.x() < event->pos().x())
if ((this->mClickPos.x() < event->pos().x()) and (this->mClickPos.y() < event->pos().y()))
{
resizeFactorX = this->mScaleDecrementBy;
else if (this->mClickPos.x() > event->pos().x())
resizeFactorX = this->mScaleIncrementBy;

if (this->mClickPos.y() < event->pos().y())
resizeFactorY = this->mScaleDecrementBy;
else if (this->mClickPos.y() > event->pos().y())
}
else if ((this->mClickPos.x() > event->pos().x()) and (this->mClickPos.y() > event->pos().y()))
{
resizeFactorX = this->mScaleIncrementBy;
resizeFactorY = this->mScaleIncrementBy;
}
break;
}
case Qt::BottomRightCorner:
{
if (this->mClickPos.x() < event->pos().x())
resizeFactorX = this->mScaleIncrementBy;
else if (this->mClickPos.x() > event->pos().x())
if ((this->mClickPos.x() > event->pos().x()) and (this->mClickPos.y() < event->pos().y()))
{
resizeFactorX = this->mScaleDecrementBy;

if (this->mClickPos.y() < event->pos().y())
resizeFactorY = this->mScaleDecrementBy;
else if (this->mClickPos.y() > event->pos().y())
}
else if ((this->mClickPos.x() < event->pos().x()) and (this->mClickPos.y() > event->pos().y()))
{
resizeFactorX = this->mScaleIncrementBy;
resizeFactorY = this->mScaleIncrementBy;
}
break;
}
}
Expand Down
20 changes: 10 additions & 10 deletions OMEdit/OMEditGUI/ProjectTabWidget.cpp
Expand Up @@ -66,6 +66,7 @@ GraphicsView::GraphicsView(ProjectTab *parent)
this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
this->setSceneRect(-100.0, -100.0, 200.0, 200.0);
this->scale(2.0, -2.0);
this->centerOn(this->sceneRect().center());
this->createActions();
this->createMenus();

Expand Down Expand Up @@ -192,11 +193,6 @@ void GraphicsView::dropEvent(QDropEvent *event)
}
}

Connector* GraphicsView::getConnector()
{
return mpConnector;
}

void GraphicsView::addComponentObject(Component *component)
{
MainWindow *pMainWindow = mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow;
Expand Down Expand Up @@ -538,7 +534,7 @@ void GraphicsView::resetZoom()
void GraphicsView::zoomIn()
{
//this->scale(1.15, 1.15);
this->scale(2.0, 2.0);
this->scale(1.12, 1.12);
}

//! Decreases zoom factor by 13.04% (1 - 1/1.15).
Expand All @@ -547,7 +543,7 @@ void GraphicsView::zoomIn()
void GraphicsView::zoomOut()
{
//if (transform().m11() != 2.0 and transform().m22() != -2.0)
this->scale(0.5, 0.5);
this->scale(1/1.12, 1/1.12);
}

void GraphicsView::showGridLines(bool showLines)
Expand Down Expand Up @@ -883,8 +879,9 @@ void ProjectTab::getModelComponents()
{
// Check if the icon is already loaded.
QString iconName;
iconName = mpGraphicsView->getUniqueComponentName(StringHandler::getLastWordAfterDot(
componentProperties->getClassName()).toLower());
// iconName = mpGraphicsView->getUniqueComponentName(StringHandler::getLastWordAfterDot(
// componentProperties->getClassName()).toLower());
iconName = componentProperties->getName();

if (!oldComponent)
{
Expand All @@ -909,7 +906,10 @@ void ProjectTab::getModelComponents()
{
newComponent->mTransformationString = componentsAnnotationsList.at(i);
Transformation *transformation = new Transformation(newComponent);
newComponent->setTransform(transformation->getTransformationMatrix());
//newComponent->setTransform(transformation->getTransformationMatrix());
newComponent->setPos(transformation->mPositionX, transformation->mPositionY);
newComponent->setRotation(transformation->getRotateAngle());
//! @todo add the scaling code later on
}
i++;
}
Expand Down
1 change: 0 additions & 1 deletion OMEdit/OMEditGUI/ProjectTabWidget.h
Expand Up @@ -73,7 +73,6 @@ class GraphicsView : public QGraphicsView
void createMenus();
public:
GraphicsView(ProjectTab *parent = 0);
Connector *getConnector();
void addComponentObject(Component *icon);
void deleteComponentObject(Component *icon);
Component* getComponentObject(QString componentName);
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/mainwindow.cpp
Expand Up @@ -86,7 +86,7 @@ MainWindow::MainWindow(SplashScreen *splashScreen, QWidget *parent)
// Set the annotations version to 3.x
if (!mExitApplication)
{
//mpOMCProxy->setAnnotationVersion(OMCProxy::ANNOTATION_VERSION2X);
//mpOMCProxy->setAnnotationVersion(OMCProxy::ANNOTATION_VERSION3X);
}
// Loads and adds the OM Standard Library into the Library Widget.
splashScreen->showMessage("Loading Modelica Standard Library", Qt::AlignRight, Qt::white);
Expand Down

0 comments on commit 7c823c0

Please sign in to comment.