File: color_manager.h

package info (click to toggle)
imsprog 1.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 17,984 kB
  • sloc: cpp: 8,301; ansic: 6,111; xml: 677; sh: 265; makefile: 5
file content (119 lines) | stat: -rw-r--r-- 3,229 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* QHexEdit is a Hex Editor Widget for the Qt Framework
* Copyright (C) 2010-2025 Winfried Simon
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* https://www.gnu.org/licenses/
*/
#ifndef COLOR_MANAGER_H
#define COLOR_MANAGER_H

/** \cond docNever */

/*! The ColorManager class is responsible for color management
 *
 * Color management is combined in this class. The definitions for pen and background colors 
 * are stored here.
 * 
 * This includes the standard colors for the address, hex data and ASCII data areas as well as 
 * the colors for the marking information. The areas for selection and highlighting are defined 
 * in advance. In addition, any number of user areas can be defined. 
 * 
 * The colors for a single area are provided by the ColoredArea class.
 */

#include <QtCore>
#include <QtGui>

#include "chunks.h"

enum Area {
    Address,
    Hex,
    Ascii,
};

class ColoredArea
{
public:
    // Cunstructors
    ColoredArea();
    ColoredArea(QPen pen, QBrush background);
    ColoredArea(qint64 posStart, qint64 posEnd, QPen pen, QBrush background);

    // Property to set/get font color
    QColor fontColor();
    void setFontColor(QColor color);

    // Property to set/get area style
    QColor areaColor();
    QBrush areaStyle();
    void setAreaColor(QColor color);
    void setAreaStyle(QBrush background);

    // other Methods to acces and set internal data
    QPen fontPen();
    qint64 posStart();
    qint64 posEnd();
    void setRange(qint64 posStart, qint64 posEnd);
    void clear();

private:
    qint64 _posStart;
    qint64 _posEnd;
    QPen _fontColor;
    QBrush _areaStyle;
};


class ColorManager
{
public:
    // Constructor including the definition of standard colors
    ColorManager();

    // reload the palette and adapt the apeareance
    void setPalette(const QPalette &palette);

    // Method returns color definitions for data at position pos in area area
    ColoredArea markedArea(qint64 pos, Area area, Chunks *chunks);

    // Method returns standard collors (without marking)
    ColoredArea& notMarked(Area);

    // Get the selection color definitions
    ColoredArea& selection();

    // Get the highlighting color definitions
    ColoredArea& highlighting();

    // Add a user defined area
    void addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QBrush areaStyle);

    // Clear all user defined areas
    void clearUserAreas();

private:
    ColoredArea _highlighting;
    ColoredArea _selection;
    ColoredArea _address;
    ColoredArea _hex;
    ColoredArea _ascii;

    QList<ColoredArea> _userAreas;
};

/** \endcond docNever */

#endif // COLOR_MANAGER_H