mirror of https://github.com/Syncplay/syncplay
Add icons when file switch is possible
This commit is contained in:
parent
a5d99c5f25
commit
b06edbc91d
Binary file not shown.
After Width: | Height: | Size: 813 B |
Binary file not shown.
After Width: | Height: | Size: 944 B |
|
@ -131,6 +131,8 @@ STYLE_NOFILEITEM_COLOR = 'blue'
|
|||
STYLE_NOTCONTROLLER_COLOR = 'grey'
|
||||
|
||||
USERLIST_GUI_USERNAME_OFFSET = 21 # Pixels
|
||||
USERLIST_GUI_USERNAME_COLUMN = 0
|
||||
USERLIST_GUI_FILENAME_COLUMN = 3
|
||||
|
||||
MPLAYER_SLAVE_ARGS = ['-slave', '--hr-seek=always', '-nomsgcolor', '-msglevel', 'all=1:global=4:cplayer=4', '-af', 'scaletempo']
|
||||
# --quiet works with both mpv 0.2 and 0.3
|
||||
|
@ -163,6 +165,10 @@ CONFIG_NAME_MARKER = ":"
|
|||
CONFIG_VALUE_MARKER = "="
|
||||
USERITEM_CONTROLLER_ROLE = 0
|
||||
USERITEM_READY_ROLE = 1
|
||||
FILEITEM_SWITCH_ROLE = 1
|
||||
FILEITEM_SWITCH_NO_SWITCH = 0
|
||||
FILEITEM_SWITCH_FILE_SWITCH = 1
|
||||
FILEITEM_SWITCH_STREAM_SWITCH = 2
|
||||
|
||||
SYNCPLAY_UPDATE_URL = u"http://syncplay.pl/checkforupdate?{}" # Params
|
||||
SYNCPLAY_DOWNLOAD_URL = "http://syncplay.pl/download/"
|
|
@ -17,15 +17,15 @@ class UserlistItemDelegate(QtGui.QStyledItemDelegate):
|
|||
|
||||
def sizeHint(self, option, index):
|
||||
size = QtGui.QStyledItemDelegate.sizeHint(self, option, index)
|
||||
if (index.column() == 0):
|
||||
if (index.column() == constants.USERLIST_GUI_USERNAME_COLUMN):
|
||||
size.setWidth(size.width() + constants.USERLIST_GUI_USERNAME_OFFSET)
|
||||
return size
|
||||
|
||||
def paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex):
|
||||
column = indexQModelIndex.column()
|
||||
if column == 0:
|
||||
if column == constants.USERLIST_GUI_USERNAME_COLUMN:
|
||||
currentQAbstractItemModel = indexQModelIndex.model()
|
||||
itemQModelIndex = currentQAbstractItemModel.index(indexQModelIndex.row(), 0, indexQModelIndex.parent())
|
||||
itemQModelIndex = currentQAbstractItemModel.index(indexQModelIndex.row(), constants.USERLIST_GUI_USERNAME_COLUMN, indexQModelIndex.parent())
|
||||
if sys.platform.startswith('win'):
|
||||
resourcespath = utils.findWorkingDir() + "\\resources\\"
|
||||
else:
|
||||
|
@ -56,6 +56,29 @@ class UserlistItemDelegate(QtGui.QStyledItemDelegate):
|
|||
isUserRow = indexQModelIndex.parent() != indexQModelIndex.parent().parent()
|
||||
if isUserRow:
|
||||
optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+constants.USERLIST_GUI_USERNAME_OFFSET)
|
||||
if column == constants.USERLIST_GUI_FILENAME_COLUMN:
|
||||
if sys.platform.startswith('win'):
|
||||
resourcespath = utils.findWorkingDir() + "\\resources\\"
|
||||
else:
|
||||
resourcespath = utils.findWorkingDir() + "/resources/"
|
||||
currentQAbstractItemModel = indexQModelIndex.model()
|
||||
itemQModelIndex = currentQAbstractItemModel.index(indexQModelIndex.row(), constants.USERLIST_GUI_FILENAME_COLUMN, indexQModelIndex.parent())
|
||||
fileSwitchRole = currentQAbstractItemModel.data(itemQModelIndex, Qt.UserRole + constants.FILEITEM_SWITCH_ROLE)
|
||||
if fileSwitchRole == constants.FILEITEM_SWITCH_FILE_SWITCH:
|
||||
fileSwitchIconQPixmap = QtGui.QPixmap(resourcespath + "film_go.png")
|
||||
itemQPainter.drawPixmap (
|
||||
(optionQStyleOptionViewItem.rect.x()),
|
||||
optionQStyleOptionViewItem.rect.y(),
|
||||
fileSwitchIconQPixmap.scaled(16, 16, Qt.KeepAspectRatio))
|
||||
optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+16)
|
||||
|
||||
elif fileSwitchRole == constants.FILEITEM_SWITCH_STREAM_SWITCH:
|
||||
streamSwitchIconQPixmap = QtGui.QPixmap(resourcespath + "world_go.png")
|
||||
itemQPainter.drawPixmap (
|
||||
(optionQStyleOptionViewItem.rect.x()),
|
||||
optionQStyleOptionViewItem.rect.y(),
|
||||
streamSwitchIconQPixmap.scaled(16, 16, Qt.KeepAspectRatio))
|
||||
optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+16)
|
||||
QtGui.QStyledItemDelegate.paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex)
|
||||
|
||||
class MainWindow(QtGui.QMainWindow):
|
||||
|
@ -118,6 +141,25 @@ class MainWindow(QtGui.QMainWindow):
|
|||
else:
|
||||
self.newMessage(time.strftime(constants.UI_TIME_FORMAT, time.localtime()) + message + "<br />")
|
||||
|
||||
def getFileSwitchState(self, filename):
|
||||
if filename:
|
||||
if self._syncplayClient.userlist.currentUser.file and filename == self._syncplayClient.userlist.currentUser.file['name']:
|
||||
return constants.FILEITEM_SWITCH_NO_SWITCH
|
||||
if isURL(filename):
|
||||
return constants.FILEITEM_SWITCH_FILE_SWITCH
|
||||
else:
|
||||
currentPath = self._syncplayClient.userlist.currentUser.file["path"] if self._syncplayClient.userlist.currentUser.file else None
|
||||
if currentPath:
|
||||
currentDirectory = os.path.dirname(currentPath)
|
||||
newPath = os.path.join(currentDirectory, filename)
|
||||
if os.path.isfile(newPath):
|
||||
return constants.FILEITEM_SWITCH_FILE_SWITCH
|
||||
else:
|
||||
return constants.FILEITEM_SWITCH_NO_SWITCH
|
||||
else:
|
||||
return constants.FILEITEM_SWITCH_NO_SWITCH
|
||||
return constants.FILEITEM_SWITCH_NO_SWITCH
|
||||
|
||||
def showUserList(self, currentUser, rooms):
|
||||
self._usertreebuffer = QtGui.QStandardItemModel()
|
||||
self._usertreebuffer.setHorizontalHeaderLabels(
|
||||
|
@ -157,6 +199,8 @@ class MainWindow(QtGui.QMainWindow):
|
|||
filesizeitem = QtGui.QStandardItem(formatSize(user.file['size']))
|
||||
filedurationitem = QtGui.QStandardItem("({})".format(formatTime(user.file['duration'])))
|
||||
filenameitem = QtGui.QStandardItem((user.file['name']))
|
||||
fileSwitchState = self.getFileSwitchState(user.file['name']) if room == currentUser.room else None
|
||||
filenameitem.setData(fileSwitchState, Qt.UserRole + constants.FILEITEM_SWITCH_ROLE)
|
||||
if currentUser.file:
|
||||
sameName = sameFilename(user.file['name'], currentUser.file['name'])
|
||||
sameSize = sameFilesize(user.file['size'], currentUser.file['size'])
|
||||
|
|
Loading…
Reference in New Issue