1 module examplewidgets.mainwindow;
2 
3 import qt.config;
4 import qt.core.string;
5 import qt.helpers;
6 import qt.widgets.mainwindow;
7 import qt.widgets.ui;
8 import qt.widgets.widget;
9 
10 // Using MainWindowUI instead of UIStruct!"mainwindow.ui" prevents a forward referencing error.
11 struct MainWindowUI
12 {
13     mixin(generateUICode(import("mainwindow.ui"), "examplewidgets"));
14 }
15 
16 class MainWindow : QMainWindow
17 {
18     mixin(Q_OBJECT_D);
19 
20 public:
21     this(QWidget parent = null)
22     {
23         import core.stdcpp.new_;
24         super(parent);
25         this.ui = cpp_new!(typeof(*ui));
26 
27         ui.setupUi(this);
28     }
29     ~this()
30     {
31         import core.stdcpp.new_;
32 
33         cpp_delete(ui);
34     }
35 
36 private /+ slots +/:
37     @QSlot final void on_actionAbout_Qt_triggered()
38     {
39         import qt.widgets.messagebox;
40 
41         QMessageBox.aboutQt(this);
42     }
43 
44     @QSlot final void on_actionSystem_Info_triggered()
45     {
46         import qt.core.sysinfo;
47         import qt.widgets.messagebox;
48 
49         QString text = QString.create;
50         text ~= "Hostname: " ~ QSysInfo.machineHostName() ~ "\n";
51         text ~= "Pretty Product Name: " ~ QSysInfo.prettyProductName() ~ "\n";
52         text ~= "Product: " ~ QSysInfo.productType() ~ " " ~ QSysInfo.productVersion() ~ "\n";
53         text ~= "Kernel: " ~ QSysInfo.kernelType() ~ " " ~ QSysInfo.kernelVersion() ~ "\n";
54         text ~= "Build ABI: " ~ QSysInfo.buildAbi() ~ "\n";
55         text ~= "CPU Architecture: " ~ QSysInfo.buildCpuArchitecture() ~ "\n";
56         text ~= "Current CPU Architecture: " ~ QSysInfo.currentCpuArchitecture();
57         QString title = "System Info";
58         QMessageBox.information(this, title, text);
59     }
60 
61 private:
62     MainWindowUI* ui;
63 }
64