summaryrefslogtreecommitdiffstats
path: root/kghostview/scrollbox.cpp
blob: 0246e89369de0b23d2789c8a6daf4ed5e5ffa73d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/** 
 * Copyright (C) 1997-2002 the KGhostView authors. See file AUTHORS.
 * 	
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <tqdrawutil.h>
#include <tqpainter.h>
#include <tqpixmap.h>

#include "scrollbox.h"

ScrollBox::ScrollBox( TQWidget* parent, const char* name )
    : TQFrame( parent, name )
{
    setFrameStyle( Panel | Sunken );
}

void ScrollBox::mousePressEvent( TQMouseEvent* e )
{
    mouse = e->pos();
    if( e->button() == Qt::RightButton )
	emit button3Pressed();
    if( e->button() == Qt::MidButton )
	emit button2Pressed();
}

void ScrollBox::mouseMoveEvent( TQMouseEvent* e )
{
    if( e->state() != Qt::LeftButton )
	return;

    int dx = ( e->pos().x() - mouse.x() ) * pagesize.width()  / width();
    int dy = ( e->pos().y() - mouse.y() ) * pagesize.height() / height();

    // Notify the word what the view position has changed
    // The word in turn will notify as that view position has changed
    // Even if coordinates are out of range TQScrollView handles
    // this properly
    emit valueChanged( TQPoint( viewpos.x() + dx, viewpos.y() + dy ) );
    emit valueChangedRelative( dx, dy );

    mouse = e->pos();
}

void ScrollBox::resizeEvent( TQResizeEvent * )
{
    if ( paletteBackgroundPixmap() ) {
	TQPixmap pm;
	pm.convertFromImage(paletteBackgroundPixmap()->convertToImage().smoothScale( size() ));
	setPaletteBackgroundPixmap( pm );
    }
}

void ScrollBox::drawContents( TQPainter* paint )
{
    if ( pagesize.isEmpty() )
	return;


    /* FIXME:
     *
     * The logic below is flawed because the page info given to us
     * contains the borders used for page decoration, while we assume
     * that it means only the actual displayed document.
     *
     */

    TQRect c( contentsRect() );

    paint -> setPen( TQt::red );

    int len = pagesize.width();
    int x = c.x() + c.width() * viewpos.x() / len;
    int w = c.width() * viewsize.width() / len ;
    if ( w > c.width() ) w = c.width();

    len = pagesize.height();
    int y = c.y() + c.height() * viewpos.y() / len;
    int h = c.height() * viewsize.height() / len;
    if ( h > c.height() ) h = c.height();

    paint->drawRect( x, y, w, h );
}

void ScrollBox::setPageSize( const TQSize& s )
{
    pagesize = s;
    setFixedHeight( s.height() * width() / s.width() );
    tqrepaint();
}

void ScrollBox::setViewSize( const TQSize& s )
{
    viewsize = s;
    tqrepaint();
}

void ScrollBox::setViewPos( const TQPoint& pos )
{
    viewpos = pos;
    tqrepaint();
}

void ScrollBox::setThumbnail( TQPixmap img )
{
    // The line below is needed to work around certain "features" of styles such as liquid
    // see bug:61711 for more info (LPC, 20 Aug '03)
    setBackgroundOrigin( TQWidget::WidgetOrigin );
    TQPixmap pm;
    pm.convertFromImage(img.convertToImage().smoothScale( size() ));
    setPaletteBackgroundPixmap( pm );
}

void ScrollBox::clear()
{
    unsetPalette();
}

#include "scrollbox.moc"

// vim:sw=4:sts=4:ts=8:noet