File indexing completed on 2024-05-05 17:19:00
0001 /*************************************************************************** 0002 * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr 0003 * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 ***************************************************************************/ 0006 #ifndef SKGGRAPHICSVIEW_H 0007 #define SKGGRAPHICSVIEW_H 0008 /** @file 0009 * A Graphic view with more functionalities. 0010 * 0011 * @author Stephane MANKOWSKI / Guillaume DE BURE 0012 */ 0013 0014 0015 #include <qtimer.h> 0016 #include <qwidget.h> 0017 0018 #include "skgbasegui_export.h" 0019 #include "ui_skggraphicsview.h" 0020 0021 class QGraphicsScene; 0022 class QGraphicsView; 0023 class QMenu; 0024 class QAction; 0025 0026 /** 0027 * This file is a Graphic view with more functionalities 0028 */ 0029 class SKGBASEGUI_EXPORT SKGGraphicsView : public QWidget 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 /** 0035 * Default Constructor 0036 * @param iParent the parent 0037 */ 0038 explicit SKGGraphicsView(QWidget* iParent); 0039 0040 /** 0041 * Default Destructor 0042 */ 0043 ~SKGGraphicsView() override; 0044 0045 /** 0046 * Set current scene 0047 * @param iScene The scene 0048 */ 0049 void setScene(QGraphicsScene* iScene); 0050 0051 /** 0052 * Get the internal Graphic view 0053 * @return the internal Graphic view 0054 */ 0055 QGraphicsView* graphicsView(); 0056 0057 /** 0058 * Set the visibility of the ToolBar 0059 * @param iVisibility visibility 0060 */ 0061 void setToolBarVisible(bool iVisibility); 0062 0063 /** 0064 * Get the visibility of the ToolBar 0065 * @return visibility 0066 */ 0067 bool isToolBarVisible() const; 0068 0069 /** 0070 * Add a widget in the toolbar 0071 * @param iWidget widget 0072 */ 0073 void addToolbarWidget(QWidget* iWidget); 0074 0075 /** 0076 * Get the current state 0077 * @return a string containing all information needed to set the same state. 0078 * Could be an XML stream 0079 */ 0080 QString getState() const; 0081 0082 /** 0083 * Set the current state 0084 * MUST BE OVERWRITTEN 0085 * @param iState must be interpreted to set the state of the widget 0086 */ 0087 void setState(const QString& iState); 0088 0089 /** 0090 * Get a pointer on the contextual menu 0091 * @return contextual menu 0092 */ 0093 QMenu* getContextualMenu() const; 0094 0095 public Q_SLOTS: 0096 /** 0097 * Set the zoom 0098 */ 0099 void onZoom(); 0100 0101 /** 0102 * Print 0103 */ 0104 void onPrint(); 0105 0106 /** 0107 * Export to a file 0108 * @param iFileName the file name 0109 */ 0110 void exportInFile(const QString& iFileName); 0111 0112 /** 0113 * Export 0114 */ 0115 void onExport(); 0116 0117 /** 0118 * Copy 0119 */ 0120 void onCopy(); 0121 0122 /** 0123 * Swith tool bar visibility 0124 */ 0125 void onSwitchToolBarVisibility(); 0126 0127 /** 0128 * Set antialiasing 0129 * @param iAntialiasing enabled or disabled 0130 */ 0131 void setAntialiasing(bool iAntialiasing); 0132 0133 /** 0134 * Reinitialize zoom 0135 */ 0136 void initializeZoom(); 0137 0138 Q_SIGNALS: 0139 /** 0140 * View is resized 0141 */ 0142 void resized(); 0143 0144 /** 0145 * The tool bar visibily changed 0146 */ 0147 void toolBarVisiblyChanged(); 0148 0149 protected: 0150 /** 0151 * Event filtering 0152 * @param iObject object 0153 * @param iEvent event 0154 * @return In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false. 0155 */ 0156 bool eventFilter(QObject* iObject, QEvent* iEvent) override; 0157 0158 private Q_SLOTS: 0159 void showMenu(QPoint iPos); 0160 0161 private: 0162 Q_DISABLE_COPY(SKGGraphicsView) 0163 Ui::skggraphicview_base ui{}; 0164 0165 double m_oscale; 0166 0167 QMenu* m_mainMenu{}; 0168 QAction* m_actZoomOriginal{}; 0169 QAction* m_actShowToolBar; 0170 QAction* m_actAntialiasing{}; 0171 bool m_toolBarVisible; 0172 QTimer m_timer; 0173 }; 0174 0175 #endif // SKGGRAPHICSVIEW_H