2 ** Project : Form Designer
3 ** File Purpose : QWidget
5 ** Author : Mahmoud Fayed <msfclipper@yahoo.com>
10 class FormDesigner_QWidget from QWidget
14 nX=0 nY=0 # for Select/Draw
19 nMenubarCounter = [0,0] # For [Menus,Items] Names
25 nClocksCount = clockspersecond() / 4
34 func SetIndexTypeValue Value
38 if IndexTypeValue() = 0 {
46 func setBackColor cValue
50 func updatestylesheets
51 setstylesheet("background-color:"+cBackColor+";")
53 func setSubWindow oObject
59 func SetWindowFlagsValue cValue
65 func SetMainLayoutValue cValue
71 func SetWindowIconValue cValue
77 func SetMenubarValue cValue
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"
96 func UpdateProperties oDesigner,nRow,nCol,cValue
100 oSubWindow.move(0+cValue,oSubWindow.y())
102 oSubWindow.move(oSubWindow.x(),0+cValue)
104 oSubWindow.resize(0+cValue,oSubWindow.height())
106 oSubWindow.resize(oSubWindow.width(),0+cValue)
108 setWindowTitle(cValue)
109 oDesigner.oView.oSub {
110 setWindowTitle(cValue)
115 case 6 # Window Flags
116 setWindowFlagsValue(cValue)
118 setMainLayoutValue(cValue)
120 setWindowIconValue(cValue)
122 setMenubarValue(cValue)
127 func ComboItemAction oDesigner,nRow
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)
137 func DisplayProperties oDesigner
138 oPropertiesTable = oDesigner.oView.oPropertiesTable
139 oPropertiesTable.Blocksignals(True)
141 oPropertiesTable.item(0,1).settext(""+(oSubWindow.x()+oDesigner.oview.oArea.horizontalScrollBar().value()))
143 oPropertiesTable.item(1,1).settext(""+(oSubWindow.y()+oDesigner.oview.oArea.verticalScrollBar().value()))
145 oPropertiesTable.item(2,1).settext(""+oSubWindow.width())
147 oPropertiesTable.item(3,1).settext(""+oSubWindow.height())
149 oPropertiesTable.item(4,1).settext(windowtitle())
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())
159 oPropertiesTable.item(9,1).settext(MenubarValue())
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)
169 func DialogButtonAction oDesigner,nRow
172 cColor = oDesigner.oGeneral.SelectColor()
174 DisplayProperties(oDesigner)
175 case 6 # Window Flags
176 open_windowInPackages(:WindowFlagsController,[
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()
190 cFile = oDesigner.oGeneral.SelectFile(oDesigner)
191 setWindowIconValue(cFile)
192 DisplayProperties(oDesigner)
194 open_windowInPackages(:MenubarDesignerController,[
197 Last_Window().setParentObject(oDesigner)
198 Last_Window().setMenubar(MenubarValue())
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()
209 func MouseReleaseAction oDesigner
210 oDesigner.oView.oLabelSelect.hide()
211 aRect = GetRectDim(oDesigner)
212 oDesigner.SelectDrawAction(aRect)
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])
222 oFDApp.processevents()
226 func MobileEventDelay
228 if nClockValue != 0 and clock() - nClockValue < nClocksCount {
231 nClockValue = clock()
235 func GetRectDim oDesigner
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()
246 width = max(nX,nX2) - min(nX,nX2)
247 height = max(nY,nY2) - min(nY,nY2)
248 return [left,top,width,height]
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())
274 func GenerateCode oDesigner
275 cOutput = char(9) + char(9) +
278 setWindowTitle("#{f5}")
279 setstylesheet("background-color:#{f6};") ' + nl
280 if not WindowFlagsValue() = NULL {
282 setWindowFlags(#{f7}) ' + nl
284 if not WindowIconValue() = NULL {
286 setWinIcon(win,"#{f8}") ' + nl
288 if not MenubarValue() = NULL {
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())
303 func GenerateCodeAfterObjects oDesigner
305 if not MainLayoutValue() = NULL {
307 oMWLayoutWidget = new qWidget() { setLayout(#{f1}) }
308 setCentralWidget(oMWLayoutWidget) ' + nl
309 cOutput = substr(cOutput,"#{f1}",MainLayoutValue())
314 if MenubarValue() = NULL { return }
315 cCode = GenerateMenubarCode(MenubarValue())
318 func GenerateMenubarCode cMenu
320 nMenubarCounter = [0,0]
321 cCode = "oMenuBar = new qmenubar(win) {" + nl
322 aChild = aMenuData[:Children]
324 cCode += GenerateSubMenuCode(aChild)
326 cCode += Copy(Char(9),2) + "}" + nl
327 cCode += Copy(Char(9),2) + "win.SetMenuBar(oMenuBar)" + nl
330 func GenerateSubMenuCode aChild
332 nMenuID = nMenubarCounter[1]
336 if ( len(Item[:Children]) > 0 ) or (nMenuID = 0) {
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])
350 oAction#{f5}_#{f6} = new qAction(win) {
351 setShortcut(new QKeySequence("#{f1}"))
352 setbtnimage(self,"#{f2}")
354 setclickevent(Method(:#{f4}))
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"
363 cTempCode = SubStr(cTempCode,"#{f4}",Item[:Action])
364 cTempCode = SubStr(cTempCode,"#{f5}",""+nMenubarCounter[1])
365 cTempCode = SubStr(cTempCode,"#{f6}",""+nMenubarCounter[2])