1 /*
2     SPDX-License-Identifier: GPL-2.0-or-later
3     SPDX-FileCopyrightText: 2012 Martin Kuettler <martin.kuettler@gmail.com>
4 */
5 
6 #include "resultitem.h"
7 #include "textresultitem.h"
8 #include "imageresultitem.h"
9 #include "animationresultitem.h"
10 #include "commandentry.h"
11 #include "worksheetentry.h"
12 
13 #include "lib/result.h"
14 #include "lib/textresult.h"
15 #include "lib/latexresult.h"
16 #include "lib/imageresult.h"
17 #include "lib/epsresult.h"
18 #include "lib/animationresult.h"
19 #include "lib/mimeresult.h"
20 #include "lib/htmlresult.h"
21 
22 #include <QObject>
23 
24 #include <QIcon>
25 #include <KLocalizedString>
26 #include <QDebug>
27 
ResultItem(Cantor::Result * result)28 ResultItem::ResultItem(Cantor::Result* result):
29     m_result(result)
30 {
31 }
32 
create(WorksheetEntry * parent,Cantor::Result * result)33 ResultItem* ResultItem::create(WorksheetEntry* parent, Cantor::Result* result)
34 {
35     switch(result->type()) {
36     case Cantor::TextResult::Type:
37     case Cantor::LatexResult::Type:
38     case Cantor::MimeResult::Type:
39     case Cantor::HtmlResult::Type:
40         {
41             return new TextResultItem(parent, result);
42         }
43     case Cantor::ImageResult::Type:
44     case Cantor::EpsResult::Type:
45         {
46             return new ImageResultItem(parent, result);
47         }
48     case Cantor::AnimationResult::Type:
49         {
50             return new AnimationResultItem(parent, result);
51         }
52     default:
53         return nullptr;
54     }
55 }
56 
addCommonActions(QObject * self,QMenu * menu)57 void ResultItem::addCommonActions(QObject* self, QMenu* menu)
58 {
59     menu->addAction(i18n("Save result"), self, SLOT(saveResult()));
60     menu->addAction(QIcon::fromTheme(QLatin1String("edit-delete")), i18n("Remove result"), self, [this](){
61         this->needRemove();
62     });
63 }
64 
graphicsObject()65 QGraphicsObject* ResultItem::graphicsObject()
66 {
67     return dynamic_cast<QGraphicsObject*>(this);
68 }
69 
parentEntry()70 CommandEntry* ResultItem::parentEntry()
71 {
72     return qobject_cast<CommandEntry*>(graphicsObject()->parentObject());
73 }
74 
result()75 Cantor::Result* ResultItem::result()
76 {
77     return m_result;
78 }
79 
needRemove()80 void ResultItem::needRemove()
81 {
82     parentEntry()->removeResult(m_result);
83 }
84