mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
do not draw to intermediate pixmap
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15501 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
55c10ff2b5
commit
1852693005
@ -116,9 +116,10 @@ int GuiFontMetrics::smallcapsWidth(QString const & s) const
|
||||
int GuiFontMetrics::width(char_type const * s, size_t ls) const
|
||||
{
|
||||
if (ls == 1 && !smallcaps_shape_) {
|
||||
QChar c = ucs4_to_qchar(s[0]);
|
||||
QChar const c = ucs4_to_qchar(s[0]);
|
||||
return width(c.unicode());
|
||||
}
|
||||
|
||||
QString ucs2;
|
||||
ucs4_to_qstring(s, ls, ucs2);
|
||||
|
||||
|
@ -21,12 +21,19 @@
|
||||
#include "LyXView.h"
|
||||
|
||||
#include "BufferView.h"
|
||||
#include "rowpainter.h"
|
||||
#include "debug.h"
|
||||
#include "funcrequest.h"
|
||||
#include "LColor.h"
|
||||
#include "version.h"
|
||||
#include "lyxrc.h"
|
||||
|
||||
#include "support/filetools.h" // LibFileSearch
|
||||
#include "support/os.h"
|
||||
|
||||
#include "graphics/GraphicsImage.h"
|
||||
#include "graphics/GraphicsLoader.h"
|
||||
|
||||
#include <QLayout>
|
||||
#include <QMainWindow>
|
||||
#include <QMimeData>
|
||||
@ -53,6 +60,15 @@ using std::string;
|
||||
|
||||
namespace os = lyx::support::os;
|
||||
|
||||
|
||||
volatile int NN;
|
||||
|
||||
void recCalled()
|
||||
{
|
||||
++NN;
|
||||
}
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
/// return the LyX key state from Qt's
|
||||
@ -115,17 +131,15 @@ SyntheticMouseEvent::SyntheticMouseEvent()
|
||||
|
||||
|
||||
GuiWorkArea::GuiWorkArea(int w, int h, LyXView & lyx_view)
|
||||
: WorkArea(lyx_view), painter_(this)
|
||||
: WorkArea(lyx_view)
|
||||
{
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
setAcceptDrops(true);
|
||||
|
||||
setMinimumSize(100, 70);
|
||||
|
||||
viewport()->setAutoFillBackground(false);
|
||||
viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
//viewport()->setAutoFillBackground(false);
|
||||
//viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
setFocusPolicy(Qt::WheelFocus);
|
||||
|
||||
viewport()->setCursor(Qt::IBeamCursor);
|
||||
@ -410,10 +424,11 @@ void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * e)
|
||||
}
|
||||
|
||||
|
||||
void GuiWorkArea::resizeEvent(QResizeEvent *)
|
||||
void GuiWorkArea::resizeEvent(QResizeEvent * ev)
|
||||
{
|
||||
verticalScrollBar()->setPageStep(viewport()->height());
|
||||
paint_device_ = QPixmap(viewport()->width(), viewport()->height());
|
||||
//paint_device_ = QPixmap(viewport()->width(), viewport()->height());
|
||||
QAbstractScrollArea::resizeEvent(ev);
|
||||
resizeBufferView();
|
||||
}
|
||||
|
||||
@ -424,12 +439,93 @@ void GuiWorkArea::update(int x, int y, int w, int h)
|
||||
}
|
||||
|
||||
|
||||
void GuiWorkArea::paintEvent(QPaintEvent * e)
|
||||
void GuiWorkArea::doGreyOut(QLPainter & pain)
|
||||
{
|
||||
lyxerr << "paintEvent begin: x: " << e->rect().x()
|
||||
<< " y: " << e->rect().y()
|
||||
<< " w: " << e->rect().width()
|
||||
<< " h: " << e->rect().height() << endl;
|
||||
greyed_out_ = true;
|
||||
pain.fillRectangle(0, 0, width(), height(),
|
||||
LColor::bottomarea);
|
||||
|
||||
//if (!lyxrc.show_banner)
|
||||
// return;
|
||||
lyxerr << "show banner: " << lyxrc.show_banner << endl;
|
||||
/// The text to be written on top of the pixmap
|
||||
string const text = lyx_version ? lyx_version : "unknown";
|
||||
string const file = support::libFileSearch("images", "banner", "ppm");
|
||||
if (file.empty())
|
||||
return;
|
||||
|
||||
QPixmap pm(toqstr(file));
|
||||
if (!pm) {
|
||||
lyxerr << "could not load splash screen: '" << file << "'" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
QFont font;
|
||||
// The font used to display the version info
|
||||
font.setStyleHint(QFont::SansSerif);
|
||||
font.setWeight(QFont::Bold);
|
||||
font.setPointSize(LyXFont::SIZE_NORMAL);
|
||||
|
||||
int const w = pm.width();
|
||||
int const h = pm.height();
|
||||
|
||||
int x = (width() - w) / 2;
|
||||
int y = (height() - h) / 2;
|
||||
|
||||
pain.drawPixmap(x, y, pm);
|
||||
|
||||
x += 260;
|
||||
y += 265;
|
||||
|
||||
pain.setPen(QColor(255, 255, 0));
|
||||
pain.setFont(font);
|
||||
pain.drawText(x, y, toqstr(text));
|
||||
}
|
||||
|
||||
|
||||
void GuiWorkArea::paintEvent(QPaintEvent * ev)
|
||||
{
|
||||
//setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
|
||||
QRect const rc = ev->rect();
|
||||
lyxerr << "paintEvent begin: x: " << rc.x()
|
||||
<< " y: " << rc.y()
|
||||
<< " w: " << rc.width()
|
||||
<< " h: " << rc.height() << endl;
|
||||
|
||||
if (!buffer_view_) {
|
||||
lyxerr << "no bufferview" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
QLPainter pain(viewport());
|
||||
|
||||
if (rc.width() == 3) { // FIXME HACK
|
||||
// Assume splash screen drawing is requested when
|
||||
// widht == 3
|
||||
doGreyOut(pain);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!buffer_view_->buffer()) {
|
||||
lyxerr << "no buffer: " << endl;
|
||||
doGreyOut(pain);
|
||||
updateScrollbar();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (rc.width() != 2) { // FIXME HACK
|
||||
// Assumes cursor drawing is requested when the
|
||||
// width is 2
|
||||
lyxerr << "Real drawing requested" << endl;
|
||||
ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo();
|
||||
paintText(*buffer_view_, vi, pain);
|
||||
}
|
||||
else {
|
||||
//
|
||||
lyxerr << "only cursor drawing requested" << endl;
|
||||
}
|
||||
|
||||
/*
|
||||
lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
|
||||
<< "\n QWidget width\t" << this->width()
|
||||
@ -445,15 +541,13 @@ void GuiWorkArea::paintEvent(QPaintEvent * e)
|
||||
<< endl;
|
||||
*/
|
||||
|
||||
QPainter q(viewport());
|
||||
q.drawPixmap(e->rect(), paint_device_, e->rect());
|
||||
//pain.drawPixmap(e->rect(), paint_device_, e->rect());
|
||||
|
||||
if (show_vcursor_)
|
||||
q.drawPixmap(cursor_x_, cursor_y_, vcursor_);
|
||||
pain.drawPixmap(cursor_x_, cursor_y_, vcursor_);
|
||||
|
||||
if (show_hcursor_)
|
||||
q.drawPixmap(cursor_x_, cursor_y_ + cursor_h_ - 1, hcursor_);
|
||||
|
||||
pain.drawPixmap(cursor_x_, cursor_y_ + cursor_h_ - 1, hcursor_);
|
||||
lyxerr << "paintEvent end" << endl;
|
||||
}
|
||||
|
||||
@ -550,8 +644,7 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
|
||||
key = Qt::Key_AsciiCircum;
|
||||
// FIXME: Needs for investigation, this key is not really used,
|
||||
// the ctor below just check if key is different from 0.
|
||||
QKeyEvent ev(QEvent::KeyPress, key,
|
||||
Qt::NoModifier, text);
|
||||
QKeyEvent ev(QEvent::KeyPress, key, Qt::NoModifier, text);
|
||||
keyPressEvent(&ev);
|
||||
}
|
||||
e->accept();
|
||||
|
@ -15,8 +15,6 @@
|
||||
|
||||
#include "frontends/WorkArea.h"
|
||||
|
||||
#include "QLPainter.h"
|
||||
|
||||
#include "funcrequest.h"
|
||||
#include "frontends/Timeout.h"
|
||||
|
||||
@ -36,12 +34,10 @@ class QWheelEvent;
|
||||
class QPaintEvent;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
class Painter;
|
||||
|
||||
namespace frontend {
|
||||
|
||||
class GuiView;
|
||||
class QLPainter;
|
||||
|
||||
/// for emulating triple click
|
||||
class double_click {
|
||||
@ -89,7 +85,7 @@ public:
|
||||
* Qt-specific implementation of the work area
|
||||
* (buffer view GUI)
|
||||
*/
|
||||
class GuiWorkArea: public QAbstractScrollArea, public WorkArea
|
||||
class GuiWorkArea : public QAbstractScrollArea, public WorkArea
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -104,18 +100,6 @@ public:
|
||||
///
|
||||
virtual void setScrollbarParams(int height, int pos, int line_height);
|
||||
|
||||
///
|
||||
virtual void dragEnterEvent(QDragEnterEvent * event);
|
||||
|
||||
///
|
||||
virtual void dropEvent(QDropEvent* event);
|
||||
|
||||
/// return the widget's painter
|
||||
virtual Painter & getPainter() { return (Painter &) painter_; }
|
||||
|
||||
/// return the backing pixmap
|
||||
QPaintDevice * paintDevice() { return &paint_device_; }
|
||||
|
||||
/// update the passed area.
|
||||
void update(int x, int y, int w, int h);
|
||||
|
||||
@ -128,8 +112,12 @@ public:
|
||||
/// hide the cursor
|
||||
virtual void removeCursor();
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
void doGreyOut(QLPainter & pain);
|
||||
///
|
||||
void dragEnterEvent(QDragEnterEvent * event);
|
||||
///
|
||||
void dropEvent(QDropEvent* event);
|
||||
/// repaint part of the widget
|
||||
void paintEvent(QPaintEvent * e);
|
||||
/// widget has been resized
|
||||
@ -164,10 +152,6 @@ public Q_SLOTS:
|
||||
void adjustViewWithScrollBar(int action = 0);
|
||||
|
||||
private:
|
||||
|
||||
/// Our painter.
|
||||
QLPainter painter_;
|
||||
|
||||
/// The slot connected to SyntheticMouseEvent::timeout.
|
||||
void generateSyntheticMouseEvent();
|
||||
|
||||
@ -175,7 +159,7 @@ private:
|
||||
SyntheticMouseEvent synthetic_mouse_event_;
|
||||
|
||||
/// Our client side painting device.
|
||||
QPixmap paint_device_;
|
||||
//QPixmap paint_device_;
|
||||
|
||||
/// \todo remove
|
||||
QTimer step_timer_;
|
||||
|
@ -33,8 +33,6 @@
|
||||
#include <QPixmap>
|
||||
#include <QImage>
|
||||
|
||||
using lyx::char_type;
|
||||
using lyx::docstring;
|
||||
|
||||
using std::endl;
|
||||
using std::string;
|
||||
@ -42,22 +40,12 @@ using std::string;
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
QLPainter::~QLPainter()
|
||||
QLPainter::QLPainter(QWidget * qwa)
|
||||
: qwa_(qwa)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QLPainter::QLPainter(GuiWorkArea * qwa)
|
||||
: Painter(), qwa_(qwa)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void QLPainter::start()
|
||||
{
|
||||
lyxerr << "QLPainter::start()" << endl;
|
||||
qp_.reset(new QPainter(qwa_->paintDevice()));
|
||||
qp_->setRenderHint(QPainter::TextAntialiasing);
|
||||
//lyxerr << "QLPainter::start()" << endl;
|
||||
QPainter::begin(qwa_);
|
||||
setRenderHint(QPainter::TextAntialiasing);
|
||||
// new QPainter has default QPen:
|
||||
current_color_ = LColor::black;
|
||||
current_ls_ = line_solid;
|
||||
@ -65,24 +53,25 @@ void QLPainter::start()
|
||||
}
|
||||
|
||||
|
||||
void QLPainter::end()
|
||||
QLPainter::~QLPainter()
|
||||
{
|
||||
qp_->end();
|
||||
lyxerr << "QLPainter::end()" << endl;
|
||||
QPainter::end();
|
||||
//lyxerr << "QLPainter::end()" << endl;
|
||||
}
|
||||
|
||||
|
||||
int QLPainter::paperWidth() const
|
||||
{
|
||||
return qwa_->viewport()->width();
|
||||
return qwa_->width();
|
||||
}
|
||||
|
||||
|
||||
int QLPainter::paperHeight() const
|
||||
{
|
||||
return qwa_->viewport()->height();
|
||||
return qwa_->height();
|
||||
}
|
||||
|
||||
|
||||
void QLPainter::setQPainterPen(LColor_color col,
|
||||
Painter::line_style ls, Painter::line_width lw)
|
||||
{
|
||||
@ -93,7 +82,7 @@ void QLPainter::setQPainterPen(LColor_color col,
|
||||
current_ls_ = ls;
|
||||
current_lw_ = lw;
|
||||
|
||||
QPen pen = qp_.get()->pen();
|
||||
QPen pen = QPainter::pen();
|
||||
|
||||
pen.setColor(guiApp->colorCache().get(col));
|
||||
|
||||
@ -107,14 +96,14 @@ void QLPainter::setQPainterPen(LColor_color col,
|
||||
case line_thick: pen.setWidth(3); break;
|
||||
}
|
||||
|
||||
qp_.get()->setPen(pen);
|
||||
setPen(pen);
|
||||
}
|
||||
|
||||
|
||||
void QLPainter::point(int x, int y, LColor_color col)
|
||||
{
|
||||
setQPainterPen(col);
|
||||
qp_->drawPoint(x, y);
|
||||
drawPoint(x, y);
|
||||
}
|
||||
|
||||
|
||||
@ -124,7 +113,7 @@ void QLPainter::line(int x1, int y1, int x2, int y2,
|
||||
line_width lw)
|
||||
{
|
||||
setQPainterPen(col, ls, lw);
|
||||
qp_->drawLine(x1, y1, x2, y2);
|
||||
drawLine(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
|
||||
@ -144,7 +133,7 @@ void QLPainter::lines(int const * xp, int const * yp, int np,
|
||||
}
|
||||
|
||||
setQPainterPen(col, ls, lw);
|
||||
qp_->drawPolyline(points.get(), np);
|
||||
drawPolyline(points.get(), np);
|
||||
}
|
||||
|
||||
|
||||
@ -154,13 +143,13 @@ void QLPainter::rectangle(int x, int y, int w, int h,
|
||||
line_width lw)
|
||||
{
|
||||
setQPainterPen(col, ls, lw);
|
||||
qp_->drawRect(x, y, w, h);
|
||||
drawRect(x, y, w, h);
|
||||
}
|
||||
|
||||
|
||||
void QLPainter::fillRectangle(int x, int y, int w, int h, LColor_color col)
|
||||
{
|
||||
qp_->fillRect(x, y, w, h, guiApp->colorCache().get(col));
|
||||
fillRect(x, y, w, h, guiApp->colorCache().get(col));
|
||||
}
|
||||
|
||||
|
||||
@ -169,25 +158,24 @@ void QLPainter::arc(int x, int y, unsigned int w, unsigned int h,
|
||||
{
|
||||
// LyX usings 1/64ths degree, Qt usings 1/16th
|
||||
setQPainterPen(col);
|
||||
qp_->drawArc(x, y, w, h, a1 / 4, a2 / 4);
|
||||
drawArc(x, y, w, h, a1 / 4, a2 / 4);
|
||||
}
|
||||
|
||||
|
||||
void QLPainter::image(int x, int y, int w, int h,
|
||||
lyx::graphics::Image const & i)
|
||||
void QLPainter::image(int x, int y, int w, int h, graphics::Image const & i)
|
||||
{
|
||||
lyx::graphics::QLImage const & qlimage =
|
||||
static_cast<lyx::graphics::QLImage const &>(i);
|
||||
graphics::QLImage const & qlimage =
|
||||
static_cast<graphics::QLImage const &>(i);
|
||||
|
||||
fillRectangle(x, y, w, h, LColor::graphicsbg);
|
||||
|
||||
qp_->drawImage(x, y, qlimage.qimage(), 0, 0, w, h);
|
||||
drawImage(x, y, qlimage.qimage(), 0, 0, w, h);
|
||||
}
|
||||
|
||||
|
||||
int QLPainter::text(int x, int y, docstring const & s, LyXFont const & f)
|
||||
{
|
||||
return text(x, y, reinterpret_cast<char_type const *>(s.data()), s.length(), f);
|
||||
return text(x, y, reinterpret_cast<char_type const *>(s.data()), s.length(), f);
|
||||
}
|
||||
|
||||
|
||||
@ -209,16 +197,16 @@ int QLPainter::smallCapsText(int x, int y,
|
||||
|
||||
setQPainterPen(f.realColor());
|
||||
int textwidth = 0;
|
||||
size_t ls = s.length();
|
||||
size_t const ls = s.length();
|
||||
for (unsigned int i = 0; i < ls; ++i) {
|
||||
QChar const c = s[i].toUpper();
|
||||
if (c != s.at(i)) {
|
||||
qp_->setFont(qsmallfont);
|
||||
setFont(qsmallfont);
|
||||
} else {
|
||||
qp_->setFont(qfont);
|
||||
setFont(qfont);
|
||||
}
|
||||
qp_->drawText(x + textwidth, y, c);
|
||||
textwidth += qp_->fontMetrics().width(c);
|
||||
drawText(x + textwidth, y, c);
|
||||
textwidth += fontMetrics().width(c);
|
||||
}
|
||||
return textwidth;
|
||||
}
|
||||
@ -249,13 +237,12 @@ int QLPainter::text(int x, int y, char_type const * s, size_t ls,
|
||||
|
||||
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
|
||||
setQPainterPen(f.realColor());
|
||||
if (qp_->font() != fi.font) {
|
||||
qp_->setFont(fi.font);
|
||||
}
|
||||
if (font() != fi.font)
|
||||
setFont(fi.font);
|
||||
// We need to draw the text as LTR as we use our own bidi code.
|
||||
qp_->setLayoutDirection(Qt::LeftToRight);
|
||||
qp_->drawText(x, y, str);
|
||||
textwidth = qp_->fontMetrics().width(str);
|
||||
setLayoutDirection(Qt::LeftToRight);
|
||||
drawText(x, y, str);
|
||||
textwidth = fontMetrics().width(str);
|
||||
} else {
|
||||
textwidth = smallCapsText(x, y, str, f);
|
||||
}
|
||||
@ -268,16 +255,5 @@ int QLPainter::text(int x, int y, char_type const * s, size_t ls,
|
||||
}
|
||||
|
||||
|
||||
void QLPainter::drawPixmap(int x, int y, QPixmap const & pixmap)
|
||||
{
|
||||
qp_->drawPixmap(x, y, pixmap);
|
||||
}
|
||||
|
||||
|
||||
void QLPainter::drawImage(int x, int y, QImage const & image)
|
||||
{
|
||||
qp_->drawImage(x, y, image);
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
class QPaintDevice;
|
||||
class QPainter;
|
||||
class QString;
|
||||
@ -34,18 +36,8 @@ class GuiWorkArea;
|
||||
/**
|
||||
* QLPainter - a painter implementation for Qt4
|
||||
*/
|
||||
class QLPainter : public Painter {
|
||||
class QLPainter : public QPainter, public Painter {
|
||||
public:
|
||||
QLPainter(GuiWorkArea *);
|
||||
|
||||
~QLPainter();
|
||||
|
||||
/// begin painting
|
||||
virtual void start();
|
||||
|
||||
/// end painting
|
||||
virtual void end();
|
||||
|
||||
/// return the width of the work area in pixels
|
||||
virtual int paperWidth() const;
|
||||
/// return the height of the work area in pixels
|
||||
@ -119,13 +111,11 @@ public:
|
||||
virtual int text(int x, int y,
|
||||
lyx::char_type c, LyXFont const & f);
|
||||
|
||||
/// draw a pixmap from the image cache
|
||||
virtual void drawPixmap(int x, int y, QPixmap const & pixmap);
|
||||
|
||||
/// draw a pixmap from the image cache
|
||||
virtual void drawImage(int x, int y, QImage const & image);
|
||||
|
||||
private:
|
||||
friend class GuiWorkArea;
|
||||
QLPainter(QWidget *);
|
||||
~QLPainter();
|
||||
|
||||
/// draw small caps text
|
||||
/**
|
||||
\return width of the drawn text.
|
||||
@ -138,11 +128,8 @@ private:
|
||||
line_style ls = line_solid,
|
||||
line_width lw = line_thin);
|
||||
|
||||
/// our qt painter
|
||||
boost::scoped_ptr<QPainter> qp_;
|
||||
|
||||
/// the working area
|
||||
GuiWorkArea * qwa_;
|
||||
QWidget * qwa_;
|
||||
|
||||
LColor::color current_color_;
|
||||
Painter::line_style current_ls_;
|
||||
|
Loading…
Reference in New Issue
Block a user