Ejemplo n.º 1
0
bool EventsListView::viewportEvent(QEvent *event)
{
    if (event->type() != QEvent::ToolTip && event->type() != QEvent::WhatsThis) {
        return QListView::viewportEvent(event);
    }

    QPoint global_pos = QCursor::pos();
    QPoint viewport_pos = viewport()->mapFromGlobal(global_pos);
    QModelIndex index = indexAt(viewport_pos);
    if (!index.isValid()) {
        return true;
    }

    EventItem *item = getItem(index);
    if (!item) {
        return true;
    }

    QRect item_rect = visualRect(index);

    QString text = "<p style='white-space:pre'>";
    text += item->event().desc;
    text += "</p>";

    QToolTip::showText(QCursor::pos(), text, viewport(), item_rect);

    return true;
}
Ejemplo n.º 2
0
void DateItem::dropEvent(QGraphicsSceneDragDropEvent* e)
{
    EventItem* eventItem = dynamic_cast<EventItem*>(parentItem());
    if(eventItem)
    {
        eventItem->handleDrop(e);
    }
}
Ejemplo n.º 3
0
void DateItem::mousePressEvent(QGraphicsSceneMouseEvent* e)
{
    parentItem()->setZValue(2.);
    EventItem* eventItem = dynamic_cast<EventItem*>(parentItem());
    if(eventItem)// && e->button() == Qt::LeftButton)
    {
        eventItem->setSelected(true);
        mEventsScene->itemClicked(eventItem, e);
        e->accept();
    }
    QGraphicsObject::mousePressEvent(e);
}
Ejemplo n.º 4
0
void ProfileGraphicsView::plot_one_event(struct event *ev)
{
	int i, depth = 0;
	struct plot_info *pi = &gc.pi;

	/* is plotting of this event disabled? */
	if (ev->name) {
		for (i = 0; i < evn_used; i++) {
			if (! strcmp(ev->name, ev_namelist[i].ev_name)) {
				if (ev_namelist[i].plot_ev)
					break;
				else
					return;
			}
		}
	}

	if (ev->time.seconds < 30 && !strcmp(ev->name, "gaschange"))
		/* a gas change in the first 30 seconds is the way of some dive computers
		 * to tell us the gas that is used; let's not plot a marker for that */
		return;

	for (i = 0; i < pi->nr; i++) {
		struct plot_data *data = pi->entry + i;
		if (ev->time.seconds < data->sec)
			break;
		depth = data->depth;
	}

	/* draw a little triangular marker and attach tooltip */

	int x = SCALEXGC(ev->time.seconds);
	int y = SCALEYGC(depth);

	EventItem *item = new EventItem();
	item->setPos(x, y);
	scene()->addItem(item);

	/* we display the event on screen - so translate */
	QString name = tr(ev->name);
	if (ev->value) {
		if (ev->name && name == "gaschange") {
			unsigned int he = ev->value >> 16;
			unsigned int o2 = ev->value & 0xffff;

			name += ": ";
			name += (he) ? QString("%1/%2").arg(o2, he)
				  : (o2 == 21) ? name += tr("air")
				  : QString("%1% %2").arg(o2).arg("O" UTF8_SUBSCRIPT_2);

		} else if (ev->name && !strcmp(ev->name, "SP change")) {
Ejemplo n.º 5
0
void EventsListModel::onAvatarUpdated(const QString& email, const QImage& img)
{
    int i, n = rowCount();

    for (i = 0; i < n; i++) {
        QStandardItem *qitem = item(i);
        if (qitem->type() != EVENT_ITEM_TYPE) {
            return;
        }
        EventItem *item = (EventItem *)qitem;

        if (item->event().author == email) {
            QModelIndex index = indexFromItem(item);
            emit dataChanged(index, index);
        }
    }
}
Ejemplo n.º 6
0
QRectF DateItem::boundingRect() const
{
    QGraphicsItem* parent = parentItem();
    if(parent)
    {
        EventItem* eventItem = dynamic_cast<EventItem*>(parent);
        if(eventItem)
        {
            QRectF pr = eventItem->boundingRect();
            QRectF r(-pr.width()/2 + eventItem->mBorderWidth + eventItem->mEltsMargin,
                     0,
                     pr.width() - 2*(eventItem->mBorderWidth + eventItem->mEltsMargin),
                     eventItem->mEltsHeight);
            return r;
        }
    }
    return QRectF(0, 0, 100, 30);
}
Ejemplo n.º 7
0
void EventsListView::onItemDoubleClicked(const QModelIndex& index)
{
    EventItem *item = getItem(index);
    if (!item) {
        return;
    }

    const SeafEvent& event = item->event();

    if (!event.isDetailsDisplayable()) {
        return;
    }

    EventDetailsDialog* dialog = new EventDetailsDialog(event, seafApplet->mainWindow());
    dialog->setAttribute(Qt::WA_DeleteOnClose, true);
    dialog->show();
    dialog->raise();
    dialog->activateWindow();
}
Ejemplo n.º 8
0
void EventItemDelegate::paint(QPainter *painter,
                              const QStyleOptionViewItem& option,
                              const QModelIndex& index) const
{
    QBrush backBrush;
    bool selected = false;

    EventItem *item = getItem(index);
    if (!item) {
        return;
    }

    const SeafEvent& event = item->event();
    QString operation_text = event.op_desc;
    QString time_text = translateCommitTime(event.timestamp);

    if (option.state & (QStyle::State_HasFocus | QStyle::State_Selected)) {
        backBrush = QColor(kEventItemBackgroundColorHighlighted);
        selected = true;

    } else {
        backBrush = QColor(kEventItemBackgroundColor);
    }

    painter->save();
    painter->fillRect(option.rect, backBrush);
    painter->restore();
    painter->setRenderHint(QPainter::Antialiasing);
    painter->setRenderHint(QPainter::HighQualityAntialiasing);

    // get the device pixel radio from current painter device
    double scale_factor = 1;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
    scale_factor = globalDevicePixelRatio();
#endif // QT5

    // paint avatar
    QImage avatar;
    if (!event.anonymous) {
        avatar = AvatarService::instance()->getAvatar(event.author);
    }

    QRect actualRect(0, 0, kAvatarWidth * scale_factor , kAvatarHeight * scale_factor);
    avatar.scaled(actualRect.size());
    QImage masked_image(actualRect.size(), QImage::Format_ARGB32_Premultiplied);
    masked_image.fill(Qt::transparent);
    QPainter mask_painter;
    mask_painter.begin(&masked_image);
    mask_painter.setRenderHint(QPainter::Antialiasing);
    mask_painter.setRenderHint(QPainter::HighQualityAntialiasing);
    mask_painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
    mask_painter.setPen(Qt::NoPen);
    mask_painter.setBrush(Qt::white);
    mask_painter.drawEllipse(actualRect);
    mask_painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
    mask_painter.drawImage(actualRect, avatar);
    mask_painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
    mask_painter.fillRect(actualRect, Qt::transparent);
    mask_painter.end();
    masked_image.setDevicePixelRatio(scale_factor);

    QPoint avatar_pos(kMarginLeft + kPadding, kMarginTop + kPadding);
    avatar_pos += option.rect.topLeft();
    painter->save();
    painter->drawImage(avatar_pos, masked_image);
    painter->restore();

    auto time_font = changeFontSize(painter->font(), kTimeFontSize);
    auto nick_font = changeFontSize(painter->font(), kNickFontSize);
    auto operation_font = changeFontSize(painter->font(), kOperationFontSize);
    auto desc_font = changeFontSize(painter->font(), kDescriptionFontSize);
    auto repo_name_font = time_font;

    const int operation_width = ::textWidthInFont(operation_text, operation_font);
    const int time_width = qMin(kTimeWidth, ::textWidthInFont(time_text, time_font));

    int nick_width;
    if (event.is_use_new_activities_api) {
        nick_width = option.rect.width() - kMarginLeft - kAvatarWidth - kMarginBetweenAvatarAndNick
            - kMarginBetweenNickAndOperation - operation_width - kMarginBetweenOperationAndTime
            - time_width - kPadding * 2 - kMarginRight;
    } else {
        nick_width = option.rect.width() - kMarginLeft - kAvatarWidth - kMarginBetweenAvatarAndNick
            - time_width - kMarginBetweenNickAndTime - kPadding * 2 - kMarginRight;
    }

    nick_width = qMin(nick_width, ::textWidthInFont(event.nick, nick_font));

    // Paint nick name
    QPoint nick_pos = avatar_pos + QPoint(kAvatarWidth + kMarginBetweenAvatarAndNick, 0);
    QRect nick_rect(nick_pos, QSize(nick_width, kNickHeight));
    painter->save();
    painter->setPen(QColor(selected ? kNickColorHighlighted : kNickColor));
    painter->setFont(nick_font);
    painter->drawText(nick_rect,
                      Qt::AlignLeft | Qt::AlignTop,
                      fitTextToWidth(event.nick, option.font, nick_width),
                      &nick_rect);
    painter->restore();

    // Paint operation name
    if (event.is_use_new_activities_api) {
        QPoint operation_pos = nick_pos + QPoint(nick_width + kMarginBetweenNickAndOperation, 3);
        QRect operation_rect(operation_pos, QSize(operation_width + 8, kOperationHeight));
        painter->save();
        QPainterPath path;
        path.addRoundedRect(operation_rect, kRadius, kRadius);
        painter->fillPath(path, QColor(kOperRectFillColor));

        painter->setPen(QColor(kOperationColor));
        painter->setFont(operation_font);
        painter->drawText(operation_rect,
                    Qt::AlignCenter,
                    fitTextToWidth(operation_text, option.font, operation_width),
                    &operation_rect);
        painter->restore();
    }

    // Paint event time
    painter->save();
    QPoint time_pos = option.rect.topRight() + QPoint(-time_width - kPadding - kMarginRight, kMarginTop + kPadding);
    QRect time_rect(time_pos, QSize(time_width, kTimeHeight));
    painter->setPen(QColor(selected ? kTimeColorHighlighted : kTimeColor));
    painter->setFont(time_font);

    painter->drawText(time_rect,
                      Qt::AlignRight | Qt::AlignTop,
                      time_text,
                      &time_rect);
    painter->restore();

    // Paint description
    painter->save();

    QString desc = event.desc;

    int repo_name_width = qMin(kRepoNameWidth, ::textWidthInFont(event.repo_name, repo_name_font));

    int desc_width = option.rect.width() - kMarginLeft - kAvatarWidth -
                     kMarginBetweenAvatarAndNick -
                     kMarginBetweenRepoNameAndDesc - repo_name_width -
                     kMarginRight - kPadding * 2;

    const int desc_height = ::textHeightInFont(desc, desc_font) * 2;

    // const QPoint event_desc_pos = option.rect.bottomLeft() + QPoint(nick_rect.left(), - desc_height - kExtraPadding - kMarginBottom);
    const QPoint event_desc_pos = nick_rect.bottomLeft() + QPoint(0, kVerticalMarginBetweenNickAndDesc);

    QRect event_desc_rect(event_desc_pos, QSize(desc_width, desc_height));
    painter->setFont(desc_font);
    painter->setPen(QColor(selected ? kDescriptionColorHighlighted : kDescriptionColor));

    desc.replace(QChar('\n'), QChar(' '));
    painter->drawText(event_desc_rect,
                      Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere,
                      // we have two lines
                      fitTextToWidth(desc, desc_font, desc_width * 2),
                      &event_desc_rect);
    painter->restore();

    // Paint repo name
    painter->save();

    repo_name_width += desc_width - event_desc_rect.width();
    // if (index.row() == 1) {
    //     printf ("width diff = %d\n", desc_width - event_desc_rect.width());
    // }

    const int repo_name_height = ::textHeightInFont(event.repo_name, repo_name_font);
    const QPoint event_repo_name_pos = option.rect.bottomRight() +
        QPoint(-repo_name_width - kPadding - kMarginRight,
               -repo_name_height - kExtraPadding - kMarginBottom);

    QRect event_repo_name_rect(event_repo_name_pos, QSize(repo_name_width, kNickHeight));
    painter->setFont(repo_name_font);
    painter->setPen(QColor(selected ? kRepoNameColorHighlighted : kRepoNameColor));
    painter->drawText(
        event_repo_name_rect,
        Qt::AlignRight | Qt::AlignTop | Qt::TextSingleLine,
        fitTextToWidth(event.repo_name, repo_name_font, repo_name_width),
        &event_repo_name_rect);
    painter->restore();

    // const EventsListModel *model = (const EventsListModel*)index.model();
    //
    // Draw the bottom border lines except for the last item (if the "load more" is present")
    // We minus 2 here becase:
    // 1) the row index starts from 0
    // 2) we addded a row for the "load more" data in the end
    // if (model->loadMoreIndex().isValid() && index.row() == model->rowCount() - 2) {
    //     return;
    // }

    painter->save();
    painter->setPen(QPen(QColor(kItemBottomBorderColor), 1, Qt::SolidLine));
    QPoint left = option.rect.bottomLeft();
    left.setY(left.y() + 1);
    QPoint right = option.rect.bottomRight();
    right.setY(right.y() + 1);
    painter->drawLine(left, right);
    painter->restore();
}
Ejemplo n.º 9
0
void ProfileGraphicsView::plot_one_event(struct event *ev)
{
    int i;
    struct plot_info *pi = &gc.pi;
    struct plot_data *entry;

    /* is plotting of this event disabled? */
    if (ev->name) {
        for (i = 0; i < evn_used; i++) {
            if (! strcmp(ev->name, ev_namelist[i].ev_name)) {
                if (ev_namelist[i].plot_ev)
                    break;
                else
                    return;
            }
        }
    }

    if (ev->time.seconds < 30 && !strcmp(ev->name, "gaschange"))
        /* a gas change in the first 30 seconds is the way of some dive computers
         * to tell us the gas that is used; let's not plot a marker for that */
        return;

    for (i = 0; i < pi->nr; i++) {
        entry = pi->entry + i;
        if (ev->time.seconds < entry->sec)
            break;
    }

    /* draw a little triangular marker and attach tooltip */

    int x = SCALEXGC(ev->time.seconds);
    int y = SCALEYGC(entry->depth);

    EventItem *item = new EventItem(0, isGrayscale);
    item->setPos(x, y);
    scene()->addItem(item);

    /* we display the event on screen - so translate */
    QString name = tr(ev->name);
    if (ev->value) {
        if (ev->name && name == "gaschange") {
            int he = get_he(&dive->cylinder[entry->cylinderindex].gasmix);
            int o2 = get_o2(&dive->cylinder[entry->cylinderindex].gasmix);

            name += ": ";
            name += (he) ? QString("%1/%2").arg((o2 + 5) / 10).arg((he + 5) / 10)
                    : is_air(o2, he) ? name += tr("air")
                                               : QString(tr("EAN%1")).arg((o2 + 5) / 10);

        } else if (ev->name && !strcmp(ev->name, "SP change")) {
            name += QString(":%1").arg((double) ev->value / 1000);
        } else {
            name += QString(":%1").arg(ev->value);
        }
    } else if (ev->name && name == "SP change") {
        name += tr("Bailing out to OC");
    } else {
        name += ev->flags == SAMPLE_FLAGS_BEGIN ? tr(" begin", "Starts with space!") :
                ev->flags == SAMPLE_FLAGS_END ? tr(" end", "Starts with space!") : "";
    }

    //item->setToolTipController(toolTip);
    //item->addToolTip(name);
    item->setToolTip(name);
}
Ejemplo n.º 10
0
void EventItemDelegate::paint(QPainter *painter,
                              const QStyleOptionViewItem& option,
                              const QModelIndex& index) const
{
    QBrush backBrush;
    bool selected = false;
    EventItem *item = getItem(index);
    const SeafEvent& event = item->event();
    QString time_text = translateCommitTime(event.timestamp);

    if (option.state & (QStyle::State_HasFocus | QStyle::State_Selected)) {
        backBrush = QColor(kEventItemBackgroundColorHighlighted);
        selected = true;

    } else {
        backBrush = QColor(kEventItemBackgroundColor);
    }

    painter->save();
    painter->fillRect(option.rect, backBrush);
    painter->restore();
    painter->setRenderHint(QPainter::Antialiasing);
    painter->setRenderHint(QPainter::HighQualityAntialiasing);

    // get the device pixel radio from current painter device
    int scale_factor = 1;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
    scale_factor = painter->device()->devicePixelRatio();
#endif // QT5

    // paint avatar
    QImage avatar;
    if (!event.anonymous) {
        avatar = AvatarService::instance()->getAvatar(event.author);
    }

    QRect actualRect(0, 0, kAvatarWidth * scale_factor , kAvatarHeight * scale_factor);
    avatar.scaled(actualRect.size());
    QImage masked_image(actualRect.size(), QImage::Format_ARGB32_Premultiplied);
    masked_image.fill(Qt::transparent);
    QPainter mask_painter;
    mask_painter.begin(&masked_image);
    mask_painter.setRenderHint(QPainter::Antialiasing);
    mask_painter.setRenderHint(QPainter::HighQualityAntialiasing);
    mask_painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
    mask_painter.setPen(Qt::NoPen);
    mask_painter.setBrush(Qt::white);
    mask_painter.drawEllipse(actualRect);
    mask_painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
    mask_painter.drawImage(actualRect, avatar);
    mask_painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
    mask_painter.fillRect(actualRect, Qt::transparent);
    mask_painter.end();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
    masked_image.setDevicePixelRatio(scale_factor);
#endif // QT5

    QPoint avatar_pos(kMarginLeft + kPadding, kMarginTop + kPadding);
    avatar_pos += option.rect.topLeft();
    painter->save();
    painter->drawImage(avatar_pos, masked_image);
    painter->restore();

    const int time_width = qMin(kTimeWidth,
        ::textWidthInFont(time_text,
            changeFontSize(painter->font(), kTimeFontSize)));
    int nick_width = option.rect.width() - kMarginLeft - kAvatarWidth - kMarginBetweenAvatarAndNick
        - time_width - kMarginBetweenNickAndTime - kPadding * 2 - kMarginRight;
    nick_width = qMin(nick_width,
                      ::textWidthInFont(event.nick,
                            changeFontSize(painter->font(), kNickFontSize)));

    // Paint nick name
    QPoint nick_pos = avatar_pos + QPoint(kAvatarWidth + kMarginBetweenAvatarAndNick, 0);
    QRect nick_rect(nick_pos, QSize(nick_width, kNickHeight));
    painter->save();
    painter->setPen(QColor(selected ? kNickColorHighlighted : kNickColor));
    painter->setFont(changeFontSize(painter->font(), kNickFontSize));
    painter->drawText(nick_rect,
                      Qt::AlignLeft | Qt::AlignTop,
                      fitTextToWidth(event.nick, option.font, nick_width),
                      &nick_rect);
    painter->restore();

    // Paint event time
    painter->save();
    QPoint time_pos = option.rect.topRight() + QPoint(-time_width - kPadding - kMarginRight, kMarginTop + kPadding);
    QRect time_rect(time_pos, QSize(time_width, kTimeHeight));
    painter->setPen(QColor(selected ? kTimeColorHighlighted : kTimeColor));
    painter->setFont(changeFontSize(painter->font(), kTimeFontSize));

    painter->drawText(time_rect,
                      Qt::AlignRight | Qt::AlignTop,
                      time_text,
                      &time_rect);
    painter->restore();

    // Paint description
    painter->save();

    const int repo_name_width = qMin(kRepoNameWidth, ::textWidthInFont(event.repo_name, changeFontSize(painter->font(), kTimeFontSize)));
    const int repo_name_height = ::textHeightInFont(event.repo_name, changeFontSize(painter->font(), kTimeFontSize));

    int desc_width = option.rect.width() - kMarginLeft - kAvatarWidth - kMarginBetweenAvatarAndNick - kPadding * 3 - kMarginBetweenRepoNameAndDesc - repo_name_width - kMarginRight;
    desc_width = qMin(desc_width, ::textWidthInFont(event.desc, changeFontSize(painter->font(), kDescriptionFontSize)));
    const int desc_height = ::textHeightInFont(event.desc, changeFontSize(painter->font(), kDescriptionFontSize)) * 2;

    const QPoint event_desc_pos = option.rect.bottomLeft() + QPoint(nick_rect.left(), - desc_height - kExtraPadding - kMarginBottom);

    QRect event_desc_rect(event_desc_pos, QSize(desc_width, desc_height));
    painter->setFont(changeFontSize(painter->font(), kDescriptionFontSize));
    painter->setPen(QColor(selected ? kDescriptionColorHighlighted : kDescriptionColor));

    QString desc = event.desc;
    desc.replace(QChar('\n'), QChar(' '));
    painter->drawText(event_desc_rect,
                      Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere,
                      // we have two lines
                      fitTextToWidth(desc, option.font, desc_width * 2),
                      &event_desc_rect);
    painter->restore();

    // Paint repo name
    painter->save();

    const QPoint event_repo_name_pos = option.rect.bottomRight() +
        QPoint(-repo_name_width - kPadding - kMarginRight,
               -repo_name_height - kExtraPadding - kMarginBottom);

    QRect event_repo_name_rect(event_repo_name_pos, QSize(repo_name_width, kNickHeight));
    painter->setFont(changeFontSize(painter->font(), kTimeFontSize));
    painter->setPen(QColor(selected ? kRepoNameColorHighlighted : kRepoNameColor));
    painter->drawText(event_repo_name_rect,
                      Qt::AlignRight | Qt::AlignTop | Qt::TextSingleLine,
                      fitTextToWidth(event.repo_name, option.font, repo_name_width),
                      &event_repo_name_rect);
    painter->restore();

    // Draw the bottom border lines
    painter->save();
    painter->setPen(QPen(QColor(kItemBottomBorderColor), 1, Qt::SolidLine));
    painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
    painter->restore();
}