Only activate a subset of the available features when the part is launched in viewer mode.

In viewer mode the part will now use a different XML GUI file (part-viewermode.rc).
Also, some actions won't be created, e.g. those used for exporting stuff, for
launching presentation mode, or for selecting parts of the document. The captions
of the configuration dialogs also contain the word 'viewer' then.
This commit is contained in:
Michel Ludwig 2011-10-12 20:36:01 +01:00
parent 1a5f2be05c
commit d29099b39c
11 changed files with 378 additions and 177 deletions

View file

@ -197,7 +197,7 @@ install(TARGETS okularpart DESTINATION ${PLUGIN_INSTALL_DIR})
########### install files ###############
install( FILES okular_part.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
install( FILES part.rc DESTINATION ${DATA_INSTALL_DIR}/okular )
install( FILES part.rc part-viewermode.rc DESTINATION ${DATA_INSTALL_DIR}/okular )
########### cmake files #################

View file

@ -15,11 +15,18 @@
#include "ui_dlggeneralbase.h"
DlgGeneral::DlgGeneral( QWidget * parent )
DlgGeneral::DlgGeneral( QWidget * parent, Okular::EmbedMode embedMode )
: QWidget( parent )
{
m_dlg = new Ui_DlgGeneralBase();
m_dlg->setupUi( this );
if( embedMode == Okular::ViewerWidgetMode )
{
m_dlg->kcfg_SyncThumbnailsViewport->setVisible( false );
m_dlg->kcfg_DisplayDocumentTitle->setVisible( false );
m_dlg->kcfg_WatchFile->setVisible( false );
}
}
DlgGeneral::~DlgGeneral()

View file

@ -12,12 +12,14 @@
#include <qwidget.h>
#include "core/global.h"
class Ui_DlgGeneralBase;
class DlgGeneral : public QWidget
{
public:
DlgGeneral( QWidget * parent = 0 );
DlgGeneral( QWidget * parent, Okular::EmbedMode embedMode );
virtual ~DlgGeneral();
protected:

View file

@ -21,15 +21,15 @@
#include "dlgeditor.h"
#include "dlgdebug.h"
PreferencesDialog::PreferencesDialog( QWidget * parent, KConfigSkeleton * skeleton )
PreferencesDialog::PreferencesDialog( QWidget * parent, KConfigSkeleton * skeleton, Okular::EmbedMode embedMode )
: KConfigDialog( parent, "preferences", skeleton )
{
m_general = new DlgGeneral( this );
m_general = new DlgGeneral( this, embedMode );
m_performance = new DlgPerformance( this );
m_accessibility = new DlgAccessibility( this );
m_presentation = new DlgPresentation( this );
m_identity = new DlgIdentity( this );
m_editor = new DlgEditor( this );
m_presentation = NULL;
m_identity = NULL;
m_editor = NULL;
#ifdef OKULAR_DEBUG_CONFIGPAGE
m_debug = new DlgDebug( this );
#endif
@ -37,11 +37,21 @@ PreferencesDialog::PreferencesDialog( QWidget * parent, KConfigSkeleton * skelet
addPage( m_general, i18n("General"), "okular", i18n("General Options") );
addPage( m_accessibility, i18n("Accessibility"), "preferences-desktop-accessibility", i18n("Accessibility Reading Aids") );
addPage( m_performance, i18n("Performance"), "preferences-system-performance", i18n("Performance Tuning") );
addPage( m_presentation, i18n("Presentation"), "view-presentation",
i18n("Options for Presentation Mode") );
addPage( m_identity, i18n("Identity"), "preferences-desktop-personal",
i18n("Identity Settings") );
addPage( m_editor, i18n("Editor"), "accessories-text-editor", i18n("Editor Options") );
if( embedMode == Okular::ViewerWidgetMode )
{
setCaption( i18n("Configure Viewer") );
}
else
{
m_presentation = new DlgPresentation( this );
m_identity = new DlgIdentity( this );
m_editor = new DlgEditor( this );
addPage( m_presentation, i18n("Presentation"), "view-presentation",
i18n("Options for Presentation Mode") );
addPage( m_identity, i18n("Identity"), "preferences-desktop-personal",
i18n("Identity Settings") );
addPage( m_editor, i18n("Editor"), "accessories-text-editor", i18n("Editor Options") );
}
#ifdef OKULAR_DEBUG_CONFIGPAGE
addPage( m_debug, "Debug", "system-run", "Debug options" );
#endif

View file

@ -12,6 +12,7 @@
#include <kconfigdialog.h>
#include "settings.h"
#include "core/global.h"
class QWidget;
class KConfigSkeleton;
@ -28,7 +29,7 @@ class PreferencesDialog : public KConfigDialog
{
public:
PreferencesDialog( QWidget * parent, KConfigSkeleton * config );
PreferencesDialog( QWidget * parent, KConfigSkeleton * config, Okular::EmbedMode embedMode );
protected:
// void updateSettings(); // Called when OK/Apply is pressed.

View file

@ -78,6 +78,15 @@ enum ScriptType
JavaScript = 0 ///< JavaScript code
};
enum EmbedMode
{
UnknownEmbedMode,
NativeShellMode, // embedded in the native Okular' shell
PrintPreviewMode, // embedded to show the print preview of a document
KHTMLPartMode, // embedded in KHTML
ViewerWidgetMode, // the part acts as a widget that can display all kinds of documents
};
}
#endif

74
part-viewermode.rc Normal file
View file

@ -0,0 +1,74 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="okular_part_viewermode" version="1">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
<Action name="file_print_preview" group="okular_print_merge"/>
</Menu>
<Menu name="settings"><text>&amp;Settings</text>
<Action name="options_configure_generators" group="configure_merge"/>
<Action name="options_configure" group="configure_merge"/>
</Menu>
<Menu name="help"><text>&amp;Help</text>
<Action name="help_about_backend" group="about_merge"/>
</Menu>
</MenuBar>
<Menu name="menu_okular_part_viewer">
<Action name="mouse_drag" group="viewer_menu_merge"/>
<Action name="mouse_zoom" group="viewer_menu_merge"/>
<Separator group="viewer_menu_merge"/>
<Action name="view_zoom_in" group="viewer_menu_merge"/>
<Action name="view_zoom_out" group="viewer_menu_merge"/>
<Action name="view_fit_to_width" group="viewer_menu_merge"/>
<Action name="view_fit_to_page" group="viewer_menu_merge"/>
<Action name="zoom_fit_rect" group="viewer_menu_merge"/>
<Separator group="viewer_menu_merge"/>
<Action name="view_continuous" group="viewer_menu_merge"/>
<Action name="view_render_mode" group="viewer_menu_merge"/>
<Separator group="viewer_menu_merge"/>
<Menu name="view_orientation" group="viewer_menu_merge"><text>&amp;Orientation</text>
<Action name="view_orientation_rotate_ccw" group="viewer_menu_merge"/>
<Action name="view_orientation_rotate_cw" group="viewer_menu_merge"/>
<Action name="view_orientation_original" group="viewer_menu_merge"/>
</Menu>
<Action name="view_pagesizes" group="viewer_menu_merge"/>
<Action name="view_trim_margins" group="viewer_menu_merge"/>
<Separator group="viewer_menu_merge"/>
<Action name="go_previous" group="viewer_menu_merge"/>
<Action name="go_next" group="viewer_menu_merge"/>
<Separator group="viewer_menu_merge"/>
<Action name="first_page" group="viewer_menu_merge"/>
<Action name="last_page" group="viewer_menu_merge"/>
<Separator group="viewer_menu_merge"/>
<Action name="go_document_back" group="viewer_menu_merge"/>
<Action name="go_document_forward" group="viewer_menu_merge"/>
<Separator group="viewer_menu_merge"/>
<Action name="go_goto_page" group="viewer_menu_merge"/>
<Separator group="viewer_menu_merge"/>
<Menu name="okular_bookmarks" group="viewer_menu_merge"><text>&amp;Bookmarks</text>
<Action name="bookmark_add" group="viewer_menu_merge"/>
<Action name="previous_bookmark" group="viewer_menu_merge"/>
<Action name="next_bookmark" group="viewer_menu_merge"/>
<Separator group="viewer_menu_merge"/>
<ActionList name="bookmarks_currentdocument" group="viewer_menu_merge"/>
</Menu>
<Separator group="viewer_menu_merge"/>
<Action name="edit_find" group="viewer_menu_merge"/>
<Action name="edit_find_next" group="viewer_menu_merge"/>
<Action name="edit_find_prev" group="viewer_menu_merge"/>
</Menu>
<ToolBar name="OkularViewerToolBar"><text>Viewer Toolbar</text>
<Action name="zoom_to" />
<Action name="view_zoom_out"/>
<Action name="view_zoom_in"/>
<Separator/>
<Action name="mouse_drag"/>
<Action name="mouse_zoom"/>
<Action name="mouse_selecttools"/>
</ToolBar>
</kpartgui>

374
part.cpp
View file

@ -198,33 +198,33 @@ static QString compressedMimeFor( const QString& mime_to_check )
return QString();
}
static Okular::Part::EmbedMode detectEmbedMode( QWidget *parentWidget, QObject *parent, const QVariantList &args )
static Okular::EmbedMode detectEmbedMode( QWidget *parentWidget, QObject *parent, const QVariantList &args )
{
Q_UNUSED( parentWidget );
if ( parent
&& ( parent->objectName() == QLatin1String( "okular::Shell" )
|| parent->objectName() == QLatin1String( "okular/okular__Shell" ) ) )
return Okular::Part::NativeShellMode;
return Okular::NativeShellMode;
if ( parent
&& ( QByteArray( "KHTMLPart" ) == parent->metaObject()->className() ) )
return Okular::Part::KHTMLPartMode;
return Okular::KHTMLPartMode;
Q_FOREACH ( const QVariant &arg, args )
{
if ( arg.type() == QVariant::String )
{
if ( arg.toString() == QLatin1String( "Print/Preview" ) ) {
return Okular::Part::PrintPreviewMode;
return Okular::PrintPreviewMode;
}
else if ( arg.toString() == QLatin1String( "ViewerWidget" ) ) {
return Okular::Part::ViewerWidgetMode;
return Okular::ViewerWidgetMode;
}
}
}
return Okular::Part::UnknownEmbedMode;
return Okular::UnknownEmbedMode;
}
static QString detectConfigFileName( const QVariantList &args )
@ -438,12 +438,81 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
connect( m_document->bookmarkManager(), SIGNAL(saved()),
this, SLOT(slotRebuildBookmarkMenu()) );
setupViewerActions();
if ( m_embedMode != ViewerWidgetMode )
{
setupActions();
}
// document watcher and reloader
m_watcher = new KDirWatch( this );
connect( m_watcher, SIGNAL(dirty(QString)), this, SLOT(slotFileDirty(QString)) );
m_dirtyHandler = new QTimer( this );
m_dirtyHandler->setSingleShot( true );
connect( m_dirtyHandler, SIGNAL(timeout()),this, SLOT(slotDoFileDirty()) );
slotNewConfig();
// [SPEECH] check for KTTSD presence and usability
const KService::Ptr kttsd = KService::serviceByDesktopName("kttsd");
Okular::Settings::setUseKTTSD( kttsd );
Okular::Settings::self()->writeConfig();
rebuildBookmarkMenu( false );
if ( m_embedMode == ViewerWidgetMode ) {
// set the XML-UI resource file for the viewer mode
setXMLFile("part-viewermode.rc");
}
else
{
// set our main XML-UI resource file
setXMLFile("part.rc");
}
m_pageView->setupBaseActions( actionCollection() );
m_sidebar->setSidebarVisibility( false );
if ( m_embedMode != PrintPreviewMode )
{
// now set up actions that are required for all remaining modes
m_pageView->setupViewerActions( actionCollection() );
// and if we are not in viewer mode, we want the full GUI
if ( m_embedMode != ViewerWidgetMode )
{
unsetDummyMode();
}
}
// ensure history actions are in the correct state
updateViewActions();
if( m_embedMode == ViewerWidgetMode ) {
m_bottomBar->setVisible(false);
m_pageView->setShowMoveDestinationGraphically(true);
// FIXME: this should probably be implemented in such a way that there is no
// need to change the configuration settings
Okular::Settings::setViewMode(Okular::Settings::EnumViewMode::Single);
Okular::Settings::setViewContinuous(true);
}
if ( m_embedMode == NativeShellMode )
m_sidebar->setAutoFillBackground( false );
#ifdef OKULAR_KEEP_FILE_OPEN
m_keeper = new FileKeeper();
#endif
}
void Part::setupViewerActions()
{
// ACTIONS
KActionCollection * ac = actionCollection();
// Page Traversal actions
m_gotoPage = KStandardAction::gotoPage( this, SLOT(slotGoToPage()), ac );
m_gotoPage->setShortcut( QKeySequence(Qt::CTRL + Qt::Key_G) );
m_gotoPage->setShortcut( QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_G) );
// dirty way to activate gotopage when pressing miniBar's button
connect( m_miniBar, SIGNAL(gotoPage()), m_gotoPage, SLOT(trigger()) );
@ -473,17 +542,20 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
ac->addAction("first_page", m_beginningOfDocument);
m_beginningOfDocument->setText(i18n( "Beginning of the document"));
m_beginningOfDocument->setWhatsThis( i18n( "Moves to the beginning of the document" ) );
m_beginningOfDocument->setShortcut( QKeySequence( Qt::CTRL + Qt::ALT + Qt::Key_Home ) );
m_endOfDocument = KStandardAction::lastPage( this, SLOT(slotGotoLast()), ac );
ac->addAction("last_page",m_endOfDocument);
m_endOfDocument->setText(i18n( "End of the document"));
m_endOfDocument->setWhatsThis( i18n( "Moves to the end of the document" ) );
m_endOfDocument->setShortcut( QKeySequence( Qt::CTRL + Qt::ALT + Qt::Key_End ) );
// we do not want back and next in history in the dummy mode
m_historyBack = 0;
m_historyNext = 0;
m_addBookmark = KStandardAction::addBookmark( this, SLOT(slotAddBookmark()), ac );
m_addBookmark->setShortcut( QKeySequence( Qt::CTRL + Qt::ALT + Qt::Key_B ) );
m_addBookmarkText = m_addBookmark->text();
m_addBookmarkIcon = m_addBookmark->icon();
@ -499,30 +571,25 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
m_nextBookmark->setWhatsThis( i18n( "Go to the next bookmarked page" ) );
connect( m_nextBookmark, SIGNAL(triggered()), this, SLOT(slotNextBookmark()) );
m_copy = KStandardAction::create( KStandardAction::Copy, m_pageView, SLOT(copyTextSelection()), ac );
m_copy = NULL;
m_selectAll = KStandardAction::selectAll( m_pageView, SLOT(selectAll()), ac );
m_selectAll = NULL;
// Find and other actions
m_find = KStandardAction::find( this, SLOT(slotShowFindBar()), ac );
QList<QKeySequence> s = m_find->shortcuts();
s.append( QKeySequence( Qt::Key_Slash ) );
m_find->setShortcuts( s );
m_find->setShortcut( QKeySequence() );
m_find->setEnabled( false );
m_findNext = KStandardAction::findNext( this, SLOT(slotFindNext()), ac);
m_findNext->setShortcut( QKeySequence() );
m_findNext->setEnabled( false );
m_findPrev = KStandardAction::findPrev( this, SLOT(slotFindPrev()), ac );
m_findPrev->setShortcut( QKeySequence() );
m_findPrev->setEnabled( false );
m_saveCopyAs = KStandardAction::saveAs( this, SLOT(slotSaveCopyAs()), ac );
m_saveCopyAs->setText( i18n( "Save &Copy As..." ) );
ac->addAction( "file_save_copy", m_saveCopyAs );
m_saveCopyAs->setEnabled( false );
m_saveAs = KStandardAction::saveAs( this, SLOT(slotSaveFileAs()), ac );
m_saveAs->setEnabled( false );
m_saveCopyAs = NULL;
m_saveAs = NULL;
QAction * prefs = KStandardAction::preferences( this, SLOT(slotPreferences()), ac);
if ( m_embedMode == NativeShellMode )
@ -537,7 +604,13 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
KAction * genPrefs = new KAction( ac );
ac->addAction("options_configure_generators", genPrefs);
genPrefs->setText( i18n( "Configure Backends..." ) );
if ( m_embedMode == ViewerWidgetMode )
{
genPrefs->setText( i18n( "Configure Viewer Backends..." ) );
}
else {
genPrefs->setText( i18n( "Configure Backends..." ) );
}
genPrefs->setIcon( KIcon( "configure" ) );
genPrefs->setEnabled( m_document->configurableGenerators() > 0 );
connect( genPrefs, SIGNAL(triggered(bool)), this, SLOT(slotGeneratorPreferences()) );
@ -545,6 +618,79 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
m_printPreview = KStandardAction::printPreview( this, SLOT(slotPrintPreview()), ac );
m_printPreview->setEnabled( false );
m_showLeftPanel = NULL;
m_showBottomBar = NULL;
m_showProperties = ac->addAction("properties");
m_showProperties->setText(i18n("&Properties"));
m_showProperties->setIcon(KIcon("document-properties"));
connect(m_showProperties, SIGNAL(triggered()), this, SLOT(slotShowProperties()));
m_showProperties->setEnabled( false );
m_showEmbeddedFiles = NULL;
m_showPresentation = NULL;
m_exportAs = NULL;
m_exportAsMenu = NULL;
m_exportAsText = NULL;
m_exportAsDocArchive = NULL;
m_aboutBackend = ac->addAction("help_about_backend");
m_aboutBackend->setText(i18n("About Backend"));
m_aboutBackend->setEnabled( false );
connect(m_aboutBackend, SIGNAL(triggered()), this, SLOT(slotAboutBackend()));
KAction *reload = ac->add<KAction>( "file_reload" );
reload->setText( i18n( "Reloa&d" ) );
reload->setIcon( KIcon( "view-refresh" ) );
reload->setWhatsThis( i18n( "Reload the current document from disk." ) );
connect( reload, SIGNAL(triggered()), this, SLOT(slotReload()) );
reload->setShortcut( QKeySequence( Qt::ALT + Qt::Key_F5 ) );
m_reload = reload;
m_closeFindBar = new KAction( i18n( "Close &Find Bar" ), ac );
ac->addAction("close_find_bar", m_closeFindBar);
connect(m_closeFindBar, SIGNAL(triggered()), this, SLOT(slotHideFindBar()));
widget()->addAction(m_closeFindBar);
}
void Part::setupActions()
{
KActionCollection * ac = actionCollection();
// we change some shortcuts back to their defaults (which were changed in 'setupViewerActions')
if ( m_embedMode != ViewerWidgetMode )
{
m_gotoPage->setShortcut( QKeySequence(Qt::CTRL + Qt::Key_G) );
m_find->setShortcut( KStandardShortcut::find() );
QList<QKeySequence> s = m_find->shortcuts();
s.append( QKeySequence( Qt::Key_Slash ) );
m_find->setShortcuts( s );
m_findNext->setShortcut( KStandardShortcut::findNext() );
m_findNext->setShortcut( KStandardShortcut::findPrev() );
m_addBookmark->setShortcut( KStandardShortcut::addBookmark() );
m_beginningOfDocument->setShortcut( KStandardShortcut::begin() );
m_endOfDocument->setShortcut( KStandardShortcut::end() );
KAction *action = static_cast<KAction*>(ac->action("close_find_bar"));
if( action ) action->setShortcut( QKeySequence( Qt::Key_Escape ) );
action = static_cast<KAction*>(ac->action("file_reload"));
if( action ) action->setShortcut( KStandardShortcut::reload() );
}
m_copy = KStandardAction::create( KStandardAction::Copy, m_pageView, SLOT(copyTextSelection()), ac );
m_selectAll = KStandardAction::selectAll( m_pageView, SLOT(selectAll()), ac );
m_saveCopyAs = KStandardAction::saveAs( this, SLOT(slotSaveCopyAs()), ac );
m_saveCopyAs->setText( i18n( "Save &Copy As..." ) );
ac->addAction( "file_save_copy", m_saveCopyAs );
m_saveCopyAs->setEnabled( false );
m_saveAs = KStandardAction::saveAs( this, SLOT(slotSaveFileAs()), ac );
m_saveAs->setEnabled( false );
m_showLeftPanel = ac->add<KToggleAction>("show_leftpanel");
m_showLeftPanel->setText(i18n( "Show &Navigation Panel"));
m_showLeftPanel->setIcon(KIcon( "view-sidetree" ));
@ -559,38 +705,12 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
m_showBottomBar->setChecked( Okular::Settings::showBottomBar() );
slotShowBottomBar();
QAction * importPS = ac->addAction("import_ps");
importPS->setText(i18n("&Import PostScript as PDF..."));
importPS->setIcon(KIcon("document-import"));
connect(importPS, SIGNAL(triggered()), this, SLOT(slotImportPSFile()));
#if 0
QAction * ghns = ac->addAction("get_new_stuff");
ghns->setText(i18n("&Get Books From Internet..."));
ghns->setIcon(KIcon("get-hot-new-stuff"));
connect(ghns, SIGNAL(triggered()), this, SLOT(slotGetNewStuff()));
// TEMP, REMOVE ME!
ghns->setShortcut( Qt::Key_G );
#endif
m_showProperties = ac->addAction("properties");
m_showProperties->setText(i18n("&Properties"));
m_showProperties->setIcon(KIcon("document-properties"));
connect(m_showProperties, SIGNAL(triggered()), this, SLOT(slotShowProperties()));
m_showProperties->setEnabled( false );
m_showEmbeddedFiles = ac->addAction("embedded_files");
m_showEmbeddedFiles->setText(i18n("&Embedded Files"));
m_showEmbeddedFiles->setIcon( KIcon( "mail-attachment" ) );
connect(m_showEmbeddedFiles, SIGNAL(triggered()), this, SLOT(slotShowEmbeddedFiles()));
m_showEmbeddedFiles->setEnabled( false );
m_showPresentation = ac->addAction("presentation");
m_showPresentation->setText(i18n("P&resentation"));
m_showPresentation->setIcon( KIcon( "view-presentation" ) );
connect(m_showPresentation, SIGNAL(triggered()), this, SLOT(slotShowPresentation()));
m_showPresentation->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_P ) );
m_showPresentation->setEnabled( false );
m_exportAs = ac->addAction("file_export_as");
m_exportAs->setText(i18n("E&xport As"));
m_exportAs->setIcon( KIcon( "document-export" ) );
@ -607,23 +727,25 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
m_exportAsMenu->addAction( m_exportAsDocArchive );
m_exportAsDocArchive->setEnabled( false );
m_aboutBackend = ac->addAction("help_about_backend");
m_aboutBackend->setText(i18n("About Backend"));
m_aboutBackend->setEnabled( false );
connect(m_aboutBackend, SIGNAL(triggered()), this, SLOT(slotAboutBackend()));
m_showPresentation = ac->addAction("presentation");
m_showPresentation->setText(i18n("P&resentation"));
m_showPresentation->setIcon( KIcon( "view-presentation" ) );
connect(m_showPresentation, SIGNAL(triggered()), this, SLOT(slotShowPresentation()));
m_showPresentation->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_P ) );
m_showPresentation->setEnabled( false );
KAction *reload = ac->add<KAction>( "file_reload" );
reload->setText( i18n( "Reloa&d" ) );
reload->setIcon( KIcon( "view-refresh" ) );
reload->setWhatsThis( i18n( "Reload the current document from disk." ) );
connect( reload, SIGNAL(triggered()), this, SLOT(slotReload()) );
reload->setShortcut( KStandardShortcut::reload() );
m_reload = reload;
m_closeFindBar = new KAction( i18n( "Close &Find Bar" ), ac );
ac->addAction("close_find_bar", m_closeFindBar);
connect(m_closeFindBar, SIGNAL(triggered()), this, SLOT(slotHideFindBar()));
widget()->addAction(m_closeFindBar);
QAction * importPS = ac->addAction("import_ps");
importPS->setText(i18n("&Import PostScript as PDF..."));
importPS->setIcon(KIcon("document-import"));
connect(importPS, SIGNAL(triggered()), this, SLOT(slotImportPSFile()));
#if 0
QAction * ghns = ac->addAction("get_new_stuff");
ghns->setText(i18n("&Get Books From Internet..."));
ghns->setIcon(KIcon("get-hot-new-stuff"));
connect(ghns, SIGNAL(triggered()), this, SLOT(slotGetNewStuff()));
// TEMP, REMOVE ME!
ghns->setShortcut( Qt::Key_G );
#endif
KToggleAction *blackscreenAction = new KToggleAction( i18n( "Switch Blackscreen Mode" ), ac );
ac->addAction( "switch_blackscreen_mode", blackscreenAction );
@ -637,54 +759,8 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
KAction *eraseDrawingAction = new KAction( i18n( "Erase Drawings" ), ac );
ac->addAction( "presentation_erase_drawings", eraseDrawingAction );
eraseDrawingAction->setIcon( KIcon( "draw-eraser" ) );
// document watcher and reloader
m_watcher = new KDirWatch( this );
connect( m_watcher, SIGNAL(dirty(QString)), this, SLOT(slotFileDirty(QString)) );
m_dirtyHandler = new QTimer( this );
m_dirtyHandler->setSingleShot( true );
connect( m_dirtyHandler, SIGNAL(timeout()),this, SLOT(slotDoFileDirty()) );
slotNewConfig();
// [SPEECH] check for KTTSD presence and usability
const KService::Ptr kttsd = KService::serviceByDesktopName("kttsd");
Okular::Settings::setUseKTTSD( kttsd );
Okular::Settings::self()->writeConfig();
rebuildBookmarkMenu( false );
// set our XML-UI resource file
setXMLFile("part.rc");
m_pageView->setupBaseActions( actionCollection() );
// ensure history actions are in the correct state
updateViewActions();
m_sidebar->setSidebarVisibility( false );
if ( m_embedMode != PrintPreviewMode && m_embedMode != ViewerWidgetMode ) {
unsetDummyMode();
}
if( m_embedMode == ViewerWidgetMode ) {
m_bottomBar->setVisible(false);
m_pageView->setShowMoveDestinationGraphically(true);
// FIXME: this should probably be implemented in such a way that there is no
// need to change the configuration settings
Okular::Settings::setViewMode(Okular::Settings::EnumViewMode::Single);
Okular::Settings::setViewContinuous(true);
}
if ( m_embedMode == NativeShellMode )
m_sidebar->setAutoFillBackground( false );
#ifdef OKULAR_KEEP_FILE_OPEN
m_keeper = new FileKeeper();
#endif
}
Part::~Part()
{
GuiUtils::removeIconLoader( iconLoader() );
@ -776,7 +852,7 @@ void Part::setWatchFileModeEnabled(bool b)
void Part::slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool &handled)
{
emit(openSourceReference(absFileName, line, col));
if ( m_embedMode == Okular::Part::ViewerWidgetMode ) {
if ( m_embedMode == Okular::ViewerWidgetMode ) {
handled = true;
}
}
@ -874,7 +950,14 @@ void Part::slotGeneratorPreferences( )
// we didn't find an instance of this dialog, so lets create it
KConfigDialog * dialog = new KConfigDialog( m_pageView, "generator_prefs", Okular::Settings::self() );
dialog->setCaption( i18n( "Configure Backends" ) );
if( m_embedMode == ViewerWidgetMode )
{
dialog->setCaption( i18n( "Configure Viewer Backends" ) );
}
else
{
dialog->setCaption( i18n( "Configure Backends" ) );
}
m_document->fillConfigDialog( dialog );
@ -1043,26 +1126,29 @@ bool Part::openFile()
m_find->setEnabled( ok && canSearch );
m_findNext->setEnabled( ok && canSearch );
m_findPrev->setEnabled( ok && canSearch );
m_saveAs->setEnabled( ok && m_document->canSaveChanges() );
m_saveCopyAs->setEnabled( ok );
if( m_saveAs ) m_saveAs->setEnabled( ok && m_document->canSaveChanges() );
if( m_saveCopyAs ) m_saveCopyAs->setEnabled( ok );
emit enablePrintAction( ok && m_document->printingSupport() != Okular::Document::NoPrinting );
m_printPreview->setEnabled( ok && m_document->printingSupport() != Okular::Document::NoPrinting );
m_showProperties->setEnabled( ok );
bool hasEmbeddedFiles = ok && m_document->embeddedFiles() && m_document->embeddedFiles()->count() > 0;
m_showEmbeddedFiles->setEnabled( hasEmbeddedFiles );
if ( m_showEmbeddedFiles ) m_showEmbeddedFiles->setEnabled( hasEmbeddedFiles );
m_topMessage->setVisible( hasEmbeddedFiles );
// m_pageView->toggleFormsAction() may be null on dummy mode
m_formsMessage->setVisible( ok && m_pageView->toggleFormsAction() && m_pageView->toggleFormsAction()->isEnabled() );
m_showPresentation->setEnabled( ok );
if ( m_showPresentation ) m_showPresentation->setEnabled( ok );
if ( ok )
{
m_exportFormats = m_document->exportFormats();
QList<Okular::ExportFormat>::ConstIterator it = m_exportFormats.constBegin();
QList<Okular::ExportFormat>::ConstIterator itEnd = m_exportFormats.constEnd();
QMenu *menu = m_exportAs->menu();
for ( ; it != itEnd; ++it )
if ( m_exportAs )
{
menu->addAction( actionForExportFormat( *it ) );
m_exportFormats = m_document->exportFormats();
QList<Okular::ExportFormat>::ConstIterator it = m_exportFormats.constBegin();
QList<Okular::ExportFormat>::ConstIterator itEnd = m_exportFormats.constEnd();
QMenu *menu = m_exportAs->menu();
for ( ; it != itEnd; ++it )
{
menu->addAction( actionForExportFormat( *it ) );
}
}
if ( isCompressedFile )
{
@ -1073,9 +1159,9 @@ bool Part::openFile()
m_keeper->open( fileNameToOpen );
#endif
}
m_exportAsText->setEnabled( ok && m_document->canExportToText() );
m_exportAsDocArchive->setEnabled( ok );
m_exportAs->setEnabled( ok );
if ( m_exportAsText ) m_exportAsText->setEnabled( ok && m_document->canExportToText() );
if ( m_exportAsDocArchive ) m_exportAsDocArchive->setEnabled( ok );
if ( m_exportAs ) m_exportAs->setEnabled( ok );
// update viewing actions
updateViewActions();
@ -1183,24 +1269,27 @@ bool Part::closeUrl()
m_find->setEnabled( false );
m_findNext->setEnabled( false );
m_findPrev->setEnabled( false );
m_saveAs->setEnabled( false );
m_saveCopyAs->setEnabled( false );
if( m_saveAs ) m_saveAs->setEnabled( false );
if( m_saveCopyAs ) m_saveCopyAs->setEnabled( false );
m_printPreview->setEnabled( false );
m_showProperties->setEnabled( false );
m_showEmbeddedFiles->setEnabled( false );
m_exportAs->setEnabled( false );
m_exportAsText->setEnabled( false );
m_exportAsDocArchive->setEnabled( false );
if ( m_showEmbeddedFiles ) m_showEmbeddedFiles->setEnabled( false );
if ( m_exportAs ) m_exportAs->setEnabled( false );
if ( m_exportAsText ) m_exportAsText->setEnabled( false );
if ( m_exportAsDocArchive ) m_exportAsDocArchive->setEnabled( false );
m_exportFormats.clear();
QMenu *menu = m_exportAs->menu();
QList<QAction*> acts = menu->actions();
int num = acts.count();
for ( int i = 2; i < num; ++i )
if ( m_exportAs )
{
menu->removeAction( acts.at(i) );
delete acts.at(i);
QMenu *menu = m_exportAs->menu();
QList<QAction*> acts = menu->actions();
int num = acts.count();
for ( int i = 2; i < num; ++i )
{
menu->removeAction( acts.at(i) );
delete acts.at(i);
}
}
m_showPresentation->setEnabled( false );
if ( m_showPresentation ) m_showPresentation->setEnabled( false );
emit setWindowCaption("");
emit enablePrintAction(false);
m_realUrl = KUrl();
@ -1418,8 +1507,8 @@ void Part::updateViewActions()
if (m_historyBack) m_historyBack->setEnabled( !m_document->historyAtBegin() );
if (m_historyNext) m_historyNext->setEnabled( !m_document->historyAtEnd() );
m_reload->setEnabled( true );
m_copy->setEnabled( true );
m_selectAll->setEnabled( true );
if (m_copy) m_copy->setEnabled( true );
if (m_selectAll) m_selectAll->setEnabled( true );
}
else
{
@ -1431,8 +1520,8 @@ void Part::updateViewActions()
if (m_historyBack) m_historyBack->setEnabled( false );
if (m_historyNext) m_historyNext->setEnabled( false );
m_reload->setEnabled( false );
m_copy->setEnabled( false );
m_selectAll->setEnabled( false );
if (m_copy) m_copy->setEnabled( false );
if (m_selectAll) m_selectAll->setEnabled( false );
}
updateBookmarksActions();
}
@ -1780,7 +1869,7 @@ void Part::slotPreferences()
return;
// we didn't find an instance of this dialog, so lets create it
PreferencesDialog * dialog = new PreferencesDialog( m_pageView, Okular::Settings::self() );
PreferencesDialog * dialog = new PreferencesDialog( m_pageView, Okular::Settings::self(), m_embedMode );
// keep us informed when the user changes settings
connect( dialog, SIGNAL(settingsChanged(QString)), this, SLOT(slotNewConfig()) );
@ -2250,9 +2339,6 @@ void Part::unsetDummyMode()
// attach the actions of the children widgets too
m_formsMessage->setActionButton( m_pageView->toggleFormsAction() );
// ensure history actions are in the correct state
updateViewActions();
}

12
part.h
View file

@ -80,15 +80,6 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
Q_INTERFACES(Okular::ViewerInterface)
public:
enum EmbedMode
{
UnknownEmbedMode,
NativeShellMode, // embedded in the native Okular' shell
PrintPreviewMode, // embedded to show the print preview of a document
KHTMLPartMode, // embedded in KHTML
ViewerWidgetMode, // the part acts as a widget that can display all kinds of documents
};
// Default constructor
/**
* If one element of 'args' contains one of the strings "Print/Preview" or "ViewerWidget",
@ -195,6 +186,9 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
void psTransformEnded(int, QProcess::ExitStatus);
private:
void setupViewerActions();
void setupActions();
void setupPrint( QPrinter &printer );
void doPrint( QPrinter &printer );
bool handleCompressed( QString &destpath, const QString &path, const QString &compressedMimetype );

View file

@ -197,6 +197,7 @@ public:
KAction * aSpeakPage;
KAction * aSpeakStop;
KActionCollection * actionCollection;
QActionGroup * mouseModeActionGroup;
int setting_viewCols;
@ -305,6 +306,7 @@ PageView::PageView( QWidget *parent, Okular::Document *document )
d->actionCollection = 0;
d->aPageSizes=0;
d->setting_viewCols = Okular::Settings::viewColumns();
d->mouseModeActionGroup = 0;
d->showMoveDestinationGraphically = false;
switch( Okular::Settings::zoomMode() )
@ -402,10 +404,13 @@ void PageView::setupBaseActions( KActionCollection * ac )
d->aZoomOut = KStandardAction::zoomOut( this, SLOT(slotZoomOut()), ac );
}
void PageView::setupActions( KActionCollection * ac )
void PageView::setupViewerActions( KActionCollection * ac )
{
d->actionCollection = ac;
d->aZoomIn->setShortcut( QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Plus) );
d->aZoomOut->setShortcut( QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Minus) );
// orientation menu actions
d->aRotateClockwise = new KAction( KIcon( "object-rotate-right" ), i18n( "Rotate &Right" ), this );
d->aRotateClockwise->setIconText( i18nc( "Rotate right", "Right" ) );
@ -482,16 +487,16 @@ do { \
connect( d->aViewContinuous, SIGNAL(toggled(bool)), SLOT(slotContinuousToggled(bool)) );
d->aViewContinuous->setChecked( Okular::Settings::viewContinuous() );
// Mouse-Mode actions
QActionGroup * actGroup = new QActionGroup( this );
actGroup->setExclusive( true );
// Mouse mode actions for viewer mode
d->mouseModeActionGroup = new QActionGroup( this );
d->mouseModeActionGroup->setExclusive( true );
d->aMouseNormal = new KAction( KIcon( "input-mouse" ), i18n( "&Browse Tool" ), this );
ac->addAction("mouse_drag", d->aMouseNormal );
connect( d->aMouseNormal, SIGNAL(triggered()), this, SLOT(slotSetMouseNormal()) );
d->aMouseNormal->setIconText( i18nc( "Browse Tool", "Browse" ) );
d->aMouseNormal->setCheckable( true );
d->aMouseNormal->setShortcut( Qt::CTRL + Qt::Key_1 );
d->aMouseNormal->setActionGroup( actGroup );
d->aMouseNormal->setActionGroup( d->mouseModeActionGroup );
d->aMouseNormal->setChecked( true );
KAction * mz = new KAction(KIcon( "page-zoom" ), i18n("&Zoom Tool"), this);
@ -500,15 +505,26 @@ do { \
mz->setIconText( i18nc( "Zoom Tool", "Zoom" ) );
mz->setCheckable( true );
mz->setShortcut( Qt::CTRL + Qt::Key_2 );
mz->setActionGroup( actGroup );
mz->setActionGroup( d->mouseModeActionGroup );
}
// WARNING: 'setupViewerActions' must have been called before this method
void PageView::setupActions( KActionCollection * ac )
{
d->actionCollection = ac;
d->aZoomIn->setShortcut( KStandardShortcut::zoomIn() );
d->aZoomOut->setShortcut( KStandardShortcut::zoomOut() );
// Mouse-Mode actions
d->aMouseSelect = new KAction(KIcon( "select-rectangular" ), i18n("&Selection Tool"), this);
ac->addAction("mouse_select", d->aMouseSelect );
connect( d->aMouseSelect, SIGNAL(triggered()), this, SLOT(slotSetMouseSelect()) );
d->aMouseSelect->setIconText( i18nc( "Select Tool", "Selection" ) );
d->aMouseSelect->setCheckable( true );
d->aMouseSelect->setShortcut( Qt::CTRL + Qt::Key_3 );
d->aMouseSelect->setActionGroup( actGroup );
d->aMouseSelect->setActionGroup( d->mouseModeActionGroup );
d->aMouseTextSelect = new KAction(KIcon( "draw-text" ), i18n("&Text Selection Tool"), this);
ac->addAction("mouse_textselect", d->aMouseTextSelect );
@ -516,7 +532,8 @@ do { \
d->aMouseTextSelect->setIconText( i18nc( "Text Selection Tool", "Text Selection" ) );
d->aMouseTextSelect->setCheckable( true );
d->aMouseTextSelect->setShortcut( Qt::CTRL + Qt::Key_4 );
d->aMouseTextSelect->setActionGroup( actGroup );
Q_ASSERT( d->mouseModeActionGroup );
d->aMouseTextSelect->setActionGroup( d->mouseModeActionGroup );
d->aMouseTableSelect = new KAction(KIcon( "select-table" ), i18n("T&able Selection Tool"), this);
ac->addAction("mouse_tableselect", d->aMouseTableSelect );
@ -524,7 +541,7 @@ do { \
d->aMouseTableSelect->setIconText( i18nc( "Table Selection Tool", "Table Selection" ) );
d->aMouseTableSelect->setCheckable( true );
d->aMouseTableSelect->setShortcut( Qt::CTRL + Qt::Key_5 );
d->aMouseTableSelect->setActionGroup( actGroup );
d->aMouseTableSelect->setActionGroup( d->mouseModeActionGroup );
d->aToggleAnnotator = new KToggleAction(KIcon( "draw-freehand" ), i18n("&Review"), this);
ac->addAction("mouse_toggle_annotate", d->aToggleAnnotator );
@ -3877,7 +3894,7 @@ void PageView::slotSetMouseNormal()
// hide the messageWindow
d->messageWindow->hide();
// reshow the annotator toolbar if hiding was forced
if ( d->aToggleAnnotator->isChecked() )
if ( d->aToggleAnnotator && d->aToggleAnnotator->isChecked() )
slotToggleAnnotator( true );
// force an update of the cursor
updateCursor( contentAreaPosition() + viewport()->mapFromGlobal( QCursor::pos() ) );

View file

@ -62,6 +62,7 @@ Q_OBJECT
// create actions that interact with this widget
void setupBaseActions( KActionCollection * collection );
void setupViewerActions( KActionCollection * collection );
void setupActions( KActionCollection * collection );
// misc methods (from RMB menu/children)