aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/multieditor/multieditortext.h
blob: 369dadad1f5d179ec7e909cbb38bc3409d05491e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef MULTIEDITORTEXT_H
#define MULTIEDITORTEXT_H

#include "multieditorwidget.h"
#include "multieditorwidgetplugin.h"
#include "common/extactioncontainer.h"
#include "plugins/builtinplugin.h"

class QPlainTextEdit;
class QMenu;

CFG_KEY_LIST(MultiEditorText, QObject::tr("Cell text value editor"),
     CFG_KEY_ENTRY(CUT,     QKeySequence::Cut,      QObject::tr("Cut selected text"))
     CFG_KEY_ENTRY(COPY,    QKeySequence::Copy,     QObject::tr("Copy selected text"))
     CFG_KEY_ENTRY(PASTE,   QKeySequence::Paste,    QObject::tr("Paste from clipboard"))
     CFG_KEY_ENTRY(DELETE,  QKeySequence::Delete,   QObject::tr("Delete selected text"))
     CFG_KEY_ENTRY(UNDO,    QKeySequence::Undo,     QObject::tr("Undo"))
     CFG_KEY_ENTRY(REDO,    QKeySequence::Redo,     QObject::tr("Redo"))
)

class GUI_API_EXPORT MultiEditorText : public MultiEditorWidget, public ExtActionContainer
{
    Q_OBJECT

    public:
        enum Action
        {
            TAB_CHANGES_FOCUS,
            CUT,
            COPY,
            PASTE,
            DELETE,
            UNDO,
            REDO
        };
        Q_ENUM(Action)

        enum ToolBar
        {
        };

        explicit MultiEditorText(QWidget *parent = 0);

        void setValue(const QVariant& value);
        QVariant getValue();
        void setReadOnly(bool value);
        QToolBar* getToolBar(int toolbar) const;
        void focusThisWidget();
        QList<QWidget*> getNoScrollWidgets();

    protected:
        void createActions();
        void setupDefShortcuts();

    private:
        void setupMenu();

        QPlainTextEdit* textEdit = nullptr;
        QMenu* contextMenu = nullptr;

    private slots:
        void modificationChanged(bool changed);
        void deleteSelected();
        void showCustomMenu(const QPoint& point);
        void updateUndoAction(bool enabled);
        void updateRedoAction(bool enabled);
        void updateCopyAction(bool enabled);
        void toggleTabFocus();
};

class GUI_API_EXPORT MultiEditorTextPlugin : public BuiltInPlugin, public MultiEditorWidgetPlugin
{
    Q_OBJECT

    SQLITESTUDIO_PLUGIN_AUTHOR("sqlitestudio.pl")
    SQLITESTUDIO_PLUGIN_DESC("Standard text data editor.")
    SQLITESTUDIO_PLUGIN_TITLE("Text")
    SQLITESTUDIO_PLUGIN_VERSION(10000)

    public:
        MultiEditorWidget* getInstance();
        bool validFor(const DataType& dataType);
        int getPriority(const DataType& dataType);
        QString getTabLabel();
};

#endif // MULTIEDITORTEXT_H