File: menubar.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 (60 lines) | stat: -rw-r--r-- 2,028 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
53
54
55
56
57
58
59
60
#include <Tui/ZCommandNotifier.h>
#include <Tui/ZHBoxLayout.h>
#include <Tui/ZMenubar.h>
#include <Tui/ZWidget.h>

void exampleMenubarItems() {
// snippet-initlist-items-start
    QVector<Tui::ZMenuItem> items = {
        { "<m>F</m>ile", "", {}, {
            { "<m>N</m>ew", "", "NewFile", {}},
            { "<m>O</m>pen", "", "OpenFile", {}},
            { "<m>S</m>ave", "", "SaveFile", {}},
            { },
            { "<m>Q</m>uit", "Ctrl-q", "Quit", {}},
        }},
        { "<m>H</m>elp", "", {}, {
            { "<m>A</m>bout", "", "AboutDialog", {}}
        }}
    };
// snippet-initlist-items-end
}

void exampleMenubar(Tui::ZWidget *root, Tui::ZHBoxLayout *layout) {
// snippet-start
    Tui::ZMenubar *menubar = new Tui::ZMenubar(root);

    QVector<Tui::ZMenuItem> items = {
        { "<m>F</m>ile", "", {}, {
            { "<m>N</m>ew", "", "NewFile", {}},
            { "<m>O</m>pen", "", "OpenFile", {}},
            { "<m>S</m>ave", "", "SaveFile", {}},
            { },
            { "<m>Q</m>uit", "Ctrl-q", "Quit", {}},
        }},
        { "<m>H</m>elp", "", {}, {
            { "<m>A</m>bout", "", "AboutDialog", {}}
        }}
    };
    menubar->setItems(items);

    layout->addWidget(menubar);

    QObject::connect(new Tui::ZCommandNotifier("NewFile", root),
                     &Tui::ZCommandNotifier::activated, [&] { /* ... */ });

    QObject::connect(new Tui::ZCommandNotifier("OpenFile", root),
                     &Tui::ZCommandNotifier::activated, [&] { /* ... */ });

    Tui::ZCommandNotifier *saveCommand = new Tui::ZCommandNotifier("SaveFile", root);
    QObject::connect(saveCommand, &Tui::ZCommandNotifier::activated, [&] { /* ... */ });

    saveCommand->setEnabled(false);

    QObject::connect(new Tui::ZCommandNotifier("Quit", root),
                     &Tui::ZCommandNotifier::activated, [&] { /* ... */ });

    QObject::connect(new Tui::ZCommandNotifier("AboutDialog", root),
                     &Tui::ZCommandNotifier::activated, [&] { /* ... */ });
// snippet-end
}