Coverage for modules/org/openteacher/interfaces/qt/topoMaps/topoMaps : 46%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#! /usr/bin/env python3 # -*- coding: utf-8 -*-
# Copyright 2011-2012, Milan Boers # Copyright 2012-2013, Marten de Vries # # This file is part of OpenTeacher. # # OpenTeacher is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # OpenTeacher is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with OpenTeacher. If not, see <http://www.gnu.org/licenses/>.
global EnterMap, EnterMapScene, Map, TeachPictureMap, TeachPictureScene, TeachPlaceOnMap
"""Abstract class for the map widgets"""
self.setViewport(QtOpenGL.QGLWidget())
# Create a new scene self.scene = QtWidgets.QGraphicsScene() # Set the pixmap of the scene self.pixmap = QtGui.QPixmap(picture) self.scene.addPixmap(self.pixmap) # Set the scene self.setScene(self.scene)
# Scrolling makes it zoom if wheelevent.angleDelta().y() > 0: self.scale(1.1,1.1) else: self.scale(0.9,0.9)
"""A place on the map for the inverted order"""
super().__init__(*args, **kwargs)
width = 10 height = 10
self.setRect(place["x"] - width / 2, place["y"] - height / 2, width, height) self.setBrush(QtGui.QBrush(QtGui.QColor("red")))
self.place = place
"""The graphics scene of the map where you enter"""
# Get coordinates x = gsme.lastScenePos().x() y = gsme.lastScenePos().y() # If its in the map if x > 0 and y > 0: # Ask for the name name = QtWidgets.QInputDialog.getText(self.enterMap, _("Name for this place"), _("What's this place's name?")) if name[1] and name[0].strip() != u"": # Make the place place = { "id": int(), "name": name[0].strip(), "x": int(x), "y": int(y) } # Set id try: place["id"] = self.enterMap.enterWidget.list["items"][-1]["id"] + 1 except IndexError: place["id"] = 0 # And add the place self.enterMap.enterWidget.addPlace(place)
"""The map on the enter tab"""
# Make it scrollable and draggable
"""Override base class _setPicture with one that uses an EnterMapScene instead of QGraphicsScene
""" # Create a new scene # Set the pixmap of the scene # Set the scene
# Remove previous items for item in self.placesList: with contextlib.suppress(RuntimeError): #RuntimeError: Object already removed self.scene.removeItem(item)
# Remove all previous items self.placesList = []
# Add all the places for place in self.enterWidget.list["items"]: # Make the little rectangle rect = QtWidgets.QGraphicsRectItem(place["x"],place["y"],6,6) rect.setBrush(QtGui.QBrush(QtGui.QColor("red"))) # Place the rectangle in the list of items self.placesList.append(rect)
# Make the shadow of the text shadow = QtWidgets.QGraphicsTextItem(place["name"]) shadow.setFont(QtGui.QFont("sans-serif",15,75)) shadow.setPos(place["x"]+2,place["y"]+2) shadow.setDefaultTextColor(QtGui.QColor("black")) shadow.setOpacity(0.5) # Place the shadow in the list of items self.placesList.append(shadow)
item = QtWidgets.QGraphicsTextItem(place["name"]) item.setFont(QtGui.QFont("sans-serif",15,75)) item.setPos(place["x"],place["y"]) item.setDefaultTextColor(QtGui.QColor("red")) # Place the text in the list of items self.placesList.append(item)
# Place the list of items on the map self.placesGroup = self.scene.createItemGroup(self.placesList)
image = QtGui.QImage(self.scene.width(), self.scene.height(), QtGui.QImage.Format_RGB32) image.fill(QtGui.QColor(QtCore.Qt.white).rgb()) painter = QtGui.QPainter(image) self.scene.render(painter) painter.end() return image
"""Scene for the TeachPictureMap"""
super().__init__(*args, **kwargs)
self.pictureMap = pictureMap
# Clicked a place clickedObject = self.itemAt(event.lastScenePos().x(), event.lastScenePos().y(), QtGui.QTransform()) if clickedObject.__class__ == TeachPlaceOnMap: self.pictureMap.teachWidget.lesson.checkAnswer(clickedObject.place)
"""The map on the teach tab"""
# Not interactive # Make sure everything is redrawn every time
"""Sets the arrow on the map to the right position"""
self.centerOn(x-15,y-50) self.crosshair.setPos(x-15,y-50)
"""Removes the arrow"""
self.scene.removeItem(self.crosshair)
"""Overriding the base class _setPicture method with one using the TeachPictureScene"""
# Create a new scene self.scene = TeachPictureScene(self) # Set the pixmap of the scene self.pixmap = QtGui.QPixmap(picture) self.scene.addPixmap(self.pixmap) # Set the scene self.setScene(self.scene)
"""Shows all the places without names"""
placesList = []
for place in self.teachWidget.places["items"]: # Make the little rectangle rect = TeachPlaceOnMap(place) # Place the rectangle in the list of items placesList.append(rect)
self.placesGroup = self.scene.createItemGroup(placesList)
with contextlib.suppress(AttributeError): for item in self.placesList: self.removeItem(item)
if val: self.showPlaceRects() # Interactive self.interactive = True # Scrollbars self.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag) self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) else: self.hidePlaceRects() # Not interactive self.interactive = False # No scrollbars self.setDragMode(QtWidgets.QGraphicsView.NoDrag) self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) # Arrow crosshairPixmap = QtGui.QPixmap(base._mm.resourcePath("resources/crosshair.png")) self.crosshair = QtWidgets.QGraphicsPixmapItem(crosshairPixmap)
self.scene.addItem(self.crosshair)
global base
"default": 416, }
self._mm.mods(type="ui"), )
self._mm.mods(type="translator"), self._mm.mods(type="settings"), )
global QtCore, QtGui, QtWidgets, QtOpenGL except ImportError: return except ImportError: QtOpenGL = None
# Add settings except (AssertionError, IndexError): self._openGlSetting = {"value": False} else: "internal_name": "org.openteacher.lessons.topo.opengl", "type": "boolean", "defaultValue": False, "advanced": True, })
#setup translation else:
#install _ and ngettext global _ global ngettext
else: self._mm.resourcePath("translations") )
"name": _("OpenGL rendering"), "category": _("Lesson"), "subcategory": _("Topography"), })
|