コード例 #1
0
ファイル: management.py プロジェクト: fabianofranz/everpad
 def init_notebooks(self):
     frame = QFrame()
     layout = QVBoxLayout()
     frame.setLayout(layout)
     self.ui.scrollArea.setWidget(frame)
     for notebook_struct in self.app.provider.list_notebooks():
         notebook = Notebook.from_tuple(notebook_struct)
         count = self.app.provider.get_notebook_notes_count(notebook.id)
         widget = QWidget()
         menu = QMenu(self)
         menu.addAction(self.tr('Change Name'), Slot()(partial(
             self.change_notebook, notebook=notebook,
         )))
         action = menu.addAction(self.tr('Remove Notebook'), Slot()(partial(
             self.remove_notebook, notebook=notebook,
         )))
         action.setEnabled(False)
         widget.ui = Ui_Notebook()
         widget.ui.setupUi(widget)
         widget.ui.name.setText(notebook.name)
         widget.ui.content.setText(self.tr('Containts %d notes') % count)
         widget.ui.actionBtn.setIcon(QIcon.fromTheme('gtk-properties'))
         widget.setFixedHeight(50)
         layout.addWidget(widget)
         widget.ui.actionBtn.clicked.connect(Slot()(partial(
             self.show_notebook_menu,
             menu=menu, widget=widget,
         )))
コード例 #2
0
class StatusScrollArea(QScrollArea):
    def __init__(self):
        super(StatusScrollArea, self).__init__()

        self._width = 0
        self._group_count = 0

        self._pan_pos = None

        self.__create_ui()
        self.__init_ui()

    def __create_ui(self):
        self.container = QWidget()
        self.container_layout = QHBoxLayout()

        self.container.setLayout(self.container_layout)
        self.setWidget(self.container)

    def __init_ui(self):
        self.container.setFixedHeight(TOOLBAR_BUTTON_SIZE)
        self.container_layout.setContentsMargins(0, 0, 0, 0)
        self.container_layout.setSpacing(1)
        self.container_layout.setAlignment(Qt.AlignLeft)

        self.setFixedHeight(TOOLBAR_BUTTON_SIZE)
        self.setFocusPolicy(Qt.NoFocus)
        self.setFrameShape(self.NoFrame)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

    def _update_width(self, expand_value):
        self._width += expand_value
        self.container.setFixedWidth(self._width + self._group_count)

    def mousePressEvent(self, event):
        if event.button() == Qt.MidButton:
            QApplication.setOverrideCursor(QCursor(Qt.SizeHorCursor))
            self._pan_pos = event.globalPos()
            event.accept()
        else:
            event.ignore()

    def mouseReleaseEvent(self, event):
        if event.button() == Qt.MidButton:
            QApplication.restoreOverrideCursor()
            self._pan_pos = None
            event.accept()
        else:
            event.ignore()

    def mouseMoveEvent(self, event):
        if self._pan_pos:
            h_bar = self.horizontalScrollBar()
            h_bar_pos = h_bar.sliderPosition()
            cursor_pos = event.globalPos()
            cursor_delta = (cursor_pos - self._pan_pos).x()

            h_bar.setValue(h_bar_pos - cursor_delta)
            self._pan_pos = cursor_pos
            event.accept()
        else:
            event.ignore()

    def wheelEvent(self, event):
        if event.orientation() == Qt.Vertical:
            num_degrees = event.delta() / 8
            h_bar = self.horizontalScrollBar()
            h_bar_pos = h_bar.sliderPosition()

            h_bar.setValue(h_bar_pos - num_degrees)
        else:
            super(StatusScrollArea, self).wheelEvent(event)

    def resizeEvent(self, event):
        max_scroll = max(0, self.container.width() - event.size().width())
        self.horizontalScrollBar().setMaximum(max_scroll)

    def add_widget(self, widget):
        # add widget to layout
        self.container_layout.addWidget(widget)

        # connect widget for future update when user interact with it
        widget.toggled.connect(self._update_width)

        # expand widget layout
        self._width += widget.max_length()
        self._group_count += 1
        self.container.setFixedWidth(self._width)