Example #1
0
    def mousePressEvent(self, event):
        """ Handle the mouse press event for the tab bar.

        This handler will set the internal '_has_mouse' flag if the
        left mouse button is pressed on a tab.

        """
        super(QDockTabBar, self).mousePressEvent(event)
        self._has_mouse = False
        if event.button() == Qt.LeftButton:
            if self.tabAt(event.pos()) != -1:
                self._has_mouse = True
        elif event.button() == Qt.RightButton:
            index = self.tabAt(event.pos())
            if index != -1:
                button = self.tabButton(index, QTabBar.RightSide)
                if button.geometry().contains(event.pos()):
                    return
                item = self.parent().widget(index).dockItem()
                item.titleBarRightClicked.emit(event.globalPos())
                # Emitting the clicked signal may have caused a popup
                # menu to open, which will have grabbed the mouse. When
                # this happens, the hover leave event is not sent and
                # the tab bar will be stuck in the hovered paint state.
                # Manual checking as 'underMouse' yields False negatives.
                p = self.mapFromGlobal(QCursor.pos())
                if not self.rect().contains(p):
                    QApplication.sendEvent(self, QEvent(QEvent.HoverLeave))
Example #2
0
    def do_drag(self, widget):
        """Perform the drag operation for the widget.

        Parameters
        ----------
        widget: QWidget
            A reference to the viewport widget.

        """
        drag_data = self.declaration.drag_start()
        if drag_data is None:
            return
        # widget = self.widget
        qdrag = QDrag(widget)
        qdrag.setMimeData(drag_data.mime_data.q_data())
        if drag_data.image is not None:
            qimg = get_cached_qimage(drag_data.image)
            qdrag.setPixmap(QPixmap.fromImage(qimg))
        # else:
        # if __version_info__ < (5, ):
        # qdrag.setPixmap(QPixmap.grabWidget(self.widget))
        # else:
        # qdrag.setPixmap(widget.grab())
        if drag_data.hotspot:
            qdrag.setHotSpot(QPoint(*drag_data.hotspot))
        else:
            cursor_position = widget.mapFromGlobal(QCursor.pos())
            qdrag.setHotSpot(cursor_position)
        default = Qt.DropAction(drag_data.default_drop_action)
        supported = Qt.DropActions(drag_data.supported_actions)
        qresult = qdrag.exec_(supported, default)
        self.declaration.drag_end(drag_data, DropAction(int(qresult)))
Example #3
0
    def mousePressEvent(self, event):
        """ Handle the mouse press event for the tab bar.

        This handler will set the internal '_has_mouse' flag if the
        left mouse button is pressed on a tab.

        """
        super(QDockTabBar, self).mousePressEvent(event)
        self._has_mouse = False
        if event.button() == Qt.LeftButton:
            index = self.tabAt(event.pos())
            if index != -1:
                self._has_mouse = True
                data = self._tab_data[index]
                container = data.container
                if container is not None:
                    # likey a no-op, but just in case
                    container.dockItem().clearAlert()
        elif event.button() == Qt.RightButton:
            index = self.tabAt(event.pos())
            if index != -1:
                button = self.tabButton(index, QTabBar.RightSide)
                if button.geometry().contains(event.pos()):
                    return
                item = self.parent().widget(index).dockItem()
                item.titleBarRightClicked.emit(event.globalPos())
                # Emitting the clicked signal may have caused a popup
                # menu to open, which will have grabbed the mouse. When
                # this happens, the hover leave event is not sent and
                # the tab bar will be stuck in the hovered paint state.
                # Manual checking as 'underMouse' yields False negatives.
                p = self.mapFromGlobal(QCursor.pos())
                if not self.rect().contains(p):
                    QApplication.sendEvent(self, QEvent(QEvent.HoverLeave))
Example #4
0
    def _releaseFrame(self):
        """ A helper method which releases the frame grab.

        Returns
        -------
        result : bool
            True if the frame was released, False otherwise.

        """
        state = self.frame_state
        if state.press_pos is not None:
            self.releaseMouse()
            if self.isWindow():
                self.manager().drag_release_frame(self, QCursor.pos())
            state.dragging = False
            state.press_pos = None
            state.start_pos = None
            return True
        return False
Example #5
0
    def _releaseFrame(self):
        """ A helper method which releases the frame grab.

        Returns
        -------
        result : bool
            True if the frame was released, False otherwise.

        """
        state = self.frame_state
        if state.press_pos is not None:
            self.releaseMouse()
            if self.isWindow():
                self.manager().drag_release_frame(self, QCursor.pos())
            state.dragging = False
            state.press_pos = None
            state.start_pos = None
            return True
        return False
Example #6
0
    def _onCornerTabsButtonClicked(self, event):
        """ Opens a context menu that lists all tabs.

        """
        context_menu = QCustomMenu(self)
        context_menu.setContextMenu(True)
        current_index = self.currentIndex()
        for i in range(self.count()):
            tab = self.widget(i)
            if tab is not None:
                action = context_menu.addAction(tab.title())
                action.setCheckable(True)
                action.setChecked(i == current_index)
                icon = self.tabIcon(i)
                if icon is not None:
                    # FIXME This overlays the icon over the checkbox
                    action.setIcon(icon)
                action.setData(i)
        action = context_menu.exec_(QCursor.pos())
        if action is not None:
            i = action.data()
            self.setCurrentIndex(i)
        context_menu.setContextMenu(False)
        del context_menu