/****************************************************************************
**
**  indeview_widget.h - of the IndeView project, see http://www.indeview.org
**
**
**  The IndeView application is a stand-alone viewer to display presentations
**  created by IndeView creator modules like IndeViewExport.bas or kpr2iv.sh.
**  -------------------------------------------------------------------------
**  This enables you to show OpenOffice/StarOffice or KOffice presentations
**  on machines where the respective presentation program is not available.
**
**
**  Copyright (C) 2003..2004 Michael & Karl-Heinz Zimmer.
**  All rights reserved.
**
**  This file is distributed under the terms of the
**  GNU Lesser General Public License version 2.1 as published by the
**  Free Software Foundation and appearing in the file LICENSE included
**  in the packaging of this file.
**
**  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
**  THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
**  PURPOSE.
**
**  See http://www.indeview.org for further information.
**
**  Contact info@indeview.org if any conditions of this
**  licensing are not clear to you.
**
**
**  Please consider sending
**  a little picture postcard to   Michael & Karl-Heinz Zimmer
**                                 Butzengasse 15
**                                 54343 Föhren
**                                 Germany
**
**  Your feedback will be very much appreciated: we would be glad about
**  receiving a visual representation of where on earth you are living
**  using our little module.
**
*****************************************************************************/

#ifndef INDEVIEW_WIDGET_H
#define INDEVIEW_WIDGET_H

#include <qwidget.h>
#include <qpixmap.h>
#include <qstring.h>
#include <qstringlist.h>

#include "indeview_enums.h"
#include "indeview_slides.h"


class IndeViewWidget : public QWidget
{
  Q_OBJECT

public:
  // If you want to grant this IndeViewWidget ownership of the slides,
  // set deleteSlidesWhenDone to true: then slides will be deleted
  // when the widget is closed.
  IndeViewWidget( IndeViewSlides* slides,
                  bool deleteSlidesWhenDone,
                  QWidget *parent=0, const char *name=0, int wFlags=0 );

  ~IndeViewWidget();

  // descendants of IndeViewWidget may overload these methods to draw
  // into the painter before / after the slide image is drawn
  //
  // thus you may add your drawings into IndeViewWidget's double buffered painter and avoid flicker
  //
  // of course drawing before makes only sense if your images are not entirely opaque
  virtual void processPainterBeforeDrawing( QPainter& );
  virtual void processPainterAfterDrawing(  QPainter& );

  // Use these to access the first/last/current
  // page of your presentation.
  const IndeViewSlide* rootSlide()const;
  const IndeViewSlide* lastSlide()const;
  const IndeViewSlide* curSlide()const;
  int curSlideIdx()const;

  // Use this to retrieve a list of all page titles in
  // the order in which they appear in the presentation
  QStringList slideNames()const;

  bool optionDontScale()const;
  bool optionDontStretch()const;

  int zoomLevel()const;
  int movedByX()const;
  int movedByY()const;

public slots:

  // Changes the slide set for an existing IndeViewWidget and
  // goes to the first page while (optionally) resetting move/zoom.
  //
  // If you want to grant this IndeViewWidget ownership of the slides,
  // set deleteSlidesWhenDone to true: then slides will be deleted
  // when the widget is closed.
  void setSlides( IndeViewSlides* slides,
                  bool deleteSlidesWhenDone,
                  bool resetMove=true,
                  bool resetZoom=true );

  // Goes to the first page and (optionally) resets move/zoom.
  void resetPresentation( bool resetMove=true,
                          bool resetZoom=true );

  // Sets the backgound color to be drawn behind the image.
  void setBackgroundColor( const QColor& bgColor );

  // Use this option to prevent the images from being scaled.
  // (scaling happens if there is no image file matching the
  //  size of the IndeViewWidget widget)
  void setOptionDontScale(   bool optionDontScale );

  // Use this potion to prevent the images from being stretched.
  // (stretching is done is the image was acaled but does not fit
  //  exactly into the widget, but ONLY if the image width (or
  //  height, resp.) is at least 90% of the widget width (or
  //  height, resp.)
  void setOptionDontStretch( bool optionDontStretch );

  // Number of horizontal pixels which shall remain visible
  // even if the slide has been moved completely to the left
  // (or to the right, resp.).  Default is 32.
  void setMinHorVisible( int minHorVisible );

  // Number of vertical pixels which shall remain visible
  // even if the slide has been moved completely to the left
  // (or to the right, resp.).  Default is 20.
  void setMinVertVisible( int minVertVisible );

  // Use these methods to switch between the pages of your presentation.
  void gotoNextSlide(  bool& bPageWasChanged );
  void gotoPrevSlide(  bool& bPageWasChanged );
  void gotoFirstSlide( bool& bPageWasChanged );
  void gotoLastSlide(  bool& bPageWasChanged );
  void gotoSlide( int slideIdx,
                  bool& bPageWasChanged );

  // Use this to move the page in horizontal and/or in vertical
  // direction.
  // It might be that IndeViewCode moves by less than the asked
  // amount if the image otherwise would become completely
  // invisible, therefor the realMove parameter returns the
  // amount by which the images actually was moved.
  void moveHoriVert( int askedX,
                     int askedY,
                     int& realMoveX,
                     int& realMoveY );
  void resetMove( bool& bWasMove );

  // Use this to increase/decrease the zoom level by n steps.
  // realDetla tells you by how many steps zooming was changed
  void changeZoom( int askedDelta,
                   int& realDelta );
  void resetZoom( bool& bWasZoom );


protected:
  void paintEvent( QPaintEvent * );

  void preLoadNextImage();
  int defaultX1( int width );
  int defaultX2( int width );
  int defaultY1( int height );
  int defaultY2( int height );
  void moveHorizontal( int askedMove,
                       int& realMove,
                       bool doUpdate=true );
  void moveVertical(   int askedMove,
                       int& realMove,
                       bool doUpdate=true );
  void gotoPage( const IndeViewSlide* slide,
                 bool& bPageWasChanged );

private:
  const IndeViewSlides* mSlides;
  bool mDeleteSlidesWhenDone;
  const IndeViewSlide* mCurSlide;
  QColor mBGColor;
  bool mOptionDontScale;
  bool mOptionDontStretch;
  int mMinHorVisible;
  int mMinVertVisible;
  int mDX;
  int mDY;
  int mZoom;
  QPixmap mScaledPix;
};


#endif // INDEVIEW_WIDGET_H
