OSDN Git Service

Ring 1.10 以来となる開発環境の日本語ローカライズ版 (評価版) を追加 (ノートパッド、フォームデザイナー、対話型実行環境、ファイルの検索)。
[ring-lang-081/ring.git] / applications / build / ja-jp / formdesigner / mainwindow / qwidget.ring
1 /*
2 **      Project : Form Designer 
3 **      File Purpose :  QWidget
4 **      Date : 2017.04.29
5 **      Author :  Mahmoud Fayed <msfclipper@yahoo.com>
6 */
7
8 package formdesigner
9
10 class FormDesigner_QWidget from QWidget
11
12         cBackColor = ""
13         oSubWindow
14         nX=0 nY=0               # for Select/Draw
15         cWindowFlags = ""
16         cMainLayout = ""
17         cWindowIcon = ""
18         cMenubar = ""
19         nMenubarCounter = [0,0] # For [Menus,Items] Names
20
21         nIndexType = 0
22
23         # For Mobile Devices 
24                 nClockValue = 0
25                 nClocksCount = clockspersecond() / 4
26
27         func init
28                 super.init()
29                 return self
30
31         func IndexTypeValue
32                 return nIndexType
33
34         func SetIndexTypeValue Value
35                 nIndexType = Value
36
37         func IndexStart
38                 if IndexTypeValue() = 0 {
39                         return 1
40                 }
41                 return 0
42
43         func BackColor
44                 return cBackColor
45
46         func setBackColor cValue
47                 cBackColor=cValue
48                 updatestylesheets()
49
50         func updatestylesheets
51                 setstylesheet("background-color:"+cBackColor+";")
52
53         func setSubWindow oObject
54                 oSubWindow = oObject
55
56         func WindowFlagsValue
57                 return cWindowFlags
58
59         func SetWindowFlagsValue cValue
60                 cWindowFlags = cValue
61
62         func MainLayoutValue
63                 return cMainLayout
64
65         func SetMainLayoutValue cValue
66                 cMainLayout = cValue
67
68         func WindowIconValue
69                 return cWindowIcon
70
71         func SetWindowIconValue cValue
72                 cWindowIcon = cValue
73
74         func MenubarValue
75                 return cMenubar
76
77         func SetMenubarValue cValue
78                 cMenubar = cValue
79
80         func AddObjectProperties  oDesigner
81                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_X,False)           # "X"
82                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_Y,False)           # "Y"
83                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_WIDTH,False)       # "Width"
84                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_HEIGHT,False)      # "Height"
85                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_TITLE,False)       # "Title"
86                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_BACKCOLOR,True)    # "Back Color"
87                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_WINDOWFLAGS,True)  # "Window Flags"
88                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_SETLAYOUT,True)    # "Set Layout"
89                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_WINDOWICON,True)   # "Window Icon"
90                 oDesigner.oView.AddProperty(T_FORMDESIGNER_ATTRIBUTE_MENUBAR,True)      # "Menubar"
91                 oDesigner.oView.AddPropertyCombobox(T_FORMDESIGNER_ATTRIBUTE_INDEXTYPE, # "Index Type"
92                                 [T_FORMDESIGNER_ATTRIBUTE_STARTFROM1,                   # "Start from 1"
93                                 T_FORMDESIGNER_ATTRIBUTE_STARTFROM0]                    # "Start from 0"
94                                 )
95
96         func UpdateProperties oDesigner,nRow,nCol,cValue
97                 if nCol = 1 {
98                         switch nRow {
99                                 case 0  # x
100                                         oSubWindow.move(0+cValue,oSubWindow.y())
101                                 case 1  # y
102                                         oSubWindow.move(oSubWindow.x(),0+cValue)
103                                 case 2  # width
104                                         oSubWindow.resize(0+cValue,oSubWindow.height())
105                                 case 3  # height
106                                         oSubWindow.resize(oSubWindow.width(),0+cValue)
107                                 case 4          # Title
108                                         setWindowTitle(cValue)
109                                         oDesigner.oView.oSub {
110                                                 setWindowTitle(cValue)
111                                                 show()
112                                         }
113                                 case 5  # back color
114                                         setBackColor(cValue)
115                                 case 6  # Window Flags
116                                         setWindowFlagsValue(cValue)
117                                 case 7          # Main Layout
118                                         setMainLayoutValue(cValue)
119                                 case 8          # Window Icon
120                                         setWindowIconValue(cValue)
121                                 case 9  # Menubar
122                                         setMenubarValue(cValue)
123
124                         }
125                 }
126
127         func ComboItemAction oDesigner,nRow
128                 nIndexTypePos = 10
129                 if nRow = nIndexTypePos  {              
130                         oWidget = oDesigner.oView.oPropertiesTable.cellwidget(nIndexTypePos,1)
131                         oCombo = new qCombobox
132                         oCombo.pObject = oWidget.pObject
133                         nIndex = oCombo.CurrentIndex()
134                         setIndexTypeValue(nIndex)
135                 }
136
137         func DisplayProperties oDesigner
138                 oPropertiesTable = oDesigner.oView.oPropertiesTable
139                 oPropertiesTable.Blocksignals(True)
140                 # Set the X
141                         oPropertiesTable.item(0,1).settext(""+(oSubWindow.x()+oDesigner.oview.oArea.horizontalScrollBar().value()))
142                 # Set the Y
143                         oPropertiesTable.item(1,1).settext(""+(oSubWindow.y()+oDesigner.oview.oArea.verticalScrollBar().value()))
144                 # Set the Width
145                         oPropertiesTable.item(2,1).settext(""+oSubWindow.width())
146                 # Set the Height
147                         oPropertiesTable.item(3,1).settext(""+oSubWindow.height())
148                 # Set the Title
149                         oPropertiesTable.item(4,1).settext(windowtitle())
150                 # Set the BackColor
151                         oPropertiesTable.item(5,1).settext(backcolor())
152                 # Set the Window Flags
153                         oPropertiesTable.item(6,1).settext(WindowFlagsValue())
154                 # Set the Main Layout
155                         oPropertiesTable.item(7,1).settext(MainLayoutValue())
156                 # Set the Window Icon
157                         oPropertiesTable.item(8,1).settext(WindowIconValue())
158                 # Set the Menubar
159                         oPropertiesTable.item(9,1).settext(MenubarValue())
160                 # Index Type 
161                         oWidget = oPropertiesTable.cellwidget(10,1)
162                         oCombo = new qCombobox
163                         oCombo.pObject = oWidget.pObject
164                         oCombo.BlockSignals(True)
165                         oCombo.setCurrentIndex(IndexTypeValue())
166                         oCombo.BlockSignals(False)
167                 oPropertiesTable.Blocksignals(False)
168
169         func DialogButtonAction oDesigner,nRow
170                 switch nRow {
171                         case 5  # Back Color
172                                 cColor = oDesigner.oGeneral.SelectColor()
173                                 setBackColor(cColor)
174                                 DisplayProperties(oDesigner)
175                         case 6  # Window Flags
176                                 open_windowInPackages(:WindowFlagsController,[
177                                         "System.GUI"
178                                 ])
179                                 Last_Window().setParentObject(oDesigner)
180                                 Last_Window().LoadSelectedItems()
181                         case 7  # Window Layout 
182                                 open_window(:WindowObjectsController)
183                                 Last_Window().setParentObject(oDesigner)
184                                 Last_Window().setPropertyIndex(7)
185                                 Last_Window().setMethodName("setMainLayoutValue")
186                                 aList = oDesigner.oModel.GetLayoutsNames()
187                                 Last_Window().LoadObjectsData(aList)
188                                 Last_Window().LoadSelectedItems()
189                         case 8  # Window Icon
190                                 cFile = oDesigner.oGeneral.SelectFile(oDesigner)
191                                 setWindowIconValue(cFile)
192                                 DisplayProperties(oDesigner)
193                         case 9  # Menubar
194                                 open_windowInPackages(:MenubarDesignerController,[
195                                         "System.GUI"
196                                 ])
197                                 Last_Window().setParentObject(oDesigner)
198                                 Last_Window().setMenubar(MenubarValue())
199                 }
200
201         func MousePressAction oDesigner
202                 # 8, 6 to start drawing from the center of the Mouse Cursor
203                         nX = oDesigner.oView.oFilter.getglobalx() - 8
204                         ny = oDesigner.oView.oFilter.getglobaly() - 6
205                 oDesigner.oView.oLabelSelect.raise()
206                 oDesigner.oView.oLabelSelect.resize(1,1)
207                 oDesigner.oView.oLabelSelect.show()
208
209         func MouseReleaseAction oDesigner
210                 oDesigner.oView.oLabelSelect.hide()
211                 aRect = GetRectDim(oDesigner)
212                 oDesigner.SelectDrawAction(aRect)
213
214         func MouseMoveAction oDesigner
215                 if MobileEventDelay() { return }
216                 aRect = GetRectDim(oDesigner)
217                 oDesigner.oView.oLabelSelect {
218                         move(aRect[1],aRect[2])
219                         resize(aRect[3],aRect[4])
220                         if isMobile() {
221                                 show()
222                                 oFDApp.processevents()
223                         }
224                 }
225
226         func MobileEventDelay
227                 if isMobile() {
228                         if nClockValue != 0 and clock() - nClockValue < nClocksCount {
229                                 return True
230                         }
231                         nClockValue = clock()
232                 }
233                 return False
234
235         func GetRectDim oDesigner
236                 C_TOPMARGIN = 25
237                 nX2 = oDesigner.oView.oFilter.getglobalx()
238                 ny2 = oDesigner.oView.oFilter.getglobaly()
239                 top = min(nY2,nY) - oDesigner.oView.oArea.y() - oSubWindow.y() - y() - C_TOPMARGIN - oDesigner.oView.win.y()
240                 left = min(nX2,nX) - oDesigner.oView.oArea.x()  - oSubWindow.x() - x() - oDesigner.oView.win.x()
241                 # Take in mind embedding the Designer in another Window like RNote
242                         if oDesigner.HasParent() {
243                                 top -= oDesigner.oView.win.parentwidget().y()
244                                 left -= oDesigner.oView.win.parentwidget().x()
245                         }
246                 width = max(nX,nX2) - min(nX,nX2)
247                 height = max(nY,nY2) - min(nY,nY2)
248                 return [left,top,width,height]
249
250         func ObjectDataAsString oDesigner,nTabsCount
251                 cTabs = copy(char(9),nTabsCount)
252                 cOutput = cTabs + " :x = #{f1} , : y = #{f2}  , " + nl
253                 cOutput += cTabs + " :width =  #{f3} , :height = #{f4} , " + nl
254                 cOutput += cTabs + ' :title =  "#{f5}" , ' + nl
255                 cOutput += cTabs + ' :backcolor =  "#{f6}" , ' + nl
256                 cOutput += cTabs + ' :windowflags =  "#{f7}" , ' + nl
257                 cOutput += cTabs + ' :mainlayout =  "#{f8}" ,' + nl
258                 cOutput += cTabs + ' :WindowIcon =  "#{f9}" , ' + nl
259                 cOutput += cTabs + ' :Menubar =  "#{f10}"  ,' + nl
260                 cOutput += cTabs + ' :IndexType =  #{f11}  ' + nl
261                 cOutput = substr(cOutput,"#{f1}",""+parentwidget().x())
262                 cOutput = substr(cOutput,"#{f2}",""+parentwidget().y())
263                 cOutput = substr(cOutput,"#{f3}",""+parentwidget().width())
264                 cOutput = substr(cOutput,"#{f4}",""+parentwidget().height())
265                 cOutput = substr(cOutput,"#{f5}",windowtitle())
266                 cOutput = substr(cOutput,"#{f6}",backcolor())
267                 cOutput = substr(cOutput,"#{f7}",WindowFlagsValue())
268                 cOutput = substr(cOutput,"#{f8}",MainLayoutValue())
269                 cOutput = substr(cOutput,"#{f9}",WindowIconValue())
270                 cOutput = substr(cOutput,"#{f10}",MenubarValue())
271                 cOutput = substr(cOutput,"#{f11}",""+IndexTypeValue())
272                 return cOutput
273
274         func GenerateCode oDesigner
275                 cOutput = char(9) + char(9) +
276                 'move(#{f1},#{f2})
277                 resize(#{f3},#{f4})
278                 setWindowTitle("#{f5}")
279                 setstylesheet("background-color:#{f6};") ' + nl
280                 if not WindowFlagsValue() = NULL {
281                         cOutput += '
282                 setWindowFlags(#{f7}) ' + nl
283                 }
284                 if not WindowIconValue() = NULL {
285                         cOutput += '
286                 setWinIcon(win,"#{f8}") ' + nl
287                 }
288                 if not MenubarValue() = NULL {
289                         cOutput += '
290                 #{f9} ' + nl
291                 }
292                 cOutput = substr(cOutput,"#{f1}",""+max(parentwidget().x(),0))
293                 cOutput = substr(cOutput,"#{f2}",""+max(parentwidget().y(),0))
294                 cOutput = substr(cOutput,"#{f3}",""+parentwidget().width())
295                 cOutput = substr(cOutput,"#{f4}",""+parentwidget().height())
296                 cOutput = substr(cOutput,"#{f5}",windowtitle())
297                 cOutput = substr(cOutput,"#{f6}",backcolor())
298                 cOutput = substr(cOutput,"#{f7}",WindowFlagsValue())
299                 cOutput = substr(cOutput,"#{f8}",WindowIconValue())
300                 cOutput = substr(cOutput,"#{f9}",MenubarCode())
301                 return cOutput
302
303         func GenerateCodeAfterObjects oDesigner
304                 cOutput = ""
305                 if not MainLayoutValue() = NULL {
306                         cOutput += '
307                 oMWLayoutWidget = new qWidget() { setLayout(#{f1}) }
308                 setCentralWidget(oMWLayoutWidget) ' + nl
309                         cOutput = substr(cOutput,"#{f1}",MainLayoutValue())
310                 }
311                 return cOutput
312
313         func MenubarCode
314                 if MenubarValue() = NULL { return }
315                 cCode = GenerateMenubarCode(MenubarValue())
316                 return cCode
317
318         func GenerateMenubarCode cMenu
319                 eval(cMenu)
320                 nMenubarCounter = [0,0]
321                 cCode = "oMenuBar = new qmenubar(win) {" + nl
322                 aChild = aMenuData[:Children]
323                 if len(aChild) > 0 {
324                         cCode += GenerateSubMenuCode(aChild)
325                 }
326                 cCode += Copy(Char(9),2) +  "}" + nl
327                 cCode += Copy(Char(9),2) + "win.SetMenuBar(oMenuBar)" + nl
328                 return cCode
329
330         func GenerateSubMenuCode aChild
331                 nMenubarCounter[2]=0
332                 nMenuID = nMenubarCounter[1]
333                 cCode = ""
334                 for Item in aChild {
335                         nMenubarCounter[2]++
336                         if ( len(Item[:Children]) > 0 ) or (nMenuID = 0) {
337                                 # Menu
338                                 nMenubarCounter[1]++
339                                 nMenuID2 = nMenubarCounter[1]
340                                 cTempCode = Copy(Char(9),3) + 'subMenu#{f1} = addmenu("#{f2}")' + nl
341                                 cTempCode += Copy(Char(9),3) + 'subMenu#{f1} {' + nl
342                                 cTempCode += GenerateSubMenuCode(Item[:Children])
343                                 cTempCode += Copy(Char(9),3) + '}' + nl
344                                 cTempCode = SubStr(cTempCode,"#{f1}",""+nMenuID2)
345                                 cTempCode = SubStr(cTempCode,"#{f2}",Item[:Text])
346                                 cCode += cTempCode
347                         else
348                                 # Action
349                                 cTempCode = `
350                                 oAction#{f5}_#{f6} = new qAction(win) {
351                                         setShortcut(new QKeySequence("#{f1}"))
352                                         setbtnimage(self,"#{f2}")
353                                         settext("#{f3}")
354                                         setclickevent(Method(:#{f4}))
355                                 }
356                                 addaction(oAction#{f5}_#{f6})`+nl
357                                 cTempCode = SubStr(cTempCode,"#{f1}",Item[:ShortCut])
358                                 cTempCode = SubStr(cTempCode,"#{f2}",Item[:Image])
359                                 cTempCode = SubStr(cTempCode,"#{f3}",Item[:Text])
360                                 if Item[:Action] = NULL {
361                                         Item[:Action] = "NoAction"
362                                 }
363                                 cTempCode = SubStr(cTempCode,"#{f4}",Item[:Action])
364                                 cTempCode = SubStr(cTempCode,"#{f5}",""+nMenubarCounter[1])
365                                 cTempCode = SubStr(cTempCode,"#{f6}",""+nMenubarCounter[2])
366                                 cCode += cTempCode
367                         }
368                 }
369                 return cCode
370