diff options
Diffstat (limited to 'wgSongList.py')
-rw-r--r-- | wgSongList.py | 68 |
1 files changed, 50 insertions, 18 deletions
diff --git a/wgSongList.py b/wgSongList.py index f669c6a..8b6dc1f 100644 --- a/wgSongList.py +++ b/wgSongList.py @@ -1,4 +1,4 @@ -from PyQt4 import QtGui, QtCore +from PyQt4 import QtGui, QtCore, QtSvg import sys from traceback import print_exc @@ -18,9 +18,12 @@ class SongList(QtGui.QWidget): """The SongList widget is a list optimized for displaying an array of songs, with filtering option.""" # CONFIGURATION VARIABLES " height of line in pxl" - lineHeight=20 + lineHeight=30 + " font size in pxl" + fontSize=16 " margin" margin=4 + vmargin=(lineHeight-fontSize)/2-1 " width of the vscrollbar" scrollbarWidth=15 " minimum column width" @@ -32,7 +35,7 @@ class SongList(QtGui.QWidget): " background color" clrBg=QtGui.QColor(255,255,255) " indentation of hierarchy, in pixels" - indentation=20 + indentation=lineHeight " what function to call when the list is double clicked" onDoubleClick=None @@ -70,6 +73,9 @@ class SongList(QtGui.QWidget): resizeColumn=None # indicates this column should be recalculated redrawID=None # redraw this ID/row only + wgGfxAlbum=QtSvg.QSvgRenderer('gfx/gnome-cd.svg') + wgGfxArtist=QtSvg.QSvgRenderer('gfx/user_icon.svg') + def __init__(self, parent, headers, onDoubleClick): QtGui.QWidget.__init__(self, parent) @@ -114,6 +120,10 @@ class SongList(QtGui.QWidget): or QtCore.Qt.StrongFocus or QtCore.Qt.WheelFocus) self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent) + font=QtGui.QFont() + font.setPixelSize(self.fontSize) + font.setFamily('Comic Sans Ms') + self.setFont(font) def sizeHint(self): return QtCore.QSize(10000,10000) @@ -363,8 +373,8 @@ class SongList(QtGui.QWidget): self.hScrollbar.setVisible(True) self.hScrollbar.setMinimum(0) self.hScrollbar.setMaximum((self.scrollWidth-self.width())/2) - self.hScrollbar.resize(self.width(), self.lineHeight) - self.hScrollbar.move(0, self.height()-self.lineHeight-1) + self.hScrollbar.resize(self.width()-4, self.scrollbarWidth) + self.hScrollbar.move(2, self.height()-self.hScrollbar.height()-1) # some changes because the hScrollbar takes some vertical space ... self.vScrollbar.resize(self.vScrollbar.width(), self.vScrollbar.height()-self.lineHeight) @@ -559,6 +569,7 @@ class SongList(QtGui.QWidget): lineHeight=self.lineHeight margin=self.margin + vmargin=self.vmargin selRows=self.selRows width=self.width() if self.vScrollbar.isVisible(): @@ -594,7 +605,7 @@ class SongList(QtGui.QWidget): x=margin+self.xOffset for hdr in self.headers: if hdr[2]: - p.drawText(QtCore.QPoint(x, lineHeight-margin), hdr[0]) + p.drawText(x, vmargin, hdr[1], lineHeight, QtCore.Qt.AlignLeft, hdr[0]) x+=hdr[1] p.drawLine(QtCore.QPoint(x-margin,0), QtCore.QPoint(x-margin,lineHeight)) @@ -614,6 +625,7 @@ class SongList(QtGui.QWidget): song=self.fSongs[row] lineHeight=self.lineHeight margin=self.margin + vmargin=self.vmargin id=song._data['id'] # determine color of row. Default is row-color, but can be overridden by @@ -658,11 +670,11 @@ class SongList(QtGui.QWidget): rect=p.boundingRect(x, y, hdr[1]-margin, lineHeight, QtCore.Qt.AlignLeft, str(song.getTag(hdr[0]))) text=str(song.getTag(hdr[0])) p.setPen(clrTxt) - p.drawText(x, y+1, hdr[1]-margin, lineHeight, QtCore.Qt.AlignLeft, text) + p.drawText(x, y+vmargin, hdr[1]-margin, lineHeight, QtCore.Qt.AlignLeft, text) if rect.width()>hdr[1]-margin: # print ellipsis, if necessary p.fillRect(x+hdr[1]-15,y+1,15,lineHeight-1, QtGui.QBrush(clr)) - p.drawText(x+hdr[1]-15,y+1,15,lineHeight-1, QtCore.Qt.AlignLeft, "...") + p.drawText(x+hdr[1]-15,y+vmargin,15,lineHeight-1, QtCore.Qt.AlignLeft, "...") x+=hdr[1] p.setPen(QtCore.Qt.black) p.drawLine(QtCore.QPoint(x-margin,y), QtCore.QPoint(x-margin,y+lineHeight)) @@ -713,11 +725,12 @@ class SongList(QtGui.QWidget): height=self.height() lineHeight=self.lineHeight margin=self.margin + vmargin=self.vmargin # paint the headers! p.fillRect(QtCore.QRect(0,0,width+self.vScrollbar.width(),lineHeight), QtGui.QBrush(QtCore.Qt.lightGray)) p.drawRect(QtCore.QRect(0,0,width+self.vScrollbar.width()-1,lineHeight-1)) - p.drawText(margin, 1, width, lineHeight, QtCore.Qt.AlignLeft, self.groupByStr) + p.drawText(margin, vmargin, width, lineHeight, QtCore.Qt.AlignLeft, self.groupByStr) entries=self.fSongs @@ -733,13 +746,14 @@ class SongList(QtGui.QWidget): isSong=isinstance(entry[LIB_VALUE], Song) if isSong: + prefix='' text=entry[LIB_VALUE].getTitle() #text=str(entry) else: if entry[LIB_EXPANDED]==1: prefix='-' elif entry[LIB_EXPANDED]==0: prefix='+' - text='%s\t%s: %s'%(prefix, self.levels[level], entry[LIB_VALUE]) - #text='%s\t%s: %s'%(prefix, self.levels[level], str(entry)) + text='%s: %s'%(self.levels[level], entry[LIB_VALUE]) + #text='%%s: %s'%(prefix, self.levels[level], str(entry)) clr=self.colors[row%2] # background color of the row clrTxt=QtCore.Qt.black @@ -761,14 +775,32 @@ class SongList(QtGui.QWidget): for i in self.selMiscs: if index==i: - clr=QtCore.Qt.lightGray + clr=self.clrSel clrTxt=QtCore.Qt.white + + # it has a VIP-status! + if isSong and entry[LIB_VALUE].getID()==int(self.clrID[0]): + clrTxt=QtCore.Qt.white + clr=self.clrID[1] - p.fillRect(QtCore.QRect(x+indent*entry[LIB_INDENT]-2,y,width-3,lineHeight), clr) + left=x+indent*(1+level) + top=y+vmargin + p.fillRect(QtCore.QRect(left,y,width-3,lineHeight), clr) p.setPen(clrTxt) - p.drawText(x+indent*entry[LIB_INDENT],y+1, width, lineHeight, QtCore.Qt.AlignLeft, text) + p.drawText(left, top, 15, lineHeight, QtCore.Qt.AlignLeft, prefix) + p.drawText(left+15, top, width, lineHeight, QtCore.Qt.AlignLeft, text) p.setPen(QtCore.Qt.black) + obj=None + if level<len(self.levels): + if self.levels[level]=='artist': + obj=self.wgGfxArtist + if self.levels[level]=='album': + obj=self.wgGfxAlbum + + if obj: + obj.render(p, QtCore.QRectF(indent*level+1,y+1,lineHeight-1,lineHeight-1)) + y+=lineHeight row+=1 index=self.libIthVisRowIndex(index) @@ -793,9 +825,9 @@ class SongList(QtGui.QWidget): p.setPen(QtCore.Qt.lightGray) p.drawRect(QtCore.QRect(1,1,self.width()-3,self.height()-3)) - text='%s - %s' % (self.selMiscs, '') + #text='%s - %s' % (self.selMiscs, '') #text='%s - %s' % (str(self.selRows), str(self.selIDs)) - r=QtCore.QRect(10,self.height()-40,self.width()-20,20) - p.fillRect(r, QtGui.QBrush(QtCore.Qt.white)) - p.drawText(r,QtCore.Qt.AlignLeft, text) + #r=QtCore.QRect(10,self.height()-40,self.width()-20,20) + #p.fillRect(r, QtGui.QBrush(QtCore.Qt.white)) + #p.drawText(r,QtCore.Qt.AlignLeft, text) |