-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathfactory.cpp
executable file
·135 lines (131 loc) · 4.44 KB
/
factory.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "factory.h"
//静态变量的初始化应该放在cpp文件中,放在头文件中会被重复包含导致重定义
QString Factory::DefaultStyleSheet="color:white;background-color:black";
QFont Factory::DefaultFont=QFont("Microsoft YaHei" ,12, 30);
QLabel* Factory::CreateQLabel(QWidget*pos, int x, int y, int w, int h,
QString Text,QString StyleSheet,QFont Font,Qt::Alignment s)
{
QLabel* p=new QLabel(pos);
p->setGeometry(x,y,w,h);
p->setText(Text);
p->setStyleSheet(StyleSheet);
p->setFont(Font);
p->setAlignment(s);
return p;
}
QLabel* Factory::CreateQLabel(QMainWindow*pos, int x, int y, int w, int h,
QString Text,QString StyleSheet,QFont Font,Qt::Alignment s)
{
QLabel* p=new QLabel(pos);
p->setGeometry(x,y,w,h);
p->setText(Text);
p->setStyleSheet(StyleSheet);
p->setFont(Font);
p->setAlignment(s);
return p;
}
QLabel* Factory::CreateQLabel(QWidget *pos, QString Text, QString StyleSheet, QFont Font)
{
QLabel* p=new QLabel(pos);
p->setText(Text);
p->setStyleSheet(StyleSheet);
p->setFont(Font);
return p;
}
QPushButton* Factory::CreateQPushButton(QWidget*pos,int x, int y, int w, int h,
QString Text,QString StyleSheet,QFont Font)
{
QPushButton* p=new QPushButton(pos);
p->setGeometry(x,y,w,h);
p->setText(Text);
p->setStyleSheet(StyleSheet);
p->setFont(Font);
return p;
}
QPushButton* Factory::CreateQPushButton(QMainWindow*pos,int x, int y, int w, int h,
QString Text,QString StyleSheet,QFont Font)
{
QPushButton* p=new QPushButton(pos);
p->setGeometry(x,y,w,h);
p->setText(Text);
p->setStyleSheet(StyleSheet);
p->setFont(Font);
return p;
}
QPushButton* Factory::CreateQPushButton(QWidget* pos,QString Text,QString StyleSheet)
{
QPushButton* p=new QPushButton(pos);
p->setText(Text);
p->setStyleSheet(StyleSheet);
return p;
}
QProgressBar* Factory::CreateQProgressBar(QWidget*pos,int x, int y, int w, int h,bool TextVisible)
{
QProgressBar* p=new QProgressBar(pos);
p->setGeometry(x,y,w,h);
p->setStyle(QStyleFactory::create("fusion"));
p->setTextVisible(TextVisible);
return p;
}
QMediaPlayer* Factory::CreateQMediaPlayer(QWidget*pos, QUrl url, int v)
{
QMediaPlayer* p=new QMediaPlayer(pos);
p->setMedia(url);//相对路径
p->setVolume(v);
return p;
}
QMediaPlaylist* Factory::CreateQMediaPlaylist(QWidget* pos)
{
QMediaPlaylist* p=new QMediaPlaylist(pos);//游戏音效
p->addMedia(QUrl("qrc:/music/music/coin.mp3"));//硬币音效
p->addMedia(QUrl("qrc:/music/music/powerup.mp3"));//升级音效
p->addMedia(QUrl("qrc:/music/music/flagpole.mp3"));//碰到旗子音效
p->addMedia(QUrl("qrc:/music/music/stomp.mp3"));//捡到钥匙音效
p->addMedia(QUrl("qrc:/music/music/one_up.mp3"));//吃到蘑菇音效
p->addMedia(QUrl("qrc:/music/music/death.mp3"));//死亡音效
return p;
}
QSpinBox* Factory::CreateQSpinBox(QWidget*pos,QString StyleSheet)
{
QSpinBox* p=new QSpinBox(pos);
p->setStyleSheet(StyleSheet);
return p;
}
QComboBox* Factory::CreateQComboBox(QWidget* pos,int index)
{
QComboBox* p=new QComboBox(pos);
p->addItem(QObject::tr("魔法少女"));//项目编号从0开始
p->addItem(QObject::tr("火影忍者"));
p->addItem(QObject::tr("超级玛丽"));
p->setCurrentIndex(index);
return p;
}
QLineEdit* Factory::CreateQLineEdit(QMainWindow*pos,int x, int y, int w,int h,QString StyleSheet,QFont Font)
{
QLineEdit* p=new QLineEdit(pos);
p->setGeometry(x,y,w,h);
p->setStyleSheet(StyleSheet);
p->setFont(Font);
return p;
}
QTcpSocket* Factory::CreateQTcpSocket(QString ServerIp,int ServerPort)
{
QTcpSocket* tcpSocket = new QTcpSocket();
QHostAddress* serverIP = new QHostAddress();
QString ip = ServerIp;
serverIP->setAddress(ip);
tcpSocket->connectToHost(*serverIP, ServerPort);
return tcpSocket;
}
QToolButton* Factory::CreateQToolButton(QString text,int w,int h,QString url,bool Enable)
{
QToolButton* p=new QToolButton();
p->setText(text);
p->setMinimumSize(w,h);
p->setIcon(QPixmap(url));
p->setIconSize(QPixmap(url).size());
p->setAutoRaise(true);
p->setEnabled(Enable);
p->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
return p;
}