diff --git a/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.h b/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.h --- a/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.h +++ b/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.h @@ -30,8 +30,8 @@ ~ViewerPluginCreateeventTest(); private Q_SLOTS: - void shouldHaveDefaultValue(); void shouldCreateAction(); + void shouldShowWidget(); }; #endif // VIEWERPLUGINCREATEEVENTTEST_H diff --git a/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.cpp b/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.cpp --- a/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.cpp +++ b/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.cpp @@ -42,25 +42,27 @@ } -void ViewerPluginCreateeventTest::shouldHaveDefaultValue() +void ViewerPluginCreateeventTest::shouldCreateAction() { MessageViewer::ViewerPluginCreateevent *event = new MessageViewer::ViewerPluginCreateevent(this); QVERIFY(!event->viewerPluginName().isEmpty()); QWidget *parent = new QWidget(0); parent->setLayout(new QHBoxLayout); - QVERIFY(event->createView(parent, new KActionCollection(this))); + MessageViewer::ViewerPluginInterface *interface = event->createView(parent, new KActionCollection(this)); + QVERIFY(interface); + QVERIFY(!interface->actions().isEmpty()); } -void ViewerPluginCreateeventTest::shouldCreateAction() +void ViewerPluginCreateeventTest::shouldShowWidget() { MessageViewer::ViewerPluginCreateevent *event = new MessageViewer::ViewerPluginCreateevent(this); QWidget *parent = new QWidget(0); parent->setLayout(new QHBoxLayout); MessageViewer::ViewerPluginInterface *interface = event->createView(parent, new KActionCollection(this)); - QVERIFY(!interface->actions().isEmpty()); + interface->execute(); QWidget *createeventwidget = parent->findChild(QStringLiteral("eventedit")); QVERIFY(createeventwidget); - QCOMPARE(createeventwidget->isVisible(), false); + QCOMPARE(createeventwidget->isHidden(), false); } QTEST_MAIN(ViewerPluginCreateeventTest) diff --git a/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.h b/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.h --- a/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.h +++ b/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.h @@ -46,6 +46,8 @@ private: void createAction(KActionCollection *ac); + EventEdit *widget(); + Akonadi::Item mMessageItem; EventEdit *mEventEdit; QList mAction; diff --git a/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.cpp b/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.cpp --- a/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.cpp +++ b/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.cpp @@ -30,13 +30,9 @@ using namespace MessageViewer; ViewerPluginCreateEventInterface::ViewerPluginCreateEventInterface(KActionCollection *ac, QWidget *parent) - : ViewerPluginInterface(parent) + : ViewerPluginInterface(parent), + mEventEdit(nullptr) { - mEventEdit = new EventEdit(parent); - connect(mEventEdit, &EventEdit::createEvent, this, &ViewerPluginCreateEventInterface::slotCreateEvent); - mEventEdit->setObjectName(QStringLiteral("eventedit")); - parent->layout()->addWidget(mEventEdit); - mEventEdit->hide(); createAction(ac); } @@ -63,17 +59,17 @@ void ViewerPluginCreateEventInterface::setMessage(const KMime::Message::Ptr &value) { - mEventEdit->setMessage(value); + widget()->setMessage(value); } void ViewerPluginCreateEventInterface::closePlugin() { - mEventEdit->slotCloseWidget(); + widget()->slotCloseWidget(); } void ViewerPluginCreateEventInterface::showWidget() { - mEventEdit->showEventEdit(); + widget()->showEventEdit(); } void ViewerPluginCreateEventInterface::setMessageItem(const Akonadi::Item &item) @@ -94,6 +90,19 @@ } } +EventEdit *ViewerPluginCreateEventInterface::widget() +{ + if (!mEventEdit) { + QWidget *parentWidget = static_cast(parent()); + mEventEdit = new EventEdit(parentWidget); + connect(mEventEdit, &EventEdit::createEvent, this, &ViewerPluginCreateEventInterface::slotCreateEvent); + mEventEdit->setObjectName(QStringLiteral("eventedit")); + parentWidget->layout()->addWidget(mEventEdit); + mEventEdit->hide(); + } + return mEventEdit; +} + void ViewerPluginCreateEventInterface::slotCreateEvent(const KCalCore::Event::Ptr &eventPtr, const Akonadi::Collection &collection) { CreateEventJob *createJob = new CreateEventJob(eventPtr, collection, mMessageItem, this);