demo_konsolepart.cpp 2.87 KB
Newer Older
1
/*
2
3
4
 SPDX-FileCopyrightText: 2017 Kurt Hindenburg <kurt.hindenburg@gmail.com>

 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5
6
7
8
*/

#include "demo_konsolepart.h"

9
10
11
#include <QApplication>
#include <QMenu>
#include <QMenuBar>
Kurt Hindenburg's avatar
Kurt Hindenburg committed
12
#include <QDebug>
13

14
15
16
#include <KPluginLoader>
#include <KPluginFactory>
#include <KService>
17
#include <KWindowSystem>
18
#include <KWindowEffects>
19

20
21
// see below notes
//#include "../../../WindowSystemInfo.h"
22
23

demo_konsolepart::demo_konsolepart()
24
25
26
27
    : KMainWindow(),
      _mainWindow(nullptr),
      _terminalPart(nullptr),
      _terminal(nullptr)
28
{
29
30
31
32
33
34
35
36
37
38
    const bool useTranslucency = KWindowSystem::compositingActive();

    setAttribute(Qt::WA_TranslucentBackground, useTranslucency);
    setAttribute(Qt::WA_NoSystemBackground, false);

    // This is used in EditProfileDialog to show the warnings about
    // transparency issues - needs refactoring as the above
    // include does not work
//    WindowSystemInfo::HAVE_TRANSPARENCY = useTranslucency;

39
40
    // Create terminal part and embed in into the main window
    _terminalPart = createPart();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
41
    if (_terminalPart == nullptr) {
42
43
44
45
46
47
48
49
50
51
52
53
54
55
        return;
    }

    QMenu* fileMenu = menuBar()->addMenu(QStringLiteral("File"));
    QAction* manageProfilesAction = fileMenu->addAction(QStringLiteral("Manage Profiles..."));
    connect(manageProfilesAction, &QAction::triggered, this, &demo_konsolepart::manageProfiles);
    QAction* quitAction = fileMenu->addAction(QStringLiteral("Quit"));
    connect(quitAction, &QAction::triggered, this, &demo_konsolepart::quit);

    connect(_terminalPart, &KParts::ReadOnlyPart::destroyed, this, &demo_konsolepart::quit);

    setCentralWidget(_terminalPart->widget());
    _terminal = qobject_cast<TerminalInterface*>(_terminalPart);

Kurt Hindenburg's avatar
Kurt Hindenburg committed
56
57
58
59
60
61
    // Test if blur is enabled for profile
    bool blurEnabled;
    QMetaObject::invokeMethod(_terminalPart, "isBlurEnabled",
                              Qt::DirectConnection,
                              Q_RETURN_ARG(bool, blurEnabled));
    qWarning()<<"blur enabled: "<<blurEnabled;
Yuri Chornoivan's avatar
Yuri Chornoivan committed
62
    KWindowEffects::enableBlurBehind(windowHandle(), blurEnabled);
63
64
65
66
}

demo_konsolepart::~demo_konsolepart()
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
67
    if (_terminalPart != nullptr) {
68
69
70
71
72
73
74
75
76
77
78
        disconnect(_terminalPart, &KParts::ReadOnlyPart::destroyed, this, &demo_konsolepart::quit);
    }
}

KParts::ReadOnlyPart* demo_konsolepart::createPart()
{
    KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("konsolepart"));
    Q_ASSERT(service);
    KPluginFactory* factory = KPluginLoader(service->library()).factory();
    Q_ASSERT(factory);

Kurt Hindenburg's avatar
Kurt Hindenburg committed
79
    auto* terminalPart = factory->create<KParts::ReadOnlyPart>(this);
80
81
82
83
84
85
86
87
88
89
90
91
92
93

    return terminalPart;
}

void demo_konsolepart::manageProfiles()
{
    QMetaObject::invokeMethod(_terminalPart, "showManageProfilesDialog",
        Qt::QueuedConnection, Q_ARG(QWidget*, QApplication::activeWindow()));
}

void demo_konsolepart::quit()
{
    close();
}