Commit 0e290081 authored by Michel Ludwig's avatar Michel Ludwig

Initial commit of the 'ViewerInterface' and of a first implementation.

parent b9da827e
......@@ -100,6 +100,7 @@ install( FILES
interfaces/configinterface.h
interfaces/guiinterface.h
interfaces/printinterface.h
interfaces/viewerinterface.h
DESTINATION ${INCLUDE_INSTALL_DIR}/okular/interfaces COMPONENT Devel)
kde4_add_ui_files(okularcore_SRCS
......
......@@ -3073,6 +3073,12 @@ void Document::processSourceReference( const SourceReference * ref )
return;
}
bool handled = false;
emit(sourceReferenceActivated(absFileName, ref->row(), ref->column(), handled));
if(handled) {
return;
}
static QHash< int, QString > editors;
// init the editors table if empty (on first run, usually)
if ( editors.isEmpty() )
......
......@@ -730,6 +730,8 @@ class OKULAR_EXPORT Document : public QObject
*/
void formFieldChanged( Okular::FormField *formField );
void sourceReferenceActivated(const QString& absFileName, int line, int col, bool &handled);
private:
/// @cond PRIVATE
friend class DocumentPrivate;
......
/***************************************************************************
* Copyright (C) 2011 by Michel Ludwig <michel.ludwig@kdemail.net> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef _VIEWERINTERFACE_H_
#define _VIEWERINTERFACE_H_
#include <QString>
/**
* @short Abstract interface for controlling advanced features of a document viewer
*
* This interface can be used to control some more or less advanced features of a document
* viewer.
*/
class ViewerInterface
{
public:
virtual ~ViewerInterface() {}
/**
* Show the specified source location centrally in the viewer.
*/
virtual void showSourceLocation(const QString& fileName, int line, int column) = 0;
/**
* Allows to enable or disable the watch file mode
*/
virtual void setWatchFileModeEnabled(bool b) = 0;
// SIGNALS
/**
* The signal 'openSourceReference' is emitted whenever the user has triggered a source
* reference in the currently displayed document.
*/
void openSourceReference(const QString& absFileName, int line, int column);
};
Q_DECLARE_INTERFACE( ViewerInterface, "org.kde.viewerinterface/0.1" )
#endif
......@@ -83,6 +83,7 @@
#include "ui/guiutils.h"
#include "conf/preferencesdialog.h"
#include "settings.h"
#include "core/action.h"
#include "core/bookmarkmanager.h"
#include "core/document.h"
#include "core/generator.h"
......@@ -214,8 +215,12 @@ static Okular::Part::EmbedMode detectEmbedMode( QWidget *parentWidget, QObject *
{
if ( arg.type() == QVariant::String )
{
if ( arg.toString() == QLatin1String( "Print/Preview" ) )
if ( arg.toString() == QLatin1String( "Print/Preview" ) ) {
return Okular::Part::PrintPreviewMode;
}
else if ( arg.toString() == QLatin1String( "ViewerWidget" ) ) {
return Okular::Part::ViewerWidgetMode;
}
}
}
......@@ -367,6 +372,7 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
connect( m_document, SIGNAL(warning(QString,int)), m_pageView, SLOT(warningMessage(QString,int)) );
connect( m_document, SIGNAL(notice(QString,int)), m_pageView, SLOT(noticeMessage(QString,int)) );
connect( m_document, SIGNAL(formFieldChanged(Okular::FormField*)), m_pageView, SLOT(slotFormFieldChanged(Okular::FormField*)) );
connect( m_document, SIGNAL(sourceReferenceActivated(const QString&,int,int,bool&)), this, SLOT(slotHandleActivatedSourceReference(const QString&,int,int,bool&)) );
rightLayout->addWidget( m_pageView );
m_findBar = new FindBar( m_document, rightContainer );
rightLayout->addWidget( m_findBar );
......@@ -634,8 +640,18 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
updateViewActions();
m_sidebar->setSidebarVisibility( false );
if ( m_embedMode != PrintPreviewMode )
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 );
......@@ -713,6 +729,34 @@ KUrl Part::realUrl() const
return url();
}
// ViewerInterface
void Part::showSourceLocation(const QString& fileName, int line, int column)
{
QString u = "src:" + QString::number(line) + ' ' + fileName;
GotoAction action(QString(), u);
m_document->processAction(&action);
}
void Part::setWatchFileModeEnabled(bool b)
{
if (b && m_watcher->isStopped()) {
m_watcher->startScan();
}
else if(!b && !m_watcher->isStopped() )
{
m_dirtyHandler->stop();
m_watcher->stopScan();
}
}
void Part::slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool &handled)
{
emit(openSourceReference(absFileName, line, col));
if ( m_embedMode == Okular::Part::ViewerWidgetMode ) {
handled = true;
}
}
void Part::openUrlFromDocument(const KUrl &url)
{
......@@ -1725,14 +1769,7 @@ void Part::slotNewConfig()
// changed before applying changes.
// Watch File
bool watchFile = Okular::Settings::watchFile();
if ( watchFile && m_watcher->isStopped() )
m_watcher->startScan();
if ( !watchFile && !m_watcher->isStopped() )
{
m_dirtyHandler->stop();
m_watcher->stopScan();
}
setWatchFileModeEnabled(Okular::Settings::watchFile());
// Main View (pageView)
m_pageView->reparseConfig();
......
......@@ -24,6 +24,7 @@
#include "core/observer.h"
#include "core/document.h"
#include "kdocumentviewer.h"
#include "interfaces/viewerinterface.h"
#include <QtDBus/QtDBus>
......@@ -71,11 +72,12 @@ class ExportFormat;
* @author Wilco Greven <greven@kde.org>
* @version 0.2
*/
class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, public KDocumentViewer
class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, public KDocumentViewer, public ViewerInterface
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.okular")
Q_INTERFACES(KDocumentViewer)
Q_INTERFACES(ViewerInterface)
public:
enum EmbedMode
......@@ -83,7 +85,8 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
UnknownEmbedMode,
NativeShellMode, // embedded in the native Okular' shell
PrintPreviewMode, // embedded to show the print preview of a document
KHTMLPartMode // embedded in KHTML
KHTMLPartMode, // embedded in KHTML
ViewerWidgetMode, // the part acts as a widget that can display all kinds of documents
};
// Default constructor
......@@ -104,6 +107,9 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
KUrl realUrl() const;
void showSourceLocation(const QString& fileName, int line, int column);
void setWatchFileModeEnabled(bool b);
public slots: // dbus
Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page);
Q_SCRIPTABLE Q_NOREPLY void openDocument( const QString &doc );
......@@ -123,6 +129,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
signals:
void enablePrintAction(bool enable);
void openSourceReference(const QString& absFileName, int line, int column);
protected:
// reimplemented from KParts::ReadOnlyPart
......@@ -276,6 +283,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
private slots:
void slotGeneratorPreferences();
void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool &handled);
};
}
......
......@@ -179,6 +179,8 @@ public:
KActionCollection * actionCollection;
int setting_viewCols;
bool showMoveDestinationGraphically;
};
PageViewPrivate::PageViewPrivate( PageView *qq )
......@@ -283,6 +285,7 @@ PageView::PageView( QWidget *parent, Okular::Document *document )
d->actionCollection = 0;
d->aPageSizes=0;
d->setting_viewCols = Okular::Settings::viewColumns();
d->showMoveDestinationGraphically = false;
d->delayResizeEventTimer = new QTimer( this );
d->delayResizeEventTimer->setSingleShot( true );
......@@ -653,6 +656,11 @@ QPoint PageView::contentAreaPoint( const QPoint & pos ) const
return pos + contentAreaPosition();
}
void PageView::setShowMoveDestinationGraphically(bool b)
{
d->showMoveDestinationGraphically = b;
}
QString PageViewPrivate::selectedText() const
{
if ( pagesWithTextSelection.isEmpty() )
......@@ -938,6 +946,10 @@ void PageView::notifyViewportChanged( bool smoothMove )
if ( d->zoomMode != ZoomFixed )
updateZoomText();
if(viewport()) {
viewport()->repaint();
}
// since the page has moved below cursor, update it
updateCursor( contentAreaPosition() + viewport()->mapFromGlobal( QCursor::pos() ) );
}
......@@ -1218,7 +1230,11 @@ void PageView::paintEvent(QPaintEvent *pe)
pixmapPainter.setPen( Qt::blue );
pixmapPainter.drawRect( contentsRect );
}
if ( d->showMoveDestinationGraphically )
{
pixmapPainter.setPen( Qt::red );
pixmapPainter.drawLine(0, d->viewportMoveDest.y(), viewport()->width(), d->viewportMoveDest.y());
}
// finish painting and draw contents
pixmapPainter.end();
screenPainter.drawPixmap( contentsRect.left(), contentsRect.top(), doubleBuffer );
......@@ -1243,6 +1259,11 @@ void PageView::paintEvent(QPaintEvent *pe)
screenPainter.setPen( Qt::red );
screenPainter.drawRect( contentsRect );
}
if ( d->showMoveDestinationGraphically )
{
screenPainter.setPen( Qt::red );
screenPainter.drawLine(0, d->viewportMoveDest.y(), viewport()->width(), d->viewportMoveDest.y());
}
}
}
}
......
......@@ -98,6 +98,8 @@ Q_OBJECT
QPoint contentAreaPosition() const;
QPoint contentAreaPoint( const QPoint & pos ) const;
void setShowMoveDestinationGraphically(bool b);
public slots:
void errorMessage( const QString & message, int duration = -1 )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment