OSDN Git Service

542a5b16f1c941a57773c2c3dbc99f5cb1b010f8
[qt-creator-jp/qt-creator-jp.git] / src / plugins / texteditor / colorscheme.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef COLORSCHEME_H
35 #define COLORSCHEME_H
36
37 #include "texteditor_global.h"
38
39 #include <QtCore/QMap>
40 #include <QtCore/QString>
41 #include <QtGui/QColor>
42
43 namespace TextEditor {
44
45 /*! Format for a particular piece of text (text/comment, etc). */
46 class TEXTEDITOR_EXPORT Format
47 {
48 public:
49     Format();
50
51     QColor foreground() const { return m_foreground; }
52     void setForeground(const QColor &foreground);
53
54     QColor background() const { return m_background; }
55     void setBackground(const QColor &background);
56
57     bool bold() const { return m_bold; }
58     void setBold(bool bold);
59
60     bool italic() const { return m_italic; }
61     void setItalic(bool italic);
62
63     bool equals(const Format &f) const;
64
65     QString toString() const;
66     bool fromString(const QString &str);
67
68 private:
69     QColor m_foreground;
70     QColor m_background;
71     bool m_bold;
72     bool m_italic;
73 };
74
75 inline bool operator==(const Format &f1, const Format &f2) { return f1.equals(f2); }
76 inline bool operator!=(const Format &f1, const Format &f2) { return !f1.equals(f2); }
77
78
79 /*! A color scheme combines a set of formats for different highlighting
80     categories. It also provides saving and loading of the scheme to a file.
81  */
82 class ColorScheme
83 {
84 public:
85     ColorScheme();
86
87     void setDisplayName(const QString &name)
88     { m_displayName = name; }
89
90     QString displayName() const
91     { return m_displayName; }
92
93     inline bool isEmpty() const
94     { return m_formats.isEmpty(); }
95
96     bool contains(const QString &category) const;
97
98     Format &formatFor(const QString &category);
99     Format formatFor(const QString &category) const;
100
101     void setFormatFor(const QString &category, const Format &format);
102
103     void clear();
104
105     bool save(const QString &fileName) const;
106     bool load(const QString &fileName);
107
108     inline bool equals(const ColorScheme &cs) const
109     {
110         return m_formats == cs.m_formats
111                 && m_displayName == cs.m_displayName;
112     }
113
114     static QString readNameOfScheme(const QString &fileName);
115
116 private:
117     QMap<QString, Format> m_formats;
118     QString m_displayName;
119 };
120
121 inline bool operator==(const ColorScheme &cs1, const ColorScheme &cs2) { return cs1.equals(cs2); }
122 inline bool operator!=(const ColorScheme &cs1, const ColorScheme &cs2) { return !cs1.equals(cs2); }
123
124 } // namespace TextEditor
125
126 #endif // COLORSCHEME_H