documentationpanelplugin.cpp 2.92 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA  02110-1301, USA.

    ---
    Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
 */

Shubham  .'s avatar
Shubham . committed
21
22
#include "cassert"

23
#include "documentationpanelplugin.h"
24
#include "session.h"
Shubham  .'s avatar
Shubham . committed
25

26
#include <QIcon>
27

Shubham  .'s avatar
Shubham . committed
28
DocumentationPanelPlugin::DocumentationPanelPlugin(QObject* parent, QList<QVariant> args) : Cantor::PanelPlugin(parent), m_widget(nullptr)
29
30
31
32
33
34
35
36
37
{
    Q_UNUSED(args);
}

DocumentationPanelPlugin::~DocumentationPanelPlugin()
{
    delete m_widget;
}

Shubham  .'s avatar
Shubham . committed
38
QWidget* DocumentationPanelPlugin::widget()
39
{
Shubham  .'s avatar
Shubham . committed
40
    if(!m_widget)
41
    {
42
43
        // find the default backend and then load it, currently hardcoding the values
        m_widget = new DocumentationPanelWidget(QLatin1String("Maxima"), QLatin1String("maximabackend"), parentWidget());
Shubham  .'s avatar
Shubham . committed
44
        connect(m_cantorShell, SIGNAL(requestDocumentation(QString)), m_widget, SLOT(contextSensitiveHelp(QString)));
45
46
47
48
49
50
51
    }

    return m_widget;
}

bool DocumentationPanelPlugin::showOnStartup()
{
Shubham  .'s avatar
Shubham . committed
52
    return true;
53
54
}

55
56
QIcon DocumentationPanelPlugin::icon() const
{
57
    return QIcon::fromTheme(m_backendIcon);
58
59
60
61
}

QString DocumentationPanelPlugin::backendName() const
{
62
    return m_backendName;
63
64
}

Shubham  .'s avatar
Shubham . committed
65
66
void DocumentationPanelPlugin::connectToShell(QObject* cantorShell)
{
Shubham  .'s avatar
Shubham . committed
67
    m_cantorShell = cantorShell;
Shubham  .'s avatar
Shubham . committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    connect(cantorShell, SIGNAL(requestDocumentation(QString)), this, SIGNAL(visibilityRequested()));
}

Cantor::PanelPlugin::State DocumentationPanelPlugin::saveState()
{
    Cantor::PanelPlugin::State state = PanelPlugin::saveState();
    state.inners.append(m_backendName);
    state.inners.append(m_backendIcon);
    return state;
}

void DocumentationPanelPlugin::restoreState(const Cantor::PanelPlugin::State& state)
{
    PanelPlugin::restoreState(state);

    if(state.inners.size() > 0)
    {
        assert(state.inners.size() == 2);
        m_backendName = state.inners[0].toString();
        m_backendIcon = state.inners[1].toString();
    }
89
    else if(session())
Shubham  .'s avatar
Shubham . committed
90
91
92
93
    {
        m_backendName = session()->backend()->name();
        m_backendIcon = session()->backend()->icon();

94
95
        if(m_widget)
            m_widget->updateBackend(m_backendName, m_backendIcon);
Shubham  .'s avatar
Shubham . committed
96
97
98
    }
}

Shubham  .'s avatar
Shubham . committed
99
K_PLUGIN_FACTORY_WITH_JSON(documentationpanelplugin, "documentationpanelplugin.json", registerPlugin<DocumentationPanelPlugin>();)
100
#include "documentationpanelplugin.moc"