File indexing completed on 2024-10-13 10:59:28
0001 /*************************************************************************** 0002 * Copyright (C) 2005-2006 David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #ifndef ITEMVIEW_H 0012 #define ITEMVIEW_H 0013 0014 #include <view.h> 0015 0016 #include <QPointer> 0017 #include <canvas.h> 0018 0019 class Canvas; 0020 class CVBEditor; 0021 class Item; 0022 class ItemDocument; 0023 class QTimer; 0024 0025 /** 0026 @author David Saxton 0027 */ 0028 class ItemView : public View 0029 { 0030 Q_OBJECT 0031 public: 0032 ItemView(ItemDocument *itemDocument, ViewContainer *viewContainer, uint viewAreaId); 0033 ~ItemView() override; 0034 0035 bool canZoomIn() const override; 0036 bool canZoomOut() const override; 0037 CVBEditor *cvbEditor() const 0038 { 0039 return m_CVBEditor; 0040 } 0041 /** 0042 * @returns The zoom level 0043 */ 0044 double zoomLevel() const 0045 { 0046 return m_zoomLevel; 0047 } 0048 /** 0049 * When the user drags from an item selector into the item view, the 0050 * item will be created and shown to the user. This function returns 0051 * that item. 0052 */ 0053 Item *dragItem() const 0054 { 0055 return m_pDragItem; 0056 } 0057 /** 0058 * Zoom in. The point center will remain fixed. 0059 */ 0060 void zoomIn(const QPoint ¢er); 0061 /** 0062 * Zoom in. The point center will remain fixed. 0063 */ 0064 void zoomOut(const QPoint ¢er); 0065 /** 0066 * Converts a mouse click position (in the contents coordinates) to the 0067 * associated position on the canvas. 0068 */ 0069 QPoint mousePosToCanvasPos(const QPoint &contentsClick) const; 0070 0071 public slots: 0072 void actualSize() override; 0073 void zoomIn(); 0074 void zoomOut(); 0075 void scrollToMouse(const QPoint &pos); 0076 virtual void updateStatus(); 0077 0078 protected slots: 0079 /** 0080 * Called when the user changes the configuration. 0081 */ 0082 void slotUpdateConfiguration() override; 0083 void startUpdatingStatus(); 0084 void stopUpdatingStatus(); 0085 0086 protected: 0087 /** 0088 * If the user drags an acceptable item in (e.g. a component in a 0089 * circuit), then call this function to create the item and have it 0090 * moved when the user moves his mouse while dragging. 0091 */ 0092 void createDragItem(QDragEnterEvent *event); 0093 void removeDragItem(); 0094 void updateZoomActions(); 0095 0096 public: 0097 /** 0098 * Attempts to create a new CNItem if one was dragged onto the canvas 0099 */ 0100 void dropEvent(QDropEvent *event) override; 0101 /** 0102 * Reinherit to allow different types of items to be dragged in. 0103 */ 0104 void dragEnterEvent(QDragEnterEvent *event) override; 0105 void dragLeaveEvent(QDragLeaveEvent *event) override; 0106 void dragMoveEvent(QDragMoveEvent *event) override; 0107 void contentsMousePressEvent(QMouseEvent *e); 0108 void contentsMouseReleaseEvent(QMouseEvent *e); 0109 void contentsMouseDoubleClickEvent(QMouseEvent *e); 0110 void contentsMouseMoveEvent(QMouseEvent *e); 0111 void contentsWheelEvent(QWheelEvent *e); 0112 void enterEvent(QEvent *e) override; 0113 void leaveEvent(QEvent *e) override; 0114 0115 void requestDocumentResizeToCanvasItems(); 0116 0117 protected: 0118 QPointer<ItemDocument> p_itemDocument; 0119 CVBEditor *m_CVBEditor; 0120 double m_zoomLevel; 0121 QTimer *m_pUpdateStatusTmr; 0122 Item *m_pDragItem; 0123 0124 // friend class CVBEditor; // 2018.09.26 0125 }; 0126 0127 /** 0128 @author David Saxton 0129 */ 0130 class CVBEditor : public KtlQCanvasView 0131 { 0132 Q_OBJECT 0133 public: 0134 CVBEditor(Canvas *canvas, ItemView *itemView); 0135 0136 void setPassEventsToView(bool pass) 0137 { 0138 b_passEventsToView = pass; 0139 } 0140 bool event(QEvent *e) override; 0141 void contentsWheelEvent(QWheelEvent *e) override; 0142 /** 0143 * Updates the world matrix from ItmeView's zoom level and from Canvas' 0144 * offset. 0145 */ 0146 void updateWorldMatrix(); 0147 0148 protected slots: 0149 void canvasResized(const QRect &oldSize, const QRect &newSize); 0150 0151 protected: 0152 void viewportResizeEvent(QResizeEvent *) override; 0153 ItemView *p_itemView; 0154 bool b_passEventsToView; 0155 bool b_ignoreEvents; 0156 Canvas *m_pCanvas; 0157 }; 0158 0159 #endif