Commit 6224796d authored by Enrico Ros's avatar Enrico Ros

Using QToolBox for left panels. Beginning to work on Continous mode.

PageWidget class is now PageView. Added actions for selecting page layouts.

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=348865
parent 2e57c7c5
......@@ -30,8 +30,8 @@
#include "page.h"
PageWidget::PageWidget( QWidget *parent, KPDFDocument *document )
: QScrollView( parent, "KPDF::pageWidget", WRepaintNoErase | WStaticContents ),
PageView::PageView( QWidget *parent, KPDFDocument *document )
: QScrollView( parent, "KPDF::pageView", WRepaintNoErase | WStaticContents ),
m_document( document ), m_page( 0 ),
m_mouseMode( MouseNormal ), m_mouseOnLink( false ),
m_zoomMode( FixedFactor ), m_zoomFactor( 1.0 ),
......@@ -51,7 +51,7 @@ PageWidget::PageWidget( QWidget *parent, KPDFDocument *document )
// connect(...);
}
void PageWidget::setupActions( KActionCollection * ac, KConfigGroup * config )
void PageView::setupActions( KActionCollection * ac, KConfigGroup * config )
{
// Zoom actions ( higher scales consumes lots of memory! )
const double zoomValue[10] = { 0.125, 0.25, 0.333, 0.5, 0.667, 0.75, 1, 1.25, 1.50, 2 };
......@@ -83,6 +83,19 @@ void PageWidget::setupActions( KActionCollection * ac, KConfigGroup * config )
m_aZoomFitPage = new KToggleAction( i18n("Fit to &Page"), "viewmagfit", 0, ac, "zoom_fit_page" );
connect( m_aZoomFitPage, SIGNAL( toggled( bool ) ), SLOT( slotFitToPageToggled( bool ) ) );
// View-Layout actions
KToggleAction * vs = new KToggleAction( i18n("Single Page"), "view_remove", 0, this, SLOT( slotSetViewSingle() ), ac, "view_single" );
vs->setExclusiveGroup("ViewLayout");
vs->setChecked( true );
KToggleAction * vd = new KToggleAction( i18n("Two Pages"), "view_left_right", 0, this, SLOT( slotSetViewDouble() ), ac, "view_double" );
vd->setExclusiveGroup("ViewLayout");
vd->setEnabled( false ); // implement feature before removing this line
KToggleAction * vc = new KToggleAction( i18n("Continous"), "view_text", 0, this, SLOT( slotSetViewContinous() ), ac, "view_continous" );
vc->setExclusiveGroup("ViewLayout");
vc->setEnabled( false ); // implement feature before removing this line
// Mouse-Mode actions
KToggleAction * mn = new KToggleAction( i18n("Normal"), "mouse", 0, this, SLOT( slotSetMouseNormal() ), ac, "mouse_drag" );
mn->setExclusiveGroup("MouseType");
......@@ -90,9 +103,11 @@ void PageWidget::setupActions( KActionCollection * ac, KConfigGroup * config )
KToggleAction * ms = new KToggleAction( i18n("Select"), "frame_edit", 0, this, SLOT( slotSetMouseSelect() ), ac, "mouse_select" );
ms->setExclusiveGroup("MouseType");
ms->setEnabled( false ); // implement feature before removing this line
KToggleAction * md = new KToggleAction( i18n("Draw"), "edit", 0, this, SLOT( slotSetMouseDraw() ), ac, "mouse_draw" );
md->setExclusiveGroup("MouseType");
md->setEnabled( false ); // implement feature before removing this line
// Other actions
KToggleAction * ss = new KToggleAction( i18n( "Show &Scrollbars" ), 0, ac, "show_scrollbars" );
......@@ -103,14 +118,14 @@ void PageWidget::setupActions( KActionCollection * ac, KConfigGroup * config )
slotToggleScrollBars( ss->isChecked() );
}
void PageWidget::saveSettings( KConfigGroup * config )
void PageView::saveSettings( KConfigGroup * config )
{
config->writeEntry( "ShowScrollBars", hScrollBarMode() == AlwaysOn );
}
//BEGIN KPDFDocumentObserver inherited methods
void PageWidget::pageSetup( const QValueVector<KPDFPage*> & pages, bool documentChanged )
void PageView::pageSetup( const QValueVector<KPDFPage*> & pages, bool documentChanged )
{
//TODO
documentChanged = false;
......@@ -128,7 +143,7 @@ documentChanged = false;
m_pages.push_back( (*pageIt)->number() );
}
void PageWidget::pageSetCurrent( int pageNumber, float position )
void PageView::pageSetCurrent( int pageNumber, float position )
{
// select next page
m_vectorIndex = 0;
......@@ -153,7 +168,7 @@ void PageWidget::pageSetCurrent( int pageNumber, float position )
verticalScrollBar()->setValue( (int)(position * verticalScrollBar()->maxValue()) );
}
void PageWidget::notifyPixmapChanged( int pageNumber )
void PageView::notifyPixmapChanged( int pageNumber )
{
// check if it's the preview we're waiting for and update it
if ( m_page && (int)m_page->number() == pageNumber )
......@@ -162,7 +177,7 @@ void PageWidget::notifyPixmapChanged( int pageNumber )
//END KPDFDocumentObserver inherited methods
//BEGIN widget events
void PageWidget::contentsMousePressEvent( QMouseEvent * e )
void PageView::contentsMousePressEvent( QMouseEvent * e )
{
switch ( m_mouseMode )
{
......@@ -192,7 +207,7 @@ void PageWidget::contentsMousePressEvent( QMouseEvent * e )
}
}
void PageWidget::contentsMouseReleaseEvent( QMouseEvent * )
void PageView::contentsMouseReleaseEvent( QMouseEvent * )
{
switch ( m_mouseMode )
{
......@@ -216,7 +231,7 @@ void PageWidget::contentsMouseReleaseEvent( QMouseEvent * )
}
}
void PageWidget::contentsMouseMoveEvent( QMouseEvent * e )
void PageView::contentsMouseMoveEvent( QMouseEvent * e )
{
switch ( m_mouseMode )
{
......@@ -252,7 +267,7 @@ void PageWidget::contentsMouseMoveEvent( QMouseEvent * e )
}
}
void PageWidget::viewportResizeEvent( QResizeEvent * )
void PageView::viewportResizeEvent( QResizeEvent * )
{
// start a timer that will refresh the pixmap after 0.5s
if ( !m_delayTimer )
......@@ -265,7 +280,7 @@ void PageWidget::viewportResizeEvent( QResizeEvent * )
//slotUpdateView( false );
}
void PageWidget::keyPressEvent( QKeyEvent * e )
void PageView::keyPressEvent( QKeyEvent * e )
{
switch ( e->key() )
{
......@@ -298,7 +313,7 @@ void PageWidget::keyPressEvent( QKeyEvent * e )
e->accept();
}
void PageWidget::wheelEvent( QWheelEvent *e )
void PageView::wheelEvent( QWheelEvent *e )
{
int delta = e->delta();
e->accept();
......@@ -316,19 +331,19 @@ void PageWidget::wheelEvent( QWheelEvent *e )
QScrollView::wheelEvent( e );
}
void PageWidget::dragEnterEvent( QDragEnterEvent * ev )
void PageView::dragEnterEvent( QDragEnterEvent * ev )
{
ev->accept();
}
void PageWidget::dropEvent( QDropEvent * ev )
void PageView::dropEvent( QDropEvent * ev )
{
KURL::List lst;
if ( KURLDrag::decode( ev, lst ) )
emit urlDropped( lst.first() );
}
void PageWidget::drawContents( QPainter *p, int clipx, int clipy, int clipw, int cliph )
void PageView::drawContents( QPainter *p, int clipx, int clipy, int clipw, int cliph )
{
QColor bc( paletteBackgroundColor() /*KGlobalSettings::calculateAlternateBackgroundColor( KGlobalSettings::baseColor() )*/ );
if ( m_page )
......@@ -385,7 +400,7 @@ void PageWidget::drawContents( QPainter *p, int clipx, int clipy, int clipw, int
//END widget events
//BEGIN internal SLOTS
void PageWidget::slotZoom( const QString & nz )
void PageView::slotZoom( const QString & nz )
{
if ( nz == i18n("Fit Width") )
{
......@@ -413,7 +428,7 @@ void PageWidget::slotZoom( const QString & nz )
}
}
void PageWidget::slotZoomIn()
void PageView::slotZoomIn()
{
if ( m_zoomFactor >= 4.0 )
return;
......@@ -427,7 +442,7 @@ void PageWidget::slotZoomIn()
m_aZoomFitPage->setChecked( false );
}
void PageWidget::slotZoomOut()
void PageView::slotZoomOut()
{
if ( m_zoomFactor <= 0.125 )
return;
......@@ -441,42 +456,54 @@ void PageWidget::slotZoomOut()
m_aZoomFitPage->setChecked( false );
}
void PageWidget::slotFitToWidthToggled( bool on )
void PageView::slotFitToWidthToggled( bool on )
{
m_zoomMode = on ? FitWidth : FixedFactor;
slotUpdateView();
m_aZoomFitPage->setChecked( false );
}
void PageWidget::slotFitToPageToggled( bool on )
void PageView::slotFitToPageToggled( bool on )
{
m_zoomMode = on ? FitPage : FixedFactor;
slotUpdateView();
m_aZoomFitWidth->setChecked( false );
}
void PageWidget::slotSetMouseNormal()
void PageView::slotSetViewSingle()
{ //TODO this
}
void PageView::slotSetViewDouble()
{ //TODO this
}
void PageView::slotSetViewContinous()
{ //TODO this
}
void PageView::slotSetMouseNormal()
{
m_mouseMode = MouseNormal;
}
void PageWidget::slotSetMouseSelect()
void PageView::slotSetMouseSelect()
{
m_mouseMode = MouseSelection;
}
void PageWidget::slotSetMouseDraw()
void PageView::slotSetMouseDraw()
{
m_mouseMode = MouseEdit;
}
void PageWidget::slotToggleScrollBars( bool on )
void PageView::slotToggleScrollBars( bool on )
{
setHScrollBarMode( on ? AlwaysOn : AlwaysOff );
setVScrollBarMode( on ? AlwaysOn : AlwaysOff );
}
void PageWidget::slotUpdateView( bool repaint )
void PageView::slotUpdateView( bool repaint )
{ //TODO ASYNC autogeneration!
if ( !m_page )
{
......@@ -510,17 +537,17 @@ void PageWidget::slotUpdateView( bool repaint )
}
//END internal SLOTS
bool PageWidget::atTop() const
bool PageView::atTop() const
{
return verticalScrollBar()->value() == verticalScrollBar()->minValue();
}
bool PageWidget::atBottom() const
bool PageView::atBottom() const
{
return verticalScrollBar()->value() == verticalScrollBar()->maxValue();
}
void PageWidget::scrollUp()
void PageView::scrollUp()
{
if( atTop() && m_vectorIndex > 0 )
// go to the bottom of previous page
......@@ -533,7 +560,7 @@ void PageWidget::scrollUp()
}
}
void PageWidget::scrollDown()
void PageView::scrollDown()
{
if( atBottom() && m_vectorIndex < (int)m_pages.count() - 1 )
// go to the top of previous page
......
......@@ -12,8 +12,8 @@
* (at your option) any later version. *
***************************************************************************/
#ifndef _KPDF_PAGEWIDGET_H_
#define _KPDF_PAGEWIDGET_H_
#ifndef _KPDF_PAGEVIEW_H_
#define _KPDF_PAGEVIEW_H_
#include <qscrollview.h>
#include <qvaluevector.h>
......@@ -26,13 +26,40 @@ class KURL;
class KActionCollection;
class KConfigGroup;
class PageWidget : public QWidget
{
public:
PageWidget(QWidget *parent, const KPDFPage *page);
// resize / select commands
int setThumbnailWidth(int width);
void setSelected(bool selected);
// query methods
int pageNumber() const;
int previewWidth() const;
int previewHeight() const;
protected:
void paintEvent(QPaintEvent *);
private:
const KPDFPage *m_page;
uint m_previewWidth;
uint m_previewHeight;
bool m_selected;
uint m_labelNumber;
uint m_labelHeight;
uint m_labelWidth;
};
class PageWidget : public QScrollView, public KPDFDocumentObserver
class PageView : public QScrollView, public KPDFDocumentObserver
{
Q_OBJECT
public:
PageWidget( QWidget *parent, KPDFDocument *document );
PageView( QWidget *parent, KPDFDocument *document );
// create actions that interact with this widget
uint observerId() { return PAGEWIDGET_ID; }
......@@ -62,6 +89,9 @@ private slots:
void slotZoomOut();
void slotFitToWidthToggled( bool );
void slotFitToPageToggled( bool );
void slotSetViewSingle();
void slotSetViewDouble();
void slotSetViewContinous();
void slotSetMouseNormal();
void slotSetMouseSelect();
void slotSetMouseDraw();
......
......@@ -26,6 +26,7 @@
#include <qlayout.h>
#include <qlabel.h>
#include <qvbox.h>
#include <qtoolbox.h>
#include <qpushbutton.h>
#include <kaction.h>
......@@ -82,28 +83,42 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
document = new KPDFDocument();
connect( document, SIGNAL( pageChanged() ), this, SLOT( updateActions() ) );
// build widgets
// widgets: [] splitter []
m_splitter = new QSplitter( parentWidget, widgetName );
m_splitter->setOpaqueResize( true );
setWidget( m_splitter );
QVBox * leftVBox = new QVBox( m_splitter );
leftVBox->setMaximumWidth( 150 );
leftVBox->setMinimumWidth( 50 );
// widgets: [left toolbox] | []
QToolBox * toolBox = new QToolBox( m_splitter );
toolBox->setMinimumWidth( 60 );
toolBox->setMaximumWidth( 200 );
new QPushButton( QIconSet(SmallIcon("thumbnail")), "only a", leftVBox );
new QPushButton( QIconSet(SmallIcon("bookmark")), "layout", leftVBox );
new QPushButton( QIconSet(SmallIcon("filter")), "test", leftVBox );
QFrame * tocFrame = new QFrame( toolBox );
toolBox->addItem( tocFrame, QIconSet(SmallIcon("text_left")), i18n("Contents") );
m_searchWidget = new SearchWidget( leftVBox, document );
QVBox * thumbsBox = new ThumbnailsBox( toolBox );
m_thumbnailList = new ThumbnailList( thumbsBox, document );
m_searchWidget = new SearchWidget( thumbsBox, document );
toolBox->addItem( thumbsBox, QIconSet(SmallIcon("thumbnail")), i18n("Thumbnails") );
toolBox->setCurrentItem( thumbsBox );
m_thumbnailList = new ThumbnailList( leftVBox, document );
document->addObserver( m_thumbnailList );
QFrame * bookmarksFrame = new QFrame( toolBox );
toolBox->addItem( bookmarksFrame, QIconSet(SmallIcon("bookmark")), i18n("Bookmarks") );
QFrame * editFrame = new QFrame( toolBox );
toolBox->addItem( editFrame, QIconSet(SmallIcon("favorites")), i18n("Edited Chunks") );
QFrame * moreFrame = new QFrame( toolBox );
toolBox->addItem( moreFrame, QIconSet(SmallIcon("fork")), i18n("More stuff..") );
m_pageWidget = new PageWidget( m_splitter, document );
connect( m_pageWidget, SIGNAL( urlDropped( const KURL& ) ), SLOT( openURL( const KURL & )));
//connect(m _pageWidget, SIGNAL( rightClick() ), this, SIGNAL( rightClick() ));
document->addObserver( m_pageWidget );
// widgets: [] | [right 'pageView']
m_pageView = new PageView( m_splitter, document );
connect( m_pageView, SIGNAL( urlDropped( const KURL& ) ), SLOT( openURL( const KURL & )));
//connect(m_pageView, SIGNAL( rightClick() ), this, SIGNAL( rightClick() ));
// add document observers
document->addObserver( m_thumbnailList );
document->addObserver( m_pageView );
// ACTIONS
KActionCollection * ac = actionCollection();
......@@ -137,7 +152,7 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
// attach the actions of the 2 children widgets too
KConfigGroup settings( KPDFPartFactory::instance()->config(), "General" );
m_pageWidget->setupActions( ac, &settings );
m_pageView->setupActions( ac, &settings );
m_searchWidget->setupActions( ac, &settings );
m_thumbnailList->setupActions( ac, &settings );
......@@ -152,7 +167,7 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
Part::~Part()
{
KConfigGroup settings( KPDFPartFactory::instance()->config(), "General" );
m_pageWidget->saveSettings( &settings );
m_pageView->saveSettings( &settings );
m_searchWidget->saveSettings( &settings );
m_thumbnailList->saveSettings( &settings );
settings.writeEntry( "SplitterSizes", m_splitter->sizes() );
......@@ -244,7 +259,7 @@ public:
void Part::slotGoToPage()
{
KPDFGotoPageDialog pageDialog( m_pageWidget, document->currentPage() + 1, document->pages() );
KPDFGotoPageDialog pageDialog( m_pageView, document->currentPage() + 1, document->pages() );
if ( pageDialog.exec() == QDialog::Accepted )
document->slotSetCurrentPage( pageDialog.getPage() - 1 );
}
......
......@@ -33,7 +33,7 @@ class LinkAction;
class LinkDest;
class ThumbnailList;
class PageWidget;
class PageView;
class SearchWidget;
class KPDFDocument;
......@@ -106,7 +106,7 @@ namespace KPDF
// main widgets
QSplitter *m_splitter;
ThumbnailList *m_thumbnailList;
PageWidget *m_pageWidget;
PageView *m_pageView;
SearchWidget *m_searchWidget;
// static instances counter
......
......@@ -42,6 +42,10 @@
<!--Action name="zoom_fit_width"/-->
<!--Action name="zoom_fit_page"/-->
<Separator/>
<Action name="view_single"/>
<Action name="view_double"/>
<Action name="view_continous"/>
<Separator/>
<Action name="mouse_drag"/>
<Action name="mouse_select"/>
<Action name="mouse_draw"/>
......
......@@ -29,14 +29,14 @@ SearchWidget::SearchWidget( QWidget * parent, KPDFDocument * document )
setMargin( 4 );
// clear button
KToolBarButton * clear = new KToolBarButton( SmallIcon("locationbar_erase"), 1, this );
QToolTip::add( clear, i18n( "Clear filter" ) );
KToolBarButton * m_clearButton = new KToolBarButton( SmallIcon("locationbar_erase"), 1, this );
QToolTip::add( m_clearButton, i18n( "Clear filter" ) );
// line edit
m_lineEdit = new KLineEdit( this );
m_lineEdit->setFrame( QFrame::Sunken );
connect( m_lineEdit, SIGNAL(textChanged(const QString &)), SLOT(slotTextChanged(const QString &)) );
connect( clear, SIGNAL(clicked()), m_lineEdit, SLOT(clear()) );
connect( m_clearButton, SIGNAL(clicked()), m_lineEdit, SLOT(clear()) );
QToolTip::add( m_lineEdit, i18n( "Enter at least 3 letters to filter pages" ) );
// change case button and menu
......@@ -49,7 +49,7 @@ SearchWidget::SearchWidget( QWidget * parent, KPDFDocument * document )
search->setPopup( m_caseMenu );
*/
int sideLength = m_lineEdit->sizeHint().height();
clear->setMinimumSize( QSize( sideLength, sideLength ) );
m_clearButton->setMinimumSize( QSize( sideLength, sideLength ) );
// search->setMinimumSize( QSize( sideLength, sideLength ) );
}
......
......@@ -40,19 +40,12 @@ ThumbnailList::ThumbnailList(QWidget *parent, KPDFDocument *document)
connect( this, SIGNAL(contentsMoving(int, int)), this, SLOT(slotRequestPixmaps(int, int)) );
}
void ThumbnailList::setupActions( KActionCollection * ac, KConfigGroup * config )
void ThumbnailList::setupActions( KActionCollection * /*ac*/, KConfigGroup * /*config*/ )
{
KToggleAction * show = new KToggleAction( i18n( "Show &Page List" ), 0, ac, "show_thumbnails" );
show->setCheckedState(i18n("Hide &Page List"));
connect( show, SIGNAL( toggled( bool ) ), SLOT( setShown( bool ) ) );
show->setChecked( config->readBoolEntry( "ShowPageList", true ) );
setShown( show->isChecked() );
}
void ThumbnailList::saveSettings( KConfigGroup * config )
void ThumbnailList::saveSettings( KConfigGroup * /*config*/ )
{
config->writeEntry( "ShowPageList", isShown() );
}
//BEGIN KPDFDocumentObserver inherited methods
......@@ -75,6 +68,12 @@ documentChanged = false;
return;
}
//FIXME change this quick fix (lines that follows). Check if filtering:
bool skipCheck = true;
for ( uint i = 0; i < pages.count(); i++ )
if ( pages[i]->isHilighted() )
skipCheck = false;
// generate Thumbnails for the given set of pages
Thumbnail *t;
int width = clipper()->width(),
......@@ -82,7 +81,7 @@ documentChanged = false;
QValueVector<KPDFPage*>::const_iterator pageIt = pages.begin();
QValueVector<KPDFPage*>::const_iterator pageEnd = pages.end();
for (; pageIt != pageEnd ; ++pageIt)
if ( (*pageIt)->isHilighted() ) {
if ( skipCheck || (*pageIt)->isHilighted() ) {
t = new Thumbnail( viewport(), *pageIt );
// add to the scrollview
addChild( t, 0, totalHeight );
......@@ -263,4 +262,16 @@ void ThumbnailList::requestPixmaps( int delayMs )
m_delayTimer->start( delayMs, true );
}
/** class ThumbnailsBox **/
ThumbnailsBox::ThumbnailsBox( QWidget * parent ) : QVBox( parent )
{
}
QSize ThumbnailsBox::sizeHint() const
{
return QSize();
}
#include "thumbnaillist.moc"
......@@ -12,6 +12,7 @@
#include <qscrollview.h>
#include <qvaluevector.h>
#include <qvbox.h>
#include "document.h"
class QTimer;
......@@ -19,6 +20,11 @@ class KActionCollection;
class KConfigGroup;
class Thumbnail;
/**
* @short A scrollview that displays pages pixmaps previews (aka thumbnails).
*
* ...
*/
class ThumbnailList : public QScrollView, public KPDFDocumentObserver
{
Q_OBJECT
......@@ -62,4 +68,14 @@ Q_OBJECT
int m_vectorIndex;
};
/**
* @short A vertical boxed container with zero size hint (for left toolbox)
*/
class ThumbnailsBox : public QVBox
{
public:
ThumbnailsBox( QWidget * parent );
QSize sizeHint() const;
};
#endif
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