Add the possibility to choose which screen to use for the presentation mode.

Default is "Default Screen", with the options for showing it to any available screen.

Also, dynamically resize when the screen used for the presentation mode changes size during a presentation.

Many thanks to 'zbsz' for his testing!
CCMAIL: zbigniewo@gmail.com

GUI:

svn path=/trunk/KDE/kdegraphics/okular/; revision=794501
This commit is contained in:
Pino Toscano 2008-04-07 18:16:39 +00:00
parent 0b2775f527
commit 1817a198d0
6 changed files with 193 additions and 105 deletions

View file

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (C) 2006 by Pino Toscano <toscano.pino@tiscali.it> *
* Copyright (C) 2006,2008 by Pino Toscano <pino@kde.org> *
* *
* 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 *
@ -11,9 +11,50 @@
#include "ui_dlgpresentationbase.h"
#include <qapplication.h>
#include <qdesktopwidget.h>
#include <klocale.h>
#include "settings.h"
DlgPresentation::DlgPresentation( QWidget * parent )
: QWidget( parent )
{
Ui_DlgPresentationBase dlg;
dlg.setupUi( this );
m_dlg = new Ui_DlgPresentationBase();
m_dlg->setupUi( this );
QStringList choices;
choices.append( i18nc( "@label:listbox The default screen for the presentation mode", "Default Screen" ) );
const int screenCount = QApplication::desktop()->numScreens();
for ( int i = 0; i < screenCount; ++i )
{
choices.append( i18nc( "@label:listbox %1 is the screen number (0, 1, ...)", "Screen %1", i ) );
}
m_dlg->screenCombo->addItems( choices );
const int screen = Okular::Settings::slidesScreen();
if ( screen >= -1 && screen < screenCount )
{
m_dlg->screenCombo->setCurrentIndex( screen + 1 );
}
else
{
m_dlg->screenCombo->setCurrentIndex( 0 );
Okular::Settings::setSlidesScreen( -1 );
}
connect( m_dlg->screenCombo, SIGNAL( activated( int ) ), this, SLOT( screenComboChanged( int ) ) );
}
DlgPresentation::~DlgPresentation()
{
delete m_dlg;
}
void DlgPresentation::screenComboChanged( int which )
{
Okular::Settings::setSlidesScreen( which - 1 );
}
#include "dlgpresentation.moc"

View file

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (C) 2006 by Pino Toscano <toscano.pino@tiscali.it> *
* Copyright (C) 2006,2008 by Pino Toscano <pino@kde.org> *
* *
* 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 *
@ -12,10 +12,21 @@
#include <qwidget.h>
class Ui_DlgPresentationBase;
class DlgPresentation : public QWidget
{
Q_OBJECT
public:
DlgPresentation( QWidget * parent = 0 );
virtual ~DlgPresentation();
protected slots:
void screenComboChanged( int which );
protected:
Ui_DlgPresentationBase * m_dlg;
};
#endif

View file

@ -6,13 +6,10 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>396</height>
<height>446</height>
</rect>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" >
<property name="margin" >
<number>0</number>
</property>
@ -73,21 +70,9 @@
<property name="title" >
<string>Appearance</string>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>9</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<layout class="QGridLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<layout class="QGridLayout" name="gridLayout_3" >
<item row="0" column="0" >
<widget class="QLabel" name="textLabel3" >
<property name="text" >
@ -102,6 +87,19 @@
<widget class="KColorButton" name="kcfg_SlidesBackgroundColor" />
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Pencil color:</string>
</property>
<property name="alignment" >
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="KColorButton" name="kcfg_SlidesPencilColor" />
</item>
<item row="2" column="0" >
<widget class="QLabel" name="textLabel2" >
<property name="text" >
<string>Mouse cursor:</string>
@ -111,7 +109,7 @@
</property>
</widget>
</item>
<item row="1" column="1" >
<item row="2" column="1" >
<widget class="QComboBox" name="kcfg_SlidesCursor" >
<item>
<property name="text" >
@ -269,39 +267,23 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3" >
<widget class="QGroupBox" name="groupBox_4" >
<property name="title" >
<string>Drawing</string>
<string>Placement</string>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>9</number>
</property>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
<layout class="QGridLayout" name="gridLayout_2" >
<item row="0" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Screen:</string>
</property>
<property name="margin" >
<number>0</number>
<property name="alignment" >
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>Pencil color:</string>
</property>
<property name="alignment" >
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="KColorButton" name="kcfg_SlidesPencilColor" />
</item>
</layout>
</widget>
</item>
<item row="0" column="1" >
<widget class="QComboBox" name="screenCombo" />
</item>
</layout>
</widget>
@ -316,8 +298,8 @@
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>318</width>
<height>16</height>
<width>20</width>
<height>4</height>
</size>
</property>
</spacer>

View file

@ -140,6 +140,11 @@
<entry key="SlidesTransitionsEnabled" type="Bool" >
<default>true</default>
</entry>
<entry key="SlidesScreen" type="Int" >
<default>-1</default>
<min>-1</min>
<max>20</max>
</entry>
</group>
<group name="General" >
<entry key="ObeyDRM" type="Bool" >

View file

@ -28,7 +28,6 @@
#include <qtoolbar.h>
#include <kaction.h>
#include <kactioncollection.h>
#include <kglobalsettings.h>
#include <klineedit.h>
#include <klocale.h>
#include <kiconloader.h>
@ -104,9 +103,47 @@ PresentationWidget::PresentationWidget( QWidget * parent, Okular::Document * doc
setWindowTitle( KDialog::makeStandardCaption( caption ) );
m_width = -1;
m_screen = -2;
// show widget and take control
showFullScreen();
// create top toolbar
m_topBar = new PresentationToolBar( this );
m_topBar->setObjectName( "presentationBar" );
m_topBar->setIconSize( QSize( 32, 32 ) );
m_topBar->setMovable( false );
m_topBar->addAction( KIcon( layoutDirection() == Qt::RightToLeft ? "go-next" : "go-previous" ), i18n( "Previous Page" ), this, SLOT( slotPrevPage() ) );
m_pagesEdit = new KLineEdit( m_topBar );
QSizePolicy sp = m_pagesEdit->sizePolicy();
sp.setHorizontalPolicy( QSizePolicy::Minimum );
m_pagesEdit->setSizePolicy( sp );
QFontMetrics fm( m_pagesEdit->font() );
QStyleOptionFrame option;
option.initFrom( m_pagesEdit );
m_pagesEdit->setMaximumWidth( fm.width( QString::number( m_document->pages() ) ) + 2 * style()->pixelMetric( QStyle::PM_DefaultFrameWidth, &option, m_pagesEdit ) + 4 ); // the 4 comes from 2*horizontalMargin, horizontalMargin being a define in qlineedit.cpp
QIntValidator *validator = new QIntValidator( 1, m_document->pages(), m_pagesEdit );
m_pagesEdit->setValidator( validator );
m_topBar->addWidget( m_pagesEdit );
QLabel *pagesLabel = new QLabel( m_topBar );
pagesLabel->setText( QLatin1String( " / " ) + QString::number( m_document->pages() ) + QLatin1String( " " ) );
m_topBar->addWidget( pagesLabel );
connect( m_pagesEdit, SIGNAL( returnPressed() ), this, SLOT( slotPageChanged() ) );
m_topBar->addAction( KIcon( layoutDirection() == Qt::RightToLeft ? "go-previous" : "go-next" ), i18n( "Next Page" ), this, SLOT( slotNextPage() ) );
m_topBar->addSeparator();
QAction * drawingAct = m_topBar->addAction( KIcon( "draw-freehand" ), i18n( "Toggle Drawing Mode" ) );
drawingAct->setCheckable( true );
connect( drawingAct, SIGNAL( toggled( bool ) ), this, SLOT( togglePencilMode( bool ) ) );
QAction * eraseDrawingAct = m_topBar->addAction( KIcon( "draw-eraser" ), i18n( "Erase Drawings" ) );
connect( eraseDrawingAct, SIGNAL( triggered() ), this, SLOT( clearDrawings() ) );
QWidget *spacer = new QWidget( m_topBar );
spacer->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::MinimumExpanding );
m_topBar->addWidget( spacer );
m_topBar->addAction( KIcon( "application-exit" ), i18n( "Exit Presentation Mode" ), this, SLOT( close() ) );
m_topBar->setAutoFillBackground( true );
m_topBar->hide();
// change topbar background color
QPalette p = m_topBar->palette();
p.setColor( QPalette::Active, QPalette::Button, Qt::gray );
p.setColor( QPalette::Active, QPalette::Background, Qt::darkGray );
m_topBar->setPalette( p );
// misc stuff
setMouseTracking( true );
@ -409,7 +446,7 @@ void PresentationWidget::mouseMoveEvent( QMouseEvent * e )
else
{
// show the bar if reaching top 2 pixels
if ( e->y() <= (geometry().top() + 1) )
if ( e->y() <= 1 )
m_topBar->show();
// handle "dragging the wheel" if clicking on its geometry
else if ( ( QApplication::mouseButtons() & Qt::LeftButton ) && m_overlayGeometry.contains( e->pos() ) )
@ -422,50 +459,8 @@ void PresentationWidget::paintEvent( QPaintEvent * pe )
{
if (m_width == -1)
{
QRect d = KGlobalSettings::desktopGeometry(this);
m_width = d.width();
m_height = d.height();
// create top toolbar
m_topBar = new PresentationToolBar( this );
m_topBar->setObjectName( "presentationBar" );
m_topBar->setIconSize( QSize( 32, 32 ) );
m_topBar->setMovable( false );
m_topBar->addAction( KIcon( layoutDirection() == Qt::RightToLeft ? "go-next" : "go-previous" ), i18n("Previous Page"), this, SLOT( slotPrevPage() ) );
m_pagesEdit = new KLineEdit( m_topBar );
QSizePolicy sp = m_pagesEdit->sizePolicy();
sp.setHorizontalPolicy( QSizePolicy::Minimum );
m_pagesEdit->setSizePolicy( sp );
QFontMetrics fm( m_pagesEdit->font() );
QStyleOptionFrame option;
option.initFrom(m_pagesEdit);
m_pagesEdit->setMaximumWidth( fm.width( QString::number( m_document->pages() ) ) + 2 * style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, m_pagesEdit) + 4 ); // the 4 comes from 2*horizontalMargin, horizontalMargin being a define in qlineedit.cpp
QIntValidator *validator = new QIntValidator( 1, m_document->pages(), m_pagesEdit );
m_pagesEdit->setValidator( validator );
m_topBar->addWidget( m_pagesEdit );
QLabel *pagesLabel = new QLabel( m_topBar );
pagesLabel->setText( QLatin1String( " / " ) + QString::number( m_document->pages() ) + QLatin1String( " " ) );
m_topBar->addWidget( pagesLabel );
connect( m_pagesEdit, SIGNAL( returnPressed() ), this, SLOT( slotPageChanged() ) );
m_topBar->addAction( KIcon( layoutDirection() == Qt::RightToLeft ? "go-previous" : "go-next" ), i18n("Next Page"), this, SLOT( slotNextPage() ) );
m_topBar->addSeparator();
QAction * drawingAct = m_topBar->addAction( KIcon( "draw-freehand" ), i18n( "Toggle Drawing Mode" ) );
drawingAct->setCheckable( true );
connect( drawingAct, SIGNAL( toggled( bool ) ), this, SLOT( togglePencilMode( bool ) ) );
QAction * eraseDrawingAct = m_topBar->addAction( KIcon( "draw-eraser" ), i18n( "Erase Drawings" ) );
connect( eraseDrawingAct, SIGNAL( triggered() ), this, SLOT( clearDrawings() ) );
QWidget *spacer = new QWidget(m_topBar);
spacer->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::MinimumExpanding );
m_topBar->addWidget( spacer );
m_topBar->addAction( KIcon("application-exit"), i18n("Exit Presentation Mode"), this, SLOT( close() ) );
m_topBar->setGeometry( 0, 0, m_width, 32 + 10 );
m_topBar->setAutoFillBackground( true );
m_topBar->hide();
// change topbar background color
QPalette p = m_topBar->palette();
p.setColor( QPalette::Active, QPalette::Button, Qt::gray );
p.setColor( QPalette::Active, QPalette::Background, Qt::darkGray );
m_topBar->setPalette( p );
m_width = width();
m_height = height();
connect( m_document, SIGNAL( linkFind() ), this, SLOT( slotFind() ) );
@ -478,7 +473,7 @@ void PresentationWidget::paintEvent( QPaintEvent * pe )
}
// check painting rect consistancy
QRect r = pe->rect().intersect( geometry() );
QRect r = pe->rect().intersect( QRect( QPoint( 0, 0 ), geometry().size() ) );
if ( r.isNull() || m_lastRenderedPixmap.isNull() )
return;
@ -550,7 +545,7 @@ const Okular::Action * PresentationWidget::getLink( int x, int y, QRect * geomet
return 0;
// check if 1) there is an object and 2) it's a link
QRect d = KGlobalSettings::desktopGeometry( const_cast< PresentationWidget * >( this ) );
const QRect d = QApplication::desktop()->screenGeometry( m_screen );
const Okular::ObjectRect * object = page->objectRect( Okular::ObjectRect::Action, nx, ny, d.width(), d.height() );
if ( !object )
return 0;
@ -958,6 +953,32 @@ void PresentationWidget::startAutoChangeTimer()
}
}
void PresentationWidget::recalcGeometry()
{
QDesktopWidget *desktop = QApplication::desktop();
const int preferenceScreen = Okular::Settings::slidesScreen();
int screen = -1;
if ( preferenceScreen >= -1 && preferenceScreen < desktop->numScreens() )
{
screen = preferenceScreen;
}
else
{
screen = -1;
Okular::Settings::setSlidesScreen( -1 );
}
const QRect screenGeom = desktop->screenGeometry( screen );
// kDebug() << screen << "=>" << screenGeom;
m_screen = screen;
setGeometry( screenGeom );
}
void PresentationWidget::repositionContent()
{
const QRect ourGeom = geometry();
m_topBar->setGeometry( 0, 0, ourGeom.width(), 32 + 10 );
}
void PresentationWidget::slotNextPage()
@ -1050,6 +1071,15 @@ void PresentationWidget::slotTransitionStep()
void PresentationWidget::slotDelayedEvents()
{
recalcGeometry();
repositionContent();
// show widget and take control
show();
setWindowState( windowState() | Qt::WindowFullScreen );
connect( QApplication::desktop(), SIGNAL( resized( int ) ), this, SLOT( screenResized( int ) ) );
// inform user on how to exit from presentation mode
KMessageBox::information( this, i18n("There are two ways of exiting presentation mode, you can press either ESC key or click with the quit button that appears when placing the mouse in the top-right corner. Of course you can cycle windows (Alt+TAB by default)"), QString(), "presentationInfo" );
}
@ -1097,6 +1127,21 @@ void PresentationWidget::clearDrawings()
m_currentPageDrawings.clear();
}
void PresentationWidget::screenResized( int screen )
{
// we can ignore if a screen was resized in the case the screen is not
// where we are on
if ( screen != m_screen
|| ( m_screen == -1 && screen == QApplication::desktop()->primaryScreen() ) )
return;
recalcGeometry();
repositionContent();
m_width = width();
m_height = height();
}
void PresentationWidget::slotFind()
{
if ( !m_searchBar )

View file

@ -81,6 +81,8 @@ class PresentationWidget : public QDialog, public Okular::DocumentObserver
const Okular::PageTransition defaultTransition( int ) const;
QRect routeMouseDrawingEvent( QMouseEvent * );
void startAutoChangeTimer();
void recalcGeometry();
void repositionContent();
// cache stuff
int m_width;
@ -93,6 +95,7 @@ class PresentationWidget : public QDialog, public Okular::DocumentObserver
QList< Okular::Annotation * > m_currentPageDrawings;
AnnotatorEngine * m_drawingEngine;
QRect m_drawingRect;
int m_screen;
// transition related
QTimer * m_transitionTimer;
@ -123,6 +126,7 @@ class PresentationWidget : public QDialog, public Okular::DocumentObserver
void slotPageChanged();
void togglePencilMode( bool );
void clearDrawings();
void screenResized( int );
};
#endif