Skip to content

Commit b38323a

Browse files
author
Henrik Eriksson
committed
Removed scrollbars from graphics area (not required with Qt 4.3.1)
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2878 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 40c3787 commit b38323a

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

OMNotebook/Pltpkg2/LegendLabel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class LegendLabel: public QLabel
6868
Q_OBJECT
6969

7070
public:
71-
LegendLabel(QColor color_, QString& s, QWidget* parent, bool showline, bool showpoints);
71+
LegendLabel(QColor color_, QString& s, QWidget* parent, bool showline, bool showpoints, int maxHeight);
7272
~LegendLabel();
7373

7474
void setCurve(Curve* c)

OMNotebook/Pltpkg2/graphScene.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class GraphScene: public QGraphicsScene
6363

6464
xRulerScene = new QGraphicsScene(this);
6565
yRulerScene = new QGraphicsScene(this);
66+
this->setSceneRect(0,0,.01,.01);
6667
}
6768

6869
~GraphScene()

OMNotebook/Pltpkg2/graphWidget.cpp

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,7 @@ GraphWidget::GraphWidget(QWidget* parent): QGraphicsView(parent)
120120
this->setMinimumHeight(150);
121121

122122
this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
123-
//this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //fjass
124-
// this->verticalScrollBar()->setMaximumWidth(1);
125-
this->verticalScrollBar()->setMinimumWidth(100);
126-
// this->verticalScrollBar()->hide();
123+
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
127124

128125
updateScaleFactors();
129126

@@ -213,9 +210,10 @@ GraphWidget::GraphWidget(QWidget* parent): QGraphicsView(parent)
213210
setZoom(true);
214211

215212

216-
//#if QT_VERSION >= 0x040300
217-
// setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing|QGraphicsView::DontSavePainterState);
218-
//#endif
213+
#if QT_VERSION >= 0x040300
214+
setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing|QGraphicsView::DontSavePainterState);
215+
// setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
216+
#endif
219217
}
220218

221219
void GraphWidget::originalZoom()
@@ -658,21 +656,28 @@ qreal GraphWidget::gridDist(qreal &min, qreal &max, qreal dist)
658656
{
659657

660658
distance = (max - min) / 10.;
659+
// distance = (max - min) / 8.;
661660

662661
qreal tmp = distance;
663662

664663
while(tmp < 1)
665664
tmp *= 10;
665+
// tmp *= 8;
666666

667667

668668
while(tmp > 10)
669669
tmp /= 10;
670+
// while(tmp > 8)
671+
// tmp /= 8;
670672

671673

672674
if(tmp > 5)
675+
// if(tmp > 4)
673676
distance = 10*distance/tmp;
677+
// distance = 8*distance/tmp;
674678
else if(tmp > 2)
675679
distance = 5*distance/tmp;
680+
// distance = 4*distance/tmp;
676681
else if(tmp > 1)
677682
distance = 2*distance/tmp;
678683
else
@@ -809,6 +814,11 @@ void GraphWidget::createGrid(bool numbersOnly)
809814
graphicsScene->grid->addToGroup(l);
810815
}
811816
QGraphicsTextItem* tmp2 = graphicsScene->xRulerScene->addText(QVariant(x).toString());
817+
if(abs(x) < xMinorDist)
818+
{
819+
tmp2->setPlainText("0");
820+
x = 0;
821+
}
812822
tmp2->setPos(gvBottom->mapToScene(mapFromScene(x, yMax)).x()-tmp2->boundingRect().width()/2, gvBottom->sceneRect().y());
813823
tmp2->moveBy(0, -tmp2->boundingRect().height()/2.);
814824
tmp2->show();
@@ -841,6 +851,7 @@ void GraphWidget::createGrid(bool numbersOnly)
841851
}
842852
}
843853
QGraphicsTextItem* tmp2 = graphicsScene->yRulerScene->addText(QString("1e") +QVariant(y).toString());
854+
844855
tmp2->setPos(gvLeft->mapToScene( gvLeft->sceneRect().x() ,mapFromScene(xMax, y).y()+tmp2->boundingRect().height()/2 ));
845856

846857
tmp2->scale(1, -1);
@@ -866,13 +877,18 @@ void GraphWidget::createGrid(bool numbersOnly)
866877
}
867878
for(qreal y = yMin-yMajorDist; y < 1.5* yMajorDist + yMax ; y+= yMajorDist)
868879
{
869-
if(abs(y) < 1e-16)
870-
y = 0;
880+
// if(abs(y) < 1e-16)
881+
// y = 0;
871882
if(!numbersOnly)
872883
{
873884
graphicsScene->grid->addToGroup(new Line2D(xMin2, y, xMax2, y, pen2));
874885
}
875886
QGraphicsTextItem* tmp2 = graphicsScene->yRulerScene->addText(QVariant(y).toString());
887+
if(abs(y) < yMinorDist)
888+
{
889+
tmp2->setPlainText("0");
890+
y = 0;
891+
}
876892
tmp2->setPos(gvLeft->mapToScene( gvLeft->sceneRect().x() ,mapFromScene(xMax, y).y()+tmp2->boundingRect().height()/2 ));
877893

878894
tmp2->scale(1, -1);
@@ -1576,6 +1592,8 @@ void GraphWidget::plotPtolemyDataStream()
15761592

15771593
LegendLabel* ll;
15781594

1595+
legendFrame->setMinimumWidth(0);
1596+
15791597
for(quint32 i = 0; i < variableCount; ++i)
15801598
{
15811599
ds >> tmp;
@@ -1607,12 +1625,22 @@ void GraphWidget::plotPtolemyDataStream()
16071625

16081626

16091627
yVars.push_back(tmp);
1610-
ll = new LegendLabel(color, tmp,legendFrame, !(interpolation_ == INTERPOLATION_NONE), points);
1628+
ll = new LegendLabel(color, tmp,legendFrame, !(interpolation_ == INTERPOLATION_NONE), points, 21);
16111629
ll->graphWidget = this;
16121630

1613-
ll->setMaximumHeight(21);
1631+
// ll->setMaximumHeight(21);
1632+
// ll->setMinimumWidth(0);
1633+
1634+
// if(!legendLayout->count() || true)
1635+
// {
1636+
// legendFrame->setMinimumWidth(ll->minimumWidth()+5);
1637+
legendFrame->setMinimumWidth(max(ll->fontMetrics().width(tmp)+41+4, legendFrame->minimumWidth()));
1638+
// QMessageBox::information(0, QVariant(legendFrame->minimumWidth()).toString(), QVariant(legendFrame->width()).toString());
1639+
// }
16141640
legendLayout->addWidget(ll);
16151641
ll->show();
1642+
1643+
16161644

16171645
temporaryCurves[tmp] = (new Curve(variables[currentXVar], variables[tmp], color, ll));
16181646
ll->setCurve(temporaryCurves[tmp]);

OMNotebook/Pltpkg2/legendLabel.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ licence: http://www.trolltech.com/products/qt/licensing.html
5353
#include "LegendLabel.h"
5454
#include "curve.h"
5555

56-
LegendLabel::LegendLabel(QColor color_, QString& s, QWidget* parent, bool showline, bool showpoints): QLabel(s, parent), color(color_)
56+
LegendLabel::LegendLabel(QColor color_, QString& s, QWidget* parent, bool showline, bool showpoints, int maxHeight): QLabel(s, parent), color(color_)
5757
{
5858
state = true;
5959
setContextMenuPolicy(Qt::ActionsContextMenu);
@@ -76,6 +76,10 @@ LegendLabel::LegendLabel(QColor color_, QString& s, QWidget* parent, bool showli
7676
connect(tmp, SIGNAL(triggered()), this, SLOT(selectColor()));
7777
addAction(tmp);
7878

79+
setMaximumHeight(maxHeight);
80+
81+
setMinimumWidth((fontMetrics().width(text())+height()+4));
82+
7983

8084

8185

@@ -150,7 +154,8 @@ void LegendLabel::render(QPainter* painter, QPointF pos)
150154
painter->drawEllipse(1, 1, max(0,height()-2), max(0,height()-2));
151155

152156
painter->setFont(font());
153-
setMinimumWidth(fontMetrics().width(text())+height()+4);
157+
// setMinimumWidth(fontMetrics().width(text())+height()+4);
158+
//setMinimumWidth(50);
154159
QRectF r = rect();
155160
r.setLeft(r.left() + height()+2);
156161
painter->drawText(r, Qt::AlignVCenter, text());

0 commit comments

Comments
 (0)