2002-06-19 03:38:44 +00:00
|
|
|
/**
|
|
|
|
* \file qscreen.C
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-06-19 03:38:44 +00:00
|
|
|
*
|
2002-10-20 01:48:28 +00:00
|
|
|
* \author John Levon
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-06-19 03:38:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "QWorkArea.h"
|
|
|
|
#include "qscreen.h"
|
2004-05-20 09:36:28 +00:00
|
|
|
|
|
|
|
#include "debug.h"
|
2005-05-19 16:34:02 +00:00
|
|
|
#include "lcolorcache.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
|
2002-07-19 23:04:55 +00:00
|
|
|
#include <qapplication.h>
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/// copy some horizontal regions about inside a pixmap
|
|
|
|
void copyInPixmap(QPixmap * p, int dest_y, int src_y, int src_w, int src_h)
|
|
|
|
{
|
2002-10-20 01:48:28 +00:00
|
|
|
// bitBlt(dest, dest_x, dest_y, source, src_x, src_y, src_w, src_h)
|
|
|
|
bitBlt(p, 0, dest_y, p, 0, src_y, src_w, src_h);
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
} // namespace anon
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
QScreen::QScreen(QWorkArea & o)
|
|
|
|
: LyXScreen(), owner_(o)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QScreen::~QScreen()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-09-05 15:06:13 +00:00
|
|
|
WorkArea & QScreen::workarea() const
|
|
|
|
{
|
|
|
|
return owner_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-12 16:02:28 +00:00
|
|
|
void QScreen::repaint()
|
|
|
|
{
|
2003-08-15 12:09:25 +00:00
|
|
|
QWidget * content = owner_.getContent();
|
2002-09-12 16:02:28 +00:00
|
|
|
content->repaint(0, 0, content->width(), content->height());
|
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-09-11 15:56:07 +00:00
|
|
|
void QScreen::expose(int x, int y, int w, int h)
|
2002-06-19 03:38:44 +00:00
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
lyxerr[Debug::GUI] << "expose " << w << 'x' << h
|
2005-05-19 16:34:02 +00:00
|
|
|
<< '+' << x << '+' << y << std::endl;
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-09-12 16:02:28 +00:00
|
|
|
owner_.getContent()->update(x, y, w, h);
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-03 18:05:53 +00:00
|
|
|
void QScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
|
|
|
|
{
|
2005-05-19 16:34:02 +00:00
|
|
|
if (!qApp->focusWidget())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Cache the dimensions of the cursor.
|
2003-05-03 18:05:53 +00:00
|
|
|
cursor_x_ = x;
|
|
|
|
cursor_y_ = y;
|
|
|
|
cursor_h_ = h;
|
|
|
|
|
|
|
|
switch (shape) {
|
2005-05-19 16:34:02 +00:00
|
|
|
case BAR_SHAPE:
|
|
|
|
cursor_w_ = 1;
|
|
|
|
break;
|
|
|
|
case L_SHAPE:
|
|
|
|
cursor_w_ = cursor_h_ / 3;
|
|
|
|
break;
|
|
|
|
case REVERSED_L_SHAPE:
|
|
|
|
cursor_w_ = cursor_h_ / 3;
|
|
|
|
cursor_x_ = x - cursor_w_ + 1;
|
|
|
|
break;
|
2003-05-03 18:05:53 +00:00
|
|
|
}
|
|
|
|
|
2005-05-19 16:34:02 +00:00
|
|
|
// We cache three pixmaps:
|
|
|
|
// 1 the rectangle of the original screen.
|
|
|
|
// 2 the vertical line of the cursor.
|
|
|
|
// 3 the horizontal line of the L-shaped cursor (if necessary).
|
2003-05-03 18:05:53 +00:00
|
|
|
|
2005-05-19 16:34:02 +00:00
|
|
|
// Initialise storage for these pixmaps as necessary.
|
|
|
|
if (cursor_w_ != nocursor_pixmap_.width() ||
|
|
|
|
cursor_h_ != nocursor_pixmap_.height()) {
|
|
|
|
nocursor_pixmap_.resize(cursor_w_, cursor_h_);
|
|
|
|
}
|
2003-05-03 18:05:53 +00:00
|
|
|
|
2005-05-19 16:34:02 +00:00
|
|
|
QColor const & required_color = lcolorcache.get(LColor::cursor);
|
|
|
|
bool const cursor_color_changed = required_color != cursor_color_;
|
|
|
|
if (cursor_color_changed)
|
|
|
|
cursor_color_ = required_color;
|
2003-06-03 01:34:34 +00:00
|
|
|
|
2005-05-19 16:34:02 +00:00
|
|
|
if (cursor_h_ != vcursor_pixmap_.height() || cursor_color_changed) {
|
|
|
|
if (cursor_h_ != vcursor_pixmap_.height())
|
|
|
|
vcursor_pixmap_.resize(1, cursor_h_);
|
|
|
|
vcursor_pixmap_.fill(cursor_color_);
|
|
|
|
}
|
2003-05-03 18:05:53 +00:00
|
|
|
|
|
|
|
switch (shape) {
|
2005-05-19 16:34:02 +00:00
|
|
|
case BAR_SHAPE:
|
|
|
|
break;
|
|
|
|
case REVERSED_L_SHAPE:
|
|
|
|
case L_SHAPE:
|
|
|
|
if (cursor_w_ != hcursor_pixmap_.width() ||
|
|
|
|
cursor_color_changed) {
|
|
|
|
if (cursor_w_ != hcursor_pixmap_.width())
|
|
|
|
hcursor_pixmap_.resize(cursor_w_, 1);
|
|
|
|
hcursor_pixmap_.fill(cursor_color_);
|
|
|
|
}
|
|
|
|
break;
|
2003-05-03 18:05:53 +00:00
|
|
|
}
|
|
|
|
|
2005-05-19 16:34:02 +00:00
|
|
|
// Save the old area (no cursor).
|
|
|
|
bitBlt(&nocursor_pixmap_, 0, 0, owner_.getPixmap(),
|
|
|
|
cursor_x_, cursor_y_, cursor_w_, cursor_h_);
|
|
|
|
|
|
|
|
// Draw the new (vertical) cursor using the cached store.
|
|
|
|
bitBlt(owner_.getPixmap(), x, y,
|
|
|
|
&vcursor_pixmap_, 0, 0,
|
|
|
|
vcursor_pixmap_.width(), vcursor_pixmap_.height());
|
|
|
|
|
|
|
|
// Draw the new (horizontal) cursor if necessary.
|
|
|
|
switch (shape) {
|
|
|
|
case BAR_SHAPE:
|
|
|
|
break;
|
|
|
|
case REVERSED_L_SHAPE:
|
|
|
|
case L_SHAPE:
|
|
|
|
bitBlt(owner_.getPixmap(), cursor_x_, y + h - 1,
|
|
|
|
&hcursor_pixmap_, 0, 0,
|
|
|
|
hcursor_pixmap_.width(), hcursor_pixmap_.height());
|
|
|
|
break;
|
|
|
|
}
|
2003-05-03 18:05:53 +00:00
|
|
|
|
|
|
|
owner_.getContent()->repaint(
|
|
|
|
cursor_x_, cursor_y_,
|
|
|
|
cursor_w_, cursor_h_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QScreen::removeCursor()
|
|
|
|
{
|
|
|
|
// before first showCursor
|
2005-05-19 16:34:02 +00:00
|
|
|
if (nocursor_pixmap_.isNull())
|
2003-05-03 18:05:53 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
bitBlt(owner_.getPixmap(), cursor_x_, cursor_y_,
|
2005-05-19 16:34:02 +00:00
|
|
|
&nocursor_pixmap_, 0, 0, cursor_w_, cursor_h_);
|
2003-05-03 18:05:53 +00:00
|
|
|
|
2005-05-19 16:34:02 +00:00
|
|
|
owner_.getContent()
|
|
|
|
->repaint(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
|
2003-05-03 18:05:53 +00:00
|
|
|
}
|