#include "inittip.h"
#include "global.h"

#include <QPainter>
#include <QFontMetrics>
#include <QDebug>

InitTip::InitTip(QWidget *parent)
    : QWidget(parent)
{
    connects();
}

InitTip::~InitTip()
{

}

void InitTip::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.drawImage(this->rect(), QImage(":/images/inittip.jpg"));

    QRect rect = this->rect();
    QString txt;

    painter.save();
    QPen pen;
    pen.setColor(QColor("#ffffff"));
    pen.setBrush(QBrush(QColor("#ffffff")));
    QFont font;
    font.setBold(true);
    font.setFamily("Microsoft Yahei");
    font.setPixelSize(40);
    painter.setFont(font);
    painter.setPen(pen);
    txt = appName() + " " + appVersion();
    painter.drawText(rect, Qt::AlignCenter, txt);
    painter.restore();

    painter.save();
    pen.setColor(QColor("#ffffff"));
    pen.setBrush(QBrush(QColor("#ffffff")));
    font.setPixelSize(25);
    font.setBold(false);
    painter.setFont(font);
    painter.setPen(pen);
    txt = "正在初始化中.......";
    QRect rect1 = rect;
    int h = rect1.height();
    rect1.setY(rect.y() + h / 2);
    rect1.setHeight(h / 2);
    painter.drawText(rect1, Qt::AlignCenter, txt);
    painter.restore();


    painter.save();
    pen.setColor(QColor("#0EFCFF"));
    pen.setBrush(QBrush(QColor("#0EFCFF")));
    font.setPixelSize(15);
    font.setBold(false);
    QFontMetrics fm(font);
    txt = "版权@武汉创景可视技术有限公司";
    QRect rect2 = fm.boundingRect(txt);
    int w = rect2.width();
    h = rect2.height();
    rect2.setX(rect.width() - w - 5);
    rect2.setY(rect.height() - h - 5);
    rect2.setHeight(h);
    rect2.setWidth(w);
    painter.setFont(font);
    painter.setPen(pen);
    painter.drawText(rect2, Qt::AlignVCenter | Qt::AlignRight, txt);
    painter.restore();

}

void InitTip::connects()
{

}

