#include "bootlistwidget.h"
#include <QIcon>
#include <QDebug>

BootListWidget::BootListWidget(QWidget *parent) : QWidget(parent)
{
    initUI();
}

BootListWidget::~BootListWidget()
{
}

/**
 * @brief BootListWidget::setBootName
 * @param text 启动项名称
 */
void BootListWidget::setBootName(const QString &text)
{
    m_pNameLabel->setText(text);
}

QString BootListWidget::getBootName()
{
    return m_pNameLabel->text();
}

/**
 * @brief BootListWidget::showSelectedIcon
 * icon 是否显示
 */
void BootListWidget::showSelectedIcon(bool flag)
{
    m_pSelectedIconLabel->setVisible(flag);
}

void BootListWidget::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        this->showSelectedIcon(true);
        Q_EMIT clicked(this->property("grubOrder").toInt());
    }
    return QWidget::mousePressEvent(event);
}

void BootListWidget::initUI()
{
    QHBoxLayout *mainLayout = new QHBoxLayout(this);
    mainLayout->setContentsMargins(17, 0, 17, 0);
    mainLayout->setSpacing(8);
    m_pSelectedIconLabel = new QLabel();
    QIcon selectIcon = QIcon::fromTheme("ukui-selected");
    m_pSelectedIconLabel->setPixmap(selectIcon.pixmap(selectIcon.actualSize(QSize(16, 16))));
    m_pNameLabel = new QLabel(this);
    mainLayout->addWidget(m_pNameLabel);
    mainLayout->addStretch();
    mainLayout->addWidget(m_pSelectedIconLabel);
}
