File indexing completed on 2025-03-09 03:52:08
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2007-11-14 0007 * Description : a presentation tool. 0008 * 0009 * SPDX-FileCopyrightText: 2007-2009 by Valerio Fuoglio <valerio dot fuoglio at gmail dot com> 0010 * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * Parts of this code are based on 0013 * smoothslidesaver by Carsten Weinhold <carsten dot weinhold at gmx dot de> 0014 * and slideshowgl by Renchi Raju <renchi dot raju at gmail dot com> 0015 * 0016 * SPDX-License-Identifier: GPL-2.0-or-later 0017 * 0018 * ============================================================ */ 0019 0020 #ifndef DIGIKAM_PRESENTATION_KB_H 0021 #define DIGIKAM_PRESENTATION_KB_H 0022 0023 // C++ includes 0024 0025 #ifndef Q_CC_MSVC 0026 # include <cstdlib> 0027 #else 0028 # include <winsock2.h> 0029 #endif 0030 0031 // Qt includes 0032 0033 #include <QList> 0034 #include <QKeyEvent> 0035 #include <QMap> 0036 #include <QMouseEvent> 0037 #include <QPair> 0038 #include <QString> 0039 #include <QStringList> 0040 #include <QTimer> 0041 #include <QOpenGLWidget> 0042 #include <QOpenGLTexture> 0043 #include <QRandomGenerator> 0044 0045 namespace DigikamGenericPresentationPlugin 0046 { 0047 0048 class PresentationContainer; 0049 0050 class KBViewTrans 0051 { 0052 0053 public: 0054 0055 KBViewTrans(bool zoomIn, float relAspect); 0056 KBViewTrans(); 0057 ~KBViewTrans(); 0058 0059 float transX(float pos) const; 0060 float transY(float pos) const; 0061 float scale(float pos) const; 0062 float xScaleCorrect() const; 0063 float yScaleCorrect() const; 0064 0065 private: 0066 0067 double rnd() const; 0068 double rndSign() const; 0069 0070 private: 0071 0072 /// delta and scale values (begin to end) and the needed offsets 0073 double m_deltaX; 0074 double m_deltaY; 0075 double m_deltaScale; 0076 double m_baseScale; 0077 double m_baseX; 0078 double m_baseY; 0079 float m_xScale; 0080 float m_yScale; 0081 }; 0082 0083 // ------------------------------------------------------------------------- 0084 0085 class KBImage 0086 { 0087 0088 public: 0089 0090 explicit KBImage(KBViewTrans* const viewTrans, float aspect = 1.0); 0091 ~KBImage(); 0092 0093 public: 0094 0095 KBViewTrans* m_viewTrans; 0096 float m_aspect; 0097 float m_pos; 0098 float m_opacity; 0099 bool m_paint; 0100 QOpenGLTexture* m_texture; 0101 }; 0102 0103 // ------------------------------------------------------------------------- 0104 0105 class PresentationKB : public QOpenGLWidget 0106 { 0107 Q_OBJECT 0108 0109 public: 0110 0111 explicit PresentationKB(PresentationContainer* const sharedData); 0112 0113 ~PresentationKB() override; 0114 0115 static QStringList effectNames(); 0116 static QMap<QString, QString> effectNamesI18N(); 0117 0118 bool checkOpenGL() const; 0119 0120 private: 0121 0122 float aspect() const; 0123 bool setupNewImage(int imageIndex); 0124 void startSlideShowOnce(); 0125 void swapImages(); 0126 void setNewKBEffect(); 0127 void endOfShow(); 0128 0129 void applyTexture(KBImage* const img, const QImage& image); 0130 void paintTexture(KBImage* const img); 0131 unsigned suggestFrameRate(unsigned forceRate); 0132 0133 void readSettings(); 0134 0135 protected: 0136 0137 void initializeGL() override; 0138 void paintGL() override; 0139 void resizeGL(int w, int h) override; 0140 0141 void mousePressEvent(QMouseEvent*) override; 0142 void mouseMoveEvent(QMouseEvent*) override; 0143 void keyPressEvent(QKeyEvent*) override; 0144 0145 private Q_SLOTS: 0146 0147 void moveSlot(); 0148 void slotMouseMoveTimeOut(); 0149 void slotClose(); 0150 0151 private: 0152 0153 // Disable 0154 explicit PresentationKB(QWidget*) = delete; 0155 0156 private: 0157 0158 class Private; 0159 Private* const d; 0160 0161 friend class KBEffect; 0162 }; 0163 0164 } // namespace DigikamGenericPresentationPlugin 0165 0166 #endif // DIGIKAM_PRESENTATION_KB_H