当前位置: 首页>>代码示例>>C++>>正文


C++ Task::deadlineTime方法代码示例

本文整理汇总了C++中Task::deadlineTime方法的典型用法代码示例。如果您正苦于以下问题:C++ Task::deadlineTime方法的具体用法?C++ Task::deadlineTime怎么用?C++ Task::deadlineTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Task的用法示例。


在下文中一共展示了Task::deadlineTime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: paint

void TaskDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    {
        Task task;
        task.setName(index.data(Task::NameRole).toString());
        task.setDescription(index.data(Task::DescriptionRole).toString());
        task.setPriority(index.data(Task::PriorityRole).toInt());
        task.setDeadlineTime(index.data(Task::DeadlineRole).toDateTime());
        task.setCompleted(index.data(Task::CompleteStatusRole).toBool());
        task.setPrivate(index.data(Task::PrivateRole).toBool());
        task.setCreateDate(index.data(Task::CreatedRole).toDate());
        task.setRepeatType((Task::RepeatType)index.data(Task::RepeatRole).toInt());

        QImage priorityImage(task.priorityIcon());




        QColor taskTextColor;
        if (option.state & QStyle::State_Selected)
        {
            if (task.deadlineTime()<QDateTime::currentDateTime() && task.deadlineTime().isValid() && !task.completed())
            {
                QColor bgColor(255,65,204);
                QBrush brush(bgColor);



                painter->fillRect(option.rect, brush);

            } else
            QStyledItemDelegate::paint(painter, option, index);
        } else if (task.deadlineTime()<QDateTime::currentDateTime() && task.deadlineTime().isValid() && !task.completed())
        {
            QColor bgColor(255,91,91);
            QBrush brush(bgColor);

            painter->fillRect(option.rect, brush);
        }

        else {
            QBrush brush = (index.row()%2)?option.palette.base():option.palette.alternateBase();
            taskTextColor.setRgb(255-brush.color().red(),
                                 255-brush.color().green(),
                                 255-brush.color().blue());

            painter->fillRect(option.rect, brush);
            }
            painter->save();
            QFont taskFont = getTaskFont(option);
            QFont descriptionFont = getDescriptionFont(option);
            QFont dateFont = getDateFont(option);
            QFont timeFont = getTimeFont(option);

            QFontMetrics fmTaskFont(taskFont);
            QFontMetrics fmDescriptionFont(descriptionFont);
            QFontMetrics fmDateFont(dateFont);
            int dateWidth=fmDateFont.width(task.deadlineTime().date().toString(Qt::SystemLocaleShortDate));

            painter->setPen(Qt::black);

            painter->setFont(taskFont);
            QRect nameRect=option.rect.adjusted(priorityImage.width(),4, -dateWidth-10,0);
            painter->drawText(nameRect,Qt::AlignHCenter, fmTaskFont.elidedText(task.name(),Qt::ElideRight,nameRect.width()-70,0));


            QRect descriptionRect=option.rect.adjusted(priorityImage.width(),30,-dateWidth-10,0);
            painter->setFont(descriptionFont);

            painter->drawText(descriptionRect,Qt::AlignHCenter,
                              fmDescriptionFont.elidedText(task.description().replace("\n"," "),Qt::ElideRight,descriptionRect.width()));


            painter->drawImage(option.rect.adjusted(0,3,-(option.rect.width()-priorityImage.width()),-(option.rect.height()-priorityImage.height())),priorityImage);
            if (task.completed()%2==1)
            {
                QImage completeImage=QImage(":/icons/task-complete");
                painter->drawImage(option.rect.adjusted(10,10,-(option.rect.width()-priorityImage.width()+10),-(option.rect.height()-priorityImage.height())-10),completeImage);
            }
            if ((int)task.repeatType()>0)
            {
                QImage completeImage=QImage(":/icons/clock");
                painter->drawImage(option.rect.adjusted(priorityImage.width(),5,-(option.rect.width()-completeImage.width()),-(option.rect.height()-completeImage.height())),completeImage);
            }

            painter->setFont(dateFont);

            painter->drawText(option.rect.adjusted((option.rect.width()-dateWidth-10),8,0,0),Qt::AlignHCenter,task.deadlineTime().date().toString(Qt::SystemLocaleShortDate));

            painter->setFont(timeFont);
            painter->drawText(option.rect.adjusted((option.rect.width()-dateWidth-10),20,0,0),Qt::AlignHCenter,task.deadlineTime().time().toString(Qt::SystemLocaleShortDate));

            if (task.isPrivate() && !task.completed())
            {
                QImage privateImage(":/icons/private");
                painter->drawImage(option.rect.adjusted(10,10,-(option.rect.width()-priorityImage.width()+10),-(option.rect.height()-priorityImage.height())-10),privateImage);
            }
            painter->restore();

        }
//.........这里部分代码省略.........
开发者ID:BGCX262,项目名称:ztasklist-svn-to-git,代码行数:101,代码来源:taskdelegate.cpp


注:本文中的Task::deadlineTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。