summaryrefslogtreecommitdiffstats
path: root/kghostview/scrollbox.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit47d455dd55be855e4cc691c32f687f723d9247ee (patch)
tree52e236aaa2576bdb3840ebede26619692fed6d7d /kghostview/scrollbox.cpp
downloadtdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz
tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kghostview/scrollbox.cpp')
-rw-r--r--kghostview/scrollbox.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/kghostview/scrollbox.cpp b/kghostview/scrollbox.cpp
new file mode 100644
index 00000000..8be3ab61
--- /dev/null
+++ b/kghostview/scrollbox.cpp
@@ -0,0 +1,129 @@
+/**
+ * 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 <qdrawutil.h>
+#include <qpainter.h>
+#include <qpixmap.h>
+
+#include "scrollbox.h"
+
+ScrollBox::ScrollBox( QWidget* parent, const char* name )
+ : QFrame( parent, name )
+{
+ setFrameStyle( Panel | Sunken );
+}
+
+void ScrollBox::mousePressEvent( QMouseEvent* e )
+{
+ mouse = e->pos();
+ if( e->button() == RightButton )
+ emit button3Pressed();
+ if( e->button() == MidButton )
+ emit button2Pressed();
+}
+
+void ScrollBox::mouseMoveEvent( QMouseEvent* e )
+{
+ if( e->state() != 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 QScrollView handles
+ // this properly
+ emit valueChanged( QPoint( viewpos.x() + dx, viewpos.y() + dy ) );
+ emit valueChangedRelative( dx, dy );
+
+ mouse = e->pos();
+}
+
+void ScrollBox::resizeEvent( QResizeEvent * )
+{
+ if ( paletteBackgroundPixmap() )
+ setPaletteBackgroundPixmap( paletteBackgroundPixmap()->convertToImage().smoothScale( size() ) );
+}
+
+void ScrollBox::drawContents( QPainter* 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.
+ *
+ */
+
+ QRect c( contentsRect() );
+
+ paint -> setPen( Qt::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 QSize& s )
+{
+ pagesize = s;
+ setFixedHeight( s.height() * width() / s.width() );
+ repaint();
+}
+
+void ScrollBox::setViewSize( const QSize& s )
+{
+ viewsize = s;
+ repaint();
+}
+
+void ScrollBox::setViewPos( const QPoint& pos )
+{
+ viewpos = pos;
+ repaint();
+}
+
+void ScrollBox::setThumbnail( QPixmap 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( QWidget::WidgetOrigin );
+ setPaletteBackgroundPixmap( img.convertToImage().smoothScale( size() ) );
+}
+
+void ScrollBox::clear()
+{
+ unsetPalette();
+}
+
+#include "scrollbox.moc"
+
+// vim:sw=4:sts=4:ts=8:noet