| 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 "historywidget.h" |
| 20 | #include <QtGui> |
| 21 | #include "deprecation.h" |
| 22 | //#define PROGRAM_NAME "shelXle" |
| 23 | HistoryWidget::HistoryWidget(QWidget *parent) : |
| 24 | QWidget(parent){ |
| 25 | setMinimumSize(100,100); |
| 26 | setMouseTracking(true); |
| 27 | } |
| 28 | |
| 29 | void HistoryWidget::mouseMoveEvent(QMouseEvent *event){ |
| 30 | if (event->pos().y()<(fh+3)) { |
| 31 | emit message("The Savehistory has an entry every time the file was saved by or before the refinement"); |
| 32 | return; |
| 33 | } |
| 34 | if (RWerte.isEmpty()) return; |
| 35 | int w = width() / RWerte.size(); |
| 36 | int index = qMin(event->pos().x() / w, saveFilesList.size()-1); |
| 37 | if ((index>-1)&&(index<saveFilesList.size())) |
| 38 | emit message(QString("%1 (R1=%2)").arg(saveFilesList.at(index)).arg(RWerte.at(index))); |
| 39 | } |
| 40 | |
| 41 | void HistoryWidget::preview(){ |
| 42 | QAction *action = qobject_cast<QAction *>(sender()); |
| 43 | QString fileName = ""; |
| 44 | if (action) |
| 45 | fileName = action->data().toString(); |
| 46 | else return; |
| 47 | if (fileName.isEmpty()) return; |
| 48 | QFile f(fileName); |
| 49 | f.open(QIODevice::ReadOnly); |
| 50 | QString all = f.readAll(); |
| 51 | all = all.section('\n',0,30); |
| 52 | //all = all.replace("\n","<br>\n"); |
| 53 | f.close(); |
| 54 | //QWhatsThis *wtf = new QWhatsThis(); |
| 55 | QWhatsThis::showText(QPoint(75,0),//<style type=\"text/css\">{ font-size:0.7em; white-space:pre; }</style> |
| 56 | QString("<h2>%2</h2><font color=red>--click here to close--</font><font size=-1><pre><code>%1</code></pre></font><center></center>") |
| 57 | .arg(all) |
| 58 | .arg(fileName)); |
| 59 | all.clear(); |
| 60 | return; |
| 61 | |
| 62 | } |
| 63 | |
| 64 | void HistoryWidget::preview2(){ |
| 65 | QAction *action = qobject_cast<QAction *>(sender()); |
| 66 | QString fileName = ""; |
| 67 | if (action) |
| 68 | fileName = action->data().toString(); |
| 69 | else return; |
| 70 | if (fileName.isEmpty()) return; |
| 71 | QFile f(fileName); |
| 72 | f.open(QIODevice::ReadOnly); |
| 73 | QString all = f.readAll(); |
| 74 | all = all.section('\n',30); |
| 75 | //all = all.replace("\n","<br>\n"); |
| 76 | f.close(); |
| 77 | //QWhatsThis *wtf = new QWhatsThis(); |
| 78 | QWhatsThis::showText(QPoint(75,0),//<style type=\"text/css\">{ font-size:0.7em; white-space:pre; }</style> |
| 79 | QString("<h2>%2</h2><font color=red>--click here to close--</font><font size=-1><pre><code>...\n%1</code></pre></font><center></center>") |
| 80 | .arg(all) |
| 81 | .arg(fileName) |
| 82 | ); |
| 83 | all.clear(); |
| 84 | return; |
| 85 | |
| 86 | } |
| 87 | |
| 88 | void HistoryWidget::prune(){ |
| 89 | QString fcfname; |
| 90 | for (int i=0; (i+10)<saveFilesList.size(); i++){ |
| 91 | QFile::remove(saveFilesList.at(i)); |
| 92 | fcfname=saveFilesList.at(i); |
| 93 | fcfname.replace(fcfname.size()-3,3,"fcf"); |
| 94 | QFile::remove(fcfname); |
| 95 | } |
| 96 | setPath(dirname,maxwid); |
| 97 | } |
| 98 | |
| 99 | void HistoryWidget::deleteOne(){ |
| 100 | QAction *action = qobject_cast<QAction *>(sender()); |
| 101 | QString fileName = ""; |
| 102 | if (action) |
| 103 | fileName = action->data().toString(); |
| 104 | else return; |
| 105 | if (fileName.isEmpty()) return; |
| 106 | QString fcfname=fileName; |
| 107 | fcfname.replace(fcfname.size()-3,3,"fcf"); |
| 108 | if (QMessageBox::Yes==QMessageBox::question ( this, "Delete history entry", |
| 109 | QString("Do you really whant to delete history files '<b>%1</b>' and '<b>%2</b>'?"). |
| 110 | arg(fileName). |
| 111 | arg(fcfname), |
| 112 | QMessageBox::Yes|QMessageBox::No, QMessageBox::NoButton )){ |
| 113 | QFile::remove(fileName); |
| 114 | QFile::remove(fcfname); |
| 115 | } |
| 116 | setPath(dirname,maxwid); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | void HistoryWidget::mousePressEvent ( QMouseEvent * event ){ |
| 121 | if (RWerte.isEmpty()) return; |
| 122 | int w = width() / RWerte.size(); |
| 123 | int index = qMin(event->pos().x() / w, saveFilesList.size()-1);//event->pos().x() / w; |
| 124 | //copy ins to last programnameSaves |
| 125 | //copy res to ins |
| 126 | //copy savefilelist.at(index) to res and open this res file |
| 127 | QString dn=dirname.section('/',0,-2), |
| 128 | argument=dirname.section('/',-1); |
| 129 | argument.remove(QRegularExpression(".res$|.ins$",QRegularExpression::CaseInsensitiveOption)); |
| 130 | if (event->buttons() & Qt::RightButton){ |
| 131 | QMenu *menu = new QMenu(""); |
| 132 | QString shortname=saveFilesList.at(index).section('/',-1); |
| 133 | QAction *a=menu->addAction(QString("Preview %1 (first 30 lines)").arg(shortname),this,SLOT(preview())); |
| 134 | a->setData(saveFilesList.at(index)); |
| 135 | a=menu->addAction(QString("Preview %1 (next 30 lines)").arg(shortname),this,SLOT(preview2())); |
| 136 | a->setData(saveFilesList.at(index)); |
| 137 | a=menu->addAction(QString("Purge history. Keep newest ten entries."),this,SLOT(prune())); |
| 138 | a=menu->addAction(QString("Delete %1 !").arg(shortname),this,SLOT(deleteOne())); |
| 139 | a->setData(saveFilesList.at(index)); |
| 140 | menu->exec(event->pos()); |
| 141 | delete menu; |
| 142 | } |
| 143 | if (event->buttons() & Qt::LeftButton){ |
| 144 | if (event->pos().y()<(fh+3)) {emit saveHist(); return;} |
| 145 | if (dirname.contains(QRegularExpression(".res$",QRegularExpression::CaseInsensitiveOption))){ |
| 146 | QString insname =dirname; |
| 147 | insname.replace(QRegularExpression(".res$", QRegularExpression::CaseInsensitiveOption),".ins"); |
| 148 | QString fcfname = dirname; |
| 149 | fcfname.replace(QRegularExpression(".res$", QRegularExpression::CaseInsensitiveOption),".fcf"); |
| 150 | QString fcfname2 = dirname; |
| 151 | fcfname2.replace(QRegularExpression(".res$", QRegularExpression::CaseInsensitiveOption),".2fcf"); |
| 152 | QDir work=QDir(QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME)); |
| 153 | QStringList filter; |
| 154 | filter << QString("%1_*_.ins").arg(argument); |
| 155 | QStringList resfs; |
| 156 | resfs=work.entryList(filter,QDir::Files,QDir::Time|QDir::Reversed); |
| 157 | int vers=0; |
| 158 | if (resfs.isEmpty()) vers=1; |
| 159 | else { |
| 160 | bool ok=true; |
| 161 | for (int i = 0; i < resfs.size(); i++) |
| 162 | vers = qMax(resfs.at(i).section("_",-2,-2).toInt(&ok,36),vers); |
| 163 | vers++; |
| 164 | } |
| 165 | if (!work.exists ( QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME))) work.mkdir (QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME)); |
| 166 | if (saveFilesList.at(index)==insname){ |
| 167 | QFile::copy(dirname,QString("%1/%4saves/%2_%3_.ins").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME)); |
| 168 | QFile::remove(dirname); |
| 169 | QFile::copy(saveFilesList.at(index),dirname); |
| 170 | // QFile::remove(saveFilesList.at(index)); |
| 171 | |
| 172 | QFile::copy(fcfname,QString("%1/%4saves/%2_%3_.fcf").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME)); |
| 173 | QFile::remove(fcfname); |
| 174 | QFile::copy(fcfname2,fcfname); |
| 175 | //printf("copy %s to %s\n",fcfname.toStdString().c_str() |
| 176 | // ,QString("%1/%4saves/%2_%3_.fcf").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME).toStdString().c_str()); |
| 177 | //printf("copy %s to %s\n",fcfname2.toStdString().c_str(), fcfname.toStdString().c_str()); |
| 178 | |
| 179 | }else{ |
| 180 | QFile::copy(insname,QString("%1/%4saves/%2_%3_.ins").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME)); |
| 181 | QFile::remove(insname); |
| 182 | QFile::copy(dirname,insname); |
| 183 | if (saveFilesList.at(index) != dirname) { |
| 184 | QFile::remove(dirname); |
| 185 | } |
| 186 | QFile::copy(fcfname2,QString("%1/%4saves/%2_%3_.fcf").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME)); |
| 187 | QFile::remove(fcfname2); |
| 188 | QFile::copy(fcfname,fcfname2); |
| 189 | QFile::remove(fcfname); |
| 190 | QString sfcf=saveFilesList.at(index); |
| 191 | sfcf = sfcf.replace(sfcf.size()-3,3,"fcf"); |
| 192 | QFile::copy(sfcf,fcfname); |
| 193 | |
| 194 | QFile::copy(saveFilesList.at(index),dirname); |
| 195 | //QFile::remove(saveFilesList.at(index)); |
| 196 | //printf("copy %s to %s\n",fcfname.toStdString().c_str() |
| 197 | // ,fcfname2.toStdString().c_str()); |
| 198 | //printf("copy %s to %s\n",fcfname2.toStdString().c_str() |
| 199 | // ,QString("%1/%4saves/%2_%3_.fcf").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME).toStdString().c_str()); |
| 200 | //printf("copy %s to %s\n",sfcf.toStdString().c_str(), fcfname.toStdString().c_str()); |
| 201 | } |
| 202 | //QTest::qWait(550); |
| 203 | /* .arg(insname) |
| 204 | .arg(QString("%1/%4saves/%2_%3_.ins").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME)) |
| 205 | .arg(dirname) |
| 206 | .arg(saveFilesList.at(index));*/ |
| 207 | }else{ |
| 208 | QDir work=QDir(QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME)); |
| 209 | QStringList filter; |
| 210 | filter << QString("%1_*_.ins").arg(argument); |
| 211 | QStringList resfs; |
| 212 | resfs=work.entryList(filter,QDir::Files,QDir::Time|QDir::Reversed); |
| 213 | int vers=0; |
| 214 | if (resfs.isEmpty()) vers=1; |
| 215 | else { |
| 216 | bool ok=true; |
| 217 | for (int i = 0; i < resfs.size(); i++) |
| 218 | vers = qMax(resfs.at(i).section("_",-2,-2).toInt(&ok,36),vers); |
| 219 | |
| 220 | vers++; |
| 221 | } |
| 222 | if (!work.exists ( QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME))) work.mkdir (QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME)); |
| 223 | QFile::copy(dirname,QString("%1/%4saves/%2_%3_.ins").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME)); |
| 224 | dirname.chop(3); |
| 225 | dirname.append("res"); |
| 226 | QFile::copy(saveFilesList.at(index),dirname); |
| 227 | } |
| 228 | emit lofi(dirname); |
| 229 | } |
| 230 | update(); |
| 231 | } |
| 232 | |
| 233 | void HistoryWidget::setPath(QString dirName,int wid){ |
| 234 | maxwid = wid-5; |
| 235 | dirname=dirName; |
| 236 | QString dn = dirName.section('/',0,-2), |
| 237 | argument=dirName.section('/',-1); |
| 238 | argument.remove(QRegularExpression(".res$|.ins$",QRegularExpression::CaseInsensitiveOption)); |
| 239 | QString insname =dirName; |
| 240 | insname.replace(QRegularExpression(".res$",QRegularExpression::CaseInsensitiveOption),".ins"); |
| 241 | |
| 242 | QDir work=QDir(QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME)); |
| 243 | QStringList filter; |
| 244 | filter << QString("%1_*_.ins").arg(argument); |
| 245 | QStringList resfs; |
| 246 | resfs=work.entryList(filter,QDir::Files,QDir::Time|QDir::Reversed); |
| 247 | filter.clear(); |
| 248 | filter << QString("%1_*_.*").arg(argument); |
| 249 | QFileInfoList resfil = work.entryInfoList(filter,QDir::Files,QDir::Time|QDir::Reversed); |
| 250 | gesamtGr=0; |
| 251 | for (int k=0; k< resfil.size(); k++){ |
| 252 | gesamtGr += resfil.at(k).size(); |
| 253 | } |
| 254 | resfil.clear(); |
| 255 | int vers=0; |
| 256 | if (resfs.isEmpty()) vers=0; |
| 257 | else { |
| 258 | bool ok=true; |
| 259 | for (int i = 0; i < resfs.size(); i++) |
| 260 | vers = qMax(resfs.at(i).section("_",-2,-2).toInt(&ok,36),vers); |
| 261 | |
| 262 | // vers++; |
| 263 | } |
| 264 | FreeWerte.clear(); |
| 265 | RWerte.clear(); |
| 266 | RallWerte.clear(); |
| 267 | gooddata.clear(); |
| 268 | alldata.clear(); |
| 269 | parameters.clear(); |
| 270 | saveFilesList.clear(); |
| 271 | dateTimesList.clear(); |
| 272 | for (int i=0; i<resfs.size();i++){ |
| 273 | QFile alt(QString("%1/%2").arg(work.absolutePath()).arg(resfs.at(i))); |
| 274 | alt.open(QIODevice::ReadOnly|QIODevice::Text); |
| 275 | QString inhalt=alt.readAll(); |
| 276 | alt.close(); |
| 277 | inhalt = inhalt.section("\nHKLF ",1); |
| 278 | |
| 279 | |
| 280 | //REM R1 = 0.0150 for 6927 Fo > 4sig(Fo) and 0.0160 for all 7220 data |
| 281 | QStringList sl = inhalt.section("REM R1 =",1).section("\n",0,0).trimmed().split(" ",skipEmptyParts); |
| 282 | if (sl.size()<11) continue; |
| 283 | RWerte.append(sl.at(0).toDouble()*100.0); |
| 284 | gooddata.append(sl.at(2).toInt()); |
| 285 | RallWerte.append(sl.at(7).toDouble()*100.0); |
| 286 | alldata.append(sl.at(10).toInt()); |
| 287 | //R1(Free) = |
| 288 | QStringList slfree = inhalt.section("REM R1(Free) =",1).section("\n",0,0).trimmed().split(" ",skipEmptyParts); |
| 289 | if (slfree.size()>1){ |
| 290 | FreeWerte[RWerte.size()-1]=slfree.at(0).toDouble()*100; |
| 291 | } |
| 292 | sl = inhalt.section("REM R1 =",1).section("\n",1,1).trimmed().split(" ",skipEmptyParts); |
| 293 | if (sl.size()<2) continue; |
| 294 | parameters.append(sl.at(1).toInt()); |
| 295 | saveFilesList.append(alt.fileName()); |
| 296 | dateTimesList.append(QFileInfo(alt.fileName()).lastModified()); |
| 297 | |
| 298 | } |
| 299 | |
| 300 | { |
| 301 | QFile alt(insname); |
| 302 | if (alt.open(QIODevice::ReadOnly)){ |
| 303 | QString inhalt=alt.readAll(); |
| 304 | |
| 305 | alt.close(); |
| 306 | |
| 307 | inhalt = inhalt.section("\nHKLF ",1); |
| 308 | //REM R1 = 0.0150 for 6927 Fo > 4sig(Fo) and 0.0160 for all 7220 data |
| 309 | QStringList sl = inhalt.section("REM R1 =",1).section("\n",0,0).trimmed().split(" ",skipEmptyParts); |
| 310 | if (sl.size()<11) return; |
| 311 | RWerte.append(sl.at(0).toDouble()*100.0); |
| 312 | gooddata.append(sl.at(2).toInt()); |
| 313 | RallWerte.append(sl.at(7).toDouble()*100.0); |
| 314 | alldata.append(sl.at(10).toInt()); |
| 315 | //R1(Free) = |
| 316 | QStringList slfree = inhalt.section("REM R1(Free) =",1).section("\n",0,0).trimmed().split(" ",skipEmptyParts); |
| 317 | if (slfree.size()>1){ |
| 318 | FreeWerte[RWerte.size()-1]=slfree.at(0).toDouble()*100; |
| 319 | } |
| 320 | |
| 321 | |
| 322 | sl = inhalt.section("REM R1 =",1).section("\n",1,1).trimmed().split(" ",skipEmptyParts); |
| 323 | if (sl.size()<2) return; |
| 324 | parameters.append(sl.at(1).toInt()); |
| 325 | saveFilesList.append(alt.fileName()); |
| 326 | dateTimesList.append(QFileInfo(alt.fileName()).lastModified()); |
| 327 | }} |
| 328 | { |
| 329 | QFile alt(dirName); |
| 330 | if (alt.open(QIODevice::ReadOnly)){ |
| 331 | QString inhalt=alt.readAll(); |
| 332 | alt.close(); |
| 333 | |
| 334 | inhalt = inhalt.section("\nHKLF ",1); |
| 335 | //REM R1 = 0.0150 for 6927 Fo > 4sig(Fo) and 0.0160 for all 7220 data |
| 336 | |
| 337 | QStringList sl = inhalt.section("REM R1 =",1).section("\n",0,0).trimmed().split(" ",skipEmptyParts); |
| 338 | if (sl.size()<11) return; |
| 339 | RWerte.append(sl.at(0).toDouble()*100.0); |
| 340 | gooddata.append(sl.at(2).toInt()); |
| 341 | RallWerte.append(sl.at(7).toDouble()*100.0); |
| 342 | alldata.append(sl.at(10).toInt()); |
| 343 | //R1(Free) = |
| 344 | QStringList slfree = inhalt.section("REM R1(Free) =",1).section("\n",0,0).trimmed().split(" ",skipEmptyParts); |
| 345 | if (slfree.size()>1){ |
| 346 | FreeWerte[RWerte.size()-1]=slfree.at(0).toDouble()*100; |
| 347 | } |
| 348 | |
| 349 | sl = inhalt.section("REM R1 =",1).section("\n",1,1).trimmed().split(" ",skipEmptyParts); |
| 350 | if (sl.size()<2) return; |
| 351 | parameters.append(sl.at(1).toInt()); |
| 352 | saveFilesList.append(alt.fileName()); |
| 353 | dateTimesList.append(QFileInfo(alt.fileName()).lastModified()); |
| 354 | }} |
| 355 | |
| 356 | |
| 357 | update(); |
| 358 | } |
| 359 | |
| 360 | QColor HistoryWidget::rwert_farbverlauf(double wrt){ |
| 361 | int rot,gruen,blau,alpha; |
| 362 | int lauf=0; |
| 363 | const float farbe[6][4]={ |
| 364 | {0.0f,0.6f,0.0f,1.0f}, |
| 365 | {0.0f,0.6f,1.0f,1.0f}, |
| 366 | {0.0f,0.0f,1.0f,1.0f}, |
| 367 | {0.7f,0.6f,0.0f,1.0f}, |
| 368 | {0.7f,0.0f,1.0f,1.0f}, |
| 369 | {0.7f,0.0f,0.0f,1.0f}}; |
| 370 | double nwrt=(wrt)/(100); |
| 371 | nwrt=(nwrt>=1.0)?0.99999:nwrt; |
| 372 | nwrt=(nwrt<=0.0)?0.00001:nwrt; |
| 373 | lauf=(int (nwrt/0.2)); |
| 374 | nwrt-=(0.2*lauf); |
| 375 | nwrt/=(0.2); |
| 376 | |
| 377 | rot=(int)(255*((1.0-nwrt)*farbe[lauf][0]+farbe[lauf+1][0]*nwrt)); |
| 378 | gruen=(int)(255*((1.0-nwrt)*farbe[lauf][1]+farbe[lauf+1][1]*nwrt)); |
| 379 | blau=(int)(255*((1.0-nwrt)*farbe[lauf][2]+farbe[lauf+1][2]*nwrt)); |
| 380 | alpha=255; |
| 381 | return QColor(rot,gruen,blau,alpha); |
| 382 | } |
| 383 | |
| 384 | void HistoryWidget::paintEvent(QPaintEvent *event){ |
| 385 | double x =0; |
| 386 | for (int i=0; i<RWerte.size(); i++){ |
| 387 | x = qMax(RWerte.at(i),x); |
| 388 | if (FreeWerte.contains(i)) |
| 389 | x = qMax(FreeWerte.value(i),x); |
| 390 | } |
| 391 | QPainter p(this); |
| 392 | #if (QT_VERSION >=0x050000) |
| 393 | setMinimumWidth(qMax(p.fontMetrics().horizontalAdvance(QString("%1").arg(x,4,'f',3))*RWerte.size(),maxwid)); |
| 394 | setMaximumWidth(qMax(p.fontMetrics().horizontalAdvance(QString("%1").arg(x,4,'f',3))*RWerte.size(),maxwid)); |
| 395 | #else |
| 396 | setMinimumWidth(qMax(p.fontMetrics().width(QString("%1").arg(x,4,'f',3))*RWerte.size(),maxwid)); |
| 397 | setMaximumWidth(qMax(p.fontMetrics().width(QString("%1").arg(x,4,'f',3))*RWerte.size(),maxwid)); |
| 398 | #endif |
| 399 | p.fillRect(0,0,width(),height(),QPalette().window());// );QColor("#eeeecc") |
| 400 | p.setPen(Qt::black); |
| 401 | |
| 402 | if (RWerte.isEmpty()) return; |
| 403 | int h = height(), w = width() / RWerte.size(); |
| 404 | fh=p.fontMetrics().height(); |
| 405 | //save History |
| 406 | p.setBrush(QBrush(QColor("#eeeecc"))); |
| 407 | p.drawRect(0,0,width(),fh); |
| 408 | p.drawText(0,0,width(),fh,Qt::AlignLeft,QString("Alternatively open the SaveHistory! (click here)"));// |
| 409 | // |
| 410 | p.drawText(0,fh,width(),fh,Qt::AlignLeft,QString("Total size of history on disk: %1%2") |
| 411 | .arg((gesamtGr/(1024*1024))?(double)gesamtGr/(1024*1024):(double)gesamtGr/1024,7,'f',1) |
| 412 | .arg((gesamtGr/(1024*1024))?"MB":"kB")); |
| 413 | double hupro=0; |
| 414 | for (int i = 0; i < RWerte.size(); i++){ |
| 415 | hupro=qMax(hupro,RWerte.at(i)); |
| 416 | } |
| 417 | hupro=(2*hupro); |
| 418 | for (int i = 0; i < RWerte.size(); i++){ |
| 419 | if (FreeWerte.contains(i)){ |
| 420 | p.setBrush(QBrush(rwert_farbverlauf(FreeWerte.value(i)*3))); |
| 421 | p.drawRect(i*w+5,qMax((int)(h-(FreeWerte.value(i)/hupro*h))-1,0),w*0.95-5,qMin((int)(FreeWerte.value(i)/hupro*h),h-2)); |
| 422 | } |
| 423 | p.setBrush(QBrush(rwert_farbverlauf(RWerte.at(i)*3))); |
| 424 | p.drawRect(i*w,qMax((int)(h-(RWerte.at(i)/hupro*h))-1,0),w*0.9,qMin((int)(RWerte.at(i)/hupro*h),h-2)); |
| 425 | if (FreeWerte.contains(i)){ |
| 426 | p.drawText(i*w, qMax((int)(h-(FreeWerte.value(i)/hupro*h)),fh+5)-fh-2, w,fh,Qt::AlignLeft, QString("%1") |
| 427 | .arg(RWerte.at(i),4,'f',2)); |
| 428 | |
| 429 | p.drawText(i*w, qMax((int)(h-((FreeWerte.value(i))/hupro*h))-fh,fh+5)-fh-2, w,fh,Qt::AlignLeft, QString("%1") |
| 430 | .arg(FreeWerte.value(i),4,'f',2)); |
| 431 | }else |
| 432 | p.drawText(i*w, qMax((int)(h-(RWerte.at(i)/hupro*h)),fh+5)-fh-2, w,fh,Qt::AlignLeft, QString("%1") |
| 433 | .arg(RWerte.at(i),4,'f',2)); |
| 434 | } |
| 435 | event->accept(); |
| 436 | //p.drawText(0,0,p.fontMetrics().width("1234567890"),p.fontMetrics().height(),Qt::AlignLeft,QString("%1 %2").arg(h).arg(w)); |
| 437 | } |
| 438 | |
| 439 | bool HistoryWidget::event(QEvent *event){ |
| 440 | if (!isVisible()) {event->ignore(); return false;} |
| 441 | if (event->type() == QEvent::ToolTip) { |
| 442 | QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event); |
| 443 | QPoint da = helpEvent->pos(); |
| 444 | if (da.y()<(fh+3))return true; |
| 445 | if (RWerte.isEmpty()) return true; |
| 446 | int w = width() / RWerte.size(); |
| 447 | int index = da.x() / w; |
| 448 | QString fcfname; |
| 449 | if ((index<0)||(index>=saveFilesList.size())) return true; |
| 450 | else fcfname=saveFilesList.at(index); |
| 451 | fcfname.replace(fcfname.size()-3,3,"fcf"); |
| 452 | bool fcfda=QFile::exists(fcfname); |
| 453 | if (FreeWerte.contains(index)){ |
| 454 | QToolTip::showText(helpEvent->globalPos(), |
| 455 | QString("<b>%4:</b><br> R1(Free) = <b>%9</b><br>R1 = <b>%1</b><br>R1all = <b>%2</b><br>Reflection/Parameter = <b>%3</b><br>Reflection = <b>%6</b><br>Parameter = <b>%7</b><br>FCF-File present: <b>%8</b><br>Last modified: <b>%5</b>") |
| 456 | .arg(RWerte.at(index)) |
| 457 | .arg(RallWerte.at(index)) |
| 458 | .arg(((index<gooddata.size())&&(index<parameters.size())) ?(double) gooddata.at(index) / parameters.at(index):0) |
| 459 | .arg((index<saveFilesList.size())?saveFilesList.at(index):0) |
| 460 | .arg((index<dateTimesList.size())?dateTimesList.at(index).toString("d MMM yyyy - hh:mm:ss"):"??") |
| 461 | .arg((index<gooddata.size())?gooddata.at(index):0) |
| 462 | .arg((index<parameters.size())?parameters.at(index):0) |
| 463 | .arg((fcfda)?"Yes":"No") |
| 464 | .arg(FreeWerte.value(index))); |
| 465 | |
| 466 | }else |
| 467 | QToolTip::showText(helpEvent->globalPos(), |
| 468 | QString("<b>%4:</b><br>R1 = <b>%1</b><br>R1all = <b>%2</b><br>Reflection/Parameter = <b>%3</b><br>Reflection = <b>%6</b><br>Parameter = <b>%7</b><br>FCF-File present: <b>%8</b><br>Last modified: <b>%5</b>") |
| 469 | .arg(RWerte.at(index)) |
| 470 | .arg(RallWerte.at(index)) |
| 471 | .arg(((index<gooddata.size())&&(index<parameters.size())) ?(double) gooddata.at(index) / parameters.at(index):0) |
| 472 | .arg((index<saveFilesList.size())?saveFilesList.at(index):0) |
| 473 | .arg((index<dateTimesList.size())?dateTimesList.at(index).toString("d MMM yyyy - hh:mm:ss"):"??") |
| 474 | .arg((index<gooddata.size())?gooddata.at(index):0) |
| 475 | .arg((index<parameters.size())?parameters.at(index):0) |
| 476 | .arg((fcfda)?"Yes":"No") |
| 477 | |
| 478 | ); |
| 479 | return true; |
| 480 | } |
| 481 | return QWidget::event(event); |
| 482 | } |