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
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2002-06-19 03:38:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
2002-10-20 01:48:28 +00:00
|
|
|
#include <iostream>
|
2002-06-19 03:38:44 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
#include "LColor.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "QWorkArea.h"
|
|
|
|
#include "qscreen.h"
|
|
|
|
#include "lyxtext.h"
|
|
|
|
#include "Painter.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "insets/insettext.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
2002-07-19 23:04:55 +00:00
|
|
|
#include <qapplication.h>
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-21 16:40:54 +00:00
|
|
|
using std::endl;
|
2002-06-19 03:38:44 +00:00
|
|
|
using std::max;
|
|
|
|
using std::min;
|
|
|
|
|
|
|
|
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
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
void QScreen::showManualCursor(LyXText const * text, int x, int y,
|
|
|
|
int asc, int desc, Cursor_Shape shape)
|
|
|
|
{
|
2002-07-19 23:04:55 +00:00
|
|
|
if (!qApp->focusWidget())
|
|
|
|
return;
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-03-06 20:21:21 +00:00
|
|
|
int const y1 = max(y - text->top_y() - asc, 0);
|
|
|
|
int const y_tmp = min(y - text->top_y() + desc, owner_.height());
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
// secure against very strange situations
|
2002-10-20 01:48:28 +00:00
|
|
|
// which would be when .... ?
|
2002-06-19 03:38:44 +00:00
|
|
|
int const y2 = max(y_tmp, y1);
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
if (y2 > 0 && y1 < owner_.height()) {
|
|
|
|
cursor_h_ = y2 - y1 + 1;
|
|
|
|
cursor_y_ = y1;
|
|
|
|
|
|
|
|
switch (shape) {
|
|
|
|
case BAR_SHAPE:
|
|
|
|
cursor_w_ = 1;
|
|
|
|
cursor_x_ = x;
|
|
|
|
break;
|
|
|
|
case L_SHAPE:
|
|
|
|
cursor_w_ = cursor_h_ / 3;
|
|
|
|
cursor_x_ = x;
|
|
|
|
break;
|
|
|
|
case REVERSED_L_SHAPE:
|
|
|
|
cursor_w_ = cursor_h_ / 3;
|
|
|
|
cursor_x_ = x - cursor_w_ + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
if (!nocursor_pixmap_.get()
|
2002-06-19 03:38:44 +00:00
|
|
|
|| cursor_w_ != nocursor_pixmap_->width()
|
|
|
|
|| cursor_h_ != nocursor_pixmap_->height()) {
|
|
|
|
nocursor_pixmap_.reset(new QPixmap(cursor_w_, cursor_h_));
|
|
|
|
}
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
owner_.getPainter().start();
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
// save old area
|
2002-06-19 03:38:44 +00:00
|
|
|
bitBlt(nocursor_pixmap_.get(), 0, 0, owner_.getPixmap(),
|
|
|
|
cursor_x_, cursor_y_, cursor_w_, cursor_h_);
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-11-25 03:18:27 +00:00
|
|
|
owner_.getPainter().line(x, y1, x, y2, LColor::cursor);
|
2002-06-19 03:38:44 +00:00
|
|
|
switch (shape) {
|
|
|
|
case BAR_SHAPE:
|
|
|
|
break;
|
|
|
|
case L_SHAPE:
|
|
|
|
case REVERSED_L_SHAPE:
|
|
|
|
int const rectangle_h = (cursor_h_ + 10) / 20;
|
|
|
|
owner_.getPainter().fillRectangle(
|
|
|
|
cursor_x_, y2 - rectangle_h + 1,
|
|
|
|
cursor_w_ - 1, rectangle_h, LColor::cursor);
|
|
|
|
break;
|
|
|
|
}
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
owner_.getPainter().end();
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
owner_.getContent()->repaint(
|
|
|
|
cursor_x_, cursor_y_,
|
2002-10-20 01:48:28 +00:00
|
|
|
cursor_w_, cursor_h_);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
cursor_visible_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QScreen::hideCursor()
|
|
|
|
{
|
2002-10-20 01:48:28 +00:00
|
|
|
if (!cursor_visible_)
|
2002-06-19 03:38:44 +00:00
|
|
|
return;
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
bitBlt(owner_.getPixmap(), cursor_x_, cursor_y_,
|
2002-06-19 03:38:44 +00:00
|
|
|
nocursor_pixmap_.get(), 0, 0, cursor_w_, cursor_h_);
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
owner_.getContent()->repaint(
|
|
|
|
cursor_x_, cursor_y_,
|
2002-10-20 01:48:28 +00:00
|
|
|
cursor_w_, cursor_h_);
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
cursor_visible_ = false;
|
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-09-12 16:02:28 +00:00
|
|
|
void QScreen::repaint()
|
|
|
|
{
|
|
|
|
QWidget * content(owner_.getContent());
|
|
|
|
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
|
|
|
|
<< '+' << x << '+' << y << 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
|
|
|
|
{
|
|
|
|
QPixmap * p(owner_.getPixmap());
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
owner_.getPainter().start();
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
if (cursor_visible_) hideCursor();
|
|
|
|
|
2003-03-06 20:21:21 +00:00
|
|
|
int const old_first = text->top_y();
|
|
|
|
text->top_y(y);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
2002-09-12 16:02:28 +00:00
|
|
|
// If you want to fix the warning below, fix it so it
|
|
|
|
// actually scrolls properly. Hint: a cast won't do.
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
// is any optimization possible?
|
2002-09-12 16:02:28 +00:00
|
|
|
if (y - old_first < owner_.workHeight()
|
|
|
|
&& old_first - y < owner_.workHeight()) {
|
2003-03-06 20:21:21 +00:00
|
|
|
if (text->top_y() < old_first) {
|
|
|
|
int const dest_y = old_first - text->top_y();
|
2003-03-22 17:26:03 +00:00
|
|
|
drawFromTo(text, bv, 0, dest_y, 0, 0);
|
2002-06-19 03:38:44 +00:00
|
|
|
copyInPixmap(p, dest_y, 0, owner_.workWidth(), owner_.height() - dest_y);
|
|
|
|
expose(0, 0, owner_.workWidth(), dest_y);
|
|
|
|
} else {
|
2003-03-06 20:21:21 +00:00
|
|
|
int const src_y = text->top_y() - old_first;
|
2003-03-22 17:26:03 +00:00
|
|
|
drawFromTo(text, bv, owner_.height() - src_y, owner_.height(), 0, 0);
|
2002-06-19 03:38:44 +00:00
|
|
|
copyInPixmap(p, 0, 0, owner_.workWidth(), owner_.height() - src_y);
|
|
|
|
expose(0, owner_.height() - src_y, owner_.workWidth(), src_y);
|
|
|
|
}
|
|
|
|
} else {
|
2002-10-20 01:48:28 +00:00
|
|
|
lyxerr[Debug::GUI] << "dumb full redraw" << endl;
|
2003-03-22 17:26:03 +00:00
|
|
|
drawFromTo(text, bv, 0, owner_.height(), 0, 0);
|
2002-09-12 16:02:28 +00:00
|
|
|
repaint();
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
owner_.getPainter().end();
|
|
|
|
}
|