2006-03-05 17:24:44 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiPainter.h
|
2006-03-05 17:24:44 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#ifndef GUIPAINTER_H
|
|
|
|
#define GUIPAINTER_H
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-02-09 20:10:11 +00:00
|
|
|
#include "Color.h"
|
|
|
|
|
2006-10-30 14:15:05 +00:00
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
2006-10-23 08:46:09 +00:00
|
|
|
#include <QPainter>
|
2016-01-24 11:49:02 +00:00
|
|
|
#include <QPainterPath>
|
2007-11-01 10:52:51 +00:00
|
|
|
#include <stack>
|
2006-10-23 08:46:09 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
class QString;
|
2006-06-20 08:39:16 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
class FontInfo;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2014-10-12 17:23:13 +00:00
|
|
|
* GuiPainter - a painter implementation for Qt
|
2006-03-05 17:24:44 +00:00
|
|
|
*/
|
2007-08-31 22:16:11 +00:00
|
|
|
class GuiPainter : public QPainter, public Painter {
|
2006-03-05 17:24:44 +00:00
|
|
|
public:
|
2014-10-12 17:23:13 +00:00
|
|
|
GuiPainter(QPaintDevice *, double pixel_ratio);
|
2007-08-31 22:16:11 +00:00
|
|
|
virtual ~GuiPainter();
|
2006-10-30 13:16:18 +00:00
|
|
|
|
2017-07-15 23:25:03 +00:00
|
|
|
/// This painter paints
|
|
|
|
virtual bool isNull() const { return false; }
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/// draw a line from point to point
|
|
|
|
virtual void line(
|
|
|
|
int x1, int y1,
|
|
|
|
int x2, int y2,
|
2009-02-09 20:10:11 +00:00
|
|
|
Color,
|
2014-04-04 19:54:32 +00:00
|
|
|
line_style ls = line_solid,
|
2015-07-14 15:42:45 +00:00
|
|
|
int lw = thin_line);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* lines - draw a set of lines
|
|
|
|
* @param xp array of points' x co-ords
|
|
|
|
* @param yp array of points' y co-ords
|
|
|
|
* @param np size of the points array
|
|
|
|
*/
|
|
|
|
virtual void lines(
|
|
|
|
int const * xp,
|
|
|
|
int const * yp,
|
|
|
|
int np,
|
2009-02-09 20:10:11 +00:00
|
|
|
Color,
|
2014-10-25 21:38:52 +00:00
|
|
|
fill_style fs = fill_none,
|
2014-04-04 19:54:32 +00:00
|
|
|
line_style ls = line_solid,
|
2015-07-14 15:42:45 +00:00
|
|
|
int lw = thin_line);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2016-01-24 11:49:02 +00:00
|
|
|
/**
|
|
|
|
* path - draw a path with bezier curves
|
|
|
|
* @param xp array of points' x co-ords
|
|
|
|
* @param yp array of points' y co-ords
|
|
|
|
* @param c1x array of first control points' x co-ords
|
|
|
|
* @param c1y array of first control points' y co-ords
|
|
|
|
* @param c2x array of second control points' x co-ords
|
|
|
|
* @param c2y array of second control points' y co-ords
|
|
|
|
* @param np size of the points array
|
|
|
|
*/
|
|
|
|
virtual void path(int const * xp, int const * yp,
|
|
|
|
int const * c1x, int const * c1y,
|
|
|
|
int const * c2x, int const * c2y,
|
|
|
|
int np, Color,
|
|
|
|
fill_style = fill_none, line_style = line_solid,
|
|
|
|
int line_width = thin_line);
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/// draw a rectangle
|
|
|
|
virtual void rectangle(
|
|
|
|
int x, int y,
|
|
|
|
int w, int h,
|
2009-02-09 20:10:11 +00:00
|
|
|
Color,
|
2006-03-05 17:24:44 +00:00
|
|
|
line_style = line_solid,
|
2015-07-14 15:42:45 +00:00
|
|
|
int lw = thin_line);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
/// draw a filled rectangle
|
|
|
|
virtual void fillRectangle(
|
|
|
|
int x, int y,
|
|
|
|
int w, int h,
|
2009-02-09 20:10:11 +00:00
|
|
|
Color);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
/// draw an arc
|
|
|
|
virtual void arc(
|
|
|
|
int x, int y,
|
|
|
|
unsigned int w, unsigned int h,
|
|
|
|
int a1, int a2,
|
2009-02-09 20:10:11 +00:00
|
|
|
Color);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
/// draw a pixel
|
2009-02-09 20:10:11 +00:00
|
|
|
virtual void point(int x, int y, Color);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
/// draw an image from the image cache
|
2007-11-23 21:39:51 +00:00
|
|
|
virtual void image(int x, int y, int w, int h,
|
2006-03-05 17:24:44 +00:00
|
|
|
lyx::graphics::Image const & image);
|
|
|
|
|
2016-03-20 19:02:05 +00:00
|
|
|
/// draw a string at position x, y (y is the baseline).
|
|
|
|
virtual void text(int x, int y, docstring const & str, FontInfo const & f);
|
|
|
|
|
|
|
|
/// draw a char at position x, y (y is the baseline)
|
|
|
|
virtual void text(int x, int y, char_type c, FontInfo const & f);
|
2014-05-23 16:59:53 +00:00
|
|
|
|
|
|
|
/** draw a string at position x, y (y is the baseline). The
|
|
|
|
* text direction is enforced by the \c Font.
|
|
|
|
*/
|
2016-03-19 16:52:07 +00:00
|
|
|
virtual void text(int x, int y, docstring const & str, Font const & f,
|
2016-03-20 19:02:05 +00:00
|
|
|
double wordspacing, double textwidth);
|
2014-05-23 16:59:53 +00:00
|
|
|
|
|
|
|
/** draw a string at position x, y (y is the baseline), but
|
|
|
|
* make sure that the part between \c from and \c to is in
|
|
|
|
* \c other color. The text direction is enforced by the \c Font.
|
|
|
|
*/
|
2016-03-19 16:52:07 +00:00
|
|
|
virtual void text(int x, int y, docstring const & str, Font const & f,
|
|
|
|
Color other, size_type from, size_type to,
|
2016-03-20 19:02:05 +00:00
|
|
|
double wordspacing, double textwidth);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2012-05-02 16:02:17 +00:00
|
|
|
///
|
|
|
|
virtual void textDecoration(FontInfo const & f, int x, int y, int width);
|
|
|
|
|
2007-11-23 21:39:51 +00:00
|
|
|
/// draw a string and enclose it inside a button frame
|
|
|
|
virtual void buttonText(int x, int baseline, docstring const & s,
|
2017-06-15 13:30:23 +00:00
|
|
|
FontInfo const & font, Color back, Color frame, int offset);
|
2007-11-23 21:39:51 +00:00
|
|
|
|
2007-11-01 10:52:51 +00:00
|
|
|
/// start monochrome painting mode, i.e. map every color into [min,max]
|
2016-03-20 19:02:05 +00:00
|
|
|
virtual void enterMonochromeMode(Color const & min,
|
2009-02-09 20:10:11 +00:00
|
|
|
Color const & max);
|
2007-11-01 10:52:51 +00:00
|
|
|
/// leave monochrome painting mode
|
|
|
|
virtual void leaveMonochromeMode();
|
2016-03-20 19:02:05 +00:00
|
|
|
|
2007-11-23 21:39:51 +00:00
|
|
|
/**
|
|
|
|
* Draw a string and enclose it inside a rectangle. If
|
|
|
|
* back color is specified, the background is cleared with
|
|
|
|
* the given color. If frame is specified, a thin frame is drawn
|
|
|
|
* around the text with the given color.
|
|
|
|
*/
|
|
|
|
virtual void rectText(int x, int baseline, docstring const & str,
|
2009-02-09 20:10:11 +00:00
|
|
|
FontInfo const & font, Color back, Color frame);
|
2007-11-23 21:39:51 +00:00
|
|
|
|
|
|
|
/// draw a character of a preedit string for cjk support.
|
|
|
|
virtual int preeditText(int x, int y,
|
|
|
|
char_type c, FontInfo const & f, preedit_style style);
|
|
|
|
|
2009-03-28 16:37:28 +00:00
|
|
|
void wavyHorizontalLine(int x, int y, int width, ColorCode col);
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
private:
|
2007-11-23 21:39:51 +00:00
|
|
|
/// check the font, and if set, draw an underline
|
|
|
|
void underline(FontInfo const & f,
|
2015-04-14 13:22:11 +00:00
|
|
|
int x, int y, int width, line_style ls = line_solid);
|
2007-11-23 21:39:51 +00:00
|
|
|
|
|
|
|
/// check the font, and if set, draw an dashed underline
|
|
|
|
void dashedUnderline(FontInfo const & f,
|
|
|
|
int x, int y, int width);
|
2009-05-05 09:26:28 +00:00
|
|
|
|
2009-05-03 22:45:14 +00:00
|
|
|
/// check the font, and if set, draw an strike-through line
|
|
|
|
void strikeoutLine(FontInfo const & f,
|
|
|
|
int x, int y, int width);
|
2007-11-23 21:39:51 +00:00
|
|
|
|
2017-04-04 22:01:19 +00:00
|
|
|
/// check the font, and if set, draw cross-through lines
|
|
|
|
void crossoutLines(FontInfo const & f,
|
|
|
|
int x, int y, int width);
|
|
|
|
|
2009-05-05 09:26:28 +00:00
|
|
|
/// check the font, and if set, draw double underline
|
|
|
|
void doubleUnderline(FontInfo const & f,
|
|
|
|
int x, int y, int width);
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/// set pen parameters
|
2007-11-01 10:52:51 +00:00
|
|
|
void setQPainterPen(QColor const & col,
|
2015-07-14 15:42:45 +00:00
|
|
|
line_style ls = line_solid, int lw = thin_line);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2016-05-31 07:13:18 +00:00
|
|
|
// Direction for painting text
|
|
|
|
enum Direction { LtR, RtL, Auto };
|
|
|
|
|
2015-10-19 14:34:04 +00:00
|
|
|
// Helper for text() method
|
2016-05-31 07:13:18 +00:00
|
|
|
void do_drawText(int x, int y, QString str, Direction dir, FontInfo const & f, QFont ff);
|
2015-10-19 14:34:04 +00:00
|
|
|
|
2016-03-20 19:02:05 +00:00
|
|
|
// Real text() method
|
|
|
|
void text(int x, int y, docstring const & s,
|
2016-05-31 07:13:18 +00:00
|
|
|
FontInfo const & f, Direction const dir,
|
2016-03-20 19:02:05 +00:00
|
|
|
double const wordspacing, double tw);
|
|
|
|
|
2007-11-01 10:52:51 +00:00
|
|
|
QColor current_color_;
|
2006-06-11 21:22:36 +00:00
|
|
|
Painter::line_style current_ls_;
|
2015-07-14 15:42:45 +00:00
|
|
|
int current_lw_;
|
2007-11-01 10:52:51 +00:00
|
|
|
///
|
2007-11-02 14:43:09 +00:00
|
|
|
bool const use_pixmap_cache_;
|
|
|
|
///
|
2007-11-01 10:52:51 +00:00
|
|
|
std::stack<QColor> monochrome_min_;
|
|
|
|
///
|
|
|
|
std::stack<QColor> monochrome_max_;
|
|
|
|
/// convert into Qt color, possibly applying the monochrome mode
|
2009-02-09 20:10:11 +00:00
|
|
|
QColor computeColor(Color col);
|
2007-11-01 10:52:51 +00:00
|
|
|
/// possibly apply monochrome mode
|
|
|
|
QColor filterColor(QColor const & col);
|
|
|
|
///
|
2016-03-11 09:08:15 +00:00
|
|
|
QString generateStringSignature(QString const & str, FontInfo const & f,
|
|
|
|
double wordspacing);
|
2006-03-05 17:24:44 +00:00
|
|
|
};
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#endif // GUIPAINTER_H
|