cantor.h 3.82 KB
Newer Older
Alexander Rieder's avatar
Alexander Rieder committed
1 2
/*
    Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com>
3

Alexander Rieder's avatar
Alexander Rieder committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
    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.
 */

20

Alexander Rieder's avatar
Alexander Rieder committed
21 22
#ifndef CANTOR_H
#define CANTOR_H
23

24
#include <QObject>
25
#include <KParts/MainWindow>
26 27

#include <QList>
28 29
#include <QStringList>
#include <QMap>
30

31 32 33
#include "lib/panelpluginhandler.h"
#include "lib/panelplugin.h"

Filipe Saraiva's avatar
Filipe Saraiva committed
34
class QTabWidget;
35
class KTextEdit;
36
class KRecentFilesAction;
37

38 39
namespace Cantor{
class WorksheetAccessInterface;
Filipe Saraiva's avatar
Filipe Saraiva committed
40
}
41

42 43 44 45
namespace KParts{
    class ReadWritePart;
}

46 47
using PanelStates = QMap<QString, Cantor::PanelPlugin::State>;

48 49 50 51
/**
 * This is the application "Shell".  It has a menubar, toolbar, and
 * statusbar but relies on the "Part" to do all the real work.
 */
Alexander Rieder's avatar
Alexander Rieder committed
52
class CantorShell : public KParts::MainWindow
53 54 55 56 57 58
{
    Q_OBJECT
public:
    /**
     * Default Constructor
     */
Alexander Rieder's avatar
Alexander Rieder committed
59
    CantorShell();
60 61 62 63

    /**
     * Default Destructor
     */
64
    ~CantorShell() override;
65

66
    Cantor::WorksheetAccessInterface* currentWorksheetAccessInterface();
67 68
    void addWorksheet();

69 70 71 72 73
protected:
    /**
     * This method is called when it is time for the app to save its
     * properties for session management purposes.
     */
74
    void saveProperties(KConfigGroup &) override;
75 76 77 78 79 80

    /**
     * This method is called when this app is restored.  The KConfig
     * object points to the session management config file that was saved
     * with @ref saveProperties
     */
81
    void readProperties(const KConfigGroup &) override;
82

83 84 85
Q_SIGNALS:
    void showHelp(QString);

86
public Q_SLOTS:
87
    void addWorksheet(const QString& backendName);
88 89
    /// Use this method/slot to load whatever file/URL you have
    void load(const QUrl& url);
90

91
private Q_SLOTS:
92 93
    void fileNew();
    void fileOpen();
94
    void onWorksheetSave(const QUrl& url);
95 96 97 98
    void optionsConfigureKeys();

    void activateWorksheet(int index);

99
    void setTabCaption(const QString& tab, const QIcon& icon);
100
    void updateBackendForPart(const QString& backend);
101
    void closeTab(int index = -1);
102 103 104

    void showSettings();

105
    void downloadExamples();
106
    void openExample();
107

108
    void initPanels();
109
    void updatePanel();
110
    void updateNewSubmenu();
111 112

    void pluginVisibilityRequested();
113
    void pluginCommandRunRequested(const QString& cmd);
114

115 116
private:
    void setupActions();
117
    void closeEvent(QCloseEvent*) override;
118
    bool reallyClose(bool checkAllParts = true);
119
    bool reallyCloseThisPart(KParts::ReadWritePart* part);
120
    void updateWindowTitle(const QString& fileName);
121
    void saveDockPanelsState(KParts::ReadWritePart* part);
122
    KParts::ReadWritePart* findPart(QWidget* widget);
123 124

private:
125
    QMap<KParts::ReadWritePart*, QStringList> m_pluginsVisibility;
126
    QMap<KParts::ReadWritePart*, PanelStates> m_pluginsStates;
127
    QList<KParts::ReadWritePart *> m_parts;
128
    QMap<KParts::ReadWritePart*, QString> m_parts2Backends;
129
    KParts::ReadWritePart* m_part;
Filipe Saraiva's avatar
Filipe Saraiva committed
130
    QTabWidget* m_tabWidget;
131
    QList<QDockWidget*> m_panels;
132
    QList<QAction*> m_newBackendActions;
133
    QDockWidget* m_helpDocker;
134
    KRecentFilesAction* m_recentProjectsAction;
Filipe Saraiva's avatar
Filipe Saraiva committed
135

136 137
    Cantor::PanelPluginHandler m_panelHandler;

Filipe Saraiva's avatar
Filipe Saraiva committed
138 139
    // For better UX: set previous used filter in "Open" action as default filter
    QString m_previousFilter;
140 141
};

Alexander Rieder's avatar
Alexander Rieder committed
142
#endif // CANTOR_H