libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

split_image_renderer.h (2575B)


      1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
      2 //
      3 // Use of this source code is governed by a BSD-style
      4 // license that can be found in the LICENSE file.
      5 
      6 #ifndef TOOLS_COMPARISON_VIEWER_SPLIT_IMAGE_RENDERER_H_
      7 #define TOOLS_COMPARISON_VIEWER_SPLIT_IMAGE_RENDERER_H_
      8 
      9 #include <QImage>
     10 #include <QKeyEvent>
     11 #include <QMouseEvent>
     12 #include <QPaintEvent>
     13 #include <QPixmap>
     14 #include <QVariantAnimation>
     15 #include <QWheelEvent>
     16 #include <QWidget>
     17 
     18 namespace jpegxl {
     19 namespace tools {
     20 
     21 struct SplitImageRenderingSettings {
     22   int fadingMSecs;
     23   bool gray;
     24   int grayMSecs;
     25 };
     26 
     27 class SplitImageRenderer : public QWidget {
     28   Q_OBJECT
     29 
     30  public:
     31   enum class RenderingMode {
     32     // The default mode when using the mouse: one (partial) image is shown on
     33     // each side of the cursor, with a vertical band of the middle image if
     34     // applicable.
     35     SPLIT,
     36     // Only show the left image (accessed by pressing the left arrow key when
     37     // the renderer has focus).
     38     LEFT,
     39     // Only show the right image (accessed by pressing the right arrow key).
     40     RIGHT,
     41     // Only show the middle image (accessed by pressing the up or down arrow
     42     // key).
     43     MIDDLE,
     44   };
     45   Q_ENUM(RenderingMode)
     46 
     47   explicit SplitImageRenderer(QWidget* parent = nullptr);
     48   ~SplitImageRenderer() override = default;
     49 
     50   QSize sizeHint() const override { return minimumSize(); }
     51 
     52   void setLeftImage(QImage image);
     53   void setRightImage(QImage image);
     54   void setMiddleImage(QImage image);
     55 
     56   void setRenderingSettings(const SplitImageRenderingSettings& settings);
     57 
     58  public slots:
     59   void setMiddleWidthPercent(int percent);
     60   void setZoomLevel(double scale);
     61 
     62  signals:
     63   void zoomLevelIncreaseRequested();
     64   void zoomLevelDecreaseRequested();
     65 
     66   void renderingModeChanged(RenderingMode newMode);
     67 
     68  protected:
     69   void keyPressEvent(QKeyEvent* event) override;
     70   void mouseMoveEvent(QMouseEvent* event) override;
     71   void wheelEvent(QWheelEvent* event) override;
     72   void paintEvent(QPaintEvent* event) override;
     73 
     74  private:
     75   void updateMinimumSize();
     76   void setRenderingMode(RenderingMode newMode);
     77 
     78   QPixmap leftImage_, rightImage_, middleImage_;
     79   RenderingMode mode_ = RenderingMode::SPLIT;
     80   RenderingMode previousMode_ = RenderingMode::SPLIT;
     81   SplitImageRenderingSettings renderingSettings_;
     82   // Goes from 0 to the animation duration in milliseconds, as a float.
     83   QVariantAnimation fadingPoint_;
     84   int middleX_ = 0;
     85   int middleWidthPercent_ = 10;
     86   double scale_ = 1.;
     87 };
     88 
     89 }  // namespace tools
     90 }  // namespace jpegxl
     91 
     92 #endif  // TOOLS_COMPARISON_VIEWER_SPLIT_IMAGE_RENDERER_H_