From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kgantt/AUTHORS | 1 + kgantt/COPYING | 341 +++++++ kgantt/Makefile.am | 5 + kgantt/README | 9 + kgantt/TODO | 1 + kgantt/kgantt/KGantt.cpp | 98 ++ kgantt/kgantt/KGantt.h | 318 +++++++ kgantt/kgantt/KGanttBarConfig.cpp | 32 + kgantt/kgantt/KGanttBarConfig.h | 58 ++ kgantt/kgantt/KGanttItem.cpp | 621 ++++++++++++ kgantt/kgantt/KGanttItem.h | 548 +++++++++++ kgantt/kgantt/KGanttRelation.cpp | 168 ++++ kgantt/kgantt/KGanttRelation.h | 256 +++++ kgantt/kgantt/Makefile.am | 24 + kgantt/kgantt/close.xpm | 72 ++ kgantt/kgantt/itemedit.ui | 612 ++++++++++++ kgantt/kgantt/itemedit2.ui | 329 +++++++ kgantt/kgantt/lupe.xpm | 62 ++ kgantt/kgantt/open.xpm | 69 ++ kgantt/kgantt/xQGanttBarView.cpp | 252 +++++ kgantt/kgantt/xQGanttBarView.h | 121 +++ kgantt/kgantt/xQGanttBarViewPort.cpp | 1101 ++++++++++++++++++++++ kgantt/kgantt/xQGanttBarViewPort.h | 352 +++++++ kgantt/kgantt/xQGanttBarViewPort_Events.cpp | 585 ++++++++++++ kgantt/kgantt/xQGanttListView.cpp | 75 ++ kgantt/kgantt/xQGanttListView.h | 107 +++ kgantt/kgantt/xQGanttListViewPort.cpp | 175 ++++ kgantt/kgantt/xQGanttListViewPort.h | 131 +++ kgantt/pixmaps/Makefile.am | 2 + kgantt/pixmaps/cr16-action-ganttSelect.png | Bin 0 -> 154 bytes kgantt/pixmaps/cr16-action-ganttSelecttask.png | Bin 0 -> 177 bytes kgantt/pixmaps/cr16-action-ganttUnselecttask.png | Bin 0 -> 181 bytes kgantt/pixmaps/cr22-action-ganttSelect.png | Bin 0 -> 178 bytes kgantt/pixmaps/cr22-action-ganttSelecttask.png | Bin 0 -> 206 bytes kgantt/pixmaps/cr22-action-ganttUnselecttask.png | Bin 0 -> 208 bytes kgantt/pixmaps/cr32-action-ganttSelect.png | Bin 0 -> 425 bytes kgantt/pixmaps/cr32-action-ganttSelecttask.png | Bin 0 -> 206 bytes kgantt/pixmaps/cr32-action-ganttUnselecttask.png | Bin 0 -> 208 bytes 38 files changed, 6525 insertions(+) create mode 100644 kgantt/AUTHORS create mode 100644 kgantt/COPYING create mode 100644 kgantt/Makefile.am create mode 100644 kgantt/README create mode 100644 kgantt/TODO create mode 100644 kgantt/kgantt/KGantt.cpp create mode 100644 kgantt/kgantt/KGantt.h create mode 100644 kgantt/kgantt/KGanttBarConfig.cpp create mode 100644 kgantt/kgantt/KGanttBarConfig.h create mode 100644 kgantt/kgantt/KGanttItem.cpp create mode 100644 kgantt/kgantt/KGanttItem.h create mode 100644 kgantt/kgantt/KGanttRelation.cpp create mode 100644 kgantt/kgantt/KGanttRelation.h create mode 100644 kgantt/kgantt/Makefile.am create mode 100644 kgantt/kgantt/close.xpm create mode 100644 kgantt/kgantt/itemedit.ui create mode 100644 kgantt/kgantt/itemedit2.ui create mode 100644 kgantt/kgantt/lupe.xpm create mode 100644 kgantt/kgantt/open.xpm create mode 100644 kgantt/kgantt/xQGanttBarView.cpp create mode 100644 kgantt/kgantt/xQGanttBarView.h create mode 100644 kgantt/kgantt/xQGanttBarViewPort.cpp create mode 100644 kgantt/kgantt/xQGanttBarViewPort.h create mode 100644 kgantt/kgantt/xQGanttBarViewPort_Events.cpp create mode 100644 kgantt/kgantt/xQGanttListView.cpp create mode 100644 kgantt/kgantt/xQGanttListView.h create mode 100644 kgantt/kgantt/xQGanttListViewPort.cpp create mode 100644 kgantt/kgantt/xQGanttListViewPort.h create mode 100644 kgantt/pixmaps/Makefile.am create mode 100644 kgantt/pixmaps/cr16-action-ganttSelect.png create mode 100644 kgantt/pixmaps/cr16-action-ganttSelecttask.png create mode 100644 kgantt/pixmaps/cr16-action-ganttUnselecttask.png create mode 100644 kgantt/pixmaps/cr22-action-ganttSelect.png create mode 100644 kgantt/pixmaps/cr22-action-ganttSelecttask.png create mode 100644 kgantt/pixmaps/cr22-action-ganttUnselecttask.png create mode 100644 kgantt/pixmaps/cr32-action-ganttSelect.png create mode 100644 kgantt/pixmaps/cr32-action-ganttSelecttask.png create mode 100644 kgantt/pixmaps/cr32-action-ganttUnselecttask.png (limited to 'kgantt') diff --git a/kgantt/AUTHORS b/kgantt/AUTHORS new file mode 100644 index 000000000..e99b4a8e3 --- /dev/null +++ b/kgantt/AUTHORS @@ -0,0 +1 @@ +Jochen Hanff diff --git a/kgantt/COPYING b/kgantt/COPYING new file mode 100644 index 000000000..54754ab4b --- /dev/null +++ b/kgantt/COPYING @@ -0,0 +1,341 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/kgantt/Makefile.am b/kgantt/Makefile.am new file mode 100644 index 000000000..e08031435 --- /dev/null +++ b/kgantt/Makefile.am @@ -0,0 +1,5 @@ +SUBDIRS = kgantt pixmaps + +EXTRA_DIST = AUTHORS COPYING ChangeLog INSTALL README TODO + +include $(top_srcdir)/admin/Doxyfile.am diff --git a/kgantt/README b/kgantt/README new file mode 100644 index 000000000..35f254c5c --- /dev/null +++ b/kgantt/README @@ -0,0 +1,9 @@ +Note : + +16 jan 2001, jh + + shared libs result in strange behaviour of your kde-program, + (some icons are not shown correctly) so i recommend to + build libkgantt as a static library. everything works fine + with libkgantt.a + diff --git a/kgantt/TODO b/kgantt/TODO new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/kgantt/TODO @@ -0,0 +1 @@ + diff --git a/kgantt/kgantt/KGantt.cpp b/kgantt/kgantt/KGantt.cpp new file mode 100644 index 000000000..6e2c01c0a --- /dev/null +++ b/kgantt/kgantt/KGantt.cpp @@ -0,0 +1,98 @@ +// +// file : KGantt.C +// date : 26 oct 2000 +// changed : 10 jan 2001 +// author : jh +// + + +#include "KGantt.h" + + +#include +#include +#include + + +KGantt::KGantt(KGanttItem* toplevelitem, + QWidget* parent, const char * name, WFlags f) + : QWidget(parent,name,f) +{ +#ifdef _DEBUG_ + printf("KGantt::KGantt()\n"); +#endif + + if(toplevelitem == 0) { + _toplevelitem = new KGanttItem(0, "toplevelitem", + QDateTime::currentDateTime(), + QDateTime::currentDateTime() ); + _toplevelitem->setMode(KGanttItem::Rubberband); + _deleteItem = true; + } + else { + _toplevelitem = toplevelitem; + _deleteItem = false; + } + + setBackgroundColor(QColor(white)); + + _splitter = new QSplitter(this); +/* +// QStyle *cdestyle=QStyleFactory::create("CDE"); +// if(cdestyle) +// _splitter->setStyle(cdestyle); +*/ + QPalette pal1(_splitter->palette()); +/* QPalette pal(_splitter->palette()); + QColorGroup cg(pal.active()); + cg.setColor( QColorGroup::Foreground, blue ); + cg.setColor( QColorGroup::Background, white ); + pal.setActive( cg ); + + _splitter->setPalette(pal);*/ + + _ganttlist = new xQGanttListView(_toplevelitem, _splitter); + _ganttlist->setMinimumWidth(1); + _ganttlist->setPalette(pal1); + + _ganttbar = new xQGanttBarView(_toplevelitem, _splitter); + _ganttbar->setPalette(pal1); + + connect(_ganttbar, SIGNAL(contentsMoving(int,int)), + _ganttlist, SLOT(contentsMoved(int,int))); + + _ganttlist->setBarView(_ganttbar); + +} + + + +KGantt::~KGantt() +/////////////////// +{ + if(_deleteItem) + delete _toplevelitem; +} + + + + +void +KGantt::dumpItems() +///////////////////////// +{ + QTextOStream cout(stdout); + + cout << "\n\n"; + cout << " start : " << _toplevelitem->getStart().toString() << endl; + cout << " end : " << _toplevelitem->getEnd().toString() << endl; + + _toplevelitem->dump(cout, " "); + + cout << "\n\n"; + +} + + + +#include "KGantt.moc" diff --git a/kgantt/kgantt/KGantt.h b/kgantt/kgantt/KGantt.h new file mode 100644 index 000000000..90c3b86f9 --- /dev/null +++ b/kgantt/kgantt/KGantt.h @@ -0,0 +1,318 @@ +#ifndef _KGANTT_H_ +#define _KGANTT_H_ + +/* + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + author : jh, jochen@ifb.bv.tu-berlin.de + + file : KGantt.h + date : 26 oct 2000 + + + changelog : 23 nov 2000, jh + + 24 nov 2000, jh + + 10 jan 2001m jh, changed to KDE : + xQGantt -> KGantt + +*/ + + +#include +#include + +#include +#include + +#include "KGanttItem.h" +#include "xQGanttListView.h" +#include "xQGanttBarView.h" + + + +/** + * \mainpage KGantt Module
+ * + * The kgantt module contains several classes (KGanttItem, KGantt) + * for drawing and editing gantt-diagramms. + * + * This example shows how to use the gantt module: + * \code + * #include "kgantt/KGantt.h" + * + * int main(int args, char* argv[]) + * { + ... + + KGantt* gantt = new KGantt(0, mainwindow); + + KGanttItem* toplevel = gantt->getToplevelItem(); + + KGanttItem* t1 = new KGanttItem(toplevel, + "task 1, no subtasks", + QDateTime::currentDateTime().addDays(10), + QDateTime::currentDateTime().addDays(20) ); + + ... + + * } + * \endcode + * + * You just have to create an object of class KGantt and add several objects of + * class KGanttItem. + * + */ + + + +/// Gantt Widget. +/*! + * A gantt widget contains two parts, a list view and a + * bar view. + */ +//////////////////////////////// +class KDE_EXPORT KGantt : public QWidget +//////////////////////////////// +{ + + Q_OBJECT + + +public: + + + /// Constructor. + /*! + * + */ + KGantt(KGanttItem* toplevelitem = 0, + QWidget* parent = 0, const char * name=0, WFlags f=0 ); + + + /// Destructor. + /*! + * + */ + ~KGantt(); + + + + /// Set toplevel item. + /*! + * If no toplevel item was specified at construction of this widget a + * toplevel item was created. This will be deleted by setting a new + * toplevel item. A toplevel item that was passed to the constructor will + * not be deleted. + */ + void setToplevelItem(KGanttItem* item) { + if(_deleteItem) + delete _toplevelitem; + _toplevelitem = item; + } + + + + /// Get toplevel item. + /*! + * + */ + KGanttItem* getToplevelItem() { + return _toplevelitem; + } + + + + /// Get bar view of items. + /*! + * + */ + xQGanttBarView* barView() { + return _ganttbar; + } + + + + /// Get list view of items. + /*! + * + */ + xQGanttListView* listView() { + return _ganttlist; + } + + + + QSplitter* splitter() { + return _splitter; + } + + + + /// + /*! + * + */ + void zoom(double factor) { + barView()->viewport()->zoom(factor); + } + + + + /// Get popup menu. + /*! + * + */ + KPopupMenu* menu() { + return _ganttbar->viewport()->menu(); + } + + + + /// Add gantt toolbar to main window. + /*! + * If you want to embed a toolbar with specific actions + * like zooming or configuring the gantt, you can add a toolbar + * automatically by invoking this method. You have to pass your + * mainwindow as a parameter if you call this method the first + * time because teh toolbar will be created then. If you + * you want to access the pointer to a already created toolbar you + * can invoke this method without any parameter. + */ + KToolBar* toolbar(QMainWindow* mw = 0) { + return _ganttbar->viewport()->toolbar(mw); + } + + + + /// Print to stdout. + /* + * + */ + void dumpItems(); + + + + /// Get all selected items. + /*! + * All selected KGanttItems will be added to the passed list. + */ + void getSelectedItems(QPtrList& list) { + _ganttbar->viewport()->getSelectedItems(list); + } + + + + void addHoliday(int y, int m, int d) { + _ganttbar->viewport()->addHoliday(y,m,d); + } + + + + void removeHoliday(int y, int m, int d) { + _ganttbar->viewport()->addHoliday(y,m,d); + } + + + +public slots: + + + void setSelect() { + _ganttbar->viewport()->setSelect(); + } + + void setZoom() { + _ganttbar->viewport()->setZoom(); + } + + void setMove() { + _ganttbar->viewport()->setMove(); + } + + + void zoomIn() { + _ganttbar->viewport()->zoomIn(); + } + + void zoomOut() { + _ganttbar->viewport()->zoomOut(); + } + + void zoomAll() { + _ganttbar->viewport()->zoomAll(); + } + + void selectAll() { + _ganttbar->viewport()->selectAll(); + } + + void unselectAll() { + _ganttbar->viewport()->unselectAll(); + } + + void deleteSelectedItems() { + _ganttbar->viewport()->deleteSelectedItems(); + } + + void insertIntoSelectedItem() { + _ganttbar->viewport()->insertIntoSelectedItem(); + } + + + /// Show list view. + /*! + * + */ + void showList() { + _ganttlist->show(); + } + + + /// Hide list view. + /* + * + */ + void hideList() { + _ganttlist->hide(); + } + + +protected: + + + void resizeEvent(QResizeEvent* /*e*/) { + _splitter->resize(width(),height()); + }; + + +private: + + KGanttItem* _toplevelitem; + + QSplitter *_splitter; + + xQGanttBarView* _ganttbar; + xQGanttListView* _ganttlist; + + bool _deleteItem; + +}; + + +#endif diff --git a/kgantt/kgantt/KGanttBarConfig.cpp b/kgantt/kgantt/KGanttBarConfig.cpp new file mode 100644 index 000000000..d5faa208a --- /dev/null +++ b/kgantt/kgantt/KGanttBarConfig.cpp @@ -0,0 +1,32 @@ +// +// file : KGanttBarConfig.cpp +// date : 16 jan 2001 +// changed : +// author : jh +// + + +#include "KGanttBarConfig.h" +#include "xQGanttBarView.h" + +#include + + +KGanttBarConfig::KGanttBarConfig(xQGanttBarView* barview, + QWidget* parent, + const char * name, WFlags f) + : QWidget(parent,name,f) +{ + _barview = barview; + KColorButton* b = new KColorButton(this); + + connect(b, SIGNAL(changed(const QColor&)), + this, SLOT(changeBackground(const QColor&))); + +} + + +void KGanttBarConfig::changeBackground(const QColor& color) { + _barview->viewport()->setBackgroundColor(color); +} +#include "KGanttBarConfig.moc" diff --git a/kgantt/kgantt/KGanttBarConfig.h b/kgantt/kgantt/KGanttBarConfig.h new file mode 100644 index 000000000..5be04f72d --- /dev/null +++ b/kgantt/kgantt/KGanttBarConfig.h @@ -0,0 +1,58 @@ +#ifndef _KGANTTBARCONFIG_H_ +#define _KGANTTBARCONFIG_H_ + +/* + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + author : jh, jochen@ifb.bv.tu-berlin.de + + file : KGanttBarConfig.h + date : 16 jan 2001 + + + changelog : + +*/ + + +#include + +class xQGanttBarView; + + +class KGanttBarConfig : public QWidget +{ + + Q_OBJECT + +public: + + KGanttBarConfig(xQGanttBarView* barview, + QWidget* parent = 0, const char* name=0, WFlags f=0); + + +protected slots: + + void changeBackground(const QColor& color); + +protected: + + xQGanttBarView* _barview; + +}; + +#endif diff --git a/kgantt/kgantt/KGanttItem.cpp b/kgantt/kgantt/KGanttItem.cpp new file mode 100644 index 000000000..9b086ae58 --- /dev/null +++ b/kgantt/kgantt/KGanttItem.cpp @@ -0,0 +1,621 @@ +// +// file : KGanttItem.C +// date : 26 oct 2000 +// changed : 11 jan 2001 +// author : jh +// + + +#include "KGanttItem.h" + + +QBrush KGanttItem::_selectBrush(QColor(255,0,0)); + + +KGanttItem::KGanttItem(KGanttItem* parentItem, const QString& text, + const QDateTime& start, const QDateTime& end) + : QObject() +//////////////////////////////////////////////////////// +{ + init(parentItem,text, start,end); +} + + + +KGanttItem::KGanttItem(KGanttItem* parentItem, const QString& text, + const QDateTime& start, long durationMin) + : QObject() +//////////////////////////////////////////////////////// +{ + init(parentItem, text, start, start.addSecs( durationMin * 60)); +} + + + +void +KGanttItem::init(KGanttItem* parentItem, const QString& text, + const QDateTime& start, const QDateTime& end) +/////////////////////////////////////////////////////////////// +{ + _style = DrawAll - DrawHandle; + _open = true; + _selected = false; + _editable = true; + + _mode = Normal; + + _brush = QBrush(QColor(140,140,255)); + _pen = QPen(QColor(100,100,100)); + _textPen = QPen(QColor(black)); + + _height = 24; + + _text = text; + + _start = start; _minDateTime = start; + _end = end; _maxDateTime = end; + + _parentItem = parentItem; + + if(_parentItem) + _parentItem->registerItem(this); + +} + + + +KGanttItem::~KGanttItem() +///////////////// +{ +#ifdef _DEBUG_ + printf("-> delete %s \n", getText().latin1() ); +#endif + + if(_parentItem) + _parentItem->unregisterItem(this); + + _subitems.setAutoDelete(true); + _subitems.clear(); + + emit destroyed(this); + +#ifdef _DEBUG_ + printf("<- delete %s \n", getText().latin1() ); +#endif +} + + + +KGanttRelation* +KGanttItem::addRelation(KGanttItem* from, KGanttItem* to, + const QString& text) +{ + if(_subitems.containsRef(from) > 0 && _subitems.containsRef(to) >0) { + KGanttRelation* rel = new KGanttRelation(from,to,text); + _relations.append(rel); + + connect(rel, SIGNAL(destroyed(KGanttRelation*)), + this, SLOT(removeRelation(KGanttRelation*))); + + emit changed(this, RelationAdded); + return rel; + } + else + return NULL; +} + + + +void +KGanttItem::removeRelation(KGanttRelation* rel) +{ + if( _relations.removeRef(rel) ) + emit changed(this, RelationRemoved); +} + + + +void +KGanttItem::endTransaction() +/////////////////////////// +{ + blockSignals(false); + emit changed(this, Unknown); +} + + + +void +KGanttItem::registerItem(KGanttItem* item) +{ + _subitems.append(item); + + connect(item, SIGNAL(changed(KGanttItem*, KGanttItem::Change)), + this, SLOT(subItemChanged(KGanttItem*, KGanttItem::Change)) ); + + bool minChanged = false; + bool maxChanged = false; + + // update min/man + + if(_subitems.count() == 1) { + + _minDateTime = item->getStart(); + _maxDateTime = item->getEnd(); + + minChanged = true; + maxChanged = true; + + } + else { + + if(item->getEnd() > _maxDateTime) { + _maxDateTime = item->getEnd(); + maxChanged = true; + } + + if(_minDateTime > item->getStart()) { + _minDateTime = item->getStart(); + minChanged = true; + } + + } // else + + + // increase start/end if necessary + Change change = adjustStartEnd(); + + if(_mode == Rubberband) { + if(minChanged && !(change & StartChanged)) + change = (Change) (change + StartChanged); + if(maxChanged && !(change & EndChanged)) + change = (Change) (change + EndChanged); + } + + if( isOpen() ) { + if(!(change & TotalHeightChanged)) + change = (Change) (change + TotalHeightChanged); + } + + if(change != NoChange) + emit changed(this,change); + +} + + + +void +KGanttItem::unregisterItem(KGanttItem* item) +{ + _subitems.removeRef(item); + disconnect(item); + + Change change = adjustMinMax(); + + if( isOpen() ) { + if(!(change & TotalHeightChanged)) + change = (Change) (change + TotalHeightChanged); + } + + if(change != NoChange) + emit changed(this,change); + +} + + + +QDateTime +KGanttItem::getStart() +{ + if(_mode == Rubberband && _subitems.count()>0) + return _minDateTime; + else + return _start; +} + + + + +QDateTime +KGanttItem::getEnd() +///////////////// +{ + if(_mode == Rubberband && _subitems.count()>0) + return _maxDateTime; + else + return _end; +} + + + +void +KGanttItem::setStart(const QDateTime& start) +{ + if(!_editable) return; + + // if there are no subitems, just set _start and _minDateTime + if(_subitems.count()==0) { + + if(_start != start) { + _start = start; + _minDateTime = _start; + emit changed(this,StartChanged); + } + + } + else { + + // if there are subitems, just change start if + // mode is not 'rubberband' and start is less than _minDateTime + + if(_mode != Rubberband) { + + if(start < _minDateTime) + _start = start; + else + _start = _minDateTime; + + emit changed(this,StartChanged); + + } + + } + +} + + + +void +KGanttItem::setEnd(const QDateTime& end) +{ + if(!_editable) return; + + // if there are no subitems, just set _end and _maxDateTime + if(_subitems.count()==0) { + + if(_end != end) { + _end = end; + _maxDateTime = _end; + emit changed(this,EndChanged); + } + + } + else { + + // if there are subitems, just change end if + // mode is not 'rubberband' and end is greater than _maxDateTime + + if(_mode != Rubberband) { + + if(end > _maxDateTime) + _end = end; + else + _end = _maxDateTime; + + emit changed(this,EndChanged); + + } + + } + +} + + + + +KGanttItem::Change +KGanttItem::adjustStartEnd() +////////////////////////// +{ + // first update _min and _max of subitems + + Change c = adjustMinMax(); + + if(_start > _minDateTime) { + _start = _minDateTime; + if(!(c & StartChanged)) + c = (Change) (c + StartChanged); + } + + if(_end < _maxDateTime) { + _end = _maxDateTime; + if(!(c & EndChanged)) + c = (Change) (c + EndChanged); + } + + return c; + +} + + + +KGanttItem::Change +KGanttItem::adjustMinMax() +////////////////////////// +{ + // + // calculate _min and _max by + // traversing the subitems. if there are no subitems + // _min = start and _max = end. + // + + QDateTime min = _minDateTime; + QDateTime max = _maxDateTime; + Change c = NoChange; + + if(_subitems.count()==0) { + + _minDateTime = _start; + _maxDateTime = _end; + + if(min != _minDateTime) c = MinChanged; + if(max != _maxDateTime) c = (Change) (c + MaxChanged); + + } + else { + + // get min/max date and time + + KGanttItem* item = _subitems.first(); + + _minDateTime = item->getStart(); + _maxDateTime = item->getEnd(); + + item = _subitems.next(); + + for(; item != 0; item = _subitems.next() ) { + + if(_minDateTime > item->getStart()) { + _minDateTime = item->getStart(); + } + + if(item->getEnd() > _maxDateTime) { + _maxDateTime = item->getEnd(); + } + + } // for() + + + if(min != _minDateTime) c = MinChanged; + if(max != _maxDateTime) c = (Change) (c + MaxChanged); + + } + + return c; + +} + + + +void +KGanttItem::subItemChanged(KGanttItem* /*item*/, Change change) +///////////////////////////////////////////////////// +{ + if(change & StyleChanged) + emit changed(this, change); + + if( (change & Opened) || (change & Closed) || + (change & TotalHeightChanged) || (change & HeightChanged) ) + emit changed(this, TotalHeightChanged); + + if( (change & StartChanged) || + (change & EndChanged) ) { + + Change c = adjustStartEnd(); + + if(_mode == Rubberband) { + if(c & MinChanged && !(c & StartChanged)) + c = (Change) (c + StartChanged); + if(c & MaxChanged && !(c & EndChanged)) + c = (Change) ( c +EndChanged); + } + + if(c != NoChange) + emit changed(this, c); + + } +} + + + +void +KGanttItem::setText(const QString& text) +/////////////////////////////////////// +{ + if(!_editable) return; + if(text != _text) { + _text = text; + emit changed(this,TextChanged); + } +} + + + +void +KGanttItem::open(bool f) +////////////////////// +{ + if(f != _open) { + _open = f; + if(_open) + emit changed(this, Opened); + else + emit changed(this, Closed); + } +} + + + +void +KGanttItem::select(bool f) +/////////////////////// +{ + if(!_editable) return; + if(f != _selected) { + _selected = f; + if(_selected) + emit changed(this, Selected); + else + emit changed(this, Unselected); + } +} + + + +void +KGanttItem::setMode(Mode flag) +//////////////////////////// +{ + if(!_editable) return; + if(_mode != flag) { + _mode = flag; + emit changed(this,ModeChanged); + } + +} + + + +void +KGanttItem::setStyle(int flag, bool includeSubItems) +/////////////////////////////////////////////// +{ + if(!_editable) return; + if(_style != flag) { + + _style = flag; + + if(includeSubItems) + for(KGanttItem* item = _subitems.first(); + item != 0; + item = _subitems.next() ) + item->setStyle(flag,true); + + emit changed(this,StyleChanged); + + } + +} + + + +void +KGanttItem::setBrush(const QBrush& brush) +/////////////////////////////////////// +{ + _brush = brush; +} + + + +void +KGanttItem::setPen(const QPen& pen) +/////////////////////////////// +{ + _pen = pen; +} + + + +void +KGanttItem::setHeight(int h) +///////////////////////// +{ + if(!_editable) return; + if(_height != h) { + _height = h; + emit changed(this,HeightChanged); + } +} + + + +int +KGanttItem::getTotalHeight() +//////////////////////////////////////// +{ + int h = _height; + + if( isOpen() ) { + for(KGanttItem* item = _subitems.first(); item != 0; item = _subitems.next() ) { + h += item->getTotalHeight(); + } + } + return h; +} + + + +int +KGanttItem::getWidth() +////////////////// +{ + // int width = _start.secsTo(_end)/60; + + int width = getStart().secsTo(getEnd())/60; + + // printf("width[%s] = %d \n", (const char*) getID(), width ); + + return width; +} + + + +void +KGanttItem::dump(QTextOStream& cout, const QString& pre) +//////////////////////////////////////////////////// +{ + cout << pre << "\n"; + cout << pre << "| start : " << getStart().toString() << " (" + <<_start.toString() << ")" << endl; + cout << pre << "| end : " << getEnd().toString() << " (" + <<_end.toString() << ")" << endl; + if(_editable) + cout << pre << "| - editable " << endl; + else + cout << pre << "| - not editable " << endl; + if(_mode == Rubberband) + cout << pre << "| mode = 'rubberband'" << endl; + else + cout << pre << "| mode = 'normal'" << endl; + + cout << pre << "| min date/time : " << _minDateTime.toString() << endl; + cout << pre << "| max date/time : " << _maxDateTime.toString() << endl; + + for(KGanttItem* item = _subitems.first(); item != 0; item = _subitems.next() ) + item->dump(cout, pre + "| "); + + for(KGanttRelation* rel = _relations.first(); + rel != 0; + rel = _relations.next() ) + rel->dump(cout, pre + "| "); + + cout << pre << "\n"; + +} + + +QString +KGanttItem::ChangeAsString(Change c) +////////////////////////////////// +{ + QString ret; + + if(c & StartChanged) ret += "StartChanged, "; + if(c & EndChanged) ret += "EndChanged, "; + if(c & HeightChanged) ret += "HeightChanged, "; + if(c & TotalHeightChanged) ret += "TotalHeightChanged, "; + if(c & StyleChanged) ret += "StyleChanged, "; + if(c & TextChanged) ret += "TextChanged, "; + if(c & ModeChanged) ret += "ModeChanged, "; + if(c & MinChanged) ret += "MinChanged, "; + if(c & MaxChanged) ret += "MaxChanged, "; + if(c & Opened) ret += "Opened, "; + if(c & Closed) ret += "Closed, "; + if(c & Selected) ret += "Selected, "; + if(c & Unselected) ret += "Unselected, "; + if(c & Unknown) ret += "Unknown, "; + return ret; + +} +#include "KGanttItem.moc" diff --git a/kgantt/kgantt/KGanttItem.h b/kgantt/kgantt/KGanttItem.h new file mode 100644 index 000000000..0528e4782 --- /dev/null +++ b/kgantt/kgantt/KGanttItem.h @@ -0,0 +1,548 @@ +#ifndef _KGANTTITEM_H_ +#define _KGANTTITEM_H_ + +/* + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + author : jh, jochen@ifb.bv.tu-berlin.de + + file : KGanttItem.h + date : 26 oct 2000 + + + changelog : 26 dec 2000, jh + 09 jan 2001, jh - added signal destroyed(xQTask*) + + 11 jan 2001, jh changed to kde : xQTask -> KGanttItem + +*/ + + +#include +#include +#include +#include +#include + +#include + +#include "KGanttRelation.h" + + + +/// KGanttItem. +/*! + * This class describes a item. It contains dates on which the item starts and + * ends. It also contains attributes that gouverns the graphical representation + * in a gantt diagramm. + */ +////////////////////////////////// +class KDE_EXPORT KGanttItem : public QObject +////////////////////////////////// +{ + + Q_OBJECT + + +public: + + enum Change { + NoChange = 0, + StartChanged = 1, + EndChanged = 2, + + /// Height for this item has changed. The + /// height doesn't include the subitems. + HeightChanged = 4, + + /// Total height has changed. This + /// happens if the item was opened, closed + /// or subitems has been added or removed while + /// item is open. + TotalHeightChanged = 8, + + /// Style for drawing has changed. + StyleChanged = 16, + TextChanged = 32, + ModeChanged = 64, + MinChanged = 128, + MaxChanged = 256, + + /// Draw item including subitems. + Opened = 512, + + /// Draw item without subitems. + Closed = 1024, + + /// Item has been selected. + Selected = 2048, + + /// Item has been unselected. + Unselected = 4096, + + /// Changes may occurred but the types are unknown + Unknown = 8192, + + /// Relation between two subitems has been added + RelationAdded = 16384, + + /// Relation between two subitems has been removed + RelationRemoved = 32768 + + }; + + + + enum Style { + /// Set item invisible + DrawNothing = 0, + + /// Draw border. + DrawBorder = 1, + + // Fill item with brush. + DrawFilled = 2, + DrawText = 4, + + // Draw handlke for opening/closing item. + DrawHandle = 16, + + /// Draw handle only if item contains subitems + DrawHandleWSubitems = 32, + + DrawAll = 255 + }; + + + enum Mode { + Normal, + Rubberband + }; + + + /// Constructor. + /*! + * + */ + KGanttItem(KGanttItem* parentItem, const QString& text, + const QDateTime& start, const QDateTime& end); + + + + /// Constructor. + /*! + * + */ + KGanttItem(KGanttItem* parentItem, const QString& text, + const QDateTime& start, long durationMin); + + + + /// Destructor. + /* + * Emits signal destroyed(KGanttItem* this). + */ + ~KGanttItem(); + + + + /// Add relation between two subitems. + /* + * + */ + KGanttRelation* addRelation(KGanttItem* from, KGanttItem* to, + const QString& text); + + + + + /// Returns true if item is open (subitems has to be drawn) + /*! + * + */ + bool isOpen() { + return _open; + } + + + + /// Open / Close item + /*! + * Draw/don't draw subitems. + */ + void open(bool f); + + + + /// Set item editable or not. + /*! + * If item is not editable these methods have no effect : + * setStart(), setEnd(), setText(), select(), setMode(), setStyle(), + * setHeight(), + * + */ + void setEditable(bool f) { + _editable = f; + } + + + + /// Returns if item is editable. + /*! + * See also setEditable(). + */ + bool isEditable() { + return _editable; + } + + + + /// Returns true if item is selected. + /*! + * + */ + bool isSelected() { + return _selected; + } + + + + /// Select/unselect item. + /*! + * + */ + void select(bool f); + + + + /// Set mode. + /*! + * If mode is 'Rubberband' and the number of subtaks is greater than 0, + * the start and end of the item is determined by the start and end of the + * earliest/latest subitem.
+ * Default is 'Normal'. + */ + void setMode(Mode flag); + + + + /// Set drawing style. + /*! + * + */ + void setStyle(int flag, bool includeSubitems = false); + + + + /// Get drawing style. + /*! + * + */ + int getStyle() { + return _style; + } + + + + /// Set brush for filling + /*! + * + */ + void setBrush(const QBrush& brush); + + + + /// Get brush that is used for filling the item. + /*! + * + */ + QBrush& getBrush() { + return _brush; + } + + + + /// Get brush which has to be used for drawing this item as selected. + /*! + * + */ + QBrush& getSelectBrush() { + return _selectBrush; + } + + + + /// Set pen for border. + /*! + * + */ + void setPen(const QPen& pen); + + + + /// + /*! + * + */ + QPen& getPen() { + return _pen; + } + + + + /// + /*! + * + */ + void setTextPen(const QPen& pen) { + _textPen = pen; + } + + + + /// + /*! + * + */ + QPen& getTextPen() { + return _textPen; + } + + + + /// Set text. + /*! + * + */ + void setText(const QString& text); + + + + /// Get text. + /*! + * + */ + QString getText() { return _text; } + + + + /// Get date of starting. + /*! + * If mode == ´Rubberband´ and this item contains + * subitems, start of the item is determined by the start of the + * earliest subitem.
+ */ + QDateTime getStart(); + + + + /// Get date of ending. + /*! + * + */ + QDateTime getEnd(); + + + + /// Set time/date of start. + /*! + * + */ + void setStart(const QDateTime& start); + + + + /// Set time/date of end. + /*! + * + */ + void setEnd(const QDateTime& end); + + + + /// Set height. + /*! + * Set height in pixel. These are scaled when this item is drawn + * by the barview. + */ + void setHeight(int h); + + + + /// Get height. + /*! + * Returns the height in pixel of this item. This does not include the height + * of any subitems; getTotalHeight() returns that if the subitems have + * to be drawn. + */ + int getHeight() { + return _height; + } + + + + /// Get total height. + /*! + * Returns the total height of this object in pixel, including any + * visible subitems. Notice, that the pixels are no screen pixel since + * the barview scales the height of a item. + */ + int getTotalHeight(); + + + + /// Get width in minutes. + /*! + * + */ + int getWidth(); + + + + /// Get list of subitems. + /*! + * + */ + QPtrList& getSubItems() { + return _subitems; + } + + + + /// Get list of relations. + /*! + * + */ + QPtrList& getRelations() { + return _relations; + } + + + + /// Start a transaction. + /*! + * If you want to add a lot of subitems -> block signals + */ + void startTransaction(){ + blockSignals(true); + } + + + + /// End a transaction. + /*! + * If you started a transaction and all signals have been blocked + * by method startTransaction(), invoke endTransaction() to unblock signals.
+ * Signal changed(this,Unknown) is emitted. + */ + void endTransaction(); + + + + /// Return a given change as a string. + /*! + * + */ + static QString ChangeAsString(Change c); + + + + + /// Dump to cout. + /*! + * + */ + void dump(QTextOStream& cout, const QString& pre); + + +signals: + + /// Item has changed. + /*! + * This signal is emitted if any of the items + * properties have been changed. + */ + void changed(KGanttItem*, KGanttItem::Change); + + + + /// Item will be deleted. + /*! + * This signal will be emitted immediately before + * the object will be deleted. + */ + void destroyed(KGanttItem*); + + + +private slots: + + void subItemChanged(KGanttItem*, KGanttItem::Change); + + void removeRelation(KGanttRelation* rel); + + +private: + + void registerItem(KGanttItem* item); + void unregisterItem(KGanttItem* item); + + void init(KGanttItem* parentItem, const QString& text, + const QDateTime& start, const QDateTime& end); + + + // set min/max date and time according to subitems + Change adjustMinMax(); + + /* if min < start set start to _min, + if max > end set end to max */ + Change adjustStartEnd(); + + + // is item open/closed + bool _open; + bool _selected; + + + // is this item editable by the user, if it is false, invoking + // of some methods has no effect + bool _editable; + + int _height, _style, _mode; + + + KGanttItem* _parentItem; + QPtrList _subitems; + QPtrList _relations; + + + // start/end date. + // start must always be earlier then _minDateTime + // end must always be later then _maxDateTime + QDateTime _start, _end, _minDateTime, _maxDateTime; + + QString _text; + + QBrush _brush; + QPen _pen, _textPen; + + static QBrush _selectBrush; + + +}; + +#endif diff --git a/kgantt/kgantt/KGanttRelation.cpp b/kgantt/kgantt/KGanttRelation.cpp new file mode 100644 index 000000000..b9123acc2 --- /dev/null +++ b/kgantt/kgantt/KGanttRelation.cpp @@ -0,0 +1,168 @@ +// +// file : KGanttRelation.cpp +// date : 17 feb 2001 +// changed : +// author : jh +// + + +#include "KGanttRelation.h" +#include "KGanttItem.h" + + +QPen KGanttRelation::_selectPen(QColor(255,0,0)); + + +KGanttRelation::KGanttRelation(KGanttItem* from, KGanttItem* to, + const QString& text ) + : QObject() +//////////////////////////////////////////////////////// +{ + _from = from; + _to = to; + _text = text; + _pen = QPen(QColor(20,20,20),1); + + connect(from, SIGNAL(destroyed(KGanttItem*)), + this, SLOT(itemDestroyed(KGanttItem*))); + + connect(to, SIGNAL(destroyed(KGanttItem*)), + this, SLOT(itemDestroyed(KGanttItem*))); + +} + + + + +KGanttRelation::~KGanttRelation() +///////////////// +{ +#ifdef _DEBUG_ + printf("-> delete Relation %s \n", getText().latin1() ); +#endif + + emit destroyed(this); + +#ifdef _DEBUG_ + printf("<- delete Relation %s \n", getText().latin1() ); +#endif +} + + + +KGanttItem* +KGanttRelation::getFrom() +{ + return _from; +} + + + + +KGanttItem* +KGanttRelation::getTo() +///////////////// +{ + return _to; +} + + + +void +KGanttRelation::itemDestroyed(KGanttItem* /*item*/) +{ + delete this; +} + + + +void +KGanttRelation::setText(const QString& text) +/////////////////////////////////////// +{ + if(!_editable) return; + if(text != _text) { + _text = text; + emit changed(this,TextChanged); + } +} + + + +void +KGanttRelation::select(bool f) +/////////////////////// +{ + if(!_editable) return; + if(f != _selected) { + _selected = f; + if(_selected) + emit changed(this, Selected); + else + emit changed(this, Unselected); + } +} + + + + +void +KGanttRelation::setPen(const QPen& pen) +{ + _pen = pen; +} + + + + +void +KGanttRelation::dump(QTextOStream& cout, const QString& pre) +{ + cout << pre << "\n"; + + cout << pre << "| from : " << getFrom()->getText().latin1() << endl; + cout << pre << "| to : " << getTo()->getText().latin1() << endl; + + if(_editable) + cout << pre << "| - editable " << endl; + else + cout << pre << "| - not editable " << endl; + + if(_selected) + cout << pre << "| - selected " << endl; + else + cout << pre << "| - not selected " << endl; + + cout << pre << "\n"; + +} + + +QString +KGanttRelation::ChangeAsString(Change c) +////////////////////////////////// +{ + QString ret; + + /* + if(c & StartChanged) ret += "StartChanged, "; + if(c & EndChanged) ret += "EndChanged, "; + if(c & HeightChanged) ret += "HeightChanged, "; + if(c & TotalHeightChanged) ret += "TotalHeightChanged, "; + if(c & StyleChanged) ret += "StyleChanged, "; + */ + if(c & TextChanged) ret += "TextChanged, "; + /* + if(c & ModeChanged) ret += "ModeChanged, "; + if(c & MinChanged) ret += "MinChanged, "; + if(c & MaxChanged) ret += "MaxChanged, "; + if(c & Opened) ret += "Opened, "; + if(c & Closed) ret += "Closed, "; + if(c & Selected) ret += "Selected, "; + if(c & Unselected) ret += "Unselected, "; + if(c & Unknown) ret += "Unknown, "; + */ + return ret; + +} +#include "KGanttRelation.moc" diff --git a/kgantt/kgantt/KGanttRelation.h b/kgantt/kgantt/KGanttRelation.h new file mode 100644 index 000000000..26baf7c4b --- /dev/null +++ b/kgantt/kgantt/KGanttRelation.h @@ -0,0 +1,256 @@ +#ifndef _KGANTTRELATION_H_ +#define _KGANTTRELATION_H_ + +/* + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + author : jh, jochen@ifb.bv.tu-berlin.de + + file : KGanttRelation.h + date : 17.02.2001 + + changelog : + +*/ + + +#include +#include +#include +#include +#include + + +class KGanttItem; + + +/// KGanttRelation. +/*! + * This class describes a item. It contains dates on which the item starts and + * ends. It also contains attributes that gouverns the graphical representation + * in a gantt diagramm. + */ +////////////////////////////////// +class KGanttRelation : public QObject +////////////////////////////////// +{ + + Q_OBJECT + + friend class KGanttItem; + +public: + + enum Change { + + NoChange = 0, + TextChanged = 32, + + /// Item has been selected. + Selected = 2048, + + /// Item has been unselected. + Unselected = 4096 + }; + + + + + /// Destructor. + /* + * Emits signal destroyed(KGanttRelation* this). + */ + ~KGanttRelation(); + + + + + /// Select/unselect item. + /*! + * + */ + void select(bool f); + + + /// Set item editable or not. + /*! + * If item is not editable these methods have no effect : + * setStart(), setEnd(), setText(), select(), setMode(), setStyle(), + * setHeight(), + * + */ + void setEditable(bool f) { + _editable = f; + } + + + + /// Returns if item is editable. + /*! + * See also setEditable(). + */ + bool isEditable() { + return _editable; + } + + + + /// Get brush which has to be used for drawing this item as selected. + /*! + * + */ + QPen& getSelectPen() { + return _selectPen; + } + + + + /// Set pen for border. + /*! + * + */ + void setPen(const QPen& pen); + + + + /// + /*! + * + */ + QPen& getPen() { + return _pen; + } + + + + /// + /*! + * + */ + void setTextPen(const QPen& pen) { + _textPen = pen; + } + + + + /// + /*! + * + */ + QPen& getTextPen() { + return _textPen; + } + + + + /// Set text. + /*! + * + */ + void setText(const QString& text); + + + + /// Get text. + /*! + * + */ + QString getText() { return _text; } + + + + /// Get date of starting. + /*! + * If mode == ´Rubberband´ and this item contains + * subitems, start of the item is determined by the start of the + * earliest subitem.
+ */ + KGanttItem* getFrom(); + + + + /// Get date of ending. + /*! + * + */ + KGanttItem* getTo(); + + + + /// Dump to cout. + /*! + * + */ + void dump(QTextOStream& cout, const QString& pre); + + + QString ChangeAsString(Change c); + + +signals: + + /// Item has changed. + /*! + * This signal is emitted if any of the items + * properties have been changed. + */ + void changed(KGanttRelation*, KGanttRelation::Change); + + + + /// Item will be deleted. + /*! + * This signal will be emitted immediately before + * the object will be deleted. + */ + void destroyed(KGanttRelation*); + + +public slots: + + void itemDestroyed(KGanttItem* item); + + +protected: + + /// Constructor. + /*! + * + */ + KGanttRelation(KGanttItem* from, KGanttItem* to, + const QString& text ); + + +private: + + + bool _selected; + + bool _editable; + + KGanttItem* _from; + KGanttItem* _to; + + QString _text; + + QPen _pen, _textPen; + + static QPen _selectPen; + +}; + +#endif diff --git a/kgantt/kgantt/Makefile.am b/kgantt/kgantt/Makefile.am new file mode 100644 index 000000000..c9dcbfdb6 --- /dev/null +++ b/kgantt/kgantt/Makefile.am @@ -0,0 +1,24 @@ + +lib_LTLIBRARIES = libkgantt.la +libkgantt_la_SOURCES = KGantt.cpp xQGanttBarViewPort.cpp \ +xQGanttListViewPort.cpp \ +KGanttItem.cpp KGanttRelation.cpp \ +xQGanttBarViewPort_Events.cpp \ +xQGanttBarView.cpp xQGanttListView.cpp KGanttBarConfig.cpp + +libkgantt_la_LDFLAGS = -version-info 0:2:0 $(all_libraries) -no-undefined +libkgantt_la_LIBADD = $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) + +# set the include path for X, qt and KDE +INCLUDES= $(all_includes) + +METASOURCES = AUTO + +kganttincludedir = $(includedir)/kgantt +kganttinclude_HEADERS = KGantt.h \ +KGanttItem.h KGanttRelation.h \ +xQGanttBarView.h \ +xQGanttBarViewPort.h xQGanttListView.h xQGanttListViewPort.h KGanttBarConfig.h + +messages: rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/kgantt.pot diff --git a/kgantt/kgantt/close.xpm b/kgantt/kgantt/close.xpm new file mode 100644 index 000000000..281aee972 --- /dev/null +++ b/kgantt/kgantt/close.xpm @@ -0,0 +1,72 @@ +/* XPM */ +static const char * close_xpm[] = { +"14 13 56 1", +" c None", +". c #000000", +"+ c #124D6F", +"@ c #0A121F", +"# c #155474", +"$ c #819EBA", +"% c #17587A", +"& c #081E31", +"* c #194A6A", +"= c #DDEFF8", +"- c #1390B4", +"; c #155678", +"> c #071728", +", c #1B4B6A", +"' c #FDFCFD", +") c #59C3DA", +"! c #3CD7E1", +"~ c #155A7A", +"{ c #1B4F6F", +"] c #71D1E0", +"^ c #19B3CE", +"/ c #0EA0C5", +"( c #48DFE9", +"_ c #1290B5", +": c #135476", +"< c #07182A", +"[ c #124C6D", +"} c #E2F0F9", +"| c #0E97BF", +"1 c #1CA2C3", +"2 c #105375", +"3 c #06101D", +"4 c #20374F", +"5 c #010304", +"6 c #114760", +"7 c #9DDEEE", +"8 c #22BAD1", +"9 c #159ABC", +"0 c #0F5D7E", +"a c #000101", +"b c #CDEBF6", +"c c #1197B9", +"d c #43D5DE", +"e c #2294B1", +"f c #0A263B", +"g c #FDFAFD", +"h c #2A98B3", +"i c #0A273B", +"j c #2CC7D5", +"k c #178EAC", +"l c #80C2DB", +"m c #58ACC5", +"n c #14839F", +"o c #0A1929", +"p c #081C2D", +"q c #071C2C", +" .......... ", +" +@ ", +" #$%& ", +" *$=-;> ", +" ,$')!-~> ", +" {$']^/(_:< ", +" [$})^||/!123 ", +"245.67|890a...", +" 2bcdef ", +" 2gcdhi ", +" 2bcjki ", +" 2lm8n. ", +" 2opq.. "}; diff --git a/kgantt/kgantt/itemedit.ui b/kgantt/kgantt/itemedit.ui new file mode 100644 index 000000000..e50689e68 --- /dev/null +++ b/kgantt/kgantt/itemedit.ui @@ -0,0 +1,612 @@ + +Form1 + + + Form1 + + + + 0 + 0 + 569 + 431 + + + + + + + + + unnamed + + + 11 + + + 6 + + + + _itemTextLabel + + + + 1 + 0 + 0 + 0 + + + + + 32767 + 30 + + + + Item text: + + + AlignBottom|AlignLeft + + + + + + + groupBox10 + + + Minimum Start + + + + unnamed + + + + _spacer3MinStart + + + Horizontal + + + Expanding + + + + 50 + 20 + + + + + + _minStartMinuetEdit + + + + 20 + 30 + + + + 2 + + + + + _minStartHourEdit + + + + 20 + 30 + + + + 2 + + + + + _minStartDateEdit + + + + + _minStartDateLabel + + + + 0 + 0 + 0 + 0 + + + + Date: + + + + + _minStartTimeSepatatorLabel + + + + 15 + 1 + + + + : + + + + + _minStartTimeLabel + + + + 0 + 0 + 0 + 0 + + + + Time: + + + + + + + groupBox11 + + + Maximum Start + + + + unnamed + + + + _maxStartHourEdit + + + + 20 + 30 + + + + 2 + + + + + _maxStartDateEdit + + + + + _maxStartTimeSepatatorLabel + + + + 15 + 1 + + + + : + + + + + _maxStartMinuetEdit + + + + 20 + 30 + + + + 2 + + + + + _spacer3MaxStart + + + Horizontal + + + Expanding + + + + 50 + 20 + + + + + + _maxStartTimeLabel + + + + 0 + 0 + 0 + 0 + + + + Time: + + + + + _maxStartDateLabel + + + + 0 + 0 + 0 + 0 + + + + Date: + + + + + + + groupBox8 + + + Start + + + + unnamed + + + + _startTimeLabel + + + + 0 + 0 + 0 + 0 + + + + Time: + + + + + _spacer3Start + + + Horizontal + + + Expanding + + + + 356 + 20 + + + + + + _startTimeSepatatorLabel + + + + 15 + 1 + + + + : + + + + + _startDateLabel + + + + 0 + 0 + 0 + 0 + + + + Date: + + + + + _startDateEdit + + + + + _startHourEdit + + + + 20 + 30 + + + + 2 + + + + + _startMinuetEdit + + + + 20 + 30 + + + + 2 + + + + + + + groupBox9 + + + End + + + + unnamed + + + + _endMinuetEdit + + + + 20 + 30 + + + + 2 + + + + + _spacer3End + + + Horizontal + + + Expanding + + + + 356 + 20 + + + + + + _endDateEdit + + + + + _endTimeLabel + + + + 0 + 0 + 0 + 0 + + + + Time: + + + + + _endDateLabel + + + + 0 + 0 + 0 + 0 + + + + Date: + + + + + _endTimeSeparator + + + + 15 + 1 + + + + : + + + + + _endHourEdit + + + + 20 + 30 + + + + 2 + + + + + + + groupBox7 + + + Style + + + + unnamed + + + + + mode1 + + + + + mode2 + + + + + mode3 + + + + _styleModeCombo + + + + + _styleHeightEdit + + + 20 + + + + + + style1 + + + + + style2 + + + + + style3 + + + + _styleStyleCombo + + + + + _styleStyleLabel + + + + 0 + 1 + 0 + 0 + + + + Style: + + + + + _styleModeLabel + + + + 0 + 1 + 0 + 0 + + + + Mode: + + + + + _styleHeightLabel + + + + 0 + 1 + 0 + 0 + + + + Height: + + + + + + + _itemTextEdit + + + + + + + knuminput.h + + diff --git a/kgantt/kgantt/itemedit2.ui b/kgantt/kgantt/itemedit2.ui new file mode 100644 index 000000000..7ef1fa002 --- /dev/null +++ b/kgantt/kgantt/itemedit2.ui @@ -0,0 +1,329 @@ + +Form1 + + + Form1 + + + + 0 + 0 + 433 + 345 + + + + + + + + + unnamed + + + 11 + + + 6 + + + + _itemTextEdit + + + + + groupBox5 + + + Style + + + + unnamed + + + + + style1 + + + + + style2 + + + + + style3 + + + + _styleStyleCombo + + + + + _styleHeightEdit + + + 20 + + + + + + mode1 + + + + + mode2 + + + + + mode3 + + + + _styleModeCombo + + + + + _styleHeightLabel + + + + 0 + 1 + 0 + 0 + + + + Height: + + + + + _styleModeLabel + + + + 0 + 1 + 0 + 0 + + + + Mode: + + + + + _styleStyleLabel + + + + 0 + 1 + 0 + 0 + + + + Style: + + + + + + + groupBox6 + + + Date/Time + + + + unnamed + + + + + Start + + + + + End + + + + + Min Start + + + + + Max Start + + + + _dateTimeEditCombo + + + + + _dateTimeTimeLabel + + + + 0 + 0 + 0 + 0 + + + + Time: + + + + + _dateTimeDateLabel + + + + 0 + 0 + 0 + 0 + + + + Date: + + + + + _startDateEdit + + + + + _dateTimeHourEdit + + + + 20 + 30 + + + + 2 + + + + + _startTimeSepatatorLabel + + + + 15 + 1 + + + + : + + + + + _dateTimeMinuetEdit + + + + 20 + 30 + + + + 2 + + + + + _spacer3DateTime + + + Horizontal + + + Expanding + + + + 194 + 20 + + + + + + _dateTimeEditLabel + + + + 0 + 1 + 0 + 0 + + + + Edit: + + + + + + + _itemTextLabel + + + + 1 + 0 + 0 + 0 + + + + + 32767 + 30 + + + + Item text: + + + PlainText + + + WordBreak|AlignBottom|AlignLeft + + + + + + + + + knuminput.h + + diff --git a/kgantt/kgantt/lupe.xpm b/kgantt/kgantt/lupe.xpm new file mode 100644 index 000000000..077e635f3 --- /dev/null +++ b/kgantt/kgantt/lupe.xpm @@ -0,0 +1,62 @@ +/* XPM */ +static const char*lupe[]={ +"22 22 37 1", +"e c #bebebe", +"D c #ababab", +"G c #989898", +"y c #dedede", +"x c #8d8d8d", +"o c #dbdbdb", +"r c #d0d0d0", +"H c #777777", +"F c #414141", +"u c #bdbdbd", +"m c #e0e0e0", +"E c #aaaaaa", +"i c #e8e8e8", +"d c #c2c2c2", +"I c #717171", +"A c #d2d2d2", +"f c #9c9c9c", +"h c #dadada", +"q c #bfbfbf", +"b c #898989", +"# c #303030", +"v c #eaeaea", +"C c #cfcfcf", +"B c #b4b4b4", +"g c #999999", +"t c #d7d7d7", +"p c #868686", +". c None", +"s c #c4c4c4", +"a c #121212", +"j c #e7e7e7", +"k c #efefef", +"w c #d4d4d4", +"l c #c1c1c1", +"n c #c9c9c9", +"z c #aeaeae", +"c c #b6b6b6", +"....##aaaa............", +"..##abcdefaa..........", +".#aghi...jkla.........", +".#gm.......kna........", +"##h........oka........", +"api.........oqa.......", +"ac...........ra.......", +"as...........ta.......", +"auv..........wa.......", +"axv.........ola.......", +".ay.........ka........", +".azk.......kAa........", +"..aBko...okCaxD.......", +"...aaEthwdaaFGxa......", +".....aaaaa..HFIxa.....", +".............aFIxa....", +"..............aFIxa...", +"...............aFIxa..", +"................aFIxa.", +".................aFIa.", +"..................aa..", +"......................"}; diff --git a/kgantt/kgantt/open.xpm b/kgantt/kgantt/open.xpm new file mode 100644 index 000000000..578107eff --- /dev/null +++ b/kgantt/kgantt/open.xpm @@ -0,0 +1,69 @@ +/* XPM */ +static const char * open_xpm[] = { +"16 16 50 1", +" c None", +". c #124D6F", +"+ c #254A64", +"@ c #18425F", +"# c #0D324C", +"$ c #A0CBDF", +"% c #EFF3FC", +"& c #D3E5F0", +"* c #64A3BD", +"= c #071620", +"- c #E0F1FB", +"; c #5FC0D8", +"> c #8FCCE2", +", c #2B91AE", +"' c #06141D", +") c #0EADCB", +"! c #40D1DB", +"~ c #2695B1", +"{ c #06141F", +"] c #0E97BF", +"^ c #46DBE6", +"/ c #1F95B2", +"( c #05151E", +"_ c #BFDFEE", +": c #0E94B9", +"< c #1BBAD1", +"[ c #1299BB", +"} c #0E5775", +"| c #114560", +"1 c #144059", +"2 c #0B293E", +"3 c #010001", +"4 c #0D3652", +"5 c #337F9E", +"6 c #DFEFF8", +"7 c #A7DCEC", +"8 c #54BDD7", +"9 c #0E8FB6", +"0 c #15C1DA", +"a c #48DFE9", +"b c #1CA2C3", +"c c #106589", +"d c #03060C", +"e c #FFFFFF", +"f c #0E9EC3", +"g c #0FA0C4", +"h c #060F19", +"i c #14A5C9", +"j c #050B12", +"k c #10698F", +" ", +" ...+@# ", +" .$%&*= ", +" .-;>,' ", +" .%)!~{ ", +" +-]^/( ", +" ..++_:<[}|123 ", +" 456789]0abcd ", +" 45ef]gabch ", +" 45eiabcj ", +" 456bcj ", +" 4kch ", +" 4d ", +" ", +" ", +" "}; diff --git a/kgantt/kgantt/xQGanttBarView.cpp b/kgantt/kgantt/xQGanttBarView.cpp new file mode 100644 index 000000000..4a79de600 --- /dev/null +++ b/kgantt/kgantt/xQGanttBarView.cpp @@ -0,0 +1,252 @@ +// +// file : xQGanttBarView.C +// date : 26 oct 2000 +// changed : 28 nov 2000 +// author : jh +// + + +#include "xQGanttBarView.h" +#include "KGanttBarConfig.h" + + + +xQGanttBarView::xQGanttBarView(KGanttItem* toplevelitem, + QWidget* parent, + const char * name, WFlags f) + : QScrollView(parent,name,f) +{ + _config = NULL; + + _toplevelitem = toplevelitem; + + setFrameStyle(QFrame::Sunken); + setLineWidth(1); + + _headerBackBrush = QBrush(QColor(250,250,250)); + + setMargins( 1, TOPMARGIN , 1, 1 ); + + _viewport = new xQGanttBarViewPort(toplevelitem, this ); + + addChild(_viewport); + + _viewport->setMode(xQGanttBarViewPort::Select); + + connect(_viewport, SIGNAL(scroll(int,int)), + this, SLOT(scrollBy(int,int)) ); + + connect(_viewport, SIGNAL(recalculated()), + this, SLOT(drawHeader()) ); + + connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), + this, SLOT(horizontalScrollBarChanged(int)) ); + +} + + + +xQGanttBarView::~xQGanttBarView() +///////////////////////////////// +{ +} + + + +void +xQGanttBarView::horizontalScrollBarChanged(int /*x*/) +//////////////////////////////////////////////////// +{ + printf("xQGanttBarView::horizontalScrollBarChanged()\n"); + drawHeader(); +} + + + +void +xQGanttBarView::drawHeader() +//////////////////////////////// +{ + static QPen _dotPen( QColor(35,35,35), 0, DotLine); + static QPen _normalPen(QColor(0,0,0)); + static QPen _redPen(QColor(254,0,0)); + static QPen _greyPen(QColor(150,150,150)); + + QPainter p(this); + p.setPen( _normalPen ); + + p.fillRect(0,0,width(),TOPMARGIN, _headerBackBrush ); + + static int top = 1; + static int height = 20; + static int skip = 1; + + int a,e,tmp; + bool drawDays = false; + double dayWidth = (double) ((_viewport->screenX(144000) - _viewport->screenX(0))/100.); + + int wx = _viewport->worldX(contentsX()); + + QDate startDate = _toplevelitem->getStart().addSecs( wx * 60 ).date(); + + wx = _viewport->worldX(contentsX()+width()); + QDate endDate = _toplevelitem->getStart().addSecs( wx * 60 ).date(); + endDate = endDate.addDays(1); + + int end = (int) startDate.daysTo(endDate); + drawDays = (end < 12); + + // draw week, which first day is not visible + + QDate t = startDate.addDays(-startDate.dayOfWeek()+1); + + tmp = _toplevelitem->getStart().secsTo(t)/60; + a = _viewport->screenX(tmp) - contentsX(); + + p.fillRect(a, top, (int) (5. * dayWidth), height, QBrush(QColor(240,240,240))); + p.drawRect(a, top, (int) (5. * dayWidth), height ); + + // draw month, which first day is not visible + + t = startDate.addDays(-startDate.day()+1); + + tmp = _toplevelitem->getStart().secsTo(t)/60; + a = _viewport->screenX(tmp) - contentsX(); + + e = t.daysInMonth(); + p.fillRect(a, top + height + skip, (int) (e*dayWidth), height, QBrush(QColor(240,240,240))); + p.drawRect(a, top + height + skip, (int) (e*dayWidth), height ); + + if(a<0) a = 0; + p.drawText(a+5, int( top + height + skip + (0.8*height) ), + t.shortMonthName(t.month()) + " " + QString::number(t.year()) ); + + + // draw snapgrid for first month + + tmp = _toplevelitem->getStart().secsTo(startDate)/60; + a = _viewport->screenX(tmp) - contentsX()+1; + double dx = (double) + ((_viewport->screenX(_viewport->_snapgrid*1000) - _viewport->screenX(0))/1000.); + double limit = ((1+e-startDate.day()) * 1440)/_viewport->_snapgrid; + + for(double k=1.; kgetStart().secsTo(t)/60; + a = _viewport->screenX(tmp) - contentsX(); + + p.setPen( QPen(QColor(black)) ); + + if(t.dayOfWeek() == 1) { + + p.fillRect(a, top, (int) (5. * dayWidth), height, QBrush(QColor(240,240,240))); + p.drawRect(a, top, (int) (5. * dayWidth), height ); + + if(!drawDays) + p.drawText(a+5, (int) (top + (0.8*height)), QString::number(t.day()) ); + + } + + if(drawDays) { + + if(a<0) a = 0; + + QString str = t.shortDayName(t.dayOfWeek()) + " " + QString::number(t.day()); + QRect rect = p.boundingRect(a+5, (int)(0.8 * height), + (int) dayWidth, height, AlignLeft, str ); + + if(t.dayOfWeek() > 5) + p.fillRect(rect.x(), rect.y(), rect.width(), -rect.height(), _headerBackBrush ); + else + p.fillRect(rect.x(), rect.y(), + rect.width(), -rect.height(), QBrush(QColor(240,240,240))); + + p.drawText(a+5, (int)(0.8 * height), str ); + + if(t.dayOfWeek()>1 && t.dayOfWeek()<6) { + p.setPen(_dotPen); + p.drawLine(a, top, a, height); + } + + } + + if(t.day()==1) { + + e = t.daysInMonth(); + + p.setPen(_normalPen); + + p.fillRect(a, top + height + skip, + (int) (e * dayWidth), height, QBrush(QColor(240,240,240))); + p.drawRect(a, top + height + skip, (int) (e * dayWidth), height ); + + p.drawText(a+5, + top + (int)(1.8 * height) + skip, + t.shortMonthName(t.month()) + " " + QString::number(t.year()) ); + + // draw snapgrid + + double limit = (e * 1440)/_viewport->_snapgrid; + for(double k=1.; kshow(); +} + + + +void +xQGanttBarView::hideConfig() +{ + if(_config) + _config->hide(); +} +#include "xQGanttBarView.moc" diff --git a/kgantt/kgantt/xQGanttBarView.h b/kgantt/kgantt/xQGanttBarView.h new file mode 100644 index 000000000..4bb3446fa --- /dev/null +++ b/kgantt/kgantt/xQGanttBarView.h @@ -0,0 +1,121 @@ +#ifndef _XQGANTTBARVIEW_H_ +#define _XQGANTTBARVIEW_H_ + +/* + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + author : jh, jochen@ifb.bv.tu-berlin.de + + file : xQGanttBarView.h + date : 26 oct 2000 + + + changelog : + +*/ + + +#define sgn(n) (n < 0 ? -1 : 1) +#define TOPMARGIN 45 + + +#include + +#include "xQGanttBarViewPort.h" + + +class KGanttBarConfig; + + +/// Gantt view. +/*! + * Widget for drawing gantt diagrams. + */ + +////////////////////////////////////////// +class xQGanttBarView : public QScrollView +////////////////////////////////////////// +{ + + Q_OBJECT + + +public: + + + /// Constructor. + /*! + * + */ + xQGanttBarView(KGanttItem* toplevelitem, QWidget* parent = 0, + const char * name=0, WFlags f=0 ); + + + /// Destructor. + /*! + * + */ + ~xQGanttBarView(); + + + + /// + /*! + * + */ + xQGanttBarViewPort* viewport() { + return _viewport; + } + + + + /// Get config widget + /*! + * + */ + KGanttBarConfig* getConfig(); + + + +public slots: + + void horizontalScrollBarChanged(int); + void showConfig(); + void hideConfig(); + + +protected slots: + + void drawHeader(); + + +protected: + + xQGanttBarViewPort* _viewport; + + QBrush _headerBackBrush; + + void paintEvent(QPaintEvent * e); + + KGanttItem* _toplevelitem; + KGanttBarConfig* _config; + +}; + + + +#endif diff --git a/kgantt/kgantt/xQGanttBarViewPort.cpp b/kgantt/kgantt/xQGanttBarViewPort.cpp new file mode 100644 index 000000000..feabc07e0 --- /dev/null +++ b/kgantt/kgantt/xQGanttBarViewPort.cpp @@ -0,0 +1,1101 @@ +// +// file : xQGanttBarViewPort.C +// date : 26 oct 2000 +// changed : 09 jan 2001 +// author : jh +// + +#include "xQGanttBarViewPort.h" +#include "xQGanttBarView.h" + +#include +#include + +#include "lupe.xpm" +#include "open.xpm" +#include "close.xpm" + +#include +#include +#include + + + +xQGanttBarViewPort::xQGanttBarViewPort(KGanttItem* toplevelitem, + xQGanttBarView* parent, + const char * name, WFlags f) + : QFrame(parent,name,f) +///////////////////////////////////////////////////////////////////////////// +{ + _parent = parent; + + closedIcon = QPixmap(open_xpm); + openedIcon = QPixmap(close_xpm); + + _observedList = NULL; + _toolbar = NULL; + + _gItemList = QPtrDict(449); + _gItemList.setAutoDelete(true); + + _toplevelitem = toplevelitem; + + _itemInfo = new QLabel(this); + _itemInfo->setBackgroundColor(QColor(235,235,255)); + _itemInfo->setFrameStyle( Panel | Sunken ); + _itemInfo->setMargin( 5 ); + _itemInfo->setLineWidth(1); + _itemInfo->hide(); + + + _itemTextEdit = new QLineEdit(this); + _itemTextEdit->hide(); + _itemTextEdit->setFrame(false); + + connect(_itemTextEdit, SIGNAL(returnPressed ()), + this, SLOT(textEdited())); + + _iconloader = new KIconLoader(); + + initMenu(); + + setBackgroundColor(QColor(white)); + /* + QPixmap back("background.png"); + setBackgroundPixmap ( back ); + */ + + _grid = 1440; + _snapgrid = 360; + + _drawGrid = true; + _drawHeader = false; + + _marginX = 10 * 1440; + _marginY = 50; + + _scaleX = 0.1; + _scaleY = 1; + + _margin = 4; // margin item in pixel + + _startPoint = new QPoint(); _endPoint = new QPoint(); + + _cursor_lupe = new QCursor( QPixmap(lupe) ); + + connect(_toplevelitem, SIGNAL(changed(KGanttItem*, KGanttItem::Change)), + this, SLOT(toplevelitemChanged(KGanttItem*, KGanttItem::Change)) ); + + recalc(); adjustSize(); + + setFocusPolicy(QWidget::StrongFocus); + _mode = Init; + +} + + + +xQGanttBarViewPort::~xQGanttBarViewPort() +///////////////////////////////////////// +{ +} + + + +KToolBar* +xQGanttBarViewPort::toolbar(QMainWindow* mw) +{ + if(_toolbar || mw == 0) return _toolbar; + + _toolbar = new KToolBar(mw,QMainWindow::DockTop); + + mw->addToolBar(_toolbar); + + + // KIconLoader* iconloader = new KIconLoader("kgantt"); + + + _toolbar->insertButton("ganttSelect.png", 0, + SIGNAL(clicked()), + this, SLOT(setSelect()), + true, i18n("Select") ); + + KPopupMenu *selectMenu = new KPopupMenu(_toolbar); + + + /* + select all items + */ + QPixmap pix = _iconloader->loadIcon("ganttSelecttask.png", KIcon::Toolbar , 16 ); + if(pix.isNull()) printf("ganttSelecttask.png not found !\n"); + selectMenu->insertItem(pix, i18n("Select All"), this, SLOT(selectAll()) ); + + + /* + unselect all items + */ + pix = _iconloader->loadIcon("ganttUnselecttask", KIcon::Toolbar , 16 ); + if(pix.isNull()) printf("ganttUnselecttask.png not found !\n"); + selectMenu->insertItem(pix, i18n("Unselect All"), this, SLOT(unselectAll()) ); + + + KToolBarButton* b = _toolbar->getButton(0); + b->setDelayedPopup(selectMenu); + + + _toolbar->insertButton("viewmag.png", 1, + SIGNAL(clicked()), + this, SLOT(setZoom()), + true, i18n("Zoom") ); + + KPopupMenu* zoomMenu = new KPopupMenu(_toolbar); + + pix = _iconloader->loadIcon("viewmag.png", KIcon::Toolbar , 16 ); + if(pix.isNull()) printf("viewmag.png not found !\n"); + zoomMenu->insertItem(pix, i18n("Zoom All"), this, SLOT(zoomAll()) ); + zoomMenu->insertSeparator(); + + pix = _iconloader->loadIcon("viewmag+.png", KIcon::Toolbar , 16 ); + if(pix.isNull()) printf("viewmag+.png not found !\n"); + zoomMenu->insertItem(pix, i18n("Zoom In +"), this, SLOT(zoomIn()) ); + + pix = _iconloader->loadIcon("viewmag-.png", KIcon::Toolbar , 16 ); + if(pix.isNull()) printf("viewmag-.png not found !\n"); + zoomMenu->insertItem(pix, i18n("Zoom Out -"), this, SLOT(zoomOut()) ); + + b = _toolbar->getButton(1); + b->setDelayedPopup(zoomMenu); + + _toolbar->insertButton("move.png", 2, + SIGNAL(clicked()), + this, SLOT(setMove()), + true, i18n("Move") ); + + return _toolbar; + +} + + + +void +xQGanttBarViewPort::initMenu() +///////////////////////////////// +{ + _menu = new KPopupMenu(this); + + /* + select + */ + + _selectMenu = new KPopupMenu(_menu); + + QPixmap pix = _iconloader->loadIcon("ganttSelect.png", KIcon::Toolbar , 16 ); + if(pix.isNull()) printf("ganttSelect.png not found !\n"); + _selectMenu->insertItem(pix, i18n("Select Mode"), this, SLOT(setSelect())); + + _selectMenu->insertSeparator(); + + pix = _iconloader->loadIcon("ganttSelecttask.png", KIcon::Toolbar , 16 ); + if(pix.isNull()) printf("ganttSelecttask.png not found !\n"); + _selectMenu->insertItem(pix, i18n("Select All"), this, SLOT(selectAll()) ); + + pix = _iconloader->loadIcon("ganttUnselecttask", KIcon::Toolbar , 16 ); + if(pix.isNull()) printf("ganttUnselecttask.png not found !\n"); + _selectMenu->insertItem(pix, i18n("Unselect All"), this, SLOT(unselectAll()) ); + + _menu->insertItem( i18n("Select"), _selectMenu); + + + /* + zoom + */ + + KPopupMenu* _zoomMenu = new KPopupMenu(_menu); + + pix = _iconloader->loadIcon("viewmag.png", KIcon::Toolbar , 16 ); + if(pix.isNull()) printf("viewmag.png not found !\n"); + _zoomMenu->insertItem(i18n("Zoom Mode"), this, SLOT(setZoom()) ); + + _zoomMenu->insertSeparator(); + + _zoomMenu->insertItem(pix, i18n("Zoom All"), this, SLOT(zoomAll()) ); + _zoomMenu->insertSeparator(); + + pix = _iconloader->loadIcon("viewmag+.png", KIcon::Toolbar , 16 ); + if(pix.isNull()) printf("viewmag+.png not found !\n"); + _zoomMenu->insertItem(pix, i18n("Zoom In +"), this, SLOT(zoomIn()) ); + + pix = _iconloader->loadIcon("viewmag-.png", KIcon::Toolbar , 16 ); + if(pix.isNull()) printf("viewmag-.png not found !\n"); + _zoomMenu->insertItem(pix, i18n("Zoom Out -"), this, SLOT(zoomOut()) ); + + _menu->insertItem( "Zoom", _zoomMenu); + + pix = _iconloader->loadIcon("move.png", KIcon::Toolbar , 16 ); + if(pix.isNull()) printf("move.png not found !\n"); + _menu->insertItem(pix, i18n("Move Mode"), this, SLOT(setMove()) ); + + _menu->insertSeparator(); + + pix = _iconloader->loadIcon("configure.png", KIcon::Toolbar , 16 ); + if(pix.isNull()) printf("configure.png not found !\n"); + _menu->insertItem(pix, i18n("Configure Gantt..."), _parent, SLOT(showConfig())); + +} + + + +void +xQGanttBarViewPort::toplevelitemChanged(KGanttItem* /*item*/, KGanttItem::Change /*c*/) +/////////////////////////////////////////////////////////////////// +{ + recalc(); + adjustSize(); +} + + + +void +xQGanttBarViewPort::adjustSize() +////////////////////////////////// +{ + // printf("xQGanttBarViewPort::adjustSize()\n"); + + static int sw = 0; + static int sh = 0; + + int w = screenX(_toplevelitem->getWidth() + _marginX); + int h = screenY(_toplevelitem->getTotalHeight() + _marginY); + + if(sw != w || sh !=h) { + + sw = w; + sh = h; + + resize(w,h); + + emit resized(); + + } + +} + + + +void +xQGanttBarViewPort::update(int x1, int y1, int x2, int y2) +////////////////////////////////////////////////////////// +{ + QPainter p(this); + + // QTime time1 = QTime::currentTime(); + + if(_drawGrid) + drawGrid(&p, x1, y1, x2, y2); + + // QTime time2 = QTime::currentTime(); + // printf("%d msec for drawing grid.\n", time1.msecsTo( time2 ) ); + + // drawContents(&p, x1, y1, x2, y2); + drawItem(_toplevelitem, &p, QRect(x1, y1, x2-x1, y2-y1) ); + + // time1 = QTime::currentTime(); + // printf("%d msec for drawing contents.\n", time2.msecsTo( time1 ) ); + + if(_drawHeader) + drawHeader(&p, x1, y1, x2, y2); + + // time2 = QTime::currentTime();< + // printf("%d msec for drawing header.\n", time1.msecsTo( time2 ) ); + +} + + + +void +xQGanttBarViewPort::drawGrid(QPainter* p, int x1, int y1, int x2, int y2) +//////////////////////////////////////////////////////////////// +{ + y2 += 5; // avoid white lines at bottom of redrawn region + + static int a, w, end, tmp; + static QBrush _sat( QColor(200,200,200)); + static QBrush _sun( QColor(255,110,110)); + static QBrush _hol( QColor(200,200,250)); + static QPen penDay( QColor(235,235,235), 0, DotLine); + static QPen penMonth( QColor(0,150,0), 3, DashDotLine); + static QPen penHour( QColor(0,0,150), 0, DashDotLine); + + QDate start( _toplevelitem->getStart().addSecs(worldX(x1)*60).date() ); + + end = (int) ((x2-x1)/(1440.*_scaleX))+1; + w = (int) (1440. * _scaleX + 0.5); + + // draw holydays + + QDate* ptrDate; + QDate cmp(start.addDays(-1)); + + for(ptrDate = _holidays.first(); ptrDate != 0; ptrDate = _holidays.next() ) { + if(*ptrDate > cmp) { + tmp = _toplevelitem->getStart().secsTo(*ptrDate)/60; + a = screenX( tmp ); + p->fillRect( a, y1, w, y2, _hol ); + } + + } + + // draw grid + + for(int i=0; i<=end; i++, start = start.addDays(1) ) { + + int dayOfWeek = start.dayOfWeek(); + tmp = _toplevelitem->getStart().secsTo(start)/60; + a = screenX( tmp ); + + // draw saturday + if(dayOfWeek == 6) { + + p->fillRect( a, y1, w, y2, _sat ); + + if(start.day() == 1) { + p->setPen( penMonth ); + p->drawLine( a, y1, a, y2); + } + + // continue; + } + + // sunday + if(dayOfWeek == 7) { + + p->fillRect( a, y1, w, y2, _sun ); + + if(start.day() == 1) { + p->setPen( penMonth ); + p->drawLine( a, y1, a, y2); + } + + // continue; + } + + if(start.day() == 1) + p->setPen( penMonth ); + else { + if(dayOfWeek == 1 || dayOfWeek == 6 || dayOfWeek == 7) + continue; + p->setPen( penDay ); + } + + p->drawLine( a, y1, a, y2); + + } +} + + + +void +xQGanttBarViewPort::recalc() +{ + // printf("xQGanttBarViewPort::recalc()\n"); + _gItemList.clear(); + recalc(_toplevelitem, screenX(0), screenY(0), 0, 0 ); + emit recalculated(); +} + + + +void +xQGanttBarViewPort::recalc(KGanttItem* item, int xPos, int yPos, + int depth, int nr) +{ + int tmpTotalHeight = item->getTotalHeight(); + int tmpHeight = item->getHeight(); + + int dd = (int) (0.25 * (double) tmpHeight * _scaleY); + + int _screenW = (int) ((double) item->getWidth() * _scaleX); + int _screenHS = (int) ((double) tmpTotalHeight * _scaleY); + int _screenH = (int) (tmpHeight * _scaleY); + int _textPosY = yPos + (int) (0.7 * (double) tmpHeight * _scaleY); + int _textPosX = xPos + dd + 18; + + xQTaskPosition* tpos = + new xQTaskPosition(nr, xPos, yPos, _screenW, _screenH, _screenHS, + _textPosX, _textPosY, depth); + + _gItemList.replace(item, tpos ); + + tpos->_screenHandleX = xPos + dd; + tpos->_screenHandleW = 2 * dd; + tpos->_screenHandleY = yPos + dd; + tpos->_screenHandleH = 2 * dd; + + + // recalc subitems + + if(item->isOpen()) { + + int h = tmpHeight; + + for(KGanttItem* subitem = item->getSubItems().first(); + subitem != 0; + subitem = item->getSubItems().next() ) { + + recalc(subitem, + xPos + (int)(item->getStart().secsTo(subitem->getStart())/60 * _scaleX), + yPos + (int)( h * _scaleY ), depth + 1, ++nr ); + + h += subitem->getTotalHeight(); + + } + } + +} + + + +void +xQGanttBarViewPort::drawItem(KGanttItem* item, QPainter* p, + const QRect& rect ) +{ + xQTaskPosition* tpos = _gItemList[item]; + + if(!tpos) return; + + if(tpos->_screenX > (rect.x() + rect.width())) return; + if((tpos->_screenX + tpos->_screenW) < rect.x()) return; + if(tpos->_screenY > (rect.y() + rect.height()) ) return; + if((tpos->_screenY + tpos->_screenHS) < rect.y()) return; + + p->setPen(item->getPen()); + p->setBrush(item->getBrush()); + + int style = item->getStyle(); + + if(item->getWidth()==0) { + + p->drawLine(tpos->_screenX, tpos->_screenY, + tpos->_screenX, tpos->_screenY + tpos->_screenH ); + + QPointArray a(4); + a.setPoint(0, tpos->_screenX, tpos->_screenY + _margin ); + a.setPoint(1, tpos->_screenX - tpos->_screenH / 2 + _margin, + tpos->_screenY + tpos->_screenH / 2 ); + a.setPoint(2, tpos->_screenX, tpos->_screenY + tpos->_screenH - _margin ); + a.setPoint(3, tpos->_screenX + tpos->_screenH / 2 - _margin, + tpos->_screenY + tpos->_screenH / 2 ); + p->drawPolygon(a); + + } + else { + + if(style & KGanttItem::DrawFilled ) { + + p->fillRect(tpos->_screenX, tpos->_screenY + _margin, + tpos->_screenW, tpos->_screenHS - 2 * _margin, + item->getBrush() ); + + } + + if(style & KGanttItem::DrawBorder ) { + + p->setBrush(NoBrush); + p->drawRect(tpos->_screenX, tpos->_screenY + _margin, + tpos->_screenW, tpos->_screenHS - 2 * _margin ); + + } + + if(item->isOpen()) { + + // draw relations + for(KGanttRelation* rel = item->getRelations().first(); + rel != 0; + rel = item->getRelations().next() ) { + + drawRelation(p, rel); + + } + + // draw subitems + for(KGanttItem* subitem = item->getSubItems().first(); + subitem != 0; + subitem = item->getSubItems().next() ) { + + drawItem(subitem, p, rect ); + + } + } + + p->setPen(item->getPen()); + p->setBrush(item->getBrush()); + + if(style & KGanttItem::DrawHandle || + ((style & KGanttItem::DrawHandleWSubitems) && item->getSubItems().count()>0) ) { + + /* + p->setBrush(QColor("steelblue")); + p->drawRect(tpos->_screenHandleX, tpos->_screenHandleY, + tpos->_screenHandleW, tpos->_screenHandleH); + */ + if(item->isOpen()) + p->drawPixmap(tpos->_screenHandleX, tpos->_screenHandleY, openedIcon ); + else + p->drawPixmap(tpos->_screenHandleX, tpos->_screenHandleY, closedIcon ); + + } + } + + if(style & KGanttItem::DrawText ) { + p->setPen(item->getTextPen()); + p->drawText(tpos->_textPosX, tpos->_textPosY, item->getText() ); + } + + if(item->isSelected()) { + + p->setPen( QPen(QColor(red),1)); + + p->setBrush(NoBrush); + p->drawRect(tpos->_screenX - 2, tpos->_screenY, + tpos->_screenW + 4, tpos->_screenHS ); + + p->fillRect(tpos->_screenX, tpos->_screenY, 6, 6, + item->getSelectBrush() ); + + p->fillRect(tpos->_screenX + tpos->_screenW - 6, + tpos->_screenY, 6, 6, + item->getSelectBrush() ); + + p->fillRect(tpos->_screenX + tpos->_screenW - 6, + tpos->_screenY + tpos->_screenHS - 6, 6, 6, + item->getSelectBrush() ); + + p->fillRect(tpos->_screenX, + tpos->_screenY + tpos->_screenHS - 6, 6, 6, + item->getSelectBrush() ); + } + +} + + + +void +xQGanttBarViewPort::drawRelation(QPainter* p, + KGanttRelation* rel) +{ + static int hw = 20; + static int margin = 2; + + KGanttItem* from = rel->getFrom(); + KGanttItem* to = rel->getTo(); + + xQTaskPosition* tpos_from = _gItemList[from]; + xQTaskPosition* tpos_to = _gItemList[to]; + + p->setPen(rel->getPen()); + + QPointArray a(6); + + int x,y; + int i=0; + + // 1 + x = tpos_from->_screenX + tpos_from->_screenW + margin; + y = tpos_from->_screenY + tpos_from->_screenH / 2; + a.setPoint(i++, x, y ); + + + // 2 + x = x + hw; + a.setPoint(i++, x, y); + + + // 3 + y = (int)( (tpos_from->_screenY + tpos_from->_screenH/2) * 0.8 + + (tpos_to->_screenY + tpos_to->_screenH/2) * 0.2 ); + a.setPoint(i++, x, y); + + + // 4 + x = tpos_to->_screenX - hw; + y = (int)( (tpos_from->_screenY + tpos_from->_screenH/2) * 0.2 + + (tpos_to->_screenY + tpos_to->_screenH/2) * 0.8 ); + + a.setPoint(i++, x, y); + + + // 5 + y = tpos_to->_screenY + tpos_to->_screenH / 2; + a.setPoint(i++, x, y); + + + // 6 + x = tpos_to->_screenX - margin; + a.setPoint(i++, x, y); + + p->drawPolyline(a); + + p->drawChord( a.point(0).x()-3, a.point(0).y()-3, 6, 6, 0, 5760 ); + + + QPointArray b(3); + + b.setPoint(0, x,y); + b.setPoint(1, x -5, y - 5); + b.setPoint(2, x - 5, y + 5); + + p->drawPolygon(b); + +} + + + +void +xQGanttBarViewPort::drawHeader(QPainter* p, int /*x1*/, int /*y1*/, int /*x2*/, int /*y2*/) +////////////////////////////////////////////////////////////////////////// +{ + bool drawDays = false; + int a,e,tmp; + + QDate start( _toplevelitem->getStart().addSecs(-_marginX * 60 ).date() ); + + // subtract 1 month to draw first month + QDate t(start.year(), start.month()-1, start.day() ); + + QDateTime itemstart = _toplevelitem->getStart(); + + int end = (int) (width()/(1440*_scaleX)); + + if(end < 12) drawDays = true; + + end += 30; // add 30 days to draw last month + + p->setPen( QPen(QColor(black)) ); + + for(int i=0; i<=end; i++, t = t.addDays(1) ) { + + tmp = itemstart.secsTo(t)/60; + a = screenX( tmp ); + + if(t.dayOfWeek() == 1) { + + p->fillRect(a, 0, (int)( 1440*5*_scaleX ), 20, QBrush(QColor(240,240,240))); + p->drawRect(a, 0, (int)( 1440*5*_scaleX ), 20 ); + + if(!drawDays) + p->drawText(a+5, 15, QString::number(t.day()) ); + } + + if(drawDays) { + p->drawText(a+5, 15, t.shortDayName(t.dayOfWeek()) + " " + QString::number(t.day()) ); + } + + if(t.day()==1) { + + e = t.daysInMonth(); + + p->fillRect(a, 21, (int)( 1440*e*_scaleX ), 20, QBrush(QColor(240,240,240))); + p->drawRect(a, 21, (int)( 1440*e*_scaleX ), 20 ); + + if(a<0) a = 0; + p->drawText(a+5, 36, t.shortMonthName(t.month()) ); + + } + + } +} + + + +void +xQGanttBarViewPort::setMode(int mode) +///////////////////////////// +{ + if(_mode == (Mode) mode) { + return; + } + + switch(_mode) { + + case Select: + + setSelect(); + break; + + + case Zoom: + + setZoom(); + break; + + + case Move: + + setMove(); + break; + + + default: + + setCursor(arrowCursor); + setMouseTracking(false); + break; + + } + + emit modeChanged(_mode); + +} + + + +void +xQGanttBarViewPort::setSelect() +//////////////////////////////// +{ + _mode = Select; + setCursor(arrowCursor); + setMouseTracking(true); +} + + + +void +xQGanttBarViewPort::setZoom() +///////////////////////////// +{ + _mode = Zoom; + setCursor( *_cursor_lupe ); + setMouseTracking(false); +} + + + +void +xQGanttBarViewPort::setMove() +////////////////////////////// +{ + _mode = Move; + setCursor( sizeAllCursor ); + setMouseTracking(false); +} + + +void +xQGanttBarViewPort::zoomIn() +{ + zoom(1.2); +} + + +void +xQGanttBarViewPort::zoomOut() +{ + zoom(0.7); +} + + +void +xQGanttBarViewPort::popup(int index) +/////////////////////////////////// +{ + + switch(index) { + + case Select: + case Zoom: + case Move: + + setMode(index); + break; + + case 10: // configure + + // setConfigDialog(); + // _config->show(); + + break; + + } + + +} + + + +void +xQGanttBarViewPort::zoom(double sfactor, int sx, int sy) +/////////////////////////////////////////////////////// +{ + printf("zoom %f, (%d,%d) \n", sfactor, sx, sy ); + + int wx = worldX(sx); + int wy = worldY(sy); + + _scaleX *= sfactor; + + printf("recalc ... \n"); + + recalc(); + adjustSize(); + + _parent->center(screenX(wx), screenY(wy) ); + + QWidget::update(); + + printf("zoom ok.\n"); + +} + + + +void +xQGanttBarViewPort::zoom(double sfactor) +{ + printf("zoom %f \n", sfactor ); + + int x = (int) (_parent->visibleWidth()/2 + 0.5); + int y = (int) (_parent->visibleHeight()/2 + 0.5); + + printf("dx/2 = %d, dy/2 = %d \n", x,y); + + zoom(sfactor, x + _parent->contentsX(), y + _parent->contentsY() ); + +} + + + +void +xQGanttBarViewPort::zoomAll() +{ +#ifdef _DEBUG_ + printf("zoom all. scaleX = %f\n", _scaleX ); +#endif + + _scaleX = ((double) _parent->visibleWidth()*60)/ + ((double) (_toplevelitem->getStart().secsTo(_toplevelitem->getEnd()) + _marginX*120)); + + recalc(); + adjustSize(); + +} + + + +void +xQGanttBarViewPort::addHoliday(int y, int m, int d) +{ + QDate* date = new QDate(y,m,d); + + QDate* ptrDate; + int i=0; + + for(ptrDate = _holidays.first(); + ptrDate != 0; + ptrDate = _holidays.next() ) { + + if(*ptrDate > *date) + break; + + i++; + + } + + _holidays.insert(i,date); + +} + + + +xQGanttBarViewPort::Position +xQGanttBarViewPort::check(KGanttItem** founditem, int x, int y) +{ + QPtrDictIterator it(_gItemList); + + static int ty, ty2, tx, tx2, hx, hx2, hy, hy2; + bool increased; + + while(it.current()) { + + ty = it.current()->_screenY; + ty2 = ty + it.current()->_screenH; + tx = it.current()->_screenX; + tx2 = tx + it.current()->_screenW; + + hx = it.current()->_screenHandleX; + hx2 = hx + it.current()->_screenHandleW; + hy = it.current()->_screenHandleY; + hy2 = hy + it.current()->_screenHandleH; + + increased = false; + + if(tx2-tx<12) { + tx -= 12; + tx2 += 12; + increased = true; + } + + if(x>tx && x < tx2) { + if(y > ty && y < ty2) { + + *founditem = (KGanttItem*) it.currentKey(); + + if(!increased) + if(x > hx && x < hx2 && + y > hy && y < hy2 ) + return Handle; + + if(x < (tx + 5)) + return West; + + if(x > (tx2 - 5)) + return East; + + return Center; + } + + } + + ++it; + + } + + return Outside; + +} + + + +void +xQGanttBarViewPort::unselectAll() +{ + selectItem(_toplevelitem, false); + QWidget::update(); +} + + + +void +xQGanttBarViewPort::selectAll() +{ + selectItem(_toplevelitem, true); + QWidget::update(); +} + + + +void +xQGanttBarViewPort::selectItem(KGanttItem* item, bool f) +{ + item->select(f); + + for(KGanttItem* subitem = item->getSubItems().first(); + subitem != 0; + subitem = item->getSubItems().next() ) { + selectItem(subitem, f); + } + +} + + + +void +xQGanttBarViewPort::deleteSelectedItems() +{ +#ifdef _DEBUG_ + printf("-> xQGanttBarViewPort::deleteSelectedItems()\n"); +#endif + + QPtrList list; + observeList(&list); + + getSelectedItems(_toplevelitem,list); + + for(KGanttItem* subitem = list.first(); + subitem != 0; + subitem =list.next() ) { +#ifdef _DEBUG_ + printf(" : %s \n", subitem->getText().latin1() ); +#endif + connect(subitem, SIGNAL(destroyed(KGanttItem*)), + this, SLOT(itemDestroyed(KGanttItem*))); + } + + list.remove(_toplevelitem); + + while(list.count()>0) { + KGanttItem* item = list.getFirst(); + delete item; + } + +#ifdef _DEBUG_ + printf("<- xQGanttBarViewPort::deleteSelectedItems()\n"); +#endif +} + + + +void +xQGanttBarViewPort::observeList(QPtrList *list) +{ + _observedList = list; +} + + + +void +xQGanttBarViewPort::itemDestroyed(KGanttItem* item) +{ + _observedList->remove(item); +} + + + +void +xQGanttBarViewPort::getSelectedItems (KGanttItem* item, + QPtrList& list) +{ + if(item->isSelected()) list.append(item); + + for(KGanttItem* subitem = item->getSubItems().first(); + subitem != 0; + subitem = item->getSubItems().next() ) { + + getSelectedItems(subitem,list); + + } + +} + + +void +xQGanttBarViewPort::insertIntoSelectedItem() +{ + QPtrList list; + + getSelectedItems(_toplevelitem,list); + + for(KGanttItem* subitem = list.first(); + subitem != 0; + subitem =list.next() ) { +#ifdef _DEBUG_ + printf(" : %s \n", subitem->getText().latin1() ); +#endif + new KGanttItem(subitem, subitem->getText() + "_subitem", + subitem->getStart(), subitem->getEnd()); + } + +} + + + +void +xQGanttBarViewPort::textEdited() +{ + if(_currentItem) { + _currentItem->setText(_itemTextEdit->text()); + setFocus(); + _itemTextEdit->hide(); + } +} +#include "xQGanttBarViewPort.moc" diff --git a/kgantt/kgantt/xQGanttBarViewPort.h b/kgantt/kgantt/xQGanttBarViewPort.h new file mode 100644 index 000000000..7f30ad297 --- /dev/null +++ b/kgantt/kgantt/xQGanttBarViewPort.h @@ -0,0 +1,352 @@ +#ifndef _XQGANTTBARVIEWPORT_H_ +#define _XQGANTTBARVIEWPORT_H_ + +/* + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + author : jh, jochen@ifb.bv.tu-berlin.de + + file : xQGanttBarViewPort.h + date : 26 oct 2000 + + + changelog : + +*/ + + + +#include "KGanttItem.h" + +#include +#include +#include + +#include +#include + +#include +#include +#include + +class xQGanttBarView; + +#define sgn(n) (n < 0 ? -1 : 1) + + +// This is an internal class. +// helper for drawing items + +class xQTaskPosition +//////////////////// +{ + +public : + + xQTaskPosition(int nr, int x, int y, int w, int h, int hiSub, + int tPx, int tPy, int d) + : _nr(nr), _screenX(x), _screenY(y), _screenW(w), _screenH(h), + _screenHS(hiSub), _textPosX(tPx), _textPosY(tPy), _depth(d) + { + _screenHandleX = _screenHandleY = _screenHandleW = _screenHandleH = 0; + } + + int _nr; + int _screenX, _screenY, _screenW; + int _screenH; // height without subitems + int _screenHS; // height including subitems + int _textPosX, _textPosY; + + int _screenHandleX, _screenHandleY, _screenHandleW, _screenHandleH; + + int _depth; + +}; + + + +/// GanttBarViewPort Widget. +/*! + * + */ + +///////////////////////////////////////// +class KDE_EXPORT xQGanttBarViewPort : public QFrame +//////////////////////////////////////// +{ + + Q_OBJECT + + friend class xQGanttBarView; + friend class KGantt; + +public: + + enum Mode {Init, Select, Zoom, Move}; + + + /// Constructor. + /*! + * + */ + xQGanttBarViewPort(KGanttItem* toplevelitem, xQGanttBarView* parent = 0, + const char * name=0, WFlags f=0 ); + + + /// Destructor. + /*! + * + */ + ~xQGanttBarViewPort(); + + + + /// Update widget. + /*! + * + */ + void update(int x1, int y1, int x2, int y2); + + + + QPtrDict _gItemList; + + + /// Add holiday. + /*! + * + */ + void addHoliday(int y, int m, int d); + + + + /// Remove holiday. + /*! + * + */ + void removeHoliday(int y, int m, int d) { + Q_UNUSED(y); Q_UNUSED(m); Q_UNUSED(d); + } + + + + KPopupMenu* menu() { + return _menu; + } + + + + /// + /*! + * + */ + KToolBar* toolbar(QMainWindow* mw = 0); + + + // zoom by factor sfactor and move wx,wy to the center + void zoom(double sfactor, int wx, int wy); + + // zoom by factor, and leave the center unmoved + void zoom(double sfactor); + + + void getSelectedItems(QPtrList& list) { + getSelectedItems(_toplevelitem, list); + } + + +signals: + + void modeChanged(int); + void scroll(int x, int y); + void resized(); + void recalculated(); + void message(const QString& msg); + + +protected slots: + + void setMode(int mode); + + void setSelect(); + void setZoom(); + void setMove(); + + void zoomIn(); + void zoomOut(); + void zoomAll(); + + void popup(int index); + + void selectAll(); + void unselectAll(); + + void deleteSelectedItems(); + void insertIntoSelectedItem(); + + + +private slots: + + void toplevelitemChanged(KGanttItem* item, KGanttItem::Change c); + void textEdited(); + void itemDestroyed(KGanttItem*); + + + +private: + + enum Position { Outside = 0, Handle = 1, + North = 2, South = 4, + West = 8, East = 16, + Center = 32 }; + + /// Transform world coordinate to screen coordinate. + /*! + * + */ + inline int screenX(int wx); + + + /// Transform world coordinate to screen coordinate. + /*! + * + */ + inline int screenY(int wy); + + + /// Transform screen coordinate to world coordinate. + /*! + * + */ + inline int worldX(int sx); + + + /// Transform screen coordinate to world coordinate. + /*! + * + */ + inline int worldY(int sy); + + + // this will be set by setParentScrollView() + xQGanttBarView* _parent; + + int _grid, _snapgrid; + bool _drawGrid, _drawHeader; + + Mode _mode; + + int _marginX, _marginY; // margin in minutes + double _scaleX, _scaleY; + + int _margin; + + + QCursor* _cursor_lupe; + + QLabel* _itemInfo; + QLineEdit* _itemTextEdit; + + + // all item are stored here + KGanttItem* _toplevelitem; + + static KGanttItem* _currentItem; + + KPopupMenu* _menu; + KPopupMenu* _selectMenu; + + KIconLoader* _iconloader; + + KToolBar* _toolbar; + + QPoint* _startPoint, *_endPoint; + + QPtrList _holidays; + + QPtrList *_observedList; + + + /// + + void initMenu(); + + void drawGrid(QPainter*, int x1, int y1, int x2, int y2); + void drawHeader(QPainter*, int x1, int y1, int x2, int y2); + void drawItem(KGanttItem* item, QPainter* p, const QRect& rect ); + + void drawRelation(QPainter*, KGanttRelation*); + + void recalc(KGanttItem* item, int xPos, int yPos, int depth, int nr ); + void recalc(); + + void selectItem(KGanttItem*,bool); + + void getSelectedItems(KGanttItem*, QPtrList&); + + void adjustSize(); + + void observeList(QPtrList*); + + Position check(KGanttItem** founditem, int x, int y); + + void mousePressEvent(QMouseEvent*); + void mouseReleaseEvent(QMouseEvent*); + + void wheelEvent ( QWheelEvent * /*e*/) { + printf("wheelEvent\n"); + } + + void mouseMoveEvent(QMouseEvent*); + void keyPressEvent(QKeyEvent* e); + void paintEvent(QPaintEvent * e); + + + QPixmap closedIcon, openedIcon; + +}; + + + + +// inline + + +int xQGanttBarViewPort::screenX(int wx) +/////////////////////////////////////// +{ + return (int) (0.5 + (wx + _marginX) * _scaleX); +} +int xQGanttBarViewPort::screenY(int wy) +///////////////////////////////////// +{ + return (int) (0.5 + (wy + _marginY) * _scaleY); +} +int xQGanttBarViewPort::worldX(int sx) +///////////////////////////////////// +{ + return (int) (0.5 + (sx/_scaleX - _marginX)); +} +int xQGanttBarViewPort::worldY(int sy) +////////////////////////////////////// +{ + return (int) (0.5 + (sy/_scaleY - _marginY)); +} + + +#endif diff --git a/kgantt/kgantt/xQGanttBarViewPort_Events.cpp b/kgantt/kgantt/xQGanttBarViewPort_Events.cpp new file mode 100644 index 000000000..8609962b7 --- /dev/null +++ b/kgantt/kgantt/xQGanttBarViewPort_Events.cpp @@ -0,0 +1,585 @@ +// +// file : xQGanttBarViewPort_Events.C +// date : 11 nov 2000 +// changed : 27 dec 2000 +// author : jh +// + + +#include "xQGanttBarViewPort.h" +#include "xQGanttBarView.h" + +#include + +KGanttItem* xQGanttBarViewPort::_currentItem; + + +static int _currentMButton; +static bool _Mousemoved; +static bool _selectItem; + +static int _timediff; + +static bool _changeEnd, _changeStart; +static int oldw = -1, oldx = -1; + +QDateTime _tmpStartDateTime, _tmpEndDateTime; + + +void +xQGanttBarViewPort::mousePressEvent(QMouseEvent* e) +{ + // set _currentItem to pushed mousebutton + _currentMButton = e->button(); + _Mousemoved = false; + + _startPoint->setX( e->x() ); + _startPoint->setY( e->y() ); + + _endPoint->setX( e->x() ); + _endPoint->setY( e->y() ); + + _itemInfo->hide(); + _itemTextEdit->hide(); + + // right mousebutton & control -> popup menu + if(e->button() == RightButton && e->state() == ControlButton ) { + _menu->popup(e->globalPos()); + return; + } + + + /* + * get clicked item and position + */ + _currentItem = NULL; + Position pos = check(&_currentItem, e->x(), e->y()); + + if(!_currentItem) { + unselectAll(); + return; + } + + + /* + * edit text + */ + if(e->button() == MidButton && _mode == Select) { + + xQTaskPosition* tp = _gItemList.find(_currentItem); + QPainter p(this); + + QRect rect = p.boundingRect(tp->_textPosX, + tp->_textPosY, 200, + tp->_screenH, AlignLeft, _currentItem->getText() ); + + _itemTextEdit->setText(_currentItem->getText()); + _itemTextEdit->move(tp->_textPosX, tp->_screenY + _margin + 1); + _itemTextEdit->setFixedWidth(rect.width()+40); + _itemTextEdit->setFixedHeight(tp->_screenH - 2 * _margin - 2); + _itemTextEdit->setFocus(); + + // if item is not editable, _itemTextEdit should be not editable + // as well + _itemTextEdit->setReadOnly(!_currentItem->isEditable()); + + _itemTextEdit->show(); + + } + + + /* + * open/close item, move start, end, item + */ + if(e->button() == LeftButton && _mode == Select) { + + _timediff = 0; + + switch(pos) { + + case Handle: + + _currentItem->open( !_currentItem->isOpen() ); + break; + + case Center: + + _changeEnd = true; + _changeStart = true; + + if(e->state() == ShiftButton) { + + QString tmp; tmp.sprintf("%s\n", _currentItem->getText().latin1() ); + + tmp += _currentItem->getStart().toString(); + tmp += " - "; + tmp += _currentItem->getEnd().toString(); + + _itemInfo->setText( tmp ); + _itemInfo->adjustSize(); + + _itemInfo->move(e->x() + 25, _gItemList.find(_currentItem)->_screenY - 50 ); + _itemInfo->show(); + } + else + _selectItem = true; + + break; + + + case East: + + _changeEnd = true; + _changeStart = false; + break; + + + case West: + + _changeStart = true; + _changeEnd = false; + break; + + default : + break; + + } + + + + } // if(e->button() == LeftButton && _mode == Select) + +} + + + +void +xQGanttBarViewPort::mouseReleaseEvent(QMouseEvent* e) +{ + switch(_mode) { + + case Select: { + + if(_Mousemoved == true) { + + _itemInfo->hide(); + + if(_changeStart == true || _changeEnd == true) { + + if(_changeStart == true) { + _currentItem->setStart( _tmpStartDateTime ); + } + if(_changeEnd == true) { + _currentItem->setEnd( _tmpEndDateTime ); + } + + oldx = -1; oldw = -1; + + recalc(); + QWidget::update(); + + } + } + else { + if(_currentItem && _selectItem) { + + + if(e->state() & ControlButton) { + _currentItem->select( !_currentItem->isSelected() ); + } + else { + bool state = _currentItem->isSelected(); + unselectAll(); + _currentItem->select( !state ); + } + + QWidget::update(); + _selectItem = false; + + } + } + + _changeEnd = false; + _changeStart = false; + + } + break; + + + case Zoom: + + if(!_Mousemoved) { + + if(e->button() == LeftButton) + zoom(1.4, e->x(), e->y() ); + + + if(e->button() == RightButton) + zoom(0.7, e->x(), e->y() ); + + + if(e->button() == MidButton) + zoomAll(); + + } + else { + + if(_currentMButton == LeftButton) { + + QPainter p(this); + QPen pen(DashLine); + pen.setColor(red); + p.setRasterOp(XorROP); + p.setPen( pen ); + + p.drawRect(_startPoint->x(), + _startPoint->y(), + _endPoint->x()-_startPoint->x(), + _endPoint->y() - _startPoint->y()); + + double x1 = _startPoint->x(); + double y1 = _startPoint->y(); + + double x2 = _endPoint->x(); + double y2 = _endPoint->y(); + + double sys_width = fabs(x2 - x1); + + double mass = (_parent->visibleWidth()/ sys_width); + + zoom(mass, (int) (x1+(x2-x1)/2), (int) (y1+(y2-y1)/2) ); + + + } + } + + break; + + + default: + break; + + } + + _Mousemoved = false; + _currentMButton = 0; + +} + + + +void +xQGanttBarViewPort::mouseMoveEvent(QMouseEvent* e) +{ + if(fabs((float)(_startPoint->x() - e->x())) < 2 && + fabs((float)(_startPoint->y() - e->y())) < 2 ) + return; + + static QPen _dashPen(QColor(255,0,0),DashLine); + static QPen _solidPen(QColor(200,200,200)); + + _Mousemoved = true; + + switch(_mode) { + + case Select: { + + if(_currentMButton == LeftButton && _currentItem) { + + QPainter p(this); + p.setRasterOp(XorROP); + // QPen pen(DashLine); + // pen.setColor(red); + p.setPen( _dashPen ); + + QString stmp; + stmp.sprintf("%s\n", _currentItem->getText().latin1() ); + + int pixeldiff = e->x() - _startPoint->x(); + _timediff = (int) ((double) pixeldiff / _scaleX + 0.5 ); + + xQTaskPosition* tpos = _gItemList[_currentItem]; + + int x = tpos->_screenX; int w = tpos->_screenW; + + if(_changeStart && _changeEnd) { + double tmp = (double) _timediff/(double) _snapgrid; + _timediff = ((int) (tmp + sgn(tmp) * 0.5)) * _snapgrid; + stmp += _currentItem->getStart().addSecs(_timediff*60).toString(); + stmp += " - "; + stmp += _currentItem->getEnd().addSecs(_timediff*60).toString(); + x += (int) (_timediff * _scaleX); + + _tmpStartDateTime = _currentItem->getStart().addSecs(_timediff*60); + _tmpEndDateTime = _currentItem->getEnd().addSecs(_timediff*60); + + } + else { + + if(_changeStart) { + + QDateTime movedStart( _currentItem->getStart().addSecs(_timediff*60) ); + + _tmpStartDateTime.setDate( movedStart.date() ); + _tmpStartDateTime.setTime(QTime(0,0,0,0)); + + double diff = _tmpStartDateTime.secsTo(movedStart)/60; + + double tmp = diff/(double) _snapgrid; + _timediff = ((int) (tmp + sgn(tmp) * 0.5)) * _snapgrid; + + _tmpStartDateTime = _tmpStartDateTime.addSecs(_timediff*60); + _timediff = _currentItem->getStart().secsTo(_tmpStartDateTime)/60; + + stmp += _tmpStartDateTime.toString().latin1(); + stmp += " - "; + stmp += _currentItem->getEnd().toString(); + + x += (int) (_timediff * _scaleX); + w -= (int) (_timediff * _scaleX); + } + + if(_changeEnd) { + + QDateTime movedEnd( _currentItem->getEnd().addSecs(_timediff*60) ); + + _tmpEndDateTime.setDate( movedEnd.date() ); + _tmpEndDateTime.setTime(QTime(0,0,0,0)); + + double diff = _tmpEndDateTime.secsTo(movedEnd)/60; + + double tmp = diff/(double) _snapgrid; + _timediff = ((int) (tmp + sgn(tmp) * 0.5)) * _snapgrid; + + _tmpEndDateTime = _tmpEndDateTime.addSecs(_timediff*60); + _timediff = _currentItem->getEnd().secsTo(_tmpEndDateTime)/60; + + stmp += _currentItem->getStart().toString(); + stmp += " - "; + stmp += _tmpEndDateTime.toString().latin1(); + + w += (int) (_timediff * _scaleX); + + } + + } + + _itemInfo->setText( stmp ); + _itemInfo->adjustSize(); + _itemInfo->move(e->x() + 25, _gItemList.find(_currentItem)->_screenY - 50); + _itemInfo->show(); + + if(oldx > 0) { + p.fillRect(oldx, _gItemList.find(_currentItem)->_screenY, + oldw, _gItemList.find(_currentItem)->_screenH, + QBrush(QColor(50,50,50), Dense4Pattern)); + p.drawRect(oldx, _gItemList.find(_currentItem)->_screenY, + oldw, _gItemList.find(_currentItem)->_screenH); + + p.setPen(_solidPen); + if(_changeStart) + p.drawLine(oldx, 0, oldx, height()); + if(oldw > 2) + if(_changeEnd) + p.drawLine(oldx + oldw, 0, oldx + oldw, height()); + + } + + p.setPen(_dashPen); + p.fillRect(x, _gItemList.find(_currentItem)->_screenY, + w, _gItemList.find(_currentItem)->_screenH, + QBrush(QColor(50,50,50), Dense4Pattern) ); + p.drawRect(x, _gItemList.find(_currentItem)->_screenY, + w, _gItemList.find(_currentItem)->_screenH); + + p.setPen(_solidPen); + if(_changeStart) + p.drawLine(x, 0, x, height()); + + if(w>2) + if(_changeEnd) + p.drawLine(x + w, 0, x + w, height()); + + oldx = x; oldw = w; + + } + else { + + static Position _pos = Outside; + + KGanttItem* item = NULL; + + Position pos = check(&item, e->x(), e->y()); + + if(_pos != pos) { + + _pos = pos; + + if(pos == West || pos == East) { + setCursor( splitHCursor ); + break; + } + if(pos == North || pos == South) { + setCursor( splitVCursor ); + break; + } + if(pos == Center) { + setCursor( upArrowCursor); + break; + } + if(pos == Handle) { + setCursor(pointingHandCursor); + break; + } + + setCursor(arrowCursor); + + } + } + } + break; + + + case Zoom: { + + if(_currentMButton == LeftButton) { + + static QString strpos; + + strpos = ""; + + int s = worldX(_startPoint->x()); + QDateTime d1 = _toplevelitem->getStart().addSecs(s*60); + + s = worldX(e->x()); + QDateTime d2 = _toplevelitem->getStart().addSecs(s*60); + + strpos += d1.date().toString(); + strpos += " - "; + strpos += d2.date().toString(); + + emit message(strpos); + + QPainter p(this); + QPen pen(DashLine); + pen.setColor(red); + + p.setRasterOp(XorROP); + + p.setPen( pen ); + + p.drawRect(_startPoint->x(), + _startPoint->y(), + _endPoint->x()-_startPoint->x(), + _endPoint->y() - _startPoint->y()); + + QBrush _selectedbrush( QColor(50,50,50), Dense4Pattern ); + + p.fillRect( _startPoint->x(), _startPoint->y(), + _endPoint->x()-_startPoint->x(), _endPoint->y() - _startPoint->y(), + _selectedbrush ); + + _endPoint->setX( e->x() ); + _endPoint->setY( e->y() ); + + + p.drawRect(_startPoint->x(), _startPoint->y(), + _endPoint->x()-_startPoint->x(), _endPoint->y() - _startPoint->y()); + + p.fillRect( _startPoint->x(), _startPoint->y(), + _endPoint->x()-_startPoint->x(), _endPoint->y() - _startPoint->y(), + _selectedbrush ); + } + + } + + break; + + case Move: { + emit scroll(_startPoint->x() - e->x(), _startPoint->y() - e->y() ); + } + break; + + + default : + break; + + } +} + + +void +xQGanttBarViewPort::keyPressEvent(QKeyEvent* e) +{ + + printf("xQGanttBarViewPort::keyPressEvent() key = %d \n", e->key() ); + + int dx = 15; + + if(e->state() == ControlButton) + dx *= 10; + + switch(e->key()) { + + case Key_Left: + + emit scroll(-dx,0); + break; + + case Key_Right: + + emit scroll(dx,0); + break; + + case Key_Up: + + emit scroll(0,-dx); + break; + + case Key_Down: + + emit scroll(0, dx); + break; + + case 43: // + + + zoom(1.4); + break; + + case 45: // - + + zoom(0.7); + break; + + case 4103: // del + + deleteSelectedItems(); + break; + + case 4102: // einfg + + insertIntoSelectedItem(); + break; + + case 4119: // bild v + + emit scroll(0, dx*15); + break; + + case 4118: // bild ^ + + emit scroll(0,-dx*15); + break; + + } + +} + + +void +xQGanttBarViewPort::paintEvent(QPaintEvent * e) +///////////////////////////////////////////////// +{ + update(e->rect().left(), e->rect().top(), + e->rect().right(), e->rect().bottom() ); +} diff --git a/kgantt/kgantt/xQGanttListView.cpp b/kgantt/kgantt/xQGanttListView.cpp new file mode 100644 index 000000000..01b4ac246 --- /dev/null +++ b/kgantt/kgantt/xQGanttListView.cpp @@ -0,0 +1,75 @@ +// +// file : xQGanttListView.C +// date : 23 nov 2000 +// changed : +// author : jh +// + +#include "xQGanttListView.h" + +#include +#include + +xQGanttListView::xQGanttListView(KGanttItem* toplevelitem, QWidget* parent, + const char * name, WFlags f) + : QScrollView(parent,name,f) +///////////////////////////////////////////////////////// +{ + _toplevelitem = toplevelitem; + + setFrameStyle(QFrame::Sunken); + setLineWidth(1); + + _headerBackBrush = QBrush(QColor(230,230,230)); + + setMargins( 1, TOPMARGIN , 1, 1 ); + + setVScrollBarMode( AlwaysOff ); + + _viewport = new xQGanttListViewPort(toplevelitem,viewport()); + addChild(_viewport); + + viewport()->setBackgroundColor(QColor(white)); + +} + + + +xQGanttListView::~xQGanttListView() +/////////////////////////////////// +{ +} + + +void +xQGanttListView::drawHeader() +/////////////////////////////// +{ + // printf("xQGanttListView::drawHeader()\n"); + + QPainter p(this); + p.setPen( QPen(QColor(black)) ); + p.fillRect(0,0,width(),TOPMARGIN, _headerBackBrush ); + + p.drawText(5, (int)(0.8 * TOPMARGIN), i18n("Items")); + +} + + + +void +xQGanttListView::contentsMoved(int x, int y) +//////////////////////////////////////////// +{ + printf("xQGanttListView::contentsMoved(%d,%d)\n", x, y); + setContentsPos( 0, y ); +} + + + +void +xQGanttListView::paintEvent(QPaintEvent * /*e*/) +{ + drawHeader(); +} +#include "xQGanttListView.moc" diff --git a/kgantt/kgantt/xQGanttListView.h b/kgantt/kgantt/xQGanttListView.h new file mode 100644 index 000000000..36a2bbc02 --- /dev/null +++ b/kgantt/kgantt/xQGanttListView.h @@ -0,0 +1,107 @@ +#ifndef _XQGANTTLISTVIEW_H_ +#define _XQGANTTLISTVIEW_H_ + +/* + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + author : jh, jochen@ifb.bv.tu-berlin.de + + file : xQGanttListView.h + date : 23 nov 2000 + + + changelog : + +*/ + + + + +#include "xQGanttBarView.h" +#include "xQGanttListViewPort.h" + +#include + + + +/// GanttListView Widget. +/*! + * + */ + +////////////////////////////////////////////// +class xQGanttListView : public QScrollView +////////////////////////////////////////////// +{ + + Q_OBJECT + + +public: + + + /// Constructor. + /*! + * + */ + xQGanttListView(KGanttItem* toplevelitem, QWidget* parent = 0, + const char * name=0, WFlags f=0 ); + + + /// Destructor. + /*! + * + */ + ~xQGanttListView(); + + + + /// Connect barview to this listview. + /*! + * + */ + void setBarView(xQGanttBarView* v) { + ((xQGanttListViewPort*) _viewport)->setBarViewPort(v->viewport()); + } + + + +public slots: + + void contentsMoved(int,int); + + +protected: + + // ptr to toplevelitem + KGanttItem* _toplevelitem; + + QBrush _headerBackBrush; + + xQGanttBarView* _barview; + xQGanttListViewPort* _viewport; + + void drawHeader(); + void paintEvent(QPaintEvent * e); + +}; + + + + + +#endif diff --git a/kgantt/kgantt/xQGanttListViewPort.cpp b/kgantt/kgantt/xQGanttListViewPort.cpp new file mode 100644 index 000000000..573d8fbe9 --- /dev/null +++ b/kgantt/kgantt/xQGanttListViewPort.cpp @@ -0,0 +1,175 @@ +// +// file : xQGanttListViewPort.C +// date : 26 oct 2000 +// changed : 29 nov 2000 +// author : jh +// + +#include "xQGanttListViewPort.h" + +#include + + +int xQGanttListViewPort::_ListViewCounter = 0; + + +xQGanttListViewPort::xQGanttListViewPort(KGanttItem* toplevelitem, QWidget* parent, + const char * name, WFlags f ) + : QFrame(parent,name,f) +{ + _toplevelitem = toplevelitem; + + setBackgroundColor(QColor(white)); + + _barviewport = NULL; + + _width = 1000; + + brush1 = QBrush(QColor(200,200,230)); + brush2 = QBrush(QColor(240,240,240)); + +} + + + +xQGanttListViewPort::~xQGanttListViewPort() +///////////////////////////////////////// +{ +} + + + +void +xQGanttListViewPort::setBarViewPort(xQGanttBarViewPort* v) +{ + _barviewport = v; + + // printf("setBarViewPort()\n"); + + resize(500, _barviewport->height()); + + printf("setBarViewPort()\n"); + + connect(_barviewport, SIGNAL(resized()), + this, SLOT(barViewResized())); + + + connect(_barviewport, SIGNAL(recalculated()), + this, SLOT(update())); + + /* + connect(_barviewport, SIGNAL(contentsRepainted()), + this, SLOT(barViewRepainted())); + */ +} + + + +void +xQGanttListViewPort::barViewResized() +////////////////////////////////////// +{ + printf("xQGanttListViewPort::barViewResized()\n"); + + static int _h = 0; + + int h = _barviewport->height(); + + if(h!=_h) { + _h = h; + resize(_width, _h); + } + +} + + + +void +xQGanttListViewPort::drawContents(QPainter* p, int x1, int y1, int x2, int y2) +////////////////////////////////////////////////////////////////////////////// +{ + /*printf("\nxQGanttListViewPort::drawContents(%d,%d,%d,%d)\n", + x1, y1, x2, y2 ); + */ + + _ListViewCounter = 0; + + if(_barviewport) { + drawItem(_toplevelitem, p, QRect(x1, y1, x2-x1, y2-y1), 5 ); + } + +} + + + +void +xQGanttListViewPort::drawItem(KGanttItem* item, QPainter* p, const QRect& rect, + int offsetX ) +///////////////////////////////////////////////////////////////////////////// +{ + static int margin = 2; + + xQTaskPosition* tpos = _barviewport->_gItemList[item]; + + if(!tpos) return; + + if( (tpos->_screenY+5 >= rect.y() && + tpos->_screenY-5 <= rect.y() + rect.height()) || + ((tpos->_screenY + tpos->_screenH)+5 >= rect.y() && + (tpos->_screenY + tpos->_screenH)-5 <= rect.y() + rect.height() ) ) { + + p->setPen(QPen(QColor(black))); + + int y = tpos->_screenY; + int h = tpos->_screenH; + + if(tpos->_nr % 2 == 0) + p->fillRect(0 + margin, y + margin , + _width - 2 * margin, h - 2 * margin, brush1); + else + p->fillRect(0 + margin, y + margin, + _width - 2* margin, h - 2* margin, brush2); + + QString str = item->getText() + " [" + + item->getStart().toString() + " / " + + item->getEnd().toString() + "]"; + + p->drawText(offsetX, tpos->_textPosY, str ); + + } + + + if(item->isOpen() && item->getSubItems().count()>0) { + + for(KGanttItem* subitem = item->getSubItems().first(); + subitem != 0; + subitem = item->getSubItems().next() ) { + + drawItem(subitem, p, rect, offsetX + 20); + + } + + p->setPen(QPen(QColor(blue),2)); + p->drawLine(offsetX + 3, tpos->_textPosY + 3, + offsetX + 3, tpos->_screenY + tpos->_screenHS - 3); + + } + +} + + +void +xQGanttListViewPort::update(int x1, int y1, int x2, int y2) +///////////////////////////////////////////////// +{ + QPainter p(this); + + /* + printf("\nxQGanttListViewPort::update(%d,%d,%d,%d)\n", + x1, y1, x2, y2 ); + */ + drawContents(&p, x1, y1, x2, y2); + +} + +#include "xQGanttListViewPort.moc" diff --git a/kgantt/kgantt/xQGanttListViewPort.h b/kgantt/kgantt/xQGanttListViewPort.h new file mode 100644 index 000000000..d133d129b --- /dev/null +++ b/kgantt/kgantt/xQGanttListViewPort.h @@ -0,0 +1,131 @@ +#ifndef _XQGANTTLISTVIEWPORT_H_ +#define _XQGANTTLISTVIEWPORT_H_ + +/* + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + author : jh, jochen@ifb.bv.tu-berlin.de + + file : xQGanttListViewPort.h + date : 26 oct 2000 + + + changelog : + +*/ + + + +#include "xQGanttBarViewPort.h" +#include "KGanttItem.h" + + +#include + + + +/// GanttListViewPort Widget. +/*! + * + */ + +//////////////////////////////////////////// +class xQGanttListViewPort : public QFrame +//////////////////////////////////////////// +{ + + Q_OBJECT + + friend class xQGanttListView; + + +public: + + + /// Constructor. + /*! + * + */ + xQGanttListViewPort(KGanttItem* toplevelitem, QWidget* parent = 0, + const char * name=0, WFlags f=0 ); + + + + /// Destructor. + /*! + * + */ + ~xQGanttListViewPort(); + + + +public slots: + + void barViewResized(); + + +protected: + + /// Update widget. + /*! + * + */ + void update(int x1, int y1, int x2, int y2); + + + /// + /*! + * + */ + void setBarViewPort(xQGanttBarViewPort* v); + + + void drawContents(QPainter*, int x1, int y1, int x2, int y2); + void drawItem(KGanttItem*, QPainter* p, const QRect&, int); + + xQGanttBarViewPort* _barviewport; + + int _width; + + KGanttItem* _toplevelitem; + + void paintEvent(QPaintEvent * e) { + // printf("xQGanttListViewPort::paintEvent()\n"); + update(e->rect().left(), e->rect().top(), + e->rect().right(), e->rect().bottom() ); + } + + QPopupMenu* _menu; + + void mousePressEvent(QMouseEvent* e) { + + if(e->button() == RightButton && e->state() == ControlButton ) { + _menu->popup(e->globalPos()); + return; + } + + } + + + QBrush brush1, brush2; + + static int _ListViewCounter; + +}; + + +#endif diff --git a/kgantt/pixmaps/Makefile.am b/kgantt/pixmaps/Makefile.am new file mode 100644 index 000000000..39843e8d5 --- /dev/null +++ b/kgantt/pixmaps/Makefile.am @@ -0,0 +1,2 @@ +kgantticondir = $(kde_datadir)/kgantt/icons +kgantticon_ICON = AUTO diff --git a/kgantt/pixmaps/cr16-action-ganttSelect.png b/kgantt/pixmaps/cr16-action-ganttSelect.png new file mode 100644 index 000000000..e302cd217 Binary files /dev/null and b/kgantt/pixmaps/cr16-action-ganttSelect.png differ diff --git a/kgantt/pixmaps/cr16-action-ganttSelecttask.png b/kgantt/pixmaps/cr16-action-ganttSelecttask.png new file mode 100644 index 000000000..4abafb283 Binary files /dev/null and b/kgantt/pixmaps/cr16-action-ganttSelecttask.png differ diff --git a/kgantt/pixmaps/cr16-action-ganttUnselecttask.png b/kgantt/pixmaps/cr16-action-ganttUnselecttask.png new file mode 100644 index 000000000..e4a86de1f Binary files /dev/null and b/kgantt/pixmaps/cr16-action-ganttUnselecttask.png differ diff --git a/kgantt/pixmaps/cr22-action-ganttSelect.png b/kgantt/pixmaps/cr22-action-ganttSelect.png new file mode 100644 index 000000000..7b59068a3 Binary files /dev/null and b/kgantt/pixmaps/cr22-action-ganttSelect.png differ diff --git a/kgantt/pixmaps/cr22-action-ganttSelecttask.png b/kgantt/pixmaps/cr22-action-ganttSelecttask.png new file mode 100644 index 000000000..da05ab127 Binary files /dev/null and b/kgantt/pixmaps/cr22-action-ganttSelecttask.png differ diff --git a/kgantt/pixmaps/cr22-action-ganttUnselecttask.png b/kgantt/pixmaps/cr22-action-ganttUnselecttask.png new file mode 100644 index 000000000..733af7e33 Binary files /dev/null and b/kgantt/pixmaps/cr22-action-ganttUnselecttask.png differ diff --git a/kgantt/pixmaps/cr32-action-ganttSelect.png b/kgantt/pixmaps/cr32-action-ganttSelect.png new file mode 100644 index 000000000..4b0d545b8 Binary files /dev/null and b/kgantt/pixmaps/cr32-action-ganttSelect.png differ diff --git a/kgantt/pixmaps/cr32-action-ganttSelecttask.png b/kgantt/pixmaps/cr32-action-ganttSelecttask.png new file mode 100644 index 000000000..da05ab127 Binary files /dev/null and b/kgantt/pixmaps/cr32-action-ganttSelecttask.png differ diff --git a/kgantt/pixmaps/cr32-action-ganttUnselecttask.png b/kgantt/pixmaps/cr32-action-ganttUnselecttask.png new file mode 100644 index 000000000..733af7e33 Binary files /dev/null and b/kgantt/pixmaps/cr32-action-ganttUnselecttask.png differ -- cgit v1.2.1