SlideController cleanups

This commit is contained in:
Tim Bentley 2011-01-21 20:53:08 +00:00
parent 84b252fe70
commit f64a25c81c

View File

@ -81,9 +81,9 @@ class SlideController(QtGui.QWidget):
self.Panel = QtGui.QWidget(parent.ControlSplitter) self.Panel = QtGui.QWidget(parent.ControlSplitter)
self.slideList = {} self.slideList = {}
# Layout for holding panel # Layout for holding panel
self.PanelLayout = QtGui.QVBoxLayout(self.Panel) self.panelLayout = QtGui.QVBoxLayout(self.Panel)
self.PanelLayout.setSpacing(0) self.panelLayout.setSpacing(0)
self.PanelLayout.setMargin(0) self.panelLayout.setMargin(0)
# Type label for the top of the slide controller # Type label for the top of the slide controller
self.TypeLabel = QtGui.QLabel(self.Panel) self.TypeLabel = QtGui.QLabel(self.Panel)
if self.isLive: if self.isLive:
@ -97,35 +97,35 @@ class SlideController(QtGui.QWidget):
self.typePrefix = u'preview' self.typePrefix = u'preview'
self.TypeLabel.setStyleSheet(u'font-weight: bold; font-size: 12pt;') self.TypeLabel.setStyleSheet(u'font-weight: bold; font-size: 12pt;')
self.TypeLabel.setAlignment(QtCore.Qt.AlignCenter) self.TypeLabel.setAlignment(QtCore.Qt.AlignCenter)
self.PanelLayout.addWidget(self.TypeLabel) self.panelLayout.addWidget(self.TypeLabel)
# Splitter # Splitter
self.Splitter = QtGui.QSplitter(self.Panel) self.Splitter = QtGui.QSplitter(self.Panel)
self.Splitter.setOrientation(QtCore.Qt.Vertical) self.Splitter.setOrientation(QtCore.Qt.Vertical)
self.PanelLayout.addWidget(self.Splitter) self.panelLayout.addWidget(self.Splitter)
# Actual controller section # Actual controller section
self.Controller = QtGui.QWidget(self.Splitter) self.controller = QtGui.QWidget(self.Splitter)
self.Controller.setGeometry(QtCore.QRect(0, 0, 100, 536)) self.controller.setGeometry(QtCore.QRect(0, 0, 100, 536))
self.Controller.setSizePolicy( self.controller.setSizePolicy(
QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
QtGui.QSizePolicy.Maximum)) QtGui.QSizePolicy.Maximum))
self.ControllerLayout = QtGui.QVBoxLayout(self.Controller) self.controllerLayout = QtGui.QVBoxLayout(self.controller)
self.ControllerLayout.setSpacing(0) self.controllerLayout.setSpacing(0)
self.ControllerLayout.setMargin(0) self.controllerLayout.setMargin(0)
# Controller list view # Controller list view
self.PreviewListWidget = SlideList(self) self.previewListWidget = SlideList(self)
self.PreviewListWidget.setColumnCount(1) self.previewListWidget.setColumnCount(1)
self.PreviewListWidget.horizontalHeader().setVisible(False) self.previewListWidget.horizontalHeader().setVisible(False)
self.PreviewListWidget.setColumnWidth( self.previewListWidget.setColumnWidth(
0, self.Controller.width()) 0, self.controller.width())
self.PreviewListWidget.isLive = self.isLive self.previewListWidget.isLive = self.isLive
self.PreviewListWidget.setObjectName(u'PreviewListWidget') self.previewListWidget.setObjectName(u'PreviewListWidget')
self.PreviewListWidget.setSelectionBehavior(1) self.previewListWidget.setSelectionBehavior(1)
self.PreviewListWidget.setEditTriggers( self.previewListWidget.setEditTriggers(
QtGui.QAbstractItemView.NoEditTriggers) QtGui.QAbstractItemView.NoEditTriggers)
self.PreviewListWidget.setHorizontalScrollBarPolicy( self.previewListWidget.setHorizontalScrollBarPolicy(
QtCore.Qt.ScrollBarAlwaysOff) QtCore.Qt.ScrollBarAlwaysOff)
self.PreviewListWidget.setAlternatingRowColors(True) self.previewListWidget.setAlternatingRowColors(True)
self.ControllerLayout.addWidget(self.PreviewListWidget) self.controllerLayout.addWidget(self.previewListWidget)
# Build the full toolbar # Build the full toolbar
self.Toolbar = OpenLPToolbar(self) self.Toolbar = OpenLPToolbar(self)
sizeToolbarPolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, sizeToolbarPolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed,
@ -204,7 +204,7 @@ class SlideController(QtGui.QWidget):
translate('OpenLP.SlideController', translate('OpenLP.SlideController',
'Edit and reload song preview'), 'Edit and reload song preview'),
self.onEditSong) self.onEditSong)
self.ControllerLayout.addWidget(self.Toolbar) self.controllerLayout.addWidget(self.Toolbar)
# Build a Media ToolBar # Build a Media ToolBar
self.Mediabar = OpenLPToolbar(self) self.Mediabar = OpenLPToolbar(self)
self.Mediabar.addToolbarButton( self.Mediabar.addToolbarButton(
@ -245,7 +245,7 @@ class SlideController(QtGui.QWidget):
self.volumeSlider.setGeometry(QtCore.QRect(90, 260, 221, 24)) self.volumeSlider.setGeometry(QtCore.QRect(90, 260, 221, 24))
self.volumeSlider.setObjectName(u'volumeSlider') self.volumeSlider.setObjectName(u'volumeSlider')
self.Mediabar.addToolbarWidget(u'Audio Volume', self.volumeSlider) self.Mediabar.addToolbarWidget(u'Audio Volume', self.volumeSlider)
self.ControllerLayout.addWidget(self.Mediabar) self.controllerLayout.addWidget(self.Mediabar)
# Screen preview area # Screen preview area
self.PreviewFrame = QtGui.QFrame(self.Splitter) self.PreviewFrame = QtGui.QFrame(self.Splitter)
self.PreviewFrame.setGeometry(QtCore.QRect(0, 0, 300, 300 * self.ratio)) self.PreviewFrame.setGeometry(QtCore.QRect(0, 0, 300, 300 * self.ratio))
@ -292,7 +292,7 @@ class SlideController(QtGui.QWidget):
self.SlideLayout.insertWidget(0, self.SlidePreview) self.SlideLayout.insertWidget(0, self.SlidePreview)
self.grid.addLayout(self.SlideLayout, 0, 0, 1, 1) self.grid.addLayout(self.SlideLayout, 0, 0, 1, 1)
# Signals # Signals
QtCore.QObject.connect(self.PreviewListWidget, QtCore.QObject.connect(self.previewListWidget,
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSlideSelected) QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSlideSelected)
if self.isLive: if self.isLive:
QtCore.QObject.connect(self.BlankScreen, QtCore.QObject.connect(self.BlankScreen,
@ -309,14 +309,14 @@ class SlideController(QtGui.QWidget):
self.Toolbar.makeWidgetsInvisible(self.loopList) self.Toolbar.makeWidgetsInvisible(self.loopList)
self.Toolbar.actions[u'Stop Loop'].setVisible(False) self.Toolbar.actions[u'Stop Loop'].setVisible(False)
else: else:
QtCore.QObject.connect(self.PreviewListWidget, QtCore.QObject.connect(self.previewListWidget,
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
self.onGoLiveClick) self.onGoLiveClick)
self.Toolbar.makeWidgetsInvisible(self.songEditList) self.Toolbar.makeWidgetsInvisible(self.songEditList)
self.Mediabar.setVisible(False) self.Mediabar.setVisible(False)
if self.isLive: if self.isLive:
self.setLiveHotkeys(self) self.setLiveHotkeys(self)
self.PreviewListWidget.addActions( self.previewListWidget.addActions(
[self.previousItem, [self.previousItem,
self.nextItem, self.nextItem,
self.previousService, self.previousService,
@ -330,7 +330,7 @@ class SlideController(QtGui.QWidget):
self.escapeItem]) self.escapeItem])
else: else:
self.setPreviewHotkeys() self.setPreviewHotkeys()
self.PreviewListWidget.addActions( self.previewListWidget.addActions(
[self.nextItem, [self.nextItem,
self.previousItem]) self.previousItem])
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
@ -464,30 +464,30 @@ class SlideController(QtGui.QWidget):
self.SlidePreview.setFixedSize(QtCore.QSize(max_width, self.SlidePreview.setFixedSize(QtCore.QSize(max_width,
max_width / self.ratio)) max_width / self.ratio))
# Make sure that the frames have the correct size. # Make sure that the frames have the correct size.
self.PreviewListWidget.setColumnWidth(0, self.previewListWidget.setColumnWidth(0,
self.PreviewListWidget.viewport().size().width()) self.previewListWidget.viewport().size().width())
if self.serviceItem: if self.serviceItem:
# Sort out songs, bibles, etc. # Sort out songs, bibles, etc.
if self.serviceItem.is_text(): if self.serviceItem.is_text():
self.PreviewListWidget.resizeRowsToContents() self.previewListWidget.resizeRowsToContents()
else: else:
# Sort out image heights. # Sort out image heights.
width = self.parent.ControlSplitter.sizes()[self.split] width = self.parent.ControlSplitter.sizes()[self.split]
for framenumber in range(len(self.serviceItem.get_frames())): for framenumber in range(len(self.serviceItem.get_frames())):
self.PreviewListWidget.setRowHeight( self.previewListWidget.setRowHeight(
framenumber, width / self.ratio) framenumber, width / self.ratio)
def onSongBarHandler(self): def onSongBarHandler(self):
request = unicode(self.sender().text()) request = unicode(self.sender().text())
slideno = self.slideList[request] slideno = self.slideList[request]
if slideno > self.PreviewListWidget.rowCount(): if slideno > self.previewListWidget.rowCount():
self.PreviewListWidget.selectRow( self.previewListWidget.selectRow(
self.PreviewListWidget.rowCount() - 1) self.previewListWidget.rowCount() - 1)
else: else:
if slideno + 1 < self.PreviewListWidget.rowCount(): if slideno + 1 < self.previewListWidget.rowCount():
self.PreviewListWidget.scrollToItem( self.previewListWidget.scrollToItem(
self.PreviewListWidget.item(slideno + 1, 0)) self.previewListWidget.item(slideno + 1, 0))
self.PreviewListWidget.selectRow(slideno) self.previewListWidget.selectRow(slideno)
self.onSlideSelected() self.onSlideSelected()
def receiveSpinDelay(self, value): def receiveSpinDelay(self, value):
@ -566,7 +566,7 @@ class SlideController(QtGui.QWidget):
Replacement item following a remote edit Replacement item following a remote edit
""" """
if item.__eq__(self.serviceItem): if item.__eq__(self.serviceItem):
self._processItem(item, self.PreviewListWidget.currentRow()) self._processItem(item, self.previewListWidget.currentRow())
def addServiceManagerItem(self, item, slideno): def addServiceManagerItem(self, item, slideno):
""" """
@ -577,10 +577,10 @@ class SlideController(QtGui.QWidget):
log.debug(u'addServiceManagerItem live = %s' % self.isLive) log.debug(u'addServiceManagerItem live = %s' % self.isLive)
# If service item is the same as the current on only change slide # If service item is the same as the current on only change slide
if item.__eq__(self.serviceItem): if item.__eq__(self.serviceItem):
if slideno + 1 < self.PreviewListWidget.rowCount(): if slideno + 1 < self.previewListWidget.rowCount():
self.PreviewListWidget.scrollToItem( self.previewListWidget.scrollToItem(
self.PreviewListWidget.item(slideno + 1, 0)) self.previewListWidget.item(slideno + 1, 0))
self.PreviewListWidget.selectRow(slideno) self.previewListWidget.selectRow(slideno)
self.onSlideSelected() self.onSlideSelected()
return return
self._processItem(item, slideno) self._processItem(item, slideno)
@ -610,16 +610,16 @@ class SlideController(QtGui.QWidget):
self.slideList = {} self.slideList = {}
width = self.parent.ControlSplitter.sizes()[self.split] width = self.parent.ControlSplitter.sizes()[self.split]
self.serviceItem = serviceItem self.serviceItem = serviceItem
self.PreviewListWidget.clear() self.previewListWidget.clear()
self.PreviewListWidget.setRowCount(0) self.previewListWidget.setRowCount(0)
self.PreviewListWidget.setColumnWidth(0, width) self.previewListWidget.setColumnWidth(0, width)
if self.isLive: if self.isLive:
self.SongMenu.menu().clear() self.SongMenu.menu().clear()
row = 0 row = 0
text = [] text = []
for framenumber, frame in enumerate(self.serviceItem.get_frames()): for framenumber, frame in enumerate(self.serviceItem.get_frames()):
self.PreviewListWidget.setRowCount( self.previewListWidget.setRowCount(
self.PreviewListWidget.rowCount() + 1) self.previewListWidget.rowCount() + 1)
item = QtGui.QTableWidgetItem() item = QtGui.QTableWidgetItem()
slideHeight = 0 slideHeight = 0
if self.serviceItem.is_text(): if self.serviceItem.is_text():
@ -648,33 +648,33 @@ class SlideController(QtGui.QWidget):
image = self.parent.renderManager.image_manager. \ image = self.parent.renderManager.image_manager. \
get_image(frame[u'title']) get_image(frame[u'title'])
label.setPixmap(QtGui.QPixmap.fromImage(image)) label.setPixmap(QtGui.QPixmap.fromImage(image))
self.PreviewListWidget.setCellWidget(framenumber, 0, label) self.previewListWidget.setCellWidget(framenumber, 0, label)
slideHeight = width * self.parent.renderManager.screen_ratio slideHeight = width * self.parent.renderManager.screen_ratio
row += 1 row += 1
text.append(unicode(row)) text.append(unicode(row))
self.PreviewListWidget.setItem(framenumber, 0, item) self.previewListWidget.setItem(framenumber, 0, item)
if slideHeight != 0: if slideHeight != 0:
self.PreviewListWidget.setRowHeight(framenumber, slideHeight) self.previewListWidget.setRowHeight(framenumber, slideHeight)
self.PreviewListWidget.setVerticalHeaderLabels(text) self.previewListWidget.setVerticalHeaderLabels(text)
if self.serviceItem.is_text(): if self.serviceItem.is_text():
self.PreviewListWidget.resizeRowsToContents() self.previewListWidget.resizeRowsToContents()
self.PreviewListWidget.setColumnWidth(0, self.previewListWidget.setColumnWidth(0,
self.PreviewListWidget.viewport().size().width()) self.previewListWidget.viewport().size().width())
if slideno > self.PreviewListWidget.rowCount(): if slideno > self.previewListWidget.rowCount():
self.PreviewListWidget.selectRow( self.previewListWidget.selectRow(
self.PreviewListWidget.rowCount() - 1) self.previewListWidget.rowCount() - 1)
else: else:
if slideno + 1 < self.PreviewListWidget.rowCount(): if slideno + 1 < self.previewListWidget.rowCount():
self.PreviewListWidget.scrollToItem( self.previewListWidget.scrollToItem(
self.PreviewListWidget.item(slideno + 1, 0)) self.previewListWidget.item(slideno + 1, 0))
self.PreviewListWidget.selectRow(slideno) self.previewListWidget.selectRow(slideno)
self.enableToolBar(serviceItem) self.enableToolBar(serviceItem)
# Pass to display for viewing # Pass to display for viewing
self.display.buildHtml(self.serviceItem) self.display.buildHtml(self.serviceItem)
if serviceItem.is_media(): if serviceItem.is_media():
self.onMediaStart(serviceItem) self.onMediaStart(serviceItem)
self.onSlideSelected() self.onSlideSelected()
self.PreviewListWidget.setFocus() self.previewListWidget.setFocus()
Receiver.send_message(u'slidecontroller_%s_started' % self.typePrefix, Receiver.send_message(u'slidecontroller_%s_started' % self.typePrefix,
[serviceItem]) [serviceItem])
@ -693,7 +693,7 @@ class SlideController(QtGui.QWidget):
dataItem[u'tag'] = unicode(framenumber) dataItem[u'tag'] = unicode(framenumber)
dataItem[u'text'] = u'' dataItem[u'text'] = u''
dataItem[u'selected'] = \ dataItem[u'selected'] = \
(self.PreviewListWidget.currentRow() == framenumber) (self.previewListWidget.currentRow() == framenumber)
data.append(dataItem) data.append(dataItem)
Receiver.send_message(u'slidecontroller_%s_text_response' Receiver.send_message(u'slidecontroller_%s_text_response'
% self.typePrefix, data) % self.typePrefix, data)
@ -710,7 +710,7 @@ class SlideController(QtGui.QWidget):
[self.serviceItem, self.isLive]) [self.serviceItem, self.isLive])
self.updatePreview() self.updatePreview()
else: else:
self.PreviewListWidget.selectRow(0) self.previewListWidget.selectRow(0)
self.onSlideSelected() self.onSlideSelected()
def onSlideSelectedIndex(self, message): def onSlideSelectedIndex(self, message):
@ -725,10 +725,10 @@ class SlideController(QtGui.QWidget):
[self.serviceItem, self.isLive, index]) [self.serviceItem, self.isLive, index])
self.updatePreview() self.updatePreview()
else: else:
if index + 1 < self.PreviewListWidget.rowCount(): if index + 1 < self.previewListWidget.rowCount():
self.PreviewListWidget.scrollToItem( self.previewListWidget.scrollToItem(
self.PreviewListWidget.item(index + 1, 0)) self.previewListWidget.item(index + 1, 0))
self.PreviewListWidget.selectRow(index) self.previewListWidget.selectRow(index)
self.onSlideSelected() self.onSlideSelected()
def mainDisplaySetBackground(self): def mainDisplaySetBackground(self):
@ -860,9 +860,9 @@ class SlideController(QtGui.QWidget):
Generate the preview when you click on a slide. Generate the preview when you click on a slide.
if this is the Live Controller also display on the screen if this is the Live Controller also display on the screen
""" """
row = self.PreviewListWidget.currentRow() row = self.previewListWidget.currentRow()
self.selectedRow = 0 self.selectedRow = 0
if row > -1 and row < self.PreviewListWidget.rowCount(): if row > -1 and row < self.previewListWidget.rowCount():
if self.serviceItem.is_command(): if self.serviceItem.is_command():
if self.isLive: if self.isLive:
Receiver.send_message( Receiver.send_message(
@ -884,10 +884,10 @@ class SlideController(QtGui.QWidget):
""" """
The slide has been changed. Update the slidecontroller accordingly The slide has been changed. Update the slidecontroller accordingly
""" """
if row + 1 < self.PreviewListWidget.rowCount(): if row + 1 < self.previewListWidget.rowCount():
self.PreviewListWidget.scrollToItem( self.previewListWidget.scrollToItem(
self.PreviewListWidget.item(row + 1, 0)) self.previewListWidget.item(row + 1, 0))
self.PreviewListWidget.selectRow(row) self.previewListWidget.selectRow(row)
self.updatePreview() self.updatePreview()
Receiver.send_message(u'slidecontroller_%s_changed' % self.typePrefix, Receiver.send_message(u'slidecontroller_%s_changed' % self.typePrefix,
row) row)
@ -924,17 +924,17 @@ class SlideController(QtGui.QWidget):
if self.serviceItem.is_command() and self.isLive: if self.serviceItem.is_command() and self.isLive:
self.updatePreview() self.updatePreview()
else: else:
row = self.PreviewListWidget.currentRow() + 1 row = self.previewListWidget.currentRow() + 1
if row == self.PreviewListWidget.rowCount(): if row == self.previewListWidget.rowCount():
if loop: if loop:
row = 0 row = 0
else: else:
Receiver.send_message('servicemanager_next_item') Receiver.send_message('servicemanager_next_item')
return return
if row + 1 < self.PreviewListWidget.rowCount(): if row + 1 < self.previewListWidget.rowCount():
self.PreviewListWidget.scrollToItem( self.previewListWidget.scrollToItem(
self.PreviewListWidget.item(row + 1, 0)) self.previewListWidget.item(row + 1, 0))
self.PreviewListWidget.selectRow(row) self.previewListWidget.selectRow(row)
self.onSlideSelected() self.onSlideSelected()
def onSlideSelectedPreviousNoloop(self): def onSlideSelectedPreviousNoloop(self):
@ -951,16 +951,16 @@ class SlideController(QtGui.QWidget):
if self.serviceItem.is_command() and self.isLive: if self.serviceItem.is_command() and self.isLive:
self.updatePreview() self.updatePreview()
else: else:
row = self.PreviewListWidget.currentRow() - 1 row = self.previewListWidget.currentRow() - 1
if row == -1: if row == -1:
if loop: if loop:
row = self.PreviewListWidget.rowCount() - 1 row = self.previewListWidget.rowCount() - 1
else: else:
row = 0 row = 0
if row + 1 < self.PreviewListWidget.rowCount(): if row + 1 < self.previewListWidget.rowCount():
self.PreviewListWidget.scrollToItem( self.previewListWidget.scrollToItem(
self.PreviewListWidget.item(row + 1, 0)) self.previewListWidget.item(row + 1, 0))
self.PreviewListWidget.selectRow(row) self.previewListWidget.selectRow(row)
self.onSlideSelected() self.onSlideSelected()
def onSlideSelectedLast(self): def onSlideSelectedLast(self):
@ -974,15 +974,15 @@ class SlideController(QtGui.QWidget):
if self.serviceItem.is_command(): if self.serviceItem.is_command():
self.updatePreview() self.updatePreview()
else: else:
self.PreviewListWidget.selectRow( self.previewListWidget.selectRow(
self.PreviewListWidget.rowCount() - 1) self.previewListWidget.rowCount() - 1)
self.onSlideSelected() self.onSlideSelected()
def onStartLoop(self): def onStartLoop(self):
""" """
Start the timer loop running and store the timer id Start the timer loop running and store the timer id
""" """
if self.PreviewListWidget.rowCount() > 1: if self.previewListWidget.rowCount() > 1:
self.timer_id = self.startTimer( self.timer_id = self.startTimer(
int(self.DelaySpinBox.value()) * 1000) int(self.DelaySpinBox.value()) * 1000)
self.Toolbar.actions[u'Stop Loop'].setVisible(True) self.Toolbar.actions[u'Stop Loop'].setVisible(True)
@ -1025,8 +1025,8 @@ class SlideController(QtGui.QWidget):
""" """
If preview copy slide item to live If preview copy slide item to live
""" """
row = self.PreviewListWidget.currentRow() row = self.previewListWidget.currentRow()
if row > -1 and row < self.PreviewListWidget.rowCount(): if row > -1 and row < self.previewListWidget.rowCount():
self.parent.liveController.addServiceManagerItem( self.parent.liveController.addServiceManagerItem(
self.serviceItem, row) self.serviceItem, row)