1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the Qt Linguist of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 21 ** included in the packaging of this file. Please review the following 22 ** information to ensure the GNU General Public License requirements will 23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 24 ** 25 ** $QT_END_LICENSE$ 26 ** 27 ****************************************************************************/ 28 29 #ifndef PHRASEVIEW_H 30 #define PHRASEVIEW_H 31 32 #include <QList> 33 #include <QShortcut> 34 #include <QTreeView> 35 #include "phrase.h" 36 37 QT_BEGIN_NAMESPACE 38 39 static const int DefaultMaxCandidates = 5; 40 41 class MultiDataModel; 42 class PhraseModel; 43 44 class GuessShortcut : public QShortcut 45 { 46 Q_OBJECT 47 public: GuessShortcut(int nkey,QWidget * parent,const char * member)48 GuessShortcut(int nkey, QWidget *parent, const char *member) 49 : QShortcut(parent), nrkey(nkey) 50 { 51 const auto key = static_cast<Qt::Key>(int(Qt::Key_1) + nrkey); 52 setKey(Qt::CTRL | key); 53 connect(this, SIGNAL(activated()), this, SLOT(keyActivated())); 54 connect(this, SIGNAL(activated(int)), parent, member); 55 } 56 57 private slots: keyActivated()58 void keyActivated() { emit activated(nrkey); } 59 60 signals: 61 void activated(int nkey); 62 63 private: 64 int nrkey; 65 }; 66 67 class PhraseView : public QTreeView 68 { 69 Q_OBJECT 70 71 public: 72 PhraseView(MultiDataModel *model, QList<QHash<QString, QList<Phrase *> > > *phraseDict, QWidget *parent = 0); 73 ~PhraseView(); 74 void setSourceText(int model, const QString &sourceText); 75 76 public slots: 77 void toggleGuessing(); 78 void update(); getMaxCandidates()79 int getMaxCandidates() const { return m_maxCandidates; } 80 void setMaxCandidates(const int max); getDefaultMaxCandidates()81 static int getDefaultMaxCandidates() { return DefaultMaxCandidates; } 82 83 signals: 84 void phraseSelected(int latestModel, const QString &phrase); 85 void showFewerGuessesAvailable(bool canShow); 86 void setCurrentMessageFromGuess(int modelIndex, const Candidate &cand); 87 88 protected: 89 // QObject 90 virtual void contextMenuEvent(QContextMenuEvent *event); 91 // QAbstractItemView 92 virtual void mouseDoubleClickEvent(QMouseEvent *event); 93 94 private slots: 95 void guessShortcut(int nkey); 96 void selectPhrase(const QModelIndex &index); 97 void selectPhrase(); 98 void editPhrase(); 99 void gotoMessageFromGuess(); 100 void moreGuesses(); 101 void fewerGuesses(); 102 void resetNumGuesses(); 103 104 private: 105 QList<Phrase *> getPhrases(int model, const QString &sourceText); 106 void deleteGuesses(); 107 108 MultiDataModel *m_dataModel; 109 QList<QHash<QString, QList<Phrase *> > > *m_phraseDict; 110 QList<Phrase *> m_guesses; 111 PhraseModel *m_phraseModel; 112 QString m_sourceText; 113 int m_modelIndex; 114 bool m_doGuesses; 115 int m_maxCandidates = DefaultMaxCandidates; 116 }; 117 118 QT_END_NAMESPACE 119 120 #endif // PHRASEVIEW_H 121