#include "wpageitemwidget.h"
#include "ui_wpageitemwidget.h"

wPageItemWidget::wPageItemWidget(QGraphicsScene *s, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::wPageItemWidget)
{
    setAttribute(Qt::WA_DeleteOnClose);
    ui->setupUi(this);
    ui->wThumView->setFixedSize(120, 60);
    ui->wThumView->setScene(s);
    ui->wThumView->setEnabled(false);
    ui->wPlayTimes->setEnabled(false);
    updateScale(s);
}

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

void wPageItemWidget::onRepeatChanged(int n)
{
    ui->wPlayTimes->setValue(n);
}

void wPageItemWidget::updateScale(QGraphicsScene *s)
{
    ui->wThumView->resetTransform();
    qreal scale_x = static_cast<qreal>(ui->wThumView->width())  / s->sceneRect().width();
    qreal scale_y = static_cast<qreal>(ui->wThumView->height()) / s->sceneRect().height();
    ui->wThumView->scale(scale_x, scale_y);
}
