From b883cbcfa62c4ae95196b7a31ccce8c8b59120dc Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Tue, 5 Jun 2007 20:49:00 +0000 Subject: [PATCH] The part starts in dummy mode (very few ui) by default Can be deactivated using unsetDummyMode(), that is the first thing the okular shell does that's useful because for example for print preview you don't want to embed all the okular ui to do the preview, you just want to see the ps svn path=/trunk/KDE/kdegraphics/okular/; revision=671928 --- part.cpp | 57 ++++++++++++++++++++++++++++++++++--------------- part.h | 3 +++ shell/shell.cpp | 4 +++- ui/pageview.cpp | 46 +++++++++++++++++++++++---------------- 4 files changed, 74 insertions(+), 36 deletions(-) diff --git a/part.cpp b/part.cpp index b637ad6bc..13e8e1e47 100644 --- a/part.cpp +++ b/part.cpp @@ -419,22 +419,6 @@ m_searchStarted(false), m_cliPresentation(false) closeFindBar->setShortcut( QKeySequence( Qt::Key_Escape ) ); widget()->addAction(closeFindBar); - // attach the actions of the children widgets too - m_pageView->setupActions( ac ); - m_formsMessage->setActionButton( m_pageView->toggleFormsAction() ); - - // apply configuration (both internal settings and GUI configured items) - QList splitterSizes = Okular::Settings::splitterSizes(); - if ( !splitterSizes.count() ) - { - // the first time use 1/10 for the panel and 9/10 for the pageView - splitterSizes.push_back( 50 ); - splitterSizes.push_back( 500 ); - } - m_splitter->setSizes( splitterSizes ); - // get notified about splitter size changes - connect( m_splitter, SIGNAL( splitterMoved( int, int ) ), this, SLOT( splitterMoved( int, int ) ) ); - // document watcher and reloader m_watcher = new KDirWatch( this ); connect( m_watcher, SIGNAL( dirty( const QString& ) ), this, SLOT( slotFileDirty( const QString& ) ) ); @@ -455,6 +439,11 @@ m_searchStarted(false), m_cliPresentation(false) setXMLFile("part.rc"); // updateViewActions(); + + // By default we start with a clean UI so that for example print preview + // does not get all the stuff embedded + m_dummyMode = true; + m_leftPanel->hide(); } @@ -498,6 +487,8 @@ QStringList Part::supportedMimeTypes() const void Part::openUrlFromDocument(const KUrl &url) { + if (m_dummyMode) return; + m_bExtension->openUrlNotify(); m_bExtension->setLocationBarUrl(url.prettyUrl()); openUrl(url); @@ -699,7 +690,8 @@ bool Part::openFile() bool hasEmbeddedFiles = ok && m_document->embeddedFiles() && m_document->embeddedFiles()->count() > 0; m_showEmbeddedFiles->setEnabled( hasEmbeddedFiles ); m_topMessage->setVisible( hasEmbeddedFiles ); - m_formsMessage->setVisible( ok && m_pageView->toggleFormsAction()->isEnabled() ); + // 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 ( ok ) { @@ -1173,6 +1165,8 @@ void Part::slotFindNext() void Part::slotSaveFileAs() { + if (m_dummyMode) return; + KUrl saveUrl = KFileDialog::getSaveUrl( url().isLocalFile() ? url().url() : url().fileName(), QString(), widget() ); if ( saveUrl.isValid() && !saveUrl.isEmpty() ) { @@ -1288,6 +1282,8 @@ void Part::slotPrintPreview() void Part::slotShowMenu(const Okular::Page *page, const QPoint &point) { + if (m_dummyMode) return; + bool reallyShow = false; if (!m_actionsSearched) { @@ -1583,6 +1579,33 @@ void Part::psTransformEnded(int exit, QProcess::ExitStatus status) } +void Part::unsetDummyMode() +{ + if (!m_dummyMode) return; + + m_dummyMode = false; + + m_leftPanel->setVisible( Okular::Settings::showLeftPanel() ); + + // apply configuration (both internal settings and GUI configured items) + QList splitterSizes = Okular::Settings::splitterSizes(); + if ( !splitterSizes.count() ) + { + // the first time use 1/10 for the panel and 9/10 for the pageView + splitterSizes.push_back( 50 ); + splitterSizes.push_back( 500 ); + } + m_splitter->setSizes( splitterSizes ); + // get notified about splitter size changes + connect( m_splitter, SIGNAL( splitterMoved( int, int ) ), this, SLOT( splitterMoved( int, int ) ) ); + + m_pageView->setupActions( actionCollection() ); + + // attach the actions of the children widgets too + m_formsMessage->setActionButton( m_pageView->toggleFormsAction() ); +} + + bool Part::handleCompressed(KUrl & url, const QString &path, const KMimeType::Ptr mimetype) { diff --git a/part.h b/part.h index 05667f48b..0af7455f3 100644 --- a/part.h +++ b/part.h @@ -162,6 +162,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi void slotFileDirty( const QString& ); void slotDoFileDirty(); void psTransformEnded(int, QProcess::ExitStatus); + void unsetDummyMode(); private: void doPrint( KPrinter& printer ); @@ -241,6 +242,8 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi QString m_addBookmarkText; QIcon m_addBookmarkIcon; + bool m_dummyMode; + private slots: void slotGeneratorPreferences(); }; diff --git a/shell/shell.cpp b/shell/shell.cpp index 94f53a9ce..a95b0c8fd 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -71,6 +71,9 @@ void Shell::init() m_part = (KParts::ReadOnlyPart*) factory->createPart(this, this); if (m_part) { + // we don't want the dummy mode + QMetaObject::invokeMethod(m_part, "unsetDummyMode"); + // then, setup our actions setupActions(); // tell the KParts::MainWindow that this is indeed the main widget @@ -103,7 +106,6 @@ void Shell::init() setAutoSaveSettings(); if (m_openUrl.isValid()) QTimer::singleShot(0, this, SLOT(delayedOpen())); - } void Shell::delayedOpen() diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 21ab6fa6e..c7742fd54 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -269,6 +269,7 @@ PageView::PageView( QWidget *parent, Okular::Document *document ) d->messageWindow = new PageViewMessage(this); d->m_formsVisible = false; d->aPrevAction = 0; + d->aToggleForms = 0; d->aPageSizes=0; d->setting_viewMode = Okular::Settings::viewMode(); d->setting_viewCols = Okular::Settings::viewColumns(); @@ -664,19 +665,25 @@ void PageView::notifySetup( const QVector< Okular::Page * > & pageSet, bool docu pageSet.count() ), PageViewMessage::Info, 4000 ); - bool pageSizes = d->document->supportsPageSizes(); - d->aPageSizes->setEnabled( pageSizes ); - // set the new page sizes: - // - if the generator supports them - // - if the document changed - if ( pageSizes && documentChanged ) - { - QStringList items; - foreach ( const Okular::PageSize &p, d->document->pageSizes() ) - items.append( p.name() ); - d->aPageSizes->setItems( items ); + if ( d->aPageSizes ) + { // may be null if dummy mode is on + bool pageSizes = d->document->supportsPageSizes(); + d->aPageSizes->setEnabled( pageSizes ); + // set the new page sizes: + // - if the generator supports them + // - if the document changed + if ( pageSizes && documentChanged ) + { + QStringList items; + foreach ( const Okular::PageSize &p, d->document->pageSizes() ) + items.append( p.name() ); + d->aPageSizes->setItems( items ); + } + } + if ( d->aToggleForms ) + { // may be null if dummy mode is on + d->aToggleForms->setEnabled( !pageSet.isEmpty() && hasformwidgets ); } - d->aToggleForms->setEnabled( !pageSet.isEmpty() && hasformwidgets ); if ( d->annotator ) d->annotator->setTextToolsEnabled( d->document->supportsSearching() ); } @@ -2278,13 +2285,16 @@ void PageView::toggleFormWidgets( bool on ) if ( somehadfocus ) setFocus(); d->m_formsVisible = on; - if ( d->m_formsVisible ) + if ( d->aToggleForms ) // it may not exist if we are on dummy mode { - d->aToggleForms->setText( i18n( "Hide Forms" ) ); - } - else - { - d->aToggleForms->setText( i18n( "Show Forms" ) ); + if ( d->m_formsVisible ) + { + d->aToggleForms->setText( i18n( "Hide Forms" ) ); + } + else + { + d->aToggleForms->setText( i18n( "Show Forms" ) ); + } } }