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