"Fossies" - the Fresh Open Source Software Archive 
Member "cb2bib-2.0.1/src/c2bClipboard.cpp" (12 Feb 2021, 2963 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "c2bClipboard.cpp" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
2.0.0_vs_2.0.1.
1 /***************************************************************************
2 * Copyright (C) 2004-2021 by Pere Constans
3 * constans@molspaces.com
4 * cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
5 * See the LICENSE file that comes with this distribution.
6 ***************************************************************************/
7 #include "c2bClipboard.h"
8 #ifdef C2B_USE_CBPOLL
9 #include "clipboardPoll.h"
10 #endif
11
12 #include <QApplication>
13
14
15 c2bClipboard::c2bClipboard(QObject* parento) : QObject(parento)
16 {
17 // Connecting clipboard
18 _cb = QApplication::clipboard();
19 _supports_selection = _cb->supportsSelection();
20 _is_connected = false;
21 _cb_text = _cb->text(QClipboard::Clipboard);
22 if (_supports_selection)
23 _cbs_text = _cb->text(QClipboard::Selection);
24
25 // Set polling
26 _interval = 1000;
27 #ifdef C2B_USE_CBPOLL
28 _poll = new clipboardPoll();
29 connect(_poll, SIGNAL(clipboardChanged(bool)), this, SLOT(newClipboardData(bool)));
30 #else
31 _timer = new QTimer(this);
32 connect(_timer, SIGNAL(timeout()), this, SLOT(checkData()));
33 #endif
34 }
35
36 c2bClipboard::~c2bClipboard()
37 {
38 #ifdef C2B_USE_CBPOLL
39 delete _poll;
40 #endif
41 }
42
43
44 void c2bClipboard::checkData()
45 {
46 if (_cb_text != _cb->text(QClipboard::Clipboard))
47 {
48 _cb_text = _cb->text(QClipboard::Clipboard);
49 emit cbDataChanged(_cb_text);
50 }
51 if (_supports_selection && _cbs_text != _cb->text(QClipboard::Selection))
52 {
53 _cbs_text = _cb->text(QClipboard::Selection);
54 emit cbDataChanged(_cbs_text);
55 }
56 }
57
58 void c2bClipboard::dataChanged()
59 {
60 if (_cb_text != _cb->text(QClipboard::Clipboard))
61 {
62 _cb_text = _cb->text(QClipboard::Clipboard);
63 emit cbDataChanged(_cb_text);
64 }
65 }
66
67 void c2bClipboard::selectionChanged()
68 {
69 if (_supports_selection && _cbs_text != _cb->text(QClipboard::Selection))
70 {
71 _cbs_text = _cb->text(QClipboard::Selection);
72 emit cbDataChanged(_cbs_text);
73 }
74 }
75
76 void c2bClipboard::setConnected(bool zconn)
77 {
78 _is_connected = zconn;
79 if (_is_connected)
80 {
81 _cb_text = _cb->text(QClipboard::Clipboard);
82 connect(_cb, SIGNAL(dataChanged()), this, SLOT(dataChanged()));
83 if (_supports_selection)
84 {
85 _cbs_text = _cb->text(QClipboard::Selection);
86 connect(_cb, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
87 }
88 #ifdef C2B_USE_CBPOLL
89 _poll->startT(_interval);
90 #else
91 _timer->start(_interval);
92 #endif
93 }
94 else
95 {
96 #ifdef C2B_USE_CBPOLL
97 _poll->stopT();
98 #else
99 _timer->stop();
100 #endif
101 disconnect(_cb, SIGNAL(dataChanged()), this, SLOT(dataChanged()));
102 if (_supports_selection)
103 disconnect(_cb, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
104 }
105 }
106
107 void c2bClipboard::newClipboardData(bool selectionMode)
108 {
109 if (selectionMode)
110 selectionChanged();
111 else
112 dataChanged();
113 }