Add a toolbar with buttons to control the preview panel

This commit is contained in:
Kovid Goyal 2013-11-09 09:20:34 +05:30
parent f77fc9493e
commit 6df507a962
6 changed files with 1595 additions and 4 deletions

1566
imgsrc/view-refresh.svg Normal file

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -876,6 +876,7 @@ class Application(QApplication):
'MessageBoxWarning': u'dialog_warning.png', 'MessageBoxWarning': u'dialog_warning.png',
'MessageBoxCritical': u'dialog_error.png', 'MessageBoxCritical': u'dialog_error.png',
'MessageBoxQuestion': u'dialog_question.png', 'MessageBoxQuestion': u'dialog_question.png',
'BrowserReload': u'view-refresh.png',
# These two are used to calculate the sizes for the doc widget # These two are used to calculate the sizes for the doc widget
# title bar buttons, therefore, they have to exist. The actual # title bar buttons, therefore, they have to exist. The actual
# icon is not used. # icon is not used.

View File

@ -12,7 +12,7 @@ from Queue import Queue, Empty
from PyQt4.Qt import ( from PyQt4.Qt import (
QWidget, QVBoxLayout, QApplication, QSize, QNetworkAccessManager, QWidget, QVBoxLayout, QApplication, QSize, QNetworkAccessManager,
QNetworkReply, QTimer, QNetworkRequest, QUrl, Qt, QNetworkDiskCache) QNetworkReply, QTimer, QNetworkRequest, QUrl, Qt, QNetworkDiskCache, QToolBar)
from PyQt4.QtWebKit import QWebView from PyQt4.QtWebKit import QWebView
from calibre import prints from calibre import prints
@ -20,7 +20,7 @@ from calibre.constants import iswindows
from calibre.ebooks.oeb.polish.parsing import parse from calibre.ebooks.oeb.polish.parsing import parse
from calibre.ebooks.oeb.base import serialize, OEB_DOCS from calibre.ebooks.oeb.base import serialize, OEB_DOCS
from calibre.ptempfile import PersistentTemporaryDirectory from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.gui2.tweak_book import current_container, editors, tprefs from calibre.gui2.tweak_book import current_container, editors, tprefs, actions
from calibre.gui2.viewer.documentview import apply_settings from calibre.gui2.viewer.documentview import apply_settings
from calibre.gui2.viewer.config import config from calibre.gui2.viewer.config import config
from calibre.utils.ipc.simple_worker import offload_worker from calibre.utils.ipc.simple_worker import offload_worker
@ -269,6 +269,19 @@ class Preview(QWidget):
l.setContentsMargins(0, 0, 0, 0) l.setContentsMargins(0, 0, 0, 0)
self.view = WebView(self) self.view = WebView(self)
l.addWidget(self.view) l.addWidget(self.view)
self.bar = QToolBar(self)
l.addWidget(self.bar)
ac = actions['auto-reload-preview']
ac.setCheckable(True)
ac.setChecked(True)
ac.toggled.connect(self.auto_reload_toggled)
self.auto_reload_toggled(ac.isChecked())
self.bar.addAction(ac)
ac = actions['reload-preview']
ac.triggered.connect(self.refresh)
self.bar.addAction(ac)
self.current_name = None self.current_name = None
self.last_sync_request = None self.last_sync_request = None
@ -301,7 +314,13 @@ class Preview(QWidget):
self.view.clear() self.view.clear()
def start_refresh_timer(self): def start_refresh_timer(self):
self.refresh_timer.start(tprefs['preview_refresh_time'] * 1000) if actions['auto-reload-preview'].isChecked():
self.refresh_timer.start(tprefs['preview_refresh_time'] * 1000)
def stop_refresh_timer(self): def stop_refresh_timer(self):
self.refresh_timer.stop() self.refresh_timer.stop()
def auto_reload_toggled(self, checked):
actions['auto-reload-preview'].setToolTip(_(
'Auto reload preview when text changes in editor') if not checked else _(
'Disable auto reload of preview'))

View File

@ -141,7 +141,8 @@ class Main(MainWindow):
def reg(icon, text, target, sid, keys, description): def reg(icon, text, target, sid, keys, description):
ac = actions[sid] = QAction(QIcon(I(icon)), text, self) ac = actions[sid] = QAction(QIcon(I(icon)), text, self)
ac.setObjectName('action-' + sid) ac.setObjectName('action-' + sid)
ac.triggered.connect(target) if target is not None:
ac.triggered.connect(target)
if isinstance(keys, type('')): if isinstance(keys, type('')):
keys = (keys,) keys = (keys,)
self.keyboard.register_shortcut( self.keyboard.register_shortcut(
@ -193,6 +194,10 @@ class Main(MainWindow):
'smarten-punctuation.png', _('&Smarten punctuation'), partial( 'smarten-punctuation.png', _('&Smarten punctuation'), partial(
self.boss.polish, 'smarten_punctuation', _('Smarten punctuation')), 'smarten-punctuation', (), _('Smarten punctuation')) self.boss.polish, 'smarten_punctuation', _('Smarten punctuation')), 'smarten-punctuation', (), _('Smarten punctuation'))
# Preview actions
self.action_auto_reload_preview = reg('auto-reload.png', _('Auto reload preview'), None, 'auto-reload-preview', (), _('Auto reload preview'))
self.action_reload_preview = reg('view-refresh.png', _('Refresh preview'), None, 'reload-preview', (), _('Refresh preview'))
def create_menubar(self): def create_menubar(self):
b = self.menuBar() b = self.menuBar()