void circleLayout
::setGeometry(const QRectF &r
) {
kDebug()<<"Set Geometry!!";
/*setting the real geometry*/
QGraphicsLayout::setGeometry(r);
/*taking the geometry*/
QRectF effectiveRect
= geometry
();
qreal left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
/*adjust margins*/
effectiveRect.adjust(+left, +top, -right, -bottom);
kDebug()<<left<<","<<top<<","<<right<<","<<bottom;
/*this is how qrectf works: Qrectf (xy top left corner, width ,height)*/
/*if there are no elements in the list, view only the main element*/
/*finding the center of the rectangular*/
qreal centerX = left + (right/2);
qreal centerY = top + (bottom/2);
/*finding the radius of the circle*/
qreal radius = 0;
if(right > bottom)
radius = bottom/2;
else
radius = right/2;
/*the main element is located in the center and fill 1/3 of th space*/
/*setting the rectf for the main element*/
QRectF mainRect
(centerX
+radius
/3, centerY
+radius
/3, radius
*2/3, radius
*2/3);
mainElement->setGeometry(mainRect);
kDebug() << "setting the main element geom";
/*if i have only one element, i'll put in the top center*/
if(list.size() == 1)
{
kDebug()<<"there is only one element";
QGraphicsLayoutItem* element = list.at(0);
/*putting this element at the top in the center*/
QRectF elementRect
(centerX
+radius
/3, centerY
+radius, radius
*2/3, radius
*2/3);
element->setGeometry(elementRect);
}
/*else i'll put the elements in the circle*/
else if(list.size() > 1)
{
kDebug()<<"there are more elements, "<<list.size();
for(int i=0; i<list.size(); i++)
{
/*this is the angle to rotate*/
double angle = (2*PI*i)/list.size();
/*than i made a rotation in center with the specified radius*/
QMatrix rotMatrix
(cos(angle
),
-sin(angle
),
sin(angle), cos(angle),
centerX,centerY);
/*then i multiply the matrix with the point on the top of the circle*/
qreal pointX;
qreal pointY;
/*rotation*/
rotMatrix.map(centerX,centerY+(radius*2)/3,&pointX, &pointY);
/*taking the i-esim element*/
QGraphicsLayoutItem* element = list.at(i);
/*try to put this element in the circle*/
QRectF elementRect
(pointX
-radius
/3, pointX
-radius, radius
*2/3, radius
*2/3);
element->setGeometry(elementRect);
}
}
}
QSizeF circleLayout
:: sizeHint(Qt
::SizeHint which,
const QSizeF &constraint
) const {
kDebug()<<"sizeHint!";
int n = list.count();
if (n > 0)
s
= QSizeF(100,
70);
//start with a nice default size int i = 0;
while (i < n) {
QGraphicsLayoutItem *o = list.at(i);
s = s.expandedTo(o->effectiveSizeHint(which, constraint));
++i;
}
return s ;
}
void circleLayout::setGeometry(const QRectF &r)
{
kDebug()<<"Set Geometry!!";
/*setting the real geometry*/
QGraphicsLayout::setGeometry(r);
/*taking the geometry*/
QRectF effectiveRect = geometry();
qreal left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
/*adjust margins*/
effectiveRect.adjust(+left, +top, -right, -bottom);
kDebug()<<left<<","<<top<<","<<right<<","<<bottom;
/*this is how qrectf works: Qrectf (xy top left corner, width ,height)*/
/*if there are no elements in the list, view only the main element*/
/*finding the center of the rectangular*/
qreal centerX = left + (right/2);
qreal centerY = top + (bottom/2);
/*finding the radius of the circle*/
qreal radius = 0;
if(right > bottom)
radius = bottom/2;
else
radius = right/2;
/*the main element is located in the center and fill 1/3 of th space*/
/*setting the rectf for the main element*/
QRectF mainRect(centerX+radius/3, centerY+radius/3, radius*2/3, radius*2/3);
mainElement->setGeometry(mainRect);
kDebug() << "setting the main element geom";
/*if i have only one element, i'll put in the top center*/
if(list.size() == 1)
{
kDebug()<<"there is only one element";
QGraphicsLayoutItem* element = list.at(0);
/*putting this element at the top in the center*/
QRectF elementRect(centerX+radius/3, centerY+radius, radius*2/3, radius*2/3);
element->setGeometry(elementRect);
}
/*else i'll put the elements in the circle*/
else if(list.size() > 1)
{
kDebug()<<"there are more elements, "<<list.size();
for(int i=0; i<list.size(); i++)
{
/*this is the angle to rotate*/
double angle = (2*PI*i)/list.size();
/*than i made a rotation in center with the specified radius*/
QMatrix rotMatrix(cos(angle), -sin(angle),
sin(angle), cos(angle),
centerX,centerY);
/*then i multiply the matrix with the point on the top of the circle*/
qreal pointX;
qreal pointY;
/*rotation*/
rotMatrix.map(centerX,centerY+(radius*2)/3,&pointX, &pointY);
/*taking the i-esim element*/
QGraphicsLayoutItem* element = list.at(i);
/*try to put this element in the circle*/
QRectF elementRect(pointX-radius/3, pointX-radius, radius*2/3, radius*2/3);
element->setGeometry(elementRect);
}
}
}
QSizeF circleLayout :: sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
kDebug()<<"sizeHint!";
QSizeF s(0,0);
int n = list.count();
if (n > 0)
s = QSizeF(100,70); //start with a nice default size
int i = 0;
while (i < n) {
QGraphicsLayoutItem *o = list.at(i);
s = s.expandedTo(o->effectiveSizeHint(which, constraint));
++i;
}
return s ;
}
To copy to clipboard, switch view to plain text mode
(the method sizeHint is semi-copied from QGraphicsGridLayout. i don't understand the true meaning of it)
plasmoidviewer(29212) AdvancedMenuLayout::sizeHint: sizeHint!
plasmoidviewer(29212) AdvancedMenuLayout::sizeHint: sizeHint!
plasmoidviewer(29212) AdvancedMenuLayout::sizeHint: sizeHint!
plasmoidviewer(29212) AdvancedMenuLayout::setGeometry: Set Geometry!!
plasmoidviewer(29212) AdvancedMenuLayout::setGeometry: 4 , 4 , 4 , 4
plasmoidviewer(29212) AdvancedMenuLayout::setGeometry: setting the main element geom
plasmoidviewer(29212) AdvancedMenuLayout::setGeometry: there is only one element
QPainter::begin: Cannot paint on a
null pixmap
QPainter::begin: Cannot paint on a
null pixmap
QPainter::begin: Cannot paint on a
null pixmap
QPainter::begin: Cannot paint on a
null pixmap
QPainter::begin: Cannot paint on a
null pixmap
QPainter::begin: Cannot paint on a
null pixmap
plasmoidviewer(29212) AdvancedMenuLayout::sizeHint: sizeHint!
plasmoidviewer(29212) AdvancedMenuLayout::sizeHint: sizeHint!
plasmoidviewer(29212) AdvancedMenuLayout::sizeHint: sizeHint!
plasmoidviewer(29212) AdvancedMenuLayout::setGeometry: Set Geometry!!
plasmoidviewer(29212) AdvancedMenuLayout::setGeometry: 4 , 4 , 4 , 4
plasmoidviewer(29212) AdvancedMenuLayout::setGeometry: setting the main element geom
plasmoidviewer(29212) AdvancedMenuLayout::setGeometry: there is only one element
QPainter::begin: Cannot paint on a null pixmap
QPainter::begin: Cannot paint on a null pixmap
QPainter::begin: Cannot paint on a null pixmap
QPainter::begin: Cannot paint on a null pixmap
QPainter::begin: Cannot paint on a null pixmap
QPainter::begin: Cannot paint on a null pixmap
To copy to clipboard, switch view to plain text mode
Bookmarks