OSDN Git Service

Ring 1.10 以来となる開発環境の日本語ローカライズ版 (評価版) を追加 (ノートパッド、フォームデザイナー、対話型実行環境、ファイルの検索)。
[ring-lang-081/ring.git] / applications / formdesigner / source / common / commonattributesmethods.ring
1 /*
2 **      Project : Form Designer 
3 **      File Purpose :  Common Attributes  and Methods
4 **      Date : 2017.04.29
5 **      Author :  Mahmoud Fayed <msfclipper@yahoo.com>
6 */
7
8 package formdesigner
9
10 class CommonAttributesMethods
11
12
13         func CreateCommonAttributes
14                 AddAttribute(self,:cTextColor)
15                 AddAttribute(self,:cBackColor)
16                 AddAttribute(self,:cFontProperty)
17                 AddAttribute(self,:cCurrentParentName)
18                 cTextColor = "black"
19                 cBackColor = ""
20                 cFontProperty = "Arial"
21                 cCurrentParentName = "win"
22
23         func TextColor
24                 return cTextColor
25
26         func setTextColor cValue
27                 cTextColor=cValue
28                 updatestylesheets()
29
30         func BackColor
31                 return cBackColor
32
33         func setBackColor cValue
34                 cBackColor=cValue
35                 updatestylesheets()
36
37         func FontProperty
38                 return cFontProperty
39
40         func setFontProperty cValue
41                 cFontProperty = cValue
42                 oFont = new qfont("",0,0,0)
43                 oFont.fromstring(cValue)
44                 setfont(oFont)
45                 oFont.delete()
46
47         func CurrentParentName
48                 return cCurrentParentName
49
50         func SetCurrentParentName cValue
51                 cCurrentParentName = cValue
52
53         func updatestylesheets
54                 setstylesheet("color:"+cTextColor+";background-color:"+cBackColor+";")
55
56         func AddObjectProperties  oDesigner
57                 AddObjectCommonProperties(oDesigner)
58
59         func AddObjectCommonProperties  oDesigner
60                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_NAME,False)        # "Name"
61                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_X,False)           # "X"
62                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_Y,False)           # "Y"
63                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_WIDTH,False)       # "Width"
64                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_HEIGHT,False)      # "Height"
65                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_TEXTCOLOR,True)    # "Text Color"
66                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_BACKCOLOR,True)    # "Back Color"
67                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_FONT,True)         # "Font"
68
69         func UpdateProperties oDesigner,nRow,nCol,cValue
70                 UpdateCommonProperties(oDesigner,nRow,nCol,cValue)
71
72         func UpdateCommonProperties oDesigner,nRow,nCol,cValue
73                 if nCol = 1 {
74                         switch nRow {
75                                 case 0  # Name
76                                         oDesigner.oModel.SetObjectName(oDesigner,self,cValue)
77                                         oDesigner.AddObjectsToCombo()
78                                         # Because we may prevent name change (duplication)
79                                                 DisplayCommonProperties(oDesigner)
80                                 case 1  # x
81                                         move(0+cValue,y())
82                                 case 2  # y
83                                         move(x(),0+cValue)
84                                 case 3  # width
85                                         resize(0+cValue,height())
86                                 case 4  # height
87                                         resize(width(),0+cValue)
88                                 case 5  # Text color
89                                         setTextColor(cValue)
90                                 case 6  # back color
91                                         setBackColor(cValue)
92                                 case 7  # font
93                                         setFontProperty(cValue)
94                         }
95                 }
96
97         func DisplayProperties oDesigner
98                 DisplayCommonProperties(oDesigner)
99
100         func DisplayCommonProperties oDesigner
101                 oPropertiesTable = oDesigner.oView.oPropertiesTable
102                 oPropertiesTable.Blocksignals(True)
103                 # Set the Name
104                         oPropertiesTable.item(0,1).settext(
105                                 oDesigner.oModel.GetObjectName(self))
106                 # Set the X
107                         oPropertiesTable.item(1,1).settext(""+x())
108                 # Set the Y
109                         oPropertiesTable.item(2,1).settext(""+y())
110                 # Set the Width
111                         oPropertiesTable.item(3,1).settext(""+width())
112                 # Set the Height
113                         oPropertiesTable.item(4,1).settext(""+height())
114                 # Set the Text Color
115                         oPropertiesTable.item(5,1).settext(textcolor())
116                 # Set the BackColor
117                         oPropertiesTable.item(6,1).settext(backcolor())
118                 # Set the Font
119                         oPropertiesTable.item(7,1).settext(fontproperty())
120
121                 oPropertiesTable.Blocksignals(False)
122
123         func DialogButtonAction oDesigner,nRow
124                 CommonDialogButtonAction(oDesigner,nRow)
125
126         func CommonDialogButtonAction oDesigner,nRow
127                 if nRow = 5 {   # Text Color
128                         cColor = oDesigner.oGeneral.SelectColor()
129                         setTextColor(cColor)
130                         DisplayProperties(oDesigner)
131                 elseif nRow = 6         # Back Color
132                         cColor = oDesigner.oGeneral.SelectColor()
133                         setBackColor(cColor)
134                         DisplayProperties(oDesigner)
135                 elseif nRow = 7 # Font
136                         cFont = oDesigner.oGeneral.SelectFont()
137                         setFontProperty(cFont)
138                         DisplayProperties(oDesigner)
139                 }
140
141         func  ObjectDataAsString oDesigner,nTabsCount
142                 return ObjectDataAsString2(oDesigner,nTabsCount)
143
144         func ObjectDataAsString2 oDesigner,nTabsCount
145                 cTabs = std_copy(char(9),nTabsCount)
146                 cOutput = cTabs + " :x = #{f1} , : y = #{f2}  , " + nl
147                 cOutput += cTabs + " :width =  #{f3} , :height = #{f4} , " + nl
148                 cOutput += cTabs + ' :textcolor =  "#{f5}" , ' + nl
149                 cOutput += cTabs + ' :backcolor =  "#{f6}" , ' + nl
150                 cOutput += cTabs + ' :font =  "#{f7}" , ' + nl
151                 cOutput += cTabs + ' :parent =  "#{f8}"  '
152                 cOutput = substr(cOutput,"#{f1}",oDesigner.PrepareStringForFormFile(""+x()))
153                 cOutput = substr(cOutput,"#{f2}",oDesigner.PrepareStringForFormFile(""+y()))
154                 cOutput = substr(cOutput,"#{f3}",oDesigner.PrepareStringForFormFile(""+width()))
155                 cOutput = substr(cOutput,"#{f4}",oDesigner.PrepareStringForFormFile(""+height()))
156                 cOutput = substr(cOutput,"#{f5}",oDesigner.PrepareStringForFormFile(textcolor()))
157                 cOutput = substr(cOutput,"#{f6}",oDesigner.PrepareStringForFormFile(backcolor()))
158                 cOutput = substr(cOutput,"#{f7}",oDesigner.PrepareStringForFormFile(fontproperty()))
159                 cOutput = substr(cOutput,"#{f8}",oDesigner.PrepareStringForFormFile(CurrentParentName()))
160                 return cOutput
161
162         func GenerateCode oDesigner
163                 cOutput = char(9) + char(9) +
164                 oDesigner.oModel.GetObjectName(self) + " = " +
165                 'new #{f1}(#{f10}) {
166                         move(#{f2},#{f3})
167                         resize(#{f4},#{f5})
168                         setstylesheet("color:#{f6};background-color:#{f7};")
169                         oFont = new qfont("",0,0,0)
170                         oFont.fromstring("#{f8}")
171                         setfont(oFont)
172                         oFont.delete()
173 #{f9}
174                 }' + nl
175                 cClass = substr(classname(self),"formdesigner_","")
176                 if cClass  = "qimage" or cClass = "qhyperlink"  {
177                         cClass = "qlabel"
178                 }
179                 # Index start from 1
180                 if  oDesigner.oModel.FormObject().IndexTypeValue() = 0 {
181                         # Remove the 'q' letter from the class name 
182                                 cClass = substr(cClass,2)       
183                 }
184                 cOutput = substr(cOutput,"#{f1}",cClass)
185                 cOutput = substr(cOutput,"#{f2}",""+x())
186                 cOutput = substr(cOutput,"#{f3}",""+y())
187                 cOutput = substr(cOutput,"#{f4}",""+width())
188                 cOutput = substr(cOutput,"#{f5}",""+height())
189                 cOutput = substr(cOutput,"#{f6}",textcolor())
190                 cOutput = substr(cOutput,"#{f7}",backcolor())
191                 cOutput = substr(cOutput,"#{f8}",fontproperty())
192                 cOutput = substr(cOutput,"#{f9}",AddTabs(GenerateCustomCode(oDesigner),3))
193                 cOutput = substr(cOutput,"#{f10}",CurrentParentName())
194                 return cOutput
195
196         func AddTabs cText,nCount
197                 cTabs = std_copy(char(9),nCount)
198                 cText = cTabs + cText
199                 cText = substr(cText,nl,nl+cTabs)
200                 return cText
201
202         func GenerateCustomCode oDesigner
203                 return ""
204
205         func RestoreProperties oDesigner,Item
206                 RestoreCommonProperties(oDesigner,item)
207
208         func RestoreCommonProperties oDesigner,item
209                 itemdata = item[:data]
210                 blocksignals(true)
211                 setMouseTracking(True)
212                 setFocusPolicy(0)
213                 oDesigner.oModel.SetObjectName(oDesigner,self,item[:name])
214                 move(itemdata[:x],itemdata[:y])
215                 resize(itemdata[:width],itemdata[:height])
216                 setTextColor(itemdata[:textcolor])
217                 setBackColor(itemdata[:backcolor])
218                 if itemdata[:font] = NULL { itemdata[:font] = "Arial" }
219                 setFontProperty(itemdata[:font])
220                 setCurrentParentName(itemdata[:parent])
221                 refreshCorners(oDesigner.oModel.ActiveObject())
222                 blocksignals(false)
223
224         func PrepareEvent cCode,cEvent,cReplace
225                 # Remove " " around event if we uses Code
226                 cEvent = std_lower(cEvent)
227                 if substr(cEvent,"(") > 0 {
228                         cCode = substr(cCode,char(34)+cReplace+char(34),cReplace)
229                 else
230                         if cEvent != "" {
231                                 cCode = substr(cCode,char(34)+cReplace+char(34),"Method(:"+cReplace+")")
232                         }
233                 }
234                 return cCode
235