-
Notifications
You must be signed in to change notification settings - Fork 10
/
aboutdialog.cpp
105 lines (83 loc) · 2.26 KB
/
aboutdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "aboutdialog.h"
#include<QHBoxLayout>
#include<QVBoxLayout>
#include<QPixmap>
#include<QDesktopServices>
#include<QUrl>
#include<QFile>
#include<QTextStream>
AboutDialog::AboutDialog(QWidget *parent) :
QDialog(parent)
{
init();
}
void AboutDialog::init()
{
//标题栏不要按钮
this->setWindowFlags(Qt::WindowTitleHint | Qt::CustomizeWindowHint);
label_Logo=new QLabel;
label_Logo->setMinimumSize(370,45);
label_Info=new QLabel;
label_Info->setMinimumSize(370,45);
textEdit=new QTextEdit;
textEdit->setMinimumSize(370,115);
textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
textEdit->setReadOnly(true);
btn_confirm=new QPushButton("确定");
btn_confirm->setMinimumSize(75,25);
QHBoxLayout* hlayout=new QHBoxLayout;
hlayout->addStretch();
hlayout->addWidget(btn_confirm);
hlayout->setMargin(4);
QVBoxLayout* vlayout=new QVBoxLayout;
vlayout->addWidget(label_Logo);
vlayout->addWidget(label_Info);
vlayout->addWidget(textEdit);
vlayout->addLayout(hlayout);
vlayout->setMargin(0);
setLayout(vlayout);
this->setMinimumSize(370,254);
this->setMaximumSize(370,254);
setBackground();
connect(btn_confirm,SIGNAL(clicked()),this,SLOT(hide()));
}
void AboutDialog::setLogo(const QString filename)
{
QPixmap pixmap(filename);
label_Logo->setPixmap(pixmap);
}
void AboutDialog::setInfo(const QString info)
{
label_Info->setText(info);
connect(label_Info,SIGNAL(linkActivated(QString)),this,SLOT(openUrl(QString)));
}
void AboutDialog::setText(const QString str, bool isFileName)
{
if(isFileName==false)
textEdit->setText(str);
else if(isFileName==true)
{
QFile file(str);
if(file.open(QIODevice::ReadOnly|QIODevice::Text))
{
QTextStream in(&file);
QString s;
s=in.readAll();
textEdit->setText(s);
file.close();
}
}
}
void AboutDialog::setBackground(const QString styleSheet)
{
if(styleSheet=="default")
{
this->setStyleSheet("AboutDialog{background: rgb(238, 241, 255);}");
}
else
setStyleSheet(styleSheet);
}
void AboutDialog::openUrl(QString url)
{
QDesktopServices::openUrl(QUrl(url));
}