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.
14 #include "QWorkArea.h"
16 #include "qt_helpers.h"
17 #include "lcolorcache.h"
18 #include "funcrequest.h"
20 #include <qapplication.h>
21 #include <qdragobject.h>
23 #include <qmainwindow.h>
25 #include <qclipboard.h>
34 QWorkArea::QWorkArea(int, int, int, int)
35 : WorkArea(), QWidget(qApp->mainWidget()), painter_(*this)
37 scrollbar_ = new QScrollBar(QScrollBar::Vertical, this);
38 content_ = new QContentPane(this);
40 (static_cast<QMainWindow*>(qApp->mainWidget()))->setCentralWidget(this);
42 setFocusProxy(content_);
47 content_->setBackgroundColor(lcolorcache.get(LColor::background));
49 QHBoxLayout * vl = new QHBoxLayout(this);
50 vl->addWidget(content_, 5);
51 vl->addWidget(scrollbar_, 0);
57 QWorkArea::~QWorkArea()
62 void QWorkArea::setScrollbarParams(int h, int pos, int line_h)
64 // do what cursor movement does (some grey)
67 int max = std::max(0, h - height());
69 scrollbar_->setRange(0, max);
70 scrollbar_->setValue(pos);
71 scrollbar_->setLineStep(line_h);
72 scrollbar_->setPageStep(height());
76 QWorkArea const * wa_ptr = 0;
80 bool lyxX11EventFilter(XEvent * xev)
83 case SelectionRequest:
84 lyxerr[Debug::GUI] << "X requested selection." << endl;
86 wa_ptr->selectionRequested();
89 lyxerr[Debug::GUI] << "Lost selection." << endl;
91 wa_ptr->selectionLost();
98 void QWorkArea::haveSelection(bool own) const
102 #if QT_VERSION >= 300
103 if (!QApplication::clipboard()->supportsSelection())
107 QApplication::clipboard()->setSelectionMode(true);
108 QApplication::clipboard()->setText(QString());
110 // We don't need to do anything if own = false, as this case is
116 string const QWorkArea::getClipboard() const
118 #if QT_VERSION >= 300
119 QApplication::clipboard()->setSelectionMode(true);
121 QString str = QApplication::clipboard()->text();
124 return fromqstr(str);
128 void QWorkArea::putClipboard(string const & str) const
130 #if QT_VERSION >= 300
131 QApplication::clipboard()->setSelectionMode(true);
133 QApplication::clipboard()->setText(toqstr(str));
137 void QWorkArea::dragEnterEvent(QDragEnterEvent * event)
139 event->accept(QUriDrag::canDecode(event));
143 void QWorkArea::dropEvent(QDropEvent* event)
147 if (QUriDrag::decodeLocalFiles(event, files)) {
148 lyxerr[Debug::GUI] << "QWorkArea::dropEvent: got URIs!"
150 for (QStringList::Iterator i = files.begin();
152 dispatch(FuncRequest(LFUN_FILE_OPEN, fromqstr(*i)));