1 /***************************************************************************
2 * Copyright (C) 2005 by S�astien Laot *
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. *
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. *
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 ***************************************************************************/
27 #include <q3valuelist.h>
30 #include <kshortcut.h>
37 * @author S�astien Laot
43 typedef Q3ValueList
<State
*> List
;
46 /// CONSTRUCTOR AND DESTRUCTOR:
47 State(const QString
&id
= QString(), Tag
*tag
= 0);
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
; }
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);
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
);
98 QColor m_backgroundColor
;
99 QString m_textEquivalent
;
100 bool m_onAllTextLines
;
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
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();
124 static long nextStateUid
;
127 /// CONSTRUCTOR AND DESTRUCTOR:
128 Tag(/*State *firstState, const QString &name, bool inheritedBySiblings*/);
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); }
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
);
147 bool m_inheritedBySiblings
;
148 State::List m_states
;
152 #include <qmenudata.h>
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
166 IndentedMenuItem(const QString
&text
, const QString
&icon
= "", const QString
&shortcut
= "");
168 void paint(QPainter
*painter
, const QColorGroup
&cg
, bool active
, bool enabled
, int x
, int y
, int w
, int h
);
170 bool fullSpan() { return true; }
177 /** A menu item representing a State or a Tag.
178 * @author S�astien Laot
180 class StateMenuItem
: public QCustomMenuItem
183 StateMenuItem(State
*state
, const QString
&shortcut
, bool withTagName
= false);
185 void paint(QPainter
*painter
, const QColorGroup
&cg
, bool active
, bool enabled
, int x
, int y
, int w
, int h
);
187 bool fullSpan() { return true; }
193 static QIcon
checkBoxIconSet(bool checked
, QColorGroup cg
);
194 static QIcon
radioButtonIconSet(bool checked
, QColorGroup cg
);
195 static int iconMargin() { return 5; }