00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "qxtscheduleview_p.h"
00027 #include "qxtscheduleview.h"
00028 #include <QPainter>
00029 #include <QScrollBar>
00030 #include <QBrush>
00031 #include <QMouseEvent>
00032 #include <QDebug>
00033 #include <QApplication>
00034 #include <QTimer>
00035 #include <QStringList>
00036 #include <QWidget>
00037 #include <QList>
00038 #include <QListIterator>
00039 #include <QMutableLinkedListIterator>
00040
00041 #include "qxtscheduleheaderwidget.h"
00042
00043
00044
00045 int QxtScheduleViewPrivate::offsetToVisualColumn(const int iOffset) const
00046 {
00047 if (iOffset >= 0)
00048 return iOffset / qxt_p().rows();
00049 return -1;
00050 }
00051
00052 int QxtScheduleViewPrivate::visualIndexToOffset(const int iRow, const int iCol) const
00053 {
00054 return (iCol* qxt_p().rows()) + iRow;
00055 }
00056
00057 int QxtScheduleViewPrivate::offsetToVisualRow(const int iOffset) const
00058 {
00059 if (iOffset >= 0 && qxt_p().model())
00060 return iOffset % qxt_p().rows();
00061 return -1;
00062 }
00063
00064 QVector< QRect > QxtScheduleViewPrivate::calculateRangeGeometries(const int iStartOffset, const int iEndOffset) const
00065 {
00066 QVector<QRect> rects;
00067
00068 if (iStartOffset < 0 || iEndOffset < 0)
00069 return rects;
00070
00071 if (iEndOffset < iStartOffset)
00072 return rects;
00073
00074 int iCurrentStartOffset = iStartOffset;
00075 int iCurrentEndOffset;
00076
00077 do
00078 {
00079 if (offsetToVisualColumn(iCurrentStartOffset) == offsetToVisualColumn(iEndOffset))
00080 iCurrentEndOffset = iEndOffset;
00081 else
00082 iCurrentEndOffset = visualIndexToOffset(m_vHeader->count() - 1, offsetToVisualColumn(iCurrentStartOffset));
00083
00084 qint32 iLeft = m_hHeader->sectionPosition(offsetToVisualColumn(iCurrentStartOffset));
00085 qint32 iTop = m_vHeader->sectionPosition(offsetToVisualRow(iCurrentStartOffset));
00086 qint32 iBottom = m_vHeader->sectionPosition(offsetToVisualRow(iCurrentEndOffset)) + m_vHeader->sectionSize(offsetToVisualRow(iCurrentEndOffset));
00087 qint32 iRight = m_hHeader->sectionPosition(offsetToVisualColumn(iCurrentEndOffset)) + m_hHeader->sectionSize(offsetToVisualColumn(iCurrentEndOffset));
00088 rects.append(QRect(iLeft + 1, iTop + 1, iRight - iLeft - 1, iBottom - iTop - 1));
00089
00090 iCurrentStartOffset = visualIndexToOffset(0, offsetToVisualColumn(iCurrentEndOffset) + 1);
00091
00092 }
00093 while (iCurrentEndOffset < iEndOffset);
00094
00095 return rects;
00096
00097 }
00098
00099 int QxtScheduleViewPrivate::pointToOffset(const QPoint & point)
00100 {
00101 int iRow = m_vHeader->visualIndexAt(point.y());
00102 int iCol = m_hHeader->visualIndexAt(point.x());
00103 return visualIndexToOffset(iRow, iCol);
00104 }
00105
00106
00107
00108 QxtScheduleInternalItem * QxtScheduleViewPrivate::internalItemAt(const QPoint & pt)
00109 {
00110 QListIterator<QxtScheduleInternalItem *>iterator(m_Items);
00111 QxtScheduleInternalItem *currentItem;
00112 iterator.toBack();
00113 while (iterator.hasPrevious())
00114 {
00115 currentItem = iterator.previous();
00116 if (currentItem->contains(pt))
00117 return currentItem;
00118 }
00119 return 0;
00120 }
00121
00122
00123 void QxtScheduleViewPrivate::reloadItemsFromModel()
00124 {
00125 qDeleteAll(m_Items.begin(), m_Items.end());
00126 m_Items.clear();
00127 m_selectedItem = NULL;
00128
00129 int iNumItems = qxt_p().model()->rowCount();
00130
00131 QxtScheduleInternalItem *currentItem;
00132 for (int iLoop = 0; iLoop < iNumItems; iLoop++)
00133 {
00134 currentItem = new QxtScheduleInternalItem(&qxt_p(), qxt_p().model()->index(iLoop, 0));
00135 m_Items.append(currentItem);
00136 connect(currentItem, SIGNAL(geometryChanged(QxtScheduleInternalItem*, QVector<QRect>)), this, SLOT(itemGeometryChanged(QxtScheduleInternalItem * , QVector< QRect >)));
00137 }
00138
00139 handleItemConcurrency(0, (qxt_p().rows()*qxt_p().cols()) - 1);
00140 }
00141
00142 void QxtScheduleViewPrivate::init()
00143 {
00144 if (qxt_p().model())
00145 {
00146 qxt_p().viewport()->setMouseTracking(true);
00147
00148 if (!m_vHeader)
00149 {
00150 m_vHeader = new QxtScheduleHeaderWidget(Qt::Vertical, &qxt_p());
00151 connect(m_vHeader, SIGNAL(geometriesChanged()), &qxt_p(), SLOT(updateGeometries()));
00152 }
00153 m_vHeader->show();
00154
00155 if (!m_hHeader)
00156 {
00157 m_hHeader = new QxtScheduleHeaderWidget(Qt::Horizontal, &qxt_p());
00158 connect(m_hHeader, SIGNAL(geometriesChanged()), &qxt_p(), SLOT(updateGeometries()));
00159 }
00160 m_hHeader->show();
00161
00162
00163 m_vHeader->setDefaultSectionSize(20);
00164 m_vHeader->setResizeMode(QHeaderView::Fixed);
00165 reloadItemsFromModel();
00166 }
00167 qxt_p().updateGeometries();
00168 }
00169
00173 QList< QLinkedList<QxtScheduleInternalItem *> > QxtScheduleViewPrivate::findConcurrentItems(const int from, const int to) const
00174 {
00175 QList< QLinkedList<QxtScheduleInternalItem *> > allConcurrentItems;
00176
00177 QList<QxtScheduleInternalItem *> allItemsSorted = m_Items;
00178
00179 if(m_Items.size() == 0)
00180 return allConcurrentItems;
00181
00182 qSort(allItemsSorted.begin(), allItemsSorted.end(), qxtScheduleItemLessThan);
00183
00184 int startItem = 0;
00185 int endItem = allItemsSorted.size() - 1;
00186
00187
00188 for (int i = 0; i < allItemsSorted.size(); i++)
00189 {
00190 if (i > 0)
00191 {
00192 if (!(allItemsSorted.at(i - 1)->visualEndTableOffset() >= allItemsSorted.at(i)->visualStartTableOffset()
00193 && allItemsSorted.at(i - 1)->visualStartTableOffset() <= allItemsSorted.at(i)->visualEndTableOffset()))
00194 startItem = i;
00195 }
00196
00197 if (allItemsSorted.at(i)->visualEndTableOffset() >= from && allItemsSorted.at(i)->visualStartTableOffset() <= to)
00198 break;
00199 }
00200
00201
00202 for (int i = allItemsSorted.size() - 1; i >= 0 ; i--)
00203 {
00204 if (i < allItemsSorted.size() - 1)
00205 {
00206 if (!(allItemsSorted.at(i + 1)->visualEndTableOffset() >= allItemsSorted.at(i)->visualStartTableOffset()
00207 && allItemsSorted.at(i + 1)->visualStartTableOffset() <= allItemsSorted.at(i)->visualEndTableOffset()))
00208 endItem = i;
00209 }
00210
00211 if (allItemsSorted.at(i)->visualEndTableOffset() >= from && allItemsSorted.at(i)->visualStartTableOffset() <= to)
00212 break;
00213 }
00214
00215 int startOffset = allItemsSorted.at(startItem)->visualStartTableOffset();
00216 int endOffset = allItemsSorted.at(endItem)->visualEndTableOffset();
00217
00218
00219 QLinkedList<QxtScheduleInternalItem *> concurrentItems;
00220 for (int iAllItemLoop = startItem; iAllItemLoop <= endItem; iAllItemLoop++)
00221 {
00222 int tempStartOffset = allItemsSorted.at(iAllItemLoop)->visualStartTableOffset();
00223 int tempEndOffset = allItemsSorted.at(iAllItemLoop)->visualEndTableOffset();
00224
00225 if (tempEndOffset >= startOffset && tempStartOffset <= endOffset)
00226 {
00227
00228 if (concurrentItems.size() >= 1)
00229 {
00230 bool bAppend = false;
00231
00232
00233
00234
00235 for (QLinkedList<QxtScheduleInternalItem *>::iterator it = concurrentItems.begin(); it != concurrentItems.end(); ++it)
00236 {
00237 int lastStartOffset = (*it)->visualStartTableOffset();
00238 int lastEndOffset = (*it)->visualEndTableOffset();
00239
00240 if (tempEndOffset >= lastStartOffset && tempStartOffset <= lastEndOffset)
00241 {
00242 bAppend = true;
00243 break;
00244 }
00245 }
00246
00247 if (bAppend)
00248 {
00249 concurrentItems.append(allItemsSorted.at(iAllItemLoop));
00250 }
00251 else
00252 {
00253 allConcurrentItems.append(concurrentItems);
00254 concurrentItems.clear();
00255 concurrentItems.append(allItemsSorted.at(iAllItemLoop));
00256 }
00257 }
00258 else
00259 concurrentItems.append(allItemsSorted.at(iAllItemLoop));
00260
00261 if (tempStartOffset < startOffset)
00262 startOffset = tempStartOffset;
00263
00264 if (tempEndOffset > endOffset)
00265 endOffset = tempEndOffset;
00266 }
00267 }
00268 if (concurrentItems.size() > 0)
00269 allConcurrentItems.append(concurrentItems);
00270
00271 return allConcurrentItems;
00272 }
00273
00274 void QxtScheduleViewPrivate::handleItemConcurrency(const int from, const int to)
00275 {
00276
00277 if (from < 0 || to < 0 || m_Items.size() == 0){
00278
00279 qxt_p().viewport()->update();
00280 return;
00281 }
00282
00283 qDebug() << "handleItemConcurrency";
00284
00285 if (handlesConcurrency)
00286 return;
00287
00288 handlesConcurrency = true;
00289
00290 QList< QLinkedList<QxtScheduleInternalItem *> > allConcurrentItems = findConcurrentItems(from, to);
00291
00292
00293
00294
00295
00296
00297
00298
00299 QList< QList< QxtScheduleInternalItem *> >virtualTable;
00300
00301 for (int iListLoop = 0; iListLoop < allConcurrentItems.size(); iListLoop++)
00302 {
00303 QLinkedList<QxtScheduleInternalItem *> & currentItems = allConcurrentItems[iListLoop];
00304 QList< QxtScheduleInternalItem * > currentColumn;
00305
00306 qDebug() << "handle overlapping for " << currentItems.size() << " Items";
00307
00308 virtualTable.clear();
00309
00310
00311
00312 while (currentItems.size())
00313 {
00314 QMutableLinkedListIterator< QxtScheduleInternalItem * > iter(currentItems);
00315
00316 while (iter.hasNext())
00317 {
00318 iter.next();
00319
00320 if (currentColumn.isEmpty() || currentColumn[currentColumn.size()-1]->visualEndTableOffset() < iter.value()->visualStartTableOffset())
00321 {
00322 currentColumn.append(iter.value());
00323 iter.remove();
00324 continue;
00325 }
00326 }
00327
00328 if (!currentColumn.isEmpty())
00329 {
00330 virtualTable.append(currentColumn);
00331 currentColumn.clear();
00332 }
00333 }
00334
00335 qDebug() << "Found columns" << virtualTable.size();
00336
00337
00338 for (int col = 0; col < virtualTable.size(); col++)
00339 {
00340 for (int item = 0; item < virtualTable.at(col).size() ; item++)
00341 {
00342 int startVisualCol = offsetToVisualColumn(virtualTable[col][item]->visualStartTableOffset());
00343 QVector<QRect> geo = virtualTable[col][item]->geometry();
00344
00345 for (int rect = 0; rect < geo.size(); rect++)
00346 {
00347 int sectionStart = m_hHeader->sectionPosition(startVisualCol);
00348 int fullWidth = m_hHeader->sectionSize(startVisualCol);
00349 int oneItemWidth = fullWidth / virtualTable.size();
00350 int itemWidth = oneItemWidth;
00351 int itemXStart = (col * oneItemWidth) + sectionStart;
00352 int overlap = oneItemWidth / 10;
00353 int adjustX1 = 0;
00354 int adjustX2 = 0;
00355
00356
00357 int possibleCols = 1;
00358 bool foundCollision;
00359
00360 for (int tmpCol = col + 1; tmpCol < virtualTable.size(); tmpCol++)
00361 {
00362 foundCollision = false;
00363 for (int tmpItem = 0; tmpItem < virtualTable.at(tmpCol).size() ; tmpItem++)
00364 {
00365 if ((virtualTable[tmpCol][tmpItem]->visualEndTableOffset() >= virtualTable[col][item]->visualStartTableOffset()
00366 && virtualTable[tmpCol][tmpItem]->visualStartTableOffset() <= virtualTable[col][item]->visualEndTableOffset()))
00367 {
00368 foundCollision = true;
00369 break;
00370 }
00371 }
00372
00373 if (!foundCollision)
00374 possibleCols++;
00375 else
00376 break;
00377 }
00378
00379 if (virtualTable.size() > 1)
00380 {
00381 if (col == 0)
00382 adjustX2 = overlap;
00383 else if (col == virtualTable.size() - 1)
00384 {
00385 adjustX1 = -overlap;
00386 adjustX2 = overlap;
00387 }
00388 else
00389 {
00390 if (col + possibleCols == virtualTable.size())
00391 adjustX2 = overlap;
00392 else
00393 adjustX2 = overlap * 2;
00394
00395 adjustX1 = -overlap;
00396 }
00397 }
00398
00399
00400 itemWidth = oneItemWidth * possibleCols;
00401
00402 qDebug() << "orginial rect" << geo[rect];
00403 geo[rect].setLeft(itemXStart + adjustX1);
00404 geo[rect].setWidth(itemWidth + adjustX2);
00405 qDebug() << "new rect" << geo[rect];
00406
00407
00408 startVisualCol++;
00409 }
00410 virtualTable[col][item]->setGeometry(geo);
00411 }
00412 }
00413 }
00414 handlesConcurrency = false;
00415 qxt_p().viewport()->update();
00416 }
00417
00418 QxtScheduleViewPrivate::QxtScheduleViewPrivate()
00419 {
00420 m_Cols = 0;
00421 m_vHeader = 0;
00422 m_hHeader = 0;
00423 m_Model = 0;
00424 m_selectedItem = 0;
00425 handlesConcurrency = false;
00426 delegate = 0;
00427 m_zoomStepWidth = 0;
00428
00429 connect(&scrollTimer, SIGNAL(timeout()), this, SLOT(scrollTimerTimeout()));
00430 }
00431
00432 void QxtScheduleViewPrivate::itemGeometryChanged(QxtScheduleInternalItem * item, QVector< QRect > oldGeometry)
00433 {
00434 QRegion oldRegion;
00435
00436 if (item->geometry() == oldGeometry)
00437 return;
00438
00439 QVectorIterator<QRect> iter(oldGeometry);
00440 QRect currRect;
00441 while (iter.hasNext())
00442 {
00443 currRect = iter.next();
00444 currRect.adjust(-1, -1, 2, 2);
00445 oldRegion += currRect;
00446 }
00447
00448
00449
00450 QRegion newRegion;
00451 QVectorIterator<QRect> newIter(item->geometry());
00452 while (newIter.hasNext())
00453 {
00454 currRect = newIter.next();
00455 currRect.adjust(-1, -1, 2, 2);
00456 newRegion += currRect;
00457 }
00458
00459 qxt_p().viewport()->update();
00460 }
00461
00462 int QxtScheduleViewPrivate::unixTimeToOffset(const uint constUnixTime, bool indexEndTime) const
00463 {
00464 uint unixTime = constUnixTime;
00465 if (unixTime >= m_startUnixTime && unixTime <= m_endUnixTime)
00466 {
00467 if (indexEndTime)
00468 {
00469 unixTime -= m_currentZoomDepth;
00470 }
00471 qint32 rows = qxt_p().rows();
00472 qint32 iOffset = unixTime - m_startUnixTime;
00473
00474
00475 iOffset = qRound((qreal)iOffset / (qreal)m_currentZoomDepth);
00476
00477 qint32 iCol = iOffset / rows;
00478 qint32 iRow = iOffset % rows;
00479 return visualIndexToOffset(iRow, iCol);
00480 }
00481
00482 return -1;
00483 }
00484
00485 void QxtScheduleViewPrivate::scrollTimerTimeout()
00486 {
00487 QPoint globalPos = QCursor::pos();
00488 QPoint viewportPos = qxt_p().viewport()->mapFromGlobal(globalPos);
00489
00490 int iScrollVertical = this->m_vHeader->defaultSectionSize();
00491 int iScrollHorizontal = this->m_hHeader->defaultSectionSize();
00492
00493 if (viewportPos.y() <= iScrollVertical)
00494 {
00495 int iCurrPos = qxt_p().verticalScrollBar()->value();
00496 if (iCurrPos > qxt_p().verticalScrollBar()->minimum() + iScrollVertical)
00497 {
00498 qxt_p().verticalScrollBar()->setValue(iCurrPos - iScrollVertical);
00499 }
00500 else
00501 qxt_p().verticalScrollBar()->setValue(qxt_p().verticalScrollBar()->minimum());
00502
00503 }
00504 else if (viewportPos.y() >= qxt_p().viewport()->height() - iScrollVertical)
00505 {
00506 int iCurrPos = qxt_p().verticalScrollBar()->value();
00507 if (iCurrPos < qxt_p().verticalScrollBar()->maximum() - iScrollVertical)
00508 {
00509 qxt_p().verticalScrollBar()->setValue(iCurrPos + iScrollVertical);
00510 }
00511 else
00512 qxt_p().verticalScrollBar()->setValue(qxt_p().verticalScrollBar()->maximum());
00513 }
00514
00515 if (viewportPos.x() <= iScrollHorizontal / 2)
00516 {
00517 int iCurrPos = qxt_p().horizontalScrollBar()->value();
00518 if (iCurrPos > qxt_p().horizontalScrollBar()->minimum() + iScrollHorizontal)
00519 {
00520 qxt_p().horizontalScrollBar()->setValue(iCurrPos - iScrollHorizontal);
00521 }
00522 else
00523 qxt_p().horizontalScrollBar()->setValue(qxt_p().horizontalScrollBar()->minimum());
00524
00525 }
00526 else if (viewportPos.x() >= qxt_p().viewport()->width() - (iScrollHorizontal / 2))
00527 {
00528 int iCurrPos = qxt_p().horizontalScrollBar()->value();
00529 if (iCurrPos < qxt_p().horizontalScrollBar()->maximum() - iScrollHorizontal)
00530 {
00531 qxt_p().horizontalScrollBar()->setValue(iCurrPos + iScrollHorizontal);
00532 }
00533 else
00534 qxt_p().horizontalScrollBar()->setValue(qxt_p().horizontalScrollBar()->maximum());
00535 }
00536
00537 }
00538
00539 int QxtScheduleViewPrivate::offsetToUnixTime(const int offset, bool indexEndTime) const
00540 {
00541 qint32 rows = qxt_p().rows();
00542 uint unixTime = (offsetToVisualRow(offset) + (offsetToVisualColumn(offset) * rows)) * m_currentZoomDepth;
00543 unixTime += m_startUnixTime;
00544
00545 if (indexEndTime)
00546 {
00547 unixTime += m_currentZoomDepth;
00548 }
00549
00550 if (unixTime >= m_startUnixTime && unixTime <= m_endUnixTime + 1)
00551 return unixTime;
00552 return -1;
00553 }
00554
00555
00556 QxtScheduleInternalItem::QxtScheduleInternalItem(QxtScheduleView *parent, QModelIndex index, QVector<QRect> geometries)
00557 : QObject(parent), m_iModelRow(index.row()), m_geometries(geometries)
00558 {
00559 m_moving = false;
00560 if (parent)
00561 {
00562 if (index.isValid())
00563 {
00564 if (m_geometries.empty())
00565 {
00566 int startOffset = this->startTableOffset();
00567 int endOffset = startOffset + this->rows() - 1;
00568 m_geometries = parent->qxt_d().calculateRangeGeometries(startOffset, endOffset);
00569 }
00570 }
00571 }
00572 }
00573
00574 QxtScheduleView * QxtScheduleInternalItem::parentView() const
00575 {
00576 return qobject_cast<QxtScheduleView *>(parent());
00577 }
00578
00582 int QxtScheduleInternalItem::visualStartTableOffset() const
00583 {
00584 if (m_geometries.size() == 0 || !parentView())
00585 return -1;
00586
00587
00588 if (!m_moving)
00589 return startTableOffset();
00590
00591 int offset = parentView()->qxt_d().pointToOffset(parentView()->mapToViewport((this->geometry()[0].topLeft())));
00592 return offset;
00593 }
00594
00598 int QxtScheduleInternalItem::visualEndTableOffset() const
00599 {
00600 if (m_geometries.size() == 0 || !parentView())
00601 return -1;
00602
00603
00604 if (!m_moving)
00605 return endTableOffset();
00606
00607 QRect rect = m_geometries[m_geometries.size()-1];
00608 int endTableOffset = parentView()->qxt_d().pointToOffset(parentView()->mapToViewport(rect.bottomRight()));
00609 return endTableOffset;
00610 }
00611
00612 bool QxtScheduleInternalItem::setData(QVariant data, int role)
00613 {
00614 if (parentView() && parentView()->model())
00615 {
00616 return parentView()->model()->setData(modelIndex(), data, role);
00617 }
00618 return false;
00619 }
00620
00621 QVariant QxtScheduleInternalItem::data(int role) const
00622 {
00623 if (modelIndex().isValid())
00624 return modelIndex().data(role);
00625 return QVariant();
00626 }
00627
00628 int QxtScheduleInternalItem::startTableOffset() const
00629 {
00630 if (parentView() && parentView()->model())
00631 {
00632 int startTime = data(Qxt::ItemStartTimeRole).toInt();
00633 int zoomDepth = parentView()->currentZoomDepth(Qxt::Second);
00634
00635 qint32 offset = startTime - parentView()->qxt_d().m_startUnixTime;
00636
00637
00638
00639 if (offset % zoomDepth)
00640 {
00641 int lower = offset / zoomDepth * zoomDepth;
00642 int upper = lower + zoomDepth;
00643
00644 offset = (offset - lower >= upper - offset ? upper : lower);
00645
00646 return parentView()->qxt_d().unixTimeToOffset(offset + parentView()->qxt_d().m_startUnixTime);
00647 }
00648
00649 return parentView()->qxt_d().unixTimeToOffset(startTime);
00650 }
00651 return -1;
00652 }
00653
00654 int QxtScheduleInternalItem::endTableOffset() const
00655 {
00656 return startTableOffset() + rows() - 1;
00657 }
00658
00659 void QxtScheduleInternalItem::setStartTableOffset(int iOffset)
00660 {
00661 if (parentView() && parentView()->model())
00662 {
00663 setData(parentView()->qxt_d().offsetToUnixTime(iOffset), Qxt::ItemStartTimeRole);
00664 }
00665 }
00666
00667 void QxtScheduleInternalItem::setRowsUsed(int rows)
00668 {
00669 if (parentView() && parentView()->model())
00670 {
00671 int seconds = rows * parentView()->currentZoomDepth(Qxt::Second);
00672 setData(seconds, Qxt::ItemDurationRole);
00673 }
00674 }
00675
00676 int QxtScheduleInternalItem::rows() const
00677 {
00678 if (parentView() && parentView()->model())
00679 {
00680 int iNumSecs = data(Qxt::ItemDurationRole).toInt();
00681 int zoomDepth = parentView()->currentZoomDepth(Qxt::Second);
00682
00683
00684
00685 if (iNumSecs % zoomDepth)
00686 {
00687 int lower = iNumSecs / zoomDepth * zoomDepth;
00688 int upper = lower + zoomDepth;
00689
00690 return (iNumSecs - lower >= upper - iNumSecs ? (upper / zoomDepth) : (lower / zoomDepth));
00691
00692 }
00693 return (iNumSecs / zoomDepth);
00694 }
00695 return -1;
00696 }
00697
00698 bool qxtScheduleItemLessThan(const QxtScheduleInternalItem * item1, const QxtScheduleInternalItem * item2)
00699 {
00700 if (item1->visualStartTableOffset() < item2->visualStartTableOffset())
00701 return true;
00702 if (item1->visualStartTableOffset() == item2->visualStartTableOffset() && item1->modelIndex().row() < item2->modelIndex().row())
00703 return true;
00704 return false;
00705 }
00706
00707 bool QxtScheduleInternalItem::contains(const QPoint & pt)
00708 {
00709 QVectorIterator<QRect> iterator(this->m_geometries);
00710 while (iterator.hasNext())
00711 {
00712 if (iterator.next().contains(pt))
00713 return true;
00714 }
00715 return false;
00716 }
00717
00718 void QxtScheduleInternalItem::setGeometry(const QVector< QRect > geo)
00719 {
00720 if (!this->parent())
00721 return;
00722
00723 QVector<QRect> oldGeo = this->m_geometries;
00724 this->m_geometries.clear();
00725 this->m_geometries = geo;
00726 emit geometryChanged(this, oldGeo);
00727 }
00728
00729 QVector< QRect > QxtScheduleInternalItem::geometry() const
00730 {
00731 return this->m_geometries;
00732 }
00733
00734 void QxtScheduleInternalItem::startMove()
00735 {
00736
00737 this->m_SavedGeometries = this->m_geometries;
00738 m_moving = true;
00739 }
00740
00741 void QxtScheduleInternalItem::resetMove()
00742 {
00743 this->setGeometry(this->m_SavedGeometries);
00744 this->m_SavedGeometries.clear();
00745 m_moving = false;
00746 }
00747
00748 void QxtScheduleInternalItem::stopMove()
00749 {
00750 this->m_SavedGeometries.clear();
00751 m_moving = false;
00752 }
00753
00754 QModelIndex QxtScheduleInternalItem::modelIndex() const
00755 {
00756 QModelIndex indx;
00757 if (parentView() && parentView()->model())
00758 {
00759 indx = parentView()->model()->index(this->m_iModelRow, 0);
00760 }
00761 return indx;
00762 }