Skip to content

Commit

Permalink
Better background colors for views.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Oct 14, 2015
1 parent 648e1a4 commit 52537d5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 141 deletions.
133 changes: 13 additions & 120 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -118,7 +118,6 @@ GraphicsView::GraphicsView(StringHandler::ViewType viewType, ModelWidget *parent
setExtentRectangle(left, bottom, right, top);
centerOn(sceneRect().center());
scale(1.0, -1.0); // invert the drawing area.
setStyleSheet(QString("QGraphicsView{background-color: lightGray;}"));
setIsCustomScale(false);
setAddClassAnnotationNeeded(false);
setIsCreatingConnection(false);
Expand All @@ -134,38 +133,13 @@ GraphicsView::GraphicsView(StringHandler::ViewType viewType, ModelWidget *parent
createActions();
}

StringHandler::ViewType GraphicsView::getViewType()
{
return mViewType;
}

ModelWidget* GraphicsView::getModelWidget()
{
return mpModelWidget;
}

CoOrdinateSystem* GraphicsView::getCoOrdinateSystem()
{
return mpCoOrdinateSystem;
}

void GraphicsView::setExtentRectangle(qreal left, qreal bottom, qreal right, qreal top)
{
mExtentRectangle = QRectF(left, bottom, fabs(left - right), fabs(bottom - top));
QRectF sceneRectangle = mExtentRectangle.adjusted(left * 2, bottom * 2, right * 2, top * 2);
setSceneRect(sceneRectangle);
}

void GraphicsView::setIsCustomScale(bool enable)
{
mIsCustomScale = enable;
}

bool GraphicsView::isCustomScale()
{
return mIsCustomScale;
}

void GraphicsView::setIsCreatingConnection(bool enable)
{
mIsCreatingConnection = enable;
Expand All @@ -177,11 +151,6 @@ void GraphicsView::setIsCreatingConnection(bool enable)
setItemsFlags(!enable);
}

bool GraphicsView::isCreatingConnection()
{
return mIsCreatingConnection;
}

void GraphicsView::setIsCreatingLineShape(bool enable)
{
mIsCreatingLineShape = enable;
Expand All @@ -194,11 +163,6 @@ void GraphicsView::setIsCreatingLineShape(bool enable)
updateUndoRedoActions(enable);
}

bool GraphicsView::isCreatingLineShape()
{
return mIsCreatingLineShape;
}

void GraphicsView::setIsCreatingPolygonShape(bool enable)
{
mIsCreatingPolygonShape = enable;
Expand All @@ -211,11 +175,6 @@ void GraphicsView::setIsCreatingPolygonShape(bool enable)
updateUndoRedoActions(enable);
}

bool GraphicsView::isCreatingPolygonShape()
{
return mIsCreatingPolygonShape;
}

void GraphicsView::setIsCreatingRectangleShape(bool enable)
{
mIsCreatingRectangleShape = enable;
Expand All @@ -228,11 +187,6 @@ void GraphicsView::setIsCreatingRectangleShape(bool enable)
updateUndoRedoActions(enable);
}

bool GraphicsView::isCreatingRectangleShape()
{
return mIsCreatingRectangleShape;
}

void GraphicsView::setIsCreatingEllipseShape(bool enable)
{
mIsCreatingEllipseShape = enable;
Expand All @@ -245,11 +199,6 @@ void GraphicsView::setIsCreatingEllipseShape(bool enable)
updateUndoRedoActions(enable);
}

bool GraphicsView::isCreatingEllipseShape()
{
return mIsCreatingEllipseShape;
}

void GraphicsView::setIsCreatingTextShape(bool enable)
{
mIsCreatingTextShape = enable;
Expand All @@ -262,11 +211,6 @@ void GraphicsView::setIsCreatingTextShape(bool enable)
updateUndoRedoActions(enable);
}

bool GraphicsView::isCreatingTextShape()
{
return mIsCreatingTextShape;
}

void GraphicsView::setIsCreatingBitmapShape(bool enable)
{
mIsCreatingBitmapShape = enable;
Expand All @@ -279,11 +223,6 @@ void GraphicsView::setIsCreatingBitmapShape(bool enable)
updateUndoRedoActions(enable);
}

bool GraphicsView::isCreatingBitmapShape()
{
return mIsCreatingBitmapShape;
}

void GraphicsView::setItemsFlags(bool enable)
{
// set components, shapes and connection flags accordingly
Expand Down Expand Up @@ -313,51 +252,6 @@ void GraphicsView::updateUndoRedoActions(bool enable)
}
}

void GraphicsView::setIsMovingComponentsAndShapes(bool enable)
{
mIsMovingComponentsAndShapes = enable;
}

bool GraphicsView::isMovingComponentsAndShapes()
{
return mIsMovingComponentsAndShapes;
}

QAction* GraphicsView::getDeleteConnectionAction()
{
return mpDeleteConnectionAction;
}

QAction* GraphicsView::getDeleteAction()
{
return mpDeleteAction;
}

QAction* GraphicsView::getDuplicateAction()
{
return mpDuplicateAction;
}

QAction* GraphicsView::getRotateClockwiseAction()
{
return mpRotateClockwiseAction;
}

QAction* GraphicsView::getRotateAntiClockwiseAction()
{
return mpRotateAntiClockwiseAction;
}

QAction* GraphicsView::getFlipHorizontalAction()
{
return mpFlipHorizontalAction;
}

QAction* GraphicsView::getFlipVerticalAction()
{
return mpFlipVerticalAction;
}

bool GraphicsView::addComponent(QString className, QPointF position)
{
MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow();
Expand Down Expand Up @@ -1488,30 +1382,34 @@ void GraphicsView::dropEvent(QDropEvent *event)

void GraphicsView::drawBackground(QPainter *painter, const QRectF &rect)
{
if (mSkipBackground)
if (mSkipBackground || mpModelWidget->getLibraryTreeItem()->isSystemLibrary()) {
return;
}
// draw scene rectangle white background
painter->setPen(Qt::NoPen);
if (mViewType == StringHandler::Icon) {
painter->setBrush(QBrush(QColor(229, 244, 255), Qt::SolidPattern));
} else {
painter->setBrush(QBrush(QColor(242, 242, 242), Qt::SolidPattern));
}
painter->drawRect(rect);
painter->setBrush(QBrush(Qt::white, Qt::SolidPattern));
painter->drawRect(getExtentRectangle());
if (mpModelWidget->getModelWidgetContainer()->isShowGridLines())
{
if (mpModelWidget->getModelWidgetContainer()->isShowGridLines()) {
painter->setBrush(Qt::NoBrush);
painter->setPen(QColor(229, 229, 229));
/* Draw left half vertical lines */
int horizontalGridStep = mpCoOrdinateSystem->getHorizontalGridStep() * 10;
qreal xAxisStep = 0;
qreal yAxisStep = rect.y();
xAxisStep -= horizontalGridStep;
while (xAxisStep > rect.left())
{
while (xAxisStep > rect.left()) {
painter->drawLine(QPointF(xAxisStep, yAxisStep), QPointF(xAxisStep, rect.bottom()));
xAxisStep -= horizontalGridStep;
}
/* Draw right half vertical lines */
xAxisStep = 0;
while (xAxisStep < rect.right())
{
while (xAxisStep < rect.right()) {
painter->drawLine(QPointF(xAxisStep, yAxisStep), QPointF(xAxisStep, rect.bottom()));
xAxisStep += horizontalGridStep;
}
Expand All @@ -1520,15 +1418,13 @@ void GraphicsView::drawBackground(QPainter *painter, const QRectF &rect)
xAxisStep = rect.x();
yAxisStep = 0;
yAxisStep += verticalGridStep;
while (yAxisStep < rect.bottom())
{
while (yAxisStep < rect.bottom()) {
painter->drawLine(QPointF(xAxisStep, yAxisStep), QPointF(rect.right(), yAxisStep));
yAxisStep += verticalGridStep;
}
/* Draw right half horizontal lines */
yAxisStep = 0;
while (yAxisStep > rect.top())
{
while (yAxisStep > rect.top()) {
painter->drawLine(QPointF(xAxisStep, yAxisStep), QPointF(rect.right(), yAxisStep));
yAxisStep -= verticalGridStep;
}
Expand Down Expand Up @@ -2285,9 +2181,6 @@ void ModelWidget::loadModelWidget()
mpDiagramGraphicsView->removeAllComponents();
mpDiagramGraphicsView->removeAllConnections();
mpDiagramGraphicsView->scene()->clear();
if (mpLibraryTreeItem->getNameStructure().compare("Modelica.Electrical.Analog.Basic.Resistor") == 0) {
qDebug() << mpLibraryTreeItem->getNameStructure();
}
getModelInheritedClasses(mpLibraryTreeItem);
drawModelInheritedClasses();
getModelIconDiagramShapes();
Expand Down
42 changes: 21 additions & 21 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h
Expand Up @@ -142,47 +142,47 @@ class GraphicsView : public QGraphicsView
public:
GraphicsView(StringHandler::ViewType viewType, ModelWidget *parent);
bool mSkipBackground; /* Do not draw the background rectangle */
StringHandler::ViewType getViewType();
ModelWidget* getModelWidget();
CoOrdinateSystem* getCoOrdinateSystem();
StringHandler::ViewType getViewType() {return mViewType;}
ModelWidget* getModelWidget() {return mpModelWidget;}
CoOrdinateSystem* getCoOrdinateSystem() {return mpCoOrdinateSystem;}
void setExtentRectangle(qreal x1, qreal y1, qreal x2, qreal y2);
QRectF getExtentRectangle() {return mExtentRectangle;}
void setIsCustomScale(bool enable);
bool isCustomScale();
void setIsCustomScale(bool enable) {mIsCustomScale = enable;}
bool isCustomScale() {return mIsCustomScale;}
void setAddClassAnnotationNeeded(bool needed) {mAddClassAnnotationNeeded = needed;}
bool isAddClassAnnotationNeeded() {return mAddClassAnnotationNeeded;}
void setIsCreatingConnection(bool enable);
bool isCreatingConnection();
bool isCreatingConnection() {return mIsCreatingConnection;}
void setIsCreatingLineShape(bool enable);
bool isCreatingLineShape();
bool isCreatingLineShape() {return mIsCreatingLineShape;}
void setIsCreatingPolygonShape(bool enable);
bool isCreatingPolygonShape();
bool isCreatingPolygonShape() {return mIsCreatingPolygonShape;}
void setIsCreatingRectangleShape(bool enable);
bool isCreatingRectangleShape();
bool isCreatingRectangleShape() {return mIsCreatingRectangleShape;}
void setIsCreatingEllipseShape(bool enable);
bool isCreatingEllipseShape();
bool isCreatingEllipseShape() {return mIsCreatingEllipseShape;}
void setIsCreatingTextShape(bool enable);
bool isCreatingTextShape();
bool isCreatingTextShape() {return mIsCreatingTextShape;}
void setIsCreatingBitmapShape(bool enable);
bool isCreatingBitmapShape();
bool isCreatingBitmapShape() {return mIsCreatingBitmapShape;}
void setItemsFlags(bool enable);
void updateUndoRedoActions(bool enable);
void setIsMovingComponentsAndShapes(bool enable);
bool isMovingComponentsAndShapes();
void setIsMovingComponentsAndShapes(bool enable) {mIsMovingComponentsAndShapes = enable;}
bool isMovingComponentsAndShapes() {return mIsMovingComponentsAndShapes;}
void setRenderingLibraryPixmap(bool renderingLibraryPixmap) {mRenderingLibraryPixmap = renderingLibraryPixmap;}
bool isRenderingLibraryPixmap() {return mRenderingLibraryPixmap;}
QList<ShapeAnnotation*> getShapesList() {return mShapesList;}
QAction* getDeleteConnectionAction();
QAction* getDeleteAction();
QAction* getDuplicateAction();
QAction* getDeleteConnectionAction() {return mpDeleteConnectionAction;}
QAction* getDeleteAction() {return mpDeleteAction;}
QAction* getDuplicateAction() {return mpDuplicateAction;}
QAction* getBringToFrontAction() {return mpBringToFrontAction;}
QAction* getBringForwardAction() {return mpBringForwardAction;}
QAction* getSendToBackAction() {return mpSendToBackAction;}
QAction* getSendBackwardAction() {return mpSendBackwardAction;}
QAction* getRotateClockwiseAction();
QAction* getRotateAntiClockwiseAction();
QAction* getFlipHorizontalAction();
QAction* getFlipVerticalAction();
QAction* getRotateClockwiseAction() {return mpRotateClockwiseAction;}
QAction* getRotateAntiClockwiseAction() {return mpRotateAntiClockwiseAction;}
QAction* getFlipHorizontalAction() {return mpFlipHorizontalAction;}
QAction* getFlipVerticalAction() {return mpFlipVerticalAction;}
bool addComponent(QString className, QPointF position);
void addComponentToView(QString name, LibraryTreeItem *pLibraryTreeItem, QString transformationString, QPointF position,
ComponentInfo *pComponentInfo, bool addObject = true, bool openingClass = false);
Expand Down

0 comments on commit 52537d5

Please sign in to comment.