00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 from ost import gui
00022 from ost import gfx
00023 from PyQt4 import QtCore, QtGui
00024
00025
00026 class ColorSelectWidget(QtGui.QWidget):
00027 def __init__(self, width, height, color, parent=None):
00028 QtGui.QWidget.__init__(self, parent)
00029
00030
00031 self.width_ = width
00032 self.height_ = height
00033
00034 if(color is None):
00035 self.color_ = QtGui.QColor("White")
00036 else:
00037 self.color_ = color
00038
00039 self.show()
00040
00041
00042 self.change_color_ = QtGui.QAction('ChangeColor', self)
00043
00044 QtCore.QObject.connect(self.change_color_, QtCore.SIGNAL('triggered()'), self.ChangeColor)
00045
00046 self.addAction(self.change_color_)
00047 self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
00048
00049 self.Resize()
00050
00051 def ChangeColor(self):
00052 color = QtGui.QColorDialog.getColor(self.color_, self)
00053
00054 if(color != self.color_ and color.isValid()):
00055 self.color_ = color
00056 self.emit(QtCore.SIGNAL("colorChanged"))
00057 self.update()
00058
00059 def GetColor(self):
00060 return self.color_
00061
00062 def GetGfxColor(self):
00063 color = self.GetColor()
00064 return gfx.RGB(color.redF(), color.greenF(), color.blueF())
00065
00066 def SetColor(self, color):
00067 if(self.color_ != color):
00068 self.color_ = color
00069 self.emit(QtCore.SIGNAL("colorChanged"))
00070 self.update()
00071
00072 def SetGfxColor(self, color):
00073 qcolor= QtGui.QColor(color.Red()*255,color.Green()*255,color.Blue()*255,color.Alpha()*255)
00074 self.SetColor(qcolor)
00075
00076 def paintEvent(self, event):
00077 if self.isEnabled():
00078 size = self.size()
00079 paint = QtGui.QPainter()
00080 if paint.begin(self):
00081 brush = QtGui.QBrush(self.color_)
00082 paint.setBrush(brush)
00083 paint.drawRect(0,
00084 0,
00085 self.width() - 1,
00086 self.height() - 1)
00087 paint.end()
00088
00089 def mouseDoubleClickEvent(self, event):
00090 self.ChangeColor()
00091
00092 def SetSize(self, width, height):
00093 self.width_ = width
00094 self.height_ = height
00095 self.Resize()
00096
00097 def Resize(self):
00098 self.setMinimumSize(self.width_, self.height_)
00099 self.setMaximumSize(self.width_, self.height_)
00100 self.resize(self.width_, self.height_)