-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathqdrawsettings.py
91 lines (74 loc) · 2.96 KB
/
qdrawsettings.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# -*- coding: utf-8 -*-
# QDraw: plugin that makes drawing easier
# Author: Jérémy Kalsron
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from builtins import str
from qgis.PyQt.QtWidgets import QWidget, QPushButton, QSlider, QDesktopWidget,\
QLabel, QColorDialog, QVBoxLayout
from qgis.PyQt.QtGui import QColor
from qgis.PyQt.QtCore import Qt, QCoreApplication, pyqtSignal
class QdrawSettings(QWidget):
"""Window used to change settings (transparency/color)"""
settingsChanged = pyqtSignal()
def __init__(self):
QWidget.__init__(self)
self.setWindowTitle(self.tr('Qdraw - Settings'))
self.setFixedSize(320, 100)
self.center()
# default color
self.color = QColor(60, 151, 255, 255)
self.sld_opacity = QSlider(Qt.Horizontal, self)
self.sld_opacity.setRange(0, 255)
self.sld_opacity.setValue(255)
self.sld_opacity.tracking = True
self.sld_opacity.valueChanged.connect(self.handler_opacitySliderValue)
self.lbl_opacity = QLabel(self.tr('Opacity') + ': 100%', self)
self.dlg_color = QColorDialog(self)
btn_chColor = QPushButton(self.tr('Change the drawing color'), self)
btn_chColor.clicked.connect(self.handler_chColor)
vbox = QVBoxLayout()
vbox.addWidget(self.lbl_opacity)
vbox.addWidget(self.sld_opacity)
vbox.addWidget(btn_chColor)
self.setLayout(vbox)
def tr(self, message):
return QCoreApplication.translate('Qdraw', message)
def handler_opacitySliderValue(self, val):
self.color.setAlpha(val)
self.lbl_opacity.setText(
self.tr('Opacity')+': '+str(int((float(val) / 255) * 100))+'%')
self.settingsChanged.emit()
def handler_chColor(self):
color = self.dlg_color.getColor(self.color)
if color.isValid():
color.setAlpha(self.color.alpha())
self.color = color
self.settingsChanged.emit()
self.close()
def getColor(self):
return self.color
def center(self):
screen = QDesktopWidget().screenGeometry()
size = self.geometry()
self.move(
int((screen.width() - size.width()) / 2),
int((screen.height() - size.height()) / 2)
)
def closeEvent(self, e):
self.clear()
e.accept()
def clear(self):
return