File indexing completed on 2024-07-21 06:25:11

0001 /***************************************************************************
0002  *   Copyright (C) 2002 by Gunnar Schmi Dt <kmouth@schmi-dt.de             *
0003  *             (C) 2015 by Jeremy Whiting <jpwhiting@kde.org>              *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
0019  ***************************************************************************/
0020 
0021 #ifndef PHRASELIST_H
0022 #define PHRASELIST_H
0023 
0024 // include files for KDE
0025 #include <QUrl>
0026 
0027 // include files for Qt
0028 #include <QWidget>
0029 
0030 class KComboBox;
0031 class KLineEdit;
0032 class QKeyEvent;
0033 class QListView;
0034 class QPrinter;
0035 class QPushButton;
0036 class QStandardItemModel;
0037 class WordCompletion;
0038 
0039 /**
0040  * This class represents a phrase list. It contains methods for manipulating
0041  * the phraselist and also methods for viewing the list.
0042  * The phrase list consists of an edit field for entering phrases and a list
0043  * box for the spoken phrases.
0044  *
0045  * @author Gunnar Schmi Dt
0046  */
0047 
0048 class PhraseList : public QWidget
0049 {
0050     Q_OBJECT
0051 public:
0052     explicit PhraseList(QWidget *parent = nullptr, const QString &name = QString());
0053     ~PhraseList() override;
0054 
0055     /** contains the implementation for printing functionality */
0056     void print(QPrinter *pPrinter);
0057 
0058     QStringList getListSelection();
0059 
0060     bool existListSelection();
0061     bool existEditSelection();
0062 
0063 public Q_SLOTS:
0064     /** Called whenever the user wants the contents of the edit line to be spoken. */
0065     void speak();
0066 
0067     void cut();
0068     void copy();
0069     void paste();
0070 
0071     /** Insert s into the edit field. */
0072     void insert(const QString &s);
0073 
0074     /** Called whenever the user wants the selected list entries to be spoken. */
0075     void speakListSelection();
0076 
0077     void removeListSelection();
0078     void cutListSelection();
0079     void copyListSelection();
0080 
0081     void save();
0082     void open();
0083     void open(const QUrl &url);
0084 
0085     void selectAllEntries();
0086     void deselectAllEntries();
0087 
0088     void configureCompletion();
0089     void saveWordCompletion();
0090     void saveCompletionOptions();
0091     void readCompletionOptions();
0092 
0093 protected Q_SLOTS:
0094     void lineEntered(const QString &phrase);
0095     void contextMenuRequested(const QPoint &pos);
0096     void textChanged(const QString &s);
0097     void selectionChanged();
0098     void keyPressEvent(QKeyEvent *e) override;
0099     void configureCompletionCombo(const QStringList &list);
0100 
0101 private:
0102     QListView *m_listView;
0103     QStandardItemModel *m_model;
0104     KComboBox *dictionaryCombo;
0105     KLineEdit *lineEdit;
0106     QPushButton *speakButton;
0107     QString line;
0108     WordCompletion *completion;
0109 
0110     bool isInSlot;
0111 
0112     void speakPhrase(const QString &phrase);
0113     void setEditLineText(const QString &s);
0114     void insertIntoPhraseList(const QString &phrase, bool clearEditLine);
0115 
0116     void enableMenuEntries();
0117 };
0118 
0119 #endif