Commit ba200685 authored by Albert Astals Cid's avatar Albert Astals Cid

Support for show/hide menubar in rmb menu, different from HEAD so that supports Konqueror too

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=368536
parent adaa58f1
......@@ -47,13 +47,13 @@ More items (first items will enter 'In progress list' first):
-> automatic online dictionaries / translators (BR80338)
-> add OCR for building TextPages out of pure graphical (aka scanned) pages
-> merge head copyright headers (by albert)
-> merge head support for show menubar in rmb (by albert)
-> wrong zoom buttons order (BR74248) (check consistancy with kdvi/kghostview/.. (not konq))
-> rotate the whole document / individual pages
-> fullscreen pdf view (presentations-like) with some gfx tools
-> incremental zoom with fast-refresh (tested but flickering!) or contour tracing
Done (newest feature comes firts):
-> ADD: Support for show/hide menubar in rmb menu, different from HEAD so that supports Konqueror too (Albert)
-> ADD: Watch File option (Albert)
-> ADD: import Marco Martin's "another kpdf icon" (kde-look: 16146) (Albert)
-> ADD: dynamic zoom with mid mouse button (click and drag up-down to zoom in-out)
......
......@@ -44,6 +44,9 @@
#include <knuminput.h>
#include <kiconloader.h>
#include <kio/netaccess.h>
#include <kpopupmenu.h>
#include <kxmlguiclient.h>
#include <kxmlguifactory.h>
#include "GlobalParams.h"
......@@ -67,7 +70,7 @@ unsigned int Part::m_count = 0;
Part::Part(QWidget *parentWidget, const char *widgetName,
QObject *parent, const char *name,
const QStringList & /*args*/ )
: DCOPObject("kpdf"), KParts::ReadOnlyPart(parent, name)
: DCOPObject("kpdf"), KParts::ReadOnlyPart(parent, name), m_showMenuBarAction(0), m_showMenuBarActionSearched(false)
{
// create browser extension (for printing when embedded into browser)
new BrowserExtension(this);
......@@ -129,7 +132,7 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
m_pageView = new PageView( m_splitter, m_document );
m_pageView->setFocus(); //usability setting
connect( m_pageView, SIGNAL( urlDropped( const KURL& ) ), SLOT( openURL( const KURL & )));
//connect(m_pageView, SIGNAL( rightClick() ), this, SIGNAL( rightClick() ));
connect(m_pageView, SIGNAL( rightClick(const KPDFPage *, const QPoint &) ), this, SLOT( slotShowMenu(const KPDFPage *, const QPoint &) ));
// add document observers
m_document->addObserver( this );
......@@ -498,6 +501,74 @@ void Part::slotPrintPreview()
doPrint(printer);
}
void Part::slotShowMenu(const KPDFPage *page, const QPoint &point)
{
if (!m_showMenuBarActionSearched)
{
// the quest for options_show_menubar
KXMLGUIClient *client;
KActionCollection *ac;
KActionPtrList::const_iterator it, end, begin;
KActionPtrList actions;
QPtrList<KXMLGUIClient> clients(factory()->clients());
QPtrListIterator<KXMLGUIClient> clientsIt( clients );
for( ; !m_showMenuBarAction && clientsIt.current(); ++clientsIt)
{
client = clientsIt.current();
ac = client->actionCollection();
actions = ac->actions();
end = actions.end();
begin = actions.begin();
for ( it = begin; it != end; ++it )
if (QString((*it)->name()) == "options_show_menubar") m_showMenuBarAction = (KToggleAction*)(*it);
}
m_showMenuBarActionSearched = true;
}
KPopupMenu *popup = new KPopupMenu( widget(), "rmb popup" );
if (page)
{
popup->insertTitle( i18n( "Page %1" ).arg( page->number() + 1 ) );
if ( page->attributes() & KPDFPage::Bookmark )
popup->insertItem( SmallIcon("bookmark"), i18n("Remove Bookmark"), 1 );
else
popup->insertItem( SmallIcon("bookmark_add"), i18n("Add Bookmark"), 1 );
popup->insertItem( SmallIcon("viewmagfit"), i18n("Fit Width"), 2 );
popup->insertItem( SmallIcon("pencil"), i18n("Edit"), 3 );
popup->setItemEnabled( 3, false );
}
/*
//Albert says: I have not ported this as i don't see it does anything
if ( d->mouseOnActiveRect )
{
m_popup->insertItem( SmallIcon("filesave"), i18n("Save Image ..."), 4 );
m_popup->setItemEnabled( 4, false );
}*/
if (m_showMenuBarAction)
{
popup->insertTitle( i18n( "Tools" ) );
m_showMenuBarAction->plug(popup);
}
switch ( popup->exec(point) )
{
case 1:
m_document->toggleBookmark( page->number() );
break;
case 2:// zoom: Fit Width, columns: 1. setActions + relayout + setPage + update
m_pageView->setZoomFitWidth();
m_document->setCurrentPage( page->number() );
break;
case 3: // ToDO switch to edit mode
m_pageView->slotSetMouseDraw();
break;
}
delete popup;
}
void Part::slotPrint()
{
if (m_document->pages() == 0) return;
......
......@@ -95,6 +95,7 @@ protected slots:
void slotPreferences();
void slotNewConfig();
void slotPrintPreview();
void slotShowMenu(const KPDFPage *page, const QPoint &point);
// can be connected to widget elements
void updateActions();
void enableTOC(bool enable);
......@@ -136,6 +137,8 @@ private:
KAction *m_find;
KAction *m_findNext;
KToggleAction* m_watchFile;
KToggleAction* m_showMenuBarAction;
bool m_showMenuBarActionSearched;
};
......
......@@ -48,13 +48,12 @@ Shell::Shell()
// this routine will find and load our Part. it finds the Part by
// name which is a bad idea usually.. but it's alright in this
// case since our Part is made for this Shell
KLibFactory *factory = KLibLoader::self()->factory("libkpdfpart");
KParts::Factory *factory = (KParts::Factory *) KLibLoader::self()->factory("libkpdfpart");
if (factory)
{
// now that the Part is loaded, we cast it to a Part to get
// our hands on it
m_part = static_cast<KParts::ReadOnlyPart*>(
factory->create(this, "kpdf_part", "KParts::ReadOnlyPart"));
m_part = (KParts::ReadOnlyPart*) factory->createPart(this, "kpdf_part", this, 0, "KParts::ReadOnlyPart");
if (m_part)
{
// then, setup our actions
......@@ -74,10 +73,8 @@ Shell::Shell()
m_part = 0;
return;
}
//FIXME READD: connect( m_part, SIGNAL( rightClick() ),SLOT( slotRMBClick() ) );
connect( this, SIGNAL( restoreDocument(const KURL &, int) ),m_part, SLOT( restoreDocument(const KURL &, int)));
connect( this, SIGNAL( saveDocumentRestoreInfo(KConfig*) ), m_part, SLOT( saveDocumentRestoreInfo(KConfig*)));
readSettings();
}
......@@ -124,13 +121,10 @@ Shell::setupActions()
setStandardToolBarMenuEnabled(true);
m_showMenuBarAction = KStdAction::showMenubar( this, SLOT( slotShowMenubar() ), actionCollection(), "options_show_menubar" );
KGlobal::config()->setGroup("MainWindow");
m_showMenuBarAction->setChecked(KGlobal::config()->readBoolEntry( "MenuBar", true ));
KStdAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection());
m_fullScreenAction = KStdAction::fullScreen( this, SLOT( slotUpdateFullScreen() ), actionCollection(), this );
m_popup = new KPopupMenu( this, "rmb popup" );
m_popup->insertTitle( i18n( "Full Screen Options" ) );
m_fullScreenAction->plug( m_popup );
m_popup->insertTitle( i18n( "Tools" ) );
m_showMenuBarAction->plug( m_popup );
}
void
......@@ -227,10 +221,4 @@ void Shell::slotUpdateFullScreen()
}
}
void Shell::slotRMBClick()
{
m_popup->exec( QCursor::pos() );
}
// vim:ts=2:sw=2:tw=78:et
......@@ -74,8 +74,7 @@ namespace KPDF
void optionsConfigureToolbars();
void applyNewToolbarConfig();
void slotUpdateFullScreen();
void slotRMBClick();
void slotShowMenubar();
void slotShowMenubar();
public slots:
void openURL( const KURL & url );
......@@ -92,9 +91,8 @@ namespace KPDF
KParts::ReadOnlyPart* m_part;
KRecentFilesAction* m_recent;
KToggleAction* m_fullScreenAction;
KToggleAction* m_showMenuBarAction;
bool m_isFullScreen;
KPopupMenu* m_popup;
KToggleAction *m_showMenuBarAction;
};
}
......
......@@ -191,6 +191,20 @@ void PageView::setupActions( KActionCollection * ac )
sd->setShortcut( "Shift+Down" );
}
void PageView::setZoomFitWidth()
{
d->zoomMode = ZoomFitWidth;
Settings::setViewColumns( 1 );
d->aZoomFitWidth->setChecked( true );
d->aZoomFitPage->setChecked( false );
d->aZoomFitText->setChecked( false );
d->aViewTwoPages->setChecked( false );
viewport()->setUpdatesEnabled( false );
slotRelayoutPages();
viewport()->setUpdatesEnabled( true );
updateContents();
}
//BEGIN KPDFDocumentObserver inherited methods
void PageView::notifyPixmapChanged( int pageNumber )
......@@ -576,8 +590,6 @@ void PageView::contentsMousePressEvent( QMouseEvent * e )
if ( !d->mouseOnLink )
setCursor( sizeAllCursor );
}
else if ( e->button() & RightButton )
emit rightClick();
break;
case MouseZoom:
......@@ -624,48 +636,10 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e )
d->document->setCurrentPage( pageItem->pageNumber() );
}
}
else if ( rightButton && pageItem )
else if ( rightButton )
{
// if over a page display a popup menu
const KPDFPage * kpdfPage = pageItem->page();
KPopupMenu * m_popup = new KPopupMenu( this, "rmb popup" );
m_popup->insertTitle( i18n( "Page %1" ).arg( kpdfPage->number() + 1 ) );
if ( kpdfPage->attributes() & KPDFPage::Bookmark )
m_popup->insertItem( SmallIcon("bookmark"), i18n("Remove Bookmark"), 1 );
else
m_popup->insertItem( SmallIcon("bookmark_add"), i18n("Add Bookmark"), 1 );
m_popup->insertItem( SmallIcon("viewmagfit"), i18n("Fit Page"), 2 );
m_popup->insertItem( SmallIcon("pencil"), i18n("Edit"), 3 );
m_popup->setItemEnabled( 3, false );
if ( d->mouseOnActiveRect )
{
m_popup->insertItem( SmallIcon("filesave"), i18n("Save Image ..."), 4 );
m_popup->setItemEnabled( 4, false );
}
switch ( m_popup->exec(e->globalPos()) )
{
case 1:
d->document->toggleBookmark( kpdfPage->number() );
break;
case 2:
// zoom: Fit Width, columns: 1. setActions + relayout + setPage + update
d->zoomMode = ZoomFitWidth;
Settings::setViewColumns( 1 );
d->aZoomFitWidth->setChecked( true );
d->aZoomFitPage->setChecked( false );
d->aZoomFitText->setChecked( false );
d->aViewTwoPages->setChecked( false );
viewport()->setUpdatesEnabled( false );
slotRelayoutPages();
viewport()->setUpdatesEnabled( true );
updateContents();
d->document->setCurrentPage( kpdfPage->number() );
break;
case 3: // ToDO switch to edit mode
slotSetMouseDraw();
break;
}
delete m_popup;
if (pageItem) emit rightClick(pageItem->page(), e->globalPos());
else emit rightClick(0, e->globalPos());
}
// reset start position
d->mouseStartPos = QPoint();
......
......@@ -51,6 +51,9 @@ class PageView : public QScrollView, public KPDFDocumentObserver
// create actions that interact with this widget
void setupActions( KActionCollection * collection );
// used from RMB menu
void setZoomFitWidth();
// inherited from KPDFDocumentObserver
uint observerId() const { return PAGEVIEW_ID; }
void notifyPixmapChanged( int pageNumber );
......@@ -58,9 +61,12 @@ class PageView : public QScrollView, public KPDFDocumentObserver
void pageSetup( const QValueVector<KPDFPage*> & pages, bool documentChanged );
void pageSetCurrent( int pageNumber, const QRect & viewport );
public slots:
void slotSetMouseDraw();
signals:
void urlDropped( const KURL& );
void rightClick();
void rightClick(const KPDFPage *, const QPoint &);
protected:
// main draw loop, draws pageViews on viewport
......@@ -117,7 +123,6 @@ class PageView : public QScrollView, public KPDFDocumentObserver
void slotSetMouseNormal();
void slotSetMouseZoom();
void slotSetMouseSelect();
void slotSetMouseDraw();
void slotScrollUp();
void slotScrollDown();
};
......
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