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);
#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>
namespace os = lyx::support::os;
+
+volatile int NN;
+
+void recCalled()
+{
+ ++NN;
+}
+
+
namespace lyx {
/// return the LyX key state from Qt's
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);
}
-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();
}
}
-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()
<< 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;
}
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();
#include "frontends/WorkArea.h"
-#include "QLPainter.h"
-
#include "funcrequest.h"
#include "frontends/Timeout.h"
class QPaintEvent;
namespace lyx {
-
-class Painter;
-
namespace frontend {
class GuiView;
+class QLPainter;
/// for emulating triple click
class double_click {
* Qt-specific implementation of the work area
* (buffer view GUI)
*/
-class GuiWorkArea: public QAbstractScrollArea, public WorkArea
+class GuiWorkArea : public QAbstractScrollArea, public WorkArea
{
Q_OBJECT
///
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);
/// 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
void adjustViewWithScrollBar(int action = 0);
private:
-
- /// Our painter.
- QLPainter painter_;
-
/// The slot connected to SyntheticMouseEvent::timeout.
void generateSyntheticMouseEvent();
SyntheticMouseEvent synthetic_mouse_event_;
/// Our client side painting device.
- QPixmap paint_device_;
+ //QPixmap paint_device_;
/// \todo remove
QTimer step_timer_;
#include <QPixmap>
#include <QImage>
-using lyx::char_type;
-using lyx::docstring;
using std::endl;
using std::string;
namespace lyx {
namespace frontend {
-QLPainter::~QLPainter()
-{
-}
-
-
-QLPainter::QLPainter(GuiWorkArea * qwa)
- : Painter(), qwa_(qwa)
+QLPainter::QLPainter(QWidget * qwa)
+ : 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;
}
-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)
{
current_ls_ = ls;
current_lw_ = lw;
- QPen pen = qp_.get()->pen();
+ QPen pen = QPainter::pen();
pen.setColor(guiApp->colorCache().get(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);
}
line_width lw)
{
setQPainterPen(col, ls, lw);
- qp_->drawLine(x1, y1, x2, y2);
+ drawLine(x1, y1, x2, y2);
}
}
setQPainterPen(col, ls, lw);
- qp_->drawPolyline(points.get(), np);
+ drawPolyline(points.get(), np);
}
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));
}
{
// 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);
}
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;
}
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);
}
}
-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
#include <boost/scoped_ptr.hpp>
+#include <QPainter>
+
class QPaintDevice;
class QPainter;
class QString;
/**
* 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
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.
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_;