]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QWorkArea.C
the qtclean-2 patch with some very small changes
[lyx.git] / src / frontends / qt2 / QWorkArea.C
1 /**
2  * \file QWorkArea.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "debug.h"
18 #include "LyXView.h"
19 #include "version.h" // lyx_version
20
21 #include "support/filetools.h" // LibFileSearch
22 #include "support/lstrings.h"
23 #include "support/LAssert.h"
24
25 #include "QWorkArea.h"
26
27 #include <qapplication.h>
28 #include <qevent.h>
29 #include <qpainter.h>
30 #include <qmainwindow.h>
31 #include <qlayout.h>
32 #include <qclipboard.h>
33
34 #include <cmath>
35 #include <cctype>
36
37 using std::endl;
38 using std::abs;
39 using std::hex;
40
41
42 QWorkArea::QWorkArea(int, int, int, int)
43         : WorkArea(), QWidget(qApp->mainWidget()), painter_(*this)
44 {
45         scrollbar_ = new QScrollBar(QScrollBar::Vertical, this);
46         content_ = new QContentPane(this);
47
48         (static_cast<QMainWindow*>(qApp->mainWidget()))->setCentralWidget(this);
49
50         setFocusProxy(content_);
51
52         content_->show();
53
54         content_->setBackgroundColor(lcolor.getX11Name(LColor::background).c_str());
55
56         QHBoxLayout * vl = new QHBoxLayout(this);
57         vl->addWidget(content_, 5);
58         vl->addWidget(scrollbar_, 0);
59
60         show();
61 }
62
63
64 QWorkArea::~QWorkArea()
65 {
66 }
67
68
69 void QWorkArea::setScrollbarParams(int h, int pos, int line_h)
70 {
71         // do what cursor movement does (some grey)
72         h += height() / 4;
73
74         int max = std::max(0, h - height());
75
76         scrollbar_->setRange(0, max);
77         scrollbar_->setValue(pos);
78         scrollbar_->setLineStep(line_h);
79         scrollbar_->setPageStep(height());
80 }
81
82
83 void QWorkArea::haveSelection(bool) const
84 {
85         // not possible in Qt !
86 }
87
88
89 string const QWorkArea::getClipboard() const
90 {
91         QString str = QApplication::clipboard()->text();
92         if (str.isNull())
93                 return string();
94         return str.latin1();
95 }
96
97
98 void QWorkArea::putClipboard(string const & str) const
99 {
100         QApplication::clipboard()->setText(str.c_str());
101 }