File indexing completed on 2022-11-29 13:00:36

0001 /*
0002     SPDX-FileCopyrightText: 2006, 2007 Peter Hedlund <peter.hedlund@kdemail.net>
0003     SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef VOCABULARYDELEGATE_H
0008 #define VOCABULARYDELEGATE_H
0009 
0010 #include "readonlycontainermodel.h"
0011 #include "translateshelladapter.h"
0012 #include <QItemDelegate>
0013 #include <QModelIndex>
0014 
0015 class KEduVocDocument;
0016 
0017 namespace Editor
0018 {
0019 class VocabularyDelegate : public QItemDelegate
0020 {
0021     Q_OBJECT
0022 public:
0023     enum entryColumns {
0024         Translation = 0,
0025         Pronunciation,
0026         WordType,
0027         Synonym,
0028         Antonym,
0029         Example,
0030         Comment,
0031         Paraphrase,
0032         //         Audio,
0033         //         Image,
0034         EntryColumnsMAX
0035     };
0036 
0037     explicit VocabularyDelegate(QObject *parent = nullptr);
0038 
0039     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0040 
0041     void setEditorData(QWidget *editor, const QModelIndex &index) const override;
0042     void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0043     void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
0044 
0045     static int columnType(int column);
0046 
0047     bool hasAudio(const QModelIndex &index) const;
0048     bool hasImage(const QModelIndex &index) const;
0049     QString audioUrl(const QModelIndex &index) const;
0050     QString imageUrl(const QModelIndex &index) const;
0051     QPolygon audioPolygon(const QStyleOptionViewItem &option) const;
0052     QPolygon imagePolygon(const QStyleOptionViewItem &option) const;
0053 
0054 public Q_SLOTS:
0055     void setDocument(const std::shared_ptr<KEduVocDocument> &doc);
0056     bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) override;
0057 
0058 private:
0059     std::shared_ptr<KEduVocDocument> m_doc;
0060     TranslateShellAdapter m_translator;
0061 
0062     /** Returns the translations of the word of the given index */
0063     QSet<QString> getTranslations(const QModelIndex &index) const;
0064 
0065     // for the word type combo
0066     class WordTypeBasicModel;
0067 };
0068 
0069 class VocabularyDelegate::WordTypeBasicModel : public ReadonlyContainerModel
0070 {
0071 public:
0072     explicit WordTypeBasicModel(QObject *parent = nullptr);
0073 
0074 protected:
0075     KEduVocContainer *rootContainer() const override;
0076 };
0077 
0078 }
0079 
0080 #endif