Ran qt3to4
[basket4.git] / src / note.h
blob25aad3c24eabd83fd6cac05311c541bc98d5aef8
1 /***************************************************************************
2 * Copyright (C) 2003 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 NOTE_H
22 #define NOTE_H
24 #include <qstring.h>
25 #include <qpixmap.h>
26 //Added by qt3to4:
27 #include <Q3ValueList>
28 #include <kpixmap.h>
29 #include <qdatetime.h>
31 #include "notecontent.h"
32 #include "tag.h"
34 class Basket;
35 class FilterData;
36 class HtmlExportData;
38 class NoteSelection;
40 class QPainter;
41 class Q3SimpleRichText;
43 /** Handle basket notes and groups!\n
44 * After creation, the note is a group. You should create a NoteContent with this Note
45 * as constructor parameter to transform it to a note with content. eg:
46 * @code
47 * Note *note = new Note(basket); // note is a group!
48 * new TextContent(note, fileName); // note is now a note with a text content!
49 * new ColorContent(note, Qt::red); // Should never be done!!!!! the old Content should be deleted...
50 * @endcode
51 * @author S�astien Laot
53 class Note
55 /// CONSTRUCTOR AND DESTRUCTOR:
56 public:
57 Note(Basket *parent);
58 ~Note();
60 /// DOUBLY LINKED LIST:
61 private:
62 Note *m_prev;
63 Note *m_next;
64 public:
65 inline void setNext(Note *next) { m_next = next; }
66 inline void setPrev(Note *prev) { m_prev = prev; }
67 inline Note* next() { return m_next; }
68 inline Note* prev() { return m_prev; }
70 /// GEOMETRY MANAGEMENT:
71 private:
72 int m_x;
73 int m_y;
74 int m_width;
75 int m_height;
76 // int m_minContentWidth;
77 public:
78 void setWidth(int width);
79 void setWidthForceRelayout(int width);
80 void setInitialHeight(int height) { m_height = height; } /// << Do NEVER use it unless you know what you do!
81 void setX(int x);
82 void setY(int y);
83 void setXRecursivly(int x);
84 void setYRecursivly(int y);
85 inline int x() { return m_x; }
86 inline int y() { return m_y; }
87 inline int width() { return (isGroup() ? (isColumn() ? 0 : GROUP_WIDTH) : m_width); }
88 inline int height() { return m_height; }
89 inline int bottom() { return m_y + m_height - 1; }
90 QRect rect();
91 QRect resizerRect();
92 QRect visibleRect();
93 void relayoutAt(int x, int y, bool animate);
94 int contentX();
95 int minWidth();
96 int minRight();
97 void unsetWidth();
98 void requestRelayout();
99 void setHeight(int height) { m_height = height; } /// << DO NEVER USE IT!!! Only available when moving notes, groups should be recreated with the exact same state as before!
101 /// FREE AND COLUMN LAYOUTS MANAGEMENT:
102 private:
103 int m_groupWidth;
104 public:
105 int groupWidth();
106 void setGroupWidth(int width);
107 int rightLimit();
108 int finalRightLimit();
109 bool isFree();
110 bool isColumn();
111 bool hasResizer();
112 int resizerHeight();
114 /// GROUPS MANAGEMENT:
115 private:
116 bool m_isFolded;
117 Note *m_firstChild;
118 Note *m_parentNote;
119 public:
120 inline bool isGroup() { return m_content == 0L; }
121 inline bool isFolded() { return m_isFolded; }
122 inline Note* firstChild() { return m_firstChild; }
123 inline Note* parentNote() { return m_parentNote; }
124 /*inline*/ bool showSubNotes();// { return !m_isFolded || !m_collapseFinished; }
125 inline void setParentNote(Note *note) { m_parentNote = note; }
126 inline void setFirstChild(Note *note) { m_firstChild = note; }
127 bool isShown();
128 void toggleFolded(bool animate);
129 Note* noteAt(int x, int y);
130 Note* firstRealChild();
131 Note* lastRealChild();
132 Note* lastChild();
133 Note* lastSibling();
134 int yExpander();
135 bool isAfter(Note *note);
136 bool contains(Note *note);
138 /// NOTES VARIOUS PROPERTIES: // CONTENT MANAGEMENT?
139 private:
140 Basket *m_basket;
141 NoteContent *m_content;
142 QDateTime m_addedDate;
143 QDateTime m_lastModificationDate;
144 public:
145 inline Basket* basket() { return m_basket; }
146 inline NoteContent* content() { return m_content; }
147 inline void setAddedDate(const QDateTime &dateTime) { m_addedDate = dateTime; }
148 inline void setLastModificationDate(const QDateTime &dateTime) { m_lastModificationDate = dateTime; }
149 inline void setParentBasket(Basket *basket) { m_basket = basket; }
150 QDateTime addedDate() { return m_addedDate; }
151 QDateTime lastModificationDate() { return m_lastModificationDate; }
152 QString addedStringDate();
153 QString lastModificationStringDate();
154 QString toText(const QString &cuttedFullPath);
155 bool saveAgain();
156 void deleteChilds();
158 protected:
159 void setContent(NoteContent *content);
160 friend class NoteContent;
161 friend class AnimationContent;
163 /// DRAWING:
164 private:
165 QPixmap m_bufferedPixmap;
166 KPixmap m_bufferedSelectionPixmap;
167 public:
168 void draw(QPainter *painter, const QRect &clipRect);
169 void drawBufferOnScreen(QPainter *painter, const QPixmap &contentPixmap);
170 static void getGradientColors(const QColor &originalBackground, QColor *colorTop, QColor *colorBottom);
171 static void drawExpander(QPainter *painter, int x, int y, const QColor &background, bool expand, Basket *basket);
172 void drawHandle( QPainter *painter, int x, int y, int width, int height, const QColor &background, const QColor &foreground);
173 void drawResizer( QPainter *painter, int x, int y, int width, int height, const QColor &background, const QColor &foreground, bool rounded);
174 void drawRoundings(QPainter *painter, int x, int y, int type, int width = 0, int height = 0);
175 void unbufferizeAll();
176 void bufferizeSelectionPixmap();
177 inline void unbufferize() { m_bufferedPixmap.resize(0, 0); m_bufferedSelectionPixmap.resize(0, 0); }
178 inline bool isBufferized() { return !m_bufferedPixmap.isNull(); }
179 void recomputeBlankRects(Q3ValueList<QRect> &blankAreas);
180 static void drawInactiveResizer(QPainter *painter, int x, int y, int height, const QColor &background, bool column);
182 /// VISIBLE AREAS COMPUTATION:
183 private:
184 Q3ValueList<QRect> m_areas;
185 bool m_computedAreas;
186 bool m_onTop;
187 void recomputeAreas();
188 bool recomputeAreas(Note *note, bool noteIsAfterThis);
189 public:
190 void setOnTop(bool onTop);
191 inline bool isOnTop() { return m_onTop; }
192 bool isEditing();
194 /// MANAGE ANIMATION:
195 private:
196 int m_deltaX;
197 int m_deltaY;
198 int m_deltaHeight;
199 bool m_collapseFinished;
200 bool m_expandingFinished;
201 public:
202 inline int deltaX() { return m_deltaX; }
203 inline int deltaY() { return m_deltaY; }
204 inline int deltaHeight() { return m_deltaHeight; }
205 inline int finalX() { return m_x + m_deltaX; }
206 inline int finalY() { return m_y + m_deltaY; }
207 inline int finalHeight() { return m_height + m_deltaHeight; }
208 inline int finalBottom() { return finalY() + finalHeight() - 1; }
209 inline void cancelAnimation() { m_deltaX = 0; m_deltaY = 0; m_deltaHeight = 0; }
210 inline bool expandingOrCollapsing() { return !m_collapseFinished || !m_expandingFinished; }
211 void addAnimation(int deltaX, int deltaY, int deltaHeight = 0);
212 void setFinalPosition(int x, int y); /// << Convenient method for addAnimation()
213 bool advance();
214 void initAnimationLoad();
215 void setRecursivelyUnder(Note *under, bool animate);
217 /// USER INTERACTION:
218 public:
219 enum Zone { None = 0,
220 Handle, TagsArrow, Custom0, /*CustomContent1, CustomContent2, */Content, Link,
221 TopInsert, TopGroup, BottomInsert, BottomGroup, BottomColumn,
222 Resizer,
223 Group, GroupExpander,
224 Emblem0 }; // Emblem0 should be at end, because we add 1 to get Emblem1, 2 to get Emblem2...
225 inline void setHovered(bool hovered) { m_hovered = hovered; unbufferize(); }
226 void setHoveredZone(Zone zone);
227 inline bool hovered() { return m_hovered; }
228 inline Zone hoveredZone() { return m_hoveredZone; }
229 Zone zoneAt(const QPoint &pos, bool toAdd = false);
230 QRect zoneRect(Zone zone, const QPoint &pos);
231 void setCursor(Zone zone);
232 QString linkAt(const QPoint &pos);
233 private:
234 bool m_hovered;
235 Zone m_hoveredZone;
237 /// SELECTION:
238 public:
239 NoteSelection* selectedNotes();
240 void setSelected(bool selected);
241 void setSelectedRecursivly(bool selected);
242 void invertSelectionRecursivly();
243 void selectIn(const QRect &rect, bool invertSelection, bool unselectOthers = true);
244 void setFocused(bool focused);
245 inline bool isFocused() { return m_focused; }
246 inline bool isSelected() { return m_selected; }
247 bool allSelected();
248 void resetWasInLastSelectionRect();
249 void unselectAllBut(Note *toSelect);
250 void invertSelectionOf(Note *toSelect);
251 Note* theSelectedNote();
252 private:
253 bool m_focused;
254 bool m_selected;
255 bool m_wasInLastSelectionRect;
257 /// TAGS:
258 private:
259 State::List m_states;
260 State m_computedState;
261 int m_emblemsCount;
262 bool m_haveInvisibleTags;
263 public:
264 /*const */State::List& states() const;
265 inline int emblemsCount() { return m_emblemsCount; }
266 void addState(State *state, bool orReplace = true);
267 void addTag(Tag *tag);
268 void removeState(State *state);
269 void removeTag(Tag *tag);
270 void removeAllTags();
271 void addTagToSelectedNotes(Tag *tag);
272 void removeTagFromSelectedNotes(Tag *tag);
273 void removeAllTagsFromSelectedNotes();
274 void addStateToSelectedNotes(State *state, bool orReplace = true);
275 void changeStateOfSelectedNotes(State *state);
276 bool selectedNotesHaveTags();
277 void inheritTagsOf(Note *note);
278 bool hasTag(Tag *tag);
279 bool hasState(State *state);
280 State* stateOfTag(Tag *tag);
281 State* stateForEmblemNumber(int number);
282 bool stateForTagFromSelectedNotes(Tag *tag, State **state);
283 void recomputeStyle();
284 void recomputeAllStyles();
285 bool removedStates(const Q3ValueList<State*> &deletedStates);
286 QFont font(); // Computed!
287 QColor backgroundColor(); // Computed!
288 QColor textColor(); // Computed!
290 /// FILTERING:
291 private:
292 bool m_matching;
293 public:
294 bool computeMatching(const FilterData &data);
295 int newFilter(const FilterData &data);
296 bool matching() { return m_matching; }
298 /// ADDED:
299 public:
300 void deleteSelectedNotes(bool deleteFilesToo = true);
301 int count();
302 int countDirectChilds();
304 QString fullPath();
305 Note* noteForFullPath(const QString &path);
307 void update();
308 void linkLookChanged();
310 void usedStates(Q3ValueList<State*> &states);
312 void listUsedTags(Q3ValueList<Tag*> &list);
315 Note* nextInStack();
316 Note* prevInStack();
317 Note* nextShownInStack();
318 Note* prevShownInStack();
320 Note* parentPrimaryNote(); // TODO: There are places in the code where this methods is hand-copied / hand-inlined instead of called.
322 Note* firstSelected();
323 Note* lastSelected();
324 Note* selectedGroup();
325 void groupIn(Note *group);
327 bool tryExpandParent();
328 bool tryFoldParent();
330 int distanceOnLeftRight(Note *note, int side);
331 int distanceOnTopBottom(Note *note, int side);
333 bool convertTexts();
335 void debug();
337 /// SPEED OPTIMIZATION
338 public:
339 void finishLazyLoad();
341 public:
342 // Values are provided here as info:
343 // Please see Settings::setBigNotes() to know whats values are assigned.
344 static int NOTE_MARGIN /*= 2*/;
345 static int INSERTION_HEIGHT /*= 5*/;
346 static int EXPANDER_WIDTH /*= 9*/;
347 static int EXPANDER_HEIGHT /*= 9*/;
348 static int GROUP_WIDTH /*= 2*NOTE_MARGIN + EXPANDER_WIDTH*/;
349 static int HANDLE_WIDTH /*= GROUP_WIDTH*/;
350 static int RESIZER_WIDTH /*= GROUP_WIDTH*/;
351 static int TAG_ARROW_WIDTH /*= 5*/;
352 static int EMBLEM_SIZE /*= 16*/;
353 static int MIN_HEIGHT /*= 2*NOTE_MARGIN + EMBLEM_SIZE*/;
356 /*class InsertionData
358 public:
359 enum Type { Free = 0, NoteRelative, ColumnBottom };
360 Type type;
362 InsertionData(int _x, int _y)
363 : type(Free),
364 x(_x), y(_y),
365 note(0), group(false), onTop(false),
366 column(0)
368 int x;
369 int y;
371 InsertionData(Note *_note, bool _group, bool _onTop)
372 : type(NoteRelative),
373 x(0), y(0),
374 note(_note), group(_group), onTop(_onTop),
375 column(0)
377 Note *note;
378 bool group;
379 bool onTop;
381 InsertionData(Note *_column)
382 : type(NoteRelative),
383 x(0), y(0),
384 note(0), group(false), onTop(false),
385 column(_column)
387 Note *column;
388 };*/
390 #endif // NOTE_H