File indexing completed on 2024-04-28 05:38:13
0001 /*************************************************************************** 0002 * Copyright (C) 2007 by Romain Campioni * 0003 * Copyright (C) 2009 by Renaud Guezennec * 0004 * https://rolisteam.org/contact * 0005 * * 0006 * rolisteam is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, write to the * 0018 * Free Software Foundation, Inc., * 0019 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0020 ***************************************************************************/ 0021 0022 #ifndef IMAGE_H 0023 #define IMAGE_H 0024 0025 #include <QAction> 0026 #include <QFile> 0027 #include <QImage> 0028 #include <QLabel> 0029 #include <QPointer> 0030 #include <QScrollArea> 0031 #include <QString> 0032 #include <QWidget> 0033 #include <memory> 0034 0035 #include "preferences/preferencesmanager.h" 0036 #include "rwidgets/mediacontainers/mediacontainer.h" 0037 #include "rwidgets_global.h" 0038 0039 class NetworkLink; 0040 class NetworkMessageWriter; 0041 class QShortcut; 0042 class ImageController; 0043 /** 0044 * @brief The Image class displays image to the screen. It also manages image from Internet and the zooming. 0045 */ 0046 class RWIDGET_EXPORT Image : public MediaContainer 0047 { 0048 Q_OBJECT 0049 public: 0050 explicit Image(ImageController* ctrl, QWidget* parent= nullptr); 0051 /** 0052 * @brief ~Image destructor. 0053 */ 0054 virtual ~Image(); 0055 /** 0056 * @brief setInternalAction may not be useful anymore. 0057 * @param action 0058 */ 0059 void setInternalAction(QAction* action); 0060 QAction* getAssociatedAction() const; 0061 bool isImageOwner(QString id); 0062 void setParent(QWidget* parent); 0063 void setImage(QImage& img); 0064 0065 protected: 0066 /** 0067 * @brief called when users roll the wheel of their mouse 0068 * @param event : define few parameters about the action (way,..) 0069 */ 0070 void wheelEvent(QWheelEvent* event); 0071 0072 /** 0073 * @brief resizeEvent make sure the window keep the right ratio. 0074 */ 0075 void resizeEvent(QResizeEvent* event); 0076 0077 // void closeEvent(QCloseEvent *event); 0078 void mousePressEvent(QMouseEvent* event); 0079 void mouseReleaseEvent(QMouseEvent* event); 0080 void mouseMoveEvent(QMouseEvent* event); 0081 void contextMenuEvent(QContextMenuEvent* event); 0082 void paintEvent(QPaintEvent* event); 0083 0084 protected slots: 0085 virtual void updateTitle(); 0086 private slots: 0087 /** 0088 * @brief refresh the size of the label (which embeds the picture) 0089 */ 0090 void resizeLabel(); 0091 /** 0092 * @brief fitWindow set the size of the picture at the best size of the window. 0093 */ 0094 void fitWindow(); 0095 0096 private: 0097 /** 0098 * @brief adapt the size window to fit the MdiArea size and no scrollbar (if possible) 0099 */ 0100 void fitWorkSpace(); 0101 void createActions(); 0102 void initImage(); 0103 0104 private: 0105 QPointer<ImageController> m_ctrl; 0106 QLabel* m_imageLabel; 0107 std::unique_ptr<QScrollArea> m_widgetArea; 0108 QPoint m_startingPoint; 0109 int m_horizontalStart; 0110 int m_verticalStart; 0111 bool m_allowedMove; 0112 QSize m_NormalSize; 0113 QSize m_windowSize; 0114 0115 QAction* m_actionZoomIn; 0116 QShortcut* m_zoomInShort; 0117 0118 QAction* m_actionZoomOut; 0119 QShortcut* m_zoomOutShort; 0120 0121 QAction* m_actionfitWorkspace; 0122 QShortcut* m_fitShort; 0123 0124 QAction* m_actionNormalZoom; // *1 0125 QShortcut* m_normalShort; 0126 0127 QAction* m_actionBigZoom; // * 4 0128 QShortcut* m_bigShort; 0129 0130 QAction* m_actionlittleZoom; // * 0.2 0131 QShortcut* m_littleShort; 0132 0133 // fit window keeping ratio 0134 QAction* m_fitWindowAct; // * 0.2 0135 QAction* m_playAct; 0136 QAction* m_stopAct; 0137 QAction* m_rename; 0138 0139 QShortcut* m_fitWindowShort; 0140 0141 double m_ratioImage; 0142 double m_ratioImageBis; 0143 }; 0144 0145 #endif