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"
24 #include "lcolorcache.h"
26 #include <qapplication.h>
29 #include <qmainwindow.h>
31 #include <qclipboard.h>
45 QWorkArea::QWorkArea(int, int, int, int)
46 : WorkArea(), QWidget(qApp->mainWidget()), painter_(*this)
48 scrollbar_ = new QScrollBar(QScrollBar::Vertical, this);
49 content_ = new QContentPane(this);
51 (static_cast<QMainWindow*>(qApp->mainWidget()))->setCentralWidget(this);
53 setFocusProxy(content_);
57 content_->setBackgroundColor(lcolorcache.get(LColor::background));
59 QHBoxLayout * vl = new QHBoxLayout(this);
60 vl->addWidget(content_, 5);
61 vl->addWidget(scrollbar_, 0);
67 QWorkArea::~QWorkArea()
72 void QWorkArea::setScrollbarParams(int h, int pos, int line_h)
74 // do what cursor movement does (some grey)
77 int max = std::max(0, h - height());
79 scrollbar_->setRange(0, max);
80 scrollbar_->setValue(pos);
81 scrollbar_->setLineStep(line_h);
82 scrollbar_->setPageStep(height());
86 QWorkArea const * wa_ptr = 0;
90 bool lyxX11EventFilter(XEvent * xev)
93 case SelectionRequest:
94 lyxerr[Debug::GUI] << "X requested selection." << endl;
96 wa_ptr->selectionRequested();
99 lyxerr[Debug::GUI] << "Lost selection." << endl;
101 wa_ptr->selectionLost();
108 void QWorkArea::haveSelection(bool own) const
112 #if QT_VERSION >= 300
113 if (!QApplication::clipboard()->supportsSelection())
117 QApplication::clipboard()->setSelectionMode(true);
118 QApplication::clipboard()->setText(QString());
120 // We don't need to do anything if own = false, as this case is
126 string const QWorkArea::getClipboard() const
128 #if QT_VERSION >= 300
129 QApplication::clipboard()->setSelectionMode(true);
131 QString str = QApplication::clipboard()->text();
134 return fromqstr(str);
138 void QWorkArea::putClipboard(string const & str) const
140 #if QT_VERSION >= 300
141 QApplication::clipboard()->setSelectionMode(true);
143 QApplication::clipboard()->setText(toqstr(str));