Patch for system tray layouting

Mathias Kraus k.matze at gmx.net
Sat Jun 14 16:43:25 CEST 2008


Hi,

this is my first patch for KDE, so I hope I don't break plasma ;)

OK, it's only a small patch for a layouting bug which occurs when you have a 
system tray with multiple rows/columns. See attached picture.

The bug is in 
kdebase/workspace/plasma/applets/systemtray/systemtraywidget.cpp.
In addWidgetToLayout the conditions in line 140
minimumHeight() + widget->height() + m_mainLayout->spacing() > maximumHeight()
is always true after the first column is full, the same applies for a vertical 
panel with rows.

My patch calculates the maximum number of items that fits into the panel and 
jumps into the next row/column if there is an overflow.

void SystemTrayWidget::addWidgetToLayout(QWidget *widget)
{
    // Add the widget to the layout
    m_mainLayout->setRowMinimumHeight(m_nextRow, 22);
    m_mainLayout->setColumnMinimumWidth(m_nextColumn, 22);
    widget->resize(22,22);
    m_mainLayout->addWidget(widget, m_nextRow, m_nextColumn, 1, 1, 
Qt::AlignCenter);

    // Figure out where the next widget should go
    if (m_orientation == Qt::Horizontal) {
        // Calculate the items that fit into a column
        m_maxCount = (maximumHeight() + m_mainLayout->spacing()) / (widget-
>height() + m_mainLayout->spacing()) -1;

        setMinimumSize(QSize(22 * (m_nextColumn + 1) + m_mainLayout->spacing() 
* m_nextColumn,
                             22 * (m_maxCount + 1) + m_mainLayout->spacing() * 
m_maxCount));

        // Add down then across when horizontal
        m_nextRow++;
        if (m_nextRow > m_maxCount){
            m_nextColumn++;
            m_nextRow = 0;
        }
    } else {
        // Calculate the items that fit into a row
        m_maxCount = (maximumWidth() + m_mainLayout->spacing()) / (widget-
>width() + m_mainLayout->spacing()) -1;

        setMinimumSize(QSize(22 * (m_maxCount + 1) + m_mainLayout->spacing() * 
m_maxCount,
                             22 * (m_nextRow + 1) + m_mainLayout->spacing() * 
m_nextRow));

        // Add across then down when vertical
        m_nextColumn++;
        if (m_nextColumn > m_maxCount) {
            m_nextRow++;
            m_nextColumn = 0;
        }
    }
}

BTW you guys rock. Keep on the good work.

Best regards,
Mathias Kraus


-------------- next part --------------
A non-text attachment was scrubbed...
Name: systray.png
Type: image/png
Size: 20431 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/panel-devel/attachments/20080614/4f220cc5/attachment-0001.png 


More information about the Panel-devel mailing list