1 /**************************************************************************
2 * Otter Browser: Web browser controlled by the user, not vice-versa.
3 * Copyright (C) 2017 - 2018 Michal Dutkiewicz aka Emdek <michal@emdek.pl>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 **************************************************************************/
19 
20 #ifndef OTTER_TEXTEDITWIDGET_H
21 #define OTTER_TEXTEDITWIDGET_H
22 
23 #include "../core/ActionExecutor.h"
24 
25 #include <QtWidgets/QPlainTextEdit>
26 
27 namespace Sonnet
28 {
29 	class Highlighter;
30 }
31 
32 namespace Otter
33 {
34 
35 class TextEditWidget final : public QPlainTextEdit, public ActionExecutor
36 {
37 	Q_OBJECT
38 
39 public:
40 	explicit TextEditWidget(const QString &text, QWidget *parent = nullptr);
41 	explicit TextEditWidget(QWidget *parent = nullptr);
42 
43 	ActionsManager::ActionDefinition::State getActionState(int identifier, const QVariantMap &parameters) const override;
44 	bool hasSelection() const;
45 
46 public slots:
47 	void triggerAction(int identifier, const QVariantMap &parameters, ActionsManager::TriggerType trigger = ActionsManager::UnknownTrigger) override;
48 
49 protected:
50 	void focusInEvent(QFocusEvent *event) override;
51 	void contextMenuEvent(QContextMenuEvent *event) override;
52 	void initialize();
53 
54 protected slots:
55 	void handleSelectionChanged();
56 	void handleTextChanged();
57 	void notifyPasteActionStateChanged();
58 
59 private:
60 	Sonnet::Highlighter *m_highlighter;
61 	bool m_hadSelection;
62 	bool m_wasEmpty;
63 
64 signals:
65 	void arbitraryActionsStateChanged(const QVector<int> &identifiers);
66 };
67 
68 }
69 
70 #endif
71