2005-01-26 10:42:07 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2005 by Enrico Ros <eros.kde@email.it> *
|
2006-02-18 12:06:52 +00:00
|
|
|
* Copyright (C) 2006 by Albert Astals Cid <aacid@kde.org> *
|
2005-01-26 10:42:07 +00:00
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-04-19 18:30:20 +00:00
|
|
|
#include "minibar.h"
|
|
|
|
|
2005-01-26 10:42:07 +00:00
|
|
|
// qt / kde includes
|
2006-05-27 13:36:41 +00:00
|
|
|
#include <qapplication.h>
|
2006-03-23 20:43:38 +00:00
|
|
|
#include <qevent.h>
|
2006-10-15 21:10:52 +00:00
|
|
|
#include <qframe.h>
|
2005-01-26 10:42:07 +00:00
|
|
|
#include <qpushbutton.h>
|
|
|
|
#include <qlabel.h>
|
|
|
|
#include <qlayout.h>
|
2018-08-17 18:05:01 +00:00
|
|
|
#include <QToolButton>
|
2005-01-26 10:42:07 +00:00
|
|
|
#include <qvalidator.h>
|
|
|
|
#include <qpainter.h>
|
2014-10-06 06:31:17 +00:00
|
|
|
#include <QIcon>
|
2007-05-28 16:34:26 +00:00
|
|
|
#include <kicontheme.h>
|
2008-01-12 19:06:46 +00:00
|
|
|
#include <klineedit.h>
|
2014-10-19 13:20:30 +00:00
|
|
|
#include <KLocalizedString>
|
2006-03-23 20:43:38 +00:00
|
|
|
#include <kacceleratormanager.h>
|
2014-01-12 21:20:29 +00:00
|
|
|
#include <qtoolbar.h>
|
2005-01-26 10:42:07 +00:00
|
|
|
|
|
|
|
// local includes
|
|
|
|
#include "core/document.h"
|
2011-08-12 13:39:57 +00:00
|
|
|
#include "core/page.h"
|
2005-01-26 10:42:07 +00:00
|
|
|
|
|
|
|
// [private widget] a flat qpushbutton that enlights on hover
|
2008-11-21 10:50:16 +00:00
|
|
|
class HoverButton : public QToolButton
|
2005-01-26 10:42:07 +00:00
|
|
|
{
|
2016-10-29 14:32:24 +00:00
|
|
|
Q_OBJECT
|
2005-01-26 10:42:07 +00:00
|
|
|
public:
|
|
|
|
HoverButton( QWidget * parent );
|
|
|
|
};
|
|
|
|
|
2012-01-31 18:48:20 +00:00
|
|
|
MiniBarLogic::MiniBarLogic( QObject * parent, Okular::Document * document )
|
|
|
|
: QObject(parent)
|
|
|
|
, m_document( document )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MiniBarLogic::~MiniBarLogic()
|
|
|
|
{
|
|
|
|
m_document->removeObserver( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MiniBarLogic::addMiniBar( MiniBar * miniBar )
|
|
|
|
{
|
|
|
|
m_miniBars.insert( miniBar );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MiniBarLogic::removeMiniBar( MiniBar * miniBar )
|
|
|
|
{
|
|
|
|
m_miniBars.remove( miniBar );
|
|
|
|
}
|
|
|
|
|
|
|
|
Okular::Document *MiniBarLogic::document() const
|
|
|
|
{
|
|
|
|
return m_document;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MiniBarLogic::currentPage() const
|
|
|
|
{
|
2012-08-16 15:37:39 +00:00
|
|
|
return m_document->currentPage();
|
2012-01-31 18:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MiniBarLogic::notifySetup( const QVector< Okular::Page * > & pageVector, int setupFlags )
|
|
|
|
{
|
|
|
|
// only process data when document changes
|
|
|
|
if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if document is closed or has no pages, hide widget
|
|
|
|
const int pages = pageVector.count();
|
|
|
|
if ( pages < 1 )
|
|
|
|
{
|
|
|
|
foreach ( MiniBar *miniBar, m_miniBars )
|
|
|
|
{
|
|
|
|
miniBar->setEnabled( false );
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool labelsDiffer = false;
|
|
|
|
foreach(const Okular::Page * page, pageVector)
|
|
|
|
{
|
|
|
|
if (!page->label().isEmpty())
|
|
|
|
{
|
|
|
|
if (page->label().toInt() != (page->number() + 1))
|
|
|
|
{
|
|
|
|
labelsDiffer = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString pagesString = QString::number( pages );
|
|
|
|
|
|
|
|
foreach ( MiniBar *miniBar, m_miniBars )
|
|
|
|
{
|
|
|
|
// resize width of widgets
|
|
|
|
miniBar->resizeForPage( pages );
|
|
|
|
|
|
|
|
// update child widgets
|
|
|
|
miniBar->m_pageLabelEdit->setPageLabels( pageVector );
|
|
|
|
miniBar->m_pageNumberEdit->setPagesNumber( pages );
|
|
|
|
miniBar->m_pagesButton->setText( pagesString );
|
|
|
|
miniBar->m_prevButton->setEnabled( false );
|
|
|
|
miniBar->m_nextButton->setEnabled( false );
|
|
|
|
miniBar->m_pageLabelEdit->setVisible( labelsDiffer );
|
|
|
|
miniBar->m_pageNumberLabel->setVisible( labelsDiffer );
|
|
|
|
miniBar->m_pageNumberEdit->setVisible( !labelsDiffer );
|
|
|
|
|
2016-07-13 01:10:15 +00:00
|
|
|
miniBar->adjustSize();
|
2012-01-31 18:48:20 +00:00
|
|
|
|
|
|
|
miniBar->setEnabled( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-16 15:37:39 +00:00
|
|
|
void MiniBarLogic::notifyCurrentPageChanged( int previousPage, int currentPage )
|
2012-01-31 18:48:20 +00:00
|
|
|
{
|
2012-08-16 15:37:39 +00:00
|
|
|
Q_UNUSED( previousPage )
|
|
|
|
|
2012-01-31 18:48:20 +00:00
|
|
|
// get current page number
|
|
|
|
const int pages = m_document->pages();
|
|
|
|
|
|
|
|
// if the document is opened and page is changed
|
2012-08-16 15:37:39 +00:00
|
|
|
if ( pages > 0 )
|
2012-01-31 18:48:20 +00:00
|
|
|
{
|
2012-08-16 15:37:39 +00:00
|
|
|
const QString pageNumber = QString::number( currentPage + 1 );
|
|
|
|
const QString pageLabel = m_document->page( currentPage )->label();
|
|
|
|
|
2012-01-31 18:48:20 +00:00
|
|
|
foreach ( MiniBar *miniBar, m_miniBars )
|
|
|
|
{
|
|
|
|
// update prev/next button state
|
2012-08-16 15:37:39 +00:00
|
|
|
miniBar->m_prevButton->setEnabled( currentPage > 0 );
|
|
|
|
miniBar->m_nextButton->setEnabled( currentPage < ( pages - 1 ) );
|
2012-01-31 18:48:20 +00:00
|
|
|
// update text on widgets
|
|
|
|
miniBar->m_pageNumberEdit->setText( pageNumber );
|
|
|
|
miniBar->m_pageNumberLabel->setText( pageNumber );
|
|
|
|
miniBar->m_pageLabelEdit->setText( pageLabel );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-26 10:42:07 +00:00
|
|
|
|
|
|
|
/** MiniBar **/
|
|
|
|
|
2012-01-31 18:48:20 +00:00
|
|
|
MiniBar::MiniBar( QWidget * parent, MiniBarLogic * miniBarLogic )
|
|
|
|
: QWidget( parent )
|
|
|
|
, m_miniBarLogic( miniBarLogic )
|
2017-09-05 21:27:18 +00:00
|
|
|
, m_oldToobarParent( nullptr )
|
2005-01-26 10:42:07 +00:00
|
|
|
{
|
2015-10-29 12:37:11 +00:00
|
|
|
setObjectName( QStringLiteral( "miniBar" ) );
|
2012-01-31 18:48:20 +00:00
|
|
|
|
|
|
|
m_miniBarLogic->addMiniBar( this );
|
2006-10-15 21:10:52 +00:00
|
|
|
|
2005-01-26 10:42:07 +00:00
|
|
|
QHBoxLayout * horLayout = new QHBoxLayout( this );
|
2008-11-21 10:50:16 +00:00
|
|
|
|
2006-10-15 15:59:22 +00:00
|
|
|
horLayout->setMargin( 0 );
|
2007-05-28 16:34:26 +00:00
|
|
|
horLayout->setSpacing( 3 );
|
|
|
|
|
2007-10-01 15:10:42 +00:00
|
|
|
QSize buttonSize( KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium );
|
2006-10-15 16:12:26 +00:00
|
|
|
// bottom: left prev_page button
|
|
|
|
m_prevButton = new HoverButton( this );
|
2019-02-27 13:47:34 +00:00
|
|
|
m_prevButton->setIcon( QIcon::fromTheme( QStringLiteral("arrow-up") ) );
|
2007-08-08 17:50:47 +00:00
|
|
|
m_prevButton->setIconSize( buttonSize );
|
2006-10-15 15:59:22 +00:00
|
|
|
horLayout->addWidget( m_prevButton );
|
2006-10-15 16:12:26 +00:00
|
|
|
// bottom: left lineEdit (current page box)
|
2011-08-12 13:39:57 +00:00
|
|
|
m_pageNumberEdit = new PageNumberEdit( this );
|
|
|
|
horLayout->addWidget( m_pageNumberEdit );
|
|
|
|
m_pageNumberEdit->installEventFilter( this );
|
|
|
|
// bottom: left labelWidget (current page label)
|
|
|
|
m_pageLabelEdit = new PageLabelEdit( this );
|
|
|
|
horLayout->addWidget(m_pageLabelEdit);
|
|
|
|
m_pageLabelEdit->installEventFilter( this );
|
|
|
|
// bottom: left labelWidget (current page label)
|
|
|
|
m_pageNumberLabel = new QLabel( this );
|
|
|
|
m_pageNumberLabel->setAlignment( Qt::AlignCenter );
|
|
|
|
horLayout->addWidget(m_pageNumberLabel);
|
2007-05-28 16:34:26 +00:00
|
|
|
// bottom: central 'of' label
|
|
|
|
horLayout->addSpacing(5);
|
2007-08-08 15:44:26 +00:00
|
|
|
horLayout->addWidget( new QLabel( i18nc( "Layouted like: '5 [pages] of 10'", "of" ), this ) );
|
2006-10-15 16:12:26 +00:00
|
|
|
// bottom: right button
|
|
|
|
m_pagesButton = new HoverButton( this );
|
2006-10-15 15:59:22 +00:00
|
|
|
horLayout->addWidget( m_pagesButton );
|
2006-10-15 16:12:26 +00:00
|
|
|
// bottom: right next_page button
|
|
|
|
m_nextButton = new HoverButton( this );
|
2019-02-27 13:47:34 +00:00
|
|
|
m_nextButton->setIcon( QIcon::fromTheme( QStringLiteral ("arrow-down") ) );
|
2007-08-08 17:50:47 +00:00
|
|
|
m_nextButton->setIconSize( buttonSize );
|
2006-10-15 15:59:22 +00:00
|
|
|
horLayout->addWidget( m_nextButton );
|
2008-11-21 10:50:16 +00:00
|
|
|
|
2006-10-15 15:59:22 +00:00
|
|
|
QSizePolicy sp = sizePolicy();
|
|
|
|
sp.setHorizontalPolicy( QSizePolicy::Fixed );
|
|
|
|
sp.setVerticalPolicy( QSizePolicy::Fixed );
|
|
|
|
setSizePolicy( sp );
|
|
|
|
|
2006-11-11 12:00:03 +00:00
|
|
|
// resize width of widgets
|
|
|
|
resizeForPage( 0 );
|
|
|
|
|
2005-01-26 10:42:07 +00:00
|
|
|
// connect signals from child widgets to internal handlers / signals bouncers
|
2011-08-12 13:39:57 +00:00
|
|
|
connect( m_pageNumberEdit, SIGNAL(returnPressed()), this, SLOT(slotChangePage()) );
|
|
|
|
connect( m_pageLabelEdit, SIGNAL(pageNumberChosen(int)), this, SLOT(slotChangePage(int)) );
|
2015-10-29 12:37:11 +00:00
|
|
|
connect( m_pagesButton, &QAbstractButton::clicked, this, &MiniBar::gotoPage );
|
|
|
|
connect( m_prevButton, &QAbstractButton::clicked, this, &MiniBar::prevPage );
|
|
|
|
connect( m_nextButton, &QAbstractButton::clicked, this, &MiniBar::nextPage );
|
2005-01-26 10:42:07 +00:00
|
|
|
|
2016-07-13 01:10:15 +00:00
|
|
|
adjustSize();
|
2006-10-15 15:59:22 +00:00
|
|
|
|
|
|
|
// widget starts disabled (will be enabled after opening a document)
|
|
|
|
setEnabled( false );
|
2005-01-26 10:42:07 +00:00
|
|
|
}
|
|
|
|
|
2006-02-18 12:06:52 +00:00
|
|
|
MiniBar::~MiniBar()
|
|
|
|
{
|
2012-01-31 18:48:20 +00:00
|
|
|
m_miniBarLogic->removeMiniBar( this );
|
2006-02-18 12:06:52 +00:00
|
|
|
}
|
|
|
|
|
2014-01-12 21:20:29 +00:00
|
|
|
void MiniBar::changeEvent( QEvent * event )
|
|
|
|
{
|
|
|
|
if ( event->type() == QEvent::ParentChange )
|
|
|
|
{
|
|
|
|
QToolBar *tb = dynamic_cast<QToolBar*>( parent() );
|
|
|
|
if ( tb != m_oldToobarParent )
|
|
|
|
{
|
|
|
|
if ( m_oldToobarParent )
|
|
|
|
{
|
2015-10-29 12:37:11 +00:00
|
|
|
disconnect( m_oldToobarParent, &QToolBar::iconSizeChanged, this, &MiniBar::slotToolBarIconSizeChanged);
|
2014-01-12 21:20:29 +00:00
|
|
|
}
|
|
|
|
m_oldToobarParent = tb;
|
|
|
|
if ( tb )
|
|
|
|
{
|
2015-10-29 12:37:11 +00:00
|
|
|
connect( tb, &QToolBar::iconSizeChanged, this, &MiniBar::slotToolBarIconSizeChanged);
|
2014-01-12 21:20:29 +00:00
|
|
|
slotToolBarIconSizeChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-08 05:47:57 +00:00
|
|
|
bool MiniBar::eventFilter( QObject *target, QEvent *event )
|
|
|
|
{
|
2011-08-12 13:39:57 +00:00
|
|
|
if ( target == m_pageNumberEdit || target == m_pageLabelEdit )
|
2011-06-08 05:47:57 +00:00
|
|
|
{
|
|
|
|
if ( event->type() == QEvent::KeyPress )
|
|
|
|
{
|
|
|
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>( event );
|
2011-08-12 13:39:57 +00:00
|
|
|
int key = keyEvent->key();
|
|
|
|
if ( key == Qt::Key_PageUp || key == Qt::Key_PageDown || key == Qt::Key_Up || key == Qt::Key_Down )
|
2011-06-08 05:47:57 +00:00
|
|
|
{
|
|
|
|
emit forwardKeyPressEvent( keyEvent );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-01-26 10:42:07 +00:00
|
|
|
void MiniBar::slotChangePage()
|
|
|
|
{
|
|
|
|
// get text from the lineEdit
|
2012-01-31 18:48:20 +00:00
|
|
|
const QString pageNumber = m_pageNumberEdit->text();
|
2005-01-26 10:42:07 +00:00
|
|
|
|
|
|
|
// convert it to page number and go to that page
|
|
|
|
bool ok;
|
|
|
|
int number = pageNumber.toInt( &ok ) - 1;
|
2012-01-31 18:48:20 +00:00
|
|
|
if ( ok && number >= 0 && number < (int)m_miniBarLogic->document()->pages() &&
|
|
|
|
number != m_miniBarLogic->currentPage() )
|
2005-01-26 10:42:07 +00:00
|
|
|
{
|
2011-08-12 13:39:57 +00:00
|
|
|
slotChangePage( number );
|
2005-01-26 10:42:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 13:39:57 +00:00
|
|
|
void MiniBar::slotChangePage( int pageNumber )
|
|
|
|
{
|
2012-01-31 18:48:20 +00:00
|
|
|
m_miniBarLogic->document()->setViewportPage( pageNumber );
|
2011-08-12 13:39:57 +00:00
|
|
|
m_pageNumberEdit->clearFocus();
|
|
|
|
m_pageLabelEdit->clearFocus();
|
|
|
|
}
|
|
|
|
|
2005-01-26 10:42:07 +00:00
|
|
|
void MiniBar::slotEmitNextPage()
|
|
|
|
{
|
|
|
|
// emit signal
|
|
|
|
nextPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MiniBar::slotEmitPrevPage()
|
|
|
|
{
|
|
|
|
// emit signal
|
|
|
|
prevPage();
|
|
|
|
}
|
|
|
|
|
2014-01-12 21:20:29 +00:00
|
|
|
void MiniBar::slotToolBarIconSizeChanged()
|
|
|
|
{
|
|
|
|
const QSize buttonSize = m_oldToobarParent->iconSize();
|
|
|
|
m_prevButton->setIconSize( buttonSize );
|
|
|
|
m_nextButton->setIconSize( buttonSize );
|
|
|
|
}
|
|
|
|
|
2006-11-11 12:00:03 +00:00
|
|
|
void MiniBar::resizeForPage( int pages )
|
|
|
|
{
|
|
|
|
int numberWidth = 10 + fontMetrics().width( QString::number( pages ) );
|
2011-08-12 13:39:57 +00:00
|
|
|
m_pageNumberEdit->setMinimumWidth( numberWidth );
|
|
|
|
m_pageNumberEdit->setMaximumWidth( 2 * numberWidth );
|
|
|
|
m_pageLabelEdit->setMinimumWidth( numberWidth );
|
|
|
|
m_pageLabelEdit->setMaximumWidth( 2 * numberWidth );
|
|
|
|
m_pageNumberLabel->setMinimumWidth( numberWidth );
|
|
|
|
m_pageNumberLabel->setMaximumWidth( 2 * numberWidth );
|
2006-11-11 12:00:03 +00:00
|
|
|
m_pagesButton->setMinimumWidth( numberWidth );
|
|
|
|
m_pagesButton->setMaximumWidth( 2 * numberWidth );
|
|
|
|
}
|
|
|
|
|
2005-01-26 10:42:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** ProgressWidget **/
|
|
|
|
|
2006-10-15 15:59:22 +00:00
|
|
|
ProgressWidget::ProgressWidget( QWidget * parent, Okular::Document * document )
|
|
|
|
: QWidget( parent ), m_document( document ),
|
2012-08-16 15:37:39 +00:00
|
|
|
m_progressPercentage( -1 )
|
2005-01-26 10:42:07 +00:00
|
|
|
{
|
2015-10-29 12:37:11 +00:00
|
|
|
setObjectName( QStringLiteral( "progress" ) );
|
2006-03-29 20:43:48 +00:00
|
|
|
setAttribute( Qt::WA_OpaquePaintEvent, true );
|
2005-01-26 10:42:07 +00:00
|
|
|
setFixedHeight( 4 );
|
|
|
|
setMouseTracking( true );
|
|
|
|
}
|
|
|
|
|
2006-10-15 15:59:22 +00:00
|
|
|
ProgressWidget::~ProgressWidget()
|
|
|
|
{
|
|
|
|
m_document->removeObserver( this );
|
|
|
|
}
|
|
|
|
|
2012-08-16 15:37:39 +00:00
|
|
|
void ProgressWidget::notifyCurrentPageChanged( int previousPage, int currentPage )
|
2006-10-15 15:59:22 +00:00
|
|
|
{
|
2012-08-16 15:37:39 +00:00
|
|
|
Q_UNUSED( previousPage )
|
|
|
|
|
2006-10-15 15:59:22 +00:00
|
|
|
// get current page number
|
|
|
|
int pages = m_document->pages();
|
|
|
|
|
|
|
|
// if the document is opened and page is changed
|
2012-08-16 15:37:39 +00:00
|
|
|
if ( pages > 0 )
|
2006-10-15 15:59:22 +00:00
|
|
|
{
|
|
|
|
// update percentage
|
2012-08-16 15:37:39 +00:00
|
|
|
const float percentage = pages < 2 ? 1.0 : (float)currentPage / (float)(pages - 1);
|
2006-10-15 15:59:22 +00:00
|
|
|
setProgress( percentage );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-26 10:42:07 +00:00
|
|
|
void ProgressWidget::setProgress( float percentage )
|
|
|
|
{
|
|
|
|
m_progressPercentage = percentage;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2006-10-15 15:59:22 +00:00
|
|
|
void ProgressWidget::slotGotoNormalizedPage( float index )
|
|
|
|
{
|
|
|
|
// figure out page number and go to that page
|
|
|
|
int number = (int)( index * (float)m_document->pages() );
|
|
|
|
if ( number >= 0 && number < (int)m_document->pages() &&
|
2012-08-16 15:37:39 +00:00
|
|
|
number != (int)m_document->currentPage() )
|
2006-10-15 15:59:22 +00:00
|
|
|
m_document->setViewportPage( number );
|
|
|
|
}
|
|
|
|
|
2005-01-26 10:42:07 +00:00
|
|
|
void ProgressWidget::mouseMoveEvent( QMouseEvent * e )
|
|
|
|
{
|
2006-05-27 13:52:29 +00:00
|
|
|
if ( ( QApplication::mouseButtons() & Qt::LeftButton ) && width() > 0 )
|
2006-10-15 15:59:22 +00:00
|
|
|
slotGotoNormalizedPage( (float)( QApplication::isRightToLeft() ? width() - e->x() : e->x() ) / (float)width() );
|
2005-01-26 10:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressWidget::mousePressEvent( QMouseEvent * e )
|
|
|
|
{
|
|
|
|
if ( e->button() == Qt::LeftButton && width() > 0 )
|
2006-10-15 15:59:22 +00:00
|
|
|
slotGotoNormalizedPage( (float)( QApplication::isRightToLeft() ? width() - e->x() : e->x() ) / (float)width() );
|
2005-01-26 10:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressWidget::wheelEvent( QWheelEvent * e )
|
|
|
|
{
|
|
|
|
if ( e->delta() > 0 )
|
2006-10-15 15:59:22 +00:00
|
|
|
emit nextPage();
|
2005-01-26 10:42:07 +00:00
|
|
|
else
|
2006-10-15 15:59:22 +00:00
|
|
|
emit prevPage();
|
2005-01-26 10:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressWidget::paintEvent( QPaintEvent * e )
|
|
|
|
{
|
2007-08-06 13:21:10 +00:00
|
|
|
QPainter p( this );
|
|
|
|
|
2005-01-26 10:42:07 +00:00
|
|
|
if ( m_progressPercentage < 0.0 )
|
2007-08-06 13:21:10 +00:00
|
|
|
{
|
|
|
|
p.fillRect( rect(), palette().color( QPalette::Active, QPalette::HighlightedText ) );
|
2005-01-26 10:42:07 +00:00
|
|
|
return;
|
2007-08-06 13:21:10 +00:00
|
|
|
}
|
2005-01-26 10:42:07 +00:00
|
|
|
|
|
|
|
// find out the 'fill' and the 'clear' rectangles
|
|
|
|
int w = width(),
|
|
|
|
h = height(),
|
|
|
|
l = (int)( (float)w * m_progressPercentage );
|
2016-07-24 21:46:53 +00:00
|
|
|
QRect cRect = ( QApplication::isRightToLeft() ? QRect( 0, 0, w - l, h ) : QRect( l, 0, w - l, h ) ).intersected( e->rect() );
|
|
|
|
QRect fRect = ( QApplication::isRightToLeft() ? QRect( w - l, 0, l, h ) : QRect( 0, 0, l, h ) ).intersected( e->rect() );
|
2005-03-24 18:54:13 +00:00
|
|
|
|
2006-05-27 13:36:41 +00:00
|
|
|
QPalette pal = palette();
|
2005-03-24 18:54:13 +00:00
|
|
|
// paint clear rect
|
2005-01-26 10:42:07 +00:00
|
|
|
if ( cRect.isValid() )
|
2006-05-27 13:36:41 +00:00
|
|
|
p.fillRect( cRect, pal.color( QPalette::Active, QPalette::HighlightedText ) );
|
2005-03-24 18:54:13 +00:00
|
|
|
// draw a frame-like outline
|
|
|
|
//p.setPen( palette().active().mid() );
|
|
|
|
//p.drawRect( 0,0, w, h );
|
|
|
|
// paint fill rect
|
2005-01-26 10:42:07 +00:00
|
|
|
if ( fRect.isValid() )
|
2006-05-27 13:36:41 +00:00
|
|
|
p.fillRect( fRect, pal.color( QPalette::Active, QPalette::Highlight ) );
|
2005-01-26 10:42:07 +00:00
|
|
|
if ( l && l != w )
|
|
|
|
{
|
2019-03-13 05:58:11 +00:00
|
|
|
p.setPen( pal.color( QPalette::Active, QPalette::Highlight ).darker( 120 ) );
|
2006-09-20 13:58:28 +00:00
|
|
|
int delta = QApplication::isRightToLeft() ? w - l : l;
|
|
|
|
p.drawLine( delta, 0, delta, h );
|
2005-01-26 10:42:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 13:39:57 +00:00
|
|
|
/** PageLabelEdit **/
|
2005-01-26 10:42:07 +00:00
|
|
|
|
2011-08-12 13:39:57 +00:00
|
|
|
PageLabelEdit::PageLabelEdit( MiniBar * parent )
|
|
|
|
: PagesEdit( parent )
|
|
|
|
{
|
|
|
|
setVisible( false );
|
|
|
|
connect( this, SIGNAL(returnPressed()), this, SLOT(pageChosen()) );
|
|
|
|
}
|
2005-01-26 10:42:07 +00:00
|
|
|
|
2011-08-12 13:39:57 +00:00
|
|
|
void PageLabelEdit::setText( const QString & newText )
|
|
|
|
{
|
|
|
|
m_lastLabel = newText;
|
|
|
|
PagesEdit::setText( newText );
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageLabelEdit::setPageLabels( const QVector<Okular::Page *> &pageVector )
|
|
|
|
{
|
|
|
|
m_labelPageMap.clear();
|
|
|
|
completionObject()->clear();
|
|
|
|
foreach(const Okular::Page * page, pageVector)
|
|
|
|
{
|
|
|
|
if ( !page->label().isEmpty() )
|
|
|
|
{
|
|
|
|
m_labelPageMap.insert( page->label(), page->number() );
|
|
|
|
bool ok;
|
|
|
|
page->label().toInt( &ok );
|
|
|
|
if ( !ok )
|
|
|
|
{
|
|
|
|
// Only add to the completion objects labels that are not numbers
|
|
|
|
completionObject()->addItem( page->label() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageLabelEdit::pageChosen()
|
|
|
|
{
|
|
|
|
const QString newInput = text();
|
|
|
|
const int pageNumber = m_labelPageMap.value( newInput, -1 );
|
|
|
|
if (pageNumber != -1)
|
|
|
|
{
|
|
|
|
emit pageNumberChosen( pageNumber );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setText( m_lastLabel );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** PageNumberEdit **/
|
|
|
|
|
|
|
|
PageNumberEdit::PageNumberEdit( MiniBar * miniBar )
|
|
|
|
: PagesEdit( miniBar )
|
2005-01-26 10:42:07 +00:00
|
|
|
{
|
|
|
|
// use an integer validator
|
|
|
|
m_validator = new QIntValidator( 1, 1, this );
|
|
|
|
setValidator( m_validator );
|
2011-08-12 13:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PageNumberEdit::setPagesNumber( int pages )
|
|
|
|
{
|
|
|
|
m_validator->setTop( pages );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** PagesEdit **/
|
|
|
|
|
|
|
|
PagesEdit::PagesEdit( MiniBar * parent )
|
|
|
|
: KLineEdit( parent ), m_miniBar( parent ), m_eatClick( false )
|
|
|
|
{
|
2005-01-26 10:42:07 +00:00
|
|
|
|
|
|
|
// customize text properties
|
|
|
|
setAlignment( Qt::AlignCenter );
|
2006-05-27 13:36:41 +00:00
|
|
|
|
|
|
|
// send a focus out event
|
|
|
|
QFocusEvent fe( QEvent::FocusOut );
|
|
|
|
QApplication::sendEvent( this, &fe );
|
2013-02-13 12:52:42 +00:00
|
|
|
|
2016-07-24 14:28:35 +00:00
|
|
|
connect( qApp, &QGuiApplication::paletteChanged, this, &PagesEdit::updatePalette );
|
2005-01-26 10:42:07 +00:00
|
|
|
}
|
|
|
|
|
2010-12-28 00:36:25 +00:00
|
|
|
void PagesEdit::setText( const QString & newText )
|
2005-01-26 10:42:07 +00:00
|
|
|
{
|
|
|
|
// call default handler if hasn't focus
|
|
|
|
if ( !hasFocus() )
|
2010-12-28 00:36:25 +00:00
|
|
|
{
|
|
|
|
KLineEdit::setText( newText );
|
|
|
|
}
|
|
|
|
// else preserve existing selection
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// save selection and adapt it to the new text length
|
|
|
|
int selectionLength = selectedText().length();
|
|
|
|
const bool allSelected = ( selectionLength == text().length() );
|
|
|
|
if ( allSelected )
|
|
|
|
{
|
|
|
|
KLineEdit::setText( newText );
|
|
|
|
selectAll();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int newSelectionStart = newText.length() - text().length() + selectionStart();
|
|
|
|
if ( newSelectionStart < 0 )
|
|
|
|
{
|
|
|
|
// the new text is shorter than the old one, and the front part, which is "cut off", is selected
|
|
|
|
// shorten the selection accordingly
|
|
|
|
selectionLength += newSelectionStart;
|
|
|
|
newSelectionStart = 0;
|
|
|
|
}
|
|
|
|
KLineEdit::setText( newText );
|
|
|
|
setSelection( newSelectionStart, selectionLength );
|
|
|
|
}
|
|
|
|
}
|
2005-01-26 10:42:07 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 12:52:42 +00:00
|
|
|
void PagesEdit::updatePalette()
|
|
|
|
{
|
|
|
|
QPalette pal;
|
|
|
|
|
|
|
|
if ( hasFocus() )
|
|
|
|
pal.setColor( QPalette::Active, QPalette::Base, QApplication::palette().color( QPalette::Active, QPalette::Base ) );
|
|
|
|
else
|
2019-03-13 05:58:11 +00:00
|
|
|
pal.setColor( QPalette::Base, QApplication::palette().color( QPalette::Base ).darker( 102 ) );
|
2013-02-13 12:52:42 +00:00
|
|
|
|
|
|
|
setPalette( pal );
|
|
|
|
}
|
|
|
|
|
2005-01-26 10:42:07 +00:00
|
|
|
void PagesEdit::focusInEvent( QFocusEvent * e )
|
|
|
|
{
|
|
|
|
// select all text
|
|
|
|
selectAll();
|
2006-03-23 20:43:38 +00:00
|
|
|
if ( e->reason() == Qt::MouseFocusReason )
|
2005-01-26 10:42:07 +00:00
|
|
|
m_eatClick = true;
|
|
|
|
// change background color to the default 'edit' color
|
2013-02-13 12:52:42 +00:00
|
|
|
updatePalette();
|
2005-01-26 10:42:07 +00:00
|
|
|
// call default handler
|
2008-01-12 19:06:46 +00:00
|
|
|
KLineEdit::focusInEvent( e );
|
2005-01-26 10:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PagesEdit::focusOutEvent( QFocusEvent * e )
|
|
|
|
{
|
|
|
|
// change background color to a dark tone
|
2013-02-13 12:52:42 +00:00
|
|
|
updatePalette();
|
2005-01-26 10:42:07 +00:00
|
|
|
// call default handler
|
2008-01-12 19:06:46 +00:00
|
|
|
KLineEdit::focusOutEvent( e );
|
2005-01-26 10:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PagesEdit::mousePressEvent( QMouseEvent * e )
|
|
|
|
{
|
|
|
|
// if this click got the focus in, don't process the event
|
|
|
|
if ( !m_eatClick )
|
2008-01-12 19:06:46 +00:00
|
|
|
KLineEdit::mousePressEvent( e );
|
2005-01-26 10:42:07 +00:00
|
|
|
m_eatClick = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PagesEdit::wheelEvent( QWheelEvent * e )
|
|
|
|
{
|
|
|
|
if ( e->delta() > 0 )
|
|
|
|
m_miniBar->slotEmitNextPage();
|
|
|
|
else
|
|
|
|
m_miniBar->slotEmitPrevPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** HoverButton **/
|
|
|
|
|
|
|
|
HoverButton::HoverButton( QWidget * parent )
|
2008-11-21 10:50:16 +00:00
|
|
|
: QToolButton( parent )
|
2005-01-26 10:42:07 +00:00
|
|
|
{
|
2008-11-21 10:50:16 +00:00
|
|
|
setAutoRaise(true);
|
2006-10-15 16:12:26 +00:00
|
|
|
setFocusPolicy(Qt::NoFocus);
|
2008-11-21 10:50:16 +00:00
|
|
|
setToolButtonStyle(Qt::ToolButtonIconOnly);
|
|
|
|
KAcceleratorManager::setNoAccel( this );
|
2005-01-26 10:42:07 +00:00
|
|
|
}
|
|
|
|
|
2016-10-29 14:32:24 +00:00
|
|
|
#include "minibar.moc"
|
2011-08-12 13:39:57 +00:00
|
|
|
|
2014-01-12 21:20:29 +00:00
|
|
|
/* kate: replace-tabs on; indent-width 4; */
|