]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiClipboard.h
Amend 4cd568d31266
[lyx.git] / src / frontends / qt / GuiClipboard.h
1 // -*- C++ -*-
2 /**
3  * \file GuiClipboard.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author unknown
8  * \author John Levon
9  * \author Abdelrazak Younes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef GUICLIPBOARD_H
15 #define GUICLIPBOARD_H
16
17 #include "frontends/Clipboard.h"
18
19 #include <QMimeData>
20 #include <QObject>
21 #include <QStringList>
22
23 #include <cstdint>
24
25 namespace lyx {
26 namespace frontend {
27
28 class QMacPasteboardMimeGraphics;
29
30 /**
31  *  \class CacheMimeData
32  *
33  *  This class is used in order to query the clipboard only once on
34  *  startup and once each time the contents of the clipboard changes.
35  */
36 class CacheMimeData : public QMimeData
37 {
38         Q_OBJECT
39 public:
40         // LyX calls "on_dataChanged" on startup, so it is not necessary to
41         // query the clipboard here.
42         CacheMimeData()
43         {}
44
45         /// reads the clipboard and updates the cached_formats_
46         void update();
47         /// returns the cached list of formats supported by the object
48         QStringList formats() const override { return cached_formats_; }
49         /// reads the clipboard and returns the data
50         QByteArray data(QString const & mimeType) const;
51
52 private:
53         /// the cached list of formats supported by the object
54         QStringList cached_formats_;
55 };
56
57
58 /**
59  * The Qt version of the Clipboard.
60  */
61 class GuiClipboard: public QObject, public Clipboard
62 {
63         Q_OBJECT
64 public:
65         GuiClipboard();
66
67         /** Clipboard overloaded methods
68          */
69         //@{
70         std::string const getAsLyX() const override;
71         support::FileName getAsGraphics(Cursor const & cur, GraphicsType type) const override;
72         docstring const getAsText(TextType type) const override;
73         void put(std::string const & text) const override;
74         void put(std::string const & lyx, docstring const & html, docstring const & text) override;
75         bool hasGraphicsContents(GraphicsType type = AnyGraphicsType) const override;
76         bool hasTextContents(TextType type = AnyTextType) const override;
77         bool isInternal() const override;
78         bool hasInternal() const override;
79         bool empty() const override;
80         //@}
81
82         support::FileName getPastedGraphicsFileName(Cursor const & cur,
83                 Clipboard::GraphicsType & type) const;
84
85         void setFindBuffer(docstring const & text) override;
86
87 private Q_SLOTS:
88         void on_dataChanged();
89         void on_findChanged();
90         void update();
91
92 private:
93         bool plaintext_clipboard_empty_;
94         bool has_text_contents_;
95         bool has_graphics_contents_;
96         /// the cached mime data used to describe the information
97         /// that can be stored in the clipboard
98         CacheMimeData cache_;
99         /// checksum for internal clipboard data (used on Mac)
100         std::uint32_t checksum;
101 };
102
103 QString const lyxMimeType();
104 QString const pdfMimeType();
105 QString const emfMimeType();
106 QString const wmfMimeType();
107
108 } // namespace frontend
109 } // namespace lyx
110
111 #endif // GUICLIPBOARD_H