115 lines
3.0 KiB
C++
115 lines
3.0 KiB
C++
#include "MultyMessageDialog.h"
|
|
#include <QHBoxLayout>
|
|
|
|
namespace
|
|
{
|
|
const int AUTO_DISAPPEAR_TIME = 5000;
|
|
const int DIALOG_WIDTH = 240;
|
|
const int DIALOG_HEIGHT = 50;
|
|
|
|
}
|
|
|
|
MultyMessageDialog::MultyMessageDialog(const QString& aMessage,MessageLevel aMessageLevel,QWidget* aParent)
|
|
: QDialog(aParent)
|
|
, mAutoDisappearTime(AUTO_DISAPPEAR_TIME)
|
|
, mTimer(new QTimer(this))
|
|
, mDisappearAnimation(new QPropertyAnimation(this,"pos",this))
|
|
, mShowAnimation(new QPropertyAnimation(this,"pos",this))
|
|
, mMessage(new QLabel(aMessage,this))
|
|
, mIcon(new QLabel(this))
|
|
, mLevel(aMessageLevel)
|
|
{
|
|
setWindowFlags(Qt::FramelessWindowHint| Qt::WindowStaysOnTopHint| Qt::BypassWindowManagerHint);
|
|
resize(DIALOG_WIDTH,DIALOG_HEIGHT);
|
|
mTimer->setSingleShot(true);
|
|
connect(mTimer,&QTimer::timeout,this,&MultyMessageDialog::startHideAnimation);
|
|
initializeAnimation();
|
|
initializeIcon();
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
|
layout->addWidget(mIcon);
|
|
layout->addWidget(mMessage);
|
|
|
|
mMessage->setWordWrap(true);
|
|
}
|
|
|
|
MultyMessageDialog::~MultyMessageDialog()
|
|
{
|
|
emit dialogDestroyed();
|
|
}
|
|
|
|
void MultyMessageDialog::initializeAnimation()
|
|
{
|
|
mDisappearAnimation->setDuration(100);
|
|
|
|
mShowAnimation->setDuration(150);
|
|
|
|
connect(mDisappearAnimation, &QPropertyAnimation::finished, this, &MultyMessageDialog::hideDialog);
|
|
}
|
|
|
|
void MultyMessageDialog::initializeIcon()
|
|
{
|
|
switch (mLevel)
|
|
{
|
|
case MessageLevel::Info:
|
|
mIcon->setObjectName("MultyMessageDialogInfo");
|
|
break;
|
|
case MessageLevel::Warning:
|
|
mIcon->setObjectName("MultyMessageDialogWarning");
|
|
break;
|
|
case MessageLevel::Error:
|
|
mIcon->setObjectName("MultyMessageDialogError");
|
|
break;
|
|
case MessageLevel::Sucess:
|
|
mIcon->setObjectName("MultyMessageDialogSucess");
|
|
break;
|
|
default:
|
|
mIcon->setObjectName("MultyMessageDialogInfo");
|
|
break;
|
|
}
|
|
}
|
|
|
|
void MultyMessageDialog::setMessage(const QString& aMessage)
|
|
{
|
|
mMessage->setText(aMessage);
|
|
}
|
|
|
|
void MultyMessageDialog::startHideAnimation()
|
|
{
|
|
if (mTimer->isActive())
|
|
{
|
|
mTimer->stop();
|
|
}
|
|
mDisappearAnimation->setStartValue(pos());
|
|
mDisappearAnimation->setEndValue(QPoint(pos().x(),pos().y()-30-height()));
|
|
mDisappearAnimation->start();
|
|
}
|
|
|
|
void MultyMessageDialog::hideDialog()
|
|
{
|
|
hide();
|
|
deleteLater();
|
|
}
|
|
|
|
void MultyMessageDialog::setAutoDisappearTime(int aAutoDisappearTime)
|
|
{
|
|
mAutoDisappearTime = aAutoDisappearTime;
|
|
}
|
|
|
|
void MultyMessageDialog::showEvent(QShowEvent* aEvent)
|
|
{
|
|
mTimer->start(mAutoDisappearTime);
|
|
mShowAnimation->setStartValue(QPoint(pos().x(),pos().y()-30-height()));
|
|
mShowAnimation->setEndValue(pos());
|
|
mShowAnimation->start();
|
|
QDialog::showEvent(aEvent);
|
|
}
|
|
|
|
void MultyMessageDialog::stopShowAnimation()
|
|
{
|
|
if (QAbstractAnimation::Running == mShowAnimation->state())
|
|
{
|
|
mShowAnimation->stop();
|
|
move(mShowAnimation->endValue().toPoint());
|
|
}
|
|
}
|