File: hotkeyTable.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 239,928 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (236 lines) | stat: -rw-r--r-- 6,514 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include <BALL/VIEW/WIDGETS/hotkeyTable.h>

namespace BALL
{
	namespace VIEW
	{
		HotkeyTable::HotkeyTable(QWidget* parent,  const char*)
			: QTableWidget(parent),
			  delegate_(this)
		{
			setItemDelegate(&delegate_);

			setColumnCount(4);
			setHorizontalHeaderItem(0, new QTableWidgetItem());
			setHorizontalHeaderItem(1, new QTableWidgetItem());
			setHorizontalHeaderItem(2, new QTableWidgetItem());
			setHorizontalHeaderItem(3, new QTableWidgetItem());
			horizontalHeaderItem(0)->setText("Modifier");
			horizontalHeaderItem(1)->setText("Key");
			horizontalHeaderItem(2)->setText("Command");
			horizontalHeaderItem(3)->setText("Comment");

			setRowCount(0);
			setShowGrid(true);

			//setColumnWidth(0, 90);
			//setColumnWidth(1, 60);
			//setColumnWidth(2, 214);
			//setColumnWidth(3, 200);
			//setGeometry(2,2, 610, 342);

			setSelectionBehavior(QAbstractItemView::SelectRows);
			setSelectionMode(QAbstractItemView::SingleSelection);

			setObjectName("PythonHotkeys");

			modifier_ << "" << "Shift";// << "Alt";

			for (Position p = 2; p < 13; p++)
			{
				keys_ << (String("F") + String(p)).c_str();
			}

			// F2 -> runCurrentScript()
			appendHotkey("None", "F2", "runCurrentScript()", "Run current Python script");

			// F3 -> hideAllRepresentations()
			appendHotkey("None", "F3", "hideAllRepresentations()", "Hide all loaded representations");

			// F4 -> removeWater()
			appendHotkey("None", "F4", "removeWater()", "Delete all water molecules");

			// S-F4 -> randomizeAtoms()
			appendHotkey("Shift", "F4", "randomizeAtoms(0.2)", "Randomize all atom positions by max 0.2 A");

			// F5 -> printAtomTypesForHighlighted()
			appendHotkey("None", "F5", "printAtomTypesForHighlighted()",
									 "Print the atom types for the currently highlighted molecular items");

			// S-F5 -> printAtomTypesForLigands()
			appendHotkey("Shift", "F5", "printAtomTypesForLigands()",
									 "Print the atom types for all ligands");

			// F6 -> showCartoonAndLigand()
			appendHotkey("None", "F6", "highlightLigand()",
									 "Highlight the ligand in the molecular control");

			// S-F6 -> showCartoonAndLigand()
			appendHotkey("Shift", "F6", "showCartoonAndLigand()",
									 "Create VDW for all ligands and a cartoon model for the receptor");

			// F7 -> addOptimizedHydrogens()
			appendHotkey("None", "F7", "addOptimizedHydrogens()",
									 "Add hydrogens through FragmentDB and optimize them");

			// S-F7 -> relaxStructure()
			appendHotkey("Shift", "F7", "relaxStructure()",
									 "Quickly optimize a ligand");

			// F8 -> quickSave()
			appendHotkey("None", "F8", "quickSave()",
									 "Quickly store a project file");

			// S-F8 -> quickLoad()
			appendHotkey("Shift", "F8", "quickLoad()",
									 "Quickly load a project file");

			// F12 -> clearRepresentations()
			appendHotkey("None", "F12", "clearRepresentations()",
									 "Delete all loaded representations");

			// S-F12 -> clearAll()
			appendHotkey("Shift", "F12", "clearAll()",
									 "Delete all molecules and representations");
		}

		void HotkeyTable::appendHotkey(const String& mod, const String& F_key,
																	 const String& command, String comment)
		{
			addEmptyRow();
			Index r = rowCount() - 1;

			item(r, 0)->setText(mod.c_str());
			item(r, 1)->setText(F_key.c_str());
			item(r, 2)->setText(command.c_str());
			item(r, 3)->setText(comment.c_str());
			scrollToBottom();
		}

		list<Hotkey> HotkeyTable::getContent() const
		{
			list<Hotkey> result;
			for (Index pos = 0; pos < rowCount(); pos++)
			{
				if (item(pos, 2)->text().isEmpty())
				{
					Log.error() << "Problem reading content of PythonHotkeys" << std::endl;
					continue;
				}

				bool ok;
				Hotkey hotkey = Hotkey::createHotkey(ascii(item(pos, 0)->text()),
																						 ascii(item(pos, 1)->text()),
																						 ascii(item(pos, 2)->text()),
																						 ok,
																						 ascii(item(pos, 3)->text()));
				if (!ok)
				{
					Log.error() << "Problem reading content of PythonHotkeys" << std::endl;
					return result;
				}

				result.push_back(hotkey);
			}

			return result;
		}


		void HotkeyTable::setContent(const list<Hotkey>& hotkeys)
		{
			setRowCount(hotkeys.size());
			setColumnWidth(2, 230);

			list<Hotkey>::const_iterator it = hotkeys.begin();
			Position p = 0;
			for (; it != hotkeys.end(); it++)
			{
				String s;
				QStringList sl;
				switch ((Position)(*it).button_state)
				{
					case (Position)Qt::NoButton:        s = "None"; break;
					case (Position)Qt::ShiftModifier:   s = "Shift"; break;
					case (Position)Qt::ControlModifier: s = "Ctrl"; break;
					default:
						Log.error() << "Invalid button state for Hotkey" << std::endl;
						return;
				}

				setItem(p, 0, new QTableWidgetItem(s.c_str()));

				Position k = (*it).key - Qt::Key_F1 + 1;
				s = String("F") + String(k);
				setItem(p,1, new QTableWidgetItem(s.c_str()));
				setItem(p,2, new QTableWidgetItem((*it).action.c_str()));
				setItem(p,3, new QTableWidgetItem((*it).comment.c_str()));

				p++;
			}
		}

		void HotkeyTable::addEmptyRow()
		{
			Position p = rowCount();
			insertRow(p);
			scrollToBottom();
			setItem(p, 0, new QTableWidgetItem());
			setItem(p, 1, new QTableWidgetItem());
			setItem(p, 2, new QTableWidgetItem());
			setItem(p, 3, new QTableWidgetItem());
			item(p, 0)->setText("None");
			item(p, 1)->setText("F2");
			item(p, 2)->setText("");
			item(p, 3)->setText("");
			Q_EMIT cellActivated(p, 2);
		}

		void HotkeyTable::removeSelection()
		{
			QList<QTableWidgetSelectionRange> l = QTableWidget::selectedRanges();
			if (l.size() == 0) return;

			removeRow((*l.begin()).bottomRow());
		}

		bool HotkeyTable::getValue(String& value) const
		{
			value = "";
			for (Position p = 0; p < (Position)rowCount(); p++)
			{
				value += ascii(item(p, 0)->text()) + "°";
				value += ascii(item(p, 1)->text()) + "°";
				value += ascii(item(p, 2)->text()) + "°";
				value += ascii(item(p, 3)->text()) + "°";
				value += '@';
			}
			return true;
		}

		bool HotkeyTable::setValue(const String& value)
		{
			setRowCount(0);

			vector<String> fields;
			vector<String> fields2;
			Size nr = value.split(fields, "@");

			for (Position p = 0; p < nr; p ++)
			{
				Size nr2 = fields[p].split(fields2, "°");
				if (nr2 < 3)
				{
		//   			BALLVIEW_DEBUG;
					continue;
				}

				fields2.resize(4);

				appendHotkey(fields2[0], fields2[1], fields2[2], fields2[3]);
			}

			return true;
		}
	}
}