#include "PathSelectorWidget.h"

#include <QFileDialog>

const QString PathSelectorWidget::type = "PathSelector";

PathSelectorWidget::PathSelectorWidget(QWidget *parent)
    : LineEditWidget(parent)
    , btn(new QPushButton(this))
{
    init();
}

void PathSelectorWidget::init()
{    
    btn->setText("选择路径");
	btn->setStyleSheet("border:0;color:#ffffff;background-color:#55aaff;border-radius:0;border-top-right-radius:1px;border-bottom-right-radius:1px;min-height:18px;min-width:40px");
    connect(btn, &QPushButton::pressed, this, &PathSelectorWidget::onButtonClick);

    setReadOnly(true);
}

void PathSelectorWidget::resizeEvent(QResizeEvent *event)
{
    Q_UNUSED(event)
	btn->setGeometry(width() - 61, 1, 60, height() - 2);
}

void PathSelectorWidget::onButtonClick()
{
    QString path = QFileDialog::getExistingDirectory(this, "选择路径");
    setText(path);
}

