File indexing completed on 2025-01-19 04:46:55

0001 /*
0002    SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "headerstylemenu_gui.h"
0008 #include <MessageViewer/HeaderStyleMenuManager>
0009 #include <QStandardPaths>
0010 
0011 #include <QApplication>
0012 #include <QCommandLineParser>
0013 #include <QMenu>
0014 #include <QMenuBar>
0015 #include <QVBoxLayout>
0016 
0017 #include <KActionCollection>
0018 #include <KActionMenu>
0019 #include <MessageViewer/HeaderStrategy>
0020 #include <MessageViewer/HeaderStyle>
0021 #include <MessageViewer/HeaderStylePlugin>
0022 #include <QTextEdit>
0023 
0024 HeaderStyleMenuTest::HeaderStyleMenuTest(QWidget *parent)
0025     : QWidget(parent)
0026 {
0027     auto menu = new QMenuBar(this);
0028     auto hbox = new QVBoxLayout(this);
0029     hbox->addWidget(menu);
0030     auto manager = new MessageViewer::HeaderStyleMenuManager(new KActionCollection(this), this);
0031     menu->addAction(manager->menu());
0032     mTextEdit = new QTextEdit(this);
0033     mTextEdit->setReadOnly(true);
0034     hbox->addWidget(mTextEdit);
0035     connect(manager, &MessageViewer::HeaderStyleMenuManager::styleChanged, this, &HeaderStyleMenuTest::styleChanged);
0036     manager->readConfig();
0037 }
0038 
0039 HeaderStyleMenuTest::~HeaderStyleMenuTest() = default;
0040 
0041 void HeaderStyleMenuTest::styleChanged(MessageViewer::HeaderStylePlugin *plugin)
0042 {
0043     mTextEdit->append(QStringLiteral("strategy: %1, headerstyle: %2")
0044                           .arg(QLatin1StringView(plugin->headerStrategy()->name()))
0045                           .arg(QLatin1StringView(plugin->headerStyle()->name())));
0046 }
0047 
0048 int main(int argc, char **argv)
0049 {
0050     QApplication app(argc, argv);
0051     QStandardPaths::setTestModeEnabled(true);
0052     QCommandLineParser parser;
0053     parser.addVersionOption();
0054     parser.addHelpOption();
0055     parser.process(app);
0056 
0057     auto w = new HeaderStyleMenuTest();
0058     w->resize(800, 200);
0059     w->show();
0060     app.exec();
0061     delete w;
0062     return 0;
0063 }
0064 
0065 #include "moc_headerstylemenu_gui.cpp"