void FlowLayout::addItem(QGraphicsLayoutItem *item)
{
QGraphicsProxyWidget * gpw;
CustomObject * cp;
//We want to make sure that we are entering something to the layout that is ultimately a custom //object
//Hence, the dynamic casts with pointers that are never used for things other than null checks.
gpw = dynamic_cast<QGraphicsProxyWidget *>(item);
if(gpw != NULL)
{
cp = dynamic_cast<CustomObject *>(gpw->widget());
label = dynamic_cast<QLabel *>(gpw->widget());
if(cp != NULL)
{
//If we have a valid object, make this layout the parent and add it to the list!
item->setParentLayoutItem(this);
m_items.append(item);
}
else if(label != NULL)
{
item->setParentLayoutItem(this);
m_labels.insert(label->text(),item);
}
}
else
{
return ;
}
invalidate();
}
bool FlowLayout
::hasLabel(QString labelname
){ return m_labels.contains(labelname);
}
}
void FlowLayout::addItem(QGraphicsLayoutItem *item)
{
QGraphicsProxyWidget * gpw;
CustomObject * cp;
QLabel *label;
//We want to make sure that we are entering something to the layout that is ultimately a custom //object
//Hence, the dynamic casts with pointers that are never used for things other than null checks.
gpw = dynamic_cast<QGraphicsProxyWidget *>(item);
if(gpw != NULL)
{
cp = dynamic_cast<CustomObject *>(gpw->widget());
label = dynamic_cast<QLabel *>(gpw->widget());
if(cp != NULL)
{
//If we have a valid object, make this layout the parent and add it to the list!
item->setParentLayoutItem(this);
m_items.append(item);
}
else if(label != NULL)
{
item->setParentLayoutItem(this);
m_labels.insert(label->text(),item);
}
}
else
{
return ;
}
invalidate();
}
bool FlowLayout::hasLabel(QString labelname){
return m_labels.contains(labelname);
}
}
To copy to clipboard, switch view to plain text mode
//We now need to iterate through the list of items again so that we can place labels appropriately
for(int i = 0; i < m_items.count(); i++)
{
int j;
if(m_order == Normal)
{
j = i;
}
else
{
j = m_items.count()-(i+1);
}
//We take the next item from the list.
curritem = m_items.at(j);
//We know that this item is going to be a custom object pointer, so we can associate a pointer //with it
gpw = dynamic_cast<QGraphicsProxyWidget *>(curritem);
cp = dynamic_cast<CustomObject *>(gpw->widget());
labelitem = m_labels.value(cp->getRelatedSmartPointer()->getLabel());
labelproxy = dynamic_cast<QGraphicsProxyWidget *>(labelitem);
currlabel = dynamic_cast<QLabel *>(labelproxy->widget());
if(currlabel != NULL)
{
currlabel->setWordWrap(true);
currlabel->setAlignment(Qt::AlignBottom | Qt::AlignLeft);
qDebug("[%d]cast for %s with text [%s]", j, qPrintable(cp->getRelatedSmartPointer()->getLabel()), qPrintable(currlabel->text()));
labelitem
->setGeometry
(QRectF((qreal
) 100+50*i,
(qreal
) 100+50*i,curritem
->geometry
().
width(),curritem
->geometry
().
height()));
currlabel
->setMinimumSize
(QSize(curritem
->geometry
().
width(), curritem
->geometry
().
height()));
currlabel
->setMaximumSize
(QSize(curritem
->geometry
().
width(), curritem
->geometry
().
height()));
labelproxy
->setMinimumSize
(QSizeF(curritem
->geometry
().
width(), curritem
->geometry
().
height()));
labelproxy
->setPreferredSize
(QSizeF(curritem
->geometry
().
width(), curritem
->geometry
().
height()));
labelproxy
->setMaximumSize
(QSizeF(curritem
->geometry
().
width(), curritem
->geometry
().
height()));
labelitem
->setMinimumSize
(QSizeF(curritem
->geometry
().
width(), curritem
->geometry
().
height()));
labelitem
->setPreferredSize
(QSizeF(curritem
->geometry
().
width(), curritem
->geometry
().
height()));
labelitem
->setMaximumSize
(QSizeF(curritem
->geometry
().
width(), curritem
->geometry
().
height()));
currlabel->show();
qDebug("item[%d] (%lf,%lf,%lf,%lf)", j, curritem->geometry().x(),curritem->geometry().y(),curritem->geometry().width(),curritem->geometry().height());
qDebug("proxy[%d] (%lf,%lf,%lf,%lf)", j, labelproxy->geometry().x(),labelproxy->geometry().y(),labelproxy->geometry().width(),labelproxy->geometry().height());
}
}
//We now need to iterate through the list of items again so that we can place labels appropriately
for(int i = 0; i < m_items.count(); i++)
{
int j;
if(m_order == Normal)
{
j = i;
}
else
{
j = m_items.count()-(i+1);
}
//We take the next item from the list.
curritem = m_items.at(j);
//We know that this item is going to be a custom object pointer, so we can associate a pointer //with it
gpw = dynamic_cast<QGraphicsProxyWidget *>(curritem);
cp = dynamic_cast<CustomObject *>(gpw->widget());
labelitem = m_labels.value(cp->getRelatedSmartPointer()->getLabel());
labelproxy = dynamic_cast<QGraphicsProxyWidget *>(labelitem);
currlabel = dynamic_cast<QLabel *>(labelproxy->widget());
if(currlabel != NULL)
{
currlabel->setWordWrap(true);
currlabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
currlabel->setAlignment(Qt::AlignBottom | Qt::AlignLeft);
qDebug("[%d]cast for %s with text [%s]", j, qPrintable(cp->getRelatedSmartPointer()->getLabel()), qPrintable(currlabel->text()));
labelitem->setGeometry(QRectF((qreal) 100+50*i,(qreal) 100+50*i,curritem->geometry().width(),curritem->geometry().height()));
currlabel->setMinimumSize(QSize(curritem->geometry().width(), curritem->geometry().height()));
currlabel->setMaximumSize(QSize(curritem->geometry().width(), curritem->geometry().height()));
labelproxy->setMinimumSize(QSizeF(curritem->geometry().width(), curritem->geometry().height()));
labelproxy->setPreferredSize(QSizeF(curritem->geometry().width(), curritem->geometry().height()));
labelproxy->setMaximumSize(QSizeF(curritem->geometry().width(), curritem->geometry().height()));
labelproxy->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
labelitem->setMinimumSize(QSizeF(curritem->geometry().width(), curritem->geometry().height()));
labelitem->setPreferredSize(QSizeF(curritem->geometry().width(), curritem->geometry().height()));
labelitem->setMaximumSize(QSizeF(curritem->geometry().width(), curritem->geometry().height()));
labelitem->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
currlabel->show();
qDebug("item[%d] (%lf,%lf,%lf,%lf)", j, curritem->geometry().x(),curritem->geometry().y(),curritem->geometry().width(),curritem->geometry().height());
qDebug("proxy[%d] (%lf,%lf,%lf,%lf)", j, labelproxy->geometry().x(),labelproxy->geometry().y(),labelproxy->geometry().width(),labelproxy->geometry().height());
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks