Debian Codegraph @

dragdropatomsdlg.cpp

raw symbols SCIP
1 #include "dragdropatomsdlg.h"
2 #include <QDialogButtonBox>
3 #include <QHBoxLayout>
4 #include <QLineEdit>
5 DragDropAtomsDialog::DragDropAtomsDialog(ChGL *gl, Molecule &mole, const QList<int> &reference, QList<int> *target, QWidget *parent)
6 :QDialog(parent){
7 chgl=gl;
8 DragDropAtoms *dda = new DragDropAtoms(mole,reference,target,parent);
9 QScrollArea *qsa = new QScrollArea();
10 qsa->setWidget(dda);
11 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
12 ok = buttonBox->button(QDialogButtonBox::Ok);
13
14 ok->setDisabled(true);
15 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
16 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
17 QLabel *usageHint = new QLabel();
18 usageHint->setText("<h1>Inherit labels assigning dialog</h1> <ul><li>If you click on OK here, then atoms on the<br>"
19 " right column will inherit their Labels from<br> the atoms given in the left column.</li>"
20 "<li> You can change the ordering of the right<br> column by drag and drop of its items.</li>"
21 "<li> If you click on the items on the left column<br> the atoms in the structure will<br> be <em>highlighted</em>.</li>"
22 "<li> You <em>MUST</em> assingn a new <em>ResidueNr</em> and an<br> appropriate <em>Residue Class</em> here!</ul>");
23 usageHint->setStyleSheet (QString(
24 "QLabel{font: bold; background-color:#ffffaa;}"));
25 QHBoxLayout *la = new QHBoxLayout();
26 setWindowTitle(tr("Inherit labels assigning dialog"));
27 QLabel *resiNrSpinL = new QLabel("Residue Nr:");
28 resiNrSpin = new QSpinBox();
29 resiNrSpin->setMinimum(0);
30 resiNrSpin->setMaximum(9999);
31 resiNrSpin->setValue(0);
32 //connect(resiNrSpin,SIGNAL(valueChanged(int)),this,SLOT(updateLabel()));
33 connect(resiNrSpin,SIGNAL(valueChanged(int)),this,SLOT(renameRNchanged(int)));
34 QLabel *resiResiClassL = new QLabel("Residue Class:");
35 resiResiClass = new QLineEdit("");
36 resiResiClass->setMaxLength(4);
37 resiResiClass->setValidator(new QRegularExpressionValidator(QRegularExpression("^[A-Za-z]\\w{0,3}"),resiResiClass));
38 resiResiClass->setMinimumWidth(100);
39 connect(resiResiClass,SIGNAL(textEdited(const QString&)),this,SLOT(grossRC(const QString&)));
40 resiResiClass->setEnabled(false);
41 QHBoxLayout *rhla = new QHBoxLayout();
42 rhla->addWidget(resiNrSpinL);
43 rhla->addWidget(resiNrSpin);
44 rhla->addWidget(resiResiClassL);
45 rhla->addWidget(resiResiClass);
46 zoomIn = new QToolButton (this);
47 zoomIn-> setIcon(QIcon(chgl->theIconPath+"zoom-in.svg"));
48 zoomIn->setShortcut(QKeySequence(Qt::ALT | Qt::Key_PageUp));
49 zoomIn->setText("Zoom +");
50 zoomIn->setToolTip("Zoom +");
51 zoomIn->setAutoRepeat(true);
52 zoomIn->setAutoRepeatDelay(150);
53 zoomIn->setAutoRepeatInterval(3);
54 zoomOut = new QToolButton(this);
55 zoomOut->setShortcut(QKeySequence(Qt::ALT | Qt::Key_PageDown));
56 zoomOut->setIcon(QIcon(chgl->theIconPath+"zoom-out.svg"));
57 zoomOut->setText("Zoom -");
58 zoomOut->setToolTip("Zoom -");
59 zoomOut->setAutoRepeat(true);
60 zoomOut->setAutoRepeatDelay(150);
61 zoomOut->setAutoRepeatInterval(3);
62
63
64 rotLeft = new QToolButton(this);
65 rotLeft->setIcon(QIcon(chgl->theIconPath+"moveleft.svg"));
66 rotLeft->setText("rotate couter clock wise");
67 rotLeft->setShortcut(QKeySequence(Qt::ALT | Qt::Key_Left));
68 rotLeft->setToolTip("rotate couter clock wise");
69 rotLeft->setAutoRepeat(true);
70 rotLeft->setAutoRepeatDelay(50);
71 rotLeft->setAutoRepeatInterval(3);
72
73
74 rotRight = new QToolButton(this);
75 rotRight->setIcon(QIcon(chgl->theIconPath+"moveright.svg"));
76 rotRight->setText("rotate clock wise");
77 rotRight->setToolTip("rotate clock wise");
78 rotRight->setShortcut(QKeySequence(Qt::ALT | Qt::Key_Right));
79 rotRight->setAutoRepeat(true);
80 rotRight->setAutoRepeatDelay(50);
81 rotRight->setAutoRepeatInterval(3);
82
83 rotUp = new QToolButton(this);
84 rotUp->setShortcut(QKeySequence(Qt::ALT | Qt::Key_Up));
85
86 rotUp->setAutoRepeatDelay(50);
87 rotUp->setAutoRepeat(true);
88 rotUp->setAutoRepeatInterval(3);
89 rotDown = new QToolButton(this);
90 rotDown->setShortcut(QKeySequence(Qt::ALT | Qt::Key_Down));
91 rotDown->setAutoRepeatDelay(50);
92 rotDown->setAutoRepeat(true);
93 rotDown->setAutoRepeatInterval(3);
94
95 connect(zoomIn,SIGNAL(pressed ()),this,SLOT(zoomin()));
96 connect(zoomOut,SIGNAL(pressed ()),this,SLOT(zoomout()));
97 connect(rotRight,SIGNAL(pressed ()),this,SLOT(rotr()));
98 connect(rotLeft,SIGNAL(pressed ()),this,SLOT(rotl()));
99 connect(rotUp,SIGNAL(pressed ()),this,SLOT(rotu()));
100 connect(rotDown,SIGNAL(pressed ()),this,SLOT(rotd()));
101
102 QGridLayout *mola = new QGridLayout();
103 mola->addWidget(zoomIn,1,1);
104 mola->addWidget(zoomOut,0,0);
105 mola->addWidget(rotLeft,1,0);
106 mola->addWidget(rotRight,1,2);
107 mola->addWidget(rotUp,0,1);
108 mola->addWidget(rotDown,2,1);
109 QPixmap up = QPixmap(chgl->theIconPath+"moveright.svg");
110 QTransform transform;
111 QTransform t90 = transform.rotate(-90);
112 QTransform t270 = transform.rotate(180);
113 rotUp->setIcon(up.transformed(t90));
114 rotDown->setIcon(up.transformed(t270));
115 QVBoxLayout *lo = new QVBoxLayout();
116 la->addWidget(qsa);
117 la->addWidget(usageHint);
118 lo->addLayout(la);
119 lo->addLayout(rhla);
120 rhla->addLayout(mola);
121 lo->addWidget(buttonBox);
122 setLayout(lo);
123 setMinimumWidth(190+usageHint->sizeHint().width());
124 connect(dda,SIGNAL(pairs(QString)),this,SIGNAL(pairs(QString)));
125 }
126
127 void DragDropAtomsDialog::grossRC(const QString &text){
128 QString s=text.toUpper ();
129 resiResiClass->setText(s);
130 update();
131 }
132
133 void DragDropAtomsDialog::renameRNchanged(int ii){
134 QMap<int,QString> resNrClass;
135 for (int i=0; i<resiFinder->count(); i++){
136 QString resil=resiFinder->itemText(i).toUpper();
137 resil.remove(QRegularExpression("^RESI"));
138 QString resinr=resil;
139 resil.remove(QRegularExpression("\\b\\d+\\b"));
140 resinr.remove(resil.trimmed());
141 int rn=resinr.trimmed().toInt();
142 resNrClass[rn]=resil.trimmed();
143 }
144 if (!ii) {
145 resiResiClass->setEnabled(false);
146 ok->setDisabled(true);
147 resiResiClass->setText("");
148 }
149 else {
150 resiResiClass->setDisabled(resNrClass.contains(ii));
151 ok->setDisabled(resNrClass.contains(ii));
152 resiResiClass->setText(resNrClass[ii]);
153 }
154
155 }
156
157 void DragDropAtomsDialog::zoomin(){
158 chgl->zoom(0.1);
159 chgl->update();
160 }
161
162 void DragDropAtomsDialog::zoomout(){
163 chgl->zoom(-0.1);
164 chgl->update();
165 }
166
167 void DragDropAtomsDialog::rotr(){
168 chgl->rotY(-0.05);
169 chgl->update();
170 }
171
172 void DragDropAtomsDialog::rotl(){
173 chgl->rotY(0.05);
174 chgl->update();
175 }
176
177 void DragDropAtomsDialog::rotu(){
178 chgl->rotX(0.05);
179 chgl->update();
180 }
181
182 void DragDropAtomsDialog::rotd(){
183 chgl->rotX(-0.05);
184 chgl->update();
185 }
186
187 DragDropAtoms::DragDropAtoms(Molecule &mole, const QList<int> &reference, QList<int> *target, QWidget *parent)
188 :QWidget(parent){
189 m_mole = mole;
190 m_reference = reference;
191 m_target = target;
192
193 // setMouseTracking(true);
194 int x = 5;
195 int y = 5;
196 dadas.clear();
197 //printf("%d %d \n",reference.size(),target.size());
198 for (int i=0; i<target->size(); i++){
199 int j=target->at(i);
200 int k=reference.at(i);
201 dadas.append(QString("%1 %2").arg(k).arg(j));
202 //printf("%d %d %s\n",i,j,mole.asymm.at(j).Label.toStdString().c_str());
203 QLabel * l =new QLabel(mole.asymm.at(k).Label,this);
204 l->move(x, y);
205 l->show();
206 l->setAcceptDrops(false);
207 l->setAlignment(Qt::AlignCenter);
208 l->setAttribute(Qt::WA_DeleteOnClose);
209 l->setStyleSheet (QString(
210 "QLabel{font: bold; border: 2px solid #2f2f31; border-radius: 1px;background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 %1, stop: 1 #dadbde);} "
211 "QLabel:hover {background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
212 "stop: 0 #ffffff, stop: 1 %1);border: 0px;}").arg(mole.AtomColor[mole.asymm.at(k).an].name()));
213 DragAtom *wordLabel = new DragAtom(j,mole.asymm.at(j).Label,mole.AtomColor[mole.asymm.at(j).an], this);
214 wordLabel->move(60, y);
215 l->setFixedSize(47,wordLabel->height()-2);
216 wordLabel->show();
217 wordLabel->setFixedWidth(56);
218 wordLabel->setAttribute(Qt::WA_DeleteOnClose);
219 dragAtoms.append(wordLabel);
220 itemheight=wordLabel->height();
221 y += wordLabel->height() + 2;
222 }
223
224 QPalette newPalette = palette();
225 newPalette.setColor(QPalette::Window, Qt::white);
226 setPalette(newPalette);
227
228 setFixedSize(120, qMax(200, y));
229 setAcceptDrops(true);
230 }
231
232 void DragDropAtoms::dragEnterEvent(QDragEnterEvent *event){
233
234 if (event->mimeData()->hasFormat("application/x-dragdropatom")) {
235 //printf("dragEnterEvent\n");
236 if (children().contains(event->source())) {
237 event->setDropAction(Qt::MoveAction);
238 event->accept();
239 } else {
240 event->acceptProposedAction();
241 }
242 } else {
243 event->ignore();
244 }
245 }
246
247 void DragDropAtoms::dragMoveEvent(QDragMoveEvent *event){
248
249 if (event->mimeData()->hasFormat("application/x-dragdropatom")) {
250 //printf("dragMoveEvent\n");
251 int idx = (event->pos().y()-5) / (itemheight+2);
252 //printf("idx %d current %d\n",idx,current);
253 for (int i = 0; i< dragAtoms.size(); i++){
254 int k=0;
255 if ((idx<current)&&(i>=idx)&&(i<current)) k=1;
256 if ((idx>current)&&(i<=idx)&&(i>=current)) k=-1;
257 dragAtoms.at(i)->move(60, 5+(itemheight+2)*(i+k));
258 }
259 if (children().contains(event->source())) {
260 event->setDropAction(Qt::MoveAction);
261
262 event->accept();
263 } else {
264 event->acceptProposedAction();
265 }
266 } else {
267 event->ignore();
268 }
269 update();
270 }
271
272 void DragDropAtoms::dropEvent(QDropEvent *event){
273
274 if (event->mimeData()->hasFormat("application/x-dragdropatom")) {
275 const QMimeData *mime = event->mimeData();
276 QByteArray itemData = mime->data("application/x-dragdropatom");
277 QDataStream dataStream(&itemData, QIODevice::ReadOnly);
278 int idx;
279 QColor cc;
280 QString text;
281 QPoint offset;
282 dataStream >>idx>>cc>> text >> offset;
283 int index = (event->pos().y()-5) / (itemheight+2);
284
285 m_target->removeOne(idx);
286 m_target->insert(index,idx);
287 //text=text.toLower();
288 DragAtom *newLabel = new DragAtom(idx,text,cc, this);
289 newLabel->move(event->pos() - offset);
290 newLabel->show();
291 newLabel->setAttribute(Qt::WA_DeleteOnClose);
292 dragAtoms.removeAt(current);
293 dragAtoms.insert(index,newLabel);
294 //printf("dropEvent\n");
295 if (event->source() == this) {
296 event->setDropAction(Qt::MoveAction);
297 event->accept();
298 } else {
299 event->acceptProposedAction();
300 }
301 dadas.clear();
302 for (int i = 0; i< dragAtoms.size(); i++){
303 dragAtoms.at(i)->move(60, 5+(itemheight+2)*(i));
304 int j=m_target->at(i);
305
306 int k=m_reference.at(i);
307
308 dadas.append(QString("%1 %2").arg(k).arg(j));
309 printf("%d %s %s\n",i,m_mole.asymm.at(k).Label.toStdString().c_str(),m_mole.asymm.at(j).Label.toStdString().c_str());
310 }
311 } /*else if (event->mimeData()->hasText()) {
312 QStringList pieces = event->mimeData()->text().split(QRegularExpression("\\s+"),
313 skipEmptyParts);
314 QPoint position = event->pos();
315
316 foreach (QString piece, pieces) {
317 DragAtom *newLabel = new DragAtom(0,piece,Qt::white this);
318 newLabel->move(position);
319 newLabel->show();
320 newLabel->setAttribute(Qt::WA_DeleteOnClose);
321
322 position += QPoint(newLabel->width(), 0);
323 }
324
325 event->acceptProposedAction();
326 }*/ else {
327 event->ignore();
328 }
329 }
330 /*
331 void DragDropAtoms::mouseMoveEvent(QMouseEvent *event){
332 if (event->buttons()==Qt::NoButton){
333 static int last=-1;
334 int index = (event->pos().y()-5) / (itemheight+2);
335 printf("index %d x=%d y=%d %d\n",index,event->pos().x(),event->pos().y(),itemheight);
336 QString dada="";
337
338
339 if ((index<0)||(index>=m_reference.size())) {
340 emit pairs(dada);
341 last=index;
342 return;
343 }
344 if ((event->pos().x()>5)){
345 emit pairs(dadas.at(index));
346
347 last=index;
348 return;
349 }
350
351 last=index;
352 emit pairs(dada);
353 }
354 }
355 */
356 void DragDropAtoms::mousePressEvent(QMouseEvent *event){
357 if (event->pos().x()<50) {
358
359 int index = (event->pos().y()) / (itemheight+2);
360 emit pairs(dadas.at(index));
361 event->accept();return;}
362 DragAtom *child = static_cast<DragAtom*>(childAt(event->pos()));
363 if (!child)
364 return;
365
366 QPoint hotSpot = event->pos() - child->pos();
367
368 QByteArray itemData;
369 QDataStream dataStream(&itemData, QIODevice::WriteOnly);
370 dataStream<<child->index()<<child->color() << child->labelText() << QPoint(hotSpot);
371 current = m_target->indexOf(child->index());
372 QMimeData *mimeData = new QMimeData;
373 mimeData->setData("application/x-dragdropatom", itemData);
374 mimeData->setText(child->labelText());
375
376 QDrag *drag = new QDrag(this);
377 drag->setMimeData(mimeData);
378 #if (QT_VERSION >0x050f00)
379 Qt::ReturnByValueConstant rbvc=Qt::ReturnByValueConstant();
380 drag->setPixmap(child->pixmap(rbvc));
381 #else
382 drag->setPixmap(*child->pixmap());
383 #endif
384 drag->setHotSpot(hotSpot);
385
386 child->hide();
387
388 if (drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction) == Qt::MoveAction)
389 child->close();
390 else
391 child->show();
392 }
393 //void DragDropAtoms::
394 //void DragDropAtoms::
395 //
396 //
397 DragAtom::DragAtom(const int index,const QString &text,QColor c, QWidget *parent): QLabel(parent){
398 m_index=index;
399 m_labelText=text;
400 m_c=c;
401 QFontMetrics metric(font());
402 QSize size = metric.size(Qt::TextSingleLine, " "+ text+" ");
403
404 QImage image(size.width() + 14, size.height() + 14,
405 QImage::Format_ARGB32_Premultiplied);
406 image.fill(qRgba(0, 0, 0, 0));
407
408 QFont font;
409 font.setStyleStrategy(QFont::ForceOutline);
410 font.setWeight(QFont::Black);
411
412 QLinearGradient gradient(0, 0, 0, image.height()-1);
413 gradient.setColorAt(0.0, Qt::white);
414 gradient.setColorAt(0.2, c);
415 gradient.setColorAt(0.8, c);
416 gradient.setColorAt(1.0, QColor(127, 127, 200));
417
418 QPainter painter;
419 painter.begin(&image);
420 painter.setRenderHint(QPainter::Antialiasing);
421 painter.setBrush(gradient);
422 painter.drawRoundedRect(QRectF(0.5, 0.5, image.width()-1, image.height()-1),
423 25, 25, Qt::RelativeSize);
424
425 painter.setFont(font);
426 painter.setBrush(Qt::black);
427 painter.drawText(QRect(QPoint(6, 6), size), Qt::AlignCenter, text);
428 painter.end();
429
430 setPixmap(QPixmap::fromImage(image));
431 }
432
433 QString DragAtom::labelText() const {
434 return m_labelText;
435 }
436
437 int DragAtom::index() const{
438 return m_index;
439 }
440
441 QColor DragAtom::color() const{
442 return m_c;
443 }