⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 part.cpp.svn-base

📁 okular
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
            Generator* (*create_plugin)(KPDFDocument* doc) = ( Generator* (*)(KPDFDocument* doc) ) lib->symbol( "create_plugin" );            if ( !create_plugin )            {                kWarning() << "Library '" << offers.at(i)->library() << "' has no symbol 'create_plugin'." << endl;                continue;            }            // the generator should do anything with the document if we are only configuring            m_loadedGenerators.insert(propName,create_plugin(m_document));            m_generatorsWithSettings << propName;          }        }    }}void Part::slotGeneratorPreferences( ){    fillGenerators();    //Generator* gen= m_loadedGenerators[m_generatorsWithSettings[number]];    // an instance the dialog could be already created and could be cached,    // in which case you want to display the cached dialog    if ( KConfigDialog::showDialog( "generator_prefs" ) )        return;    // we didn't find an instance of this dialog, so lets create it    KConfigDialog * dialog = new KConfigDialog( m_pageView, "generator_prefs", KpdfSettings::self() );    dialog->setCaption( i18n( "Configure Backends" ) );    QHashIterator<QString, Generator*> it(m_loadedGenerators);    while(it.hasNext())    {        it.next();        it.value()->addPages(dialog);    }    // (for now dont FIXME) keep us informed when the user changes settings    // connect( dialog, SIGNAL( settingsChanged() ), this, SLOT( slotNewConfig() ) );    dialog->show();}void Part::notifyViewportChanged( bool /*smoothMove*/ ){    // update actions if the page is changed    static int lastPage = -1;    int viewportPage = m_document->viewport().pageNumber;    if ( viewportPage != lastPage )    {        updateViewActions();        lastPage = viewportPage;    }}void Part::goToPage(uint i){    if ( i <= m_document->pages() )        m_document->setViewportPage( i - 1 );}void Part::openDocument(KUrl doc){    openURL(doc);}uint Part::pages(){    return m_document->pages();}uint Part::currentPage(){    return m_document->pages() ? m_document->currentPage() + 1 : 0;}KUrl Part::currentDocument(){    return m_document->currentDocument();}//this don't go anywhere but is required by genericfactory.hKAboutData* Part::createAboutData(){	// the non-i18n name here must be the same as the directory in	// which the part's rc file is installed ('partrcdir' in the	// Makefile)	KAboutData* aboutData = new KAboutData("okularpart", I18N_NOOP("okular::Part"), "0.1");	aboutData->addAuthor("Wilco Greven", 0, "greven@kde.org");	return aboutData;}bool Part::slotImportPSFile(){	QString app = KStandardDirs::findExe( "ps2pdf" );	if ( app.isEmpty() )	{		// TODO point the user to their distro packages?		KMessageBox::error( widget(), i18n( "The program \"ps2pdf\" was not found, so okular can not import PS files using it." ), i18n("ps2pdf not found") );		return false;	}    KUrl url = KFileDialog::getOpenUrl( KUrl(), "application/postscript", this->widget() );    KTempFile tf( QString::null, ".pdf" );    if ( tf.status() == 0 && url.isLocalFile())    {        tf.close();        m_file = url.path();        m_temporaryLocalFile = tf.name();        KProcess *p = new KProcess;        *p << app;        *p << m_file << m_temporaryLocalFile;        m_pageView->displayMessage(i18n("Importing PS file as PDF (this may take a while)..."));        connect(p, SIGNAL(processExited(KProcess *)), this, SLOT(psTransformEnded()));        p -> start();        return true;    }    m_temporaryLocalFile = QString::null;    return false;}bool Part::openFile(){    KMimeType::Ptr mime;    if ( m_bExtension->urlArgs().serviceType.isEmpty() )    {        mime = KMimeType::findByPath( m_file );    }    else    {        mime = KMimeType::mimeType( m_bExtension->urlArgs().serviceType );    }    bool ok = m_document->openDocument( m_file, url(), mime );    bool canSearch = m_document->supportsSearching();    // update one-time actions    m_find->setEnabled( ok && canSearch );    m_findNext->setEnabled( ok && canSearch );    m_saveAs->setEnabled( ok );    m_printPreview->setEnabled( ok );    m_showProperties->setEnabled( ok );    m_showEmbeddedFiles->setEnabled( ok && m_document->embeddedFiles() && m_document->embeddedFiles()->count() > 0);    m_showPresentation->setEnabled( ok );    if ( ok )    {        m_exportItems = m_document->exportFormats();        QList<ExportEntry*>::ConstIterator it = m_exportItems.constBegin();        QList<ExportEntry*>::ConstIterator itEnd = m_exportItems.constEnd();        QMenu *menu = m_exportAs->menu();        for ( ; it != itEnd; ++it )        {            ExportEntry* cur = *it;            if ( !cur->icon.isEmpty() )            {                menu->addAction( KIcon( cur->icon ), cur->description );            }            else            {                menu->addAction( cur->description );            }        }    }    m_exportAsText->setEnabled( ok && m_document->canExportToText() );    // update viewing actions    updateViewActions();    if ( !ok )    {        // if can't open document, update windows so they display blank contents        m_pageView->updateContents();        m_thumbnailList->update();        return false;    }    // set the file to the fileWatcher    if ( !m_watcher->contains(m_file) )        m_watcher->addFile(m_file);    // if the 'StartFullScreen' flag is set, start presentation    if ( m_document->getMetaData( "StartFullScreen" ) == "yes" )    {        KMessageBox::information( m_presentationWidget, i18n("The document is going to be launched on presentation mode because the file requested it."), QString::null, "autoPresentationWarning" );        slotShowPresentation();    }/*    if (m_document->getXMLFile() != QString::null)        setXMLFile(m_document->getXMLFile(),true);*/    m_document->setupGUI(actionCollection(),m_toolBox);    return true;}bool Part::openURL(const KUrl &url){    // note: this can be the right place to check the file for gz or bz2 extension    // if it matches then: download it (if not local) extract to a temp file using    // KTar and proceed with the URL of the temporary file    // this calls in sequence the 'closeURL' and 'openFile' methods    bool openOk = KParts::ReadOnlyPart::openURL(url);    if ( openOk )    {        m_viewportDirty = 0;        // if the document have a 'DocumentTitle' flag set (and it is not empty), set it as title        QString title = m_document->getMetaData( "DocumentTitle" );        if ( !title.isEmpty() && !title.trimmed().isEmpty() )        {            emit setWindowCaption( title );        }    }    else        KMessageBox::error( widget(), i18n( "Could not open %1", url.prettyUrl() ) );    emit enablePrintAction(openOk);    return openOk;}bool Part::closeURL(){    if (!m_temporaryLocalFile.isNull())    {        QFile::remove( m_temporaryLocalFile );        m_temporaryLocalFile = QString::null;    }    slotHidePresentation();    m_find->setEnabled( false );    m_findNext->setEnabled( false );    m_saveAs->setEnabled( false );    m_printPreview->setEnabled( false );    m_showProperties->setEnabled( false );    m_showEmbeddedFiles->setEnabled( false );    m_exportAsText->setEnabled( false );    m_exportItems.clear();    QMenu *menu = m_exportAs->menu();    QList<QAction*> acts = menu->actions();    int num = acts.count();    for ( int i = 1; i < num; ++i )    {        menu->removeAction( acts.at(i) );        delete acts.at(i);    }    m_showPresentation->setEnabled( false );    emit setWindowCaption("");    emit enablePrintAction(false);    m_searchStarted = false;    if (!m_file.isEmpty()) m_watcher->removeFile(m_file);    m_document->closeDocument();    updateViewActions();    m_searchWidget->clearText();    return KParts::ReadOnlyPart::closeURL();}void Part::close(){  if (parent() && (parent()->objectName() == QLatin1String("okular::Shell")))  {    closeURL();  }  else KMessageBox::information(widget(), i18n("This link points to a close document action that does not work when using the embedded viewer."), QString::null, "warnNoCloseIfNotInKPDF");}void Part::cannotQuit(){	KMessageBox::information(widget(), i18n("This link points to a quit application action that does not work when using the embedded viewer."), QString::null, "warnNoQuitIfNotInKPDF");}bool Part::eventFilter( QObject * watched, QEvent * e ){    // if pageView has been resized, save splitter sizes    if ( watched == m_pageView && e->type() == QEvent::Resize )        saveSplitterSize();    // only intercept events, don't block them    return false;}void Part::slotShowLeftPanel(){    bool showLeft = m_showLeftPanel->isChecked();    KpdfSettings::setShowLeftPanel( showLeft );    KpdfSettings::writeConfig();    // show/hide left panel    m_leftPanel->setVisible( showLeft );    // this needs to be hidden explicitly to disable thumbnails gen    m_thumbnailList->setVisible( showLeft );}void Part::saveSplitterSize(){    KpdfSettings::setSplitterSizes( m_splitter->sizes() );    KpdfSettings::writeConfig();}void Part::slotFileDirty( const QString& fileName ){  // The beauty of this is that each start cancels the previous one.  // This means that timeout() is only fired when there have  // no changes to the file for the last 750 milisecs.  // This ensures that we don't update on every other byte that gets  // written to the file.  if ( fileName == m_file )  {    m_dirtyHandler->start( 750 );  }}void Part::slotDoFileDirty(){    // do the following the first time the file is reloaded    if ( m_viewportDirty.pageNumber == -1 )    {        // store the current viewport        m_viewportDirty = DocumentViewport( m_document->viewport() );        // inform the user about the operation in progress        m_pageView->displayMessage( i18n("Reloading the document...") );    }    // close and (try to) reopen the document    if ( KParts::ReadOnlyPart::openURL(m_file) )    {        // on successfull opening, restore the previous viewport        if ( m_viewportDirty.pageNumber >= (int) m_document->pages() )             m_viewportDirty.pageNumber = (int) m_document->pages() - 1;        m_document->setViewport( m_viewportDirty );        m_viewportDirty.pageNumber = -1;        emit enablePrintAction(true);    }    else    {        // start watching the file again (since we dropped it on close)        m_watcher->addFile(m_file);        m_dirtyHandler->start( 750 );    }}void Part::updateViewActions(){    bool opened = m_document->pages() > 0;    if ( opened )    {        bool atBegin = m_document->currentPage() < 1;        bool atEnd = m_document->currentPage() >= (m_document->pages() - 1);        m_gotoPage->setEnabled( m_document->pages() > 1 );        m_firstPage->setEnabled( !atBegin );        m_prevPage->setEnabled( !atBegin );        m_lastPage->setEnabled( !atEnd );        m_nextPage->setEnabled( !atEnd );        m_historyBack->setEnabled( !m_document->historyAtBegin() );        m_historyNext->setEnabled( !m_document->historyAtEnd() );    }    else    {        m_gotoPage->setEnabled( false );        m_firstPage->setEnabled( false );        m_lastPage->setEnabled( false );        m_prevPage->setEnabled( false );        m_nextPage->setEnabled( false );        m_historyBack->setEnabled( false );        m_historyNext->setEnabled( false );    }}void Part::enableTOC(bool enable){	m_toolBox->setItemEnabled(0, enable);}//BEGIN go to page dialogclass KPDFGotoPageDialog : public KDialog{public:	KPDFGotoPageDialog(QWidget *p, int current, int max) : KDialog(p) {		setCaption(i18n("Go to Page"));		setButtons(Ok | Cancel);		setDefaultButton(Ok);		QWidget *w = new QWidget(this);		setMainWidget(w);		QVBoxLayout *topLayout = new QVBoxLayout(w);		topLayout->setMargin(0);		topLayout->setSpacing(spacingHint());		e1 = new KIntNumInput(current, w);		e1->setRange(1, max);		e1->setEditFocus(true);		QLabel *label = new QLabel(i18n("&Page:"), w);		label->setBuddy(e1);		topLayout->addWidget(label);		topLayout->addWidget(e1);		topLayout->addSpacing(spacingHint()); // A little bit extra space		topLayout->addStretch(10);		e1->setFocus();	}	int getPage() const {		return e1->value();	}  protected:    KIntNumInput *e1;};//END go to page dialogvoid Part::slotGoToPage(){    KPDFGotoPageDialog pageDialog( m_pageView, m_document->currentPage() + 1, m_document->pages() );    if ( pageDialog.exec() == QDialog::Accepted )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -