File: highlighterexample.cpp

package info (click to toggle)
sonnet 5.116.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,976 kB
  • sloc: cpp: 7,535; sh: 15; makefile: 9
file content (53 lines) | stat: -rw-r--r-- 1,227 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
/**
 * test_highlighter.cpp
 *
 * SPDX-FileCopyrightText: 2004 Zack Rusin <zack@kde.org>
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */
#include "highlighterexample.h"

#include <QAction>
#include <QApplication>
#include <QContextMenuEvent>
#include <QDebug>
#include <QMenu>

TestSpell::TestSpell()
    : QTextEdit()
{
    hl = new Sonnet::Highlighter(this);
}

void TestSpell::contextMenuEvent(QContextMenuEvent *e)
{
    qDebug() << "TestSpell::contextMenuEvent";
    QMenu *popup = createStandardContextMenu();
    QMenu *subMenu = new QMenu(popup);
    subMenu->setTitle(QStringLiteral("Text highlighting"));
    connect(subMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotActivate()));
    QAction *action = new QAction(QStringLiteral("active or not"), popup);
    popup->addSeparator();
    popup->addMenu(subMenu);
    subMenu->addAction(action);
    popup->exec(e->globalPos());
    delete popup;
}

void TestSpell::slotActivate()
{
    qDebug() << "Activate or not highlight :";
    hl->setActive(!hl->isActive());
}

int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QTextEdit *test = new TestSpell();
    test->show();

    return app.exec();
}

#include "moc_highlighterexample.cpp"