Exemplo n.º 1
0
    def __init__(self, source_file=None, parent=None):
        """
        Create a new PynalDocument for the given file.

        Parameters:
        source_file -- String path to the pdf that is to be displayed.
        parent      -- the parent widget of this widget.
        """
        QtGui.QGraphicsView.__init__(self, parent)
        self.max_width = -1
        self.setCursor(tools.current_tool.cursor)

        # Needed for proper rendering of selection box
        self.setViewportUpdateMode(self.FullViewportUpdate)

        self.configure_scene()

        # Set the default zoom level to 1.0
        self.scale_level = 1

        self.pages = []

#        if Config.get_group("rendering").readEntry("use_opengl", False).toBool():
#            self.setViewport(QtOpenGL.QGLWidget())

        if source_file is not None:
            self.document = QtPoppler.Poppler.Document.load(source_file)
            self.document.setRenderHint(QtPoppler.Poppler.Document.Antialiasing and
                                        QtPoppler.Poppler.Document.TextAntialiasing)

            # This might want to be moved into an own thread
            # (when numPages is over a certain threshold?)
            for page_number in range(0, self.document.numPages()):
                self.insert_new_page_at(page_number,
                    Backgrounds.pdf_page(self.document.page(page_number)))

                # Note that the pdf pages are not rendered
                # now. That happens when the page is to be
                # displayed / cached for displaying.

        else:
            self.insert_new_page_at(0) # Add an empty page.

        self.undo_stack = kdeui.KUndoStack(self)

        self.removed_pages = []

        self.cache = PynalCache()
Exemplo n.º 2
0
    def insert_new_page_at(self, index, bg_source=None):
        """
        Insert a new page at the given index.

        Parameters:
          index     -- Index/site number that this page will have.

          bg_source -- The bg_source for this page. None results in a blank page.
        """
        if bg_source is None:
            bg_source = Backgrounds.empty_background()

        new_page = DocumentPage(self, index, bg_source)
        if new_page.boundingRect().width() > self.max_width:
           self.max_width = new_page.boundingRect().width()

        self.pages.insert(index, new_page)

        # Move all pages after this down to accommodate it.
        for i in range(index + 1, len(self.pages)):
            self.pages[i].page_number = i
            self.pages[i].update_bounding_rect()

        self.refresh_viewport_size()
Exemplo n.º 3
0
    def __init__(self, source_file=None, parent=None):
        """
        Create a new PynalDocument for the given file.

        Parameters:
        source_file -- String path to the pdf that is to be displayed.
        parent      -- the parent widget of this widget.
        """
        QtGui.QGraphicsView.__init__(self, parent)
        self.max_width = -1
        self.setCursor(tools.current_tool.cursor)

        self.configure_scene()

        # Set the default zoom level to 1.0
        self.scale_level = 1

        self.pages = []
        
        self.undoStack = QtGui.QUndoStack(self)


        if Config.get_group("rendering").readEntry("use_opengl", False).toBool():
            self.setViewport(QtOpenGL.QGLWidget())


        if source_file is not None:
            self.document = QtPoppler.Poppler.Document.load(source_file)
            self.document.setRenderHint(QtPoppler.Poppler.Document.Antialiasing and
                                        QtPoppler.Poppler.Document.TextAntialiasing)

            # This might want to be moved into an own thread
            # (when numPages is over a certain threshold?)
            for page_number in range(0, self.document.numPages()):
                self.insert_new_page_at(page_number,
                    Backgrounds.pdf_page(self.document.page(page_number)))

                # Note that the pdf pages are not rendered
                # now. That happens when the page is to be
                # displayed / cached for displaying.

        else:
            self.insert_new_page_at(0) # Add an empty page.

        self.undo_stack = kdeui.KUndoStack(self)

        self.removed_pages = []

        # Toolbar
        toolbar = QtGui.QToolBar()

        # Actions
        self.actionAdd = toolbar.addAction("New", self.refresh_viewport_size)
        self.actionEdit = toolbar.addAction("Edit", self.refresh_viewport_size)
        self.actionDelete = toolbar.addAction("Delete", self.refresh_viewport_size)
        
        self.setContextMenuPolicy( QtCore.Qt.CustomContextMenu )
        self.connect(self, QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'), self.on_context_menu)

        # Popup Menu
        self.popMenu = QtGui.QMenu(self)
        self.popMenu.addAction( self.actionEdit )
        self.popMenu.addAction( self.actionDelete )
        self.popMenu.addSeparator()
        self.popMenu.addAction( self.actionAdd )
        
        self.cache = PynalCache()
Exemplo n.º 4
0
 def checked_bg(self):
     """ Set the background to checked. """
     parent = self.parentItem()
     parent.bg_source = Backgrounds.checked_background(size=parent.bg_source.sizeF())
     parent.background_is_dirty = True
Exemplo n.º 5
0
 def plain_bg(self):
     """ Set the background to plain. """
     parent = self.parentItem()
     parent.bg_source = Backgrounds.empty_background(size=parent.bg_source.sizeF())
     parent.background_is_dirty = True