⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pageviewutils.cpp.svn-base

📁 okular
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************** *   Copyright (C) 2004-2005 by Enrico Ros <eros.kde@email.it>             * *                                                                         * *   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.                                   * ***************************************************************************/// qt/kde includes#include <qapplication.h>#include <qbitmap.h>#include <qimage.h>#include <qpainter.h>#include <qevent.h>#include <qtimer.h>#include <qpushbutton.h>#include <QStyleOptionButton>#include <kacceleratormanager.h>#include <kiconloader.h>#include <kimageeffect.h>#include <klocale.h>// system includes#include <math.h>// local includes#include "pageviewutils.h"#include "core/page.h"#include "settings.h"/*********************//** PageViewItem     *//*********************/PageViewItem::PageViewItem( const KPDFPage * page )    : m_page( page ), m_zoomFactor( 1.0 ){}const KPDFPage * PageViewItem::page() const{    return m_page;}int PageViewItem::pageNumber() const{    return m_page->number();}const QRect& PageViewItem::geometry() const{    return m_geometry;}int PageViewItem::width() const{    return m_geometry.width();}int PageViewItem::height() const{    return m_geometry.height();}double PageViewItem::zoomFactor() const{    return m_zoomFactor;}void PageViewItem::setGeometry( int x, int y, int width, int height ){    m_geometry.setRect( x, y, width, height );}void PageViewItem::setWHZ( int w, int h, double z ){    m_geometry.setWidth( w );    m_geometry.setHeight( h );    m_zoomFactor = z;}void PageViewItem::moveTo( int x, int y ){    m_geometry.moveLeft( x );    m_geometry.moveTop( y );}void PageViewItem::invalidate(){    m_geometry.setRect( 0, 0, 0, 0 );}/*********************//** PageViewMessage  *//*********************/PageViewMessage::PageViewMessage( QWidget * parent )    : QWidget( parent ), m_timer( 0 ){    setObjectName( "pageViewMessage" );    setFocusPolicy( Qt::NoFocus );    setAttribute( Qt::WA_OpaquePaintEvent );    QPalette pal = palette();    pal.setColor( QPalette::Active, QPalette::Window, QApplication::palette().color( QPalette::Active, QPalette::Window ) );    setPalette( pal );    move( 10, 10 );    resize( 0, 0 );    hide();}void PageViewMessage::display( const QString & message, Icon icon, int durationMs )// give Caesar what belongs to Caesar: code taken from Amarok's osd.h/.cpp// "redde (reddite, pl.) cesari quae sunt cesaris", just btw.  :){    if ( !KpdfSettings::showOSD() )    {        hide();        return;    }    // determine text rectangle    QRect textRect = fontMetrics().boundingRect( message );    textRect.translate( -textRect.left(), -textRect.top() );    textRect.adjust( 0, 0, 2, 2 );    int width = textRect.width(),        height = textRect.height(),        textXOffset = 0,        shadowOffset = message.isRightToLeft() ? -1 : 1;    // load icon (if set) and update geometry    QPixmap symbol;    if ( icon != None )    {        switch ( icon )        {            case Annotation:                symbol = SmallIcon( "pencil" );                break;            case Find:                symbol = SmallIcon( "viewmag" );                break;            case Error:                symbol = SmallIcon( "messagebox_critical" );                break;            case Warning:                symbol = SmallIcon( "messagebox_warning" );                break;            default:                symbol = SmallIcon( "messagebox_info" );                break;        }        textXOffset = 2 + symbol.width();        width += textXOffset;        height = qMax( height, symbol.height() );    }    QRect geometry( 0, 0, width + 10, height + 8 );    // resize pixmap, mask and widget    static QBitmap mask;    mask = QBitmap( geometry.size() + QSize( 1, 1 ) );    m_pixmap = QPixmap( geometry.size() + QSize( 1, 1 ) );    resize( geometry.size() + QSize( 1, 1 ) );    // create and set transparency mask    QPainter maskPainter( &mask);    mask.fill( Qt::white );    maskPainter.setBrush( Qt::black );    maskPainter.drawRoundRect( geometry, 1600 / geometry.width(), 1600 / geometry.height() );    setMask( mask );    // draw background    QPalette pal = palette();    QPainter bufferPainter( &m_pixmap );    bufferPainter.setPen( Qt::black );    bufferPainter.setBrush( pal.color( QPalette::Window ) );    bufferPainter.drawRoundRect( geometry, 1600 / geometry.width(), 1600 / geometry.height() );    // draw icon if present    if ( !symbol.isNull() )        bufferPainter.drawPixmap( 5, 4, symbol, 0, 0, symbol.width(), symbol.height() );    // draw shadow and text    int yText = geometry.height() - height / 2;    bufferPainter.setPen( pal.color( QPalette::Window ).dark( 115 ) );    bufferPainter.drawText( 5 + textXOffset + shadowOffset, yText + 1, message );    bufferPainter.setPen( pal.color( QPalette::WindowText ) );    bufferPainter.drawText( 5 + textXOffset, yText, message );    // show widget and schedule a repaint    show();    update();    // close the message window after given mS    if ( durationMs > 0 )    {        if ( !m_timer )        {            m_timer = new QTimer( this );            m_timer->setSingleShot( true );            connect( m_timer, SIGNAL( timeout() ), SLOT( hide() ) );        }        m_timer->start( durationMs );    } else if ( m_timer )        m_timer->stop();}void PageViewMessage::paintEvent( QPaintEvent * e ){    // paint the internal pixmap over the widget    bitBlt( this, e->rect().topLeft(), &m_pixmap, e->rect() );}void PageViewMessage::mousePressEvent( QMouseEvent * /*e*/ ){    if ( m_timer )        m_timer->stop();    hide();}/*********************//** PageViewToolBar  *//*********************/class ToolBarButton : public QPushButton{    public:        static const int iconSize = 32;        static const int buttonSize = 40;        ToolBarButton( QWidget * parent, const ToolBarItem & item, const QPixmap & parentPix );        int buttonID() const { return m_id; }    protected:        void mouseMoveEvent( QMouseEvent * e );        void paintEvent( QPaintEvent * e );    private:        int m_id;        bool m_hovering;        const QPixmap & m_background;};ToolBarButton::ToolBarButton( QWidget * parent, const ToolBarItem & item, const QPixmap & pix )    : QPushButton( parent ), m_id( item.id ), m_hovering( false ), m_background( pix ){    setMouseTracking( true );    setCheckable( true );    resize( buttonSize, buttonSize );    setIconSize( QSize( iconSize, iconSize ) );    setIcon( DesktopIconSet( item.pixmap, iconSize ) );    setAttribute( Qt::WA_OpaquePaintEvent );    // set shortcut if defined    if ( !item.shortcut.isEmpty() )        setShortcut( QKeySequence( item.shortcut ) );    else        KAcceleratorManager::setNoAccel( this );    // if accel is set display it along name    QString accelString = shortcut().toString( QKeySequence::NativeText );    if ( !accelString.isEmpty() )        setToolTip( QString("%1 [%2]").arg( item.text ).arg( accelString ) );    else        setToolTip( item.text );}void ToolBarButton::mouseMoveEvent( QMouseEvent * e ){    // if hovering changes, update gfx    bool hover = QRect( 0, 0, width(), height() ) .contains( e->pos() );    if ( m_hovering != hover )    {        m_hovering = hover;        update();    }}void ToolBarButton::paintEvent( QPaintEvent * e ){    // if the button is pressed or we're hovering it, use QPushButton style    if ( isChecked() || m_hovering )    {        QPushButton::paintEvent( e );        return;    }    // draw button's pixmap over the parent's background (fake transparency)    QPainter p( this );    QRect backRect = e->rect();    backRect.translate( x(), y() );    p.drawPixmap( e->rect().topLeft(), m_background, backRect );    QStyleOptionButton opt;    opt.initFrom( this );    opt.features = QStyleOptionButton::Flat;    opt.icon = icon();    opt.iconSize = QSize( iconSize, iconSize );    opt.text = text();    style()->drawControl( QStyle::CE_PushButton, &opt, &p, this );}/* PageViewToolBar */static const int toolBarGridSize = 40;static const int toolBarRBMargin = 2;struct ToolBarPrivate{    // anchored widget and side    QWidget * anchorWidget;    PageViewToolBar::Side anchorSide;    // slide in/out stuff    QTimer * animTimer;    QPoint currentPosition;    QPoint endPosition;    bool hiding;    // background pixmap and buttons    QPixmap backgroundPixmap;    QLinkedList< ToolBarButton * > buttons;};PageViewToolBar::PageViewToolBar( QWidget * parent, QWidget * anchorWidget )    : QWidget( parent ), d( new ToolBarPrivate ){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -