Skip to content

Commit

Permalink
Update translation
Browse files Browse the repository at this point in the history
  • Loading branch information
krrr committed Mar 4, 2017
1 parent 2f22b61 commit a4ef65a
Show file tree
Hide file tree
Showing 4 changed files with 451 additions and 265 deletions.
1 change: 1 addition & 0 deletions hazama/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# 1. Only slots methods which is auto connected need Slot decorator
# 2. StyleSheets using dynamic property require (un)polish to take effect
# 3. Subclass of QWidget refuse to paint QSS background. Use QFrame or set WA_StyledBackground
# 4. Inner class will break qt linguist!

def main_entry():
import time
Expand Down
103 changes: 52 additions & 51 deletions hazama/ui/diarylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,69 +209,70 @@ def sizeHint(self, option, index):
return QSize(-1, self._itemW.heightWithTag if hasTag else self._itemW.heightNoTag)


class DiaryListScrollBar(QScrollBar):
"""Annotated scrollbar."""
wantSetRow = Signal(int)

def __init__(self, parent):
super().__init__(parent, objectName='diaryListSB')
self._poses = ()
self._pairs = () # year: row
self._color = QColor('gold')

def paintEvent(self, event):
super().paintEvent(event)
if not self._poses:
return
p = QPainter(self)
# avoid painting on slider handle
opt = QStyleOptionSlider()
self.initStyleOption(opt)
groove = self.style().subControlRect(QStyle.CC_ScrollBar, opt,
QStyle.SC_ScrollBarGroove, self)
slider = self.style().subControlRect(QStyle.CC_ScrollBar, opt,
QStyle.SC_ScrollBarSlider, self)
p.setClipRegion(QRegion(groove) - QRegion(slider), Qt.IntersectClip)

x, y, w, h = groove.getRect()
x += 1
w -= 2
c = self._color
c.setAlpha(70)
p.setBrush(c)
c.setAlpha(145)
p.setPen(QPen(c, scaleRatio))
p.drawRects([QRect(x, y+h*i, w, 3*scaleRatio) for i in self._poses])

def contextMenuEvent(self, event):
"""Used to jump to the first day of years. Original menu is almost useless."""
menu = QMenu()
menu.addAction(QAction(self.tr('Go to the first diary of each year'), menu, enabled=False))
for year, row in self._pairs:
menu.addAction(QAction(str(year), menu,
triggered=lambda r=row: self.wantSetRow.emit(r)))
menu.exec_(event.globalPos())
menu.deleteLater()

def setPositions(self, rowCount, pairs):
self._poses = tuple(p / rowCount for _, p in pairs)
self._pairs = pairs

annotateColor = NProperty(QColor, '_color')


class DiaryList(QListView):
"""Main List that display preview of diaries"""
startLoading = Signal()
countChanged = Signal()

class ScrollBar(QScrollBar):
"""Annotated scrollbar."""
wantSetRow = Signal(int)

def __init__(self, parent):
super().__init__(parent, objectName='diaryListSB')
self._poses = ()
self._pairs = () # year: row
self._color = QColor('gold')

def paintEvent(self, event):
super().paintEvent(event)
if not self._poses:
return
p = QPainter(self)
# avoid painting on slider handle
opt = QStyleOptionSlider()
self.initStyleOption(opt)
groove = self.style().subControlRect(QStyle.CC_ScrollBar, opt,
QStyle.SC_ScrollBarGroove, self)
slider = self.style().subControlRect(QStyle.CC_ScrollBar, opt,
QStyle.SC_ScrollBarSlider, self)
p.setClipRegion(QRegion(groove) - QRegion(slider), Qt.IntersectClip)

x, y, w, h = groove.getRect()
x += 1
w -= 2
c = self._color
c.setAlpha(70)
p.setBrush(c)
c.setAlpha(145)
p.setPen(QPen(c, scaleRatio))
p.drawRects([QRect(x, y+h*i, w, 3*scaleRatio) for i in self._poses])

def contextMenuEvent(self, event):
"""Used to jump to the first day of years. Original menu is almost useless."""
menu = QMenu()
menu.addAction(QAction(self.tr('Go to the first diary of each year'), menu, enabled=False))
for year, row in self._pairs:
menu.addAction(QAction(str(year), menu,
triggered=lambda r=row: self.wantSetRow.emit(r)))
menu.exec_(event.globalPos())
menu.deleteLater()

def setPositions(self, rowCount, pairs):
self._poses = tuple(p / rowCount for _, p in pairs)
self._pairs = pairs

annotateColor = NProperty(QColor, '_color')

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 = DiaryList.ScrollBar(self)
self.scrollbar = DiaryListScrollBar(self)
self.scrollbar.wantSetRow.connect(self.setRow)
self.setVerticalScrollBar(self.scrollbar)

Expand Down
Loading

0 comments on commit a4ef65a

Please sign in to comment.