File indexing completed on 2022-12-06 18:50:22

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2012 Martin Kuettler <martin.kuettler@gmail.com>
0004 */
0005 
0006 #include "resultitem.h"
0007 #include "textresultitem.h"
0008 #include "imageresultitem.h"
0009 #include "animationresultitem.h"
0010 #include "commandentry.h"
0011 #include "worksheetentry.h"
0012 
0013 #include "lib/result.h"
0014 #include "lib/textresult.h"
0015 #include "lib/latexresult.h"
0016 #include "lib/imageresult.h"
0017 #include "lib/epsresult.h"
0018 #include "lib/animationresult.h"
0019 #include "lib/mimeresult.h"
0020 #include "lib/htmlresult.h"
0021 
0022 #include <QObject>
0023 
0024 #include <QIcon>
0025 #include <KLocalizedString>
0026 #include <QDebug>
0027 
0028 ResultItem::ResultItem(Cantor::Result* result):
0029     m_result(result)
0030 {
0031 }
0032 
0033 ResultItem* ResultItem::create(WorksheetEntry* parent, Cantor::Result* result)
0034 {
0035     switch(result->type()) {
0036     case Cantor::TextResult::Type:
0037     case Cantor::LatexResult::Type:
0038     case Cantor::MimeResult::Type:
0039     case Cantor::HtmlResult::Type:
0040         {
0041             return new TextResultItem(parent, result);
0042         }
0043     case Cantor::ImageResult::Type:
0044     case Cantor::EpsResult::Type:
0045         {
0046             return new ImageResultItem(parent, result);
0047         }
0048     case Cantor::AnimationResult::Type:
0049         {
0050             return new AnimationResultItem(parent, result);
0051         }
0052     default:
0053         return nullptr;
0054     }
0055 }
0056 
0057 void ResultItem::addCommonActions(QObject* self, QMenu* menu)
0058 {
0059     menu->addAction(QIcon::fromTheme(QLatin1String("document-export")), i18n("Save result"), self, SLOT(saveResult()));
0060     menu->addAction(QIcon::fromTheme(QLatin1String("edit-delete")), i18n("Remove result"), self, [this](){
0061         this->needRemove();
0062     });
0063 }
0064 
0065 QGraphicsObject* ResultItem::graphicsObject()
0066 {
0067     return dynamic_cast<QGraphicsObject*>(this);
0068 }
0069 
0070 CommandEntry* ResultItem::parentEntry()
0071 {
0072     return qobject_cast<CommandEntry*>(graphicsObject()->parentObject());
0073 }
0074 
0075 Cantor::Result* ResultItem::result()
0076 {
0077     return m_result;
0078 }
0079 
0080 void ResultItem::needRemove()
0081 {
0082     parentEntry()->removeResult(m_result);
0083 }