예제 #1
0
void TimeScene::drawTime(DateTime currentDay, DTime time, QModelIndex index, int groupLevel) {
    QSize size = sizeHint(index);
    int bordermargin = (size.height() * .1) / 2;

    QBrush b;
    QPen pen(QColor(0, 0, 150));
    QBrush textBrush;
    if (groupLevel == 2) {
        b = QBrush(Qt::white);
        pen = QPen(QColor(0, 0, 150));
        textBrush = QBrush(Qt::darkBlue);
    }
    if (groupLevel == 1) {
        b = QBrush(Qt::lightGray);
        pen = QPen(QColor(0, 0, 50));
        textBrush = QBrush(Qt::blue);
    }
    if (groupLevel == 0) {
        b = QBrush(Qt::darkGray);
        pen = QPen(QColor(100, 100, 200));
        textBrush = QBrush(Qt::white);
    }

    int daysToStart = _startDate.daysTo(currentDay);
    int x1 = daysToStart * _dayWidth;
    int y1 = _currentY + bordermargin;
    int x2 = x1 + _dayWidth;
    int y2 = _currentY + size.height() - bordermargin;

//    QGraphicsRectItem* item = this->addRect(x1, y1, (x2 - x1), (y2 - y1), pen, b);
    QRect rect(x1, y1, (x2 - x1), (y2 - y1));
    GraphicsRectItem* item = new GraphicsRectItem(rect, index);
    this->addItem(item);
    item->setPen(pen);
    item->setBrush(b);
    item->setZValue(1);
    item->setAcceptHoverEvents(true);

    connect(item, SIGNAL(itemHoverEnter(QModelIndex)), this, SLOT(receiveItemHoverEnter(QModelIndex)));
    connect(item, SIGNAL(itemHoverLeave(QModelIndex)), this, SLOT(receiveItemHoverLeave(QModelIndex)));

    QFont font("Arial", 8);

    font.setBold((groupLevel <= 1));
    font.setItalic((groupLevel == 0));

    QGraphicsSimpleTextItem* text = addSimpleText(time.toQString(), font);
    text->setBrush(textBrush);
    text->setPos(x1 + 2, y1 + 1);
    text->setVisible(true);
    text->setZValue(1);
}
예제 #2
0
 QVariant TaskItem::data(int column, int role) const
 {
     if (_type == BLANK) {
         return QVariant();
     }
     if (column == 1) {
         if (role == Qt::DisplayRole) {
             return QVariant();
         }
     } else {
         if (role != Qt::DisplayRole) {
             return QVariant();
         }
     }
     switch(column) {
     case 0:
         if (_type == PROJECT) {
             return QString(_project->name()->c_str());
         }
         if (_type == TASK) {
             return QString(_task->shortDescription()->c_str());
         }
         if (_type == NONE) {
             return itemData.at(column);
         }
         if (_type == SUMMARY) {
             return "Projects";
         }
     case 1:
         // Closed
         switch (_type) {
         case PROJECT:
         case NONE:
         case SUMMARY:
             return QVariant();
         case TASK:
             return QVariant(_task->isClosed() ? Qt::Checked : Qt::Unchecked);
             return false;
         }
     case 2:
         if (_type == PROJECT) {
             return _project->totalTime().toQString();
         }
         if (_type == TASK) {
             return _task->totalTime().toQString();
         }
         if (_type == NONE) {
             return itemData.at(column);
         }
         if (_type == SUMMARY) {
             DTime totalTime;
             for (std::vector<Project*>::const_iterator iter = _allprojects.begin(); iter != _allprojects.end(); iter++) {
                 Project *prj = *iter;
                 totalTime = totalTime + prj->totalTime();
             }
             return totalTime.toQString();
         }
     case 3:
         if (_type == PROJECT) {
             return _project->totalTimeCurrentWeek().toQString();
         }
         if (_type == TASK) {
             return _task->totalTimeCurrentWeek().toQString();
         }
         if (_type == NONE) {
             return itemData.at(column);
         }
         if (_type == SUMMARY) {
             DTime totalTime;
             for (vector<Project*>::const_iterator iter = _allprojects.begin(); iter != _allprojects.end(); iter++) {
                 Project* prj = *iter;
                 totalTime = totalTime + prj->totalTimeCurrentWeek();
             }
             return totalTime.toQString();
         }
     case 4:
         if (_type == PROJECT) {
             return _project->totalTimeCurrentDay().toQString();
         }
         if (_type == TASK) {
             return _task->totalTimeCurrentDay().toQString();
         }
         if (_type == NONE) {
             return itemData.at(column);
         }
         if (_type == SUMMARY) {
             DTime totalTime;
             for (vector<Project*>::const_iterator iter = _allprojects.begin(); iter != _allprojects.end(); iter++) {
                 Project* prj = *iter;
                 totalTime = totalTime + prj->totalTimeCurrentDay();
             }
             return totalTime.toQString();
         }
     default:
         return QVariant();
     }
 }