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


C++ TabBar::grabMouse方法代码示例

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


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

示例1: mouseMoveEvent

void TabBar::mouseMoveEvent(QMouseEvent* event) {
  // while dragging
  if (event->buttons() & Qt::LeftButton) {
    // If we call winId() here, drag no longer works.
    //  qDebug() << "mouseMoveEvent. pos:" << event->pos() << "globalPos:" << event->globalPos();
    //    qDebug() << "mouseMoveEvent" << event;

    // first mouse enter event after dragging
    if (m_dragInitiated && geometry().contains(event->pos())) {
      qDebug("first mouse enter event");
      finishDrag();

      // Start mouse move
      emit onDetachTabEntered(event->screenPos().toPoint());
      return QTabBar::mouseMoveEvent(event);
    }

    // dragging tab is over an another tab bar.
    TabBar* anotherTabBar = App::tabBarAt(event->screenPos().x(), event->screenPos().y());

    if (m_dragInitiated && anotherTabBar && anotherTabBar != this) {
      qDebug("dragging tab is over an another tab bar.");

      finishDrag();

      // NOTE: dirty Hack!!!
      //
      // TabView A  TabView B
      // tab1 tab2  tab3
      //
      // When starting to move a tab1, in QTabBarPrivate d->pressedIndex is 0
      // When tab1 passes tab2, d->pressedIndex is 1
      // When tab1 moves to TabView B, this code block is executed and onDetachTabEntered is
      // emitted
      // In TabView::detachTabEntered, insertTab is called with tab1
      // TabView B becomes the parent of tab1 and TabView A removes tab1 becaues it's no longer
      // parent
      // In paintEvent of TabView A, it tries to paint d->tabList[d->pressedIndex] but crash occurs
      // because it's out of range
      //
      // In mouseReleaseEvent below, it resets d->pressedIndex to -1 to avoid the situation above

      mouseReleaseEvent(new QMouseEvent(QEvent::MouseButtonRelease, event->screenPos().toPoint(),
                                        Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));

      emit anotherTabBar->onDetachTabEntered(event->screenPos().toPoint());
      anotherTabBar->m_sourceTabBar = this;
      anotherTabBar->grabMouse();
      return;
    }

    if (m_dragInitiated && m_fakeWindow) {
      m_fakeWindow->moveWithOffset(event->globalPos());
      return QTabBar::mouseMoveEvent(event);
    }

    //    qDebug() << "manhattanLength? " << ((event->pos() - m_dragStartPos).manhattanLength() <
    //    QApplication::startDragDistance()) << "outside of tabbar? " <<
    //    !geometry().contains(event->pos());
    if (!m_dragStartPos.isNull() && ((event->buttons() & Qt::LeftButton)) &&
        ((event->pos() - m_dragStartPos).manhattanLength() > QApplication::startDragDistance()) &&
        (!geometry().contains(event->pos()))) {
      m_dragInitiated = true;
      // Stop the move to be able to convert to a drag
      QMouseEvent finishMoveEvent(QEvent::MouseMove, event->pos(), Qt::NoButton, Qt::NoButton,
                                  Qt::NoModifier);
      QTabBar::mouseMoveEvent(&finishMoveEvent);

      // Initiate Drag
      qDebug("start dragging a tab");
      m_fakeWindow = new FakeWindow(this, m_dragStartPos);
      m_fakeWindow->show();
      emit onDetachTabStarted(tabAt(m_dragStartPos), event->screenPos().toPoint());
    } else {
      QTabBar::mouseMoveEvent(event);
    }
    // not dragging
  } else {
    showCloseButtonOnActiveTab(event->pos());
  }
}
开发者ID:silkedit,项目名称:silkedit,代码行数:81,代码来源:TabBar.cpp


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