-
Notifications
You must be signed in to change notification settings - Fork 3
/
widget.cpp
70 lines (65 loc) · 2.02 KB
/
widget.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
//-----本文件用于窗口的初始化-----
#include "widget.h"
#include "ui_widget.h"
#include "configure.h"
LFEvent *lfevent;
QGraphicsScene *MainScene;
GraphicsView *MainView;
JSVM *MainJSVM;
#ifdef SelfAdaption
float adaptiveRatioX;
float adaptiveRatioY;
#endif
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
Initialization();//开始初始化
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
//程序启动时调用的函数
void Widget::Initialization()
{
lfevent=new LFEvent;//初始化全局变量
//编码校正
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForLocale(codec);
//注册普通类型
RegisterJSType(ParametersStru,"ParametersStru");
RegisterJSType(ParametersStru*,"ParametersStru*"); //被逼无奈
RegisterJSType(LFEvent*,"LFEvent*");
RegisterJSType(Item*,"Item*");
RegisterJSType(String,"String");
RegisterJSType(VideoPlayer*,"VideoPlayer*");
RegisterJSType(GraphicsView*,"GraphicsView*");
RegisterJSType(CaluThread*,"CaluThread*");
RegisterJSType(AnimationType,"AnimationType");
RegisterJSType(Pixmap*,"Pixmap*");
RegisterJSType(MusicPlayer*,"MusicPlayer*");
RegisterJSType(GraphicsScene*,"GraphicsScene*");
RegisterJSType(Key,"Key");
RegisterJSType(JSVM*,"JSVM*");
#ifdef SelfAdaption
//计算自适应比
int scWidth=GetScreenWidth();
int scHeigh=GetScreenHeigh();
adaptiveRatioX=float(scWidth)/float(WindowsWidth);
adaptiveRatioY=float(scHeigh)/float(WindowsHeigh);
setGeometry(0,0,scWidth,scHeigh);
setFixedSize(GetScreenWidth(),GetScreenHeigh());
#else
//计算窗口出现位置
int widX=(GetScreenWidth()-WindowsWidth)/2;
int widY=(GetScreenHeigh()-WindowsHeigh)/2;
setGeometry(widX,widY,WindowsWidth,WindowsHeigh);
setFixedSize(WindowsWidth,WindowsHeigh);
#endif
setWindowTitle(title);
MainScene=AddScene(MaximumWidth,MaximunHeigh);
MainView=AddView(0,0,WindowsWidth,WindowsHeigh);
SetViewScene();
}