korganizer
cellitem.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "cellitem.h"
00026
00027 #include <klocale.h>
00028 #include <kdebug.h>
00029
00030 #include <qintdict.h>
00031
00032 using namespace KOrg;
00033
00034 QString CellItem::label() const
00035 {
00036 return i18n("<undefined>");
00037 }
00038
00039 QPtrList<CellItem> CellItem::placeItem( QPtrList<CellItem> cells,
00040 CellItem *placeItem )
00041 {
00042 kdDebug(5855) << "Placing " << placeItem->label() << endl;
00043
00044 QPtrList<KOrg::CellItem> conflictItems;
00045 int maxSubCells = 0;
00046 QIntDict<KOrg::CellItem> subCellDict;
00047
00048
00049 QPtrListIterator<KOrg::CellItem> it2( cells );
00050 for( it2.toFirst(); it2.current(); ++it2 ) {
00051 KOrg::CellItem *item = it2.current();
00052 if ( item == placeItem ) continue;
00053
00054 if ( item->overlaps( placeItem ) ) {
00055 kdDebug(5855) << " Overlaps: " << item->label() << endl;
00056
00057 conflictItems.append( item );
00058 if ( item->subCells() > maxSubCells ) maxSubCells = item->subCells();
00059 subCellDict.insert( item->subCell(), item );
00060 }
00061 }
00062
00063 if ( conflictItems.count() > 0 ) {
00064
00065 int i;
00066 for( i = 0; i < maxSubCells; ++i ) {
00067 kdDebug(5855) << " Trying subcell " << i << endl;
00068 if ( !subCellDict.find( i ) ) {
00069 kdDebug(5855) << " Use subcell " << i << endl;
00070 placeItem->setSubCell( i );
00071 break;
00072 }
00073 }
00074 if ( i == maxSubCells ) {
00075 kdDebug(5855) << " New subcell " << i << endl;
00076 placeItem->setSubCell( maxSubCells );
00077 maxSubCells++;
00078 }
00079
00080 kdDebug(5855) << " Sub cells: " << maxSubCells << endl;
00081
00082
00083 conflictItems.append( placeItem );
00084 placeItem->setSubCells( maxSubCells );
00085
00086 QPtrListIterator<KOrg::CellItem> it3( conflictItems );
00087 for( it3.toFirst(); it3.current(); ++it3 ) {
00088 (*it3)->setSubCells( maxSubCells );
00089 }
00090
00091 } else {
00092 kdDebug(5855) << " no conflicts" << endl;
00093 placeItem->setSubCell( 0 );
00094 placeItem->setSubCells( 1 );
00095 }
00096
00097 return conflictItems;
00098 }
|