diff --git a/soitool/main_window.py b/soitool/main_window.py index 2abe6dce5b822ff081816d3ce5b1f7c475613545..2a50c4d2daf3953e286e9011cc3765674019500f 100644 --- a/soitool/main_window.py +++ b/soitool/main_window.py @@ -1,11 +1,11 @@ """Hovedvinduet.""" import sys import os -from PySide2.QtCore import QRectF, QPoint, QTimer +from PySide2.QtCore import QRectF, QPoint, QTimer, Qt from PySide2.QtWidgets import QTabWidget, QWidget, QMainWindow, QApplication, \ QHBoxLayout, QVBoxLayout, QPushButton, QTreeWidget, QGraphicsScene, \ - QGraphicsView, QAction -from PySide2 import QtGui + QGraphicsView, QAction, QScrollArea, QGraphicsRectItem +from PySide2.QtGui import QBrush, QIcon, QPalette class MainWindow(QMainWindow): @@ -92,7 +92,7 @@ class MainWindow(QMainWindow): filename = 'media/HVlogo.PNG' dirname = os.path.dirname(__file__) filepath = os.path.join(dirname, filename) - self.setWindowIcon(QtGui.QIcon(filepath)) + self.setWindowIcon(QIcon(filepath)) class MainWidget(QWidget): @@ -135,10 +135,43 @@ class ViewArea(QWidget): def __init__(self): super().__init__() - self.layout = QHBoxLayout() + self.layout = QHBoxLayout(self) + self.scroll_area = QScrollArea(self) + # necessary to make the scroll area fill the space it's given + self.scroll_area.setWidgetResizable(True) + + # scene and view widgets self.scene = QGraphicsScene() + self.setup_scene() + self.view = QGraphicsView(self.scene) + self.view.scale(0.50, 0.50) + + self.scroll_area.setWidget(self.view) + self.layout.addWidget(self.scroll_area) + self.setLayout(self.layout) + + self.launch_auto_zoom() + + def setup_scene(self): + """Prepare scene for use. + + Draws borders, background, etc. + """ self.scene.setSceneRect(QRectF(0, 0, self.WIDTH, self.HEIGHT)) + + # sets the background color of the scene to be the appropriate + # system-specific background color + # source: https://stackoverflow.com/a/23880531/3545896 + # source: https://stackoverflow.com/questions/15519749/how-to-get-widget-background-qcolor + self.scene.setBackgroundBrush(app.palette().color(QPalette.Window)) + + # color the page white + page_background = QGraphicsRectItem(0, 0, self.WIDTH, self.HEIGHT) + page_background.setBrush(QBrush(Qt.white)) + self.scene.addItem(page_background) + + # draw borders self.scene.addRect(0, 0, self.WIDTH, self.HEIGHT) self.scene.addRect(self.PADDING, self.PADDING, self.CONTENT_WIDTH, self.CONTENT_HEIGHT) @@ -147,14 +180,6 @@ class ViewArea(QWidget): self.scene.addRect(self.PADDING, self.PADDING, self.CONTENT_WIDTH, self.HEADER_HEIGHT) - self.view = QGraphicsView(self.scene) - self.view.scale(0.50, 0.50) - - self.layout.addWidget(self.view) - self.setLayout(self.layout) - - self.launch_auto_zoom() - def launch_auto_zoom(self): """Zoom in a regular interval.