2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file qscreen.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2006-03-20 10:43:21 +00:00
|
|
|
#include <config.h>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-20 10:43:21 +00:00
|
|
|
#include "QWorkArea.h"
|
|
|
|
#include "qscreen.h"
|
|
|
|
|
|
|
|
#include <QColor>
|
|
|
|
#include <QPainter>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QApplication>
|
|
|
|
|
2006-03-20 10:43:21 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "lcolorcache.h"
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
QScreen::QScreen(QWorkArea & o)
|
2006-03-20 10:43:21 +00:00
|
|
|
: LyXScreen(), owner_(o), nocursor_(0,0)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QScreen::~QScreen()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WorkArea & QScreen::workarea() const
|
|
|
|
{
|
|
|
|
return owner_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QScreen::expose(int x, int y, int w, int h)
|
|
|
|
{
|
2006-03-20 10:43:21 +00:00
|
|
|
lyxerr[Debug::GUI] << "expose " << w << 'x' << h
|
|
|
|
<< '+' << x << '+' << y << std::endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-20 10:43:21 +00:00
|
|
|
owner_.update(x, y, w, h);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
|
|
|
|
{
|
|
|
|
if (!qApp->focusWidget())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (x==cursor_x_ && y==cursor_y_ && h==cursor_h_) {
|
|
|
|
// Draw the new (vertical) cursor using the cached store.
|
2006-03-20 10:43:21 +00:00
|
|
|
owner_.drawScreen(cursor_x_, cursor_y_, vcursor_);
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache the dimensions of the cursor.
|
|
|
|
cursor_x_ = x;
|
|
|
|
cursor_y_ = y;
|
|
|
|
cursor_h_ = h;
|
|
|
|
|
|
|
|
switch (shape) {
|
|
|
|
case BAR_SHAPE:
|
|
|
|
cursor_w_ = 2;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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).
|
2006-03-20 10:43:21 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
QColor const & required_color = lcolorcache.get(LColor::cursor);
|
|
|
|
bool const cursor_color_changed = required_color != cursor_color_;
|
|
|
|
if (cursor_color_changed)
|
2006-03-20 10:43:21 +00:00
|
|
|
cursor_color_ = required_color;
|
|
|
|
|
|
|
|
vcursor_ = QPixmap(cursor_w_, cursor_h_);
|
|
|
|
vcursor_ .fill(cursor_color_);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
switch (shape) {
|
|
|
|
case BAR_SHAPE:
|
|
|
|
break;
|
|
|
|
case REVERSED_L_SHAPE:
|
|
|
|
case L_SHAPE:
|
2006-03-20 10:43:21 +00:00
|
|
|
if (cursor_w_ != hcursor_.width() ||
|
2006-03-05 17:24:44 +00:00
|
|
|
cursor_color_changed) {
|
2006-03-20 10:43:21 +00:00
|
|
|
if (cursor_w_ != hcursor_.width())
|
|
|
|
hcursor_ = QPixmap(cursor_w_, 1);
|
|
|
|
hcursor_.fill(cursor_color_);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-03-20 10:43:21 +00:00
|
|
|
// Save the old area (no cursor).
|
|
|
|
nocursor_ = owner_.copyScreen(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// Draw the new (vertical) cursor using the cached store.
|
2006-03-20 10:43:21 +00:00
|
|
|
owner_.drawScreen(cursor_x_, cursor_y_, vcursor_);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// Draw the new (horizontal) cursor if necessary.
|
|
|
|
switch (shape) {
|
|
|
|
case BAR_SHAPE:
|
|
|
|
break;
|
|
|
|
case REVERSED_L_SHAPE:
|
|
|
|
case L_SHAPE:
|
2006-03-20 10:43:21 +00:00
|
|
|
owner_.drawScreen(cursor_x_, y + h - 1, hcursor_);
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QScreen::removeCursor()
|
|
|
|
{
|
|
|
|
// before first showCursor
|
2006-03-20 10:43:21 +00:00
|
|
|
if (nocursor_.isNull())
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
|
2006-03-20 10:43:21 +00:00
|
|
|
owner_.drawScreen(cursor_x_, cursor_y_, nocursor_);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|