#!/usr/bin/env python3
#-*- coding: utf-8 -*-

from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy, QMenu, QPushButton, QCheckBox
from PyQt5.QtGui import QPalette
from .View import View
from PyQt5.QtCore import pyqtSignal, Qt, QMargins, QRect
from ..Util import qPixmapToNumpy

class _StatusBar(QLabel):
    def __init__(self):
        super().__init__()

class _Display(QWidget):
    markSet = pyqtSignal((int, int))
    selectionSet = pyqtSignal(QRect)

    def __init__(self, label=None):
        super().__init__()
        self._maximized = True
        self._hidden = False
        self._label = label
        self.initUI()

    def initUI(self):
        lay = QVBoxLayout()
        lay.setSpacing(0)
        lay.setContentsMargins(0, 0, 0, 0)

        self._headlayout = QHBoxLayout()

        self._headline = QLabel()
        self._headline.setFixedHeight(15)
        self._headline.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self._headline.setAlignment(Qt.AlignCenter)
        self._headlayout.addWidget(self._headline)

        self._includeSaveCheckbox = QCheckBox()
        self._includeSaveCheckbox.setStyleSheet('padding: 0; margin: 0; height: 10px; font: 10px')
        self._headlayout.addWidget(self._includeSaveCheckbox)

        self._hideButton = QPushButton()
        self._hideButton.setText('Hide')
        self._hideButton.setStyleSheet('padding: 0; margin: 0; height: 10px; font: 10px')
        self._hideButton.clicked.connect(self.toggleHidden)
        self._headlayout.addWidget(self._hideButton)

        self._headWidget = QWidget()
        self._headWidget.setLayout(self._headlayout)
        self._headlayout.setContentsMargins(QMargins(0,0,0,0))
        lay.addWidget(self._headWidget)

        self._view = View()
        self._view.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        pal=QPalette()
        pal.setColor(QPalette.Background, Qt.black)
        self._view.setPalette(pal)
        self._view.setStyleSheet('background-color: #555555')
        lay.addWidget(self._view)

        self._view.markSet.connect(self.setMark)
        self._view.markSet.connect(self.markSet)

        self._view.selectionSet.connect(self.setSelection)
        self._view.selectionSet.connect(self.selectionSet)

        self._controls = QWidget()
        self._controls.setFixedHeight(40)
        self._controls.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        lay.addWidget(self._controls)

        self._status = _StatusBar()
        self._status.setFixedHeight(15)
        self._status.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self._status.setStyleSheet('background-color: #c0c0c0')
        lay.addWidget(self._status)

        self.setLayout(lay)

        self.setStyleSheet('background-color: #dddddd')

        self._contextMenu = QMenu(self)

    def view(self): return self._view

    def image(self): return self.view().data().image()
    def previewImage(self): return qPixmapToNumpy(self._view.previewPixmap())
    def selectedImage(self): return self.view().selectedImage()

    def executeAction(self, action):
        pass

    def setMark(self, x, y):
        self._view.setMark(x, y)

    def setSelection(self, rect):
        self._view.setSelection(rect)

    def contextMenuEvent(self, event):
        action = self._contextMenu.exec_(self.mapToGlobal(event.pos()))
        self.executeAction(action)

    def setMaximized(self, value):
        self._maximized = value

        if self._maximized:
            # self._headWidget.show()
            self._controls.show()
            self._status.show()
        else:
            # self._headWidget.hide()
            self._controls.hide()
            self._status.hide()

    def setZoomOriginal(self, value):
        self._view.setZoomOriginal(value)

    def toggleHidden(self):
        if self._hidden:
            self._hidden = False
            self._controls.show()
            self._status.show()
            self._view.show()
            self._hideButton.setText('Hide')
            self.setSizePolicy(self._sizePolicy)
            self._headline.show()
        else:
            self._hidden = True
            self._controls.hide()
            self._status.hide()
            self._view.hide()
            self._hideButton.setText('Show')
            self._sizePolicy = self.sizePolicy()
            self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
            self._headline.hide()

    def includeInSave(self):
        return self._includeSaveCheckbox.isChecked()

    def showIdleMessage(self):
        pass

    def setHeadline(self, text):
        self._headline.setText(text)

    def getHeadline(self):
        return self._headline.text()

    def setStatusMessage(self, text):
        self._status.setText(text)
#!/usr/bin/env python3
#-*- coding: utf-8 -*-

from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy, QMenu, QPushButton, QCheckBox
from PyQt5.QtGui import QPalette
from .View import View
from PyQt5.QtCore import pyqtSignal, Qt, QMargins, QRect
from ..Util import qPixmapToNumpy

class _StatusBar(QLabel):
    def __init__(self):
        super().__init__()

class _Display(QWidget):
    markSet = pyqtSignal((int, int))
    selectionSet = pyqtSignal(QRect)

    def __init__(self, label=None):
        super().__init__()
        self._maximized = True
        self._hidden = False
        self._label = label
        self.initUI()

    def initUI(self):
        lay = QVBoxLayout()
        lay.setSpacing(0)
        lay.setContentsMargins(0, 0, 0, 0)

        self._headlayout = QHBoxLayout()

        self._headline = QLabel()
        self._headline.setFixedHeight(15)
        self._headline.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self._headline.setAlignment(Qt.AlignCenter)
        self._headlayout.addWidget(self._headline)

        self._includeSaveCheckbox = QCheckBox()
        self._includeSaveCheckbox.setStyleSheet('padding: 0; margin: 0; height: 10px; font: 10px')
        self._headlayout.addWidget(self._includeSaveCheckbox)

        self._hideButton = QPushButton()
        self._hideButton.setText('Hide')
        self._hideButton.setStyleSheet('padding: 0; margin: 0; height: 10px; font: 10px')
        self._hideButton.clicked.connect(self.toggleHidden)
        self._headlayout.addWidget(self._hideButton)

        self._headWidget = QWidget()
        self._headWidget.setLayout(self._headlayout)
        self._headlayout.setContentsMargins(QMargins(0,0,0,0))
        lay.addWidget(self._headWidget)

        self._view = View()
        self._view.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        pal=QPalette()
        pal.setColor(QPalette.Background, Qt.black)
        self._view.setPalette(pal)
        self._view.setStyleSheet('background-color: #555555')
        lay.addWidget(self._view)

        self._view.markSet.connect(self.setMark)
        self._view.markSet.connect(self.markSet)

        self._view.selectionSet.connect(self.setSelection)
        self._view.selectionSet.connect(self.selectionSet)

        self._controls = QWidget()
        self._controls.setFixedHeight(40)
        self._controls.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        lay.addWidget(self._controls)

        self._status = _StatusBar()
        self._status.setFixedHeight(15)
        self._status.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self._status.setStyleSheet('background-color: #c0c0c0')
        lay.addWidget(self._status)

        self.setLayout(lay)

        self.setStyleSheet('background-color: #dddddd')

        self._contextMenu = QMenu(self)

    def view(self): return self._view

    def image(self): return self.view().data().image()
    def previewImage(self): return qPixmapToNumpy(self._view.previewPixmap())
    def selectedImage(self): return self.view().selectedImage()

    def executeAction(self, action):
        pass

    def setMark(self, x, y):
        self._view.setMark(x, y)

    def setSelection(self, rect):
        self._view.setSelection(rect)

    def contextMenuEvent(self, event):
        action = self._contextMenu.exec_(self.mapToGlobal(event.pos()))
        self.executeAction(action)

    def setMaximized(self, value):
        self._maximized = value

        if self._maximized:
            # self._headWidget.show()
            self._controls.show()
            self._status.show()
        else:
            # self._headWidget.hide()
            self._controls.hide()
            self._status.hide()

    def setZoomOriginal(self, value):
        self._view.setZoomOriginal(value)

    def toggleHidden(self):
        if self._hidden:
            self._hidden = False
            self._controls.show()
            self._status.show()
            self._view.show()
            self._hideButton.setText('Hide')
            self.setSizePolicy(self._sizePolicy)
            self._headline.show()
        else:
            self._hidden = True
            self._controls.hide()
            self._status.hide()
            self._view.hide()
            self._hideButton.setText('Show')
            self._sizePolicy = self.sizePolicy()
            self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
            self._headline.hide()

    def includeInSave(self):
        return self._includeSaveCheckbox.isChecked()

    def showIdleMessage(self):
        pass

    def setHeadline(self, text):
        self._headline.setText(text)

    def getHeadline(self):
        return self._headline.text()

    def setStatusMessage(self, text):
        self._status.setText(text)
#!/usr/bin/env python3 #-*- coding: utf-8 -*- #555555') #c0c0c0') #dddddd') # self._headWidget.show() # self._headWidget.hide()