* qt_helpers.cpp:
[lyx.git] / src / MetricsInfo.h
bloba711a2a416e14a303ba8a055dfb62b1887d19cbb
1 // -*- C++ -*-
2 /**
3 * \file MetricsInfo.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author André Pönitz
8 * \author Stefan Schimanski
10 * Full author contact details are available in file CREDITS.
13 #ifndef METRICSINFO_H
14 #define METRICSINFO_H
16 #include "Changes.h"
17 #include "ColorCode.h"
18 #include "FontInfo.h"
20 #include "support/strfwd.h"
21 #include "support/types.h"
23 #include <string>
25 class BufferView;
27 namespace lyx {
29 namespace frontend { class Painter; }
30 class Inset;
31 class MacroContext;
34 /// Standard Sizes (mode styles)
35 enum Styles {
36 ///
37 LM_ST_DISPLAY = 0,
38 ///
39 LM_ST_TEXT,
40 ///
41 LM_ST_SCRIPT,
42 ///
43 LM_ST_SCRIPTSCRIPT
48 // This is the part common to MetricsInfo and PainterInfo
50 class MetricsBase {
51 public:
52 ///
53 MetricsBase();
54 ///
55 MetricsBase(BufferView * bv, FontInfo const & font, int textwidth);
57 /// the current view
58 BufferView * bv;
59 /// current font
60 FontInfo font;
61 /// current math style (display/text/script/..)
62 Styles style;
63 /// name of current font - mathed specific
64 std::string fontname;
65 /// This is the width available in pixels
66 int textwidth;
71 // This contains a MetricsBase and information that's only relevant during
72 // the first phase of the two-phase draw
74 class MetricsInfo {
75 public:
76 ///
77 MetricsInfo();
78 ///
79 MetricsInfo(BufferView * bv, FontInfo const & font, int textwidth, MacroContext const & mc);
81 ///
82 MetricsBase base;
83 /// The context to resolve macros
84 MacroContext const & macrocontext;
89 // This contains a MetricsBase and information that's only relevant during
90 // the second phase of the two-phase draw
92 class PainterInfo {
93 public:
94 ///
95 PainterInfo(BufferView * bv, frontend::Painter & pain);
96 ///
97 void draw(int x, int y, char_type c);
98 ///
99 void draw(int x, int y, docstring const & str);
100 /// Determines the background color for the specified inset based on the
101 /// selection state, the background color inherited from the parent inset
102 /// and the inset's own background color.
103 /// \param sel whether to take the selection state into account
104 ColorCode backgroundColor(Inset const * inset, bool sel = true) const;
107 MetricsBase base;
109 frontend::Painter & pain;
110 /// Whether the text at this point is right-to-left (for InsetNewline)
111 bool ltr_pos;
112 /// The change the parent is part of (change tracking)
113 Change change_;
114 /// Whether the parent is selected as a whole
115 bool selected;
117 bool full_repaint;
118 /// Current background color
119 ColorCode background_color;
122 class TextMetricsInfo {};
125 /// Generic base for temporarily changing things.
126 /// The original state gets restored when the Changer is destructed.
127 template <class Struct, class Temp = Struct>
128 class Changer {
129 public:
131 Changer(Struct & orig) : orig_(orig) {}
132 protected:
134 Struct & orig_;
136 Temp save_;
141 // temporarily change some aspect of a font
142 class FontChanger : public Changer<FontInfo> {
143 public:
145 FontChanger(FontInfo & orig, docstring const & font);
146 FontChanger(MetricsBase & mb, char const * const font);
148 ~FontChanger();
152 // temporarily change a full font
153 class FontSetChanger : public Changer<MetricsBase> {
154 public:
156 FontSetChanger(MetricsBase & mb, docstring const & font);
157 FontSetChanger(MetricsBase & mb, char const * const font);
159 ~FontSetChanger();
163 // temporarily change the style
164 class StyleChanger : public Changer<MetricsBase> {
165 public:
167 StyleChanger(MetricsBase & mb, Styles style);
169 ~StyleChanger();
173 // temporarily change the style to script style
174 class ScriptChanger : public StyleChanger {
175 public:
177 ScriptChanger(MetricsBase & mb);
181 // temporarily change the style suitable for use in fractions
182 class FracChanger : public StyleChanger {
183 public:
185 FracChanger(MetricsBase & mb);
189 // temporarily change the style suitable for use in tabulars and arrays
190 class ArrayChanger : public StyleChanger {
191 public:
193 ArrayChanger(MetricsBase & mb);
198 // temporarily change the shape of a font
199 class ShapeChanger : public Changer<FontInfo, FontShape> {
200 public:
202 ShapeChanger(FontInfo & font, FontShape shape);
204 ~ShapeChanger();
208 // temporarily change the available text width
209 class WidthChanger : public Changer<MetricsBase>
211 public:
213 WidthChanger(MetricsBase & mb, int width);
215 ~WidthChanger();
219 // temporarily change the used color
220 class ColorChanger : public Changer<FontInfo, std::string> {
221 public:
223 ColorChanger(FontInfo & font, std::string const & color);
225 ~ColorChanger();
228 } // namespace lyx
230 #endif