class MessageFrame
: public QFrame{
Q_OBJECT
Q_PROPERTY(QString currentText READ currentText WRITE setCurrentText
) Q_ENUMS(Icon)
Q_ENUMS(TextType)
public:
enum Icon { Question, Information, Warning, Critical };
enum TextType { ScreenDescription, GeneralText };
MessageFrame
(QWidget* parent
= 0) : poBaseWidget
(new QFrame(this)) {
setObjectName("MessageFrame");
setGeometry(0,20,800,460);
//
poBaseWidget->setGeometry(120,0,560,100);
poBaseWidget->setStyleSheet("* { background-color: rgb(192,192,192);"
"background-origin: content;"
"border: 2px rgb(128,128,127);"
"border-radius: 10px; }");
//
iconLabel
= new QLabel(poBaseWidget
);
iconLabel->resize(32,32);
setIcon(Information);
//
textLabel
= new QLabel(poBaseWidget
);
textLabel->setWordWrap(true);
textLabel->setMaximumSize(textLabel->parentWidget()->width() - iconLabel->width() - 20, textLabel->parentWidget()->height() - 10);
textLabel->resize(textLabel->maximumSize());
//
startFadeAnimation = new QPropertyAnimation(poBaseWidget, "windowOpacity",this);
startFadeAnimation->setStartValue(0.0);
startFadeAnimation->setEndValue(1.0);
startFadeAnimation->setDuration(5000);
stopFadeAnimation = new QPropertyAnimation(poBaseWidget, "windowOpacity",this);
stopFadeAnimation->setStartValue(1.0);
stopFadeAnimation->setEndValue(0.0);
stopFadeAnimation->setDuration(5000);
connect(stopFadeAnimation,SIGNAL(finished()),this,SLOT(close()));
//
poBaseWidget->installEventFilter(this);
hide(); //hide();
}
virtual ~MessageFrame()
{
poBaseWidget->removeEventFilter(this);
}
inline QString currentText
() const;
void setCurrentText(const QString& text);
void setIcon(const Icon icon);
static void information(const QString& text);
static void warning(const QString& text);
static void critical(const QString& text);
private:
* iconLabel;
QPropertyAnimation* startFadeAnimation,
* stopFadeAnimation;
protected:
{
if (obj
== poBaseWidget
&& ev
->type
() == QEvent::MouseButtonRelease) {
stopFadeAnimation->start();
return true;
}
else
return QFrame::eventFilter(obj,ev
);
}
public slots:
void show1(const TextType type = GeneralText)
{
switch (type)
{
case GeneralText: //last set text
break;
case ScreenDescription:
// setCurrentText(screenText);
break;
}
show();
startFadeAnimation->start();
}
inline void setScreenText(const QString& text) { screenText = text; }
/////////////////////////////////////////////////////
/// SINGLETON STUFF - DON'T TOUCH
public:
static void start
(QWidget* parent
= 0);
static void MessageFrameDestroy();
inline static MessageFrame& instance();
private:
static MessageFrame* poInstance;
};
class MessageFrame : public QFrame
{
Q_OBJECT
Q_PROPERTY(QString currentText READ currentText WRITE setCurrentText)
Q_ENUMS(Icon)
Q_ENUMS(TextType)
public:
enum Icon { Question, Information, Warning, Critical };
enum TextType { ScreenDescription, GeneralText };
MessageFrame(QWidget* parent = 0) :
QFrame(parent),
poBaseWidget(new QFrame(this))
{
setObjectName("MessageFrame");
setGeometry(0,20,800,460);
//
poBaseWidget->setGeometry(120,0,560,100);
poBaseWidget->setStyleSheet("* { background-color: rgb(192,192,192);"
"background-origin: content;"
"border: 2px rgb(128,128,127);"
"border-radius: 10px; }");
//
iconLabel = new QLabel(poBaseWidget);
iconLabel->resize(32,32);
setIcon(Information);
//
textLabel = new QLabel(poBaseWidget);
textLabel->setWordWrap(true);
textLabel->setMaximumSize(textLabel->parentWidget()->width() - iconLabel->width() - 20, textLabel->parentWidget()->height() - 10);
textLabel->resize(textLabel->maximumSize());
//
startFadeAnimation = new QPropertyAnimation(poBaseWidget, "windowOpacity",this);
startFadeAnimation->setStartValue(0.0);
startFadeAnimation->setEndValue(1.0);
startFadeAnimation->setDuration(5000);
stopFadeAnimation = new QPropertyAnimation(poBaseWidget, "windowOpacity",this);
stopFadeAnimation->setStartValue(1.0);
stopFadeAnimation->setEndValue(0.0);
stopFadeAnimation->setDuration(5000);
connect(stopFadeAnimation,SIGNAL(finished()),this,SLOT(close()));
//
poBaseWidget->installEventFilter(this);
hide(); //hide();
}
virtual ~MessageFrame()
{
poBaseWidget->removeEventFilter(this);
}
inline QString currentText() const;
void setCurrentText(const QString& text);
void setIcon(const Icon icon);
static void information(const QString& text);
static void warning(const QString& text);
static void critical(const QString& text);
private:
QLabel* textLabel,
* iconLabel;
QPropertyAnimation* startFadeAnimation,
* stopFadeAnimation;
QString screenText;
QFrame* poBaseWidget;
protected:
bool eventFilter(QObject *obj, QEvent *ev)
{
if (obj == poBaseWidget && ev->type() == QEvent::MouseButtonRelease)
{
stopFadeAnimation->start();
return true;
}
else
return QFrame::eventFilter(obj,ev);
}
public slots:
void show1(const TextType type = GeneralText)
{
switch (type)
{
case GeneralText: //last set text
break;
case ScreenDescription:
// setCurrentText(screenText);
break;
}
show();
startFadeAnimation->start();
}
inline void setScreenText(const QString& text) { screenText = text; }
/////////////////////////////////////////////////////
/// SINGLETON STUFF - DON'T TOUCH
public:
static void start(QWidget* parent = 0);
static void MessageFrameDestroy();
inline static MessageFrame& instance();
private:
static MessageFrame* poInstance;
};
To copy to clipboard, switch view to plain text mode
Bookmarks