예제 #1
0
	void ItemListView::dragMoveEvent(QDragMoveEvent *event)
	{
		QModelIndex index = indexAt(event->pos());
		bool afterLastItem = false;

		if(index.isValid())
		{
			mDropIndicator = visualRect(index);

			if(event->pos().y() > mDropIndicator.top() + mDropIndicator.height() / 2)
			{
				index = model()->index(index.row() + 1, 0, QModelIndex());
				if(index.isValid())
					mDropIndicator = visualRect(index);
				else
					afterLastItem = true;
			}
		}
		else
			afterLastItem = true;

		if(afterLastItem)
		{
			index = model()->index(model()->rowCount() - 1, 0, QModelIndex());
			mDropIndicator = visualRect(index);
			mDropIndicator = mDropIndicator.translated(0, mDropIndicator.height());
		}

		QListView::dragMoveEvent(event);
	}
예제 #2
0
void ThumbnailView::rowsAboutToBeRemoved( const QModelIndex &parent, int start, int end )
{
    QModelIndex index = currentIndex();

    QScrollBar *vScroll = verticalScrollBar();

    int startY = visualRect( index.sibling( start, index.column() ) ).top();
    int endY = visualRect( index.sibling( end + 1, index.column() ) ).top();

    int scrollValue = vScroll->value() - endY + startY;

    QListView::rowsAboutToBeRemoved( parent, start, end );

    if( index.row() >= start )
    {
        if( index.row() <= end && end + 1 < model()->rowCount( parent ) )
        {
            selectionModel()->setCurrentIndex(
                    model()->index( end + 1, index.column(), parent ),
                    QItemSelectionModel::ClearAndSelect);
        }
    }

    if( startY <= 0 )
        vScroll->setValue( scrollValue );
}
예제 #3
0
void TracksView::keepVisible(const QModelIndex &previous, const QModelIndex &current)
      {
      // update scroll bars to show the cell hidden by the frozen table view if it gets focus
      const int hInvisibleGap = visualRect(current).topLeft().x() - frozenVTableWidth();
      const int vInvisibleGap = visualRect(current).topLeft().y() - frozenHTableHeight();

      if (current.column() != previous.column() && current.column() >= _frozenColCount
                  && hInvisibleGap < 0) {
            const int newValue = horizontalScrollBar()->value() + hInvisibleGap;
            horizontalScrollBar()->setValue(newValue);
            }
      if (current.row() != previous.row() && current.row() >= _frozenRowCount
                  && vInvisibleGap < 0) {
            const int newValue = verticalScrollBar()->value() + vInvisibleGap;
            verticalScrollBar()->setValue(newValue);
            }

      // update scroll bars to show the cell hidden by the borders of main table view
      const int hInvisibleGap2 = width() - verticalHeader()->width() - 4 * frameWidth()
                  - ((verticalScrollBar()->isHidden()) ? 0 : verticalScrollBar()->width())
                  - visualRect(current).bottomRight().x();
      const int vInvisibleGap2 = height() - horizontalHeader()->height() - 4 * frameWidth()
                  - ((horizontalScrollBar()->isHidden()) ? 0 : horizontalScrollBar()->height())
                  - visualRect(current).bottomRight().y();

      if (current.column() != previous.column() && hInvisibleGap2 < 0) {
            const int newValue = horizontalScrollBar()->value() - hInvisibleGap2;
            horizontalScrollBar()->setValue(newValue);
            }
      if (current.row() != previous.row() && vInvisibleGap2 < 0) {
            const int newValue = verticalScrollBar()->value() - vInvisibleGap2;
            verticalScrollBar()->setValue(newValue);
            }
      }
예제 #4
0
void KNMusicTreeViewBase::keyReleaseEvent(QKeyEvent *event)
{
    QRect selectedRect;
    //Get the key event
    switch(event->key())
    {
    case Qt::Key_Menu:
        //Hide preview tooltips.
        KNMusicGlobal::detailTooltip()->hide();
        //Check the select rows count.
        switch(selectionModel()->selectedRows().size())
        {
        case 0:
            break;
        case 1:
            //Calculate the selected rows position.
            selectedRect=visualRect(currentIndex());
            showSoloMenu(QPoint(0,
                                selectedRect.y()));
            break;
        default:
            //Calculate the selected rows position.
            selectedRect=visualRect(currentIndex());
            showMultiMenu(QPoint(0,
                                 selectedRect.y()));
            break;
        }
    default:
        QTreeView::keyReleaseEvent(event);
        break;
    }
}
예제 #5
0
QRect QMdStyle::subControlRect(ComplexControl whichControl,
                                  const QStyleOptionComplex *option,
                                  SubControl whichSubControl,
                                  const QWidget *widget) const
{
    if (whichControl == CC_SpinBox) {
        int frameWidth = pixelMetric(PM_DefaultFrameWidth, option,
                                     widget);
        int buttonWidth = 40;

        switch (whichSubControl) {
        case SC_SpinBoxFrame:
            return option->rect;
        case SC_SpinBoxEditField:
            return option->rect.adjusted(+buttonWidth, +frameWidth,
                                         -buttonWidth, -frameWidth);
        case SC_SpinBoxDown:
            return visualRect(option->direction, option->rect,
                              QRect(option->rect.x(), option->rect.y(),
                                    buttonWidth,
                                    option->rect.height()));
        case SC_SpinBoxUp:
            return visualRect(option->direction, option->rect,
                              QRect(option->rect.right() - buttonWidth,
                                    option->rect.y(),
                                    buttonWidth,
                                    option->rect.height()));
        default:
            return QRect();
        }
    } else {
        return QWindowsStyle::subControlRect(whichControl, option,
                                             whichSubControl, widget);
    }
}
예제 #6
0
void KNMusicAlbumView::selectAlbum(const QModelIndex &albumIndex)
{
    //If the index is vaild, set the initial animation parameters.
    if(albumIndex.isValid())
    {
        //Check whether the album index is the same as the current one.
        if(albumIndex==m_selectedIndex)
        {
            //We don't need to expand the same album.
            return;
        }
        //Set current index to the proxy index of the album index.
        setCurrentIndex(m_proxyModel->mapFromSource(albumIndex));
        //Set the selected index.
        m_selectedIndex=albumIndex;
        //Show the detail.
        m_albumDetail->setAnimeParameter(
                    visualRect(m_proxyModel->mapFromSource(m_selectedIndex)),
                    m_itemWidth);
        m_albumDetail->displayAlbumDetail(m_selectedIndex);
        //Update the album view.
        viewport()->update();
        //Finished.
        return;
    }
    //Show the detail.
    m_albumDetail->setAnimeParameter(
                visualRect(m_proxyModel->mapFromSource(m_selectedIndex)),
                m_itemWidth);
    //Do fold detail animation.
    m_albumDetail->foldAlbumDetail();
    //Update the viewport.
    update();
    viewport()->update();
}
예제 #7
0
bool ThumbView::isThumbVisible(QModelIndex idx)
{
	if (viewport()->rect().contains(QPoint(0, visualRect(idx).y() + visualRect(idx).height() + 1))) {
		return true;
	}

	return false;
}
예제 #8
0
/**
 * QT 4.7.1 拖拽的函数默认调用过程:
 *
 * Model.supportedDropActions()
 *
 * View.startDrag()
 *     Model.mimeData() // 获取拖拽数据
 *     Model.supportedDragActions()
 *         Model.supportedDropActions()
 *     QDrag.exec() // 阻塞,直到拖拽结束
 *
 *         // 在拖拽过程中,如果拖拽进入某个节点
 *         View.dragEnterEvent() // 默认实现会拒绝拖拽,需要重写并调用 QDragEnterEvent.acceptProposedAction()
 *             Model.mimeTypes()
 *         View.dragMoveEvent()
 *             Model.mimeTypes()
 *         View.dragLeaveEvent()
 *
 *         // 拖拽结束后
 *         View.dropEvent()
 *             Model.dropMimeData() // QT用来接收数据
 *
 *     // exec()执行完后,如果是 MoveAction,则调用
 *     Model.removeSelectedRows() // QT用来删除数据
 *
 * 上述默认过程对跨 View 拖放支持不好, 下面的startDrag()函数摘自默认实现,并
 * 将部分代码替换掉以免调用removeSelectedRows()函数
 */
void DirectoryTree::startDrag(Qt::DropActions)
{
    const QModelIndexList indexes = selectedIndexes();
    if (indexes.count() == 0)
        return;

    // setup pixmap
    QRect rect = visualRect(indexes.at(0));
    QList<QRect> rects;
    for (size_t i = 0, s = indexes.count(); i < s; ++i)
    {
        rects.append(visualRect(indexes.at(i)));
        rect |= rects.at(i);
    }
    rect = rect.intersected(viewport()->rect());
    QPixmap pixmap(rect.size());
    pixmap.fill(palette().base().color());
    QPainter painter(&pixmap);
    QStyleOptionViewItem option = viewOptions();
    option.state |= QStyle::State_Selected;
    for (size_t j = 0, s = indexes.count(); j < s; ++j)
    {
        option.rect = QRect(rects.at(j).topLeft() - rect.topLeft(),
        rects.at(j).size());
        itemDelegate()->paint(&painter, option, indexes.at(j));
    }
    painter.end();

    // create drag object
    QDrag *drag = new QDrag(this);
    drag->setPixmap(pixmap);
    drag->setMimeData(model()->mimeData(indexes));
    drag->setHotSpot(viewport()->mapFromGlobal(QCursor::pos()) - rect.topLeft());

    /**
     * 在拖动之前,先把 parent 和  row 保存下来,
     * 在 Model.dropMimeData() 中统一进行底层数据和视图层数据的修改,
     * 避免索引混乱
     */
    DirectoryTreeModel *m = (DirectoryTreeModel*) model();
    QModelIndex parent = indexes.at(0).parent();
    int row = indexes.at(0).row();
    m->prepare_draging_drop(parent, row);

    /*
     * 这里的原来的实现 removeSelectedRows() 是我们不需要的, 且 QDrag->start() 总是允许 Qt::CopyAction
     * 而我们需要的是,内部用 Qt::MoveAction,外部用 Qt::CopyAction且内部不支持 Qt::CopyAction且内部不支持
     * Qt::CopyAction,否则导致错误
     *
    if (drag->start(supportedActions) == Qt::MoveAction)
        removeSelectedRows();
    */
    drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction);
}
예제 #9
0
QModelIndex QFrozenRowTableWidget::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
{
      QModelIndex current = QTableWidget::moveCursor(cursorAction, modifiers);

      if (cursorAction == MoveLeft && current.column() > 0
              && visualRect(current).topLeft().x() < frozenTableWidget->rowHeight(0) ){
            const int newValue = verticalScrollBar()->value() + visualRect(current).topLeft().x()
                                 - frozenTableWidget->rowHeight(0);
            verticalScrollBar()->setValue(newValue);
      }
      return current;
}
예제 #10
0
int ThumbView::getLastVisibleThumb()
{
	QModelIndex idx;

	for (int currThumb = thumbViewModel->rowCount() -1; currThumb >= 0 ; --currThumb) {
		idx = thumbViewModel->indexFromItem(thumbViewModel->item(currThumb));
		if (viewport()->rect().contains(QPoint(0, visualRect(idx).y() + visualRect(idx).height() + 1))) {
			return idx.row();
		}
	}

	return -1;
}
//! [navigate]
QModelIndex FreezeTableWidget::moveCursor(CursorAction cursorAction,
                                          Qt::KeyboardModifiers modifiers)
{
      QModelIndex current = QTableView::moveCursor(cursorAction, modifiers);

      if (cursorAction == MoveLeft && current.column() > 0
              && visualRect(current).topLeft().x() < frozenTableView->columnWidth(0) ){
            const int newValue = horizontalScrollBar()->value() + visualRect(current).topLeft().x()
                                 - frozenTableView->columnWidth(0);
            horizontalScrollBar()->setValue(newValue);
      }
      return current;
}
예제 #12
0
void ItemList::startDrag(Qt::DropActions supportedActions)
{
    const QModelIndexList indexes = selectedIndexes();
    if (indexes.count() == 0)
        return;

    // setup pixmap
    QRect rect = visualRect(indexes.at(0));
    QList<QRect> rects;
    for (size_t i = 0, s = indexes.count(); i < s; ++i)
    {
        rects.append(visualRect(indexes.at(i)));
        rect |= rects.at(i);
    }
    rect = rect.intersected(viewport()->rect());
    QPixmap pixmap(rect.size());
    pixmap.fill(palette().base().color());
    QPainter painter(&pixmap);
    QStyleOptionViewItem option = viewOptions();
    option.state |= QStyle::State_Selected;
    for (size_t j = 0, s = indexes.count(); j < s; ++j)
    {
        option.rect = QRect(rects.at(j).topLeft() - rect.topLeft(),
        rects.at(j).size());
        itemDelegate()->paint(&painter, option, indexes.at(j));
    }
    painter.end();

    // create drag object
    QDrag *drag = new QDrag(this);
    drag->setPixmap(pixmap);
    drag->setMimeData(model()->mimeData(indexes));
    drag->setHotSpot(viewport()->mapFromGlobal(QCursor::pos()) - rect.topLeft());

    /*
     * 这里的原来的实现被注释掉
    if (drag->start(supportedActions) == Qt::MoveAction)
        removeSelectedRows();
    */
    ItemListModel *m = dynamic_cast<ItemListModel*>(model());
    assert(NULL != m); /// QAbstractItemModel::supportedDragActions()居然不是虚函数,我C了!!!
    Qt::DropAction rs = drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction);
    if (rs == Qt::MoveAction)
    {
        assert(indexes.count() != 0);
        m->_remove_after_drag(indexes.at(0).row());
    }
}
예제 #13
0
void PieView::scrollTo(const QModelIndex &index, ScrollHint)
{
    QRect area = viewport()->rect();
    QRect rect = visualRect(index);

    if (rect.left() < area.left()) {
        horizontalScrollBar()->setValue(
            horizontalScrollBar()->value() + rect.left() - area.left());
    } else if (rect.right() > area.right()) {
        horizontalScrollBar()->setValue(
            horizontalScrollBar()->value() + qMin(
                rect.right() - area.right(), rect.left() - area.left()));
    }

    if (rect.top() < area.top()) {
        verticalScrollBar()->setValue(
            verticalScrollBar()->value() + rect.top() - area.top());
    } else if (rect.bottom() > area.bottom()) {
        verticalScrollBar()->setValue(
            verticalScrollBar()->value() + qMin(
                rect.bottom() - area.bottom(), rect.top() - area.top()));
    }

    update();
}
예제 #14
0
QModelIndex FolderViewListView::indexAt(const QPoint& point) const {
  QModelIndex index = QListView::indexAt(point);
  // NOTE: QListView has a severe design flaw here. It does hit-testing based on the 
  // total bound rect of the item. The width of an item is determined by max(icon_width, text_width).
  // So if the text label is much wider than the icon, when you click outside the icon but
  // the point is still within the outer bound rect, the item is still selected.
  // This results in very poor usability. Let's do precise hit-testing here.
  // An item is hit only when the point is in the icon or text label.
  // If the point is in the bound rectangle but outside the icon or text, it should not be selected.
  if(viewMode() == QListView::IconMode && index.isValid()) {
    // FIXME: this hack only improves the usability partially. We still need more precise sizeHint handling.
    // FolderItemDelegate* delegate = static_cast<FolderItemDelegate*>(itemDelegateForColumn(FolderModel::ColumnFileName));
    // Q_ASSERT(delegate != NULL);
    // We use the grid size - (2, 2) as the size of the bounding rectangle of the whole item.
    // The width of the text label hence is gridSize.width - 2, and the width and height of the icon is from iconSize().
    QRect visRect = visualRect(index); // visibal area on the screen
    QSize itemSize = gridSize();
    itemSize.setWidth(itemSize.width() - 2);
    itemSize.setHeight(itemSize.height() - 2);
    QSize _iconSize = iconSize();
    int textHeight = itemSize.height() - _iconSize.height();
    if(point.y() < visRect.bottom() - textHeight) {
      // the point is in the icon area, not over the text label
      int iconXMargin = (itemSize.width() - _iconSize.width()) / 2;
      if(point.x() < (visRect.left() + iconXMargin) || point.x() > (visRect.right() - iconXMargin))
	return QModelIndex();
    }
    // qDebug() << "visualRect: " << visRect << "point:" << point;
  }
  return index;
}
예제 #15
0
void ColumnDropCSVView::mousePressEvent(QMouseEvent *press)
{
	QModelIndex atClick = indexAt(press->pos());
	if (!atClick.isValid() || atClick.row())
		return;

	QRect indexRect = visualRect(atClick);
	QPixmap pix(indexRect.width(), indexRect.height());
	pix.fill(QColor(0,0,0,0));
	render(&pix, QPoint(0, 0),QRegion(indexRect));

	QDrag *drag = new QDrag(this);
	QMimeData *mimeData = new QMimeData;
	mimeData->setData(subsurface_mimedata, atClick.data().toByteArray());
	mimeData->setData(subsurface_index, QString::number(atClick.column()).toUtf8());
	drag->setPixmap(pix);
	drag->setMimeData(mimeData);
	if (drag->exec() != Qt::IgnoreAction){
		QObject *target = drag->target();
		if (target->objectName() ==  "qt_scrollarea_viewport")
			target = target->parent();
		if (target != drag->source())
			model()->setData(atClick, QString());
	}
}
예제 #16
0
void QmlConsoleView::mousePressEvent(QMouseEvent *event)
{
    QPoint pos = event->pos();
    QModelIndex index = indexAt(pos);
    if (index.isValid()) {
        ConsoleItem::ItemType type = (ConsoleItem::ItemType)index.data(
                    QmlConsoleItemModel::TypeRole).toInt();
        bool handled = false;
        if (type == ConsoleItem::UndefinedType) {
            bool showTypeIcon = index.parent() == QModelIndex();
            ConsoleItemPositions positions(visualRect(index), viewOptions().font, showTypeIcon,
                                           true);

            if (positions.expandCollapseIcon().contains(pos)) {
                if (isExpanded(index))
                    setExpanded(index, false);
                else
                    setExpanded(index, true);
                handled = true;
            }
        }
        if (!handled)
            Utils::TreeView::mousePressEvent(event);
    } else {
        selectionModel()->setCurrentIndex(model()->index(model()->rowCount() - 1, 0),
                                          QItemSelectionModel::ClearAndSelect);
    }
}
예제 #17
0
void PlaylistView::mousePressEvent(QMouseEvent* event) {
  if (!(editTriggers() & QAbstractItemView::SelectedClicked)) {
    QTreeView::mousePressEvent(event);
    return;
  }

  QModelIndex index = indexAt(event->pos());
  if (event->button() == Qt::LeftButton && index.isValid() &&
      index.data(Playlist::Role_CanSetRating).toBool()) {
    // Calculate which star was clicked
    double new_rating =
        RatingPainter::RatingForPos(event->pos(), visualRect(index));

    if (selectedIndexes().contains(index)) {
      // Update all the selected items
      QModelIndexList src_index_list;
      for (const QModelIndex& index : selectedIndexes()) {
        if (index.data(Playlist::Role_CanSetRating).toBool()) {
          QModelIndex src_index = playlist_->proxy()->mapToSource(index);
          src_index_list << src_index;
        }
      }
      playlist_->RateSongs(src_index_list, new_rating);
    } else {
      // Update only this item
      playlist_->RateSong(playlist_->proxy()->mapToSource(index), new_rating);
    }
  } else {
    QTreeView::mousePressEvent(event);
  }

  inhibit_autoscroll_ = true;
  inhibit_autoscroll_timer_->start();
}
예제 #18
0
void HoverableTreeView::drawRow(QPainter* painter, const QStyleOptionViewItem& options, const QModelIndex& index) const
{
    HoverableStyleOptionViewItem opt = options;

    QRect r = visualRect(index).adjusted(0, 1, 0, 1);
    r.setLeft(0);

    opt.decorationSize = QSize();
    if (underMouse() &&
        !mousePosition_.isNull() &&
        r.contains(mousePosition_) &&
        !verticalScrollBar()->underMouse() &&
        !verticalScrollBar()->isSliderDown())
    {
        // we're hacking our way through the QTreeView which casts HoverableStyleOptionViewItem
        // down to HoverableStyleOptionViewItemBaseClass and loses the hovered flag
        opt.displayAlignment = Qt::AlignLeft | Qt::AlignRight | Qt::AlignHCenter | Qt::AlignJustify;

        // decorationSize will hold the mouse coordinates starting from opt.rect.topLeft()
        QPoint offset = mousePosition_ /*- QPoint(opt.rect.left(), 0)*/;
        opt.decorationSize = QSize(offset.x(), offset.y());

        opt.hovered = true;
        opt.hoveredPosition = QPoint(offset.x(), offset.y());
    }
    QTreeView::drawRow(painter, opt, index);
}
//-----------------------------------------------------------------------------
void vktraceviewer_QTimelineView::scrollTo(const QModelIndex &index, ScrollHint hint/* = EnsureVisible*/)
{
    if (!index.isValid())
    {
        return;
    }

    QRect viewRect = viewport()->rect();
    QRect itemRect = visualRect(index);

    if (itemRect.left() < viewRect.left())
    {
        horizontalScrollBar()->setValue(horizontalScrollBar()->value() + itemRect.center().x() - viewport()->width()/2);
    }
    else if (itemRect.right() > viewRect.right())
    {
        horizontalScrollBar()->setValue(horizontalScrollBar()->value() + itemRect.center().x() - viewport()->width()/2);
    }

    if (!viewRect.contains(itemRect))
    {
        deletePixmap();
    }
    viewport()->update();
}
예제 #20
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;
}
예제 #21
0
int KexiRelationsTableFieldList::globalY(const QString &item)
{
    QAbstractItemModel *themodel = model();
    QModelIndex idx;
    
    for (int i = 0; i < themodel->rowCount(); ++i) {
        idx = themodel->index(i, 0);
        QVariant data = themodel->data(idx);
        if (data.toString() == item) {
            break;
        }
    }
    
    if (idx.isValid()) {
        QRect r = this->rectForIndex(idx);
        int y = r.y() + r.height()/2;
        
        //Not sure what this line is supposed to do...is it to check if the item is visible?
        if (visualRect(idx).y() > viewport()->height()){   
            y = 0;
        } else if (y == 0) {
            y = height();
        }
        return mapToGlobal(QPoint(0, y)).y();
    }
    return -1;
}
예제 #22
0
bool RepoTreeView::viewportEvent(QEvent *event)
{
    if (event->type() != QEvent::ToolTip && event->type() != QEvent::WhatsThis) {
        return QTreeView::viewportEvent(event);
    }

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

    QStandardItem *item = getRepoItem(index);
    if (!item) {
        return true;
    }

    QRect item_rect = visualRect(index);
    if (item->type() == REPO_ITEM_TYPE) {
        showRepoItemToolTip((RepoItem *)item, global_pos, item_rect);
    } else {
        showRepoCategoryItemToolTip((RepoCategoryItem *)item, global_pos, item_rect);
    }

    return true;
}
예제 #23
0
void TreeView::startDrag(Qt::DropActions supportedActions)
{
	QModelIndex index = selectedIndexes().value(0);

	if (!index.isValid())
		return;

	QMimeData *data = model()->mimeData(QModelIndexList() << index);

	if (!data)
		return;
	QRect rect;
	QPixmap pixmap;
	QPoint point;
	{
		QAbstractItemDelegate *delegate = itemDelegate(index);
		QStyleOptionViewItemV4 option = viewOptions();
		option.locale = this->locale();
		option.locale.setNumberOptions(QLocale::OmitGroupSeparator);
		option.widget = this;
		option.state |= QStyle::State_Selected;
		option.rect = visualRect(index);
		point = option.rect.topLeft();
		option.rect.moveTo(0, 0);
		option.rect.setSize(delegate->sizeHint(option, index));
		rect = option.rect;
		pixmap = QPixmap(rect.size());
		pixmap.fill(Qt::transparent);
		QPainter painter(&pixmap);
		delegate->paint(&painter, option, index);
	}
	QDrag *drag = new QDrag(this);
	drag->setPixmap(pixmap);
	drag->setMimeData(data);
	point = QCursor::pos() - viewport()->mapToGlobal(point);
	drag->setHotSpot(point);
	//			drag->setHotSpot(QCursor::pos() - rect.topLeft());
	Qt::DropAction setDefaultDropAction = QAbstractItemView::defaultDropAction();
	Qt::DropAction defaultDropAction = Qt::IgnoreAction;
	if (setDefaultDropAction != Qt::IgnoreAction && (supportedActions & setDefaultDropAction))
		defaultDropAction = setDefaultDropAction;
	else if (supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove)
		defaultDropAction = Qt::CopyAction;
	if (drag->exec(supportedActions, defaultDropAction) == Qt::IgnoreAction
			&& index.data(ItemTypeRole).toInt() == ContactType) {
		if (QWidget *widget = QApplication::topLevelAt(QCursor::pos())) {
			if (widget->window() == this->window())
				return;
		}
		Event ev("contact-list-drop",
				 QCursor::pos() - point,
				 index.data(BuddyRole));
		ev.send();
	}
	//			debug() << "DropAction" << drag->exec(supportedActions, defaultDropAction);
	//			if (drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction)
	//				d->clearOrRemove();
	//			{}
}
예제 #24
0
void ItemViewCategorized::scrollToRelaxed(const QModelIndex& index, QAbstractItemView::ScrollHint hint)
{
    if (viewport()->rect().intersects(visualRect(index)))
    {
        return;
    }

    scrollTo(index, hint);
}
int CustomTreeView::sizeHintForColumn(int col) const {
  if (!model() || col > 0)
    return -1;

  ensurePolished();
  int hint = 0;
  QModelIndex index = model()->index(0,col);

  while (index.isValid()) {
    if (viewport()->rect().contains(visualRect(index))) {
      hint = qMax(hint, visualRect(index).x() + itemDelegate(index)->sizeHint(viewOptions(), index).width());
    }

    index = indexBelow(index);
  }

  return qMin(hint, viewport()->rect().width());
}
예제 #26
0
void TTreeWidget::mousePressEvent( QMouseEvent *event )
{
    QModelIndex indexClicked = indexAt(event->pos());
    if( mIsVarTree && indexClicked.isValid() )
    {
        QRect vrect = visualRect(indexClicked);
        int itemIndentation = vrect.x() - visualRect(rootIndex()).x();
        QRect rect = QRect(header()->sectionViewportPosition(0) + itemIndentation,
                           vrect.y(), style()->pixelMetric(QStyle::PM_IndicatorWidth), vrect.height());
        if(rect.contains(event->pos()))
        {
            mClickedItem = indexClicked;
            QTreeWidget::mousePressEvent(event);
            return;
        }
    }
    QTreeWidget::mousePressEvent(event);
}
예제 #27
0
/**
 * This function is used to create custom behaviour when clicking
 * on user/channel flags (e.g. showing the comment)
 */
void UserView::mouseReleaseEvent(QMouseEvent *evt) {
	QPoint qpos = evt->pos();

	QModelIndex idx = indexAt(qpos);
	if ((evt->button() == Qt::LeftButton) && idx.isValid()) {
		UserModel *um = static_cast<UserModel *>(model());
		ClientUser *cu = um->getUser(idx);
		Channel * c = um->getChannel(idx);
		if ((cu && ! cu->qbaCommentHash.isEmpty()) ||
		        (! cu && c && ! c->qbaDescHash.isEmpty())) {
			QRect r = visualRect(idx);

			int offset = 18;

			if (cu) {
				// Calculate pixel offset of comment flag
				if (cu->bLocalIgnore)
					offset += 18;
				if (cu->bRecording)
					offset += 18;
				if (cu->bPrioritySpeaker)
					offset += 18;
				if (cu->bMute)
					offset += 18;
				if (cu->bSuppress)
					offset += 18;
				if (cu->bSelfMute)
					offset += 18;
				if (cu->bLocalMute)
					offset += 18;
				if (cu->bSelfDeaf)
					offset += 18;
				if (cu->bDeaf)
					offset += 18;
				if (! cu->qsFriendName.isEmpty())
					offset += 18;
				if (cu->iId >= 0)
					offset += 18;
			}

			offset = r.topRight().x() - offset;

			if ((qpos.x() >= offset) && (qpos.x() <= (offset+18))) {
				QString str = um->data(idx, Qt::ToolTipRole).toString();
				if (str.isEmpty()) {
					um->bClicked = true;
				} else {
					QWhatsThis::showText(viewport()->mapToGlobal(r.bottomRight()), str, this);
					um->seenComment(idx);
				}
				return;
			}
		}
	}
	QTreeView::mouseReleaseEvent(evt);
}
예제 #28
0
bool AlbumSelectionTreeView::viewportEvent(QEvent* event)
{
    // let the base class handle the event if it is not a tool tip request
    if (event->type() != QEvent::ToolTip)
    {
        return AlbumTreeView::viewportEvent(event);
    }

    // only show tool tips if requested
    if (!d->enableToolTips)
    {
        return false;
    }

    // check that we got a correct event
    QHelpEvent* const helpEvent = dynamic_cast<QHelpEvent*> (event);

    if (!helpEvent)
    {
        qCDebug(DIGIKAM_GENERAL_LOG) << "Unable to determine the correct type of the event. "
                 << "This should not happen.";
        return false;
    }

    // find the item this tool tip belongs to
    QModelIndex index = indexAt(helpEvent->pos());

    if (!index.isValid())
    {
        return true;
    }

    PAlbum* const album = albumForIndex(index);

    if (!album || album->isRoot() || album->isAlbumRoot())
    {
        // there was no album so we really don't want to show a tooltip.
        return true;
    }

    QRect itemRect = visualRect(index);

    if (!itemRect.contains(helpEvent->pos()))
    {
        return true;
    }

    QStyleOptionViewItem option = viewOptions();
    option.rect                 = itemRect;
    // visualRect can be larger than viewport, intersect with viewport rect
    option.rect                 &= viewport()->rect();
    option.state                |= (index == currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);
    d->toolTip->show(option, index);

    return true;
}
예제 #29
0
void WinBarGroup::mousePressEvent(QMouseEvent *event)
{
    QModelIndex index = indexAt(event->pos());
    if(event->button() == Qt::LeftButton && index.isValid()){
       m_rect = visualRect(index);
        m_pressed = true;
        update(index);
    }
    QTableView::mousePressEvent(event);
}
예제 #30
0
bool BaseFinderView::isHoveringPlayIcon(QMouseEvent *event) {
    const QModelIndex itemIndex = indexAt(event->pos());
    const QRect itemRect = visualRect(itemIndex);

    // qDebug() << " itemRect.x()" <<  itemRect.x();

    const int x = event->x() - itemRect.x();
    const int y = event->y() - itemRect.y();
    return x > 90 && x < 140 && y > 10 && y < 60;
}