1 /***************************************************************************
2 * Copyright (C) 2003 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>
29 #include <qdatetime.h>
31 #include "notecontent.h"
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:
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...
51 * @author S�astien Laot
55 /// CONSTRUCTOR AND DESTRUCTOR:
60 /// DOUBLY LINKED LIST:
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:
76 // int m_minContentWidth;
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!
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; }
93 void relayoutAt(int x
, int y
, bool animate
);
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:
106 void setGroupWidth(int width
);
108 int finalRightLimit();
114 /// GROUPS MANAGEMENT:
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
; }
128 void toggleFolded(bool animate
);
129 Note
* noteAt(int x
, int y
);
130 Note
* firstRealChild();
131 Note
* lastRealChild();
135 bool isAfter(Note
*note
);
136 bool contains(Note
*note
);
138 /// NOTES VARIOUS PROPERTIES: // CONTENT MANAGEMENT?
141 NoteContent
*m_content
;
142 QDateTime m_addedDate
;
143 QDateTime m_lastModificationDate
;
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
);
159 void setContent(NoteContent
*content
);
160 friend class NoteContent
;
161 friend class AnimationContent
;
165 QPixmap m_bufferedPixmap
;
166 KPixmap m_bufferedSelectionPixmap
;
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:
184 Q3ValueList
<QRect
> m_areas
;
185 bool m_computedAreas
;
187 void recomputeAreas();
188 bool recomputeAreas(Note
*note
, bool noteIsAfterThis
);
190 void setOnTop(bool onTop
);
191 inline bool isOnTop() { return m_onTop
; }
194 /// MANAGE ANIMATION:
199 bool m_collapseFinished
;
200 bool m_expandingFinished
;
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()
214 void initAnimationLoad();
215 void setRecursivelyUnder(Note
*under
, bool animate
);
217 /// USER INTERACTION:
219 enum Zone
{ None
= 0,
220 Handle
, TagsArrow
, Custom0
, /*CustomContent1, CustomContent2, */Content
, Link
,
221 TopInsert
, TopGroup
, BottomInsert
, BottomGroup
, BottomColumn
,
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
);
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
; }
248 void resetWasInLastSelectionRect();
249 void unselectAllBut(Note
*toSelect
);
250 void invertSelectionOf(Note
*toSelect
);
251 Note
* theSelectedNote();
255 bool m_wasInLastSelectionRect
;
259 State::List m_states
;
260 State m_computedState
;
262 bool m_haveInvisibleTags
;
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!
294 bool computeMatching(const FilterData
&data
);
295 int newFilter(const FilterData
&data
);
296 bool matching() { return m_matching
; }
300 void deleteSelectedNotes(bool deleteFilesToo
= true);
302 int countDirectChilds();
305 Note
* noteForFullPath(const QString
&path
);
308 void linkLookChanged();
310 void usedStates(Q3ValueList
<State
*> &states
);
312 void listUsedTags(Q3ValueList
<Tag
*> &list
);
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
);
337 /// SPEED OPTIMIZATION
339 void finishLazyLoad();
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
359 enum Type { Free = 0, NoteRelative, ColumnBottom };
362 InsertionData(int _x, int _y)
365 note(0), group(false), onTop(false),
371 InsertionData(Note *_note, bool _group, bool _onTop)
372 : type(NoteRelative),
374 note(_note), group(_group), onTop(_onTop),
381 InsertionData(Note *_column)
382 : type(NoteRelative),
384 note(0), group(false), onTop(false),