Krita Source Code Documentation
Loading...
Searching...
No Matches
photobash_images.photobash_images_modulo Namespace Reference

Classes

class  Photobash_Button
 
class  Photobash_Display
 

Functions

 customMouseMoveEvent (self, event)
 
 customPaintEvent (instance, event)
 
 customSetImage (instance, image)
 

Variables

int DRAG_DELTA = 30
 
 FAVOURITE_TRIANGLE
 
 pixmap
 
 PREVIOUS_DRAG_X
 
 qimage
 
int TRIANGLE_SIZE = 20
 

Function Documentation

◆ customMouseMoveEvent()

photobash_images.photobash_images_modulo.customMouseMoveEvent ( self,
event )

Definition at line 93 of file photobash_images_modulo.py.

93def customMouseMoveEvent(self, event):
94 if event.modifiers() != Qt.KeyboardModifier.ShiftModifier and event.modifiers() != Qt.KeyboardModifier.AltModifier:
95 self.PREVIOUS_DRAG_X = None
96 return
97
98 # alt modifier is reserved for scrolling through
99 if self.PREVIOUS_DRAG_X and event.modifiers() == Qt.KeyboardModifier.AltModifier:
100 if self.PREVIOUS_DRAG_X < event.x() - DRAG_DELTA:
101 self.SIGNAL_WUP.emit(0)
102 self.PREVIOUS_DRAG_X = event.x()
103 elif self.PREVIOUS_DRAG_X > event.x() + DRAG_DELTA:
104 self.SIGNAL_WDN.emit(0)
105 self.PREVIOUS_DRAG_X = event.x()
106
107 return
108
109 # MimeData
110 mimedata = QMimeData()
111 url = QUrl().fromLocalFile(self.path)
112 mimedata.setUrls([url])
113
114 # create appropriate res image that will placed
115 doc = Krita.instance().activeDocument()
116
117 # Saving a non-existent document causes crashes, so lets check for that first.
118 if doc is None:
119 return
120
121 scale = self.scale / 100
122
123 # only scale to document if it exists
124 if self.fitCanvasChecked and not doc is None:
125 fullImage = QImage(self.path).scaled(doc.width() * scale, doc.height() * scale, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)
126 else:
127 fullImage = QImage(self.path)
128 # scale image, now knowing the bounds
129 fullImage = fullImage.scaled(fullImage.width() * scale, fullImage.height() * scale, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)
130
131 fullPixmap = QPixmap(50, 50).fromImage(fullImage)
132 mimedata.setImageData(fullPixmap)
133
134 # Clipboard
135 QApplication.clipboard().setImage(self.qimage)
136
137 # drag, using information about the smaller version of the image
138 drag = QDrag(self)
139 drag.setMimeData(mimedata)
140 drag.setPixmap(self.pixmap)
141 drag.setHotSpot(QPoint(self.qimage.width() / 2, self.qimage.height() / 2))
142 drag.exec(Qt.DropAction.CopyAction)
143
static Krita * instance()
instance retrieve the singleton instance of the Application object.
Definition Krita.cpp:390

◆ customPaintEvent()

photobash_images.photobash_images_modulo.customPaintEvent ( instance,
event )

Definition at line 37 of file photobash_images_modulo.py.

37def customPaintEvent(instance, event):
38 painter = QPainter(instance)
39 painter.setRenderHint(QPainter.RenderHint.Antialiasing, True)
40 painter.setPen(QPen(Qt.GlobalColor.black, 2, Qt.PenStyle.SolidLine))
41 painter.setBrush(QBrush(Qt.GlobalColor.white, Qt.BrushStyle.SolidPattern))
42
43 # Calculations
44 total_width = event.rect().width()
45 total_height = event.rect().height()
46 image_width = instance.qimage.width()
47 image_height = instance.qimage.height()
48
49 try:
50 var_w = total_width / image_width
51 var_h = total_height / image_height
52 except:
53 var_w = 1
54 var_h = 1
55
56 size = 0
57
58 if var_w <= var_h:
59 size = var_w
60 if var_w > var_h:
61 size = var_h
62
63 wt2 = total_width * 0.5
64 ht2 = total_height * 0.5
65
66 instance.scaled_width = image_width * size
67 instance.scaled_height = image_height * size
68
69 offset_x = wt2 - (instance.scaled_width * 0.5)
70 offset_y = ht2 - (instance.scaled_height * 0.5)
71
72 # Save State for Painter
73 painter.save()
74 painter.translate(offset_x, offset_y)
75 painter.scale(size, size)
76 painter.drawImage(0,0,instance.qimage)
77 # paint something if it is a favourite
78 if hasattr(instance, 'isFavourite'):
79 if instance.isFavourite:
80 # reset scale to draw favourite triangle
81 painter.scale(1/size, 1/size)
82 painter.drawPolygon(FAVOURITE_TRIANGLE)
83
84 # Restore Space
85 painter.restore()
86

◆ customSetImage()

photobash_images.photobash_images_modulo.customSetImage ( instance,
image )

Definition at line 87 of file photobash_images_modulo.py.

87def customSetImage(instance, image):
88 instance.qimage = QImage() if image is None else image
89 instance.pixmap = QPixmap(50, 50).fromImage(instance.qimage)
90
91 instance.update()
92

Variable Documentation

◆ DRAG_DELTA

int photobash_images.photobash_images_modulo.DRAG_DELTA = 30

Definition at line 28 of file photobash_images_modulo.py.

◆ FAVOURITE_TRIANGLE

photobash_images.photobash_images_modulo.FAVOURITE_TRIANGLE
Initial value:
1= QPolygon([
2 QPoint(0, 0),
3 QPoint(0, TRIANGLE_SIZE),
4 QPoint(TRIANGLE_SIZE, 0)
5])

Definition at line 31 of file photobash_images_modulo.py.

◆ pixmap

photobash_images.photobash_images_modulo.pixmap

Definition at line 140 of file photobash_images_modulo.py.

◆ PREVIOUS_DRAG_X

photobash_images.photobash_images_modulo.PREVIOUS_DRAG_X

Definition at line 95 of file photobash_images_modulo.py.

◆ qimage

photobash_images.photobash_images_modulo.qimage

Definition at line 135 of file photobash_images_modulo.py.

◆ TRIANGLE_SIZE

int photobash_images.photobash_images_modulo.TRIANGLE_SIZE = 20

Definition at line 29 of file photobash_images_modulo.py.