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 from PyQt4.QtGui import (
29 QPainter,
30 QGraphicsView,
31 QGraphicsScene,
32 QColor, QPixmap,
33 QGraphicsPixmapItem,
34 )
35 from PyQt4.QtCore import Qt
36
37 from camelot.view.art import Pixmap
38
39
41 from PyQt4.QtCore import QCoreApplication
42 return QCoreApplication.instance().desktop()
43
46
48 d = get_desktop()
49 dh = d.height()
50 dw = d.width()
51 if dh < pixmap.height() or dw < pixmap.width():
52 fit = .95
53 return pixmap.scaled(dw * fit, dh * fit, Qt.KeepAspectRatio)
54 return pixmap
55
56
58
59 - def __init__(self, pixmap=None, hover_pixmap=None, parent=None):
60 super(CloseMark, self).__init__(parent)
61
62 DEFAULT_PIXMAP = Pixmap('close_mark.png').getQPixmap()
63 DEFAULT_HOVER_PIXMAP = Pixmap('close_mark_hover.png').getQPixmap()
64
65 self._pixmap = pixmap or DEFAULT_PIXMAP
66 self._hover_pixmap = hover_pixmap or DEFAULT_HOVER_PIXMAP
67
68 self.setPixmap(self._pixmap)
69
70
71 width = self.pixmap().width()
72 height = self.pixmap().height()
73 parent_width = self.parentItem().boundingRect().width()
74 self.setPos(-width/2 + parent_width, -height/2)
75
76 self.setAcceptsHoverEvents(True)
77
78 self.setZValue(10)
79
81 self.setPixmap(self._hover_pixmap)
82 self.update()
83
85 self.setPixmap(self._pixmap)
86 self.update()
87
89 view = self.scene().views()[0]
90 view.close()
91
92
94
95 ALPHA = QColor(0, 0, 0, 192)
96
98 super(LiteBoxView, self).__init__(parent)
99 self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
100 self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
101 self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
102
103 self.desktopshot = None
104
105
106 self.setRenderHint(QPainter.Antialiasing)
107 self.setRenderHint(QPainter.TextAntialiasing)
108
109 self.scene = QGraphicsScene()
110 self.setScene(self.scene)
111
113 if self.desktopshot is None:
114 self.desktopshot = get_desktop_pixmap()
115
116 painter.drawPixmap(self.mapToScene(0, 0), self.desktopshot)
117 painter.setBrush(LiteBoxView.ALPHA)
118 painter.drawRect(rect)
119
121 """:param path: path to an svg file"""
122 from PyQt4 import QtSvg
123 item = QtSvg.QGraphicsSvgItem(path)
124 self.show_fullscreen_item(item)
125
127 """:param image: a QImage"""
128 pixmap = QPixmap.fromImage(image)
129 item = QGraphicsPixmapItem(pixmap)
130 self.show_fullscreen_item(item)
131
133 """:param item: a QGraphicsItem to be shown fullscreen"""
134 self.scene.clear()
135 self.scene.addItem(item)
136 CloseMark(parent=item)
137 self.showFullScreen()
138