Ran qt3to4
[basket4.git] / src / tag.h
blobd89a220aeabef712f9669939654dc87ee89e4bd5
1 /***************************************************************************
2 * Copyright (C) 2005 by S�astien Laot *
3 * slaout@linux62.org *
4 * *
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 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifndef TAG_H
22 #define TAG_H
24 #include <qstring.h>
25 #include <qcolor.h>
26 #include <qfont.h>
27 #include <q3valuelist.h>
29 #include <kaction.h>
30 #include <kshortcut.h>
32 class QPainter;
34 class Tag;
36 /**
37 * @author S�astien Laot
39 class State
41 public:
42 /// LIST OF STATES:
43 typedef Q3ValueList<State*> List;
45 public:
46 /// CONSTRUCTOR AND DESTRUCTOR:
47 State(const QString &id = QString(), Tag *tag = 0);
48 ~State();
49 /// SET PROPERTIES:
50 void setId(const QString &id) { m_id = id; }
51 void setName(const QString &name) { m_name = name; }
52 void setEmblem(const QString &emblem) { m_emblem = emblem; }
53 void setBold(bool bold) { m_bold = bold; }
54 void setItalic(bool italic) { m_italic = italic; }
55 void setUnderline(bool underline) { m_underline = underline; }
56 void setStrikeOut(bool strikeOut) { m_strikeOut = strikeOut; }
57 void setTextColor(const QColor &color) { m_textColor = color; }
58 void setFontName(const QString &font) { m_fontName = font; }
59 void setFontSize(int size) { m_fontSize = size; }
60 void setBackgroundColor(const QColor &color) { m_backgroundColor = color; }
61 void setTextEquivalent(const QString &text) { m_textEquivalent = text; }
62 void setOnAllTextLines(bool yes) { m_onAllTextLines = yes; }
63 void setParentTag(Tag *tag) { m_parentTag = tag; }
64 /// GET PROPERTIES:
65 QString id() const { return m_id; }
66 QString name() const { return m_name; }
67 QString emblem() const { return m_emblem; }
68 bool bold() const { return m_bold; }
69 bool italic() const { return m_italic; }
70 bool underline() const { return m_underline; }
71 bool strikeOut() const { return m_strikeOut; }
72 QColor textColor() const { return m_textColor; }
73 QString fontName() const { return m_fontName; }
74 int fontSize() const { return m_fontSize; }
75 QColor backgroundColor() const { return m_backgroundColor; }
76 QString textEquivalent() const { return m_textEquivalent; }
77 bool onAllTextLines() const { return m_onAllTextLines; }
78 Tag* parentTag() const { return m_parentTag; }
79 /// HELPING FUNCTIONS:
80 State *nextState(bool cycle = true);
81 QString fullName();
82 QFont font(QFont base);
83 QString toCSS(const QString &gradientFolderPath, const QString &gradientFolderName, const QFont &baseFont);
84 static void merge(const List &states, State *result, int *emblemsCount, bool *haveInvisibleTags, const QColor &backgroundColor);
85 void copyTo(State *other);
86 private:
87 /// PROPERTIES:
88 QString m_id;
89 QString m_name;
90 QString m_emblem;
91 bool m_bold;
92 bool m_italic;
93 bool m_underline;
94 bool m_strikeOut;
95 QColor m_textColor;
96 QString m_fontName;
97 int m_fontSize;
98 QColor m_backgroundColor;
99 QString m_textEquivalent;
100 bool m_onAllTextLines;
101 Tag *m_parentTag;
104 /** A Tag is a category of Notes.
105 * A Note can have 0, 1 or more Tags.
106 * A Tag can have a unique State or several States.
107 * @author S�astien Laot
109 class Tag
111 public:
112 /// LIST OF ALL TAGS IN THE APPLICATION:
113 typedef Q3ValueList<Tag*> List;
114 static Tag::List all;
115 static State* stateForId(const QString &id);
116 static Tag* tagForKAction(KAction *action);
117 static Tag* tagSimilarTo(Tag *tagToTest);
118 static QMap<QString, QString> loadTags(const QString &path = QString()/*, bool merge = false*/); /// << Load the tags contained in the XML file @p path or those in the application settings if @p path isEmpty(). If @p merge is true and a tag with the id of a tag that should be loaded already exist, the tag will get a new id. Otherwise, the tag will be dismissed.
119 static void saveTags();
120 static void saveTagsTo(Q3ValueList<Tag*> &list, const QString &fullPath);
121 static void createDefaultTagsSet(const QString &file);
122 static long getNextStateUid();
123 private:
124 static long nextStateUid;
126 public:
127 /// CONSTRUCTOR AND DESTRUCTOR:
128 Tag(/*State *firstState, const QString &name, bool inheritedBySiblings*/);
129 ~Tag();
130 /// SET PROPERTIES:
131 void setName(const QString &name);
132 void setShortcut(const KShortcut &shortcut) { m_action->setShortcut(shortcut); }
133 void setInheritedBySiblings(bool inherited) { m_inheritedBySiblings = inherited; }
134 void appendState(State *state) { m_states.append(state); state->setParentTag(this); }
135 void removeState(State *state) { m_states.remove(state); state->setParentTag(0); }
136 /// GET PROPERTIES:
137 QString name() const { return m_name; }
138 KShortcut shortcut() const { return m_action->shortcut(); }
139 bool inheritedBySiblings() const { return m_inheritedBySiblings; }
140 State::List& states() const { return (State::List&)m_states; }
141 int countStates() const { return m_states.count(); }
142 void copyTo(Tag *other);
143 private:
144 /// PROPERTIES:
145 QString m_name;
146 KAction *m_action;
147 bool m_inheritedBySiblings;
148 State::List m_states;
151 #include <qicon.h>
152 #include <qmenudata.h>
153 #include <qstring.h>
155 class QPainter;
157 /** A menu item to indent icon and text (to keep place for a checkbox or a radiobutton on left).
158 * You should not set any icon when adding this entry to the menu.
159 * Instead, the constructor take the icon and the item take care to draw it itself.
160 * Better suited to be used with StateMenuItem (or TagMenuItem).
161 * @author S�astien Laot
163 class IndentedMenuItem : public QCustomMenuItem
165 public:
166 IndentedMenuItem(const QString &text, const QString &icon = "", const QString &shortcut = "");
167 ~IndentedMenuItem();
168 void paint(QPainter *painter, const QColorGroup &cg, bool active, bool enabled, int x, int y, int w, int h);
169 QSize sizeHint();
170 bool fullSpan() { return true; }
171 private:
172 QString m_text;
173 QString m_icon;
174 QString m_shortcut;
177 /** A menu item representing a State or a Tag.
178 * @author S�astien Laot
180 class StateMenuItem : public QCustomMenuItem
182 public:
183 StateMenuItem(State *state, const QString &shortcut, bool withTagName = false);
184 ~StateMenuItem();
185 void paint(QPainter *painter, const QColorGroup &cg, bool active, bool enabled, int x, int y, int w, int h);
186 QSize sizeHint();
187 bool fullSpan() { return true; }
188 private:
189 State *m_state;
190 QString m_name;
191 QString m_shortcut;
192 public:
193 static QIcon checkBoxIconSet(bool checked, QColorGroup cg);
194 static QIcon radioButtonIconSet(bool checked, QColorGroup cg);
195 static int iconMargin() { return 5; }
198 #endif // TAG_H