#include "wrintingselectitem.h"
#include "ui_wrintingselectitem.h"
#include <QMouseEvent>

WrintingSelectItem::WrintingSelectItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::WrintingSelectItem)
{
    ui->setupUi(this);

    // 设置整个控件可点击
    setCursor(Qt::PointingHandCursor);

    // 连接radioButton的信号
    connect(ui->radioButton, &QRadioButton::toggled,
            this, &WrintingSelectItem::selectionChanged);
}

WrintingSelectItem::~WrintingSelectItem()
{
    delete ui;
}

// 设置标题
void WrintingSelectItem::setTitle(const QString &title)
{
    ui->label_title->setText(title);
}

// 设置提示
void WrintingSelectItem::setTip(const QString &tip)
{
    ui->label_tip->setText(tip);
}

// 同时设置标题和提示
void WrintingSelectItem::setContent(const QString &title, const QString &tip)
{
    setTitle(title);
    setTip(tip);
}

// 获取选中状态
bool WrintingSelectItem::isSelected() const
{
    return ui->radioButton->isChecked();
}

// 设置选中状态
void WrintingSelectItem::setSelected(bool selected)
{
    ui->radioButton->setChecked(selected);
}

// 鼠标点击事件处理
void WrintingSelectItem::mousePressEvent(QMouseEvent *event)
{
    QWidget::mousePressEvent(event);

    // 点击控件时选中radioButton
    setSelected(true);
}
