refresh 77518ae98cef372c3d26fc7e5c43c5ad4a09c6f5
[tagua/yd.git] / src / hline.h
blob69823562e3d13440add3b780429eaf72bb4b4eb6
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef HLINE_H
12 #define HLINE_H
14 #include <QTextCharFormat>
15 #include <vector>
16 #include <QString>
17 #include <QColor>
19 class HLineExecutor {
20 public:
21 virtual ~HLineExecutor() { }
22 virtual void writeChunk(const QString&) = 0;
23 virtual void setFormat(const QTextCharFormat&) = 0;
26 class HLine {
27 class Region {
28 int m_end;
29 QTextCharFormat m_format;
30 public:
31 Region(int end, QTextCharFormat format)
32 : m_end(end)
33 , m_format(format) { }
35 int end() const { return m_end; }
36 const QTextCharFormat& format() const { return m_format; }
37 QTextCharFormat& format() { return m_format; }
39 void setEnd(int index) { m_end = index; }
40 void setFormat(const QTextCharFormat& format) { m_format = format; }
42 struct Format {
43 std::pair<bool, bool> m_bold;
44 std::pair<bool, bool> m_italic;
45 std::pair<bool, QColor> m_color;
46 Format()
47 : m_bold(false, false)
48 , m_italic(false, false)
49 , m_color(false, QColor()) { }
50 void applyTo(QTextCharFormat& fmt) const;
53 std::vector<Region> m_regions;
54 QString m_text;
56 int begin(uint index) const;
57 uint findRegion(int index) const;
58 uint splitRegion(int index);
59 void setFormat(int begin, int end, const Format&);
60 public:
61 HLine(const QString& text, const QTextCharFormat& baseFormat);
62 HLine(const HLine& other);
64 const QTextCharFormat& getFormat(int index) const;
66 void setBold(int begin, int end, bool value);
67 void setItalic(int begin, int end, bool value);
68 void setColor(int begin, int end, const QColor& color);
69 QString mid(int begin, int end) const;
70 int length() const { return m_text.length(); }
71 HLine* extract(int begin, int end) const;
72 HLine* append(const HLine& other, int begin, int end) const;
74 void dump() const;
76 void run(HLineExecutor&) const;
79 #endif // HLINE_H