File indexing completed on 2024-04-28 11:21:00

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 
0012 #include "lib/result.h"
0013 #include "lib/textresult.h"
0014 #include "lib/latexresult.h"
0015 #include "lib/imageresult.h"
0016 #include "lib/epsresult.h"
0017 #include "lib/animationresult.h"
0018 #include "lib/mimeresult.h"
0019 #include "lib/htmlresult.h"
0020 
0021 #include <KLocalizedString>
0022 
0023 ResultItem::ResultItem(Cantor::Result* result):
0024     m_result(result)
0025 {
0026 }
0027 
0028 ResultItem* ResultItem::create(WorksheetEntry* parent, Cantor::Result* result)
0029 {
0030     switch(result->type()) {
0031     case Cantor::TextResult::Type:
0032     case Cantor::LatexResult::Type:
0033     case Cantor::MimeResult::Type:
0034     case Cantor::HtmlResult::Type:
0035         return new TextResultItem(parent, result);
0036     case Cantor::ImageResult::Type:
0037     case Cantor::EpsResult::Type:
0038         return new ImageResultItem(parent, result);
0039     case Cantor::AnimationResult::Type:
0040         return new AnimationResultItem(parent, result);
0041     default:
0042         return nullptr;
0043     }
0044 }
0045 
0046 void ResultItem::addCommonActions(QObject* self, QMenu* menu)
0047 {
0048     menu->addAction(QIcon::fromTheme(QLatin1String("document-export")), i18n("Save result"), self, SLOT(saveResult()));
0049     menu->addAction(QIcon::fromTheme(QLatin1String("edit-delete")), i18n("Remove result"), self, [this](){
0050         this->needRemove();
0051     });
0052 }
0053 
0054 QGraphicsObject* ResultItem::graphicsObject()
0055 {
0056     return dynamic_cast<QGraphicsObject*>(this);
0057 }
0058 
0059 CommandEntry* ResultItem::parentEntry()
0060 {
0061     return qobject_cast<CommandEntry*>(graphicsObject()->parentObject());
0062 }
0063 
0064 Cantor::Result* ResultItem::result()
0065 {
0066     return m_result;
0067 }
0068 
0069 void ResultItem::needRemove()
0070 {
0071     parentEntry()->removeResult(m_result);
0072 }