void SetDummyLabel(Container c, string section, string text) { Label lbl = new Label(); lbl.Markup = small ? "<span color=\"#FF6600\"><b><big><big>" + text + "</big></big></b></span>" : "<i>" + text + "</i>"; lbl.SetPadding(5, 5); MiscHelpers.AddToContainer(c, lbl, small); // Setup appropiate DragDest DragDropHelpers.DestSet(lbl, DestDefaults.All, DragDropHelpers.TgtFromString(section), Gdk.DragAction.Move); // correctly count the number of "real" widgets in // container, since their might be some more // widgets for layouting in it (in small mode for example) int index = 0; foreach (Widget w in c) { if (w is IDragDropWidget) { index++; } } lbl.DragDataReceived += delegate(object o, DragDataReceivedArgs args) { object data = DragDropHelpers.Deserialize(args.SelectionData); // save data here SetItem(section, index, data); // delete data there MyButton b = (MyButton)Drag.GetSourceWidget(args.Context); b.Owner.SetData(null); }; }
void SetupTeamRow(Container c, object data, int i) { if (i > 8) { // a team is easy Team t = new Team((TeamData)data); MiscHelpers.AddToContainer(c, t); dataWidgets.Add(t); } else { DebaterWidget dw = new DebaterWidget((RoundDebater)data); dataWidgets.Add(dw); if (dw.HasResult) { results.Add(dw.Debater. GetRoundResult(roomData.RoundName, i, roomData.Judges.Count)); } else { results.Add(null); } uint type = RoundResultData.PosToRoleType[i]; if (type != (uint)RoundResultData.RoleType.Free) { string section = type == 0 ? "OnlyGov" : "OnlyOpp"; // Setup Drag Drop dw.SetupDragDropSource(section, i); // Container ATTACH MiscHelpers.AddToContainer(c, dw); // DragDrop DEST DragDropHelpers.DestSet(dw, DestDefaults.All, DragDropHelpers.TgtFromString(section), Gdk.DragAction.Move); dw.DragDataReceived += delegate(object s, DragDataReceivedArgs args) { int j = (int)DragDropHelpers.Deserialize(args.SelectionData); // Swap Rows SwapTableRows(debaterRows[results[i].GetPosition()], debaterRows[results[j].GetPosition()]); // backswap the labels of the frames... SwapSpeakerFrameLabels(i, j); // save this in results int tmp = results[i].Index; results[i].Index = results[j].Index; results[j].Index = tmp; // update infos dataWidgets[i].UpdateInfo(); dataWidgets[j].UpdateInfo(); }; } else { MiscHelpers.AddToContainer(c, dw); } } }
// FIRST : SourceSet // SECOND : Add IDragDropWidget to container // THIRD : DestSet and DragDataReceived public static void SetupDragDropSourceButton(MyButton btn, string t, object data) { if (btn == null) { return; } Drag.SourceSet(btn, Gdk.ModifierType.Button1Mask, TgtFromString(t), Gdk.DragAction.Move); btn.DragDataGet += delegate(object o, DragDataGetArgs args_) { // save after drag & drop Tournament.I.Save(); DragDropHelpers.Serialize(args_.SelectionData, data); }; }
void SetDragDestToAllWidgets() { DragDropHelpers.ApplyToWidget(notebookDragDrop, delegate(Widget w) { Drag.DestSet(w, DestDefaults.Motion | DestDefaults.Drop, DragDropHelpers.TgtAll, Gdk.DragAction.Move); w.DragDataReceived += delegate(object o, DragDataReceivedArgs args) { // first delete MyButton b = (MyButton)Drag.GetSourceWidget(args.Context); b.Owner.SetData(null); // then set... object data = DragDropHelpers.Deserialize(args.SelectionData); SetItem(data); }; }); }
void UpdateGuiSection(string section, int i, object data) { Container c = (Container)GetField("c" + section); if (data == null) { SetDummyLabel(c, section); } else if (data is List <RoundDebater> ) { // Judges or FreeSpeakers (variable number...) MiscHelpers.ClearContainer(c); List <RoundDebater> list = (List <RoundDebater>)data; if (list.Count == 0) { SetDummyLabel(c, section); } else { for (int j = 0; j < list.Count; j++) { UpdateGuiSection(section, j, list[j]); } // append label for adding by D&D if (small) { if (section == "Judges") { SetDummyLabel(c, section, roomData.Judges.Count.ToString()); } else if (section == "FreeSpeakers" && list.Count < 3) { SetDummyLabel(c, section, "F"); } } else if (section == "Judges" || list.Count < 3) { SetDummyLabel(c, section, "Drag here to add"); } } } else { IDragDropWidget w = null; if (data is TeamData) { if (small) { w = Team.Small((TeamData)data); } else { w = new Team((TeamData)data, null); } } else if (data is RoundDebater) { if (small) { w = DebaterWidget.Small((RoundDebater)data, false); } else { w = new DebaterWidget((RoundDebater)data); } } else { throw new NotImplementedException("Don't know how to create widget for data"); } // tell Debater the room for visitedRooms list.. w.SetRoom(roomData.RoundName, roomData); w.SetupDragDropSource(section, data); w.SetDataTrigger += delegate(Widget sender, object data_) { SetItem(section, i, data_); }; // Add to container after source, but before Dest Widget wi = (Widget)w; MiscHelpers.AddToContainer(c, wi, small); // Drag drop DestSet, needs Container for scrolling support... DragDropHelpers.DestSet(wi, DestDefaults.All, DragDropHelpers.TgtFromString(section), Gdk.DragAction.Move); wi.DragDataReceived += delegate(object o, DragDataReceivedArgs args) { object data_ = DragDropHelpers.Deserialize(args.SelectionData); // save data here SetItem(section, i, data_); // delete data there MyButton b = (MyButton)Drag.GetSourceWidget(args.Context); b.Owner.SetData(data); }; } // show judge quality by icons if (section == "Judges" && !small) { int nStars = 0; double sumAvgSpkr = 0.0; double sumAvgTeam = 0.0; int nAvgSpkr = 0; int nAvgTeam = 0; foreach (RoundDebater rd in roomData.Judges) { Debater d = Tournament.I.FindDebater(rd); if (d == null) { continue; } nStars += d.Role.JudgeQuality; if (!double.IsNaN(d.StatsAvg[0])) { sumAvgSpkr += d.StatsAvg[0]; nAvgSpkr++; } if (!double.IsNaN(d.StatsAvg[2])) { sumAvgTeam += d.StatsAvg[2]; nAvgTeam++; } } lblJudgeStats.Markup = "JudgeStats: " + JudgeStatsToMarkup(sumAvgSpkr, nAvgSpkr, 2) + " " + JudgeStatsToMarkup(sumAvgTeam, nAvgTeam, 5); MiscHelpers.ClearTable(tableJudgeStars); tableJudgeStars.NRows = (uint)nStars / 5 + 1; for (int j = 0; j < nStars; j++) { uint col = (uint)j % 5; uint row = (uint)j / 5; tableJudgeStars.Attach(new Image(MiscHelpers.LoadIcon("face-smile")), col, col + 1, row, row + 1, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0); } if (nStars == 0) { tableJudgeStars.HideAll(); } else { tableJudgeStars.ShowAll(); } } }
public void SetupDragDropSource(string t, object data) { DragDropHelpers.SetupDragDropSourceButton(btnExpand, t, data); }
void SetupJudgeColumn(int i) { // Setup small DebaterWidget (keep colsize small...) DebaterWidget dw = DebaterWidget.Small(roomData.Judges[(int)i], false); // add to results, nJudges doesnt matter for judges resultsJudges.Add(dw.Debater.GetRoundResult(roomData.RoundName, i, -1)); dataWidgets.Add(dw); // default position uint pos = (uint)(i + judgesOffset); // THE FOLLOWING ORDER FOR DRAG DROP IS IMPORTANT, see DragDropHelpers // DragDrop SOURCE // we send always the fixed index i if (roomData.Judges.Count > 1) { dw.SetupDragDropSource("Judge", i); } //DragDropHelpers.SourceSet(dw, "Judge", i); // Container ATTACH table.Attach(dw, pos, pos + 1, 0, 1, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0); // DragDrop DEST if (roomData.Judges.Count > 1) { DragDropHelpers.DestSet(dw, DestDefaults.All, DragDropHelpers.TgtFromString("Judge"), Gdk.DragAction.Move); dw.DragDataReceived += delegate(object o, DragDataReceivedArgs args) { int j = (int)DragDropHelpers.Deserialize(args.SelectionData); // Swap Columns SwapTableCols((uint)(resultsJudges[i].Index + judgesOffset), (uint)(resultsJudges[j].Index + judgesOffset)); // save this in results int tmp = resultsJudges[i].Index; resultsJudges[i].Index = resultsJudges[j].Index; resultsJudges[j].Index = tmp; // update infos dataWidgets[i + 11].UpdateInfo(); dataWidgets[j + 11].UpdateInfo(); }; } // Setup Spinbuttons int k = 0; foreach (uint row in debaterRows) { Alignment al = null; if (dataWidgets[k].HasResult) { // k denotes speaker position // k=9, k=10 are team points // i denotes judgeIndex MySpinButton sb = k < 9 ? SetupSbSpeaker(i, k) : SetupSbTeam(i, k); // spinbuttons are parents for avg labels.. labels[k].AddParent(sb); // nice alignment al = new Alignment(0f, 0f, 1f, 1f); al.LeftPadding = 6; al.RightPadding = 6; al.Add(sb); } table.Attach(MiscHelpers.MakeBackground(al, colBg[RoundResultData.PosToRoleType[k]]), pos, pos + 1, row, row + 1, AttachOptions.Fill, AttachOptions.Fill, 0, 0); k++; } }