welcome page: remove background in active window when plugin is disabled

Before the change in the plugin enabling would only be effective on
next program start.
parent d348a833
Pipeline #14066 failed with stage
in 60 minutes and 1 second
......@@ -104,6 +104,7 @@ public:
/** Sets a @p w widget that will be shown when there are no opened documents.
* This method takes the ownership of @p w.
* Pass @c nullptr for @p w for a blank background (default).
*/
void setBackgroundCentralWidget(QWidget* w);
......
......@@ -284,10 +284,14 @@ void MainWindowPrivate::showRightDock(bool b)
void MainWindowPrivate::setBackgroundCentralWidget(QWidget* w)
{
delete bgCentralWidget;
auto* l = static_cast<QVBoxLayout*>(centralWidget->layout());
l->addWidget(w, 2);
bgCentralWidget=w;
setBackgroundVisible(area->views().isEmpty());
bgCentralWidget = w;
if (bgCentralWidget) {
auto* l = static_cast<QVBoxLayout*>(centralWidget->layout());
l->addWidget(bgCentralWidget, 2);
setBackgroundVisible(area->views().isEmpty());
}
}
void MainWindowPrivate::setBackgroundVisible(bool v)
......
......@@ -33,7 +33,7 @@ K_PLUGIN_FACTORY_WITH_JSON(KDevWelcomePagePluginFactory, "kdevwelcomepage.json",
using namespace KDevelop;
namespace {
WelcomePageWidget* createWelcomePageWidget(QWidget* parent)
WelcomePageWidget* createWelcomePageWidget()
{
// don't attempt to load any QML if CPU doesn't have SSE2 support (cf. bug 381999)
// Note: Clang 4.0 moved the definition of __cpu_model (used by __builtin_cpu_supporst) into compiler-rt lib it seems -- let's just disable this feature on this compiler
......@@ -44,16 +44,25 @@ WelcomePageWidget* createWelcomePageWidget(QWidget* parent)
}
#endif
return new WelcomePageWidget({}, parent);
return new WelcomePageWidget({});
}
}
KDevWelcomePagePlugin::KDevWelcomePagePlugin( QObject* parent, const QVariantList& )
: IPlugin(QStringLiteral("kdevwelcomepage"), parent )
{
m_welcomePageWidget = createWelcomePageWidget();
if (m_welcomePageWidget) {
auto mainWindow = qobject_cast<Sublime::MainWindow*>(ICore::self()->uiController()->activeMainWindow());
mainWindow->setBackgroundCentralWidget(m_welcomePageWidget);
}
}
void KDevWelcomePagePlugin::unload()
{
auto mainWindow = qobject_cast<Sublime::MainWindow*>(ICore::self()->uiController()->activeMainWindow());
if (auto welcomePageWidget = createWelcomePageWidget(mainWindow)) {
mainWindow->setBackgroundCentralWidget(welcomePageWidget);
if (mainWindow && m_welcomePageWidget) {
mainWindow->setBackgroundCentralWidget(nullptr);
}
}
......
......@@ -21,12 +21,20 @@
#define KDEVPLATFORM_PLUGIN_KDEVWELCOMEPAGEPLUGIN_H
#include <interfaces/iplugin.h>
// Qt
#include <QPointer>
class KDevWelcomePagePlugin : public KDevelop::IPlugin
{
Q_OBJECT
public:
KDevWelcomePagePlugin( QObject* parent, const QList<QVariant>& );
public:
void unload() override;
private:
QPointer<QWidget> m_welcomePageWidget;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment