File: kcodecactiontest.cpp

package info (click to toggle)
kconfigwidgets 5.116.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,220 kB
  • sloc: cpp: 8,164; perl: 43; sh: 21; makefile: 7
file content (87 lines) | stat: -rw-r--r-- 2,813 bytes parent folder | download | duplicates (2)
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
#include "kcodecactiontest.h"

#include <QApplication>
#include <QMenuBar>
#include <QToolBar>

#include <QDebug>

#include <kcodecaction.h>

int main(int argc, char **argv)
{
    QApplication::setApplicationName(QStringLiteral("kcodecactiontest"));
    QApplication app(argc, argv);

    CodecActionTest *test = new CodecActionTest;
    test->show();

    return app.exec();
}

CodecActionTest::CodecActionTest(QWidget *parent)
    : QMainWindow(parent)
    , m_comboCodec(new KCodecAction(QStringLiteral("Combo Codec Action"), this))
    , m_buttonCodec(new KCodecAction(QStringLiteral("Button Codec Action"), this))
{
    // clang-format off
    m_comboCodec->setToolBarMode(KCodecAction::ComboBoxMode);
    connect(m_comboCodec, qOverload<QAction *>(&KSelectAction::triggered), this, &CodecActionTest::actionTriggered);
    connect(m_comboCodec, &KSelectAction::indexTriggered, this, &CodecActionTest::indexTriggered);
    connect(m_comboCodec, &KSelectAction::textTriggered, this, &CodecActionTest::textTriggered);
#if KCONFIGWIDGETS_BUILD_DEPRECATED_SINCE(5, 103)
    connect(m_comboCodec, &KCodecAction::codecTriggered, this, &CodecActionTest::codecTriggered);
#endif
    connect(m_comboCodec, &KCodecAction::codecNameTriggered, this, &CodecActionTest::nameTriggered);

    m_buttonCodec->setToolBarMode(KCodecAction::MenuMode);
    connect(m_buttonCodec, qOverload<QAction *>(&KSelectAction::triggered), this, &CodecActionTest::actionTriggered);
    connect(m_buttonCodec, &KSelectAction::indexTriggered, this, &CodecActionTest::indexTriggered);
    connect(m_buttonCodec, &KSelectAction::textTriggered, this, &CodecActionTest::textTriggered);
#if KCONFIGWIDGETS_BUILD_DEPRECATED_SINCE(5, 103)
    connect(m_buttonCodec, &KCodecAction::codecTriggered, this, &CodecActionTest::codecTriggered);
#endif
    connect(m_buttonCodec, &KCodecAction::codecNameTriggered, this, &CodecActionTest::nameTriggered);
    // clang-format on

    menuBar()->addAction(m_comboCodec);
    menuBar()->addAction(m_buttonCodec);

    QToolBar *toolBar = addToolBar(QStringLiteral("Test"));
    toolBar->addAction(m_comboCodec);
    toolBar->addAction(m_buttonCodec);
}

void CodecActionTest::actionTriggered(QAction *action)
{
    qDebug() << action;
}

void CodecActionTest::indexTriggered(int index)
{
    qDebug() << index;
}

void CodecActionTest::textTriggered(const QString &text)
{
    qDebug() << text;
}

#if KCONFIGWIDGETS_BUILD_DEPRECATED_SINCE(5, 103)
void CodecActionTest::codecTriggered(QTextCodec *codec)
{
    qDebug() << codec->name() << ':' << codec->mibEnum();
}
#endif

void CodecActionTest::nameTriggered(const QString &codecName)
{
    qDebug() << codecName;
}

void CodecActionTest::slotActionTriggered(bool state)
{
    qDebug() << sender() << " state " << state;
}

#include "moc_kcodecactiontest.cpp"