Debian Codegraph @

psewidget.cpp

raw symbols SCIP
1
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Christian B. Huebschle & George M. Sheldrick
5 ** All rights reserved.
6 ** Contact: [email protected]
7 **
8 ** This file is part of the ShelXle
9 **
10 ** This file may be used under the terms of the GNU Lesser
11 ** General Public License version 2.1 as published by the Free Software
12 ** Foundation and appearing in the file COPYING included in the
13 ** packaging of this file. Please review the following information to
14 ** ensure the GNU Lesser General Public License version 2.1 requirements
15 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 **
18 ****************************************************************************/
19 #include "psewidget.h"
20 #include <QtGui>
21 #include <QGridLayout>
22
23 PSEWidget::PSEWidget(Molecule *_mole, QWidget *parent) :
24 QWidget(parent){
25 mole=_mole;
26 selection=0;
27 HisD=false;
28 mole->loadSettings();
29 //#define PROGRAM_NAME "shelXle"
30 einstellung = new QSettings( QSettings::IniFormat, QSettings::UserScope ,PROGRAM_NAME,mole->mynewnameis ,this);
31 sz=mole->pseFontSize;
32 QFont f=QFont();
33 if (mole->mynewnameis=="BrukerShelXle") sz=f.pointSize();
34 QToolButton *TB;
35 lplus = new QToolButton();
36 lplus->setIcon(QIcon(mole->theIconPath+"efplus.svg"));
37 connect(lplus,SIGNAL(pressed()),this,SLOT(incFontSize()));
38 lminus = new QToolButton();
39 lminus->setIcon(QIcon(mole->theIconPath+"efminus.svg"));
40 lplus->setStyleSheet(
41 QString(
42 "QToolButton { /* all types of tool button */\n"
43 "border: 1px solid #8f8f91;"
44 "border-radius: 2px;"
45 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
46 "stop: 0 %1, stop: 1 #dadbde);"
47 "}"
48 "QToolButton:hover {"
49 "border: 5px; solid #8f8f91;"
50 "border-radius: 2px;"
51 // "width: 40px;"
52 // "height: 40px;"
53 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
54 "stop: 0 #ffffff, stop: 1 %1);"
55
56 // "border: 0px;"
57 "}"
58 "QToolButton:pressed {"
59 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
60 "stop: 0 %1, stop: 1 #ffffff);"
61 "border: 0px;"
62 "}").arg("#dddddd"));
63 #if (QT_VERSION >=0x050000)
64 lplus->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).horizontalAdvance("Mmk"));
65 #else
66 lplus->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).width("Mmk"));
67 #endif
68 lminus->setStyleSheet(
69 QString(
70 "QToolButton { /* all types of tool button */\n"
71 "border: 1px solid #8f8f91;"
72 "border-radius: 2px;"
73 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
74 "stop: 0 %1, stop: 1 #dadbde);"
75 "}"
76 "QToolButton:hover {"
77 "border: 5px; solid #8f8f91;"
78 "border-radius: 2px;"
79 // "width: 40px;"
80 // "height: 40px;"
81 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
82 "stop: 0 #ffffff, stop: 1 %1);"
83
84 // "border: 0px;"
85 "}"
86 "QToolButton:pressed {"
87 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
88 "stop: 0 %1, stop: 1 #ffffff);"
89 "border: 0px;"
90 "}").arg("#dddddd"));
91 #if (QT_VERSION >=0x050000)
92 lminus->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).horizontalAdvance("Mmk"));
93 #else
94 lminus->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).width("Mmk"));
95 #endif
96 connect(lminus,SIGNAL(pressed()),this,SLOT(decFontSize()));
97
98 if (mole->mynewnameis=="BrukerShelXle"){
99 printf("I am %s\n",mole->mynewnameis.toStdString().c_str());
100 lminus->hide();
101 lplus->hide();
102 }
103 /* a=viewMenu->addAction(QIcon(mole->theIconPath+"laminus.svg"),
104 tr("decrease label fontsize"),chgl,SLOT(decFontSize()),
105 QKeySequence("Alt+-"));*/
106 esm = new QSignalMapper(this);
107 for (int i=0; i<mole->pseSize(); i++){
108 TB = new QToolButton();
109 TB->setText(mole->pse(i));
110 //TB->setBackgroundRole(QPalette::AlternateBase);
111 TB->setFont(QFont("Arial",sz,QFont::Black));
112
113 //printf("ii %d %d\n",i,QFontMetrics(QFont("Arial",-1,QFont::Black)).horizontalAdvance("Mmk"));
114 //fflush(stdout);
115 TB->setAutoRaise(true);
116 #if (QT_VERSION >=0x050000)
117 TB->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).horizontalAdvance("Mmk"));
118 #else
119 TB->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).width("Mmk"));
120 #endif
121 if (i<107)TB->setStyleSheet(
122 QString(
123 "QToolButton { /* all types of tool button */\n"
124 "color: #000000;\n"
125 "border: 1px solid #8f8f91;"
126 "border-radius: 2px;"
127 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
128 "stop: 0 %1, stop: 1 #dadbde);"
129 "}"
130 "QToolButton:hover {"
131 "border: 5px; solid #8f8f91;"
132 "border-radius: 2px;"
133 // "width: 40px;"
134 // "height: 40px;"
135 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
136 "stop: 0 #ffffff, stop: 1 %1);"
137
138 // "border: 0px;"
139 "}"
140 "QToolButton:pressed {"
141 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
142 "stop: 0 %1, stop: 1 #ffffff);"
143 "border: 0px;"
144 "}").arg(mole->atomColor(i).name()));
145 {
146 }
147 elebutt[i]=TB;
148
149 esm->setMapping(elebutt[i],i);
150 connect(elebutt[i], SIGNAL(clicked()), esm, SLOT(map()));
151 }
152
153 #if (QT_VERSION >= 0x050f00)
154 connect(esm, &QSignalMapper::mappedInt, this, &PSEWidget::selectPSE);
155 #else
156 connect(esm, SIGNAL(mapped(int)), this, SLOT(selectPSE(int)));
157 #endif
158 QGridLayout *gl = new QGridLayout();
159 gl->addWidget(elebutt[0],0,0); //H
160 gl->addWidget(lplus,0,5);
161 gl->addWidget(lminus,0,6);
162
163 gl->addWidget(elebutt[1],0,17);//He
164 gl->addWidget(elebutt[2],1,0); //Li
165 gl->addWidget(elebutt[3],1,1); //Be
166 gl->addWidget(elebutt[4],1,12);//B
167 gl->addWidget(elebutt[5],1,13);//C
168 gl->addWidget(elebutt[6],1,14);//N
169 gl->addWidget(elebutt[7],1,15);//O
170 gl->addWidget(elebutt[8],1,16);//F
171 gl->addWidget(elebutt[9],1,17);//Ne
172 gl->addWidget(elebutt[10],2,0); //Na
173 gl->addWidget(elebutt[11],2,1); //Mg
174 gl->addWidget(elebutt[12],2,12);//Al
175 gl->addWidget(elebutt[13],2,13);//Si
176 gl->addWidget(elebutt[14],2,14);//P
177 gl->addWidget(elebutt[15],2,15);//S
178 gl->addWidget(elebutt[16],2,16);//Cl
179 gl->addWidget(elebutt[17],2,17);//Ar
180 gl->addWidget(elebutt[18],3,0);//K
181 gl->addWidget(elebutt[19],3,1);//Ca
182 gl->addWidget(elebutt[20],3,2);//Sc
183 gl->addWidget(elebutt[21],3,3);//Ti
184 gl->addWidget(elebutt[22],3,4);//V
185 gl->addWidget(elebutt[23],3,5);//Cr
186 gl->addWidget(elebutt[24],3,6);//Mn
187 gl->addWidget(elebutt[25],3,7);//Fe
188 gl->addWidget(elebutt[26],3,8);//Co
189 gl->addWidget(elebutt[27],3,9);//Ni
190 gl->addWidget(elebutt[28],3,10);//Cu
191 gl->addWidget(elebutt[29],3,11);//Zn
192 gl->addWidget(elebutt[30],3,12);//Ga
193 gl->addWidget(elebutt[31],3,13);//Ge
194 gl->addWidget(elebutt[32],3,14);//As
195 gl->addWidget(elebutt[33],3,15);//Se
196 gl->addWidget(elebutt[34],3,16);//Br
197 gl->addWidget(elebutt[35],3,17);//Kr
198 gl->addWidget(elebutt[36],4,0);//Rb
199 gl->addWidget(elebutt[37],4,1);//Sr
200 gl->addWidget(elebutt[38],4,2);//Y
201 gl->addWidget(elebutt[39],4,3);//Zr
202 gl->addWidget(elebutt[40],4,4);//Nb
203 gl->addWidget(elebutt[41],4,5);//Mo
204 gl->addWidget(elebutt[42],4,6);//Tc
205 gl->addWidget(elebutt[43],4,7);//Ru
206 gl->addWidget(elebutt[44],4,8);//Rh
207 gl->addWidget(elebutt[45],4,9);//Pd
208 gl->addWidget(elebutt[46],4,10);//Ag
209 gl->addWidget(elebutt[47],4,11);//Cd
210 gl->addWidget(elebutt[48],4,12);//In
211 gl->addWidget(elebutt[49],4,13);//Sn
212 gl->addWidget(elebutt[50],4,14);//Sb
213 gl->addWidget(elebutt[51],4,15);//Te
214 gl->addWidget(elebutt[52],4,16);//I
215 gl->addWidget(elebutt[53],4,17);//Xe
216 gl->addWidget(elebutt[54],5,0);//Cs
217 gl->addWidget(elebutt[55],5,1);//Ba
218 gl->addWidget(elebutt[56],7,0);//La
219 gl->addWidget(elebutt[57],7,1);//Ce
220 gl->addWidget(elebutt[58],7,2);//Pr
221 gl->addWidget(elebutt[59],7,3);//Nd
222 gl->addWidget(elebutt[60],7,4);//Pm
223 gl->addWidget(elebutt[61],7,5);//Sm
224 gl->addWidget(elebutt[62],7,6);//Eu
225 gl->addWidget(elebutt[63],7,7);//Gd
226 gl->addWidget(elebutt[64],7,8);//Tb
227 gl->addWidget(elebutt[65],7,9);//Dy
228 gl->addWidget(elebutt[66],7,10);//Ho
229 gl->addWidget(elebutt[67],7,11);//Er
230 gl->addWidget(elebutt[68],7,12);//Tm
231 gl->addWidget(elebutt[69],7,13);//Yb
232 gl->addWidget(elebutt[70],7,14);//Lu
233 gl->addWidget(elebutt[71],5,3);//Hf
234 gl->addWidget(elebutt[72],5,4);//Ta
235 gl->addWidget(elebutt[73],5,5);//W
236 gl->addWidget(elebutt[74],5,6);//Re
237 gl->addWidget(elebutt[75],5,7);//Os
238 gl->addWidget(elebutt[76],5,8);//Ir
239 gl->addWidget(elebutt[77],5,9);//Pt
240 gl->addWidget(elebutt[78],5,10);//Au
241 gl->addWidget(elebutt[79],5,11);//Hg
242 gl->addWidget(elebutt[80],5,12);//Tl
243 gl->addWidget(elebutt[81],5,13);//Pb
244 gl->addWidget(elebutt[82],5,14);//Bi
245 gl->addWidget(elebutt[83],5,15);//Po
246 gl->addWidget(elebutt[84],5,16);//At
247 gl->addWidget(elebutt[85],5,17);//Rn
248 gl->addWidget(elebutt[86],6,0);//Fr
249 gl->addWidget(elebutt[87],6,1);//Ra
250 gl->addWidget(elebutt[88],8,0);//Ac
251 gl->addWidget(elebutt[89],8,1);//Th
252 gl->addWidget(elebutt[90],8,2);//Pa
253 gl->addWidget(elebutt[91],8,3);//U
254 gl->addWidget(elebutt[92],8,4);//Np
255 gl->addWidget(elebutt[93],8,5);//Pu
256 gl->addWidget(elebutt[94],8,6);//Am
257 gl->addWidget(elebutt[95],8,7);//Cm
258 gl->addWidget(elebutt[96],8,8);//Bk
259 gl->addWidget(elebutt[97],8,9);//Cf
260 gl->addWidget(elebutt[98],8,10);//Es
261 gl->addWidget(elebutt[99],8,11);//Fm
262 gl->addWidget(elebutt[100],8,12);//Md
263 gl->addWidget(elebutt[101],8,13);//No
264 gl->addWidget(elebutt[102],8,14);//Lr
265 //gl->addWidget(elebutt[103],8,17);//Ku
266 //gl->addWidget(elebutt[104],6,4);//Ha
267 //gl->addWidget(elebutt[105],6,5);//Rf
268 //gl->addWidget(elebutt[106],6,6);//Ns
269 // gl->addWidget(elebutt[107],6,7);//Hs
270 // gl->addWidget(elebutt[108],6,8);//Mt
271 gl->setRowStretch(9,12);
272 gl->setSpacing(1);
273 setLayout(gl);
274 QTimer *shifttester = new QTimer(this);
275 connect(shifttester,SIGNAL(timeout()),this,SLOT(probeShiftState()));
276 shifttester->start(100);
277 }
278
279 void PSEWidget::incFontSize(){
280 QToolButton *action = qobject_cast<QToolButton *>(sender());
281
282 QFont ft;
283 ft= elebutt[0]->font();
284 mole->pseFontSize=sz=qMin(ft.pointSize()+1,24);
285 ft.setPointSize(sz);
286 #if (QT_VERSION >=0x050000)
287 action->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).horizontalAdvance("Mmk"));
288 lminus->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).horizontalAdvance("Mmk"));
289 for (int i=0; i<103; i++){
290 elebutt[i]->setFont(ft);
291 elebutt[i]->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).horizontalAdvance("Mmk"));
292 }
293 #else
294 action->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).width("Mmk"));
295 lminus->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).width("Mmk"));
296 for (int i=0; i<103; i++){
297 elebutt[i]->setFont(ft);
298 elebutt[i]->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).width("Mmk"));
299 }
300 #endif
301 einstellung->beginGroup("PSE");
302 einstellung->setValue("FontSize",mole->pseFontSize);
303 einstellung->endGroup();
304 update();
305 }
306
307 void PSEWidget::decFontSize(){
308 QToolButton *action = qobject_cast<QToolButton *>(sender());
309 QFont ft;
310 ft= elebutt[0]->font();
311 mole->pseFontSize=sz=qMax(ft.pointSize()-1,6);
312 ft.setPointSize(sz);
313 #if (QT_VERSION >=0x050000)
314
315 action->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).horizontalAdvance("Mmk"));
316 lplus->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).horizontalAdvance("Mmk"));
317 for (int i=0; i<103; i++){
318 elebutt[i]->setFont(ft);
319 elebutt[i]->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).horizontalAdvance("Mmk"));
320 }
321 #else
322 action->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).width("Mmk"));
323 lplus->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).width("Mmk"));
324 for (int i=0; i<103; i++){
325 elebutt[i]->setFont(ft);
326 elebutt[i]->setFixedWidth(QFontMetrics(QFont("Arial",sz+2,QFont::Black)).width("Mmk"));
327 }
328 #endif
329 einstellung->beginGroup("PSE");
330 einstellung->setValue("FontSize",mole->pseFontSize);
331 einstellung->endGroup();
332 update();
333
334 }
335
336 void PSEWidget::colorchange(QColor bgcolor){
337 elebutt[selection]->setStyleSheet(
338 QString(
339 "QToolButton { /* all types of tool button */\n"
340 "border: 1px solid #8f8f91;"
341 "border-radius: 2px;"
342 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
343 "stop: 0 %1, stop: 1 #dadbde);"
344 "}"
345 "QToolButton:hover {"
346 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
347 "stop: 0 #ffffff, stop: 1 %1);"
348 "}"
349 "QToolButton:pressed {"
350 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
351 "stop: 0 %1, stop: 1 #ffffff);"
352 "border: 0px;"
353 "}").arg(bgcolor.name()));
354 update();
355 }
356
357 void PSEWidget::probeShiftState(){
358 if (isVisible()){
359 //printf("SHIFT? %d\n",QApplication::keyboardModifiers ());
360 if (QApplication::queryKeyboardModifiers () == Qt::ShiftModifier){
361 elebutt[0]->setText("D");
362 if (!HisD) {
363 HisD=true;
364 emit Htransmutated(0,HisD);
365 }
366 elebutt[0]->setStyleSheet(
367 QString(
368 "QToolButton { /* all types of tool button */\n"
369 "color: #000000;\n"
370 "border: 1px solid #8f8f91;"
371 "border-radius: 2px;"
372 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
373 "stop: 0 %1, stop: 1 #dadbde);"
374 "}"
375 "QToolButton:hover {"
376 "border: 5px; solid #8f8f91;"
377 "border-radius: 2px;"
378 // "width: 40px;"
379 // "height: 40px;"
380 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
381 "stop: 0 #ffffff, stop: 1 %1);"
382
383 // "border: 0px;"
384 "}"
385 "QToolButton:pressed {"
386 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
387 "stop: 0 %1, stop: 1 #ffffff);"
388 "border: 0px;"
389 "}").arg(mole->atomColor(0,HisD).name()));
390 } else {
391 elebutt[0]->setText("H");
392 if (HisD) {
393 HisD=false;
394 emit Htransmutated(0,HisD);
395 }
396 elebutt[0]->setStyleSheet(
397 QString(
398 "QToolButton { /* all types of tool button */\n"
399 "color: #000000;\n"
400 "border: 1px solid #8f8f91;"
401 "border-radius: 2px;"
402 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
403 "stop: 0 %1, stop: 1 #dadbde);"
404 "}"
405 "QToolButton:hover {"
406 "border: 5px; solid #8f8f91;"
407 "border-radius: 2px;"
408 // "width: 40px;"
409 // "height: 40px;"
410 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
411 "stop: 0 #ffffff, stop: 1 %1);"
412
413 // "border: 0px;"
414 "}"
415 "QToolButton:pressed {"
416 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
417 "stop: 0 %1, stop: 1 #ffffff);"
418 "border: 0px;"
419 "}").arg(mole->atomColor(0,HisD).name()));
420 }
421 }
422 }