mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add printing support to the ebook viewer
This commit is contained in:
parent
03236fb0b2
commit
3a3a05be79
14298
src/calibre/gui2/images/document-print-preview.svg
Normal file
14298
src/calibre/gui2/images/document-print-preview.svg
Normal file
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 354 KiB |
14229
src/calibre/gui2/images/document-print.svg
Normal file
14229
src/calibre/gui2/images/document-print.svg
Normal file
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 350 KiB |
@ -8,7 +8,8 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os, math, re
|
import os, math, re
|
||||||
from PyQt4.Qt import QWidget, QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer, \
|
from PyQt4.Qt import QWidget, QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer, \
|
||||||
QPainter, QPalette, QBrush, QFontDatabase, QDialog, \
|
QPainter, QPalette, QBrush, QFontDatabase, QDialog, \
|
||||||
QByteArray, QColor, QWheelEvent, QPoint, QImage, QRegion, QFont
|
QByteArray, QColor, QWheelEvent, QPoint, QImage, QRegion, \
|
||||||
|
QFont, QPrinter, QPrintPreviewDialog, QPrintDialog
|
||||||
from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings
|
from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings
|
||||||
|
|
||||||
from calibre.utils.config import Config, StringConfig
|
from calibre.utils.config import Config, StringConfig
|
||||||
@ -305,6 +306,27 @@ class DocumentView(QWebView):
|
|||||||
|
|
||||||
def goto_bookmark(self, bm):
|
def goto_bookmark(self, bm):
|
||||||
self.document.goto_bookmark(bm)
|
self.document.goto_bookmark(bm)
|
||||||
|
|
||||||
|
def print_preview(self):
|
||||||
|
printer = QPrinter(QPrinter.HighResolution)
|
||||||
|
printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch)
|
||||||
|
|
||||||
|
previewDialog = QPrintPreviewDialog(printer, self)
|
||||||
|
|
||||||
|
self.connect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), self.print_)
|
||||||
|
previewDialog.exec_()
|
||||||
|
self.disconnect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), self.print_)
|
||||||
|
|
||||||
|
def print_book(self):
|
||||||
|
printer = QPrinter(QPrinter.HighResolution)
|
||||||
|
printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch)
|
||||||
|
|
||||||
|
printDialog = QPrintDialog(printer, self)
|
||||||
|
printDialog.setWindowTitle(_("Print eBook"))
|
||||||
|
|
||||||
|
printDialog.exec_()
|
||||||
|
if printDialog.result() == QDialog.Accepted:
|
||||||
|
self.print_(printer)
|
||||||
|
|
||||||
def config(self, parent=None):
|
def config(self, parent=None):
|
||||||
self.document.do_config(parent)
|
self.document.do_config(parent)
|
||||||
@ -552,4 +574,4 @@ class DocumentView(QWebView):
|
|||||||
self.manager.scrolled(self.scroll_fraction)
|
self.manager.scrolled(self.scroll_fraction)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -248,6 +248,8 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
self.connect(self.action_back, SIGNAL('triggered(bool)'), self.back)
|
self.connect(self.action_back, SIGNAL('triggered(bool)'), self.back)
|
||||||
self.connect(self.action_bookmark, SIGNAL('triggered(bool)'), self.bookmark)
|
self.connect(self.action_bookmark, SIGNAL('triggered(bool)'), self.bookmark)
|
||||||
self.connect(self.action_forward, SIGNAL('triggered(bool)'), self.forward)
|
self.connect(self.action_forward, SIGNAL('triggered(bool)'), self.forward)
|
||||||
|
self.connect(self.action_print_preview, SIGNAL('triggered()'), self.view.print_preview)
|
||||||
|
self.connect(self.action_print, SIGNAL('triggered()'), self.view.print_book)
|
||||||
self.connect(self.action_preferences, SIGNAL('triggered(bool)'), lambda x: self.view.config(self))
|
self.connect(self.action_preferences, SIGNAL('triggered(bool)'), lambda x: self.view.config(self))
|
||||||
self.connect(self.pos, SIGNAL('valueChanged(double)'), self.goto_page)
|
self.connect(self.pos, SIGNAL('valueChanged(double)'), self.goto_page)
|
||||||
self.connect(self.vertical_scrollbar, SIGNAL('valueChanged(int)'),
|
self.connect(self.vertical_scrollbar, SIGNAL('valueChanged(int)'),
|
||||||
|
@ -27,8 +27,8 @@
|
|||||||
<widget class="QWidget" name="layoutWidget" >
|
<widget class="QWidget" name="layoutWidget" >
|
||||||
<layout class="QGridLayout" name="gridLayout" >
|
<layout class="QGridLayout" name="gridLayout" >
|
||||||
<item row="0" column="0" >
|
<item row="0" column="0" >
|
||||||
<widget class="QWebView" native="1" name="view" >
|
<widget class="QWebView" name="view" >
|
||||||
<property name="url" stdset="0" >
|
<property name="url" >
|
||||||
<url>
|
<url>
|
||||||
<string>about:blank</string>
|
<string>about:blank</string>
|
||||||
</url>
|
</url>
|
||||||
@ -87,6 +87,9 @@
|
|||||||
<addaction name="action_bookmark" />
|
<addaction name="action_bookmark" />
|
||||||
<addaction name="action_reference_mode" />
|
<addaction name="action_reference_mode" />
|
||||||
<addaction name="separator" />
|
<addaction name="separator" />
|
||||||
|
<addaction name="action_print_preview" />
|
||||||
|
<addaction name="action_print" />
|
||||||
|
<addaction name="separator" />
|
||||||
<addaction name="action_preferences" />
|
<addaction name="action_preferences" />
|
||||||
<addaction name="action_full_screen" />
|
<addaction name="action_full_screen" />
|
||||||
</widget>
|
</widget>
|
||||||
@ -234,6 +237,24 @@
|
|||||||
<string>Toggle full screen</string>
|
<string>Toggle full screen</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="action_print" >
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset resource="../images.qrc" >
|
||||||
|
<normaloff>:/images/document-print.svg</normaloff>:/images/document-print.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Print</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="action_print_preview" >
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset resource="../images.qrc" >
|
||||||
|
<normaloff>:/images/document-print-preview.svg</normaloff>:/images/document-print-preview.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Print Preview</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user