Beispiel #1
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self._delegate = None
        # ScrollPerPixel means user can draw scroll bar and move list items pixel by pixel,
        # but mouse wheel still scroll item by item (the number of items scrolled depends on
        # qApp.wheelScrollLines)
        self.setVerticalScrollMode(self.ScrollPerPixel)
        self.scrollbar = DiaryListScrollBar(self)
        self.scrollbar.wantSetRow.connect(self.setRow)
        self.setVerticalScrollBar(self.scrollbar)

        # disable default editor. Editor is implemented in the View
        self.setEditTriggers(QAbstractItemView.NoEditTriggers)

        self.originModel = DiaryModel(self)
        self.modelProxy = MultiSortFilterProxyModel(self)
        self.modelProxy.setSourceModel(self.originModel)
        self.modelProxy.setDynamicSortFilter(True)
        self.modelProxy.addFilter([db.TAGS], cs=Qt.CaseSensitive)
        self.modelProxy.addFilter([db.TITLE, db.TEXT], cs=Qt.CaseInsensitive)
        self.modelProxy.addFilter([db.DATETIME])
        self.setModel(self.modelProxy)
        self.sort()

        self.setupTheme()

        self.editAct = QAction(self.tr('Edit'), self)
        self.delAct = QAction(makeQIcon(':/menu/list-delete.png',
                                        scaled2x=True),
                              self.tr('Delete'),
                              self,
                              shortcut=QKeySequence.Delete)
        self.randAct = QAction(makeQIcon(':/menu/random-big.png',
                                         scaled2x=True),
                               self.tr('Random'),
                               self,
                               shortcut=QKeySequence(Qt.Key_F7),
                               triggered=self.selectRandomly)
        self.gotoAct = QAction(self.tr('Go to location'), self)
        for i in (self.editAct, self.delAct, self.randAct, self.gotoAct):
            self.addAction(i)