File indexing completed on 2024-04-14 14:31:19

0001 /**
0002  * test_highlighter.cpp
0003  *
0004  * SPDX-FileCopyrightText: 2004 Zack Rusin <zack@kde.org>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-or-later
0007  */
0008 #include "highlighterexample.h"
0009 
0010 #include <QAction>
0011 #include <QApplication>
0012 #include <QContextMenuEvent>
0013 #include <QDebug>
0014 #include <QMenu>
0015 
0016 TestSpell::TestSpell()
0017     : QTextEdit()
0018 {
0019     hl = new Sonnet::Highlighter(this);
0020 }
0021 
0022 void TestSpell::contextMenuEvent(QContextMenuEvent *e)
0023 {
0024     qDebug() << "TestSpell::contextMenuEvent";
0025     QMenu *popup = createStandardContextMenu();
0026     QMenu *subMenu = new QMenu(popup);
0027     subMenu->setTitle(QStringLiteral("Text highlighting"));
0028     connect(subMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotActivate()));
0029     QAction *action = new QAction(QStringLiteral("active or not"), popup);
0030     popup->addSeparator();
0031     popup->addMenu(subMenu);
0032     subMenu->addAction(action);
0033     popup->exec(e->globalPos());
0034     delete popup;
0035 }
0036 
0037 void TestSpell::slotActivate()
0038 {
0039     qDebug() << "Activate or not highlight :";
0040     hl->setActive(!hl->isActive());
0041 }
0042 
0043 int main(int argc, char **argv)
0044 {
0045     QApplication app(argc, argv);
0046 
0047     QTextEdit *test = new TestSpell();
0048     test->show();
0049 
0050     return app.exec();
0051 }
0052 
0053 #include "moc_highlighterexample.cpp"