File: getting-started.cpp

package info (click to toggle)
tuiwidgets 0.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,940 kB
  • sloc: cpp: 54,583; python: 495; sh: 83; makefile: 8
file content (52 lines) | stat: -rw-r--r-- 1,252 bytes parent folder | download | duplicates (3)
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
// snippet-header-start
#include "getting-started.h"

#include <QCoreApplication>
#include <QRect>

#include <Tui/ZButton.h>
#include <Tui/ZShortcut.h>
#include <Tui/ZTerminal.h>
#include <Tui/ZWindow.h>
// snippet-header-end

// snippet-root-start
void Root::terminalChanged() {
    // (1)
    Tui::ZShortcut *shortcut = new Tui::ZShortcut(Tui::ZKeySequence::forKey(Tui::Key_Escape),
                                                  this, Tui::ApplicationShortcut);
    QObject::connect(shortcut,
                     &Tui::ZShortcut::activated,
                     this, &Root::quit);

    // (2)
    Tui::ZWindow *win = new Tui::ZWindow("Hello World", this);
    win->setGeometry({5, 3, 20, 10});

    // (3)
    Tui::ZButton *button = new Tui::ZButton(Tui::withMarkup, "<m>Q</m>uit", win);
    QObject::connect(button, &Tui::ZButton::clicked, this, &Root::quit);
    button->setGeometry({6, 7, 10, 1});
    button->setFocus();
}

// (4)
void Root::quit() {
    QCoreApplication::instance()->quit();
}
// snippet-root-end


// snippet-main-start
int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);

    Tui::ZTerminal terminal;

    Root root;

    terminal.setMainWidget(&root);

    return app.exec();
}
// snippet-main-end