Add a GUIMessageDialog class.
This commit is contained in:
75
src/guimessagedialog.cpp
Normal file
75
src/guimessagedialog.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "guimessagedialog.h"
|
||||
#include "ui_guimessagedialog.h"
|
||||
#include "event/EventCenter.h"
|
||||
GUIMessageDialog::GUIMessageDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::GUIMessageDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setWindowFlags (Qt :: FramelessWindowHint | Qt :: Dialog);
|
||||
this->showFullScreen ();
|
||||
ui->lbl_msg->setVisible(false);
|
||||
ui->lbl_progressicon->setVisible(false);
|
||||
ui->btn_main->setVisible(false);
|
||||
this->setWindowOpacity(0.6);
|
||||
for (int i=1; i<=6;i++)
|
||||
{
|
||||
QString str(" ");
|
||||
for(int j=0;j<i;j++)
|
||||
{
|
||||
str[j]='.';
|
||||
}
|
||||
frame.append(str);
|
||||
}
|
||||
for (int i=1; i<=6;i++)
|
||||
{
|
||||
QString str("......");
|
||||
for(int j=0;j<i;j++)
|
||||
{
|
||||
str[j]=' ';
|
||||
}
|
||||
frame.append(str);
|
||||
}
|
||||
connect(EventCenter::Default(),&EventCenter::InvokeOperationEnd,[=](){
|
||||
if (timerID != -1){
|
||||
killTimer(timerID);
|
||||
timerID = -1;
|
||||
}
|
||||
accept();
|
||||
});
|
||||
}
|
||||
|
||||
GUIMessageDialog::~GUIMessageDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void GUIMessageDialog::timerEvent(QTimerEvent *event) {
|
||||
if (frameIndex>11) frameIndex = frameIndex % 12;
|
||||
ui->lbl_progressicon->setText(frame[frameIndex++]);
|
||||
this->update();
|
||||
printf("trigger timer event\r\n");
|
||||
}
|
||||
|
||||
void GUIMessageDialog::stopLoading() {
|
||||
if (timerID!=-1)killTimer(timerID);
|
||||
ui->lbl_progressicon->setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
void GUIMessageDialog::startLoading() {
|
||||
ui->lbl_progressicon->setVisible(true);
|
||||
timerID = startTimer(100);
|
||||
}
|
||||
|
||||
void GUIMessageDialog::showMessage(QString msg) {
|
||||
ui->lbl_msg->setText(msg);
|
||||
}
|
||||
|
||||
void GUIMessageDialog::showExitButton() {
|
||||
ui->btn_main->setVisible(true);
|
||||
disconnect(ui->btn_main);
|
||||
connect(ui->btn_main,&QToolButton::clicked,[=](){
|
||||
accept();
|
||||
});
|
||||
}
|
||||
30
src/guimessagedialog.h
Normal file
30
src/guimessagedialog.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef GUIMESSAGEDIALOG_H
|
||||
#define GUIMESSAGEDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QList>
|
||||
namespace Ui {
|
||||
class GUIMessageDialog;
|
||||
}
|
||||
|
||||
class GUIMessageDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GUIMessageDialog(QWidget *parent = nullptr);
|
||||
~GUIMessageDialog();
|
||||
void showMessage(QString msg);
|
||||
void showExitButton();
|
||||
void startLoading();
|
||||
void stopLoading();
|
||||
protected:
|
||||
void timerEvent(QTimerEvent* event) override ;
|
||||
private:
|
||||
Ui::GUIMessageDialog *ui;
|
||||
QList<QString> frame;
|
||||
int frameIndex=0;
|
||||
int timerID = -1;
|
||||
};
|
||||
|
||||
#endif // GUIMESSAGEDIALOG_H
|
||||
107
src/guimessagedialog.ui
Normal file
107
src/guimessagedialog.ui
Normal file
@@ -0,0 +1,107 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>GUIMessageDialog</class>
|
||||
<widget class="QDialog" name="GUIMessageDialog">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::WindowModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>620</width>
|
||||
<height>532</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>680</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>380</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>680</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>380</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="innerWidget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lbl_progressicon">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lbl_msg">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignHCenter">
|
||||
<widget class="QToolButton" name="btn_main">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user