File indexing completed on 2024-05-05 16:39:02

0001 /* This file is part of the KDE project
0002    Copyright (C) 1998-2003 Carsten Pfeiffer <pfeiffer@kde.org>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License as published by the Free Software Foundation, version 2.
0007 
0008    This program is distributed in the hope that it will be useful,
0009    but WITHOUT ANY WARRANTY; without even the implied warranty of
0010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0011     General Public License for more details.
0012 
0013    You should have received a copy of the GNU General Public License
0014    along with this program; see the file COPYING.  If not, write to
0015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0016    Boston, MA 02110-1301, USA.
0017 */
0018 
0019 #ifndef IMAGEWINDOW_H
0020 #define IMAGEWINDOW_H
0021 
0022 #include <QString>
0023 
0024 #include "imlibwidget.h"
0025 
0026 class KActionCollection;
0027 class QContextMenuEvent;
0028 class QCursor;
0029 class QDragEnterEvent;
0030 class QDropEvent;
0031 class QFocusEvent;
0032 class QKeyEvent;
0033 class QMenu;
0034 class QMouseEvent;
0035 class QResizeEvent;
0036 class QSize;
0037 class QUrl;
0038 class QWheelEvent;
0039 class QWidget;
0040 class KuickFile;
0041 
0042 
0043 class ImageWindow : public ImlibWidget
0044 {
0045   Q_OBJECT
0046 
0047 public:
0048   ImageWindow( ImData *_idata, ImlibData *id, QWidget *parent=0 );
0049   ImageWindow( ImData *_idata=0, QWidget *parent=0 );
0050   ~ImageWindow();
0051 
0052   bool      showNextImage( KuickFile * file );
0053   bool      showNextImage( const QUrl& url );
0054   void      scrollImage( int, int, bool restrict=true );
0055   void      setFullscreen( bool );
0056   bool      isFullscreen()  const { return myIsFullscreen; }
0057 
0058   void          addBrightness( int );
0059   void      addContrast( int );
0060   void      addGamma( int );
0061 
0062   void      updateActions();
0063 
0064   KActionCollection * actionCollection() const { return m_actions; }
0065 
0066   /**
0067    * Resizes image to @p w, @p h, but takes into account the workarea, so
0068    * it won't ever get a bigger size than the workarea.
0069    */
0070   void resizeOptimal( int w, int h );
0071   void autoScale( KuickImage *kuim );
0072   virtual bool autoRotate(KuickImage *kuim) override;
0073 
0074   bool          saveImage( const QUrl& dest, bool keepOriginalSize );
0075 
0076 public slots:
0077   void      zoomIn();
0078   void      zoomOut();
0079   void          moreBrightness();
0080   void          lessBrightness();
0081   void          moreContrast();
0082   void          lessContrast();
0083   void          moreGamma();
0084   void          lessGamma();
0085   void      scrollUp();
0086   void      scrollDown();
0087   void      scrollLeft();
0088   void      scrollRight();
0089   void          printImage();
0090   void      toggleFullscreen();
0091   void      maximize();
0092   void      imageDelete();
0093   void      imageTrash();
0094 
0095 signals:
0096   void      sigFocusWindow( ImageWindow * );
0097   // go advance images back/forth
0098   void          requestImage( ImageWindow *, int advance );
0099   void          deleteImage(ImageWindow *viewer);
0100   void          trashImage(ImageWindow *viewer);
0101   void      nextSlideRequested();
0102   void      prevSlideRequested();
0103 
0104 protected:
0105 
0106   void      init();
0107   void      centerImage();
0108   virtual void  updateGeometry( int imWidth, int imHeight ) override;
0109   virtual void  loaded( KuickImage *, bool wasCached ) override;
0110   virtual bool  canZoomTo( int newWidth, int newHeight ) override;
0111   virtual void  rotated( KuickImage *kuim, int rotation ) override;
0112 
0113   virtual void  wheelEvent( QWheelEvent * ) override;
0114   virtual void  keyPressEvent( QKeyEvent * ) override;
0115   virtual void  keyReleaseEvent( QKeyEvent * ) override;
0116   virtual void  mousePressEvent( QMouseEvent * ) override;
0117   virtual void  mouseReleaseEvent( QMouseEvent * ) override;
0118   virtual void  mouseMoveEvent( QMouseEvent * ) override;
0119   virtual void  focusInEvent( QFocusEvent * ) override;
0120   virtual void  resizeEvent( QResizeEvent * ) override;
0121   virtual void  dragEnterEvent( QDragEnterEvent * ) override;
0122   virtual void  dropEvent( QDropEvent * ) override;
0123   virtual void  contextMenuEvent( QContextMenuEvent * ) override;
0124 
0125   void          showWindow();
0126   enum KuickCursor { DefaultCursor = 0, ZoomCursor, MoveCursor };
0127   void  updateCursor( KuickCursor cursor = DefaultCursor );
0128 
0129   // popupmenu entries
0130   uint      itemViewerZoomMax, itemViewerZoomOrig, itemViewerZoomIn;
0131   uint          itemViewerZoomOut, itemViewerFlipH, itemViewerProps;
0132   uint      itemRotate90, itemRotate180, itemRotate270;
0133   uint      itemViewerFlipV, itemViewerPrint;
0134   uint          itemViewerSave, itemViewerClose;
0135   uint      itemBrightnessPlus, itemBrightnessMinus;
0136   uint      itemContrastPlus, itemContrastMinus;
0137   uint      itemGammaPlus, itemGammaMinus;
0138 
0139 
0140   uint      xmove, ymove;   // used for scrolling the image with the mouse
0141   int       xpos, ypos;     // top left corner of the image
0142   int       xzoom, yzoom;  // used for zooming the image with the mouse
0143   uint      xposPress, yposPress;
0144 
0145 
0146   QMenu    *viewerMenu, *gammaMenu, *brightnessMenu, *contrastMenu;
0147   QWidget       *transWidget;
0148 
0149 
0150 protected slots:
0151   void      saveImage();
0152   void          slotRequestNext()           { emit requestImage( this, +1 ); }
0153   void          slotRequestPrevious()       { emit requestImage( this, -1 ); }
0154   void          reload();
0155   void          slotProperties();
0156   void          pauseSlideShow();
0157   virtual void  setBusyCursor();
0158   virtual void  restoreCursor();
0159 
0160 signals:
0161   void          pauseSlideShowSignal();
0162 
0163 private:
0164   int       desktopWidth( bool totalScreen = false ) const;
0165   int       desktopHeight( bool totalScreen = false ) const;
0166   QSize     maxImageSize() const;
0167   void          setupActions();
0168   void      setPopupMenu();
0169   bool          isCursorHidden() const;
0170 
0171   bool      myIsFullscreen;
0172   int           m_numHeads;
0173   QString   m_saveDirectory;
0174 
0175   KActionCollection *m_actions;
0176 
0177   static QCursor * s_handCursor;
0178 };
0179 
0180 
0181 #endif // IMAGEWINDOW_H