📄 part.cpp.svn-base
字号:
m_document->setViewportPage( pageDialog.getPage() - 1 );}void Part::slotPreviousPage(){ if ( m_document->isOpened() && !(m_document->currentPage() < 1) ) m_document->setViewportPage( m_document->currentPage() - 1 );}void Part::slotNextPage(){ if ( m_document->isOpened() && m_document->currentPage() < (m_document->pages() - 1) ) m_document->setViewportPage( m_document->currentPage() + 1 );}void Part::slotGotoFirst(){ if ( m_document->isOpened() ) m_document->setViewportPage( 0 );}void Part::slotGotoLast(){ if ( m_document->isOpened() ) m_document->setViewportPage( m_document->pages() - 1 );}void Part::slotHistoryBack(){ m_document->setPrevViewport();}void Part::slotHistoryNext(){ m_document->setNextViewport();}void Part::slotPreviousBookmark(){ uint current = m_document->currentPage(); // we are at the first page if ( current == 0 ) return; for ( int i = current - 1; i >= 0; --i ) { if ( m_document->page( i )->hasBookmark() ) { m_document->setViewportPage( i ); break; } }}void Part::slotNextBookmark(){ uint current = m_document->currentPage(); uint pages = m_document->pages(); // we are at the last page if ( current == pages ) return; for ( uint i = current + 1; i < pages; ++i ) { if ( m_document->page( i )->hasBookmark() ) { m_document->setViewportPage( i ); break; } }}void Part::slotFind(){ KFindDialog dlg( widget() ); dlg.setHasCursor( false ); if ( !m_searchHistory.empty() ) dlg.setFindHistory( m_searchHistory ); dlg.setSupportsBackwardsFind( false ); dlg.setSupportsWholeWordsFind( false ); dlg.setSupportsRegularExpressionFind( false ); if ( dlg.exec() == QDialog::Accepted ) { m_searchHistory = dlg.findHistory(); m_searchStarted = true; m_document->resetSearch( PART_SEARCH_ID ); m_document->searchText( PART_SEARCH_ID, dlg.pattern(), false, dlg.options() & KFind::CaseSensitive, KPDFDocument::NextMatch, true, qRgb( 255, 255, 64 ) ); }}void Part::slotFindNext(){ if (!m_document->continueLastSearch()) slotFind();}void Part::slotSaveFileAs(){ KUrl saveURL = KFileDialog::getSaveUrl( url().isLocalFile() ? url().url() : url().fileName(), QString::null, widget() ); if ( saveURL.isValid() && !saveURL.isEmpty() ) { if ( KIO::NetAccess::exists( saveURL, false, widget() ) ) { if (KMessageBox::warningContinueCancel( widget(), i18n("A file named \"%1\" already exists. Are you sure you want to overwrite it?", saveURL.fileName()), QString::null, i18n("Overwrite")) != KMessageBox::Continue) return; } if ( !KIO::NetAccess::file_copy( url(), saveURL, -1, true ) ) KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", saveURL.prettyUrl() ) ); }}void Part::slotGetNewStuff(){ // show the modal dialog over pageview and execute it NewStuffDialog * dialog = new NewStuffDialog( m_pageView ); dialog->exec(); delete dialog;}void Part::slotPreferences(){ // an instance the dialog could be already created and could be cached, // in which case you want to display the cached dialog if ( PreferencesDialog::showDialog( "preferences" ) ) return; // we didn't find an instance of this dialog, so lets create it PreferencesDialog * dialog = new PreferencesDialog( m_pageView, KpdfSettings::self() ); // keep us informed when the user changes settings connect( dialog, SIGNAL( settingsChanged( const QString & ) ), this, SLOT( slotNewConfig() ) ); dialog->show();}void Part::slotNewConfig(){ // Apply settings here. A good policy is to check wether the setting has // changed before applying changes. // Watch File bool watchFile = KpdfSettings::watchFile(); if ( watchFile && m_watcher->isStopped() ) m_watcher->startScan(); if ( !watchFile && !m_watcher->isStopped() ) { m_dirtyHandler->stop(); m_watcher->stopScan(); } bool showSearch = KpdfSettings::showSearchBar(); if ( !m_searchWidget->isHidden() != showSearch ) m_searchWidget->setVisible( showSearch ); // Main View (pageView) Q3ScrollView::ScrollBarMode scrollBarMode = KpdfSettings::showScrollBars() ? Q3ScrollView::AlwaysOn : Q3ScrollView::AlwaysOff; if ( m_pageView->hScrollBarMode() != scrollBarMode ) { m_pageView->setHScrollBarMode( scrollBarMode ); m_pageView->setVScrollBarMode( scrollBarMode ); } // update document settings m_document->reparseConfig(); // update Main View and ThumbnailList contents // TODO do this only when changing KpdfSettings::renderMode() m_pageView->updateContents(); if ( KpdfSettings::showLeftPanel() && !m_thumbnailList->isHidden() ) m_thumbnailList->updateWidgets();}void Part::slotPrintPreview(){ if (m_document->pages() == 0) return; double width, height; int landscape, portrait; KPrinter printer; const KPDFPage *page; printer.setMinMax(1, m_document->pages()); printer.setPreviewOnly( true ); printer.setMargins(0, 0, 0, 0); // if some pages are landscape and others are not the most common win as kprinter does // not accept a per page setting landscape = 0; portrait = 0; for (uint i = 0; i < m_document->pages(); i++) { page = m_document->page(i); width = page->width(); height = page->height(); if (page->orientation() == 90 || page->orientation() == 270) qSwap(width, height); if (width > height) landscape++; else portrait++; } if (landscape > portrait) printer.setOption("orientation-requested", "4"); doPrint(printer);}void Part::slotShowMenu(const KPDFPage *page, const QPoint &point){ bool reallyShow = false; if (!m_actionsSearched) { // the quest for options_show_menubar KActionCollection *ac; KAction *act; if (factory()) { QList<KXMLGUIClient*> clients(factory()->clients()); for(int i = 0 ; (!m_showMenuBarAction || !m_showFullScreenAction) && i < clients.size(); ++i) { ac = clients.at(i)->actionCollection(); // show_menubar act = ac->action("options_show_menubar"); if (act && qobject_cast<KToggleAction*>(act)) m_showMenuBarAction = qobject_cast<KToggleAction*>(act); // fullscreen act = ac->action("fullscreen"); if (act && qobject_cast<KToggleFullScreenAction*>(act)) m_showFullScreenAction = qobject_cast<KToggleFullScreenAction*>(act); } } m_actionsSearched = true; } KMenu *popup = new KMenu( widget() ); QAction *toggleBookmark, *fitPageWidth; toggleBookmark = 0; fitPageWidth = 0; if (page) { popup->addTitle( i18n( "Page %1", page->number() + 1 ) ); if ( page->hasBookmark() ) toggleBookmark = popup->addAction( KIcon("bookmark"), i18n("Remove Bookmark") ); else toggleBookmark = popup->addAction( KIcon("bookmark_add"), i18n("Add Bookmark") ); if ( m_pageView->canFitPageWidth() ) fitPageWidth = popup->addAction( KIcon("viewmagfit"), i18n("Fit Width") ); //popup->insertItem( SmallIcon("pencil"), i18n("Edit"), 3 ); //popup->setItemEnabled( 3, false ); popup->addAction( m_prevBookmark ); popup->addAction( m_nextBookmark ); reallyShow = true; }/* //Albert says: I have not ported this as i don't see it does anything if ( d->mouseOnRect ) // and rect->objectType() == ObjectRect::Image ... { m_popup->insertItem( SmallIcon("filesave"), i18n("Save Image..."), 4 ); m_popup->setItemEnabled( 4, false );}*/ if ((m_showMenuBarAction && !m_showMenuBarAction->isChecked()) || (m_showFullScreenAction && m_showFullScreenAction->isChecked())) { popup->addTitle( i18n( "Tools" ) ); if (m_showMenuBarAction && !m_showMenuBarAction->isChecked()) popup->addAction(m_showMenuBarAction); if (m_showFullScreenAction && m_showFullScreenAction->isChecked()) popup->addAction(m_showFullScreenAction); reallyShow = true; } if (page && reallyShow) { QAction *res = popup->exec(point); if (res) { if (res == toggleBookmark) m_document->toggleBookmark( page->number() ); else if (res == fitPageWidth) m_pageView->fitPageWidth( page->number() ); } } delete popup;}void Part::slotShowProperties(){ PropertiesDialog *d = new PropertiesDialog(widget(), m_document); d->exec(); delete d;}void Part::slotShowEmbeddedFiles(){ EmbeddedFilesDialog *d = new EmbeddedFilesDialog(widget(), m_document); d->exec(); delete d;}void Part::slotShowPresentation(){ if ( !m_presentationWidget ) { m_presentationWidget = new PresentationWidget( widget(), m_document ); m_presentationWidget->setupActions( actionCollection() ); }}void Part::slotHidePresentation(){ if ( m_presentationWidget ) delete (PresentationWidget*) m_presentationWidget;}void Part::slotExportAs(QAction * act){ QList<QAction*> acts = m_exportAs->menu() ? m_exportAs->menu()->actions() : QList<QAction*>(); int id = acts.indexOf( act ); if ( ( id < 0 ) || ( id >= acts.count() ) ) return; QString filter = id == 0 ? "text/plain" : m_exportItems.at( id - 1 )->mime->name(); QString fileName = KFileDialog::getSaveFileName( url().isLocalFile() ? url().fileName() : QString::null, filter, widget() ); if ( !fileName.isEmpty() ) { bool saved = id == 0 ? m_document->exportToText( fileName ) : m_document->exportTo( fileName, m_exportItems.at( id - 1 )->mime ); if ( !saved ) KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) ); }}void Part::slotPrint(){ if (m_document->pages() == 0) return; double width, height; int landscape, portrait; KPrinter printer; const KPDFPage *page; printer.setPageSelection(KPrinter::ApplicationSide); printer.setMinMax(1, m_document->pages()); printer.setCurrentPage(m_document->currentPage()+1); printer.setMargins(0, 0, 0, 0); // if some pages are landscape and others are not the most common win as kprinter does // not accept a per page setting landscape = 0; portrait = 0; for (uint i = 0; i < m_document->pages(); i++) { page = m_document->page(i); width = page->width(); height = page->height(); if (page->orientation() == 90 || page->orientation() == 270) qSwap(width, height); if (width > height) landscape++; else portrait++; } if (landscape > portrait) printer.setOrientation(KPrinter::Landscape); if ( m_document->canConfigurePrinter() ) doPrint( printer ); else if (printer.setup(widget())) doPrint( printer );}void Part::doPrint(KPrinter &printer){ if (!m_document->isAllowed(KPDFDocument::AllowPrint)) { KMessageBox::error(widget(), i18n("Printing this document is not allowed.")); return; } if (!m_document->print(printer)) { KMessageBox::error(widget(), i18n("Could not print the document. Please report to bugs.kde.org")); }}void Part::restoreDocument(const KUrl &url, int page){ if (openURL(url)) goToPage(page);}void Part::saveDocumentRestoreInfo(KConfig* config){ config->writePathEntry( "URL", url().url() ); if (m_document->pages() > 0) config->writeEntry( "Page", m_document->currentPage() + 1 );}void Part::psTransformEnded(){ m_file = m_temporaryLocalFile; openFile();}/** BrowserExtension class*/BrowserExtension::BrowserExtension(Part* parent) : KParts::BrowserExtension( parent ){ emit enableAction("print", true); setURLDropHandlingEnabled(true);}void BrowserExtension::print(){ static_cast<Part*>(parent())->slotPrint();}#include "part.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -