forked from openlp/openlp
Got screen to update after adding and removing files
Added tooltip of entire path name bzr-revno: 335
This commit is contained in:
parent
f0177bdbda
commit
851c669e8b
@ -18,6 +18,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|||||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
import os.path
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
from openlp.core.resources import *
|
from openlp.core.resources import *
|
||||||
from openlp.core.lib import Plugin, PluginUtils, MediaManagerItem, ImageServiceItem
|
from openlp.core.lib import Plugin, PluginUtils, MediaManagerItem, ImageServiceItem
|
||||||
@ -33,7 +35,6 @@ class ListWithPreviews(QtCore.QAbstractListModel):
|
|||||||
log=logging.getLogger("ListWithPreviews")
|
log=logging.getLogger("ListWithPreviews")
|
||||||
log.info("started")
|
log.info("started")
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
QtCore.QAbstractListModel.__init__(self)
|
QtCore.QAbstractListModel.__init__(self)
|
||||||
self.items=[] # will be a list of (filename, QPixmap) tuples
|
self.items=[] # will be a list of (filename, QPixmap) tuples
|
||||||
self.rowheight=50
|
self.rowheight=50
|
||||||
@ -41,23 +42,28 @@ class ListWithPreviews(QtCore.QAbstractListModel):
|
|||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
return len(self.items)
|
return len(self.items)
|
||||||
def insertRow(self, row, filename):
|
def insertRow(self, row, filename):
|
||||||
|
self.beginInsertRows(QModelIndex(),row,row)
|
||||||
log.info("insert row %d:%s"%(row,filename))
|
log.info("insert row %d:%s"%(row,filename))
|
||||||
|
# get short filename to display next to image
|
||||||
|
(prefix, shortfilename) = os.path.split(str(filename))
|
||||||
|
log.info("shortfilename=%s"%(shortfilename))
|
||||||
|
# create a preview image
|
||||||
preview = QtGui.QPixmap(str(filename))
|
preview = QtGui.QPixmap(str(filename))
|
||||||
w=self.maximagewidth;h=self.rowheight
|
w=self.maximagewidth;h=self.rowheight
|
||||||
preview = preview.scaled(w,h, Qt.KeepAspectRatio)
|
preview = preview.scaled(w,h, Qt.KeepAspectRatio)
|
||||||
realw=preview.width(); realh=preview.height()
|
realw=preview.width(); realh=preview.height()
|
||||||
|
# and move it to the centre of the preview space
|
||||||
p=QPixmap(w,h)
|
p=QPixmap(w,h)
|
||||||
p.fill(Qt.transparent)
|
p.fill(Qt.transparent)
|
||||||
painter=QPainter(p)
|
painter=QPainter(p)
|
||||||
# gradient=QRadialGradient(w/2,h/2,min(w,h)/2, w/2, h/2)
|
|
||||||
# gradient.setColorAt(0, QColor.fromRgbF(0, 0, 0, 1));
|
|
||||||
# gradient.setColorAt(1, QColor.fromRgbF(0, 0, 0, 0));
|
|
||||||
# painter.fillRect(0,0,w,h,gradient)
|
|
||||||
painter.drawPixmap((w-realw)/2,(h-realh)/2,preview)
|
painter.drawPixmap((w-realw)/2,(h-realh)/2,preview)
|
||||||
(prefix, shortfilename) =os.path.split(filename)
|
# finally create the row
|
||||||
self.items.insert(row, (filename, p, shortfilename))
|
self.items.insert(row, (filename, p, shortfilename))
|
||||||
|
self.endInsertRows()
|
||||||
def removeRow(self, row):
|
def removeRow(self, row):
|
||||||
|
self.beginRemoveRows(QModelIndex(), row,row)
|
||||||
self.items.pop(row)
|
self.items.pop(row)
|
||||||
|
self.endRemoveRows()
|
||||||
def addRow(self, filename):
|
def addRow(self, filename):
|
||||||
self.insertRow(len(self.items), filename)
|
self.insertRow(len(self.items), filename)
|
||||||
|
|
||||||
@ -70,6 +76,8 @@ class ListWithPreviews(QtCore.QAbstractListModel):
|
|||||||
retval= self.items[row][2]
|
retval= self.items[row][2]
|
||||||
elif role == Qt.DecorationRole:
|
elif role == Qt.DecorationRole:
|
||||||
retval= self.items[row][1]
|
retval= self.items[row][1]
|
||||||
|
elif role == Qt.ToolTipRole:
|
||||||
|
retval= self.items[row][0]
|
||||||
else:
|
else:
|
||||||
retval= QVariant()
|
retval= QVariant()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user