Пример #1
0
bool Hdd::addVisualization(const QString& source)
{
    Plasma::Meter *w;
    Plasma::DataEngine *engine = dataEngine("soliddevice");
    Plasma::DataEngine::Data data;

    if (!engine) {
        return false;
    }
    if (!isValidDevice(source, &data)) {
        // do not try to show hard drives and swap partitions.
        return false;
    }
    QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Horizontal);
    layout->setContentsMargins(3, 3, 3, 3);
    layout->setSpacing(5);

    w = new Plasma::Meter(this);
    w->setMeterType(Plasma::Meter::BarMeterHorizontal);
    if (mode() != SM::Applet::Panel) {
        MonitorIcon *icon = new MonitorIcon(this);
        m_icons.insert(source, icon);
        icon->setImage("drive-harddisk");
        if (data["Accessible"].toBool()) {
            QStringList overlays;
            overlays << QString("emblem-mounted");
            icon->setOverlays(overlays);
        }
        layout->addItem(icon);
    } else {
        w->setSvg("system-monitor/hdd_panel");
    }
    w->setLabel(0, hddTitle(source, data));
    w->setLabelAlignment(0, Qt::AlignVCenter | Qt::AlignLeft);
    w->setLabelAlignment(1, Qt::AlignVCenter | Qt::AlignRight);
    w->setLabelAlignment(2, Qt::AlignVCenter | Qt::AlignCenter);
    w->setMaximum(data["Size"].toULongLong() / (1024 * 1024));
    applyTheme(w);
    appendVisualization(source, w);
    layout->addItem(w);
    mainLayout()->addItem(layout);
    dataUpdated(source, data);
    setPreferredItemHeight(layout->preferredSize().height());

    QString disk = data["Parent UDI"].toString();

    m_diskMap[disk] << w;
    if (!connectedSources().contains(disk)) {
        data = engine->query(disk);
        dataUpdated(disk, data);
        connectSource(disk);
    }
    return true;
}
Пример #2
0
void Pt_MLayout::heightForWidthPerformance()
{
    QFETCH(bool, qtOnly);
    QFETCH(bool, hfw);
    QFETCH(bool, nested);

    QGraphicsLinearLayout *outerlayout = NULL;
    if(nested) {
       outerlayout = new QGraphicsLinearLayout(m_form);
       for(int i = 0; i < 5; i++) {
           QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
           outerlayout->addItem(layout);
           outerlayout = layout;
       }
    }

    QGraphicsLinearLayout *qlayout = NULL;
    MLayout *layout = NULL;
    MLinearLayoutPolicy *policy = NULL;
    if(qtOnly) {
        qlayout = new QGraphicsLinearLayout(Qt::Vertical);
        if (nested)
            outerlayout->addItem(qlayout);
        else
            m_form->setLayout(qlayout);
    } else {
        layout = new MLayout;
        policy = new MLinearLayoutPolicy(layout, Qt::Vertical);
        if (nested)
            outerlayout->addItem(layout);
        else
            m_form->setLayout(layout);
    }

    for(int i = 0; i < 1; i++) {
        MySquareWidget *widget = new MySquareWidget;
        QSizePolicy sizepolicy = widget->sizePolicy();
        sizepolicy.setHeightForWidth(hfw);
        widget->setSizePolicy(sizepolicy);
        if (qtOnly)
            qlayout->addItem(widget);
        else
            policy->addItem(widget);
    }

    while (MTheme::hasPendingRequests()) {
        usleep(10);
        QCoreApplication::processEvents();
    }

    QBENCHMARK {
        if (qtOnly) {
            qlayout->invalidate();
            QCoreApplication::processEvents();
            (void)qlayout->preferredSize();
        } else {
            layout->invalidate();
            QCoreApplication::processEvents();
            (void)layout->preferredSize();
        }
    }
}