def wheelEvent(self, event): " Mouse wheel event " if QApplication.keyboardModifiers() == Qt.ControlModifier: if event.delta() > 0: self.onZoomIn() else: self.onZoomOut() else: HTMLTabWidget.wheelEvent(self, event) return
def __createLayout( self ): " Helper to create the viewer layout " self.viewer = HTMLTabWidget() # Buttons self.__sendUpButton = QAction( PixmapCache().getIcon( 'senddiffup.png' ), 'Send to Main Editing Area', self ) self.__sendUpButton.triggered.connect( self.__sendUp ) spacer = QWidget() spacer.setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Expanding ) self.__clearButton = QAction( PixmapCache().getIcon( 'trash.png' ), 'Clear Generated Diff', self ) self.__clearButton.triggered.connect( self.__clear ) # Toolbar self.toolbar = QToolBar() self.toolbar.setOrientation( Qt.Vertical ) self.toolbar.setMovable( False ) self.toolbar.setAllowedAreas( Qt.LeftToolBarArea ) self.toolbar.setIconSize( QSize( 16, 16 ) ) self.toolbar.setFixedWidth( 28 ) self.toolbar.setContentsMargins( 0, 0, 0, 0 ) self.toolbar.addAction( self.__sendUpButton ) self.toolbar.addWidget( spacer ) self.toolbar.addAction( self.__clearButton ) verticalLayout = QVBoxLayout() verticalLayout.setContentsMargins( 2, 2, 2, 2 ) verticalLayout.setSpacing( 2 ) verticalLayout.addWidget( self.viewer ) # layout layout = QHBoxLayout() layout.setContentsMargins( 0, 0, 0, 0 ) layout.setSpacing( 0 ) layout.addWidget( self.toolbar ) layout.addLayout( verticalLayout ) self.setLayout( layout ) return
def eventFilter(self, obj, event): " Event filter to catch shortcuts on UBUNTU " if event.type() == QEvent.KeyPress: key = event.key() modifiers = event.modifiers() if modifiers == Qt.ControlModifier: if key == Qt.Key_Minus: return self.onZoomOut() if key == Qt.Key_Equal: return self.onZoomIn() if key == Qt.Key_0: return self.onZoomReset() if modifiers == Qt.KeypadModifier | Qt.ControlModifier: if key == Qt.Key_Minus: return self.onZoomOut() if key == Qt.Key_Plus: return self.onZoomIn() if key == Qt.Key_0: return self.onZoomReset() return HTMLTabWidget.eventFilter(self, obj, event)
def loadFormFile(self, path): " Loads the content from the given file " HTMLTabWidget.loadFormFile(self, path) self.zoomTo(Settings().zoom) return
def setHTML(self, content): " Sets the content from the given string " HTMLTabWidget.setHTML(self, content) self.zoomTo(Settings().zoom) return
def __init__(self, parent=None): HTMLTabWidget.__init__(self, parent) self.installEventFilter(self) return
class DiffViewer( QWidget ): """ The diff viewer widget at the bottom """ NODIFF = '<html><body bgcolor="#ffffe6"></body></html>' def __init__( self, parent = None ): QWidget.__init__( self, parent ) self.viewer = None self.__clearButton = None self.__sendUpButton = None self.__createLayout() self.__isEmpty = True self.__tooltip = "" self.__inClear = False self.viewer.setHTML( self.NODIFF ) self.__updateToolbarButtons() return def __createLayout( self ): " Helper to create the viewer layout " self.viewer = HTMLTabWidget() # Buttons self.__sendUpButton = QAction( PixmapCache().getIcon( 'senddiffup.png' ), 'Send to Main Editing Area', self ) self.__sendUpButton.triggered.connect( self.__sendUp ) spacer = QWidget() spacer.setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Expanding ) self.__clearButton = QAction( PixmapCache().getIcon( 'trash.png' ), 'Clear Generated Diff', self ) self.__clearButton.triggered.connect( self.__clear ) # Toolbar self.toolbar = QToolBar() self.toolbar.setOrientation( Qt.Vertical ) self.toolbar.setMovable( False ) self.toolbar.setAllowedAreas( Qt.LeftToolBarArea ) self.toolbar.setIconSize( QSize( 16, 16 ) ) self.toolbar.setFixedWidth( 28 ) self.toolbar.setContentsMargins( 0, 0, 0, 0 ) self.toolbar.addAction( self.__sendUpButton ) self.toolbar.addWidget( spacer ) self.toolbar.addAction( self.__clearButton ) verticalLayout = QVBoxLayout() verticalLayout.setContentsMargins( 2, 2, 2, 2 ) verticalLayout.setSpacing( 2 ) verticalLayout.addWidget( self.viewer ) # layout layout = QHBoxLayout() layout.setContentsMargins( 0, 0, 0, 0 ) layout.setSpacing( 0 ) layout.addWidget( self.toolbar ) layout.addLayout( verticalLayout ) self.setLayout( layout ) return def setHTML( self, content, tooltip ): """ Shows the given content """ if self.__inClear: self.viewer.setHTML( content ) self.viewer.zoomTo( Settings().zoom ) return if content == '' or content is None: self.__clear() else: self.viewer.setHTML( content ) self.viewer.zoomTo( Settings().zoom ) self.__isEmpty = False self.__updateToolbarButtons() self.__tooltip = tooltip return def zoomTo( self, zoomValue ): " Sets the required zoom " self.viewer.zoomTo( zoomValue ) return def __sendUp( self ): """ Triggered when the content should be sent to the main editor area """ if not self.__isEmpty: GlobalData().mainWindow.showDiffInMainArea( self.viewer.getHTML(), self.__tooltip ) return def __clear( self ): """ Triggered when the content should be cleared """ self.__inClear = True # Dirty hack - reset the tooltip GlobalData().mainWindow.showDiff( "", "No diff shown" ) self.viewer.setHTML( DiffViewer.NODIFF ) self.__inClear = False self.__isEmpty = True self.__tooltip = "" self.__updateToolbarButtons() return def __updateToolbarButtons( self ): " Contextually updates toolbar buttons " self.__sendUpButton.setEnabled( not self.__isEmpty ) self.__clearButton.setEnabled( not self.__isEmpty ) return