OSDN Git Service

タグを打ち忘れていたついでに、html版ドキュメントを追加しました。
[ring-lang-081/ring.git] / docs / build / html / _sources / qt.txt
1 .. index:: 
2         single: デスクトップとモバイル開発 (RingQt);  はじめに
3
4 ===================================
5 デスクトップとモバイル開発 (RingQt)
6 ===================================
7
8 Ring アプリケーション (デスクトップとモバイル) 開発のために Qt フレームワーククラスの用法を学びます。
9
10 .. index:: 
11         pair: RingQt によるデスクトップとモバイル開発; はじめての GUI アプリケーション
12
13
14 はじめての GUI アプリケーション
15 ===============================
16
17 この用例では、彼氏、彼女の名前を質問するアプリケーションを作成します。
18 ユーザがテキストボックスへ名前を入力して “Say Hello” ボタンをクリックした後に、
19 “Hello ” を名前へ追加することでテキストボックスの値を更新します。
20
21 .. code-block:: ring
22
23         Load "guilib.ring"
24
25         oApp = New qApp {
26
27                 win1 = new qWidget() {
28
29                         setwindowtitle("Hello World")
30                         setGeometry(100,100,370,250)
31
32                         label1 = new qLabel(win1) {
33                                 settext("What is your name ?")
34                                 setGeometry(10,20,350,30)
35                                 setalignment(Qt_AlignHCenter)
36                         }
37
38                         btn1 = new qpushbutton(win1) {
39                                 setGeometry(10,200,100,30)
40                                 settext("Say Hello")
41                                 setclickevent("pHello()")
42                         }
43
44                         btn1 = new qpushbutton(win1) {
45                                 setGeometry(150,200,100,30)
46                                 settext("Close")
47                                 setclickevent("pClose()")
48                         }
49
50                         lineedit1 = new qlineedit(win1) {
51                                 setGeometry(10,100,350,30)
52                         }
53
54                         show()
55                 }
56
57                 exec()
58         }
59
60         Func pHello  
61                 lineedit1.settext( "Hello " + lineedit1.text())
62
63         Func pClose 
64                 oApp.quit()
65
66 プログラムの実行結果:
67
68 最初にテキストボックスへ名前を入力します。
69
70 .. image:: ringqt_shot1.jpg
71         :alt: テキストボックスへの名前入力
72
73 そして Say Hello ボタンをクリックします。
74
75 .. image:: ringqt_shot2.jpg
76         :alt: ボタンのクリック
77
78 .. index:: 
79         pair: デスクトップとモバイル開発 (RingQt); イベントループ
80
81 イベントループ
82 ==============
83
84 qApp クラスから exec() メソッドを呼び出すときは Qt はイベント駆動とイベントループで制御します。
85
86 一度でも exec() を呼び出すと、イベントループを開始し、ウィジェットは様々なイベントへの応答を開始します (マウス、キーボード、タイマーなど)。
87
88 イベントが発行されてコールバック関数が呼び出されるときは再び制御を戻します。
89
90 コールバック関数の実行完了後、制御をイベントループへ再び戻します。
91
92 覚えていると便利なことは
93
94 (1) ほとんどの作業は標準イベントで行います (イベントは各種ウィジェットで用意されています)。
95
96 (2) イベントフィルタを使うとウィジェットにイベントを追加できます。
97
98 (3) タイマーを使うと制御を戻します。これにより、各種検査を簡単にできます。
99
100 コールバック関数で処理時間がかかり、ビジー状態であるとき、 GUI の停止を回避するために qApp クラスで ProcessEvents() メソッドを呼び出せます。
101
102 .. code-block:: ring
103
104         oApp.processevents()
105
106 exec() メソッドを呼び出さずに、メインループを作成することもできます。
107
108 この方法は非推奨であり、選択肢の一つに過ぎません。
109
110 .. code-block:: ring
111
112         # exec() メソッドを呼び出さない方法
113                 while true
114                         oApp.processevents()    # GUI イベントへの応答
115                         # さらにコードを追加することで、制御を行います!
116                         # .....
117                 end 
118
119 .. index:: 
120         pair: RingQt によるデスクトップとモバイル開発; レイアウトの用法
121
122 レイアウトの用法
123 ====================
124
125 この用例は、前述のアプリケーションで垂直レイアウトを使用するように更新したものです。
126
127 .. code-block:: ring
128
129         Load "guilib.ring"
130
131         MyApp = New qApp {
132
133                 win1 = new qWidget() {
134
135                         setwindowtitle("Hello World") 
136                         setGeometry(100,100,400,130) 
137                         label1 = new qLabel(win1) {
138                                 settext("What is your name ?") 
139                                 setGeometry(10,20,350,30) 
140                                 setalignment(Qt_AlignHCenter)
141                         }
142                         btn1 = new qpushbutton(win1) {
143                                 setGeometry(10,200,100,30) 
144                                 settext("Say Hello") 
145                                 setclickevent("pHello()")
146                         }
147                         btn2 = new qpushbutton(win1) {
148                                 setGeometry(150,200,100,30) 
149                                 settext("Close") 
150                                 setclickevent("pClose()")
151                         }
152                         lineedit1 = new qlineedit(win1) {
153                                 setGeometry(10,100,350,30) 
154                         }
155                         layout1 = new qVBoxLayout() {
156                                 addwidget(label1)  
157                                 addwidget(lineedit1)  
158                                 addwidget(btn1)  
159                                 addwidget(btn2)         
160                         }
161                         win1.setlayout(layout1) 
162                         show()
163                 }
164
165                 exec()
166
167         }
168
169         Func pHello  
170                 lineedit1.settext( "Hello " + lineedit1.text())
171
172         Func pClose 
173                 MyApp.quit()
174
175 実行中のアプリケーション!
176                 
177 .. image:: ringqt_shot3.jpg
178         :alt: 垂直レイアウト
179
180 .. index:: 
181         pair: RingQt によるデスクトップとモバイル開発; QTextEdit クラスの用法
182
183 QTextEdit クラスの用法
184 ==========================
185
186 この用例では、 QTextEdit クラスを使用しています。
187
188 .. code-block:: ring
189
190         Load "guilib.ring"
191
192         New qApp {
193
194                 win1 = new qWidget() {
195
196                         setwindowtitle("QTextEdit Class")
197                         setGeometry(100,100,500,500)
198
199                         new qtextedit(win1) {
200                                 setGeometry(10,10,480,480)
201
202                         }
203
204                         show()
205                 }
206
207                 exec()
208         }       
209                 
210 実行中は qtextedit へリッチテキストを貼り付けることができます。
211
212 .. image:: ringqt_shot4.jpg
213         :alt: QTextEdit クラス
214         
215 .. index:: 
216         pair: RingQt によるデスクトップとモバイル開発; QListWidget クラスの用法
217
218 QListWidget クラスの用法
219 ============================
220
221 この用例では、 QListWidget クラスを使用しています。
222
223 .. code-block:: ring
224
225         Load "guilib.ring"
226
227         New qApp {
228
229                 win1 = new qWidget() {
230
231                         setGeometry(100,100,400,400)
232
233                         list1 = new qlistwidget(win1) {
234                                 setGeometry(150,100,200,200)
235                                 alist = ["one","two","three","four","five"]
236                                 for x in alist additem(x) next
237                                 setcurrentrow(3,2)
238                                 win1.setwindowtitle("Items Count : " + count() )
239                         }
240
241                         btn1 = new qpushbutton(win1) {
242                                 setGeometry(10,200,100,30)
243                                 settext("selected item")
244                                 setclickevent("pWork()")
245                         }
246
247                         btn2 = new qpushbutton(win1) {
248                                 setGeometry(10,240,100,30)
249                                 settext("Delete item")
250                                 setclickevent("pWork2()")
251                         }
252
253                         show()
254                 }
255
256                 exec()
257         }
258
259         func pWork
260                 btn1.settext(string(list1.currentrow()))
261
262         func pWork2
263                 list1 {
264                        takeitem(currentrow())
265                 }
266
267 実行中のアプリケーション
268
269 .. image:: ringqt_shot5.jpg
270         :alt: QListWidget Class
271
272
273 別の用例:
274
275 .. code-block:: ring
276
277         Load "guilib.ring"
278
279         New qApp {
280
281                 win1 = new qWidget() {
282
283                         setGeometry(100,100,500,400)
284
285                         list1 = new qlistwidget(win1) {
286                                 setGeometry(150,100,200,200)
287                                 alist = ["one","two","three","four","five"]
288                                 for x in alist additem(x) next
289                                 
290                                 setcurrentrow(3,2)
291                                 win1.setwindowtitle("Items Count : " + count() )
292                         }
293
294                         btn1 = new qpushbutton(win1) {
295                                 setGeometry(10,200,100,30)
296                                 settext("selected item")
297                                 setclickevent("pWork()")
298                         }
299
300                         btn2 = new qpushbutton(win1) {
301                                 setGeometry(10,240,100,30)
302                                 settext("Delete item")
303                                 setclickevent("pWork2()")
304                         }
305
306                         show()
307                 }
308
309                 exec()
310         }
311
312         func pWork
313                         
314                 nbrOfItems = list1.count()
315                 curItemNbr = list1.currentrow()
316                 curValue   = list1.item(list1.currentrow()).text()
317                 
318                 win1.setwindowtitle( "After Select - NbrOfItems: " + nbrOfItems +
319                         " CurItemNbr: " + curItemNbr + " CurValue: " + curValue )
320                 
321                 btn1.settext( string(list1.currentrow() ) + " --- " +
322                               list1.item(list1.currentrow()).text() )
323
324                 
325
326         func pWork2
327                 list1 {
328                         takeitem(currentrow())
329                         
330                         nbrOfItems = count()
331                         curItemNbr = currentrow()
332                         curValue   = item(currentrow()).text()
333                     
334                         win1.setwindowtitle("After Delete - NbrOfItems: " + nbrOfItems +
335                                 " CurItemNbr: " + curItemNbr +" CurValue: " + curValue )
336                 }
337
338        
339
340 .. index:: 
341         pair: RingQt によるデスクトップとモバイル開発; QTreeView および QFileSystemModel の用法
342
343 QTreeView および QFileSystemModel の用法
344 ============================================
345
346 この用例では、ファイルシステムを表示するために QTreeView ウィジェットの用法を学びます。
347
348 .. code-block:: ring
349
350         Load "guilib.ring"
351
352         New qApp {
353
354                 win1 = New qWidget() {
355
356                         setwindowtitle("Using QTreeView and QFileSystemModel")
357                         setGeometry(100,100,500,400)
358
359                         New qtreeview(win1) {
360                                 setGeometry(00,00,500,400)
361                                 oDir = new QDir()                       
362                                 ofile = new QFileSystemModel()
363                                 ofile.setrootpath(oDir.currentpath())
364                                 setmodel(ofile)
365                         }
366
367                         show()
368                 }
369
370                 exec()
371         }
372
373 実行中のアプリケーション
374
375 .. image:: ringqt_shot6.jpg
376         :alt: QTreeView および QFileSystemModel      
377         
378 .. index:: 
379         pair: RingQt によるデスクトップとモバイル開発; QTreeWidget と QTreeWidgetItem の用法
380
381 QTreeWidget と QTreeWidgetItem の用法
382 =========================================
383
384 この用例では、 QTreeWidget および QTreeWidgetItem クラスを学びます。
385
386 .. code-block:: ring
387
388         Load "guilib.ring"
389
390         New qApp {
391
392                 win1 = new qWidget() {
393
394                         setwindowtitle("TreeWidget")
395                         setGeometry(100,100,400,400)
396
397                         layout1 = new qvboxlayout()
398
399                         tree1 = new qtreewidget(win1) {
400                                 setGeometry(00,00,400,400)
401                                 setcolumncount(1)
402                                 myitem = new qtreewidgetitem()
403                                 myitem.settext(0,"The First Step")
404                                 addtoplevelitem(myitem)
405                                 for  x = 1 to 10
406                                         myitem2 = new qtreewidgetitem()
407                                         myitem2.settext(0,"hello"+x)
408                                         myitem.addchild(myitem2)
409                                         for  y = 1 to 10
410                                                 myitem3 = new qtreewidgetitem()
411                                                 myitem3.settext(0,"hello"+x)
412                                                 myitem2.addchild(myitem3)
413                                         next
414                                 next
415                                 setheaderlabel("Steps Tree")
416                         }
417
418                         layout1.addwidget(tree1)
419                         setlayout(layout1)
420
421                         show()
422                 }
423
424                 exec()
425         }
426
427 実行中のアプリケーション
428
429 .. image:: ringqt_shot7.jpg
430         :alt: QTreeWidget と QTreeWidgetItem
431
432 .. index:: 
433         pair: RingQt によるデスクトップとモバイル開発; QComboBox クラスの用法
434
435 QComboBox クラスの用法
436 ==========================
437
438 この用例では、 QComboBox クラスを学びます。
439
440 .. code-block:: ring
441
442         Load "guilib.ring"
443
444         New qApp {
445
446                 win1 = new qWidget() {
447
448                         setwindowtitle("Using QComboBox")
449                         setGeometry(100,100,400,400)
450
451                         New QComboBox(win1) {
452                                 setGeometry(150,100,200,30)
453                                 alist = ["one","two","three","four","five"]
454                                 for x in aList additem(x,0) next
455                         }
456
457                         show()
458                 }
459
460                 exec()
461         }
462
463             
464 実行中のアプリケーション
465
466 .. image:: ringqt_shot8.jpg
467         :alt: QComboBox
468
469         
470 .. index:: 
471         pair: RingQt によるデスクトップとモバイル開発; メニューバーの作成方法
472
473 メニューバーの作成方法
474 ======================
475
476 この用例では、 QMenuBar クラスを学びます。
477
478 .. code-block:: ring
479
480         Load "guilib.ring"
481
482         MyApp = New qApp {
483
484                 win1 = new qWidget() {
485
486                         setwindowtitle("Using QMenubar")
487                         setGeometry(100,100,400,400)
488
489                         menu1 = new qmenubar(win1) {            
490                                 sub1 = addmenu("File")
491                                 sub2 = addmenu("Edit")
492                                 sub3 = addmenu("Help")
493                                 sub1 { 
494                                         oAction = new qAction(win1) {
495                                                 settext("New")
496                                         }
497                                         addaction(oAction)
498                                         oAction = new qAction(win1) {
499                                                 settext("Open")
500                                         }
501                                         addaction(oAction)
502                                         oAction = new qAction(win1) {
503                                                 settext("Save")
504                                         }
505                                         addaction(oAction)
506                                         oAction = new qAction(win1) {
507                                                 settext("Save As")
508                                         }
509                                         addaction(oAction)                      
510                                         addseparator()
511                                         oAction = new qaction(win1) {
512                                                 settext("Exit")
513                                                 setclickevent("myapp.quit()")
514                                         }
515                                         addaction(oAction)
516                                 }
517                                 sub2 { 
518                                         oAction = new qAction(win1) {
519                                                 settext("Cut")
520                                         }
521                                         addaction(oAction)
522                                         oAction = new qAction(win1) {
523                                                 settext("Copy")
524                                         }
525                                         addaction(oAction)
526                                         oAction = new qAction(win1) {
527                                                 settext("Paste")
528                                         }
529                                         addaction(oAction)
530                                         addseparator()
531                                         oAction = new qAction(win1) {
532                                                 settext("Select All")
533                                         }
534                                         addaction(oAction)
535                                 }                               
536                                 sub3 { 
537                                         oAction = new qAction(win1) {
538                                                 settext("Reference")
539                                         }
540                                         addaction(oAction)                      
541                                         sub4 = addmenu("Sub Menu")
542                                         sub4 { 
543                                                 oAction = new qAction(win1) {
544                                                         settext("Website")
545                                                 }
546                                                 addaction(oAction)
547                                                 oAction = new qAction(win1) {
548                                                         settext("Forum")
549                                                 }
550                                                 addaction(oAction)
551                                                 oAction = new qAction(win1) {
552                                                         settext("Blog")
553                                                 }
554                                                 addaction(oAction)
555                                         }
556                                         addseparator()
557                                                 oAction = new qAction(win1) {
558                                                         settext("About")
559                                                 }
560                                                 addaction(oAction)                      
561                                 }
562                         }
563                         show()
564                 }
565                 exec()
566         }
567
568 実行中のアプリケーション
569
570 .. image:: ringqt_shot9.jpg
571         :alt: QMenuBar
572
573 .. index:: 
574         pair: RingQt によるデスクトップとモバイル開発; コンテキストメニュー
575
576 コンテキストメニュー
577 ====================
578
579 用例:
580
581 .. code-block:: ring
582
583         load "guilib.ring"
584
585         new qApp {
586                 win = new qwidget() {
587                         setwindowtitle("Context Menu")
588                         resize(400,400)
589                         myfilter = new qAllEvents(win) {
590                                 setContextmenuEvent("mymenu()")
591                         }
592                         installeventfilter(myfilter)
593                         show()
594                 }
595                 exec()
596         }
597
598
599         func mymenu 
600
601                 new qMenu(win) {
602                         oAction = new qAction(win) {
603                                 settext("new")
604                                 SetCLickevent("See :New")
605                         }
606                         addaction(oAction)
607                         oAction = new qAction(win) {
608                                 settext("open")
609                                 SetCLickevent("See :Open")
610                         }
611                         addaction(oAction)
612                         oAction = new qAction(win) {
613                                 settext("save")
614                                 SetCLickevent("See :Save")
615                         }
616                         addaction(oAction)
617                         oAction = new qAction(win) {
618                                 settext("close")
619                                 SetCLickevent("See :Close")
620                         }
621                         addaction(oAction)
622                         oCursor  = new qCursor()
623                         exec(oCursor.pos())
624                 }
625         
626
627
628 .. index:: 
629         pair: RingQt によるデスクトップとモバイル開発; ツールバーの作成方法
630         
631 ツールバーの作成方法
632 ====================
633
634 この用例では、 QToolBar クラスを学びます。
635
636 .. code-block:: ring
637
638         Load "guilib.ring"
639
640         New qApp {
641
642                 win1 = new qMainWindow() {
643
644                         setwindowtitle("Using QToolbar")
645                         setGeometry(100,100,600,400)
646
647                         abtns = [
648                                         new qpushbutton(win1) { settext("Add") } ,
649                                         new qpushbutton(win1) { settext("Edit") } ,
650                                         new qpushbutton(win1) { settext("Find") } ,
651                                         new qpushbutton(win1) { settext("Delete") } ,
652                                         new qpushbutton(win1) { settext("Exit") 
653                                                                 setclickevent("win1.close()") } 
654                                 ]
655
656                         tool1 = new qtoolbar(win1) {
657                                 for x in abtns addwidget(x) addseparator() next
658                                 setmovable(true)
659                                 setGeometry(0,0,500,30)                 
660                                 setFloatable(true)
661                         }
662
663                         show()
664                 }
665
666                 exec()
667         }
668
669 実行中のアプリケーション
670
671 .. image:: ringqt_shot10.jpg
672         :alt: QToolBar
673
674 .. index:: 
675         pair: RingQt によるデスクトップとモバイル開発; ステータスバーの作成方法
676         
677 ステータスバーの作成方法
678 ========================
679
680 この用例では、 QStatusBar クラスを学びます。
681
682 .. code-block:: ring
683
684         Load "guilib.ring"
685
686         New qApp {
687
688                 win1 = new qMainWindow() {
689
690                         setwindowtitle("Using QStatusbar")
691                         setGeometry(100,100,400,400)
692
693                         status1 = new qstatusbar(win1) {
694                                 showmessage("Ready!",0)
695                         }
696
697                         setstatusbar(status1)
698                         show()
699                 }
700
701                 exec()
702         }
703
704 実行中のアプリケーション
705
706 .. image:: ringqt_shot11.jpg
707         :alt: QStatusBar
708
709         
710 .. index:: 
711         pair: RingQt によるデスクトップとモバイル開発; QDockWidget の用法
712
713 QDockWidget の用法
714 ======================
715
716 この用例では、 QDockWidget クラスを学びます。
717
718 .. code-block:: ring
719
720         Load "guilib.ring"
721
722         New qApp {
723         
724                 win1 = new qMainWindow() {
725                 
726                         setwindowtitle("QDockWidget")
727                         setGeometry(100,100,400,400)
728
729                         label1 = new qlabel(win1) {
730                                 settext("Hello")
731                                 setGeometry(300,300,100,100)
732                         }
733                         
734                         label2 = new qlabel(win1) {
735                                 settext("How are you ?")
736                                 setGeometry(100,100,100,100)
737                         }
738                         
739                         dock1 = new qdockwidget(win1,0) {
740                                 setwidget(label1)
741                                 SetAllowedAreas(1)
742                         }
743                         
744                         dock2 = new qdockwidget(win1,0) {
745                                 setwidget(label2)
746                                 SetAllowedAreas(2)
747                         }
748
749                         adddockwidget(Qt_LeftDockWidgetArea,dock1,Qt_Horizontal)
750                         adddockwidget(Qt_LeftDockWidgetArea,dock2,Qt_Vertical)
751
752                         show()
753                 }
754                 exec()
755         }
756
757 実行中のアプリケーション
758
759 .. image:: ringqt_shot12.jpg
760         :alt: QDockWidget
761
762 .. index:: 
763         pair: RingQt によるデスクトップとモバイル開発; QTabWidget の用法
764
765 QTabWidget の用法
766 =====================
767
768 この用例では、 QTabWidget クラスを学びます。
769
770 .. code-block:: ring
771
772         Load "guilib.ring"
773
774         New qApp {
775
776                 win1 = new qMainWindow() {
777
778                         setwindowtitle("Using QTabWidget")
779                         setGeometry(100,100,400,400)
780
781                         page1 = new qwidget() {
782                                 new qpushbutton(page1) {
783                                         settext("The First Page")
784                                 }
785                         }
786
787                         page2 = new qwidget() {
788                                 new qpushbutton(page2) {
789                                         settext("The Second Page")
790                                 }
791                         }
792
793                         page3 = new qwidget() {
794                                 new qpushbutton(page3) {
795                                         settext("The Third Page")
796                                 }
797                         }
798
799                         tab1 = new qtabwidget(win1) {
800                                 inserttab(0,page1,"Page 1")
801                                 inserttab(1,page2,"Page 2")
802                                 inserttab(2,page3,"Page 3")
803                                 setGeometry(100,100,400,400)
804                         }               
805
806                         status1 = new qstatusbar(win1) {
807                                 showmessage("Ready!",0)
808                         }
809
810                         setstatusbar(status1)
811                         showMaximized()
812                 }
813
814                 exec()
815         }
816
817 実行中のアプリケーション
818
819 .. image:: ringqt_shot13.jpg
820         :alt: QTabWidget
821
822 .. index:: 
823         pair: RingQt によるデスクトップとモバイル開発; QTableWidget の用法
824
825 QTableWidget の用法
826 =======================
827
828 この用例では、 QTableWidget クラスを学びます。
829
830 .. code-block:: ring
831
832         Load "guilib.ring"
833
834         New qApp {
835
836                 win1 = new qMainWindow() {
837
838                         setGeometry(100,100,1100,370)
839                         setwindowtitle("Using QTableWidget")
840
841                         Table1 = new qTableWidget(win1) {       
842
843                                 setrowcount(10) setcolumncount(10)
844                                 setGeometry(0,0,800,400)
845                                 setselectionbehavior(QAbstractItemView_SelectRows)
846
847                                 for x = 1 to 10
848                                         for y = 1 to 10
849                                                 item1 = new qtablewidgetitem("R"+X+"C"+Y)
850                                                 setitem(x-1,y-1,item1)
851                                         next
852                                 next             
853
854                         }
855
856                         setcentralwidget(table1)
857                         show()
858
859                 }
860
861                 exec()
862         }
863
864
865 実行中のアプリケーション
866
867 .. image:: ringqt_shot14.jpg
868         :alt: QTableWidget
869
870 .. index:: 
871         pair: RingQt によるデスクトップとモバイル開発; QProgressBar の用法
872         
873 QProgressBar の用法
874 =======================
875
876 この用例では、 QProgressBar クラスを学びます。
877
878 .. code-block:: ring
879
880         Load "guilib.ring"
881
882         New qApp {
883                 win1 = new qMainWindow() {
884
885                         setGeometry(100,100,600,150)
886                         setwindowtitle("Using QProgressBar")
887
888                         for x = 10 to 100 step 10
889                                 new qprogressbar(win1) {        
890                                         setGeometry(100,x,350,30)
891                                         setvalue(x)
892                                 }
893                         next
894
895                         show()
896                 }
897                 exec()
898         }
899
900 実行中のアプリケーション
901
902 .. image:: ringqt_shot15.jpg
903         :alt: QProgressBar
904
905 .. index:: 
906         pair: RingQt によるデスクトップとモバイル開発; QSpinBox の用法
907
908 QSpinBox の用法
909 ===================
910
911 この用例では、 QSpinBox クラスを学びます。
912
913 .. code-block:: ring
914
915         Load "guilib.ring"
916
917         New qApp {
918                 win1 = new qMainWindow() {
919                         setGeometry(100,100,450,260)
920                         setwindowtitle("Using QSpinBox")
921                                 new qspinbox(win1) {    
922                                         setGeometry(50,100,350,30)
923                                         setvalue(50)
924                                 }
925                         show()
926                 }
927                 exec()
928         }
929
930 実行中のアプリケーション
931
932 .. image:: ringqt_shot16.jpg
933         :alt: QSpinBox
934         
935 .. index:: 
936         pair: RingQt によるデスクトップとモバイル開発; QSlider の用法
937
938 QSlider の用法
939 ==================
940
941 この用例では、 QSlider クラスを学びます。
942
943 .. code-block:: ring
944
945         Load "guilib.ring"
946
947         New qApp {
948
949                 win1 = new qMainWindow() {
950
951                         setGeometry(100,100,500,400)
952                         setwindowtitle("Using QSlider")
953
954                         new qslider(win1) {     
955                                 setGeometry(100,100,50,130)
956                                 settickinterval(50)                             
957                         }
958
959                         new qslider(win1) {     
960                                 setGeometry(100,250,250,30)
961                                 settickinterval(50)     
962                                 setorientation(Qt_Horizontal)                   
963                         }
964
965                         show()
966
967                 }
968
969                 exec()
970         }
971         
972 実行中のアプリケーション
973
974 .. image:: ringqt_shot17.jpg
975         :alt: QSlider
976
977 .. index:: 
978         pair: RingQt によるデスクトップとモバイル開発; QDateEdit の用法
979
980 QDateEdit の用法
981 ====================
982
983 この用例では、 QDateEdit クラスを学びます。
984
985 .. code-block:: ring
986         
987         Load "guilib.ring"
988
989         New qApp {
990                 win1 = new qMainWindow() {
991                         setwindowtitle("Using QDateEdit")
992                         setGeometry(100,100,250,100)
993                         new qdateedit(win1) {   
994                                 setGeometry(20,40,220,30)
995                         }
996                         show()
997                 }
998                 exec()
999         }
1000         
1001 実行中のアプリケーション
1002
1003 .. image:: ringqt_shot18.jpg
1004         :alt: QDateEdit
1005
1006 .. index:: 
1007         pair: RingQt によるデスクトップとモバイル開発; QDial の用法
1008         
1009
1010 QDial の用法
1011 ================
1012
1013 この用例では、 QDial クラスを学びます。
1014
1015 .. code-block:: ring
1016
1017         Load "guilib.ring"
1018
1019         New qApp {
1020                 win1 = new qMainWindow() {
1021                         setGeometry(100,100,450,500)
1022                         setwindowtitle("Using QDial")
1023                         new qdial(win1) {       
1024                                 setGeometry(100,100,250,300)
1025                         }
1026                         show()
1027                 }
1028                 exec()
1029         }
1030
1031 実行中のアプリケーション
1032
1033 .. image:: ringqt_shot19.jpg
1034         :alt: QDial
1035
1036 その他の用例:
1037
1038 .. code-block:: ring
1039
1040         Load "guilib.ring"
1041
1042         New qApp {
1043                          win1 = new qMainWindow() 
1044                         {
1045                                 setGeometry(100,100,450,500)
1046                                 setwindowtitle("Using QDial")
1047                                 button1 = new QPushButton(win1){
1048                                         setGeometry(100,350,100,30)
1049                                         settext("Increment")
1050                                         setClickEvent("pIncrement()")
1051                                 }
1052
1053                                 button2 = new QPushButton(win1){
1054                                         setGeometry(250,350,100,30)
1055                                         settext("Decrement")
1056                                         setClickEvent("pDecrement()")                                                                              
1057                                 } 
1058                                 pdial = new qdial(win1) {
1059                                         setGeometry(100,50,250,300)
1060                                         setNotchesVisible(true)
1061                                         setValue(50)
1062                                         SetValueChangedEvent("pDialMove()")
1063                                 }
1064                                 lineedit1 = new qlineedit(win1) {
1065                                         setGeometry(200,400,50,30)
1066                                         setalignment(Qt_AlignHCenter)
1067                                         settext(string(pdial.value()))
1068                                         setreturnPressedEvent("pPress()") 
1069                                 } 
1070                                 show()
1071                           }
1072                 exec()
1073         }
1074
1075         func pIncrement
1076                 pdial{val=value()}
1077                 pdial.setvalue(val+1)  
1078                 lineedit1{settext(string(val+1))}   
1079
1080         func pDecrement
1081                 pdial{val=value()}
1082                 pdial.setvalue(val-1)   
1083                 lineedit1{settext(string(val-1))}  
1084
1085         func pPress
1086                 lineedit1{val=text()}
1087                 pdial.setvalue(number(val)) 
1088
1089         func pDialMove
1090                 lineedit1.settext(""+pdial.value())
1091
1092
1093 .. image:: usingqdial.png
1094         :alt: QDial - 第二用例
1095
1096
1097 .. index:: 
1098         pair: RingQt によるデスクトップとモバイル開発; QWebView の用法
1099
1100 QWebView の用法
1101 ===================
1102
1103 この用例では、 QWebView クラスを学びます。
1104
1105 .. code-block:: ring
1106
1107         Load "guilib.ring"
1108
1109         New qApp {
1110                 win1 = new qMainWindow() {
1111                         setwindowtitle("QWebView")
1112                         myweb = new qwebview(win1) {    
1113                                 setGeometry(10,10,600,600)
1114                                 loadpage(new qurl("http://google.com"))
1115                         }
1116                         setcentralwidget(myweb)
1117                         showMaximized()
1118                 }
1119                 exec()
1120         }
1121
1122 実行中のアプリケーション
1123
1124 .. image:: ringqt_shot20.jpg
1125         :alt: QWebView
1126
1127
1128 .. index:: 
1129         pair: RingQt によるデスクトップとモバイル開発; QCheckBox の用法
1130         
1131 QCheckBox の用法
1132 ====================
1133
1134 この用例では、 QCheckBox クラスを学びます。
1135
1136 .. code-block:: ring
1137
1138         Load "guilib.ring"
1139
1140         New qApp {
1141                 win1 = new qMainWindow() {
1142                         setwindowtitle("Using QCheckBox")
1143                         new qcheckbox(win1) {   
1144                                 setGeometry(100,100,100,30)
1145                                 settext("New Customer!")
1146                         }
1147                         showMaximized()
1148                 }
1149                 exec()
1150         }
1151
1152 実行中のアプリケーション
1153
1154 .. image:: ringqt_shot21.jpg
1155         :alt: QCheckBox
1156
1157
1158 その他の用例:
1159
1160 .. code-block:: ring
1161
1162         Load "guilib.ring"
1163
1164         New qApp {
1165                 win1 = new qMainWindow() {
1166                         setGeometry(100,100,400,300)
1167                         setwindowtitle("Using QCheckBox")
1168                         
1169                         ### 0: チェックされていない。  1: チェックされた。
1170                         
1171                         CheckBox = new qcheckbox(win1) {
1172                                 setGeometry(100,100,160,30)
1173                                 settext("New Customer!")
1174                                 setclickedEvent("HandleClickEvent()")
1175                         }                   
1176                                     
1177                         show()                            
1178                 }
1179                 exec()
1180         }
1181
1182         Func HandleClickEvent
1183             
1184             if CheckBox.isChecked() = 1 
1185                 CheckBox.settext("New Customer. Check 1-ON")
1186             else
1187                 CheckBox.settext("New Customer. Check 0-OFF")
1188             ok
1189
1190
1191 .. index:: 
1192         pair: RingQt によるデスクトップとモバイル開発; QRadioButton と QButtonGroup の用法
1193         
1194 QRadioButton と QButtonGroup の用法
1195 =======================================
1196
1197 この用例では、 QRadioButton および QButtonGroup クラスを学びます。
1198
1199 .. code-block:: ring
1200
1201         Load "guilib.ring"
1202
1203         New qApp {
1204
1205                 win1 = new qMainWindow() {
1206
1207                         setwindowtitle("Using QRadioButton")
1208
1209                         new qradiobutton(win1) {        
1210                                 setGeometry(100,100,100,30)
1211                                 settext("One")
1212                         }
1213                         new qradiobutton(win1) {        
1214                                 setGeometry(100,150,100,30)
1215                                 settext("Two")
1216                         }
1217                         new qradiobutton(win1) {        
1218                                 setGeometry(100,200,100,30)
1219                                 settext("Three")
1220                         }
1221
1222
1223                         group2  = new qbuttongroup(win1) {
1224                                 btn4 = new qradiobutton(win1) { 
1225                                         setGeometry(200,150,100,30)
1226                                         settext("Four")
1227                                 }
1228                                 btn5 = new qradiobutton(win1) { 
1229                                         setGeometry(200,200,100,30)
1230                                         settext("Five")
1231                                 }
1232                                 addbutton(btn4,0)
1233                                 addbutton(btn5,0)
1234
1235                         }
1236
1237                         showMaximized()
1238
1239                 }
1240                 exec()
1241         }
1242
1243 実行中のアプリケーション
1244
1245 .. image:: ringqt_shot22.jpg
1246         :alt: QRadioButton と QButtonGroup の用法
1247
1248 .. index:: 
1249         pair: RingQt によるデスクトップとモバイル開発; QLabel へハイパーリンクを追加するには
1250
1251 QLabel へハイパーリンクを追加するには
1252 =====================================
1253
1254 この用例では、 QLabel クラスでハイパーリンクを作成する方法を学びます。
1255
1256 .. code-block:: ring
1257
1258         Load "guilib.ring"
1259
1260         New qApp {
1261                 win1 = new qMainWindow() {
1262                         setwindowtitle("QLabel - Hyperlink")
1263                         new qlabel(win1) {      
1264                                 setGeometry(100,100,100,30)
1265                                 setopenexternallinks(true)
1266                                 settext('<a href="http://google.com">Google</a>')
1267                         }
1268                         showMaximized()
1269                 }
1270                 exec()
1271         }
1272
1273 実行中のアプリケーション
1274
1275 .. image:: ringqt_shot23.jpg
1276         :alt: ハイパーリンク
1277         
1278 .. index:: 
1279         pair: RingQt によるデスクトップとモバイル開発; QVideoWidget と QMediaPlayer
1280
1281 QVideoWidget と QMediaPlayer
1282 =============================
1283
1284 この用例では、 QVideoWidget および QMediaPlayer クラスで動画のグループを
1285 異なる位置から同時再生する方法を学びます。
1286
1287
1288 .. code-block:: ring
1289
1290         Load "guilib.ring"
1291
1292         New qApp {
1293
1294                 win1 = new qMainWindow() {
1295
1296                         setwindowtitle("QVideoWidget")
1297                         
1298                         btn1 = new qpushbutton(win1)    {
1299                                 setGeometry(0,0,100,30)
1300                                 settext("play")
1301                                 setclickevent("player.play() player2.play() 
1302                                                            player3.play() player4.play()")
1303                         }
1304
1305                         videowidget = new qvideowidget(win1) {
1306                                 setGeometry(50,50,600,300)
1307                                 setstylesheet("background-color: black")                        
1308                         }
1309
1310                         videowidget2 = new qvideowidget(win1) {
1311                                 setGeometry(700,50,600,300)
1312                                 setstylesheet("background-color: black")
1313                         }
1314
1315
1316                         videowidget3 = new qvideowidget(win1) {
1317                                 setGeometry(50,370,600,300)
1318                                 setstylesheet("background-color: black")
1319                         }
1320
1321                         videowidget4 = new qvideowidget(win1) {
1322                                 setGeometry(700,370,600,300)
1323                                 setstylesheet("background-color: black")
1324                         }
1325
1326                         player = new qmediaplayer() {
1327                                 setmedia(new qurl("1.mp4"))
1328                                 setvideooutput(videowidget)
1329                                 setposition(35*60*1000)
1330                                 
1331                         }               
1332
1333                         player2 = new qmediaplayer() {
1334                                 setmedia(new qurl("2.mp4"))
1335                                 setvideooutput(videowidget2)
1336                                 setposition(23*60*1000)
1337                         }               
1338
1339                         player3 = new qmediaplayer() {
1340                                 setmedia(new qurl("3.mp4"))
1341                                 setvideooutput(videowidget3)
1342                                 setposition(14.22*60*1000)
1343                         }               
1344
1345                         player4 = new qmediaplayer() {
1346                                 setmedia(new qurl("4.avi"))
1347                                 setvideooutput(videowidget4)
1348                                 setposition(8*60*1000)
1349                         }               
1350                         
1351                         showfullscreen()                
1352
1353                 }
1354
1355                 exec()
1356
1357         }
1358
1359         
1360 実行中のアプリケーション
1361
1362 .. image:: ringqt_shot24.jpg
1363         :alt: QVideoWidget
1364
1365         
1366 .. index:: 
1367         pair: RingQt によるデスクトップとモバイル開発; QFrame の用法
1368
1369 QFrame の用法
1370 =================
1371
1372 この用例では、 QFrame クラスを学びます。
1373
1374 .. code-block:: ring
1375
1376         Load "guilib.ring"
1377
1378         New qApp {
1379                 win1 = new qMainWindow() {
1380                         setwindowtitle("Using QFrame")
1381                         for x = 0 to 10
1382                                 frame1 = new qframe(win1,0) {   
1383                                         setGeometry(100,20+50*x,400,30)
1384                                         setframestyle(QFrame_Raised | QFrame_WinPanel)                          
1385                                 }
1386                         next
1387                         showMaximized()
1388                 }
1389                 exec()
1390         }
1391
1392
1393 実行中のアプリケーション
1394
1395 .. image:: ringqt_shot25.jpg
1396         :alt: QFrame
1397
1398
1399 .. index:: 
1400         pair: RingQt によるデスクトップとモバイル開発; QLabel による画像の表示方法
1401         
1402 QLabel による画像の表示方法
1403 ===============================
1404
1405 QLabel ウイジェットによる画像の表示方法を学びます。
1406
1407 .. code-block:: ring
1408
1409         Load "guilib.ring"
1410
1411         New qApp {
1412                 win1 = new qMainWindow() {
1413                         setwindowtitle("QLabel - Display image")
1414                         new qlabel(win1) {      
1415                                 image = new qpixmap("b:/mahmoud/photo/advice.jpg")
1416                                 setpixmap(image)
1417                                 setGeometry(0,0,image.width(),image.height())
1418                         }
1419                         showMaximized()
1420                 }
1421                 exec()
1422         }
1423
1424 実行中のアプリケーション
1425
1426 .. image:: ringqt_shot26.jpg
1427         :alt: 画像の表示
1428
1429         
1430 .. index:: 
1431         pair: RingQt によるデスクトップとモバイル開発; メニューバーとスタイルシートの用例
1432
1433 メニューバーとスタイルシートの用例
1434 ==================================
1435
1436 メニューバーの作成、およびウィンドウのスタイルシートの設定方法を学びます。
1437
1438 .. code-block:: ring
1439
1440         Load "guilib.ring"
1441
1442         New qApp {
1443
1444                 win1 = new qMainWindow() {
1445
1446                         setwindowtitle("Menubar")
1447
1448                         menu1 = new qmenubar(win1) {            
1449                                 sub1 = addmenu("File")
1450                                 sub1 { 
1451                                         oAction = new qAction(win1) {
1452                                                 settext("New")          
1453                                                 setenabled(false)
1454                                         }
1455                                         addaction(oAction)
1456                                         oAction = new qAction(win1) {
1457                                                 settext("Open")
1458                                                 setcheckable(true)
1459                                                 setchecked(true)
1460                                                 setstatustip("open new file")                                    
1461                                         }
1462                                         addaction(oAction)
1463                                         oAction = new qAction(win1) {
1464                                                 settext("Save")
1465                                         }
1466                                         addaction(oAction)
1467                                         oAction = new qAction(win1) {
1468                                                 settext("Save As")
1469                                         }
1470                                         addaction(oAction)
1471                                 
1472                                         addseparator()
1473                                         oAction = new qaction(win1)
1474                                         oAction.settext("Exit")
1475                                         oAction.setclickevent("myapp.quit()")
1476                                         addaction(oAction)
1477                                 }                       
1478
1479                         }
1480                         status1 = new qstatusbar(win1) {
1481                                 showmessage("Ready!",0)
1482                         }
1483                         setmenubar(menu1)
1484                         setmousetracking(true)
1485                         setstatusbar(status1)
1486                         setStyleSheet("color: black; selection-color: black;
1487                         selection-background-color:white ;
1488                         background: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1,
1489                         stop: 0 #eef, stop: 1 #ccf);")
1490                         showmaximized()
1491                 }
1492                 exec()
1493         }
1494
1495 実行中のアプリケーション
1496
1497 .. image:: ringqt_shot27.jpg
1498         :alt: メニューバー
1499
1500 .. index:: 
1501         pair: RingQt によるデスクトップとモバイル開発; QLineEdit イベントと QMessageBox
1502
1503 QLineEdit イベントと QMessageBox
1504 ================================
1505
1506 QLineEdit イベントの用法、およびメッセージボックスの表示方法を学びます。
1507
1508 .. code-block:: ring
1509
1510         Load "guilib.ring"
1511
1512         MyApp = New qApp {
1513
1514                 win1 = new qWidget() {
1515
1516                         setwindowtitle("Welcome")
1517                         setGeometry(100,100,400,300)
1518
1519
1520                         label1 = new qLabel(win1) {
1521                                 settext("What is your name ?")
1522                                 setGeometry(10,20,350,30)
1523                                 setalignment(Qt_AlignHCenter)
1524                         }
1525
1526                         btn1 = new qpushbutton(win1) {
1527                                 setGeometry(10,200,100,30)
1528                                 settext("Say Hello")
1529                                 setclickevent("pHello()")
1530                         }
1531
1532                         btn1 = new qpushbutton(win1) {
1533                                 setGeometry(150,200,100,30)
1534                                 settext("Close")
1535                                 setclickevent("pClose()")
1536                         }
1537
1538                         lineedit1 = new qlineedit(win1) {
1539                                 setGeometry(10,100,350,30)
1540                                 settextchangedevent("pChange()")
1541                                 setreturnpressedevent("penter()")
1542                         }
1543
1544                         show()
1545                 }
1546
1547                 exec()
1548         }
1549
1550         Func pHello  
1551                 lineedit1.settext( "Hello " + lineedit1.text())
1552
1553         Func pClose 
1554                 MyApp.quit()
1555
1556         Func pChange
1557                 win1 { setwindowtitle( lineedit1.text() ) }
1558
1559         Func pEnter
1560                 new qmessagebox(win1) {
1561                         setwindowtitle("Thanks")
1562                         settext("Hi " + lineedit1.text() )
1563                         setstylesheet("background-color : white")
1564                         show()
1565                 }
1566
1567 実行中のアプリケーション
1568
1569 .. image:: ringqt_shot28.jpg
1570         :alt: QLineEdit イベントと QMessageBox
1571
1572 .. image:: ringqt_shot29.jpg
1573         :alt: QLineEdit イベントと QMessageBox
1574         
1575 .. index:: 
1576         pair: RingQt によるデスクトップとモバイル開発; そのほかのウイジェットイベント
1577
1578 そのほかのウイジェットイベント
1579 ==============================
1580
1581 各 Qt シグナルは RingQt で使えます。シグナル名の前に設定を行うことで追加、 
1582 およびイベントのコードを決定するために使用できるメソッドを取得するためにシグナル名の後にイベントを追加します。
1583
1584 例えば QProgressBar クラスにはシグナル名である valueChanged() があります。
1585 使用するには setValueChangedEvent() 関数を使用します。
1586
1587 用例:
1588
1589 .. code-block:: ring
1590
1591         Load "guilib.ring"
1592
1593         New qApp {
1594                 win1 = new qMainWindow() {
1595
1596                         setwindowtitle("QProgressBar valueChanged Event")
1597
1598                         progress1 = new qprogressbar(win1) {    
1599                                 setGeometry(100,100,350,30)
1600                                 setvalue(10)
1601                                 setvaluechangedevent("pChange()")
1602                         }
1603
1604                         new qpushbutton(win1) {
1605                                 setGeometry(10,10,100,30)                       
1606                                 settext("increase")
1607                                 setclickevent("pIncrease()")
1608                         }
1609
1610                         showMaximized()
1611
1612                 }
1613
1614                 exec()
1615         }
1616
1617         func pIncrease
1618                 progress1 { setvalue(value()+1)  }
1619
1620         func pchange
1621                 win1.setwindowtitle("value : " + progress1.value() )
1622
1623 実行中のアプリケーション
1624
1625 .. image:: ringqt_shot30.jpg
1626         :alt: qProgressBar クラスの valueChanged イベント
1627
1628 別の用例は QCheckBox クラスの stateChanged イベントです。
1629
1630 .. code-block:: ring
1631
1632         Load "guilib.ring"
1633
1634         New qApp {
1635                 win1 = new qMainWindow() {
1636                         setwindowtitle("QCheckBox")
1637                         new qcheckbox(win1) {   
1638                                 setGeometry(100,100,100,30)
1639                                 settext("New Customer!")
1640                                 setstatechangedevent("pchange()")
1641                         }
1642                         showMaximized()
1643                 }
1644                 exec()
1645         }
1646
1647         Func pChange
1648
1649                 new qMessageBox(Win1) {
1650                         setWindowTitle("Checkbox")
1651                         settext("State Changed!")
1652                         show()
1653                 }
1654
1655 実行中のアプリケーション
1656
1657 .. image:: ringqt_shot31.jpg
1658         :alt: qProgressBar クラスの valueChanged イベント
1659
1660 .. index:: 
1661         pair: RingQt によるデスクトップとモバイル開発; QTimer クラスの用法
1662
1663 QTimer クラスの用法
1664 =======================
1665
1666 この用例では、 QTimer クラスを学びます。
1667
1668 .. code-block:: ring
1669
1670         Load "guilib.ring"
1671
1672         new qApp {
1673                 win1 = new qwidget() {
1674                         setgeometry(100,100,200,70)
1675                         setwindowtitle("Timer")
1676                         label1 = new qlabel(win1) {
1677                                 setgeometry(10,10,200,30)
1678                                 settext(thetime()) 
1679                         }
1680                         new qtimer(win1) {
1681                                 setinterval(1000)
1682                                 settimeoutevent("pTime()")
1683                                 start()
1684                         }
1685                         show()
1686                 }
1687                 exec()
1688         }
1689
1690         func ptime
1691                 label1.settext(thetime())
1692
1693         Func thetime
1694                 return "Time : " + Time()
1695
1696
1697 実行中のアプリケーション
1698
1699 .. image:: ringqt_shot32.jpg
1700         :alt: QTimer クラス
1701
1702 .. index:: 
1703         pair: RingQt によるデスクトップとモバイル開発; QProgressBar およびタイマーの用法
1704
1705 QProgressBar およびタイマーの用法
1706 =====================================
1707
1708 この用例では、“アニメーション”つきの QProgressBar クラスとタイマーを学びます。
1709
1710 .. code-block:: ring    
1711
1712         ###------------------------------------
1713         ### プログレスバーとタイマーの用例
1714         
1715         Load "guilib.ring"
1716         
1717         new qApp
1718         {
1719             win1 = new qwidget()
1720             {
1721                 setgeometry(100,100,400,100)
1722                 setwindowtitle("Timer and ProgressBar")
1723         
1724                 LabelMan = new qlabel(win1)
1725                 {
1726                     setgeometry(10,10,200,30)
1727                     settext(theTime())          ### ==>> 関数
1728                 }
1729         
1730                 TimerMan = new qtimer(win1)
1731                 {
1732                     setinterval(1000)
1733                     settimeoutevent("pTime()")  ### ==>> 関数
1734                     start()
1735                 }
1736         
1737                 BarMan = new qprogressbar(win1)
1738                 {
1739                     setGeometry(100,50,300,10)  ###  X, Y 位置、長さ、チックネス
1740                     setvalue(0)                 ###  パーセントが塗りつぶされた
1741                 }
1742         
1743                 show()
1744             }
1745             exec()
1746         }
1747         
1748         func pTime
1749                 LabelMan.settext(theTime())     ### ==>> 関数
1750         
1751                 Increment = 10
1752                 if BarMan.value() >= 100        ### プログレスバーの開始後.
1753                     BarMan.setvalue(0)
1754                 ok
1755                 BarMan{ setvalue(value() + Increment) }
1756         
1757         Func theTime
1758                 return "Time : " + Time()
1759
1760 .. image:: ringqt_shot15-B.jpg
1761         :alt: QProgressBar
1762
1763 .. index:: 
1764         pair: RingQt によるデスクトップとモバイル開発; QLabel による寸法変更画像の表示方法
1765
1766 QLabel による寸法変更画像の表示方法
1767 =======================================
1768
1769 この例では QLabel ウィジェットで“アニメーションつき”の画像を表示して寸法を変更する方法を学びます。
1770
1771 .. code-block:: ring
1772
1773         Load "guilib.ring"
1774
1775         #----------------------------------------------------
1776         # 必携: image = "C:\RING\bin\stock.jpg"
1777
1778         # imageStock: 伸張する画像の開始寸法
1779
1780         imageW = 200 ;  imageH = 200 ; GrowBy = 4
1781
1782         ###----------------------------------------------------
1783         ### ウィンドウと箱の大きさの寸法
1784
1785         WinWidth = 1280 ; WinHeight = 960
1786         BoxWidth = WinWidth -80 ; BoxHeight = WinHeight -80
1787
1788         ###----------------------------------------------------
1789
1790         New qapp {
1791
1792                 win1 = new qwidget() {
1793
1794                         setgeometry(50,50, WinWidth,WinHeight)
1795                         setwindowtitle("Animated Image - Display Image Scaled and Resized")
1796
1797                         imageStock = new qlabel(win1) {
1798
1799                                 image = new qpixmap("C:\RING\bin\stock.jpg")
1800                                 AspectRatio = image.width() / image.height()
1801
1802                                 imageW = 200
1803                                 imageH = imageH / AspectRatio
1804
1805                                 ### 水平寸法、垂直寸法、アスペクト比、変形
1806                                 setpixmap(image.scaled(imageW , imageH ,0,0))   
1807
1808                                 PosLeft = (BoxWidth  - imageW ) / 2
1809                                 PosTop  = (BoxHeight - imageH ) / 2
1810                                 setGeometry(PosLeft,PosTop,imageW,imageH)
1811
1812                         }
1813
1814                         TimerMan = new qtimer(win1) {
1815                                 setinterval(100)            ### 100 ミリ秒間隔です。
1816                                 settimeoutevent("pTime()")  ### ==>> 関数
1817                                 start()
1818                         }
1819
1820                         show()
1821                 }
1822         exec()
1823         }
1824
1825
1826         ###------------------------------------------------------
1827         ### TimerMan 関数: 100 ミリ秒間隔で呼び出します。
1828
1829         func pTime
1830
1831                 ### 画像の大きさがウィンドウ領域に達したときにタイマーを停止します。
1832                 if imageW > BoxWidth
1833                         TimerMan.stop()
1834                         imageStock.clear()      ### 画像の消去
1835                 ok
1836
1837                 ## 画像の伸張
1838                 imageW += GrowBy
1839                 imageH  = imageW / AspectRatio
1840
1841                 ### 画像の寸法変更: 水平寸法、垂直寸法、アスペクト比、変形
1842                 imageStock.setpixmap(image.scaled(imageW , imageH ,0,0))
1843
1844                 ### 画像を中央へ
1845                 PosLeft = (WinWidth  - imageW ) / 2
1846                 PosTop  = (WinHeight - imageH ) / 2
1847                 imageStock.setGeometry(PosLeft,PosTop,imageW,imageH)
1848
1849
1850 .. index:: 
1851         pair: RingQt によるデスクトップとモバイル開発; QFileDialog クラスの用法
1852
1853 QFileDialog クラスの用法
1854 ============================
1855
1856 用例:
1857
1858 .. code-block:: ring
1859
1860         Load "guilib.ring"
1861
1862         New qapp {
1863                 win1 = new qwidget() {
1864                         setwindowtitle("open file")
1865                         setgeometry(100,100,400,400)
1866                         new qpushbutton(win1) {
1867                                 setgeometry(10,10,200,30)
1868                                 settext("open file")
1869                                 setclickevent("pOpen()")
1870                         }
1871                         show()
1872                 }
1873                 exec()
1874         }
1875
1876         Func pOpen
1877                 new qfiledialog(win1) {
1878                         cName = getopenfilename(win1,"open file","c:\","source files(*.ring)")
1879                         win1.setwindowtitle(cName)
1880                 }
1881                 
1882 実行中のアプリケーション
1883
1884 .. image:: ringqt_shot33.jpg
1885         :alt: QFileDialog クラス
1886
1887 .. index:: 
1888         pair: RingQt によるデスクトップとモバイル開発; QPainter による描画方法
1889
1890 QPainter による描画方法
1891 ===========================
1892
1893 この用例では、 QPainter クラスによる描画方法を学びます。
1894
1895 .. code-block:: ring
1896
1897         Load "guilib.ring"
1898         New qapp {
1899                 win1 = new qwidget() {
1900                         setwindowtitle("Drawing using QPainter")
1901                         setgeometry(100,100,500,500)
1902                         label1 = new qlabel(win1) {
1903                                 setgeometry(10,10,400,400)
1904                                 settext("")
1905                         }
1906                         new qpushbutton(win1) {
1907                                 setgeometry(200,400,100,30)
1908                                 settext("draw")
1909                                 setclickevent("draw()")
1910                         }
1911
1912                         show()
1913                 }
1914                 exec()
1915         }
1916
1917         Func draw
1918                         p1 = new qpicture()
1919                         color = new qcolor() {
1920                                 setrgb(0,0,255,255)
1921                         }
1922                         pen = new qpen() {
1923                                 setcolor(color)
1924                                 setwidth(10)
1925                         }
1926                         new qpainter() {
1927                                 begin(p1)
1928                                 setpen(pen)
1929                                 drawline(500,150,950,450)
1930                                 drawline(950,550,500,150)
1931                                 endpaint()
1932                         }
1933                         label1 { setpicture(p1) show() }
1934
1935 実行中のアプリケーション
1936
1937 .. image:: ringqt_shot34.jpg
1938         :alt: QPainter クラス
1939
1940 .. index:: 
1941         pair: RingQt によるデスクトップとモバイル開発; QPrinter による印刷方法
1942
1943 QPrinter による印刷方法
1944 ===========================
1945
1946 この用例では、 QPrinter で PDF ファイルを印刷する方法を学びます。
1947
1948 .. code-block:: ring
1949
1950         Load "guilib.ring"
1951         new qApp {
1952                 win1 = new qwidget() {
1953                         setwindowtitle("Printer")
1954                         setgeometry(100,100,500,500)
1955                         myweb = new qwebview(win1) {    
1956                                 setgeometry(100,100,1000,500)                                           
1957                                 loadpage(new qurl("http://google.com"))
1958                         } 
1959                         new qpushbutton(win1) {
1960                                 setGeometry(20,20,100,30)                       
1961                                 settext("Print")
1962                                 setclickevent("print()")
1963                         }
1964                         showmaximized()
1965                 }
1966                 exec()
1967         }
1968         
1969         func print
1970                 printer1 = new qPrinter(0) {
1971                         setoutputformat(1)      # 1 = pdf
1972                         setoutputfilename("test.pdf")
1973                         painter = new qpainter() {
1974                                 begin(printer1)
1975                                 myfont = new qfont("Times",50,-1,0)                     
1976                                 setfont(myfont)
1977                                 drawtext(100,100,"test")
1978                                 printer1.newpage()
1979                                 drawtext(100,100,"test2")                       
1980                                 endpaint()
1981                         }
1982                 }
1983
1984                 printer1 = new qPrinter(0) {
1985                         setoutputformat(1)      
1986                         setoutputfilename("test2.pdf")
1987                         myweb.print(printer1)
1988                         myweb.show()
1989                 }
1990
1991                 system ("test.pdf")
1992                 system ("test2.pdf")
1993
1994
1995 .. index:: 
1996         pair: RingQt によるデスクトップとモバイル開発; QPrintPreviewDialog の用法
1997
1998 QPrintPreviewDialog の用法
1999 ==============================
2000
2001 この用例では、 QPrintPreviewDialog クラスの用法を学びます。
2002
2003 用例:
2004
2005 .. code-block:: ring
2006
2007         load "guilib.ring"
2008
2009         new qApp {
2010                 win1 = new qwidget() {
2011                         setwindowtitle("Printer Preview Dialog")
2012                         setgeometry(100,100,800,880)
2013                         printer1 = new qPrinter(0)
2014                         show()
2015                         oPreview = new qPrintPreviewDialog(printer1) {
2016                                 setParent(win1)
2017                                 move(10,10) 
2018                                 setPaintrequestedevent("printPreview()")
2019                                 exec()
2020                         }
2021                 }
2022                 exec()
2023         }
2024
2025         func printPreview
2026                 printer1  {
2027                         painter = new qpainter() {
2028                                 begin(printer1)
2029                                 myfont = new qfont("Times",50,-1,0)
2030                                 setfont(myfont)
2031                                 drawtext(100,100,"Test - Page (1)")
2032                                 printer1.newpage()
2033                                 drawtext(100,100,"Test - Page (2)")
2034                                 printer1.newpage()
2035                                 myfont2 = new qfont("Times",14,-1,0)
2036                                 setfont(myfont2)
2037                                 for x = 1 to 30
2038                                         drawtext(100,100+(20*x),"Number : " + x)
2039                                 next 
2040                                 endpaint()
2041                         }
2042                 }
2043
2044 スクリーンショット:
2045
2046 .. image:: printpreviewdialog.png
2047         :alt: 印刷プレビューのダイアログ
2048
2049 .. index:: 
2050         pair: RingQt によるデスクトップとモバイル開発; 複数ウィンドウの作成方法
2051
2052 複数ウィンドウの作成方法
2053 ========================
2054
2055 この用例は、複数ウィンドウの作成をするためのデモです。
2056
2057 .. code-block:: ring
2058
2059         Load "guilib.ring"
2060         app1 = new qapp {
2061                 win1 = new qwidget() {
2062                         setwindowtitle("First")
2063                         setgeometry(100,100,500,500)
2064
2065                         new qpushbutton(win1) {
2066                                 setgeometry(100,100,100,30)
2067                                 settext("close")
2068                                 setclickevent("app1.quit()")
2069                         }
2070
2071                         new qpushbutton(win1) {
2072                                 setgeometry(250,100,100,30)
2073                                 settext("Second")
2074                                 setclickevent("second()")
2075                         }
2076
2077                         showmaximized()
2078                 }
2079                 exec()
2080         }
2081          
2082         func second
2083                 win2 = new qwidget() {
2084                         setwindowtitle("Second")
2085                         setgeometry(100,100,500,500)
2086                         setwindowflags(Qt_dialog)
2087                         show()
2088                 }
2089  
2090 実行中のアプリケーション
2091
2092 .. image:: ringqt_shot35.jpg
2093         :alt: 複数ウィンドウの作成方法
2094
2095 .. index:: 
2096         pair: RingQt によるデスクトップとモバイル開発; 音声の再生
2097
2098 音声の再生
2099 =============
2100
2101 用例:
2102
2103 .. code-block:: ring
2104
2105         Load "guilib.ring"
2106         new qapp {
2107                 win1 = new qwidget() {
2108                         setwindowtitle("play sound!") show()    
2109                 }
2110                 new qmediaplayer()      {
2111                         setmedia(new qurl("footstep.wav"))
2112                         setvolume(50) play()    
2113                 }
2114                 exec()
2115         }
2116         
2117 .. index:: 
2118         pair: RingQt によるデスクトップとモバイル開発; QColorDialog クラスの用法
2119
2120 QColorDialog クラスの用法
2121 =============================
2122
2123 用例: 
2124
2125 .. code-block:: ring
2126
2127         Load "guilib.ring"
2128
2129         oApp = new myapp { start() }
2130
2131         Class MyApp
2132
2133                 oColor  win1
2134
2135                 Func start
2136
2137                         myapp = new qapp 
2138
2139                         win1 = new qMainWindow() {
2140                                 setwindowtitle("Color Dialog")
2141                                 setgeometry(100,100,400,400)
2142                         }
2143
2144                         new qpushbutton(win1) {
2145                                 setgeometry(10,10,100,30)
2146                                 settext("Get Color")
2147                                 setclickevent("oApp.pColor()")
2148                         }
2149
2150                         win1.show()
2151                         myapp.exec()
2152
2153
2154                 Func pColor
2155                         myobj = new qcolordialog()
2156                         aColor = myobj.GetColor()
2157                         r=acolor[1] g=acolor[2] b=acolor[3]      
2158                         win1.setstylesheet("background-color: rgb("+r+", " + g+ "," + b + ")")
2159
2160 実行中のアプリケーション
2161                         
2162 .. image:: ringqt_shot37.jpg
2163         :alt: QColorDialog クラス
2164
2165 .. index:: 
2166         pair: RingQt によるデスクトップとモバイル開発; qLCDNumber クラスの用法
2167
2168 qLCDNumber クラスの用法
2169 ===========================
2170
2171 この用例では、 qLCDNumber クラスを学びます。
2172
2173 .. code-block:: ring
2174
2175         Load "guilib.ring"
2176
2177         New qApp 
2178         {
2179                 win1 = new qWidget() 
2180                 {
2181                         setwindowtitle("LCD Number")
2182                         setgeometry(100,100,250,120)
2183
2184                         new qLCDNumber(win1) 
2185                         {
2186                                 setgeometry(10,10,100,40)
2187                                 display(100)    
2188                                 
2189                         }
2190
2191                         new qLCDNumber(win1) 
2192                         {
2193                                 setgeometry(10,60,100,40)
2194                                 display(80)     
2195                                 
2196                         }
2197
2198                         show()
2199                 }
2200         
2201                 exec()
2202         }
2203
2204 実行中のアプリケーション
2205                         
2206 .. image:: ringqt_shot38.jpg
2207         :alt: QLCDNumber クラス
2208
2209 .. index:: 
2210         pair: RingQt によるデスクトップとモバイル開発; 移動可能ラベルの用例
2211
2212 移動可能ラベルの用例
2213 ======================
2214
2215 .. code-block:: ring
2216
2217         Load "guilib.ring"
2218
2219         new qApp {
2220
2221                 win1 = new qWidget() 
2222                 {
2223
2224                         label1 = new qLabel(win1) 
2225                         {
2226                                 setText("Welcome")
2227                                 setgeometry(10,10,200,50)
2228                                 setstylesheet("color: purple ; font-size: 30pt;")
2229                         }
2230
2231                         new qTimer(win1)
2232                         {
2233                                 setInterVal(10)
2234                                 setTimeOutEvent("pMove()")
2235                                 start()
2236                         }
2237
2238                         setWindowTitle("Movable Label")
2239                         setgeometry(100,100,600,80)
2240                         setStyleSheet("background-color: white;")
2241                         show()
2242
2243                 }
2244
2245                 exec()
2246         }
2247
2248         Func pMove
2249                 label1 
2250                 {
2251                         move(x()+1,y())
2252                         if x() > 600
2253                                 move(10,y())
2254                         ok
2255                 }
2256         
2257         
2258 実行中のアプリケーション
2259                         
2260 .. image:: ringqt_shot39.jpg
2261         :alt: 移動可能ラベル
2262         
2263 .. index:: 
2264         pair: RingQt によるデスクトップとモバイル開発; QMessagebox の用例
2265
2266 QMessagebox の用例
2267 ===================
2268
2269 メッセージ・ボックスの出力を確認する方法を学びます。
2270
2271 .. code-block:: ring
2272
2273         Load "guilib.ring"
2274
2275         new qApp {
2276                 win1 = new qWidget() 
2277                 {
2278                         label1 = new qpushbutton(win1) 
2279                         {
2280                                 setText("Test")
2281                                 setgeometry(10,10,200,50)
2282                                 setstylesheet("color: purple ; font-size: 30pt;")
2283                                 setclickevent("pWork()")
2284                         }
2285                         setWindowTitle("Messagebox")
2286                         setgeometry(100,100,600,80)
2287                         setStyleSheet("background-color: white;")
2288                         show()
2289                 }
2290                 exec()
2291         }
2292          
2293         func pWork
2294                 new qmessagebox(win1)
2295                 {
2296                         setwindowtitle("messagebox title")
2297                         settext("messagebox text")
2298                         setInformativeText("Do you want to save your changes?")
2299                         setstandardbuttons(QMessageBox_Yes | QMessageBox_No | QMessageBox_Close)
2300                         result = exec()
2301                         win1 {
2302                                 if result = QMessageBox_Yes
2303                                         setwindowtitle("Yes")
2304                                 but result = QMessageBox_No
2305                                         setwindowtitle("No")
2306                                 but result = QMessageBox_Close
2307                                         setwindowtitle("Close")
2308                                 ok
2309                         }
2310                 }
2311
2312 実行中のアプリケーション
2313                         
2314 .. image:: ringqt_shot40.jpg
2315         :alt: QMessageBox の実行結果
2316
2317 .. index:: 
2318         pair: RingQt によるデスクトップとモバイル開発; QInputDialog クラスの用法
2319
2320 QInputDialog クラスの用法
2321 =============================
2322
2323 この用例では、 QInputDialog クラスの用法を学びます。
2324
2325 .. code-block:: ring
2326
2327         Load "guilib.ring"
2328
2329         New QApp {
2330
2331                 Win1 = New QWidget () {
2332
2333                         SetGeometry(100,100,400,400)
2334                         SetWindowTitle("Input Dialog")
2335
2336                         New QPushButton(win1) 
2337                         {
2338
2339                                 SetText ("Input Dialog")
2340                                 SetGeometry(100,100,100,30)
2341                                 SetClickEvent("pWork()")
2342                         }
2343
2344                         Show()
2345                 }
2346
2347                 exec()
2348         }
2349
2350         Func pWork
2351                 oInput = New QInputDialog(win1)
2352                 {
2353                         setwindowtitle("What is your name?")
2354                         setgeometry(100,100,400,50)
2355                         setlabeltext("User Name")
2356                         settextvalue("Mahmoud")
2357                         lcheck = exec()
2358                         if lCheck win1.setwindowtitle(oInput.textvalue()) ok
2359                 }
2360                 
2361
2362 実行中のアプリケーション
2363                         
2364 .. image:: ringqt_shot41.jpg
2365         :alt: QInputDialog
2366
2367 .. index:: 
2368         pair: RingQt によるデスクトップとモバイル開発; ダイアログ関数
2369
2370 ダイアログ関数
2371 ==============
2372
2373 この関数があります。
2374
2375 .. code-block:: none
2376
2377         SetDialogIcon(cIconFile)
2378         MsgInfo(cTitle,cMessage)
2379         ConfirmMsg(cTitle,cMessage) --> lResult
2380         InputBox(cTitle,cMessage) --> cValue
2381         InputBoxInt(cTitle,cMessage) --> nValue
2382         InputBoxNum(cTitle,cMessage) --> nValue
2383         InputBoxPass(cTitle,cMessage) --> cValue
2384
2385 用例
2386
2387 .. code-block:: ring
2388
2389         load "guilib.ring"
2390
2391         new qApp 
2392         {
2393                 SetDialogIcon("notepad.png")
2394                 msginfo(:Ring,:Welcome)
2395                 see confirmMsg(:Ring,"Are you sure?") + nl
2396                 see InputBoxNum(:Ring,"Enter Number(double) :") + nl
2397                 see InputBox(:Ring,"Enter Value :") + nl
2398                 see InputBoxInt(:Ring,"Enter Number(int)") + nl
2399                 see InputBoxPass(:Ring,"Enter Password") +nl
2400         }
2401
2402
2403 .. index:: 
2404         pair: RingQt によるデスクトップとモバイル開発; キー入力とマウス移動イベント
2405
2406 キー入力とマウス移動イベント
2407 ==============================
2408
2409 この用例では、イベントフィルタによりキー入力と
2410 マウスの移動イベントを検知するための方法を学びます。
2411
2412 .. code-block:: ring
2413
2414         Load "guilib.ring"
2415
2416         new qApp {
2417
2418                 win1 = new qWidget()
2419                 {
2420                         setWindowTitle("Test using Event Filter!")
2421                         setGeometry(100,100,400,400)
2422                         setmousetracking(true)
2423                         myfilter = new qallevents(win1)
2424                         myfilter.setKeyPressEvent("pWork()")
2425                         myfilter.setMouseButtonPressevent("pClick()")
2426                         myfilter.setmousemoveevent("pMove()")
2427
2428                         installeventfilter(myfilter)
2429
2430                         show()
2431                 }
2432
2433                 exec()
2434         }
2435
2436         func pWork
2437                 win1.setwindowtitle('KeyPress! : ' + myfilter.getkeycode())
2438
2439         func pClick
2440                 new qmessagebox(win1) {
2441                         setgeometry(100,100,400,100)
2442                         setwindowtitle("click event!")
2443                         settext("x : " + myfilter.getx() + 
2444                                 " y : " + myfilter.gety() + " button : " +
2445                                  myfilter.getbutton() )
2446                         show()
2447                 }
2448
2449         func pMove
2450                 win1.setwindowtitle("Mouse Move , X : " + myfilter.getx() +
2451                                     " Y : " + myfilter.gety() )
2452
2453 実行中のアプリケーション
2454                         
2455 .. image:: ringqt_shot42.jpg
2456         :alt: キー入力とマウス移動イベント
2457
2458 .. index:: 
2459         pair: RingQt によるデスクトップとモバイル開発; マウスによるオブジェクトの移動方法
2460
2461 マウスによるオブジェクトの移動方法
2462 ======================================
2463
2464 ユーザがラベルを移動できる移動可能なオブジェクトをプログラムする方法を学びます。
2465
2466 .. code-block:: ring
2467
2468         Load "guilib.ring"
2469
2470         lPress = false
2471         nX = 0
2472         nY = 0
2473
2474         new qApp {
2475
2476                 win1 = new qWidget()
2477                 {
2478
2479                         setWindowTitle("Move this label!")
2480                         setGeometry(100,100,400,400)
2481                         setstylesheet("background-color:white;")
2482
2483                         Label1 = new qLabel(Win1){
2484                                 setGeometry(100,100,200,50)
2485                                 setText("Welcome")
2486                                 setstylesheet("font-size: 30pt")
2487                                 myfilter = new qallevents(label1)
2488                                 myfilter.setEnterevent("pEnter()")
2489                                 myfilter.setLeaveevent("pLeave()")
2490                                 myfilter.setMouseButtonPressEvent("pPress()")
2491                                 myfilter.setMouseButtonReleaseEvent("pRelease()")
2492                                 myfilter.setMouseMoveEvent("pMove()")
2493                                 installeventfilter(myfilter)
2494                         }
2495
2496                         show()
2497                 }
2498
2499                 exec()
2500         }
2501
2502         Func pEnter
2503                 Label1.setStyleSheet("background-color: purple; color:white;font-size: 30pt;")
2504
2505         Func pLeave
2506                 Label1.setStyleSheet("background-color: white; color:black;font-size: 30pt;")
2507
2508         Func pPress
2509                 lPress = True   
2510                 nX = myfilter.getglobalx()
2511                 ny = myfilter.getglobaly()
2512
2513         Func pRelease
2514                 lPress = False
2515                 pEnter()
2516
2517         Func pMove
2518                 nX2 = myfilter.getglobalx()
2519                 ny2 = myfilter.getglobaly()
2520                 ndiffx = nX2 - nX
2521                 ndiffy = nY2 - nY
2522                 if lPress
2523                         Label1 {
2524                                 move(x()+ndiffx,y()+ndiffy)
2525                                 setStyleSheet("background-color: Green;
2526                                          color:white;font-size: 30pt;")
2527                                 nX = nX2
2528                                 ny = nY2
2529                         }
2530
2531                 ok
2532
2533
2534 実行中のアプリケーション
2535                         
2536 .. image:: ringqt_shot43.jpg
2537         :alt: マウスで移動できるオブジェクト
2538         
2539 .. image:: ringqt_shot44.jpg
2540         :alt: マウスで移動できるオブジェクト
2541         
2542 .. image:: ringqt_shot45.jpg
2543         :alt: マウスをで移動できるオブジェクト
2544         
2545 .. index:: 
2546         pair: RingQt によるデスクトップとモバイル開発; GUI クラスからの継承
2547
2548 GUI クラスからの継承
2549 ============================
2550
2551 用例:
2552
2553 .. code-block:: ring
2554
2555         Load "guilib.ring"
2556
2557         New MyWindow()
2558
2559         new qApp { exec() }
2560
2561         class mywindow from qwidget
2562                 Func init
2563                         super.init()
2564                         setwindowtitle("First Window")
2565                         setgeometry(100,100,400,400)
2566                         setstylesheet("background-color: purple;")
2567                         settooltip("my first window!")
2568                         show()
2569
2570 実行中のアプリケーション
2571                         
2572 .. image:: ringqt_shot46.jpg
2573         :alt: GUI クラスからの継承
2574         
2575 .. index:: 
2576         pair: RingQt によるデスクトップとモバイル開発; QDesktopWidget クラスの用法
2577
2578 QDesktopWidget クラスの用法
2579 ===============================
2580
2581 この用例では、 QDesktopWidget の用法を学びます。
2582
2583 .. code-block:: ring
2584
2585         Load "guilib.ring"
2586
2587         New qApp {
2588                 win1 = New qWidget()
2589                 {
2590                         resize(400,400)
2591                         btn1 = new qPushbutton(win1)
2592                         {
2593                                 setText("Center")
2594                                 move(100,100)
2595                                 resize(100,30)
2596                                 setClickEvent("pCenter()")
2597                         }
2598
2599                         Show()
2600                 }
2601
2602                 exec()
2603         }
2604
2605         Func pCenter
2606                 oDesktop  = new qDesktopWidget()
2607                 oRect = oDesktop.screenGeometry( oDesktop.primaryScreen()  ) 
2608                 win1.move((oRect.width()-win1.width()) /2 , (oRect.Height()-win1.Height())/2 )
2609                 win1.show()
2610
2611 実行中のアプリケーション
2612                         
2613 .. image:: ringqt_shot47.jpg
2614         :alt: Using QDesktopWidget クラス
2615
2616 .. index:: 
2617         pair: RingQt によるデスクトップとモバイル開発; テキストの回転
2618
2619 テキストの回転
2620 ==============
2621
2622 この用例では、タイマーでテキストを回転しています。
2623
2624 .. code-block:: ring
2625
2626         Load "guilib.ring"
2627
2628         nAngle  = 0
2629
2630         New qapp {
2631                 win1 = new qwidget() {
2632                         setwindowtitle("Rotate Text")
2633                         resize(800,600)
2634                         label1 = new qlabel(win1) {
2635                                 settext("")
2636                                 myfilter = new qallevents(win1)
2637                                 myfilter.setMouseButtonPressevent("pClick()")
2638                                 installeventfilter(myfilter)
2639                         }
2640                         new qtimer(win1) {
2641                                 setinterval(50)
2642                                 settimeoutevent("pTime()")
2643                                 start()
2644                         }
2645                         pDraw()
2646                         L1 = new qVBoxLayout() { AddWidget(Label1) } SetLayout(L1)
2647                         showMaximized()
2648                 }
2649                 exec()
2650         }
2651
2652         Func pDraw
2653                 p1 = new qpicture()
2654                 color = new qcolor() {
2655                         setrgb(0,0,255,255)
2656                 }
2657                 pen = new qpen() {
2658                         setcolor(color)
2659                         setwidth(50)
2660                 }
2661                 painter = new qpainter() {
2662                         begin(p1)               
2663                                 setpen(pen)
2664                                 myfont = font()
2665                                 myfont.setpointsize(50)
2666                                 setfont(myfont)
2667                                 rotate(nAngle)
2668                                 drawtext(350,0*nAngle,"welcome")                 
2669                                 drawtext(0,0*nAngle,"welcome")           
2670                         endpaint()
2671                           }
2672                 label1 {
2673                         setpicture(p1)  
2674                         show() 
2675                 }
2676
2677         Func pClick
2678                 win1 { setwindowtitle("Click Event") } 
2679
2680         Func pTime
2681                 nAngle++
2682                 if nAngle = 90
2683                         nAngle = 10
2684                 ok
2685                 pDraw()
2686
2687 実行中のアプリケーション
2688
2689 .. image:: shotrotatetext.png
2690         :alt: テキスト回転の用例
2691
2692
2693 .. index:: 
2694         pair: RingQt によるデスクトップとモバイル開発; フォーカスの変更
2695
2696 フォーカスの変更
2697 ================
2698
2699 この用例は、 ENTER キーでフォーカスを変更します。
2700
2701 .. code-block:: ring
2702
2703         load "guilib.ring"
2704
2705         new qApp {
2706                 win = new qWidget() {
2707                         resize(600,600)
2708                         SetWindowTitle("Change Focus")
2709                         text1 = new qLineEdit(win)
2710                         text2 = new qLineEdit(win)
2711                         text3 = new qLineEdit(win)
2712                         text4 = new qLineEdit(win)
2713                         layout1 = new qVBoxLayout() {
2714                                 AddWidget(text1)
2715                                 AddWidget(text2)
2716                                 AddWidget(text3)
2717                                 AddWidget(text4)
2718
2719                         }
2720                         setLayout(Layout1)
2721                         aList = [text1,text2,text3,text4]
2722                         oFilter = new qallevents(win)
2723                         oFilter.setKeyPressEvent("pWork()")
2724                         installeventfilter(oFilter)
2725                         show()
2726                 }
2727                 exec()
2728         }
2729
2730         func pWork
2731                 nCode =  oFilter.getkeycode()
2732                 if nCode = 16777220     # ENTER キー
2733                         for x=1 to len(aList) 
2734                                 if aList[x].HasFocus() 
2735                                         t = x+1
2736                                         if t > len(aList) t=1 ok
2737                                         aList[t].SetFocus(0)
2738                                         exit
2739                                 ok
2740                         next
2741                 ok
2742
2743
2744 .. index:: 
2745         pair: RingQt によるデスクトップとモバイル開発; 正規表現
2746
2747 正規表現
2748 ========
2749
2750 この用例では、正規表現のクラスを使用しています。
2751
2752 .. code-block:: ring
2753
2754         load "guilib.ring"
2755
2756         new qApp
2757         {
2758                 see "Using Regular Expressions" + nl
2759
2760                 exp = new qregularexpression() {
2761                         setPattern("\d\d \w+")
2762                         see pattern() + nl
2763                         match = match("33 one",0,0,0)
2764                         see match.hasmatch() + nl
2765                         match = match("3 one",0,0,0)
2766                         see match.hasmatch() + nl
2767                         match = match("welcome 11 one",0,0,0)
2768                         see match.hasmatch() + nl
2769                         matched = match.captured(0)
2770                         see matched + nl
2771                 }
2772                 exp = new qregularexpression() {
2773                         setPattern("^(\d\d)/(\d\d)/(\d\d\d\d)$")
2774                         see pattern() + nl
2775                         match = match("08/12/1985",0,0,0)
2776                         see match.hasmatch() + nl
2777                         day = match.captured(1)
2778                         month = match.captured(2)
2779                         year = match.captured(3)
2780                         see day + nl + month + nl + year + nl
2781                         see  "(" + match.capturedStart(1) + "," + match.capturedEnd(1)+ ")" + nl
2782                         see  "(" + match.capturedStart(2) + "," + match.capturedEnd(2)+ ")" + nl
2783                         see  "(" + match.capturedStart(3) + "," + match.capturedEnd(3)+ ")" + nl
2784                 }
2785
2786         }
2787
2788 実行結果:
2789
2790 .. code-block:: ring
2791
2792         Using Regular Expressions
2793         \d\d \w+
2794         1
2795         0
2796         1
2797         11 one
2798         ^(\d\d)/(\d\d)/(\d\d\d\d)$
2799         1
2800         08
2801         12
2802         1985
2803         (0,2)
2804         (3,5)
2805         (6,10)
2806
2807
2808
2809 .. index:: 
2810         pair: RingQt によるデスクトップとモバイル開発; シンプルなクライアントとサーバーの用例
2811
2812 シンプルなクライアントとサーバーの用例
2813 ======================================
2814
2815 この用例では、シンプルなクライアントとサーバーアプリケーションの作成方法を学びます。
2816
2817 .. code-block:: ring
2818
2819         Load "guilib.ring"
2820
2821         new qApp {
2822                 oClient = new Client { client() }
2823                 oServer = new Server { server() }
2824                 exec()
2825         }
2826
2827         Class Client
2828
2829                 win1 lineedit1  cOutput=""
2830                 oTcpSocket
2831
2832                 func client
2833
2834                         win1 = new qwidget() 
2835
2836                         new qpushbutton(win1) {
2837                                 setgeometry(50,50,100,30)
2838                                 settext("connect")
2839                                 setclickevent("oClient.Connect()")
2840                         }
2841
2842                         lineedit1 = new qtextedit(win1) {
2843                                 setGeometry(150,50,200,300)
2844                         }
2845
2846                         win1 {
2847                                 setwindowtitle("client")
2848                                 setgeometry(10,100,400,400)
2849                                 show()
2850                         }
2851
2852                 func connect
2853                         cOutput = "Connect to host 127.0.0.1 port 9999" + nl
2854                         lineedit1.settext(cOutput)
2855                         oTcpSocket = new qTcpSocket(win1) {
2856                                 setconnectedevent("oClient.pConnected()")
2857                                 setreadyreadevent("oClient.pRead()")
2858                                 connecttohost("127.0.0.1",9999,3,0)
2859                                 waitforconnected(5000)
2860                         }                       
2861                         
2862                 func pConnected         
2863
2864                         cOutput += "Connected!" + nl
2865                         lineedit1.settext(cOutput)
2866
2867                 func pRead
2868
2869                         cOutput += "Ready Read!" + nl
2870                         lineedit1.settext(cOutput)
2871                         cOutput += oTcpSocket.readall().data() + nl
2872                         lineedit1.settext(cOutput)
2873
2874         Class Server
2875
2876                 win1 lineedit1 
2877                 oTcpServer oTcpClient
2878                 cOutput = ""
2879
2880                 func server
2881
2882                         win1 = new qwidget()
2883                         
2884                         lineedit1 = new qtextedit(win1) {
2885                                 setGeometry(150,50,200,300)
2886                         }
2887
2888                         win1 {
2889                                 setwindowtitle("Server")
2890                                 setgeometry(450,100,400,400)
2891                                 show()
2892                         }
2893
2894                         oTcpServer = new qTcpServer(win1) {
2895                                 setNewConnectionEvent("oServer.pNewConnection()")
2896                                 oHostAddress = new qHostAddress()
2897                                 oHostAddress.SetAddress("127.0.0.1")
2898                                 listen(oHostAddress,9999)
2899                         }
2900                         cOutput = "Server Started" + nl +
2901                                    "listen to port 9999" + nl
2902
2903                         lineedit1.settext(cOutput)
2904
2905                 Func pNewConnection
2906                 
2907                         oTcpClient = oTcpServer.nextPendingConnection()
2908                         cOutput += "Accept Connection" + nl
2909                         lineedit1.settext(cOutput)
2910                         oTcpClient {
2911                                 cStr ="Hello from server to client!"+char(13)+char(10)
2912                                 write(cStr,len(cStr))
2913                                 flush()
2914                                 waitforbyteswritten(300000)
2915                                 close()
2916                         }
2917
2918 実行中のアプリケーション
2919
2920 .. image:: ringqt_shot36.jpg
2921         :alt: クライアントとサーバーの用例
2922
2923 .. index:: 
2924         pair: RingQt によるデスクトップとモバイル開発; 動的オブジェクト
2925
2926 動的オブジェクト
2927 ================
2928
2929 実行時にオブジェクトの作成、およびウィンドウへオブジェクトを追加します。
2930
2931 用例:
2932
2933 .. code-block:: ring
2934
2935         load "guilib.ring"
2936
2937         oFormDesigner = new FormDesigner { start("oFormDesigner") }
2938
2939         Class FormDesigner
2940
2941                 winToolBox  winForm
2942
2943                 aObjects = []
2944
2945                 func start cObjectName
2946
2947                         oApp = new qApp
2948
2949                         winToolBox = new qWidget() 
2950                         winToolBox.setWindowTitle("ToolBox")
2951                         winToolBox.move(10,10)
2952                         winToolBox.resize(300,600)
2953                         
2954                         btn = new qPushButton(winToolBox) 
2955                         btn.resize(300,30)
2956                         btn.setText("Create Button")
2957                         btn.setClickEvent(cObjectName+".pCreateButton()")
2958                         btn.show()              
2959
2960                         winToolBox.show()
2961
2962                         winForm = new qWidget() {
2963                                 move(400,50)
2964                                 setWindowTitle("Form Designer")
2965                                 resize(600,600)
2966                                 show()  
2967                         }
2968
2969                         oApp.exec()
2970
2971
2972                 func pCreateButton              
2973
2974                         nCount = len(aObjects)
2975
2976                         aObjects + new MyButton(winForm) 
2977                         {
2978                                 nIndex = nCount + 1
2979                                 setText("Button"+ nIndex) 
2980                                 Move(30*nIndex,30*nIndex)
2981                                 resize(100,30)
2982                                 show()
2983                         }
2984
2985
2986         Class MyButton from qPushButton
2987                 nIndex = 0
2988
2989
2990 .. index:: 
2991         pair: RingQt によるデスクトップとモバイル開発; Weight History アプリケーション
2992
2993 Weight History アプリケーション
2994 ===============================
2995
2996 このサンプルは体重の記録で役に立ちます (日付、時刻と体重)。
2997
2998 .. code-block:: ring
2999
3000         Load "guilib.ring"
3001
3002         MyApp = new qApp
3003         {  
3004           $ApplicationObject = "oApp"   # イベントを呼び出すときに使用します。
3005           oApp = new App     
3006           exec()
3007           oApp.CloseDatabase()
3008         }
3009
3010         class App
3011
3012           cDir = currentdir() + "/"
3013           oCon 
3014           aIDs = []
3015
3016           win1 = new qWidget()
3017           {
3018                 setWindowTitle("Weight History")
3019                 resize(600,600)
3020                 layoutButtons = new qhboxlayout()
3021                 {
3022                   label1 = new qLabel(win1) { setText("Weight") }
3023                   text1 = new qlineedit(win1)
3024                   btnAdd = new qpushbutton(win1) { 
3025                           setText("Add") 
3026                           setClickEvent($ApplicationObject+".AddWeight()") 
3027                   }
3028                   btnDelete = new qpushbutton(win1) { 
3029                           setText("Delete") 
3030                           setClickEvent($ApplicationObject+".Deleteweight()") 
3031                   }
3032                   addwidget(label1)
3033                   addwidget(text1)
3034                   addwidget(btnAdd)
3035                   addwidget(btnDelete)
3036                 }
3037                 layoutData  = new qhboxlayout()
3038                 {
3039                   Table1 = new qTableWidget(win1) {
3040                         setrowcount(0)
3041                         setcolumncount(3)
3042                         setselectionbehavior(QAbstractItemView_SelectRows)
3043                         setHorizontalHeaderItem(0, new QTableWidgetItem("Date"))
3044                         setHorizontalHeaderItem(1, new QTableWidgetItem("Time"))
3045                         setHorizontalHeaderItem(2, new QTableWidgetItem("Weight"))
3046                         setitemChangedEvent($ApplicationObject+".ItemChanged()")
3047                                            setAlternatingRowColors(true)    
3048                                            horizontalHeader().setStyleSheet("color: blue")
3049                                            verticalHeader().setStyleSheet("color: red") 
3050                   }
3051                   addWidget(Table1)
3052                 }
3053                 layoutClose = new qhboxlayout()
3054                 {
3055                   btnclose = new qpushbutton(win1) { 
3056                     setText("Close") 
3057                     setClickEvent("MyApp.Quit()") 
3058                   }
3059                   addwidget(btnClose)
3060                 }
3061                 layoutMain = new qvboxlayout()
3062                 {
3063                   addlayout(layoutButtons)
3064                   addLayout(LayoutData)
3065                   addLayout(layoutClose)
3066                 }
3067                 setlayout(layoutMain)
3068                 self.OpenDatabase()
3069                 self.ShowRecords()        
3070                 show()  
3071           }
3072                 
3073           Func OpenDatabase
3074                 lCreate = False
3075                 if not fexists(cDir + "weighthistory.db")
3076                   lCreate = True
3077                 ok
3078                 new QSqlDatabase() {
3079                   this.oCon = addDatabase("QSQLITE") {
3080                         setDatabaseName("weighthistory.db")
3081                         Open()      
3082                   }
3083                 }  
3084                 if lCreate
3085                   new QSqlQuery( ) {
3086                         exec("create table weighthistory (id integer primary key,"+
3087                              " f_date varchar(10),"+
3088                              " f_time varchar(8), f_weight varchar(8) );")
3089                         delete()
3090                   }
3091                 ok
3092
3093
3094           Func CloseDatabase
3095                 oCon.Close()
3096
3097           Func AddWeight
3098                 cWeight = text1.text()
3099                 AddRecord(cWeight)
3100
3101           Func DeleteWeight
3102                 Table1 {
3103                    nRow = CurrentRow() 
3104                   if nRow >= 0
3105                         nID = this.aIDs[nROW+1] 
3106                         new QSqlQuery( ) {
3107                           exec("delete from weighthistory where id = " + nID )
3108                         }
3109                         Del(this.aIDs,nRow+1)
3110                         removerow(nRow)  
3111                         selectrow(nRow)
3112                   ok
3113                 }
3114                 
3115
3116           Func AddRecord cWeight
3117                 new QSqlQuery( ) {
3118                   cStr = "insert into weighthistory (f_date,f_time,f_weight) values"+
3119                   " ('%f1','%f2','%f3')"
3120                   cDate = Date()
3121                   cTime = Time()
3122                   cStr = substr(cStr,"%f1",cDate)
3123                   cStr = substr(cStr,"%f2",cTime)
3124                   cStr = substr(cStr,"%f3",cWeight)
3125                   exec(cStr)
3126                   delete()
3127                 }
3128                 ShowRecords()
3129                 Table1.selectrow(table1.rowcount()-1)
3130
3131
3132           Func ShowRecords
3133                 table1.setitemChangedEvent("")
3134                 aIDs = []
3135                 query = new QSqlQuery() {
3136                   exec("select * from weighthistory")
3137                   nRows = 0
3138                   this.Table1.setrowcount(0)
3139                   while movenext() 
3140                         this.table1 {
3141                           insertRow(nRows)
3142                           this.aIDs + query.value(0).tostring()
3143                           for x = 1 to 3 
3144                                 cStr = query.value(x).tostring()
3145                                 item = new qTableWidgetItem(cStr)
3146                                 setItem(nRows,x-1,item)
3147                           next
3148                         }
3149                         nRows++
3150                   end
3151                   delete()
3152                 }
3153                 table1.setitemChangedEvent($ApplicationObject+".ItemChanged()")
3154            
3155           Func ItemChanged
3156                 nRow =  table1.currentrow()
3157                 if nRow >= 0 
3158                   myitem = Table1.item(table1.currentrow(),0)
3159                   cDate = myitem.text()
3160                   myitem = Table1.item(table1.currentrow(),1)
3161                   cTime = myitem.text()
3162                   myitem = Table1.item(table1.currentrow(),2)
3163                   cWeight = myitem.text()
3164                   new QSqlQuery( ) {
3165                         cStr = "update weighthistory set f_date ='%f1' , f_time = '%f2' , "+
3166                         "f_weight ='%f3' where id = " +  this.aIDs[nROW+1] 
3167                         cStr = substr(cStr,"%f1",cDate)
3168                         cStr = substr(cStr,"%f2",cTime)
3169                         cStr = substr(cStr,"%f3",cWeight)  
3170                         exec(cStr)
3171                         delete()
3172                   }
3173                 ok
3174
3175
3176 このスクリーンショットはアプリケーション実行中のものです。
3177
3178 .. image:: weighthistory_app.png
3179         :alt: Weight History アプリケーション
3180
3181 .. index:: 
3182         pair: RingQt によるデスクトップとモバイル開発; Notepad アプリケーション
3183
3184
3185 Notepad アプリケーション
3186 ========================
3187
3188 この用例では、 RingQt を使用してシンプルな Notepad を開発したものです。
3189
3190 .. code-block:: ring
3191
3192         Load "guilib.ring"
3193
3194         cActiveFileName = ""
3195         aTextColor = [0,0,0]  
3196         aBackColor = [255,255,255]
3197         cFont = "MS Shell Dlg 2,14,-1,5,50,0,0,0,0,0"
3198         cWebsite = "http://www.google.com"
3199
3200         oSearch = NULL
3201         oSearchValue = NULL 
3202         oSearchCase = NULL
3203         oSearchFilter = NULL
3204         oReplaceValue = NULL
3205
3206         lAskToSave = false
3207
3208         MyApp = New qApp {
3209                 win1 = new qMainWindow() {
3210
3211                         setwindowtitle("Ring Notepad")
3212                         setGeometry(100,100,400,400)
3213                         aBtns = [
3214                                         new qpushbutton(win1) { 
3215                                                 setbtnimage(self,"image/new.png") 
3216                                                 setclickevent("pNew()")
3217                                                 settooltip("New File")
3218                                         } ,
3219                                         new qpushbutton(win1) { 
3220                                                 setbtnimage(self,"image/open.png") 
3221                                                 setclickevent("pOpen()")
3222                                                 settooltip("Open File")
3223                                         } ,
3224                                         new qpushbutton(win1) { 
3225                                                 setbtnimage(self,"image/save.png")
3226                                                 setclickevent("pSave()")
3227                                                 settooltip("Save")
3228                                          } ,
3229                                         new qpushbutton(win1) { 
3230                                                 setbtnimage(self,"image/saveas.png")
3231                                                 setclickevent("pSaveAs()")
3232                                                 settooltip("Save As")
3233                                          } ,
3234                                         new qpushbutton(win1) { 
3235                                                 setbtnimage(self,"image/cut.png")
3236                                                 setclickevent("pCut()")
3237                                                 settooltip("Cut")
3238                                          } ,
3239                                         new qpushbutton(win1) { 
3240                                                 setbtnimage(self,"image/copy.png") 
3241                                                 setclickevent("pCopy()")
3242                                                 settooltip("Copy")
3243                                         } ,
3244                                         new qpushbutton(win1) { 
3245                                                 setbtnimage(self,"image/paste.png") 
3246                                                 setclickevent("pPaste()")
3247                                                 settooltip("Paste")
3248                                         } ,
3249                                         new qpushbutton(win1) { 
3250                                                 setbtnimage(self,"image/font.png") 
3251                                                 setclickevent("pFont()")
3252                                                 settooltip("Font")
3253                                         } ,
3254                                         new qpushbutton(win1) { 
3255                                                 setbtnimage(self,"image/colors.jpg") 
3256                                                 setclickevent("pColor()")
3257                                                 settooltip("Text Color")
3258                                         } ,
3259                                         new qpushbutton(win1) { 
3260                                                 setbtnimage(self,"image/search.png") 
3261                                                 setclickevent("pFind()")
3262                                                 settooltip("Find and Replace")
3263                                         } ,
3264                                         new qpushbutton(win1) { 
3265                                                 setbtnimage(self,"image/print.png") 
3266                                                 setclickevent("pPrint()")
3267                                                 settooltip("Print")
3268                                         } ,
3269                                         new qpushbutton(win1) { 
3270                                                 setbtnimage(self,"image/debug.png") 
3271                                                 setclickevent("pDebug()")
3272                                                 settooltip("Debug (Run then wait!)")
3273                                         } ,
3274                                         new qpushbutton(win1) { 
3275                                                 setbtnimage(self,"image/run.png") 
3276                                                 setclickevent("pRun()")
3277                                                 settooltip("Run the program")
3278                                         } ,
3279                                         new qpushbutton(win1) { 
3280                                                 setbtnimage(self,"image/close.png") 
3281                                                 setclickevent("pQuit()")
3282                                                 settooltip("Quit")
3283                                         } 
3284                                 ]
3285
3286                         tool1 = addtoolbar("files")  {
3287                                 for x in aBtns addwidget(x) addseparator() next
3288                         }
3289
3290                         menu1 = new qmenubar(win1) {            
3291                                 sub1 = addmenu("File")
3292                                 sub2 = addmenu("Edit")
3293                                 sub3 = addmenu("View")
3294                                 sub4 = addmenu("Help")
3295                                 sub1 { 
3296                                         oAction = new qAction(win1) {
3297                                                 setShortcut(new QKeySequence("Ctrl+n"))
3298                                                 setbtnimage(self,"image/new.png")
3299                                                 settext("New")
3300                                                 setclickevent("pNew()")
3301                                         }
3302                                         addaction(oAction)
3303                                         oAction = new qAction(win1) {
3304                                                 setShortcut(new QKeySequence("Ctrl+o"))
3305                                                 setbtnimage(self,"image/open.png") 
3306                                                 settext("Open")
3307                                                 setclickevent("pOpen()")
3308                                         }
3309                                         addaction(oAction)
3310                                         addseparator()
3311                                         oAction = new qAction(win1) {
3312                                                 setShortcut(new QKeySequence("Ctrl+s"))
3313                                                 setbtnimage(self,"image/save.png")
3314                                                 settext("Save")
3315                                                 setclickevent("pSave()")
3316                                         }
3317                                         addaction(oAction)
3318                                         addseparator()
3319                                         oAction = new qAction(win1) {
3320                                                 setShortcut(new QKeySequence("Ctrl+e"))
3321                                                 setbtnimage(self,"image/saveas.png")
3322                                                 settext("Save As")
3323                                                 setclickevent("pSaveAs()")
3324                                         }
3325                                         addaction(oAction)
3326                                         addseparator()
3327                                         oAction = new qAction(win1) {
3328                                                 setShortcut(new QKeySequence("Ctrl+p"))
3329                                                 setbtnimage(self,"image/print.png")
3330                                                 settext("Print to PDF")
3331                                                 setclickevent("pPrint()")
3332                                         }
3333                                         addaction(oAction)
3334                                         addseparator()
3335                                         oAction = new qAction(win1) {
3336                                                 setShortcut(new QKeySequence("Ctrl+d"))
3337                                                 setbtnimage(self,"image/debug.png")
3338                                                 settext("Debug (Run then wait!)")
3339                                                 setclickevent("pDebug()")
3340                                         }
3341                                         addaction(oAction)
3342                                         addseparator()
3343                                         oAction = new qAction(win1) {
3344                                                 setShortcut(new QKeySequence("Ctrl+r"))
3345                                                 setbtnimage(self,"image/run.png")
3346                                                 settext("Run")
3347                                                 setclickevent("pRun()")
3348                                         }
3349                                         addaction(oAction)
3350                                         addseparator()
3351                                         oAction = new qAction(win1) {
3352                                                 setShortcut(new QKeySequence("Ctrl+F5"))
3353                                                 setbtnimage(self,"image/run.png")
3354                                                 settext("Run GUI Application (No Console)")
3355                                                 setclickevent("pRunNoConsole()")
3356                                         }
3357                                         addaction(oAction)      
3358                                         addseparator()
3359                                         oAction = new qaction(win1) {
3360                                                 setShortcut(new QKeySequence("Ctrl+q"))
3361                                                 setbtnimage(self,"image/close.png") 
3362                                                 settext("Exit")
3363                                                 setstatustip("Exit")
3364                                                 setclickevent("pQuit()")
3365                                         }
3366                                         addaction(oAction)
3367                                 }
3368                                 sub2 { 
3369                                         oAction = new qAction(win1) {
3370                                                 setShortcut(new QKeySequence("Ctrl+x"))
3371                                                 setbtnimage(self,"image/cut.png")
3372                                                 settext("Cut")
3373                                                 setclickevent("pCut()")
3374                                         }
3375                                         addaction(oAction)
3376                                         oAction = new qAction(win1) {
3377                                                 setShortcut(new QKeySequence("Ctrl+c"))
3378                                                 setbtnimage(self,"image/copy.png")
3379                                                 settext("Copy")
3380                                                 setclickevent("pCopy()")
3381                                         }
3382                                         addaction(oAction)
3383                                         oAction = new qAction(win1) {
3384                                                 setShortcut(new QKeySequence("Ctrl+v"))
3385                                                 setbtnimage(self,"image/paste.png")
3386                                                 settext("Paste")
3387                                                 setclickevent("pPaste()")
3388                                         }
3389                                         addaction(oAction)
3390                                         addseparator()
3391                                         oAction = new qAction(win1) {
3392                                                 setShortcut(new QKeySequence("Ctrl+i"))
3393                                                 setbtnimage(self,"image/font.png")
3394                                                 settext("Font")
3395                                                 setclickevent("pFont()")
3396                                         }
3397                                         addseparator()
3398                                         addaction(oAction)
3399                                         oAction = new qAction(win1) {
3400                                                 setShortcut(new QKeySequence("Ctrl+t"))
3401                                                 setbtnimage(self,"image/colors.jpg")
3402                                                 settext("Text Color")
3403                                                 setclickevent("pColor()")
3404                                         }
3405                                         addaction(oAction)
3406                                         oAction = new qAction(win1) {
3407                                                 setShortcut(new QKeySequence("Ctrl+b"))
3408                                                 setbtnimage(self,"image/colors.jpg")
3409                                                 settext("Back Color")
3410                                                 setclickevent("pColor2()")
3411                                         }
3412                                         addaction(oAction)
3413                                         addseparator()
3414                                         oAction = new qAction(win1) {
3415                                                 setShortcut(new QKeySequence("Ctrl+g"))
3416                                                 settext("Go to line")
3417                                                 setclickevent("pGoto()")
3418                                         }
3419                                         addaction(oAction)
3420                                         oAction = new qAction(win1) {
3421                                                 setShortcut(new QKeySequence("Ctrl+f"))
3422                                                 setbtnimage(self,"image/search.png")
3423                                                 settext("Find and Replace")
3424                                                 setclickevent("pFind()")
3425                                         }
3426                                         addaction(oAction)
3427                                 }                               
3428                                 sub3 {
3429                                         oAction = new qAction(win1) {
3430                                                 setShortcut(new QKeySequence("Ctrl+p"))
3431                                                 setbtnimage(self,"image/project.png")
3432                                                 settext("Project Files")
3433                                                 setclickevent("pProject()")
3434                                         }
3435                                         addaction(oAction)                      
3436                                         oAction = new qAction(win1) {
3437                                                 setShortcut(new QKeySequence("Ctrl+u"))
3438                                                 setbtnimage(self,"image/source.png")
3439                                                 setclickevent("pSourceCode()")
3440                                                 settext("Source Code")
3441                                         }
3442                                         addaction(oAction)      
3443                                         oAction = new qAction(win1) {
3444                                                 setShortcut(new QKeySequence("Ctrl+w"))
3445                                                 setbtnimage(self,"image/richtext.png")
3446                                                 setclickevent("pWebBrowser()")
3447                                                 settext("Web Browser")
3448                                         }
3449                                         addaction(oAction)      
3450                                 }
3451                                 sub4 { 
3452                                         sub5 = addmenu("Development Tools")
3453                                         sub5 { 
3454
3455                                                 oAction = new qAction(win1) {
3456                                                         settext("Programming Language")
3457                                                         setclickevent("pLang()")
3458                                                 }
3459                                                 addaction(oAction)
3460                                                 oAction = new qAction(win1) {
3461                                                         settext("GUI Library")
3462                                                         setclickevent("pGUI()")
3463                                                 }
3464                                                 addaction(oAction)
3465                                         }
3466                                         addseparator()
3467                                                 oAction = new qAction(win1) {
3468                                                         settext("About")
3469                                                         setclickevent("pAbout()")
3470                                                 }
3471                                                 addaction(oAction)                      
3472                                 }
3473                         }
3474
3475                         setmenubar(menu1)
3476
3477                         status1 = new qstatusbar(win1) {
3478                                 showmessage("Ready!",0)
3479                         }
3480
3481                         setstatusbar(status1)
3482
3483                         tree1 = new qtreeview(win1) {
3484                                 setclickedevent("pChangeFile()")
3485                                 setGeometry(00,00,200,400)
3486                                 oDir = new QDir()                                       
3487                                 ofile = new QFileSystemModel() {
3488                                         setrootpath(oDir.currentpath())
3489                                         myfiles = new qstringlist()
3490                                         myfiles.append("*.ring")
3491                                         myfiles.append("*.rh")
3492                                         setnamefilters(myfiles) 
3493                                         setNameFilterDisables(false)
3494                                 }
3495                                 setmodel(ofile)
3496                                 myindex = ofile.index(oDir.currentpath(),0)
3497                                 for x = 1 to ofile.columncount()
3498                                         hidecolumn(x)
3499                                 next
3500                                 setcurrentindex(myindex)
3501                                 setexpanded(myindex,true)
3502                                 header().hide()                 
3503                         }
3504
3505                         oDock1 = new qdockwidget(win1,0) {
3506                                 setGeometry(00,00,200,200)
3507                                 setwindowtitle("Project Files")
3508                                 setwidget(tree1)
3509                         }
3510
3511                         textedit1 = new qtextedit(win1) {
3512                                 setCursorPositionChangedevent("pCursorPositionChanged()")
3513                                 setLineWrapMode(QTextEdit_NoWrap)
3514                                 setAcceptRichText(false)
3515                                 setTextChangedEvent("lAskToSave = true")
3516                         }
3517
3518
3519                         oDock2 = new qdockwidget(win1,0) {
3520                                 setwidget(textedit1)
3521                                 setwindowtitle("Source Code")
3522                         }
3523
3524                         oWebBrowser = new qWidget() {   
3525                                 setWindowFlags(Qt_SubWindow)
3526                                 oWBLabel = new qLabel(win1) {
3527                                         setText("Website: ")
3528                                 }       
3529                                 oWBText = new qLineEdit(win1) {
3530                                         setText(cWebSite)
3531                                         setReturnPressedEvent("pWebGo()")
3532                                 }
3533                                 oWBGo = new qPushButton(win1) {
3534                                         setText("Go")
3535                                         setClickEvent("pWebGo()")
3536                                 }
3537                                 oWBBack = new qPushButton(win1) {
3538                                         setText("Back")
3539                                         setClickEvent("pWebBack()")
3540                                 }
3541                                 oWBLayout1 = new qHBoxLayout() {
3542                                         addWidget(oWBLabel)
3543                                         addWidget(oWBText)
3544                                         addWidget(oWBGo)
3545                                         addWidget(oWBBack)
3546                                 }
3547                                 oWebView = new qWebView(win1) {
3548                                         loadpage(new qurl(cWebSite))
3549                                 }
3550                                 oWBlayout2 = new qVBoxLayout() {
3551                                         addLayout(oWBLayout1)
3552                                         addWidget(oWebView)
3553                                 }
3554                                 setLayout(oWBLayout2)
3555                         }
3556
3557                         oDock3 = new qdockwidget(win1,0) {
3558                                 setwidget(oWebBrowser)          
3559                                 setwindowtitle("Web Browser")
3560                                 setFeatures(QDockWidget_DocWidgetClosable)
3561                         }       
3562
3563                         adddockwidget(1,oDock1,1)
3564                         adddockwidget(2,oDock2,2)
3565                         adddockwidget(2,oDock3,1)
3566                 
3567                         setwinicon(self,"image/notepad.png")
3568
3569                         showmaximized()
3570                 }
3571                 RestoreSettings()
3572                 exec()
3573         }
3574
3575         func pWebGo
3576                 cWebsite = oWBText.text() 
3577                 oWebView.LoadPage( new qurl( cWebSite ) )
3578
3579         func pWebBack
3580                 oWebView.Back()
3581
3582         func pProject
3583                 oDock1.Show()
3584                 
3585         func pSourceCode
3586                 oDock2.Show()
3587
3588         func pWebBrowser
3589                 oDock3.Show()
3590
3591         func pChangeFile
3592                 myitem = tree1.currentindex()
3593                 if ofile.isdir(myitem)
3594                         return
3595                 ok
3596                 cActiveFileName = ofile.filepath(myitem)
3597                 textedit1.settext(read(cActiveFileName))
3598                 textedit1.setfocus(0)
3599                 pCursorPositionChanged()
3600                 pSetActiveFileName()
3601
3602         func pSetActiveFileName
3603                 oDock2.setWindowTitle("Source Code : " + cActiveFileName)
3604
3605         func pCursorPositionChanged
3606                 status1.showmessage(" Line : "+(textedit1.textcursor().blocknumber()+1)+
3607                                 " Column : " +(textedit1.textcursor().columnnumber()+1) +
3608                                 " Total Lines : " + textedit1.document().linecount() ,0)
3609
3610         func pGoto
3611                 oInput = New QInputDialog(win1)
3612                 {
3613                         setwindowtitle("Enter the line number?")
3614                         setgeometry(100,100,400,50)
3615                         setlabeltext("Line")
3616                         settextvalue("1")
3617                         exec()
3618                         nLine = 0 + oInput.textvalue()
3619                         oBlock = textedit1.document().findBlockByLineNumber(nLine-1)
3620                         oCursor = textedit1.textcursor()
3621                         oCursor.setposition(oBlock.position(),0)
3622                         textedit1.settextcursor(oCursor)
3623                 }
3624
3625         func pFind
3626                 if isobject(oSearch)
3627                         oSearch.activatewindow()
3628                         return
3629                 ok
3630                 oSearch = new qWidget()
3631                 {
3632                         new qLabel(oSearch)
3633                         {
3634                                 setText("Find What : ")
3635                                 setgeometry(10,10,50,30)
3636                         }
3637                         oSearchValue = new qlineedit(oSearch)
3638                         {
3639                                 setgeometry(80,10,460,30)
3640                                 setReturnPressedEvent("pFindValue()")
3641                         }
3642                         new qLabel(oSearch)
3643                         {
3644                                 setText("Replace with ")
3645                                 setgeometry(10,45,80,30)
3646                         }
3647                         oReplaceValue = new qlineedit(oSearch)
3648                         {
3649                                 setgeometry(80,45,460,30)
3650                         }
3651                         oSearchCase = new qCheckbox(oSearch)
3652                         {
3653                                 setText("Case Sensitive")
3654                                 setgeometry(80,85,100,30)
3655                         }
3656                         new qPushButton(oSearch)
3657                         {
3658                                 setText("Find/Find Next")
3659                                 setgeometry(80,120,100,30)
3660                                 setclickevent("pFindValue()")
3661                         }
3662                         new qPushButton(oSearch)
3663                         {
3664                                 setText("Replace")
3665                                 setgeometry(200,120,100,30)
3666                                 setclickevent("pReplace()")
3667                         }
3668                         new qPushButton(oSearch)
3669                         {
3670                                 setText("Replace All")
3671                                 setgeometry(320,120,100,30)
3672                                 setclickevent("pReplaceAll()")
3673                         }
3674                         new qPushButton(oSearch)
3675                         {
3676                                 setText("Close")
3677                                 setgeometry(440,120,100,30)
3678                                 setclickevent("pSearchClose()")
3679                         }
3680
3681                         setwinicon(oSearch,"image/notepad.png")
3682                         setWindowTitle("Find/Replace")          
3683                         setStyleSheet("background-color:white;")
3684                         setFixedsize(550,160)
3685                         setwindowflags( Qt_CustomizeWindowHint | 
3686                                         Qt_WindowTitleHint | Qt_WindowStaysOnTopHint) 
3687
3688                         oSearchFilter = new qallevents(oSearch)
3689                         oSearchFilter.setKeyPressEvent("pSearchKeyPress()")                                                             
3690                         installeventfilter(oSearchFilter)
3691
3692                         show()
3693                 }
3694
3695         Func pReplace
3696                 oCursor = textedit1.textCursor()
3697                 if oCursor.HasSelection() = false
3698                         new qMessagebox(oSearch)
3699                         {
3700                                 SetWindowTitle("Replace") 
3701                                 SetText("No Selection")
3702                                 show()  
3703                         }
3704                         return false
3705                 ok
3706                 cValue = oSearchValue.text()
3707                 cSelected = oCursor.SelectedText()
3708                 if oSearchCase.checkState() = Qt_Unchecked
3709                         cValue = lower(cValue)  
3710                         cSelected = lower(cSelected)
3711                 ok
3712                 if cSelected != cValue
3713                         new qMessagebox(oSearch)
3714                         {
3715                                 SetWindowTitle("Replace") 
3716                                 SetText("No Match")
3717                                 show()  
3718                         }
3719                         return false
3720                 ok
3721                 cValue = oReplaceValue.text()
3722                 nStart = oCursor.SelectionStart()
3723                 nEnd = oCursor.SelectionEnd()
3724                 cStr = textedit1.toPlainText()
3725                 cStr = left(cStr,nStart)+cValue+substr(cStr,nEnd+1)
3726                 textedit1.setText(cStr) 
3727                 return pFindValue()
3728
3729         Func pReplaceAll
3730                 cStr = textedit1.toPlainText()
3731                 cOldValue = oSearchValue.text()
3732                 cNewValue = oReplaceValue.text()
3733                 if oSearchCase.checkState() = Qt_Unchecked
3734                         # 英数大小文字非同一視
3735                         cStr = SubStr(cStr,cOldValue,cNewValue,true)
3736                 else
3737                         # 英数大小文字同一視
3738                         cStr = SubStr(cStr,cOldValue,cNewValue)
3739                 ok
3740                 textedit1.setText(cStr) 
3741                 new qMessagebox(oSearch)
3742                 {
3743                         SetWindowTitle("Replace All") 
3744                         SetText("Operation Done")
3745                         show()  
3746                 }
3747
3748         Func pSearchClose
3749                 oSearch.close() 
3750                 oSearch = NULL
3751
3752         func pSearchKeyPress
3753                 if oSearchFilter.getKeyCode() = Qt_Key_Escape
3754                         pSearchClose()          
3755                 ok
3756
3757         func pFindValue
3758                 oCursor = textedit1.textcursor()
3759                 nPosStart = oCursor.Position() + 1
3760                 cValue = oSearchValue.text()
3761                 cStr = textedit1.toplaintext()
3762                 cStr = substr(cStr,nPosStart)
3763                 if oSearchCase.checkState() = Qt_Unchecked
3764                         cStr = lower(cStr)  cValue = lower(cValue)
3765                 ok
3766                 nPos = substr(cStr,cValue)
3767                 if nPos > 0
3768                         nPos += nPosStart - 2
3769                         oCursor = textedit1.textcursor()
3770                         oCursor.setposition(nPos,0)
3771                         textedit1.settextcursor(oCursor)
3772                         oCursor = textedit1.textcursor()
3773                         oCursor.setposition(nPos+len(cValue),1)
3774                         textedit1.settextcursor(oCursor)
3775                         return true
3776                 else
3777                         new qMessagebox(oSearch)
3778                         {
3779                                 SetWindowTitle("Search") 
3780                                 SetText("Cannot find :" + cValue)
3781                                 show()  
3782                         }
3783                         return false
3784                 ok              
3785
3786         func pNofileopened
3787                 New qMessageBox(win1) {
3788                         setWindowTitle("Sorry")
3789                         setText("Save the file first!")
3790                         show()
3791                 }
3792
3793         func pDebug
3794                 if cActiveFileName = Null return pNofileopened() ok
3795                 cCode = "start run " + cActiveFileName + nl 
3796                 system(cCode)
3797
3798         func pRun
3799                 if cActiveFileName = Null return pNofileopened() ok
3800                 cCode = "start ring " + cActiveFileName + nl 
3801                 system(cCode)
3802
3803         func pRunNoConsole
3804                 if cActiveFileName = Null return pNofileopened() ok
3805                 cCode = "start /b ring " + cActiveFileName + nl 
3806                 system(cCode)
3807
3808         func pSave
3809                 if cActiveFileName = NULL return pSaveAs() ok
3810                 writefile(cActiveFileName,textedit1.toplaintext())
3811                 status1.showmessage("File : " + cActiveFileName + " saved!",0)
3812                 lAskToSave = false
3813
3814         func pSaveAs
3815                 new qfiledialog(win1) {
3816                         cName = getsavefilename(win1,"Save As","","source files(*.ring)")
3817                         if cName != NULL
3818                                 cActiveFileName = cName
3819                                 writefile(cActiveFileName,textedit1.toplaintext())
3820                                 status1.showmessage("File : " + cActiveFileName + " saved!",0)  
3821                                 pSetActiveFileName()
3822                                 lAskToSave = false
3823                         ok      
3824                 }
3825
3826         func pPrint
3827                 status1.showmessage("Printing to File : RingDoc.pdf",0)
3828                 printer1 = new qPrinter(0) {
3829                         setoutputformat(1)      # 1 = pdf
3830                         setoutputfilename("RingDoc.pdf")
3831                         textedit1.print(printer1)
3832                 }
3833                 status1.showmessage("Done!",0)
3834                 system("RingDoc.pdf")
3835
3836         func pCut
3837                 textedit1.cut()
3838                 status1.showmessage("Cut!",0)           
3839
3840         func pCopy
3841                 textedit1.copy()
3842                 status1.showmessage("Copy!",0)          
3843
3844         func pPaste
3845                 textedit1.paste()
3846                 status1.showmessage("Paste!",0)         
3847
3848         func pFont
3849                 oFontDialog = new qfontdialog() {
3850                         aFont = getfont()
3851                 }
3852                 textedit1.selectall()
3853                 cFont = aFont[1]
3854                 pSetFont()
3855
3856         Func pSetFont
3857                 myfont = new qfont("",0,0,0)
3858                 myfont.fromstring(cFont)
3859                 textedit1.setcurrentfont(myfont)
3860
3861         Func pColor
3862                 new qcolordialog() { aTextColor = GetColor() }  
3863                 pSetColors()
3864
3865         Func pColor2
3866                 new qcolordialog() { aBackColor = GetColor() }  
3867                 pSetColors()
3868                 
3869         Func pSetColors
3870                 textedit1.setstylesheet("color: rgb(" + aTextColor[1] + "," + aTextColor[2] +
3871                                         "," + aTextColor[3] + ");" + "background-color: rgb(" +
3872                                         aBackColor[1] + "," + aBackColor[2] + "," +
3873                                         aBackColor[3] + ")")
3874
3875         func pOpen
3876                 new qfiledialog(win1) {
3877                         cName = getopenfilename(win1,"open file","c:\","source files(*.ring)")                  
3878                         if cName != NULL
3879                                 cActiveFileName = cName
3880                                 textedit1.settext(read(cActiveFileName))
3881                         ok
3882                 }
3883                 
3884         func pNew
3885                 new qfiledialog(win1) {
3886                         cName = getsavefilename(win1,"New file","","source files(*.ring)")
3887                         if cName != NULL
3888                                 write(cName,"")
3889                                 cActiveFileName = cName
3890                                 textedit1.settext(read(cActiveFileName))
3891                                 
3892                         ok      
3893                 }
3894                 
3895         Func WriteFile cFileName,cCode
3896                 aCode = str2list(cCode)
3897                 fp = fopen(cFileName,"wb")
3898                 for cLine in aCode
3899                         fwrite(fp,cLine+char(13)+char(10))      
3900                 next
3901                 fclose(fp)
3902
3903         Func MsgBox cTitle,cMessage
3904                 new qMessagebox(win1) {
3905                         setwindowtitle(cTitle)
3906                         setText(cMessage)
3907                         show()
3908                 }
3909                 
3910
3911         Func pLang
3912                 MsgBox("Programming Language",
3913                         "This application developed using the Ring programming language")
3914
3915         Func pGUI
3916                 MsgBox("GUI Library",
3917                         "This application uses the Qt GUI Library through RingQt")
3918
3919         Func pAbout
3920                 MsgBox("About",
3921                         "2016, Mahmoud Fayed <msfclipper@yahoo.com>")           
3922
3923         Func pSaveSettings
3924                 cSettings = "aTextColor = ["+aTextColor[1]+","+aTextColor[2]+
3925                                 ","+aTextColor[3]+"]" + nl + 
3926                                 "aBackColor = ["+aBackColor[1]+","+aBackColor[2]+
3927                                 ","+aBackColor[3]+"]" + nl +
3928                                 "cFont = '" + cFont + "'" + nl + 
3929                                 "cWebSite = '" + cWebsite + "'" + nl
3930                 cSettings = substr(cSettings,nl,char(13)+char(10))
3931                 write("ringnotepad.ini",cSettings)
3932                 if lAsktoSave
3933                         new qmessagebox(win1)
3934                         {
3935                                 setwindowtitle("Save Changes?")
3936                                 settext("Some changes are not saved!")
3937                                 setInformativeText("Do you want to save your changes?")
3938                                 setstandardbuttons(QMessageBox_Yes |
3939                                                    QMessageBox_No | QMessageBox_Cancel)
3940                                 result = exec()
3941                                 win1 {
3942                                 if result = QMessageBox_Yes
3943                                         pSave()
3944                                 but result = QMessageBox_Cancel
3945                                         return false
3946                                 ok
3947                         }
3948                 }       
3949                 ok
3950                 return true
3951
3952         Func pSetWebsite
3953                 oWebView { loadpage(new qurl(cWebSite)) }       
3954                 oWBText  { setText(cWebSite) }          
3955
3956         Func RestoreSettings
3957                 eval(read("ringnotepad.ini"))
3958                 pSetColors()
3959                 pSetFont()
3960                 pSetWebsite()
3961
3962         Func pQuit
3963                 if pSaveSettings() 
3964                         myapp.quit()
3965                 ok
3966
3967
3968 実行中のアプリケーション
3969
3970 このスクリーンショットは “ファイル” メニューのデモです。
3971
3972 .. image:: ringqt_shot50.jpg
3973         :alt: Ring ノートパッド - ファイルメニュー
3974
3975 このウィンドウは “検索と置換”です。
3976
3977 .. image:: ringqt_shot51.jpg
3978         :alt: Ring ノートパッド - 検索と置換
3979
3980 このスクリーンショットはアプリケーションのメインウィンドウのデモです。
3981
3982 .. image:: ringqt_shot49.jpg
3983         :alt: Ring ノートパッド - メインウィンドウ
3984
3985 .. note:: 前述のサンプルにある pDebug(), pRun() および pRunNoConsole() 関数は移植性がありません!
3986         このサンプルでは MS-Windows 用に記述されており、ほかのオペレーティングシステム用に更新できます。
3987
3988 .. index:: 
3989         pair: RingQt によるデスクトップとモバイル開発; Cards ゲーム
3990
3991 Cards ゲーム
3992 ============
3993
3994 この用例は、 RingQt で開発したシンプルなカードゲームです。
3995
3996 各プレイヤーは五枚のカードを取得しますが、カードの中身は誰にもわかりません。
3997 プレイヤーは毎回カードを確認するためにカードを一枚クリックします。
3998 カードが別のカードと同じ番号ならば各カードのポイントを取得します。
3999 カードの番号が “5” ならば、すべての可視状態のカードのポイントを取得します。
4000
4001 .. code-block:: ring
4002
4003         Load "guilib.ring"
4004
4005         nScale = 1
4006
4007         app1 = new qApp
4008
4009         mypic = new QPixmap("cards.jpg")
4010
4011         mypic2 = mypic.copy(0,(124*4)+1,79,124)
4012         Player1EatPic = mypic.copy(80,(124*4)+1,79,124)
4013         Player2EatPic= mypic.copy(160,(124*4)+1,79,124)
4014
4015         aMyCards = []
4016         aMyValues = []
4017         for x1 = 0 to 3
4018                 for y1 = 0 to 12
4019                   temppic = mypic.copy((79*y1)+1,(124*x1)+1,79,124)
4020                           aMyCards + temppic
4021                           aMyValues + (y1+1)
4022                 next
4023         next
4024
4025         nPlayer1Score = 0   nPlayer2Score=0
4026
4027         do
4028                 Page1 = new Game
4029                 Page1.Start()
4030         again Page1.lnewgame
4031
4032         mypic.delete()
4033         mypic2.delete()
4034         Player1EatPic.delete()
4035         Player2EatPic.delete()
4036
4037         for t in aMyCards
4038                   t.delete()
4039         next
4040
4041         func gui_setbtnpixmap pBtn,pPixmap
4042                 pBtn {
4043                         setIcon(new qicon(pPixmap.scaled(width(),height(),0,0)))
4044                         setIconSize(new QSize(width(),height()))
4045                 }
4046
4047         Class Game
4048                 
4049                 nCardsCount = 10
4050                 win1 layout1 label1 label2 layout2 layout3 aBtns aBtns2
4051                 aCards nRole=1 aStatus = list(nCardsCount) aStatus2 = aStatus
4052                 aValues        aStatusValues = aStatus  aStatusValues2 = aStatus
4053                 Player1EatPic   Player2EatPic
4054                 lnewgame = false
4055                 nDelayEat = 0.5
4056                 nDelayNewGame = 1
4057
4058                 func start
4059
4060                         win1 = new qWidget() { 
4061                                 setwindowtitle("Five") 
4062                                 setstylesheet("background-color: White")
4063                                 showfullscreen()
4064                         }
4065                 
4066                         layout1 = new qvboxlayout()
4067                 
4068                         label1 = new qlabel(win1) {
4069                                 settext("Player (1) - Score : " + nPlayer1Score)
4070                                 setalignment(Qt_AlignHCenter | Qt_AlignVCenter)
4071                                 setstylesheet("color: White; background-color: Purple;
4072                                                  font-size:20pt")
4073                                 setfixedheight(200)
4074                         }
4075
4076                         closebtn = new qpushbutton(win1)  {
4077                                 settext("Close Application")
4078                                 setstylesheet("font-size: 18px ; color : white ;
4079                                                  background-color: black ;")
4080                                 setclickevent("Page1.win1.close()")
4081                         }
4082                 
4083                         aCards = aMyCards
4084                         aValues = aMyValues
4085
4086                         layout2 = new qhboxlayout()
4087
4088                         aBtns = []
4089
4090                         for x = 1 to nCardsCount
4091                                 aBtns + new qpushbutton(win1) 
4092                                 aBtns[x].setfixedwidth(79*nScale)
4093                                 aBtns[x].setfixedheight(124*nScale)
4094                                 gui_setbtnpixmap(aBtns[x],mypic2)
4095                                 layout2.addwidget(aBtns[x])
4096                                 aBtns[x].setclickevent("Page1.Player1click("+x+")")
4097                         next
4098
4099                         layout1.addwidget(label1)       
4100                         layout1.addlayout(layout2)
4101
4102                         label2 = new qlabel(win1) {
4103                                 settext("Player (2) - Score : " + nPlayer2Score)
4104                                 setalignment(Qt_AlignHCenter | Qt_AlignVCenter)
4105                                 setstylesheet("color: white; background-color: red;
4106                                                  font-size:20pt")
4107                                 setfixedheight(200)
4108                         }
4109
4110                         layout3 = new qhboxlayout()
4111
4112                         aBtns2 = []
4113                         for x = 1 to nCardsCount
4114                                 aBtns2 + new qpushbutton(win1)
4115                                 aBtns2[x].setfixedwidth(79*nScale)
4116                                 aBtns2[x].setfixedheight(124*nScale)
4117                                 gui_setbtnpixmap(aBtns2[x],mypic2)
4118                                 layout3.addwidget(aBtns2[x])
4119                                 aBtns2[x].setclickevent("Page1.Player2click("+x+")")
4120                         next
4121
4122                         layout1.addwidget(label2)
4123                         layout1.addlayout(layout3)
4124                         layout1.addwidget(closebtn)
4125
4126                         win1.setlayout(layout1)
4127
4128                         app1.exec()
4129
4130                 Func Player1Click x
4131                         if nRole = 1 and aStatus[x] = 0
4132                                 nPos = ((random(100)+clock())%(len(aCards)-1)) + 1
4133                                 gui_setbtnpixmap(aBtns[x],aCards[nPos])
4134                                 del(aCards,nPos)
4135                                 nRole = 2
4136                                 aStatus[x] = 1
4137                                 aStatusValues[x] = aValues[nPos]
4138                                 del(aValues,nPos)
4139                                 Player1Eat(x,aStatusValues[x])
4140                                 checknewgame()
4141                         ok
4142
4143                 Func Player2Click x
4144                         if nRole = 2 and aStatus2[x] = 0
4145                                 nPos = ((random(100)+clock())%(len(aCards)-1)) + 1
4146                                 gui_setbtnpixmap(aBtns2[x],aCards[nPos])
4147                                 del(aCards,nPos)
4148                                 nRole = 1
4149                                 aStatus2[x] = 1
4150                                 aStatusValues2[x] = aValues[nPos]
4151                                 del(aValues,nPos)
4152                                 Player2Eat(x,aStatusValues2[x])
4153                                 checknewgame()
4154                         ok
4155
4156                 Func Player1Eat nPos,nValue
4157
4158                          app1.processEvents()
4159
4160                          delay(nDelayEat)
4161                          lEat = false
4162                          for x = 1 to nCardsCount
4163                                  if aStatus2[x] = 1 and (aStatusValues2[x] = nValue or nValue=5)
4164                                         aStatus2[x] = 2
4165                                         gui_setbtnpixmap(aBtns2[x],Player1EatPic)
4166                                         lEat = True
4167                                         nPlayer1Score++
4168                                  ok
4169                                  if (x != nPos) and (aStatus[x] = 1) and 
4170                                         (aStatusValues[x] = nValue or nValue=5)
4171                                         aStatus[x] = 2
4172                                         gui_setbtnpixmap(aBtns[x],Player1EatPic)
4173                                         lEat = True
4174                                         nPlayer1Score++
4175                                  ok
4176                          next
4177                          if lEat
4178                                         nPlayer1Score++
4179                                         gui_setbtnpixmap(aBtns[nPos],Player1EatPic)
4180                                         aStatus[nPos] = 2
4181                                         label1.settext("Player (1) - Score : " + nPlayer1Score)
4182                          ok
4183
4184                 Func Player2Eat nPos,nValue
4185
4186                          app1.processEvents()
4187
4188                          delay(nDelayEat)
4189                          lEat = false
4190                          for x = 1 to  nCardsCount
4191                                  if aStatus[x] = 1 and (aStatusValues[x] = nValue or nValue = 5)
4192                                         aStatus[x] = 2
4193                                         gui_setbtnpixmap(aBtns[x],Player2EatPic)
4194                                         lEat = True
4195                                         nPlayer2Score++
4196                                  ok
4197
4198                                  if (x != nPos) and (aStatus2[x] = 1) and
4199                                         (aStatusValues2[x] = nValue or nValue=5 )
4200                                         aStatus2[x] = 2
4201                                         gui_setbtnpixmap(aBtns2[x],Player2EatPic)
4202                                         lEat = True
4203                                         nPlayer2Score++
4204                                  ok
4205                          next
4206                          if lEat
4207                                         nPlayer2Score++
4208                                         gui_setbtnpixmap(aBtns2[nPos],Player2EatPic)
4209                                         aStatus2[nPos] = 2
4210                                         label2.settext("Player (2) - Score : " + nPlayer2Score)
4211                          ok
4212
4213                 Func checknewgame
4214                         if isnewgame()
4215                                           lnewgame = true
4216
4217                                           if nPlayer1Score > nPlayer2Score
4218                                                  label1.settext("Player (1) Wins!!!")
4219                                           ok
4220                                           if nPlayer2Score > nPlayer1Score
4221                                                  label2.settext("Player (2) Wins!!!")
4222                                           ok
4223
4224                                           app1.processEvents()
4225                                           delay(nDelayNewGame)
4226
4227                                           win1.delete()
4228                                           app1.quit()
4229                         ok
4230
4231                 Func isnewgame
4232                         for t in aStatus
4233                                 if t = 0
4234                                         return false
4235                                 ok
4236                         next
4237                         for t in aStatus2
4238                                 if t = 0
4239                                         return false
4240                                 ok
4241                         next
4242                         return true
4243
4244                 Func delay x
4245                 nTime = x * 1000
4246                 oTest = new qTest
4247                 oTest.qsleep(nTime)
4248
4249 実行中のアプリケーション
4250                         
4251 .. image:: ringqt_shot48.jpg
4252         :alt: Cards ゲーム
4253
4254 .. note:: 前述のスクリーンショットではプレイヤーが‘5’番のカードを入手していますがスコアは加算されていません。
4255         これはほかのカードが不可視状態のときに‘5’番のカードを開いたからです!
4256
4257 このスクリーンショットはモバイル機器 (Android) でゲームを実行しています。
4258
4259 .. image:: ringqt_shot52.jpg
4260         :alt: Cards ゲーム
4261
4262 .. note:: Qt を使うと同じアプリケーションをほかのモバイルシステムで実行できます。
4263
4264
4265 .. index:: 
4266         pair: RingQt によるデスクトップとモバイル開発; クラスとメソッドでデフォルトのイベントを使うには
4267
4268
4269 クラスとメソッドでデフォルトのイベントを使うには
4270 ================================================
4271
4272 この表ではクラス名、およびメソッドで使用するデフォルトのイベントについて説明しています。
4273
4274 ==============================  ===========================================================
4275 クラス名                                            メソッドで使用するデフォルトのイベント
4276 ==============================  ===========================================================
4277 QPushButton                     SetClickEvent()
4278 QAction                         SetClickEvent()
4279 QLineEdit                       SetTextChangedEvent()
4280 ..                              SetCursorPositionChangedEvent()
4281 ..                              SetEditingFinishedEvent()
4282 ..                              SetReturnPressedEvent()
4283 ..                              SetSelectionChangedEvent()
4284 ..                              SetTextEditedEvent()
4285 QTextEdit                       SetCopyAvailableEvent()
4286 ..                              SetCurrentCharFormatChangedEvent()
4287 ..                              SetCursorPositionChangedEvent()
4288 ..                              SetRedoAvailableEvent()
4289 ..                              SetSelectionChangedEvent()
4290 ..                              SetTextChangedEvent()
4291 ..                              SetUndoAvailableEvent()
4292 QListWidget                     SetCurrentItemChangedEvent()
4293 ..                              SetCurrentRowChangedEvent()
4294 ..                              SetCurrentTextChangedEvent()
4295 ..                              SetItemActivatedEvent()
4296 ..                              SetItemChangedEvent()
4297 ..                              SetItemClickedEvent()
4298 ..                              SetItemDoubleClickedEvent()
4299 ..                              SetItemEnteredEvent()
4300 ..                              SetItemPressedEvent()
4301 ..                              SetItemSelectionChangedEvent()
4302 QTreeView                       SetCollapseEvent()
4303 ..                              SetExpandedEvent()
4304 ..                              SetActivatedEvent()
4305 ..                              SetClickedEvent()
4306 ..                              SetDoubleClickedEvent()
4307 ..                              SetEnteredEvent()
4308 ..                              SetPressedEvent()
4309 ..                              SetViewportEnteredEvent()
4310 QTreeWidget                     SetCollapsedEvent()
4311 ..                              SetExpandedEvent()
4312 ..                              SetActivatedEvent()
4313 ..                              SetClickedEvent()
4314 ..                              SetDoubleClickedEvent()
4315 ..                              SetEnteredEvent()
4316 ..                              SetPressedEvent()
4317 ..                              SetViewportEnteredEvent()
4318 ..                              SetCurrentItemChangedEvent()
4319 ..                              SetItemActivatedEvent()
4320 ..                              SetItemChangedEvent()
4321 ..                              SetItemClickedEvent()
4322 ..                              SetItemCollapsedEvent()
4323 ..                              SetItemDoubleClickedEvent()
4324 ..                              SetItemEnteredEvent()
4325 ..                              SetItemExpandedEvent()
4326 ..                              SetItemPressedEvent()
4327 ..                              SetItemSelectionChangedEvent()
4328 QComboBox                       SetActivatedEvent()
4329 ..                              SetCurrentIndexChangedEvent()
4330 ..                              SetEditTextChangedEvent()
4331 ..                              SetHighlightedEvent()
4332 QTabWidget                      SetCurrentChangedEvent()
4333 ..                              SetTabCloseRequestedEvent()
4334 QTableWidget                    SetCellActivatedEvent()
4335 ..                              SetCellChangedEvent()
4336 ..                              SetCellClickedEvent()
4337 ..                              SetCellDoubleClickedEvent()
4338 ..                              SetCellEnteredEvent()
4339 ..                              SetCellPressedEvent()
4340 ..                              SetCurrentCellChangedEvent()
4341 ..                              SetCurrentItemChangedEvent()
4342 ..                              SetItemActivatedEvent()
4343 ..                              SetItemChangedEvent()
4344 ..                              SetItemClickedEvent()
4345 ..                              SetItemDoubleClickedEvent()
4346 ..                              SetItemEnteredEvent()
4347 ..                              SetItemPressedEvent()
4348 ..                              SetItemSelectionChangedEvent()
4349 QProgressBar                    SetValueChangedEvent()
4350 QSpinBox                        SetValueChangedEvent()
4351 QSlider                         SetActionTriggeredEvent()
4352 ..                              SetRangeChangedEvent()
4353 ..                              SetSliderMovedEvent()
4354 ..                              SetSliderPressedEvent()
4355 ..                              SetSliderReleasedEvent()
4356 ..                              SetValueChangedEvent()
4357 QDial                           SetActionTriggeredEvent()
4358 ..                              SetRangeChangedEvent()
4359 ..                              SetSliderMovedEvent()
4360 ..                              SetSliderPressedEvent()
4361 ..                              SetSliderReleasedEvent()
4362 ..                              SetValueChangedEvent()
4363 QWebView                        SetLoadFinishedEvent()
4364 ..                              SetLoadProgressEvent()
4365 ..                              SetLoadStartedEvent()
4366 ..                              SetSelectionChangedEvent()
4367 ..                              SetTitleChangedEvent()
4368 ..                              SetUrlChangedEvent()
4369 QCheckBox                       SetStateChangedEvent()
4370 ..                              SetClickedEvent()
4371 ..                              SetPressedEvent()
4372 ..                              SetReleasedEvent()
4373 ..                              SetToggledEvent()
4374 QRadioButton                    SetClickedEvent()
4375 ..                              SetPressedEvent()
4376 ..                              SetReleasedEvent()
4377 ..                              SetToggledEvent()
4378 QButtonGroup                    SetButtonClickedEvent()
4379 ..                              SetButtonPressedEvent()
4380 ..                              SetButtonReleasedEvent()
4381 QVideoWidget                    SetBrightnessChangedEvent()
4382 ..                              SetContrastChangedEvent()
4383 ..                              SetFullScreenChangedEvent()
4384 ..                              SetHueChangedEvent()
4385 ..                              SetSaturationChangedEvent()
4386 QTimer                          SetTimeoutEvent()
4387 QTcpServer                      SetAcceptErrorEvent()
4388 ..                              SetNewConnectionEvent()
4389 QIODevice                       SetAboutToCloseEvent()
4390 ..                              SetBytesWrittenEvent()
4391 ..                              SetReadChannelFinishedEvent()
4392 ..                              SetReadyReadEvent()
4393 QAbstractSocket                 SetConnectedEvent()
4394 ..                              SetDisconnectedEvent()
4395 ..                              SetErrorEvent()
4396 ..                              SetHostFoundEvent()
4397 ..                              SetProxyAuthenticationRequiredEvent()
4398 ..                              SetStateChangedEvent()
4399 QTcpSocket                      SetConnectedEvent()
4400 ..                              SetDisconnectedEvent()
4401 ..                              SetErrorEvent()
4402 ..                              SetHostFoundEvent()
4403 ..                              SetProxyAuthenticationRequiredEvent()
4404 ..                              SetStateChangedEvent()
4405 ..                              SetAboutToCloseEvent()
4406 ..                              SetBytesWrittenEvent()
4407 ..                              SetReadChannelFinishedEvent()
4408 ..                              SetReadyReadEvent()
4409 QColorDialog                    SetColorSelectedEvent()
4410 ..                              SetCurrentColorChangedEvent()
4411 QNetworkAccessManager           SetFinishedEvent()
4412 QThread                         SetStartedEvent()
4413 ..                              SetFinishedEvent()
4414 ==============================  ===========================================================
4415
4416 .. index:: 
4417         pair: RingQt によるデスクトップとモバイル開発; イベントでイベントフィルタによるメソッド
4418
4419 イベントでイベントフィルタによるメソッド
4420 ============================================
4421
4422 RingQt はイベントフィルタを使用することにより、新しいクラス QAllEvents を定義しています。
4423
4424 この表は利用可能なメソッドです。
4425
4426 ================================        ======================
4427 メソッドで取得する仮引数                    クラス名
4428 ================================        ======================
4429 getKeyCode()    --> Number              QAllEvents
4430 getx()          --> Number
4431 gety()          --> Number
4432 getglobalx()    --> Number
4433 getglobaly()    --> Number
4434 getbutton()     --> Number
4435 getbuttons()    --> Number
4436 ================================        ======================
4437
4438 この表はイベントで使用するメソッドを解説しています。
4439
4440 ===================================================     ======================
4441 メソッド名                                                                                 クラス名
4442 ===================================================     ======================
4443 setKeyPressEvent(cEvent)                                QAllEvents
4444 setMouseButtonPressEvent(cEvent)
4445 setMouseButtonReleaseEvent(cEvent)
4446 setMouseButtonDblClickEvent(cEvent)
4447 setMouseMoveEvent(cEvent)
4448 setCloseEvent(cEvent)
4449 setContextMenuEvent(cEvent)
4450 setDragEnterEvent(cEvent)
4451 setDragLeaveEvent(cEvent)
4452 setDragMoveEvent(cEvent)
4453 setDropEvent(cEvent)
4454 setEnterEvent(cEvent)
4455 setFocusInEvent(cEvent)
4456 setFocusOutEvent(cEvent)
4457 setKeyReleaseEvent(cEvent)
4458 setLeaveEvent(cEvent)
4459 setNonClientAreaMouseButtonDblClickEvent(cEvent)
4460 setNonClientAreaMouseButtonPressEvent(cEvent)
4461 setNonClientAreaMouseButtonReleaseEvent(cEvent)
4462 setNonClientAreaMouseMoveEvent(cEvent)
4463 setMoveEvent(cEvent)
4464 setResizeEvent(cEvent)
4465 setWindowActivateEvent(cEvent)
4466 setWindowBlockedEvent(cEvent)
4467 setWindowDeactivateEvent(cEvent)
4468 setWindowStateChangeEvent(cEvent)
4469 setWindowUnblockedEvent(cEvent)
4470 ===================================================     ======================
4471
4472 .. index:: 
4473         pair: RingQt によるデスクトップとモバイル開発; Qt と RingQt の違い
4474
4475 Qt と RingQt の違い
4476 ===================
4477
4478 (1) RingQt ではイベントの実行用コードを設定するために単純なメソッドを使用します。
4479
4480 文法:
4481
4482 .. code-block:: none
4483
4484         Set<Event_Name>Event(cEventCode)
4485         
4486 (2) RingQt では Ring キーワードとの衝突を回避するためにメソッド名を変更しています。
4487
4488 この表は変更点の解説です。
4489
4490 ===============================     ======================      =====================
4491 クラス名                            Qt メソッド名               RingQt メソッド名
4492 ===============================     ======================      =====================
4493 QWebView                            load                        loadpage
4494 QMediaPlaylist                      load                        loadfile
4495 QMediaPlaylist                      next                        movenext
4496 QPainter                            end                         endpaint
4497 QPicture                            load                        loadfile
4498 QLineEdit                           end                         endtext
4499 QDialog                             done                        donedialog
4500 QTextDocument                       end                         enddoc
4501 QTextBlock                          next                        nextblock
4502 QSqlQuery                           next                        movenext
4503 QImage                              load                        loadimage
4504 QNetworkAccessManager               get                         getvalue
4505 QNetworkAccessManager               put                         putvalue
4506 QThread                             exit                        exitfromthread
4507 QRegularExpressionMatchIterator     next                        nextitem
4508 QCamera                             load                        loadcamera
4509 ===============================     ======================      =====================
4510
4511 .. index:: 
4512         pair: RingQt によるデスクトップとモバイル開発; RingQt クラスおよび Qt の取扱説明書
4513
4514 RingQt クラスおよび Qt の取扱説明書
4515 =========================================
4516
4517 Qt 取扱説明書 : http://doc.qt.io/qt-5/classes.html
4518
4519 対応しているクラスとメソッドについては “RingQt クラスとメソッドのリファレンス” の章を参照してください。
4520
4521
4522 .. index:: 
4523         pair: RingQt によるデスクトップとモバイル開発; 新しいクラス名 - 1 からインデックスを開始
4524
4525 新しいクラス名 - 1 からインデックスを開始
4526 =========================================
4527
4528 RingQt には新しいクラスが追加されています - 別バージョンのクラス名は小文字 “q” で開始されません。
4529 また GUI コントロールなど扱うときにインデックスが 1 から開始するようにメソッドを更新してあります。
4530
4531 * ComboBox
4532 * ListWidget
4533 * TableWidget
4534 * TreeWidget
4535
4536 前述のクラスは guilib.ring の System.GUI パッケージに実装されています:
4537
4538 用法
4539
4540 .. code-block:: ring
4541
4542         load "guilib.ring"
4543
4544         import System.GUI
4545
4546 これは以前のコードに一切影響を与えません。
4547 つまり Ring の規則と整合性がある優れたコードへの第三の選択です。
4548
4549 またフォームデザイナーは、クラス間で「インデックスを 0 から開始」
4550 または「インデックスを 1 から開始」を選択肢を使用するために更新しました。
4551
4552 用例 (フォームデザイナーを使用)
4553
4554 (1) https://github.com/ring-lang/ring/blob/master/applications/formdesigner/tests/indexstart/indexstartView.ring
4555
4556 (2) https://github.com/ring-lang/ring/blob/master/applications/formdesigner/tests/indexstart/indexstartController.ring 
4557
4558 .. index:: 
4559         pair: RingQt によるデスクトップとモバイル開発; WebLib および GUILib によるレポートの作成方法
4560
4561
4562 WebLib および GUILib によるレポートの作成方法
4563 =================================================
4564
4565 WebLib には HtmlPage クラスがあります。
4566
4567 このクラスにより WebLib と GUILib で手軽にレポートを作成できます。
4568
4569 用例:
4570
4571 .. code-block:: ring
4572
4573         load "stdlib.ring"
4574         load "weblib.ring"
4575         load "guilib.ring"
4576
4577         import System.Web
4578         import System.GUI
4579
4580         new qApp {
4581                 open_window(:CustomersReportController)
4582                 exec()
4583         }
4584
4585         class CustomersReportController
4586
4587                 oView = new CustomersReportView
4588
4589                 func Start
4590                         CreateReport()
4591
4592                 func CreateReport
4593                         mypage = new HtmlPage {
4594                                 h1 { text("Customers Report") }
4595                                 Table
4596                                 {
4597                                         style = stylewidth("100%") + stylegradient(4)
4598                                         TR
4599                                         {
4600                                                 TD { WIDTH="10%" 
4601                                                         text("Customers Count : " )  }
4602                                                 TD { text (100) }
4603                                         }
4604                                 }
4605                                 Table
4606                                 {
4607                                         style = stylewidth("100%") + stylegradient(26)
4608                                         TR
4609                                         {
4610                                                 style = stylewidth("100%") +
4611                                                         stylegradient(24)
4612                                                 TD { text("Name " )  }
4613                                                 TD { text("Age" ) }
4614                                                 TD { text("Country" ) }
4615                                                 TD { text("Job" ) }     
4616                                                 TD { text("Company" ) }
4617                                         }
4618                                         for x =  1 to 100
4619                                                 TR
4620                                                 {
4621                                                         TD { text("Test" )  }
4622                                                         TD { text("30" ) }
4623                                                         TD { text("Egypt" ) }
4624                                                         TD { text("Sales" ) }   
4625                                                         TD { text("Future" ) }
4626                                                 }
4627                                         next
4628                                 }
4629                         }
4630                         write("report.html",mypage.output())
4631
4632                 func PrintEvent
4633                         printer1 = new qPrinter(0) {
4634                                 setoutputformat(1)
4635                                 setoutputfilename("report.pdf")
4636                         }
4637                         oView {
4638                                 web.print(printer1)
4639                                 web.show()
4640                         }
4641                         system ("report.pdf")
4642
4643         class CustomersReportView
4644
4645                         win = new window() {
4646                                         setwindowtitle("Report Window")
4647                                         setgeometry(100,100,500,500)
4648                                         web = new webview(win) {
4649                                                 setgeometry(100,100,1000,500)
4650                                                 loadpage(new qurl("file:///"+
4651                                                 currentdir()+"/report.html"))
4652                                         }
4653                                         new pushbutton(win) {
4654                                                         setGeometry(100,20,100,30)
4655                                                         settext("Print")
4656                                                         setclickevent(Method(:PrintEvent))
4657                                         }
4658                                         showMaximized()
4659                                 }
4660
4661 スクリーンショット:
4662
4663 .. image:: ring15reportshot.png
4664         :alt: 顧客報告書
4665