File: MyWidget.py

package info (click to toggle)
kddockwidgets 2.4.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,412 kB
  • sloc: cpp: 50,019; ansic: 765; python: 239; xml: 61; makefile: 17; sh: 7
file content (55 lines) | stat: -rw-r--r-- 1,764 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# This file is part of KDDockWidgets.
#
# SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# Author: Renato Araujo Oliveira Filho <renato.araujo@kdab.com>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
#
# Contact KDAB at <info@kdab.com> for commercial licensing options.
#

# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring

from PySide6 import QtWidgets, QtGui, QtCore

# pylint: disable=too-few-public-methods


class MyWidget(QtWidgets.QWidget):
    s_images = {}

    def __init__(self, backgroundFile="", logoFile="", parent=None):
        super().__init__(parent)

        self.background = self._lookupImage(backgroundFile)
        self.logo = self._lookupImage(logoFile)

    # pylint: disable=no-self-use
    def _lookupImage(self, imageName):
        if imageName == "":
            return None

        if imageName not in MyWidget.s_images:
            MyWidget.s_images[imageName] = QtGui.QImage(imageName)

        return MyWidget.s_images[imageName]

    def drawLogo(self, p):

        if not self.logo:
            return

        ratio = self.logo.height() / (self.logo.width() * 1.0)
        maxWidth = int(0.80 * self.size().width())
        maxHeight = int(0.80 * self.size().height())
        proposedHeight = int(maxWidth * ratio)
        if proposedHeight <= maxHeight:
            width = maxWidth
        else:
            width = int(maxHeight / ratio)

        height = int(width * ratio)
        targetLogoRect = QtCore.QRect(0, 0, width, height)
        targetLogoRect.moveCenter(self.rect().center(
        ) + QtCore.QPoint(0, -int(self.size().height() * 0.00)))
        p.drawImage(targetLogoRect, self.logo, self.logo.rect())