Source Code (Use browser search to find items of interest.)

Class Index

kimage'KImageView (./koffice/kimage/kimage_view.h:30)

class KImageView : public KoView
{
  Q_OBJECT

public:
  KImageView( KImageDocument* doc, QWidget* _parent = 0, const char* _name = 0 );

  KImageDocument* doc();

protected slots:

  // edit action slots
  void undo();
  void redo();

  void editImportImage();
  void editExportImage();
  void editPageLayout();
  void editPreferences();

  // view action slots
  void viewZoomFactor();
  void viewFitToView();
  void viewFitWithProportions();
  void viewOriginalSize();
  void viewCentered();
  void viewScrollbars();
  void viewInformations();
  void viewBackgroundColor();

  // transform action slots
  void transformRotateRight();
  void transformRotateLeft();
  void transformRotateAngle();
  void transformFlipVertical();
  void transformFlipHorizontal();
  void transformZoomFactor();
  void transformZoomIn10();
  void transformZoomOut10();
  void transformZoomDouble();
  void transformZoomHalf();
  void transformZoomMax();
  void transformZoomMaxAspect();

  // help action slots
  void helpUsingHelp();

public slots:

  // Document signals
  void slotUpdateView();

protected:

  virtual void paintEvent( QPaintEvent* );

  virtual void updateReadWrite( bool readwrite );

private:

  // edit menu
  KAction *m_undo, *m_redo, *m_import, *m_export, *m_pageSetup, *m_preferences;

  // view menu
  KAction *m_viewFactor, *m_fitToView, *m_fitWithProps, *m_original, *m_center, *m_scrollbars, *m_info, *m_backgroundColor;

  // transform menu
  KAction *m_rotateRight, *m_rotateLeft, *m_rotateAngle, *m_flipVertical, *m_flipHorizontal;
  KAction *m_zoomFactor, *m_zoomIn10, *m_zoomOut10, *m_zoomDouble, *m_zoomHalf, *m_zoomMax, *m_zoomMaxAspect;

  // help menu
  KAction *m_helpUsing;
};

kimage'KImageView::KImageView() (./koffice/kimage/kimage_view.cc:48)

KImageView::KImageView( KImageDocument* _doc, QWidget* _parent, const char* _name )
  : KoView( _doc, _parent, _name )
{
  setInstance( KImageFactory::global() );
  setXMLFile( "kimage.rc" );

  QObject::connect( _doc, SIGNAL( sigUpdateView() ), this, SLOT( slotUpdateView() ) );

  // edit actions
  m_undo  = new KAction( i18n( "&Undo" ), KImageBarIcon( "undo" ), 0, this, SLOT( undo() ), actionCollection(), "undo" );
  m_redo  = new KAction( i18n( "&Redo" ), KImageBarIcon( "redo" ), 0, this, SLOT( redo() ), actionCollection(), "redo" );
  m_import = new KAction( i18n( "&Import image..." ), 0, this, SLOT( editImportImage() ), actionCollection(), "editImportImage" );
  m_export = new KAction( i18n( "&Export image..." ), 0, this, SLOT( editExportImage() ), actionCollection(), "editExportImage" );
  m_pageSetup   = new KAction( i18n( "Page &layout..." ), 0, this, SLOT( editPageLayout() ), actionCollection(), "editPageLayout" );
  m_preferences = new KAction( i18n( "Pr&eferences..." ), 0, this, SLOT( editPreferences() ), actionCollection(), "editPreferences" );

  // view actions
  m_viewFactor      = new KAction( i18n( "&Zoom view..." ), 0, this, SLOT( viewZoomFactor() ), actionCollection(), "viewZoomFactor" );
  m_fitToView       = new KAction( i18n( "&Fit image to view" ), KImageBarIcon( "fittoview" ), 0, this, SLOT( viewFitToView() ), actionCollection(), "viewFitToView" );
  m_fitWithProps    = new KAction( i18n( "&Fit image to view props" ), KImageBarIcon( "fitwithprops" ), 0, this, SLOT( viewFitWithProportions() ), actionCollection(), "viewFitWithProportions" );
  m_original        = new KAction( i18n( "&Original size" ), KImageBarIcon( "originalsize" ), 0, this, SLOT( viewOriginalSize() ), actionCollection(), "viewOriginalSize" );
  m_center          = new KAction( i18n( "&Center image" ), 0, this, SLOT( viewCentered() ), actionCollection(), "viewCentered" );
  m_scrollbars      = new KAction( i18n( "&Scrollbars" ), 0, this, SLOT( viewScrollbars() ), actionCollection(), "viewScrollbars" );
  m_info            = new KAction( i18n( "&Informations..." ), 0, this, SLOT( viewInformations() ), actionCollection(), "viewInformations" );
  m_backgroundColor = new KAction( i18n( "&Background color..." ), 0, this, SLOT( viewBackgroundColor() ), actionCollection(), "viewBackgroundColor" );

  // transform actions
  m_rotateRight    = new KAction( i18n( "Rotate &right" ), 0, this, SLOT( transformRotateRight() ), actionCollection(), "transformRotateRight" );
  m_rotateLeft     = new KAction( i18n( "Rotate &left" ), 0, this, SLOT( transformRotateLeft() ), actionCollection(), "transformRotateLeft" );
  m_rotateAngle    = new KAction( i18n( "Rotate &angle" ), 0, this, SLOT( transformRotateAngle() ), actionCollection(), "transformRotateAngle" );
  m_flipVertical   = new KAction( i18n( "Flip &vertical" ), 0, this, SLOT( transformFlipVertical() ), actionCollection(), "transformFlipVertical" );
  m_flipHorizontal = new KAction( i18n( "Flip &horizontal" ), 0, this, SLOT( transformFlipHorizontal() ), actionCollection(), "transformFlipHorizontal" );
  m_zoomFactor     = new KAction( i18n( "&Zoom..." ), 0, this, SLOT( transformZoomFactor() ), actionCollection(), "transformZoomFactor" );
  m_zoomIn10       = new KAction( i18n( "Zoom &in 10 %" ), 0, this, SLOT( transformZoomIn10() ), actionCollection(), "transformZoomIn10" );
  m_zoomOut10      = new KAction( i18n( "Zoom &out 10%" ), 0, this, SLOT( transformZoomOut10() ), actionCollection(), "transformZoomOut10" );
  m_zoomDouble     = new KAction( i18n( "Zoom &double" ), 0, this, SLOT( transformZoomDouble() ), actionCollection(), "transformZoomDouble" );
  m_zoomHalf       = new KAction( i18n( "Zoom &half" ), 0, this, SLOT( transformZoomHalf() ), actionCollection(), "transformZoomHalf" );
  m_zoomMax        = new KAction( i18n( "Zoom &max" ), 0, this, SLOT( transformZoomMax() ), actionCollection(), "transformZoomMax" );
  m_zoomMaxAspect  = new KAction( i18n( "Zoom max &aspect" ), 0, this, SLOT( transformZoomMaxAspect() ), actionCollection(), "transformZoomMaxAspect" );

  // help actions
  m_helpUsing = new KAction( i18n( "Contents..." ), 0, this, SLOT( helpUsingHelp() ), actionCollection(), "helpUsingHelp" );

  m_undo->setEnabled( false );
  m_redo->setEnabled( false );

  m_scrollbars->setEnabled( false );

  // FIXME: set the user preferred color
  //setBackgroundColor( darkBlue );

   slotUpdateView();
}


kimage'KImageView::paintEvent() (./koffice/kimage/kimage_view.cc:102)

void KImageView::paintEvent( QPaintEvent* /* _event */ )
{
  if( doc()->isEmpty() )
    return;

  QPainter painter;
  painter.begin( this );

  doc()->paintContent( painter, rect() );

  painter.end();
}


kimage'KImageView::updateReadWrite() (./koffice/kimage/kimage_view.cc:115)

void KImageView::updateReadWrite( bool readwrite )
{
#ifdef __GNUC__
#warning TODO
#endif
}


kimage'KImageView::doc() (./koffice/kimage/kimage_view.cc:122)

KImageDocument* KImageView::doc()
{
  return (KImageDocument*) koDocument();
}

/*
bool KImageView::printDlg()
{
  if( doc()->isEmpty() )
    return;

  QPrinter prt;

  if( QPrintDialog::getPrinterSetup( &prt ) )
  {
    doc()->print( &prt );
  }
  return true;
}
*/


kimage'KImageView::undo() (./koffice/kimage/kimage_view.cc:143)

void KImageView::undo()
{
  // TODO: undo
}


kimage'KImageView::redo() (./koffice/kimage/kimage_view.cc:148)

void KImageView::redo()
{
  // TODO: redo
}


kimage'KImageView::editImportImage() (./koffice/kimage/kimage_view.cc:153)

void KImageView::editImportImage()
{
  KURL url = KFileDialog::getOpenURL( getenv( "HOME" ), KImageIO::pattern( KImageIO::Reading ) );

  // TODO: use file preview dialog
  //KURL url = KFilePreviewDialog::getOpenURL( getenv( "HOME" ), KImageIO::pattern( KImageIO::Reading ), 0 );

  if( url.isEmpty() )
    return;

  /*
  QString tempFile;

  KIO::NetAccess::download( url, tempFile );

  if( !KImageIO::isSupported( KImageIO::mimeType( tempFile ) ) )
  {
    if( !doc()->openURL( tempFile ) )
    {
      QString tmp;
      tmp.sprintf( i18n( "Could not open\n%s" ), url.path().data() );
      QMessageBox::critical( 0L, i18n( "IO Error" ), tmp, i18n( "OK" ) );
    }

    KIO::NetAccess::removeTempFile( tempFile );

    slotUpdateView();
  }*/

  //David: KParts takes care of the network transparency

    if( !doc()->openURL( url ) )
    {
      KMessageBox::sorry( 0L, i18n( "Could not open\n%1" ).arg(url.url()) );
    }
    slotUpdateView();
}


kimage'KImageView::editExportImage() (./koffice/kimage/kimage_view.cc:191)

void KImageView::editExportImage()
{
  if( doc()->image().isNull() )
    return;

  // TODO: export image to a special format
  // slotFileSaveAs();
}


kimage'KImageView::editPreferences() (./koffice/kimage/kimage_view.cc:200)

void KImageView::editPreferences()
{
  KImagePreferencesDialog dlg;

  int result = dlg.exec();
  if( result != QDialog::Accepted )
    return;
}


kimage'KImageView::editPageLayout() (./koffice/kimage/kimage_view.cc:209)

void KImageView::editPageLayout()
{
  if( doc()->isEmpty() )
  {
    QMessageBox::critical( this, i18n( "KImage Error" ), i18n( "The document is empty.\nEditing page layout not possible." ), i18n( "OK" ) );
    return;
  }

  doc()->paperLayoutDlg();
}


kimage'KImageView::viewFitToView() (./koffice/kimage/kimage_view.cc:220)

void KImageView::viewFitToView()
{
  if( doc()->image().isNull() )
    return;

  doc()->setDrawMode( KImageDocument::FitToView );
  slotUpdateView();
}


kimage'KImageView::viewFitWithProportions() (./koffice/kimage/kimage_view.cc:229)

void KImageView::viewFitWithProportions()
{
  if( doc()->image().isNull() )
    return;

  doc()->setDrawMode( KImageDocument::FitWithProps );
  slotUpdateView();
}


kimage'KImageView::viewOriginalSize() (./koffice/kimage/kimage_view.cc:238)

void KImageView::viewOriginalSize()
{
  if( doc()->image().isNull() )
    return;

  doc()->setDrawMode( KImageDocument::OriginalSize );
  slotUpdateView();
}


kimage'KImageView::viewInformations() (./koffice/kimage/kimage_view.cc:247)

void KImageView::viewInformations()
{
  if( doc()->isEmpty() )
  {
    QMessageBox::critical( this, i18n( "KImage Error" ), i18n( "The document is empty.\nNo information available." ), i18n( "OK" ) );
    return;
  }

  QString tmp;

  // TODO: show mimetype here
  tmp.sprintf( i18n( "X-Size : %i\nY-Size : %i\n\nColor depth : %i\n" ),
    doc()->image().size().width(),
    doc()->image().size().height(),
    doc()->image().depth() );
  KMessageBox::information( this, tmp, i18n( "Image information" ) );
}


kimage'KImageView::viewZoomFactor() (./koffice/kimage/kimage_view.cc:265)

void KImageView::viewZoomFactor()
{
  if( doc()->isEmpty() )
  {
    QMessageBox::critical( this, i18n( "KImage Error" ), i18n("The document is empty.\nAction not available."), i18n( "OK" ) );
    return;
  }

  KZoomFactorDialog dlg( NULL, "Set zoom factor - KImage" );
  QPoint factor = doc()->zoomFactor();

  if( dlg.getValue( factor ) != QDialog::Accepted )
    return;

  doc()->setZoomFactor( factor );

  kDebugInfo( 0, "zoom factor: X: %i, Y: %i", factor.x(), factor.y() );

  doc()->setDrawMode( KImageDocument::ZoomFactor );
  slotUpdateView();
}


kimage'KImageView::viewCentered() (./koffice/kimage/kimage_view.cc:287)

void KImageView::viewCentered()
{
  if( doc()->isEmpty() )
  {
    QMessageBox::critical( this, i18n( "KImage Error" ), i18n("The document is empty.\nAction not available."), i18n( "OK" ) );
    return;
  }

  if( doc()->positionMode() == KImageDocument::Center )
    doc()->setPositionMode( KImageDocument::LeftTop );
  else
    doc()->setPositionMode( KImageDocument::Center );
  slotUpdateView();
}


kimage'KImageView::viewScrollbars() (./koffice/kimage/kimage_view.cc:302)

void KImageView::viewScrollbars()
{
  // TODO: implement scrollbars
  // click scrollbars on/off
}


kimage'KImageView::viewBackgroundColor() (./koffice/kimage/kimage_view.cc:308)

void KImageView::viewBackgroundColor()
{
  KColorDialog dlg;
  QColor color;

  if( dlg.getColor( color ) )
  {
    setBackgroundColor( color );
    slotUpdateView();
  }
}


kimage'KImageView::transformRotateRight() (./koffice/kimage/kimage_view.cc:320)

void KImageView::transformRotateRight()
{
  kDebugInfo( 0, "Rotate Right" );

  QWMatrix matrix;
  matrix.rotate( 90 );
  doc()->transformImage( matrix );
}


kimage'KImageView::transformRotateLeft() (./koffice/kimage/kimage_view.cc:329)

void KImageView::transformRotateLeft()
{
  kDebugInfo( 0, "Rotate Left" );

  QWMatrix matrix;
  matrix.rotate( -90 );
  doc()->transformImage( matrix );
}


kimage'KImageView::transformRotateAngle() (./koffice/kimage/kimage_view.cc:338)

void KImageView::transformRotateAngle()
{
  kDebugInfo( 0, "Rotate Angle" );

  int angle = 0;
  KIntegerInputDialog dlg( NULL, "KImage", i18n( "Enter angle:" ) );

  if( dlg.getValue( angle ) != QDialog::Accepted )
    return;
  if( angle == 0 )
    return;

  QWMatrix matrix;
  matrix.rotate( angle );
  doc()->transformImage( matrix );
}


kimage'KImageView::transformFlipVertical() (./koffice/kimage/kimage_view.cc:355)

void KImageView::transformFlipVertical()
{
  kDebugInfo( 0, "flipVertical" );

  QWMatrix matrix;
  QWMatrix matrix2( 1.0F, 0.0F, 0.0F, -1.0F, 0.0F, 0.0F);
  matrix *= matrix2;
  doc()->transformImage( matrix );
}


kimage'KImageView::transformFlipHorizontal() (./koffice/kimage/kimage_view.cc:365)

void KImageView::transformFlipHorizontal()
{
  kDebugInfo( 0, "flipHorizontal" );

  QWMatrix matrix;
  QWMatrix matrix2( 1.0F, 0.0F, 0.0F, -1.0F, 0.0F, 0.0F);
  matrix2.rotate( 180 );
  matrix *= matrix2;
  doc()->transformImage( matrix );
}


kimage'KImageView::transformZoomFactor() (./koffice/kimage/kimage_view.cc:376)

void KImageView::transformZoomFactor()
{
  kDebugInfo( 0, "Zoom Factor" );

  QWMatrix matrix;
  int factor = (int)(matrix.m11() * 100 );
  KIntegerInputDialog dlg( NULL, "KImage", i18n( "Enter Zoom factor (100 = 1x):" ) );
  if( dlg.getValue( factor ) != QDialog::Accepted )
    return;
  if( ( factor <= 0 ) || ( factor == 100 ) )
    return;
  double val = (double)factor/100;
  matrix.scale( val, val );
  doc()->transformImage( matrix );

}


kimage'KImageView::transformZoomIn10() (./koffice/kimage/kimage_view.cc:393)

void KImageView::transformZoomIn10()
{
  kDebugInfo( 0, "Zoom In 10" );

  QWMatrix matrix;
  matrix.scale( 1.1, 1.1 );
  doc()->transformImage( matrix );

}


kimage'KImageView::transformZoomOut10() (./koffice/kimage/kimage_view.cc:403)

void KImageView::transformZoomOut10()
{
  kDebugInfo( 0, "Zoom Out 10" );

  QWMatrix matrix;
  matrix.scale( 0.9, 0.9 );
  doc()->transformImage( matrix );
}


kimage'KImageView::transformZoomDouble() (./koffice/kimage/kimage_view.cc:412)

void KImageView::transformZoomDouble()
{
  kDebugInfo( 0, "Zoom Double" );

  QWMatrix matrix;
  matrix.scale( 2.0, 2.0 );
  doc()->transformImage( matrix );
}


kimage'KImageView::transformZoomHalf() (./koffice/kimage/kimage_view.cc:421)

void KImageView::transformZoomHalf()
{
  kDebugInfo( 0, "Zoom Half" );

  QWMatrix matrix;
  matrix.scale( 0.5, 0.5 );
  doc()->transformImage( matrix );
}


kimage'KImageView::transformZoomMax() (./koffice/kimage/kimage_view.cc:430)

void KImageView::transformZoomMax()
{
  kDebugInfo( 0, "Zoom Max" );

  QWMatrix matrix;
  double dw = (double) width() / (double) doc()->image().width();
  double dh = (double) height() / (double) doc()->image().height();
  matrix.scale( dw, dh );
  doc()->transformImage( matrix );
}


kimage'KImageView::transformZoomMaxAspect() (./koffice/kimage/kimage_view.cc:441)

void KImageView::transformZoomMaxAspect()
{
  kDebugInfo( 0, "Zoom Max Aspect" );

  QWMatrix matrix;
  double dw = (double) width() / (double) doc()->image().width();
  double dh = (double) height() / (double) doc()->image().height();
  double d = ( dh < dw ? dh : dw );
  matrix.scale( d, d );
  doc()->transformImage( matrix );
}


kimage'KImageView::helpUsingHelp() (./koffice/kimage/kimage_view.cc:453)

void KImageView::helpUsingHelp()
{
  kapp->invokeHTMLHelp( "kimage/kimage.html", QString::null );
}


kimage'KImageView::slotUpdateView() (./koffice/kimage/kimage_view.cc:458)

void KImageView::slotUpdateView()
{
  if( doc()->isEmpty() )
    return;

  QWidget::update();
}