KGanttItem.h
00001 #ifndef _KGANTTITEM_H_ 00002 #define _KGANTTITEM_H_ 00003 00004 /* 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 00021 author : jh, jochen@ifb.bv.tu-berlin.de 00022 00023 file : KGanttItem.h 00024 date : 26 oct 2000 00025 00026 00027 changelog : 26 dec 2000, jh 00028 09 jan 2001, jh - added signal destroyed(xTQTask*) 00029 00030 11 jan 2001, jh changed to kde : xTQTask -> KGanttItem 00031 00032 */ 00033 00034 00035 #include <tqobject.h> 00036 #include <tqdatetime.h> 00037 #include <tqtextstream.h> 00038 #include <tqptrlist.h> 00039 #include <tqpainter.h> 00040 00041 #include <kdepimmacros.h> 00042 00043 #include "KGanttRelation.h" 00044 00045 00046 00048 00053 00054 class KDE_EXPORT KGanttItem : public TQObject 00056 { 00057 00058 Q_OBJECT 00059 TQ_OBJECT 00060 00061 00062 public: 00063 00064 enum Change { 00065 NoChange = 0, 00066 StartChanged = 1, 00067 EndChanged = 2, 00068 00071 HeightChanged = 4, 00072 00077 TotalHeightChanged = 8, 00078 00080 StyleChanged = 16, 00081 TextChanged = 32, 00082 ModeChanged = 64, 00083 MinChanged = 128, 00084 MaxChanged = 256, 00085 00087 Opened = 512, 00088 00090 Closed = 1024, 00091 00093 Selected = 2048, 00094 00096 Unselected = 4096, 00097 00099 Unknown = 8192, 00100 00102 RelationAdded = 16384, 00103 00105 RelationRemoved = 32768 00106 00107 }; 00108 00109 00110 00111 enum Style { 00113 DrawNothing = 0, 00114 00116 DrawBorder = 1, 00117 00118 // Fill item with brush. 00119 DrawFilled = 2, 00120 DrawText = 4, 00121 00122 // Draw handlke for opening/closing item. 00123 DrawHandle = 16, 00124 00126 DrawHandleWSubitems = 32, 00127 00128 DrawAll = 255 00129 }; 00130 00131 00132 enum Mode { 00133 Normal, 00134 Rubberband 00135 }; 00136 00137 00139 00142 KGanttItem(KGanttItem* parentItem, const TQString& text, 00143 const TQDateTime& start, const TQDateTime& end); 00144 00145 00146 00148 00151 KGanttItem(KGanttItem* parentItem, const TQString& text, 00152 const TQDateTime& start, long durationMin); 00153 00154 00155 00157 /* 00158 * Emits signal destroyed(KGanttItem* this). 00159 */ 00160 ~KGanttItem(); 00161 00162 00163 00165 /* 00166 * 00167 */ 00168 KGanttRelation* addRelation(KGanttItem* from, KGanttItem* to, 00169 const TQString& text); 00170 00171 00172 00173 00175 00178 bool isOpen() { 00179 return _open; 00180 } 00181 00182 00183 00185 00188 void open(bool f); 00189 00190 00191 00193 00199 void setEditable(bool f) { 00200 _editable = f; 00201 } 00202 00203 00204 00206 00209 bool isEditable() { 00210 return _editable; 00211 } 00212 00213 00214 00216 00219 bool isSelected() { 00220 return _selected; 00221 } 00222 00223 00224 00226 00229 void select(bool f); 00230 00231 00232 00234 00240 void setMode(Mode flag); 00241 00242 00243 00245 00248 void setStyle(int flag, bool includeSubitems = false); 00249 00250 00251 00253 00256 int getStyle() { 00257 return _style; 00258 } 00259 00260 00261 00263 00266 void setBrush(const TQBrush& brush); 00267 00268 00269 00271 00274 TQBrush& getBrush() { 00275 return _brush; 00276 } 00277 00278 00279 00281 00284 TQBrush& getSelectBrush() { 00285 return _selectBrush; 00286 } 00287 00288 00289 00291 00294 void setPen(const TQPen& pen); 00295 00296 00297 00299 00302 TQPen& getPen() { 00303 return _pen; 00304 } 00305 00306 00307 00309 00312 void setTextPen(const TQPen& pen) { 00313 _textPen = pen; 00314 } 00315 00316 00317 00319 00322 TQPen& getTextPen() { 00323 return _textPen; 00324 } 00325 00326 00327 00329 00332 void setText(const TQString& text); 00333 00334 00335 00337 00340 TQString getText() { return _text; } 00341 00342 00343 00345 00350 TQDateTime getStart(); 00351 00352 00353 00355 00358 TQDateTime getEnd(); 00359 00360 00361 00363 00366 void setStart(const TQDateTime& start); 00367 00368 00369 00371 00374 void setEnd(const TQDateTime& end); 00375 00376 00377 00379 00383 void setHeight(int h); 00384 00385 00386 00388 00393 int getHeight() { 00394 return _height; 00395 } 00396 00397 00398 00400 00405 int getTotalHeight(); 00406 00407 00408 00410 00413 int getWidth(); 00414 00415 00416 00418 00421 TQPtrList<KGanttItem>& getSubItems() { 00422 return _subitems; 00423 } 00424 00425 00426 00428 00431 TQPtrList<KGanttRelation>& getRelations() { 00432 return _relations; 00433 } 00434 00435 00436 00438 00441 void startTransaction(){ 00442 blockSignals(true); 00443 } 00444 00445 00446 00448 00453 void endTransaction(); 00454 00455 00456 00458 00461 static TQString ChangeAsString(Change c); 00462 00463 00464 00465 00467 00470 void dump(TQTextOStream& cout, const TQString& pre); 00471 00472 00473 signals: 00474 00476 00480 void changed(KGanttItem*, KGanttItem::Change); 00481 00482 00483 00485 00489 void destroyed(KGanttItem*); 00490 00491 00492 00493 private slots: 00494 00495 void subItemChanged(KGanttItem*, KGanttItem::Change); 00496 00497 void removeRelation(KGanttRelation* rel); 00498 00499 00500 private: 00501 00502 void registerItem(KGanttItem* item); 00503 void unregisterItem(KGanttItem* item); 00504 00505 void init(KGanttItem* parentItem, const TQString& text, 00506 const TQDateTime& start, const TQDateTime& end); 00507 00508 00509 // set min/max date and time according to subitems 00510 Change adjustMinMax(); 00511 00512 /* if min < start set start to _min, 00513 if max > end set end to max */ 00514 Change adjustStartEnd(); 00515 00516 00517 // is item open/closed 00518 bool _open; 00519 bool _selected; 00520 00521 00522 // is this item editable by the user, if it is false, invoking 00523 // of some methods has no effect 00524 bool _editable; 00525 00526 int _height, _style, _mode; 00527 00528 00529 KGanttItem* _parentItem; 00530 TQPtrList<KGanttItem> _subitems; 00531 TQPtrList<KGanttRelation> _relations; 00532 00533 00534 // start/end date. 00535 // start must always be earlier then _minDateTime 00536 // end must always be later then _maxDateTime 00537 TQDateTime _start, _end, _minDateTime, _maxDateTime; 00538 00539 TQString _text; 00540 00541 TQBrush _brush; 00542 TQPen _pen, _textPen; 00543 00544 static TQBrush _selectBrush; 00545 00546 00547 }; 00548 00549 #endif