labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

CantorWorksheetView.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  File : CantorWorksheetView.cpp
3  Project : LabPlot
4  Description : View class for CantorWorksheet
5  --------------------------------------------------------------------
6  Copyright : (C) 2015 Garvit Khatri (garvitdelhi@gmail.com)
7 
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  * This program is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU General Public License for more details. *
21  * *
22  * You should have received a copy of the GNU General Public License *
23  * along with this program; if not, write to the Free Software *
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
25  * Boston, MA 02110-1301 USA *
26  * *
27  ***************************************************************************/
28 
29 #include "CantorWorksheetView.h"
31 
32 #include <QHBoxLayout>
33 #include <QLabel>
34 #include <QMenu>
35 #include <QToolBar>
36 
37 #include <KToggleAction>
38 #include <KLocalizedString>
39 #include <KParts/ReadWritePart>
40 
42  m_worksheet(worksheet) {
43 
44  auto* layout = new QHBoxLayout(this);
45  layout->setContentsMargins(0, 0, 0, 0);
46  m_part = worksheet->part();
47  if (m_part) {
48  layout->addWidget(m_part->widget());
49  initActions();
52  } else {
53  QLabel* label = new QLabel(i18n("Failed to initialize %1", m_worksheet->backendName()));
54  label->setAlignment(Qt::AlignHCenter);
55  layout->addWidget(label);
56  }
57 }
58 
60  auto* cantorActionGroup = new QActionGroup(this);
61  cantorActionGroup->setExclusive(false);
62 
63  m_restartBackendAction = new QAction(QIcon::fromTheme("system-reboot"), i18n("Restart Backend"), cantorActionGroup);
64  m_restartBackendAction->setData("restart_backend");
65 
66  m_evaluateWorsheetAction = new QAction(QIcon::fromTheme("system-run"), i18n("Evaluate Worksheet"), cantorActionGroup);
67  m_evaluateWorsheetAction->setData("evaluate_worksheet");
68 
69  m_evaluateEntryAction = new QAction(QIcon::fromTheme(QLatin1String("media-playback-start")), i18n("Evaluate Entry"), cantorActionGroup);
70  m_evaluateEntryAction->setShortcut(Qt::SHIFT + Qt::Key_Return);
71  m_evaluateEntryAction->setData("evaluate_current");
72 
73  m_insertCommandEntryAction = new QAction(QIcon::fromTheme(QLatin1String("run-build")), i18n("Insert Command Entry"), cantorActionGroup);
74  m_insertCommandEntryAction->setData("insert_command_entry");
75  m_insertCommandEntryAction->setShortcut(Qt::CTRL + Qt::Key_Return);
76 
77  m_insertTextEntryAction = new QAction(QIcon::fromTheme(QLatin1String("draw-text")), i18n("Insert Text Entry"), cantorActionGroup);
78  m_insertTextEntryAction->setData("insert_text_entry");
79 
80  //markdown entry is only available if cantor was compiled with libdiscovery (cantor 18.12 and later)
81  if (m_part->action("insert_markdown_entry")) {
82  m_insertTextEntryAction = new QAction(QIcon::fromTheme(QLatin1String("text-x-markdown")), i18n("Insert Markdown Entry"), cantorActionGroup);
83  m_insertTextEntryAction->setData("insert_markdown_entry");
84  }
85 
86  m_insertLatexEntryAction = new QAction(QIcon::fromTheme(QLatin1String("text-x-tex")), i18n("Insert LaTeX Entry"), cantorActionGroup);
87  m_insertLatexEntryAction->setData("insert_latex_entry");
88 
89  m_insertPageBreakAction = new QAction(QIcon::fromTheme(QLatin1String("go-next-view-page")), i18n("Insert Page Break"), cantorActionGroup);
90  m_insertPageBreakAction->setData("insert_page_break_entry");
91 
92  m_removeCurrentEntryAction = new QAction(QIcon::fromTheme(QLatin1String("edit-delete")), i18n("Remove Current Entry"), cantorActionGroup);
93  m_removeCurrentEntryAction->setData("remove_current");
94 
95  m_zoomIn = new QAction(QIcon::fromTheme(QLatin1String("zoom-in")), i18n("Zoom In"), cantorActionGroup);
96  m_zoomIn->setData("view_zoom_in");
97  m_zoomIn->setShortcut(Qt::CTRL+Qt::Key_Plus);
98 
99  m_zoomOut = new QAction(QIcon::fromTheme(QLatin1String("zoom-out")), i18n("Zoom Out"), cantorActionGroup);
100  m_zoomOut->setData("view_zoom_out");
101  m_zoomOut->setShortcut(Qt::CTRL+Qt::Key_Minus);
102 
103  m_find = new QAction(QIcon::fromTheme(QLatin1String("edit-find")), i18n("Find"), cantorActionGroup);
104  m_find->setData("edit_find");
105  m_find->setShortcut(Qt::CTRL+Qt::Key_F);
106 
107  m_replace = new QAction(QIcon::fromTheme(QLatin1String("edit-find-replace")), i18n("Replace"), cantorActionGroup);
108  m_replace->setData("edit_replace");
109  m_replace->setShortcut(Qt::CTRL+Qt::Key_R);
110 
111  m_lineNumbers = new KToggleAction(i18n("Line Numbers"), cantorActionGroup);
112  m_lineNumbers->setChecked(false);
113  m_lineNumbers->setData("enable_expression_numbers");
114 
115  m_animateWorksheet = new KToggleAction(i18n("Animate Worksheet"), cantorActionGroup);
116  m_animateWorksheet->setChecked(true);
117  m_animateWorksheet->setData("enable_animations");
118 
119  m_latexTypesetting = new KToggleAction(i18n("LaTeX Typesetting"), cantorActionGroup);
120  m_latexTypesetting->setChecked(true);
121  m_latexTypesetting->setData("enable_typesetting");
122 
123  m_showCompletion = new QAction(i18n("Syntax Completion"), cantorActionGroup);
124  m_showCompletion->setShortcut(Qt::CTRL + Qt::Key_Space);
125  m_showCompletion->setData("show_completion");
126 
127  //actions, that are CAS-backend specific and not always available
128  if (m_part->action("eigenvectors_assistant")) {
129  m_computeEigenvectorsAction = new QAction(i18n("Compute Eigenvectors"), cantorActionGroup);
130  m_computeEigenvectorsAction->setData("eigenvectors_assistant");
131  }
132 
133  if (m_part->action("creatematrix_assistant")) {
134  m_createMatrixAction = new QAction(i18n("Create Matrix"), cantorActionGroup);
135  m_createMatrixAction->setData("creatematrix_assistant");
136  }
137 
138  if (m_part->action("eigenvalues_assistant")) {
139  m_computeEigenvaluesAction = new QAction(i18n("Compute Eigenvalues"), cantorActionGroup);
140  m_computeEigenvaluesAction->setData("eigenvalues_assistant");
141  }
142 
143  if (m_part->action("invertmatrix_assistant")) {
144  m_invertMatrixAction = new QAction(i18n("Invert Matrix"), cantorActionGroup);
145  m_invertMatrixAction->setData("invertmatrix_assistant");
146  }
147 
148  if (m_part->action("differentiate_assistant")) {
149  m_differentiationAction = new QAction(i18n("Differentiation"), cantorActionGroup);
150  m_differentiationAction->setData("differentiate_assistant");
151  }
152 
153  if (m_part->action("integrate_assistant")) {
154  m_integrationAction = new QAction(i18n("Integration"), cantorActionGroup);
155  m_integrationAction->setData("integrate_assistant");
156  }
157 
158  if (m_part->action("solve_assistant")) {
159  m_solveEquationsAction = new QAction(i18n("Solve Equations"), cantorActionGroup);
160  m_solveEquationsAction->setData("solve_assistant");
161  }
162 
163  connect(cantorActionGroup, &QActionGroup::triggered, this, &CantorWorksheetView::triggerCantorAction);
164 }
165 
167  m_worksheetMenu = new QMenu(i18n("Worksheet"), m_part->widget());
169  m_worksheetMenu->addSeparator();
177  m_worksheetMenu->addSeparator();
179 
181  m_linearAlgebraMenu = new QMenu("Linear Algebra", m_part->widget());
190  }
191 
193  m_calculateMenu = new QMenu(i18n("Calculate"), m_part->widget());
200  }
201 
202  m_settingsMenu = new QMenu(i18n("Settings"), m_part->widget());
203  m_settingsMenu->setIcon(QIcon::fromTheme(QLatin1String("settings-configure")));
204  m_settingsMenu->addAction(m_lineNumbers);
207  m_settingsMenu->addAction(m_showCompletion);
208 }
209 
210 /*!
211  * Populates the menu \c menu with the CantorWorksheet and CantorWorksheet view relevant actions.
212  * The menu is used
213  * - as the context menu in CantorWorksheetView
214  * - as the "CantorWorksheet menu" in the main menu-bar (called form MainWin)
215  * - as a part of the CantorWorksheet context menu in project explorer
216  */
218  Q_ASSERT(menu);
219  if (!m_part)
220  return;
221 
222  QAction* firstAction = nullptr;
223  // if we're populating the context menu for the project explorer, then
224  //there're already actions available there. Skip the first title-action
225  //and insert the action at the beginning of the menu.
226  if (menu->actions().size()>1)
227  firstAction = menu->actions().at(1);
228 
229  if (!m_worksheetMenu)
230  initMenus();
231 
232  menu->insertMenu(firstAction, m_worksheetMenu);
234  menu->insertMenu(firstAction, m_linearAlgebraMenu);
235  if (m_calculateMenu)
236  menu->insertMenu(firstAction, m_calculateMenu);
237  menu->insertSeparator(firstAction);
238  menu->insertAction(firstAction, m_zoomIn);
239  menu->insertAction(firstAction, m_zoomOut);
240  menu->insertSeparator(firstAction);
241  menu->insertAction(firstAction, m_find);
242  menu->insertAction(firstAction, m_replace);
243  menu->insertSeparator(firstAction);
244  menu->insertMenu(firstAction, m_settingsMenu);
245  menu->insertSeparator(firstAction);
246  menu->insertAction(firstAction, m_restartBackendAction);
247  menu->insertSeparator(firstAction);
248 }
249 
250 void CantorWorksheetView::fillToolBar(QToolBar* toolbar) {
251  if (!m_part)
252  return;
253  toolbar->addAction(m_restartBackendAction);
254  toolbar->addAction(m_evaluateWorsheetAction);
255 }
256 
257 /*!
258  * Slot for actions triggered
259  */
261  QString actionName = action->data().toString();
262  if (!actionName.isEmpty()) m_part->action(actionName.toStdString().c_str())->trigger();
263 }
264 
266  if (m_part)
267  m_part->widget()->setParent(nullptr);
268 }
269 
270 void CantorWorksheetView::statusChanged(Cantor::Session::Status status) {
271  if (status == Cantor::Session::Running) {
272  m_evaluateWorsheetAction->setText(i18n("Interrupt"));
273  m_evaluateWorsheetAction->setIcon(QIcon::fromTheme(QLatin1String("dialog-close")));
274  emit m_worksheet->statusInfo(i18n("Calculating..."));
275  } else {
276  m_evaluateWorsheetAction->setText(i18n("Evaluate Worksheet"));
277  m_evaluateWorsheetAction->setIcon(QIcon::fromTheme(QLatin1String("system-run")));
278  emit m_worksheet->statusInfo(i18n("Ready"));
279  }
280 }
void statusInfo(const QString &)
Emitted whenever some aspect in the tree wants to give status information to the user.
void statusChanged(Cantor::Session::Status)
QAction * m_insertLatexEntryAction
QAction * m_insertMarkdownEntryAction
void triggerCantorAction(QAction *)
CantorWorksheet * m_worksheet
KParts::ReadWritePart * m_part
QAction * m_insertCommandEntryAction
QAction * m_computeEigenvaluesAction
QAction * m_evaluateWorsheetAction
CantorWorksheetView(CantorWorksheet *)
void fillToolBar(QToolBar *)
QAction * m_computeEigenvectorsAction
QAction * m_removeCurrentEntryAction
void statusChanged(Cantor::Session::Status)
KParts::ReadWritePart * part()
void requestProjectContextMenu(QMenu *)
#define i18n(m)
Definition: nsl_common.h:38