1 /*************************************************************************** 2 * Copyright (C) 2005 by Sébastien Laoût * 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 ***************************************************************************/ 20 21 #ifndef TAG_H 22 #define TAG_H 23 24 #include <QtCore/QList> 25 26 #include <KToggleAction> 27 28 class QColor; 29 class QFont; 30 class QPainter; 31 class QString; 32 33 class QKeySequence; 34 35 class Tag; 36 37 /** 38 * @author Sébastien Laoût 39 */ 40 class State 41 { 42 public: 43 /// LIST OF STATES: 44 typedef QList<State*> List; 45 46 public: 47 /// CONSTRUCTOR AND DESTRUCTOR: 48 explicit State(const QString &id = QString(), Tag *tag = 0); 49 ~State(); 50 /// SET PROPERTIES: setId(const QString & id)51 void setId(const QString &id) { 52 m_id = id; 53 } setName(const QString & name)54 void setName(const QString &name) { 55 m_name = name; 56 } setEmblem(const QString & emblem)57 void setEmblem(const QString &emblem) { 58 m_emblem = emblem; 59 } setBold(bool bold)60 void setBold(bool bold) { 61 m_bold = bold; 62 } setItalic(bool italic)63 void setItalic(bool italic) { 64 m_italic = italic; 65 } setUnderline(bool underline)66 void setUnderline(bool underline) { 67 m_underline = underline; 68 } setStrikeOut(bool strikeOut)69 void setStrikeOut(bool strikeOut) { 70 m_strikeOut = strikeOut; 71 } setTextColor(const QColor & color)72 void setTextColor(const QColor &color) { 73 m_textColor = color; 74 } setFontName(const QString & font)75 void setFontName(const QString &font) { 76 m_fontName = font; 77 } setFontSize(int size)78 void setFontSize(int size) { 79 m_fontSize = size; 80 } setBackgroundColor(const QColor & color)81 void setBackgroundColor(const QColor &color) { 82 m_backgroundColor = color; 83 } setTextEquivalent(const QString & text)84 void setTextEquivalent(const QString &text) { 85 m_textEquivalent = text; 86 } setOnAllTextLines(bool yes)87 void setOnAllTextLines(bool yes) { 88 m_onAllTextLines = yes; 89 } setAllowCrossReferences(bool yes)90 void setAllowCrossReferences(bool yes) { 91 m_allowCrossReferences = yes; 92 } setParentTag(Tag * tag)93 void setParentTag(Tag *tag) { 94 m_parentTag = tag; 95 } 96 /// GET PROPERTIES: id()97 QString id() const { 98 return m_id; 99 } name()100 QString name() const { 101 return m_name; 102 } emblem()103 QString emblem() const { 104 return m_emblem; 105 } bold()106 bool bold() const { 107 return m_bold; 108 } italic()109 bool italic() const { 110 return m_italic; 111 } underline()112 bool underline() const { 113 return m_underline; 114 } strikeOut()115 bool strikeOut() const { 116 return m_strikeOut; 117 } textColor()118 QColor textColor() const { 119 return m_textColor; 120 } fontName()121 QString fontName() const { 122 return m_fontName; 123 } fontSize()124 int fontSize() const { 125 return m_fontSize; 126 } backgroundColor()127 QColor backgroundColor() const { 128 return m_backgroundColor; 129 } textEquivalent()130 QString textEquivalent() const { 131 return m_textEquivalent; 132 } onAllTextLines()133 bool onAllTextLines() const { 134 return m_onAllTextLines; 135 } allowCrossReferences()136 bool allowCrossReferences() const { 137 return m_allowCrossReferences; 138 } parentTag()139 Tag* parentTag() const { 140 return m_parentTag; 141 } 142 /// HELPING FUNCTIONS: 143 State *nextState(bool cycle = true); 144 QString fullName(); 145 QFont font(QFont base); 146 QString toCSS(const QString &gradientFolderPath, const QString &gradientFolderName, const QFont &baseFont); 147 static void merge(const List &states, State *result, int *emblemsCount, bool *haveInvisibleTags, const QColor &backgroundColor); 148 void copyTo(State *other); 149 private: 150 /// PROPERTIES: 151 QString m_id; 152 QString m_name; 153 QString m_emblem; 154 bool m_bold; 155 bool m_italic; 156 bool m_underline; 157 bool m_strikeOut; 158 QColor m_textColor; 159 QString m_fontName; 160 int m_fontSize; 161 QColor m_backgroundColor; 162 QString m_textEquivalent; 163 bool m_onAllTextLines; 164 bool m_allowCrossReferences; 165 Tag *m_parentTag; 166 }; 167 168 /** A Tag is a category of Notes. 169 * A Note can have 0, 1 or more Tags. 170 * A Tag can have a unique State or several States. 171 * @author Sébastien Laoût 172 */ 173 class Tag 174 { 175 public: 176 /// LIST OF ALL TAGS IN THE APPLICATION: 177 typedef QList<Tag*> List; 178 static Tag::List all; 179 static State* stateForId(const QString &id); 180 static Tag* tagForKAction(QAction *action); 181 static Tag* tagSimilarTo(Tag *tagToTest); 182 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. 183 static void saveTags(); 184 static void saveTagsTo(QList<Tag*> &list, const QString &fullPath); 185 static void createDefaultTagsSet(const QString &file); 186 static long getNextStateUid(); 187 private: 188 static long nextStateUid; 189 190 public: 191 /// CONSTRUCTOR AND DESTRUCTOR: 192 Tag(/*State *firstState, const QString &name, bool inheritedBySiblings*/); 193 ~Tag(); 194 /// SET PROPERTIES: 195 void setName(const QString &name); setShortcut(const QKeySequence & shortcut)196 void setShortcut(const QKeySequence &shortcut) { 197 m_action->setShortcut(shortcut); 198 } setInheritedBySiblings(bool inherited)199 void setInheritedBySiblings(bool inherited) { 200 m_inheritedBySiblings = inherited; 201 } appendState(State * state)202 void appendState(State *state) { 203 m_states.append(state); state->setParentTag(this); 204 } removeState(State * state)205 void removeState(State *state) { 206 m_states.removeOne(state); state->setParentTag(0); 207 } 208 /// GET PROPERTIES: name()209 QString name() const { 210 return m_name; 211 } shortcut()212 QKeySequence shortcut() const { 213 return m_action->shortcut(); 214 } inheritedBySiblings()215 bool inheritedBySiblings() const { 216 return m_inheritedBySiblings; 217 } states()218 State::List& states() const { 219 return (State::List&)m_states; 220 } countStates()221 int countStates() const { 222 return m_states.count(); 223 } 224 void copyTo(Tag *other); 225 private: 226 /// PROPERTIES: 227 QString m_name; 228 QAction *m_action; 229 bool m_inheritedBySiblings; 230 State::List m_states; 231 }; 232 233 #include <qicon.h> 234 #include <qstring.h> 235 236 /** An action that represents a State or a Tag 237 * @author Kelvie Wong 238 * Based off of StateMenuItem by Sébastien Laoût 239 */ 240 class StateAction : public KToggleAction 241 { 242 Q_OBJECT 243 Q_DISABLE_COPY(StateAction); 244 public: 245 StateAction(State *state, 246 const QKeySequence &shortcut, 247 QWidget * parent, 248 bool withTagName = false); 249 250 ~StateAction(); 251 private: 252 State *m_state; 253 QString m_name; 254 QString m_shortcut; 255 }; 256 257 #endif // TAG_H 258