ok sure here is the code from the QPaintEvent and below it is the function that gets the user input:
{
int looplength=0;
foreach (ShapeItem shapeItem, shapeItems)
{
QPoint mid
(-shapeItem.
position());
//QPoint offset(7,13);
painter.translate(shapeItem.position());
painter.setBrush(shapeItem.color());
painter.drawPath(shapeItem.path());
painter.translate(-shapeItem.position());
painter.setPen(initialItemColor());
painter.drawText((shapeItem.position() + offset),tr("%1").arg(shapeItem.instanceNumber()));
list.position[shapeItem.instanceNumber()] = shapeItem.position();
list.nodeID[shapeItem.instanceNumber()] = shapeItem.instanceNumber();
looplength = shapeItem.instanceNumber();
}
midpoint = ((list.position[n1] + list.position[n2])/2);
if( drawLine == 1)
{
painter.setPen(myTextColor());
for(int j=0;j<looplength;j++)
/*{
if(list.nodeID[j]>0 && list.nodeID[j]<100)
{
painter.drawLine( list.position[list.nodeID[j]]+offset, list.position[list.nodeID[j+1]]+offset );
}
}*/
painter.drawLine( list.position[n1]+offset, list.position[n2]+offset );
painter.
drawText(QRect(midpoint,textbox
),
0,tr
("%1").
arg(topology
[n1
][n2
]));
}
}
void SortingBox::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
QPoint offset(7,13);
int looplength=0;
foreach (ShapeItem shapeItem, shapeItems)
{
QPoint mid(-shapeItem.position());
//QPoint offset(7,13);
QPoint text(100,100);
painter.translate(shapeItem.position());
painter.setBrush(shapeItem.color());
painter.drawPath(shapeItem.path());
painter.translate(-shapeItem.position());
painter.setPen(initialItemColor());
painter.drawText((shapeItem.position() + offset),tr("%1").arg(shapeItem.instanceNumber()));
list.position[shapeItem.instanceNumber()] = shapeItem.position();
list.nodeID[shapeItem.instanceNumber()] = shapeItem.instanceNumber();
looplength = shapeItem.instanceNumber();
}
QPoint midpoint;
midpoint = ((list.position[n1] + list.position[n2])/2);
QPoint test(100,100);
QSize textbox(100,100);
if( drawLine == 1)
{
painter.setPen(myTextColor());
for(int j=0;j<looplength;j++)
/*{
if(list.nodeID[j]>0 && list.nodeID[j]<100)
{
painter.drawLine( list.position[list.nodeID[j]]+offset, list.position[list.nodeID[j+1]]+offset );
}
}*/
painter.drawLine( list.position[n1]+offset, list.position[n2]+offset );
painter.drawText(QRect(midpoint,textbox),0,tr("%1").arg(topology[n1][n2]));
}
}
To copy to clipboard, switch view to plain text mode
function user input( )
void SortingBox::user_input()
{
drawLine = 1;
bool ok;
n1
= QInputDialog::getInteger(this, tr
("QInputDialog::getInteger()"),
tr("enter first node to link:"), 25, 0, 100, 1, &ok);
if(ok)
integerLabel->setText(tr("%1").arg(n1));
n2
= QInputDialog::getInteger(this, tr
("QInputDialog::getInteger()"),
tr("enter second node to link:"), 25, 0, 100, 1, &ok);
if(ok)
integerLabel->setText(tr("%1").arg(n2));
topology
[n1
][n2
] = QInputDialog::getInteger(this, tr
("QInputDialog::getInteger()"),
tr("required capacity:"), 25, 0, 100, 1, &ok);
if(ok)
integerLabel->setText(tr("%1").arg(topology[n1][n2]));
}
void SortingBox::user_input()
{
drawLine = 1;
QLabel *integerLabel = new QLabel(this);
bool ok;
n1 = QInputDialog::getInteger(this, tr("QInputDialog::getInteger()"),
tr("enter first node to link:"), 25, 0, 100, 1, &ok);
if(ok)
integerLabel->setText(tr("%1").arg(n1));
n2 = QInputDialog::getInteger(this, tr("QInputDialog::getInteger()"),
tr("enter second node to link:"), 25, 0, 100, 1, &ok);
if(ok)
integerLabel->setText(tr("%1").arg(n2));
topology[n1][n2] = QInputDialog::getInteger(this, tr("QInputDialog::getInteger()"),
tr("required capacity:"), 25, 0, 100, 1, &ok);
if(ok)
integerLabel->setText(tr("%1").arg(topology[n1][n2]));
}
To copy to clipboard, switch view to plain text mode
Bookmarks