src/glrenderer.cpp

changeset 1247
7e1ce2fc066b
parent 1246
0054d13ed614
child 1248
8059668a2cf3
equal deleted inserted replaced
1246:0054d13ed614 1247:7e1ce2fc066b
69 m_compiler = new GLCompiler (this); 69 m_compiler = new GLCompiler (this);
70 m_toolTipTimer = new QTimer (this); 70 m_toolTipTimer = new QTimer (this);
71 m_toolTipTimer->setSingleShot (true); 71 m_toolTipTimer->setSingleShot (true);
72 setAcceptDrops (true); 72 setAcceptDrops (true);
73 connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (showCameraIconTooltip())); 73 connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (showCameraIconTooltip()));
74 connect(model, SIGNAL(aboutToRemoveObject(LDObject*)), this, SLOT(removeObject(LDObject*)));
75 resetAllAngles(); 74 resetAllAngles();
76 m_needZoomToFit = true; 75 m_needZoomToFit = true;
77 76
78 // Init camera icons 77 // Init camera icons
79 for (Camera camera : iterateEnum<Camera>()) 78 for (Camera camera : iterateEnum<Camera>())
189 } 188 }
190 189
191 /* 190 /*
192 * Returns the object currently highlighted by the cursor. 191 * Returns the object currently highlighted by the cursor.
193 */ 192 */
194 LDObject* GLRenderer::objectAtCursor() const 193 QPersistentModelIndex GLRenderer::objectAtCursor() const
195 { 194 {
196 return m_objectAtCursor; 195 return m_objectAtCursor;
197 } 196 }
198 197
199 // ============================================================================= 198 // =============================================================================
796 // Restore line thickness 795 // Restore line thickness
797 glLineWidth(m_config->lineThickness()); 796 glLineWidth(m_config->lineThickness());
798 } 797 }
799 } 798 }
800 799
801 // =============================================================================
802 //
803 void GLRenderer::removeObject(LDObject* object)
804 {
805 if (m_objectAtCursor == object)
806 m_objectAtCursor = nullptr;
807 }
808
809 /* 800 /*
810 * Returns an image containing the current render of the scene. 801 * Returns an image containing the current render of the scene.
811 */ 802 */
812 QImage GLRenderer::screenCapture() 803 QImage GLRenderer::screenCapture()
813 { 804 {
934 925
935 // ============================================================================= 926 // =============================================================================
936 // 927 //
937 void GLRenderer::highlightCursorObject() 928 void GLRenderer::highlightCursorObject()
938 { 929 {
939 if (not m_config->highlightObjectBelowCursor() and objectAtCursor() == nullptr) 930 if (not m_config->highlightObjectBelowCursor() and not objectAtCursor().isValid())
940 return; 931 return;
941 932
942 LDObject* newObject = nullptr; 933 QModelIndex newIndex;
943 LDObject* oldObject = objectAtCursor(); 934 QModelIndex oldIndex = m_objectAtCursor;
944 qint32 newIndex; 935
945 936 if (not m_isCameraMoving and m_config->highlightObjectBelowCursor())
946 if (m_isCameraMoving or not m_config->highlightObjectBelowCursor())
947 {
948 newIndex = 0;
949 }
950 else
951 { 937 {
952 setPicking (true); 938 setPicking (true);
953 drawGLScene(); 939 drawGLScene();
954 setPicking (false); 940 setPicking (false);
955 941
956 unsigned char pixel[4]; 942 unsigned char pixel[4];
957 glReadPixels (m_mousePosition.x(), height() - m_mousePosition.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel[0]); 943 glReadPixels (m_mousePosition.x(), height() - m_mousePosition.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel[0]);
958 newIndex = pixel[0] * 0x10000 | pixel[1] * 0x100 | pixel[2]; 944 qint32 id = pixel[0] * 0x10000 | pixel[1] * 0x100 | pixel[2];
959 } 945
960 946 if (id != 0)
961 if (newIndex != (oldObject ? oldObject->id() : 0)) 947 newIndex = model()->indexFromId(id);
962 { 948 }
963 if (newIndex != 0) 949
964 newObject = LDObject::fromID (newIndex); 950 if (newIndex != oldIndex)
965 951 {
966 m_objectAtCursor = newObject; 952 m_objectAtCursor = newIndex;
967 953 emit objectHighlightingChanged(oldIndex, newIndex);
968 if (oldObject)
969 emit objectHighlightingChanged(oldObject);
970
971 if (newObject)
972 emit objectHighlightingChanged(newObject);
973 } 954 }
974 955
975 update(); 956 update();
976 } 957 }
977 958

mercurial