3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
16 #include "version.h" // lyx_version
18 #include "support/filetools.h" // LibFileSearch
19 #include "support/lstrings.h"
20 #include "support/LAssert.h"
22 #include "QWorkArea.h"
23 #include "qt_helpers.h"
25 #include <qapplication.h>
28 #include <qmainwindow.h>
30 #include <qclipboard.h>
44 QWorkArea::QWorkArea(int, int, int, int)
45 : WorkArea(), QWidget(qApp->mainWidget()), painter_(*this)
47 scrollbar_ = new QScrollBar(QScrollBar::Vertical, this);
48 content_ = new QContentPane(this);
50 (static_cast<QMainWindow*>(qApp->mainWidget()))->setCentralWidget(this);
52 setFocusProxy(content_);
56 content_->setBackgroundColor(toqstr(lcolor.getX11Name(LColor::background)));
58 QHBoxLayout * vl = new QHBoxLayout(this);
59 vl->addWidget(content_, 5);
60 vl->addWidget(scrollbar_, 0);
66 QWorkArea::~QWorkArea()
71 void QWorkArea::setScrollbarParams(int h, int pos, int line_h)
73 // do what cursor movement does (some grey)
76 int max = std::max(0, h - height());
78 scrollbar_->setRange(0, max);
79 scrollbar_->setValue(pos);
80 scrollbar_->setLineStep(line_h);
81 scrollbar_->setPageStep(height());
85 QWorkArea const * wa_ptr = 0;
89 bool lyxX11EventFilter(XEvent * xev)
92 case SelectionRequest:
93 lyxerr[Debug::GUI] << "X requested selection." << endl;
95 wa_ptr->selectionRequested();
98 lyxerr[Debug::GUI] << "Lost selection." << endl;
100 wa_ptr->selectionLost();
107 void QWorkArea::haveSelection(bool own) const
111 #if QT_VERSION >= 300
112 if (!QApplication::clipboard()->supportsSelection())
116 QApplication::clipboard()->setSelectionMode(true);
117 QApplication::clipboard()->setText(QString());
119 // We don't need to do anything if own = false, as this case is
125 string const QWorkArea::getClipboard() const
127 #if QT_VERSION >= 300
128 QApplication::clipboard()->setSelectionMode(true);
130 QString str = QApplication::clipboard()->text();
133 return fromqstr(str);
137 void QWorkArea::putClipboard(string const & str) const
139 #if QT_VERSION >= 300
140 QApplication::clipboard()->setSelectionMode(true);
142 QApplication::clipboard()->setText(toqstr(str));