Skip to content

Commit

Permalink
- Fixed the text annotation resize problem. Although still requires s…
Browse files Browse the repository at this point in the history
…ome improvement.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7976 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Feb 21, 2011
1 parent 4558e28 commit 58e39c4
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 182 deletions.
25 changes: 3 additions & 22 deletions OMEdit/OMEditGUI/BitmapAnnotation.cpp
Expand Up @@ -75,17 +75,7 @@ QRectF BitmapAnnotation::boundingRect() const
QPainterPath BitmapAnnotation::shape() const
{
QPainterPath path;
QPointF p1 = this->mExtent.at(0);
QPointF p2 = this->mExtent.at(1);

qreal left = qMin(p1.x(), p2.x());
qreal top = qMin(p1.y(), p2.y());
qreal width = fabs(p1.x() - p2.x());
qreal height = fabs(p1.y() - p2.y());

QRectF rect (left, top, width, height);
path.addRoundedRect(rect, mCornerRadius, mCornerRadius);

path.addRoundedRect(getBoundingRect(), mCornerRadius, mCornerRadius);
return path;
}

Expand All @@ -94,27 +84,18 @@ void BitmapAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *
Q_UNUSED(option);
Q_UNUSED(widget);

QPointF p1 = this->mExtent.at(0);
QPointF p2 = this->mExtent.at(1);

qreal left = qMin(p1.x(), p2.x());
qreal top = qMin(p1.y(), p2.y());
qreal width = fabs(p1.x() - p2.x());
qreal height = fabs(p1.y() - p2.y());
QRectF rect (left, top, width, height);

if(!mImageSource.isEmpty())
{
//open file from image source
QByteArray data = QByteArray::fromBase64(mImageSource.toLatin1());
QImage image;
if(image.loadFromData(data))
painter->drawImage(rect, image.mirrored());
painter->drawImage(getBoundingRect(), image.mirrored());
}
else
{
QImage image(mFileName);
painter->drawImage(rect, image.mirrored());
painter->drawImage(getBoundingRect(), image.mirrored());
}
}

Expand Down
39 changes: 7 additions & 32 deletions OMEdit/OMEditGUI/EllipseAnnotation.cpp
Expand Up @@ -63,30 +63,14 @@ EllipseAnnotation::EllipseAnnotation(QString shape, GraphicsView *graphicsView,

QRectF EllipseAnnotation::boundingRect() const
{
// if ((mExtent.size() < 2) or (mIsCustomRectangle and !mIsFinishedCreatingRectangle))
// return QRectF();
// else
// return QRectF(mExtent.at(0), mExtent.at(1));
return shape().boundingRect();
}

QPainterPath EllipseAnnotation::shape() const
{
QPainterPath path;
QPointF p1 = this->mExtent.at(0);
QPointF p2 = this->mExtent.at(1);

qreal left = qMin(p1.x(), p2.x());
qreal top = qMin(p1.y(), p2.y());
qreal width = fabs(p1.x() - p2.x());
qreal height = fabs(p1.y() - p2.y());

QRectF ellipse (left, top, width, height);
path.addEllipse(ellipse);

QPainterPathStroker stroker;
stroker.setWidth(Helper::shapesStrokeWidth);
return stroker.createStroke(path);
path.addEllipse(getBoundingRect());
return addPathStroker(path);
}

void EllipseAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Expand All @@ -101,21 +85,11 @@ void EllipseAnnotation::drawEllipseAnnotaion(QPainter *painter)
{
QPainterPath path;

QPointF p1 = this->mExtent.at(0);
QPointF p2 = this->mExtent.at(1);

qreal left = qMin(p1.x(), p2.x());
qreal top = qMin(p1.y(), p2.y());
qreal width = fabs(p1.x() - p2.x());
qreal height = fabs(p1.y() - p2.y());

QRectF ellipse (left, top, width, height);

switch (this->mFillPattern)
{
case Qt::LinearGradientPattern:
{
QLinearGradient gradient(ellipse.center().x(), ellipse.center().y(), ellipse.center().x(), ellipse.y());
QLinearGradient gradient(boundingRect().center().x(), boundingRect().center().y(), boundingRect().center().x(), boundingRect().y());
gradient.setColorAt(0.0, this->mFillColor);
gradient.setColorAt(1.0, this->mLineColor);
gradient.setSpread(QGradient::ReflectSpread);
Expand All @@ -124,7 +98,8 @@ void EllipseAnnotation::drawEllipseAnnotaion(QPainter *painter)
}
case Qt::Dense1Pattern:
{
QLinearGradient gradient(ellipse.center().x(), ellipse.center().y(), ellipse.x(), ellipse.center().y());
QLinearGradient gradient(boundingRect().center().x(), boundingRect().center().y(),
boundingRect().x(), boundingRect().center().y());
gradient.setColorAt(0.0, this->mFillColor);
gradient.setColorAt(1.0, this->mLineColor);
gradient.setSpread(QGradient::ReflectSpread);
Expand All @@ -133,7 +108,7 @@ void EllipseAnnotation::drawEllipseAnnotaion(QPainter *painter)
}
case Qt::RadialGradientPattern:
{
QRadialGradient gradient(ellipse.center().x(), ellipse.center().y(), width);
QRadialGradient gradient(boundingRect().center().x(), boundingRect().center().y(), boundingRect().width());
gradient.setColorAt(0.0, this->mFillColor);
gradient.setColorAt(1.0, this->mLineColor);
gradient.setSpread(QGradient::ReflectSpread);
Expand All @@ -151,7 +126,7 @@ void EllipseAnnotation::drawEllipseAnnotaion(QPainter *painter)
pen.setCosmetic(true);
painter->setPen(pen);

path.addEllipse(ellipse);
path.addEllipse(boundingRect());
painter->drawPath(path);
}

Expand Down
5 changes: 5 additions & 0 deletions OMEdit/OMEditGUI/LibraryWidget.cpp
Expand Up @@ -818,6 +818,11 @@ SearchMSLWidget::SearchMSLWidget(MainWindow *pParent)
setLayout(verticalLayout);
}

MSLSearchBox* SearchMSLWidget::getMSLSearchTextBox()
{
return mpSearchTextBox;
}

void SearchMSLWidget::searchMSL()
{
// Remove the items from search tree
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/LibraryWidget.h
Expand Up @@ -163,6 +163,7 @@ class SearchMSLWidget : public QWidget
Q_OBJECT
public:
SearchMSLWidget(MainWindow *pParent = 0);
MSLSearchBox* getMSLSearchTextBox();

MainWindow *mpParentMainWindow;
private:
Expand Down
5 changes: 1 addition & 4 deletions OMEdit/OMEditGUI/LineAnnotation.cpp
Expand Up @@ -77,10 +77,7 @@ QPainterPath LineAnnotation::shape() const
path.moveTo(p1.x(), p1.y());
path.lineTo(p1.x(), p1.y());
}

QPainterPathStroker stroker;
stroker.setWidth(Helper::shapesStrokeWidth);
return stroker.createStroke(path);
return addPathStroker(path);
}

void LineAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Expand Down
5 changes: 1 addition & 4 deletions OMEdit/OMEditGUI/PolygonAnnotation.cpp
Expand Up @@ -70,10 +70,7 @@ QPainterPath PolygonAnnotation::shape() const
{
QPainterPath path;
path.addPolygon(QPolygonF(mPoints));

QPainterPathStroker stroker;
stroker.setWidth(Helper::shapesStrokeWidth);
return stroker.createStroke(path);
return addPathStroker(path);
}

void PolygonAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Expand Down
38 changes: 15 additions & 23 deletions OMEdit/OMEditGUI/ProjectTabWidget.cpp
Expand Up @@ -772,28 +772,20 @@ void GraphicsView::contextMenuEvent(QContextMenuEvent *event)
menu.exec(event->globalPos());
return; // return from it because at a time we only want one context menu.
}
// bool isFound = false;
// foreach (Component *pCompnent, mComponentsList)
// {
// if (pCompnent->isSelected())
// {
// isFound = true;
// break;
// }
// }
// // if no component is selected then show the graphics view context menu
// if (!isFound)
// {
// if (StringHandler::ICON == mIconType)
// {
// QMenu menu(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow);
// mpCancelConnectionAction->setText("Context Menu");
// menu.addAction(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->exportAsImage);
// menu.addAction(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->exportToOMNotebookAction);
// menu.exec(event->globalPos());
// return; // return from it because at a time we only want one context menu.
// }
// }
// if some item is right clicked then don't show graphics view context menu
ShapeAnnotation *pShape = static_cast<ShapeAnnotation*>(itemAt(event->pos()));
if (!pShape)
{
if (StringHandler::ICON == mIconType)
{
QMenu menu(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow);
mpCancelConnectionAction->setText("Context Menu");
menu.addAction(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->exportAsImage);
menu.addAction(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->exportToOMNotebookAction);
menu.exec(event->globalPos());
return; // return from it because at a time we only want one context menu.
}
}
QGraphicsView::contextMenuEvent(event);
}

Expand Down Expand Up @@ -1165,7 +1157,7 @@ ProjectTab::ProjectTab(int modelicaType, int iconType, bool readOnly, bool isChi

// create project status bar
mpProjectStatusBar = new QStatusBar;
mpProjectStatusBar->setObjectName(tr("PojectStatusBar"));
mpProjectStatusBar->setObjectName(tr("ProjectStatusBar"));
mpProjectStatusBar->setSizeGripEnabled(false);
mpProjectStatusBar->addPermanentWidget(viewsButtonsFrame, 5);
mpProjectStatusBar->addPermanentWidget(mpReadOnlyLabel, 6);
Expand Down
40 changes: 9 additions & 31 deletions OMEdit/OMEditGUI/RectangleAnnotation.cpp
Expand Up @@ -63,30 +63,14 @@ RectangleAnnotation::RectangleAnnotation(QString shape, GraphicsView *graphicsVi

QRectF RectangleAnnotation::boundingRect() const
{
// if ((mExtent.size() < 2) or (mIsCustomRectangle and !mIsFinishedCreatingRectangle))
// return QRectF();
// else
// return QRectF(mExtent.at(0), mExtent.at(1));
return shape().boundingRect();
}

QPainterPath RectangleAnnotation::shape() const
{
QPainterPath path;
QPointF p1 = this->mExtent.at(0);
QPointF p2 = this->mExtent.at(1);

qreal left = qMin(p1.x(), p2.x());
qreal top = qMin(p1.y(), p2.y());
qreal width = fabs(p1.x() - p2.x());
qreal height = fabs(p1.y() - p2.y());

QRectF rect (left, top, width, height);
path.addRoundedRect(rect, mCornerRadius, mCornerRadius);

QPainterPathStroker stroker;
stroker.setWidth(Helper::shapesStrokeWidth);
return stroker.createStroke(path);
path.addRoundedRect(getBoundingRect(), mCornerRadius, mCornerRadius);
return addPathStroker(path);
}

void RectangleAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Expand All @@ -100,21 +84,13 @@ void RectangleAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsIte
void RectangleAnnotation::drawRectangleAnnotaion(QPainter *painter)
{
QPainterPath path;
QPointF p1 = mExtent.at(0);
QPointF p2 = mExtent.at(1);

qreal left = qMin(p1.x(), p2.x());
qreal top = qMin(p1.y(), p2.y());
qreal width = fabs(p1.x() - p2.x());
qreal height = fabs(p1.y() - p2.y());

QRectF rect (left, top, width, height);

switch (this->mFillPattern)
{
case Qt::LinearGradientPattern:
{
QLinearGradient gradient(rect.center().x(), rect.center().y(), rect.center().x(), rect.y());
QLinearGradient gradient(getBoundingRect().center().x(), getBoundingRect().center().y(),
getBoundingRect().center().x(), getBoundingRect().y());
gradient.setColorAt(0.0, this->mFillColor);
gradient.setColorAt(1.0, this->mLineColor);
gradient.setSpread(QGradient::ReflectSpread);
Expand All @@ -123,7 +99,8 @@ void RectangleAnnotation::drawRectangleAnnotaion(QPainter *painter)
}
case Qt::Dense1Pattern:
{
QLinearGradient gradient(rect.center().x(), rect.center().y(), rect.x(), rect.center().y());
QLinearGradient gradient(getBoundingRect().center().x(), getBoundingRect().center().y(),
getBoundingRect().x(), getBoundingRect().center().y());
gradient.setColorAt(0.0, this->mFillColor);
gradient.setColorAt(1.0, this->mLineColor);
gradient.setSpread(QGradient::ReflectSpread);
Expand All @@ -132,7 +109,8 @@ void RectangleAnnotation::drawRectangleAnnotaion(QPainter *painter)
}
case Qt::RadialGradientPattern:
{
QRadialGradient gradient(rect.center().x(), rect.center().y(), width);
QRadialGradient gradient(getBoundingRect().center().x(), getBoundingRect().center().y(),
getBoundingRect().width());
gradient.setColorAt(0.0, this->mFillColor);
gradient.setColorAt(1.0, this->mLineColor);
gradient.setSpread(QGradient::ReflectSpread);
Expand All @@ -152,7 +130,7 @@ void RectangleAnnotation::drawRectangleAnnotaion(QPainter *painter)
pen.setCosmetic(true);
painter->setPen(pen);

path.addRoundedRect(rect, mCornerRadius, mCornerRadius);
path.addRoundedRect(getBoundingRect(), mCornerRadius, mCornerRadius);
painter->drawPath(path);
}

Expand Down
6 changes: 3 additions & 3 deletions OMEdit/OMEditGUI/Resources/css/stylesheet.qss
Expand Up @@ -38,16 +38,16 @@ QGraphicsView {
border: 1px solid gray;
}

QStatusBar#PojectStatusBar {
QStatusBar#ProjectStatusBar {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #d2d2d2, stop: 1 lightGray);
border: 1px solid gray;
}
QStatusBar#PojectStatusBar::item {
QStatusBar#ProjectStatusBar::item {
margin-top: -5px;
padding: 0px;
border-left: 1px solid gray;
}
QStatusBar#PojectStatusBar QLabel {
QStatusBar#ProjectStatusBar QLabel {
margin: 0px;
padding: 0px 0px 0px 1px;
}
Expand Down
20 changes: 20 additions & 0 deletions OMEdit/OMEditGUI/ShapeAnnotation.cpp
Expand Up @@ -126,6 +126,26 @@ QString ShapeAnnotation::getShapeAnnotation()
return QString();
}

QRectF ShapeAnnotation::getBoundingRect() const
{
QPointF p1 = mExtent.at(0);
QPointF p2 = mExtent.at(1);

qreal left = qMin(p1.x(), p2.x());
qreal top = qMin(p1.y(), p2.y());
qreal width = fabs(p1.x() - p2.x());
qreal height = fabs(p1.y() - p2.y());

return QRectF (left, top, width, height);
}

QPainterPath ShapeAnnotation::addPathStroker(QPainterPath &path) const
{
QPainterPathStroker stroker;
stroker.setWidth(Helper::shapesStrokeWidth);
return stroker.createStroke(path);
}

//! Tells the component to ask its parent to delete it.
void ShapeAnnotation::deleteMe()
{
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/ShapeAnnotation.h
Expand Up @@ -56,6 +56,8 @@ class ShapeAnnotation : public QObject, public QGraphicsItem
void setSelectionBoxPassive();
void setSelectionBoxHover();
virtual QString getShapeAnnotation();
QRectF getBoundingRect() const;
QPainterPath addPathStroker(QPainterPath &path) const;

GraphicsView *mpGraphicsView;
signals:
Expand Down

0 comments on commit 58e39c4

Please sign in to comment.