[q-lang-cvs] qcalc qcalc.q,1.148,1.149
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2007-11-16 03:59:49
|
Update of /cvsroot/q-lang/qcalc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv3185 Modified Files: qcalc.q Log Message: code cleanup, add support for action button elements Index: qcalc.q =================================================================== RCS file: /cvsroot/q-lang/qcalc/qcalc.q,v retrieving revision 1.148 retrieving revision 1.149 diff -C2 -d -r1.148 -r1.149 *** qcalc.q 15 Nov 2007 13:20:01 -0000 1.148 --- qcalc.q 16 Nov 2007 03:59:44 -0000 1.149 *************** *** 960,964 **** where (N,M) = cell_span (I,J), IT:QtObject = qt_object "QCheckTableItem" ! (TABLE,S) "MyCheckTableItem" (ref (),ref (),ref (),()|DATA) [] [] []; --- 960,964 ---- where (N,M) = cell_span (I,J), IT:QtObject = qt_object "QCheckTableItem" ! (TABLE,S) "MyCheckBox" (ref (),ref (),ref (),()|DATA) [] [] []; *************** *** 971,975 **** where (N,M) = cell_span (I,J), IT:QtObject = qt_object "QComboTableItem" ! (TABLE,SL,E) "MyComboTableItem" (ref (),ref (),ref (),()|DATA) [] [] []; --- 971,976 ---- where (N,M) = cell_span (I,J), IT:QtObject = qt_object "QComboTableItem" ! (TABLE,SL,E) ! (if E then "MyComboEdit" else "MyComboBox") (ref (),ref (),ref (),()|DATA) [] [] []; *************** *** 1046,1049 **** --- 1047,1054 ---- = IT if eq () X; + gui_data (I,J) = DATA + where IT:QtObject = get CELLS!(I,J), + (_,_,_,_|DATA) = qt_data IT; + has_table_item (I,J) = true *************** *** 1071,1082 **** qt TABLE "clearSelection" (); - private yytask KEY MSG; - clear_cell (I,J) ! where X:QtObject = gui_elem (I,J), ("MyTaskButton"|_) = qt_mob_data X: ! = // nuke an existing background thread ! send_expr '(yytask (I,J) ()) || ! fail; // falls through to below ! if (I,J) = real_index (I,J): = qt TABLE "clearCell" (I,J) if not has_table_item (I,J); = cell_setval (I,J) Y --- 1076,1086 ---- qt TABLE "clearSelection" (); clear_cell (I,J) ! if (I,J) <> real_index (I,J): ! = _FAIL_; ! where X:QtObject = gui_elem (I,J): ! = // clean up GUI element in the inferior process ! gui_clear (I,J) || fail; // falls through to below ! otherwise: = qt TABLE "clearCell" (I,J) if not has_table_item (I,J); = cell_setval (I,J) Y *************** *** 1210,1219 **** gui_update X (I,J) _ ! where (I,J) = real_index (I,J), (CC|_) = qt_mob_data X if is_global and then not is_recursive and then not is_nil X: = if (I,J)<>real_current_cell then set_current_cell (I,J) || ! if CC = "MyTaskButton" then ! send_expr '(yytask (I,J) ~(qt X "isOn" ())) || process_gui2 (I,J) X || digest_loop; --- 1214,1222 ---- gui_update X (I,J) _ ! where (I,J) = real_index (I,J) if is_global and then not is_recursive and then not is_nil X: = if (I,J)<>real_current_cell then set_current_cell (I,J) || ! gui_action X (I,J) || process_gui2 (I,J) X || digest_loop; *************** *** 2454,2457 **** --- 2457,2483 ---- ICONSET = qt_new "QIconSet" PM; + actionbutton_gui (I,J) () (TEXT,ICON) + = qt_connect X (SIGNAL "clicked()") X (SLOT "guiUpdate()") || + qt TABLE "setCellWidget" (I,J,X) || IT + if not is_nil IT and then not is_nil X + where ICONSET = + if null ICON then () + else qt_new "QIconSet" $ qt_new "QPixmap" ICON, + X:QtObject = qt_object "QPushButton" + (if is_qt_object ICONSET then (ICONSET,TEXT,TABLE) + else (TEXT,TABLE)) + "MyActionButton" (I,J) [] + // slots + [("guiUpdate()",gui_update)] [], + IT:QtObject = make_table_item (I,J,X,ref ()) + (qt_val "QTableItem" "Never"); + + actionbutton_gui (I,J) X:QtObject (TEXT,ICON) + = qt X "setText" TEXT || qt X "setIconSet" ICONSET + where PM = + if null ICON then NULLPM + else qt_new "QPixmap" ICON, + ICONSET = qt_new "QIconSet" PM; + togglebutton_gui (I,J) () (TEXT,ICON,INIT) = qt X "setToggleButton" true || *************** *** 2571,2613 **** fval MIN STEP S = round ((V-MIN)/STEP) where V:Num = val S; ! /* Get the "type" (denoted by the creation/update function) of a GUI ! element. */ ! gui_gettype X ! where C:String = class_name X: ! = checkbox_gui ! if C = "QCheckTableItem"; ! = if qt X "isEditable" () then comboedit_gui ! else combobox_gui ! if C = "QComboTableItem"; ! = spinbox_gui ! if C = "QSpinBox"; ! = slider_gui ! if C = "QSlider"; ! = if CC = "MyTaskButton" then taskbutton_gui ! else if qt X "isToggleButton" () then togglebutton_gui ! else pushbutton_gui ! where (CC|_) = qt_mob_data X ! if C = "QPushButton"; ! // = printf "unknown GUI element %s\n" C || fail otherwise; /* Get the value of a GUI element. */ ! gui_getval X ! where C:String = class_name X: ! = qt X "isChecked" () ! if C = "QCheckTableItem"; ! = qt X "currentText" () ! if C = "QComboTableItem"; ! = spinbox_value $ qt X "cleanText" () ! if C = "QSpinBox"; ! = qt X "value" () ! if C = "QSlider"; ! = qt X "isOn" () ! if (C = "QPushButton") and then qt X "isToggleButton" (); ! = qt X "isDown" () ! if C = "QPushButton"; ! = //printf "unknown GUI element %s\n" C || ! 0 otherwise; // default value spinbox_value S = X if checknum 'X where 'X = valq S; --- 2597,2657 ---- fval MIN STEP S = round ((V-MIN)/STEP) where V:Num = val S; ! /* Table of GUI elements with the corresponding creation/update, getter and ! setter functions. */ ! def GUI_TYPES = dict ! ["MyCheckBox", (checkbox_gui,gui_get_checkbox,gui_set_checkbox); ! "MyComboBox", (combobox_gui,gui_get_combobox,gui_set_combobox); ! "MyComboEdit", (comboedit_gui,gui_get_combobox,gui_set_combobox); ! "MySpinBox", (spinbox_gui,gui_get_spinbox,gui_set_spinbox); ! "MySlider", (slider_gui,gui_get_slider,gui_set_slider); ! "MyPushButton", (pushbutton_gui,gui_get_pushbutton,()); ! "MyToggleButton", (togglebutton_gui,gui_get_togglebutton, ! gui_set_togglebutton); ! "MyTaskButton", (taskbutton_gui,gui_get_togglebutton, ! gui_set_taskbutton); ! "MyActionButton", (actionbutton_gui,gui_get_actionbutton, ! gui_set_actionbutton);]; ! ! /* Get our class name for a GUI element. Note that the checkbox and combobox ! elements are actually implemented as special QTableItems which are *not* ! widgets (not even QObjects) and so the meta object is not available; we ! handle those cases manually. */ ! ! gui_class X = C where (C|_) = qt_mob_data X; ! = "MyCheckBox" if class_name X = "QCheckTableItem"; ! = if qt X "isEditable" () then "MyComboEdit" ! else "MyComboBox" ! if class_name X = "QComboTableItem"; ! ! gui_gettype X = F where C:String = gui_class X, (F|_) = GUI_TYPES!C; ! // = printf "unknown GUI element %s\n" (class_name X) || fail otherwise; /* Get the value of a GUI element. */ ! gui_getval X = GV X where C:String = gui_class X, (_,GV,_) = GUI_TYPES!C; ! // = printf "unknown GUI element %s\n" (class_name X) || 0; ! = 0 otherwise; // default value ! ! gui_get_checkbox X ! = qt X "isChecked" (); ! ! gui_get_combobox X ! = qt X "currentText" (); ! ! gui_get_pushbutton X ! = qt X "isDown" (); ! ! gui_get_actionbutton X ! = get Y where (I,J) = qt_data X, (Y,) = gui_data (I,J); ! ! gui_get_togglebutton X ! = qt X "isOn" (); ! ! gui_get_spinbox X ! = spinbox_value $ qt X "cleanText" (); ! ! gui_get_slider X ! = qt X "value" (); spinbox_value S = X if checknum 'X where 'X = valq S; *************** *** 2616,2624 **** /* Set the value of a GUI element from a string. */ ! gui_setval X S ! where C:String = class_name X: = qt X "setChecked" Y ! if checkbool 'Y where 'Y = valq S ! if C = "QCheckTableItem"; = if all (<>S) L then (qt X "setStringList" $ append L S || --- 2660,2670 ---- /* Set the value of a GUI element from a string. */ ! gui_setval X S = SV X S where C:String = gui_class X, (_,_,SV) = GUI_TYPES!C; ! ! gui_set_checkbox X S = qt X "setChecked" Y ! if checkbool 'Y where 'Y = valq S; ! ! gui_set_combobox X S = if all (<>S) L then (qt X "setStringList" $ append L S || *************** *** 2626,2640 **** else qt X "setCurrentItem" S ! where S = Y, ! N = qt X "count" (), L = map (qt X "text") [0..N-1] if checkstr 'Y where 'Y = valq S ! if (C = "QComboTableItem") and then ! qt X "isEditable" (); = qt X "setCurrentItem" S if any (=S) L ! where S = Y, ! N = qt X "count" (), L = map (qt X "text") [0..N-1] if checkstr 'Y where 'Y = valq S ! if C = "QComboTableItem"; = if Y<>Y0 then qt X "setValue" Y where Y0 = qt X "value" (), --- 2672,2704 ---- else qt X "setCurrentItem" S ! where S = Y, N = qt X "count" (), ! L = map (qt X "text") [0..N-1] if checkstr 'Y where 'Y = valq S ! if qt X "isEditable" (); = qt X "setCurrentItem" S if any (=S) L ! where S = Y, N = qt X "count" (), ! L = map (qt X "text") [0..N-1] if checkstr 'Y where 'Y = valq S ! otherwise; ! ! gui_set_actionbutton X S ! = Y := Z ! where (I,J) = qt_data X, (Y,) = gui_data (I,J), ! 'Z = valq S, Z = catch fail Z; ! ! gui_set_togglebutton X S ! = qt X "setOn" Y ! if checkbool 'Y where 'Y = valq S; ! ! gui_set_taskbutton X S ! = if checkstr 'Y then ! qt X "setText" Y ! else if checkbool 'Y then ! qt X "setOn" Y ! else fail ! where 'Y = valq S; ! ! gui_set_spinbox X S = if Y<>Y0 then qt X "setValue" Y where Y0 = qt X "value" (), *************** *** 2643,2648 **** STEP = qt X "lineStep" (), Y = min MAX $ (Y-MIN) div STEP*STEP+MIN ! where Y:Int = make_spinbox_value X S ! if C = "QSpinBox"; = if Y<>Y0 then qt X "setValue" Y where Y0 = qt X "value" (), --- 2707,2713 ---- STEP = qt X "lineStep" (), Y = min MAX $ (Y-MIN) div STEP*STEP+MIN ! where Y:Int = make_spinbox_value X S; ! ! gui_set_slider X S = if Y<>Y0 then qt X "setValue" Y where Y0 = qt X "value" (), *************** *** 2650,2668 **** MAX = qt X "maxValue" (), Y = (min MAX.max MIN) (round Y) ! if checknum 'Y where 'Y = valq S ! if C = "QSlider"; ! = if checkstr 'Y then ! qt X "setText" Y ! else if checkbool 'Y then ! qt X "setOn" Y ! // else printf "bad value %s for GUI element %s\n" (str S,C) ! where ("MyTaskButton"|_) = qt_mob_data X, 'Y = valq S ! if (C = "QPushButton") and then qt X "isToggleButton" (); ! = qt X "setOn" Y ! if checkbool 'Y where 'Y = valq S ! if (C = "QPushButton") and then qt X "isToggleButton" (); ! = () if C = "QPushButton"; ! // = printf "bad value %s for GUI element %s\n" (str S,C); ! = () otherwise; // Convert a spinbox value; use the special value text and the text->value --- 2715,2719 ---- MAX = qt X "maxValue" (), Y = (min MAX.max MIN) (round Y) ! if checknum 'Y where 'Y = valq S; // Convert a spinbox value; use the special value text and the text->value *************** *** 2679,2683 **** gui_enter (I,J) X ! where C:String = class_name X: = // enter a new item in an editable combobox if all (<>S) L then --- 2730,2734 ---- gui_enter (I,J) X ! where C:String = gui_class X: = // enter a new item in an editable combobox if all (<>S) L then *************** *** 2688,2693 **** where S = qt X "currentText" (), N = qt X "count" (), L = map (qt X "text") [0..N-1] ! if (C = "QComboTableItem") and then ! qt X "isEditable" (); = // confine the value to the given range and step size if Y<>Y0 then recursive (qt X "setValue" Y) || --- 2739,2743 ---- where S = qt X "currentText" (), N = qt X "count" (), L = map (qt X "text") [0..N-1] ! if C = "MyComboEdit"; = // confine the value to the given range and step size if Y<>Y0 then recursive (qt X "setValue" Y) || *************** *** 2698,2702 **** STEP = qt X "lineStep" (), Y = min MAX $ (Y0-MIN) div STEP*STEP+MIN ! if C = "QSpinBox"; /* Undo/redo. **************************************************************/ --- 2748,2771 ---- STEP = qt X "lineStep" (), Y = min MAX $ (Y0-MIN) div STEP*STEP+MIN ! if C = "MySpinBox"; ! ! /* Special actions on GUI elements. */ ! ! private yyeval KEY X, yyset KEY X, yyclear X, yyval KEY, yytask KEY MSG, ! yyaction KEY, yyclearaction KEY; ! ! gui_action X (I,J) ! where C:String = gui_class X: ! = send_expr '(yytask (I,J) ~(qt X "isOn" ())) ! if C = "MyTaskButton"; ! = send_expr '(yyaction (I,J)) ! if C = "MyActionButton"; ! ! gui_clear X (I,J) ! where C:String = gui_class X: ! = send_expr '(yytask (I,J) ()) ! if C = "MyTaskButton"; ! = send_expr '(yyclearaction (I,J)) ! if C = "MyActionButton"; /* Undo/redo. **************************************************************/ *************** *** 3109,3114 **** and the executing script). */ - private yyeval KEY X, yyset KEY X, yyclear X, yyval KEY, yytask KEY MSG; - parse S = 'X where --- 3178,3181 ---- *************** *** 3286,3289 **** --- 3353,3363 ---- = results_loop (insert U ((I1,J1),IT)) [(I,J)|V] where [(K1,S1)] = regex "" + "^\\+\\+\\+ Actionbutton: (\\([0-9]+,[0-9]+\\)) (.*)$" S + (reg 1,reg 2), + (I1,J1) = val K1, (TEXT,ICON) = val S1, + IT:QtObject = make_gui actionbutton_gui (I1,J1) + (TEXT,ICON); + = results_loop (insert U ((I1,J1),IT)) [(I,J)|V] + where [(K1,S1)] = regex "" "^\\+\\+\\+ Togglebutton: (\\([0-9]+,[0-9]+\\)) (.*)$" S (reg 1,reg 2), |