forked from nodegui/nodegui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.ts
More file actions
172 lines (148 loc) · 4.59 KB
/
demo.ts
File metadata and controls
172 lines (148 loc) · 4.59 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import {
QMainWindow,
QLabel,
QCheckBox,
QLineEdit,
QPushButton,
QProgressBar,
QRadioButton,
FlexLayout,
QWidget,
QIcon,
QDial,
QPlainTextEdit,
QTabWidget,
QGridLayout,
QScrollArea,
QPixmap,
CursorShape,
WindowState,
QTextOptionWrapMode,
QCheckBoxEvents,
QSystemTrayIcon,
ReadWriteImageFormats,
QPushButtonEvents
} from "./index";
import { ok, equal } from "assert";
import { existsSync, unlinkSync, readFileSync } from "fs";
import { resolve } from "path";
import { QMenuBar } from "./lib/QtWidgets/QMenuBar";
import { QMenu } from "./lib/QtWidgets/QMenu";
const win = new QMainWindow();
const label1 = new QLabel();
label1.setText("Hello world 1 🧙");
label1.setInlineStyle("font-size: 20px;");
label1.setCursor(CursorShape.ForbiddenCursor);
const label2 = new QLabel();
label2.setText("Hello world 2 💻");
label2.setInlineStyle("font-size: 20px;");
label2.setCursor(CursorShape.ForbiddenCursor);
const checkbox = new QCheckBox();
checkbox.setText("Check me out?");
checkbox.setObjectName("check");
checkbox.setChecked(true);
checkbox.addEventListener(QCheckBoxEvents.toggled, checked => {
console.log(`${checked ? "checked" : "unchecked"}`);
label1.setInlineStyle(`color: ${checked ? "green" : "red"}`);
});
const dial = new QDial();
checkbox.setObjectName("dial");
const lineEdit = new QLineEdit();
lineEdit.setPlaceholderText("Enter your thoughts here");
lineEdit.setObjectName("editable");
const button = new QPushButton();
button.setText("Push Push Push!");
button.setObjectName("btn");
const nodeguiLogo = new QIcon(
resolve(__dirname, "../extras/assets/nodegui.png")
);
const icon = new QIcon(resolve(__dirname, "../extras/assets/start_icon.png"));
button.setIcon(icon);
const tabs = new QTabWidget();
tabs.setTabsClosable(true);
const tab1 = new QWidget();
const tab2 = new QWidget();
tab1.setLayout(new QGridLayout());
tab2.setLayout(new QGridLayout());
if (tab1.layout && tab2.layout) {
tab1.layout.addWidget(label1);
tab2.layout.addWidget(label2);
}
tabs.addTab(tab1, icon, "Tab 1");
tabs.addTab(tab2, icon, "Tab 2");
const progressBar = new QProgressBar();
progressBar.setValue(6);
equal(progressBar.value(), 6);
progressBar.setMinimum(1);
progressBar.setMaximum(15);
const radioButton = new QRadioButton();
radioButton.setText("Roger that!");
const rootView = new QWidget();
rootView.setObjectName("root");
rootView.setLayout(new FlexLayout());
const textEdit = new QPlainTextEdit();
textEdit.setPlainText("Hello");
textEdit.setWordWrapMode(QTextOptionWrapMode.NoWrap);
const scrollArea = new QScrollArea();
scrollArea.setInlineStyle("flex: 1; width:'100%';");
const imageLabel = new QLabel();
const pixmap = new QPixmap(resolve(__dirname, "../extras/assets/kitchen.png"));
imageLabel.setPixmap(pixmap);
scrollArea.setWidget(imageLabel);
function testQPixmapSave(fileName: string, format?: ReadWriteImageFormats) {
try {
existsSync(fileName) && unlinkSync(fileName);
ok(!existsSync(fileName));
equal(pixmap.save(fileName, format), true);
ok(existsSync(fileName));
// ideally we want to use file-type, jimp or magica to verify tmp.png has the correct encoding and/or is identical to source img.
ok(readFileSync(fileName).byteLength > 1000);
} catch (error) {
console.error("QPixmap.save test failed", error, error.stack);
} finally {
unlinkSync(fileName);
}
}
testQPixmapSave("tmp.png");
testQPixmapSave("tmp.jpg");
testQPixmapSave("tmp_jpg", "JPG");
testQPixmapSave("tmp_bmp", "BMP");
const trayIcon = new QIcon(
resolve(__dirname, "../extras/assets/nodegui_white.png")
);
const tray = new QSystemTrayIcon();
tray.setIcon(trayIcon);
tray.show();
if (rootView.layout) {
rootView.layout.addWidget(tabs);
rootView.layout.addWidget(checkbox);
rootView.layout.addWidget(radioButton);
rootView.layout.addWidget(lineEdit);
rootView.layout.addWidget(button);
rootView.layout.addWidget(progressBar);
rootView.layout.addWidget(textEdit);
rootView.layout.addWidget(scrollArea);
rootView.layout.addWidget(dial);
}
const menuBar = new QMenuBar();
const menu = new QMenu();
win.setMenuBar(menuBar);
menu.setTitle("hello");
menuBar.addMenu(menu);
menuBar.setNativeMenuBar(false);
win.setCentralWidget(rootView);
win.setStyleSheet(`
#root {
flex: 1;
height: '100%';
align-items: 'center';
justify-content: 'space-around';
}
`);
win.setWindowIcon(nodeguiLogo);
win.setWindowTitle("NodeGUI Demo");
win.resize(400, 700);
win.show();
win.setWindowState(WindowState.WindowActive);
(global as any).win = win; // To prevent win from being garbage collected.
(global as any).systemTray = tray; // To prevent system tray from being garbage collected.