bool PathGroups::keyPressEvent(QKeyEvent *event) { for(int i=0; i<m_paths.count(); i++) { if (m_paths[i]->grabsMouse()) { if (event->key() == Qt::Key_G) { m_paths[i]->removeFromMouseGrabberPool(); return true; } if (event->key() == Qt::Key_C) { bool b = m_paths[i]->closed(); m_paths[i]->setClosed(!b); return true; } else if (event->key() == Qt::Key_P) { bool b = m_paths[i]->showPoints(); m_paths[i]->setShowPoints(!b); return true; } else if (event->key() == Qt::Key_L) { bool b = m_paths[i]->showLength(); m_paths[i]->setShowLength(!b); return true; } else if (event->key() == Qt::Key_X) { m_paths[i]->setMoveAxis(PathGroupGrabber::MoveX); return true; } else if (event->key() == Qt::Key_Y) { if (event->modifiers() & Qt::ControlModifier || event->modifiers() & Qt::MetaModifier) m_paths[i]->redo(); else m_paths[i]->setMoveAxis(PathGroupGrabber::MoveY); return true; } else if (event->key() == Qt::Key_Z) { if (event->modifiers() & Qt::ControlModifier || event->modifiers() & Qt::MetaModifier) m_paths[i]->undo(); else m_paths[i]->setMoveAxis(PathGroupGrabber::MoveZ); return true; } else if (event->key() == Qt::Key_W) { m_paths[i]->setMoveAxis(PathGroupGrabber::MoveAll); return true; } else if (event->key() == Qt::Key_S) { int idx = m_paths[i]->pointPressed(); if (idx > -1) { float radx = m_paths[i]->getRadX(idx); if (event->modifiers() & Qt::ShiftModifier) radx--; else radx++; radx = qMax(1.0f, radx); m_paths[i]->setRadX(idx, radx, m_sameForAll); return true; } } else if (event->key() == Qt::Key_T) { int idx = m_paths[i]->pointPressed(); if (idx > -1) { float rady = m_paths[i]->getRadY(idx); if (event->modifiers() & Qt::ShiftModifier) rady--; else rady++; rady = qMax(1.0f, rady); m_paths[i]->setRadY(idx, rady, m_sameForAll); } else // switch to tube mode { if (event->modifiers() & Qt::ShiftModifier) { m_paths[i]->loadCaption(); } else { bool b = m_paths[i]->tube(); m_paths[i]->setTube(!b); } } return true; } else if (event->key() == Qt::Key_A) { int idx = m_paths[i]->pointPressed(); if (idx > -1) { float a = m_paths[i]->getAngle(idx); if (event->modifiers() & Qt::ShiftModifier) a--; else a++; m_paths[i]->setAngle(idx, a, m_sameForAll); return true; } } else if (event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Backtab) { m_paths[i]->removeFromMouseGrabberPool(); m_paths.removeAt(i); return true; } if (event->key() == Qt::Key_Space) { PropertyEditor propertyEditor; QMap<QString, QVariantList> plist; QVariantList vlist; vlist.clear(); vlist << QVariant("double"); vlist << QVariant(m_paths[i]->opacity()); vlist << QVariant(0.0); vlist << QVariant(1.0); vlist << QVariant(0.1); // singlestep vlist << QVariant(1); // decimals plist["opacity"] = vlist; vlist.clear(); vlist << QVariant("colorgradient"); QGradientStops stops = m_paths[i]->stops(); for(int s=0; s<stops.size(); s++) { float pos = stops[s].first; QColor color = stops[s].second; int r = color.red(); int g = color.green(); int b = color.blue(); int a = color.alpha(); vlist << QVariant(pos); vlist << QVariant(r); vlist << QVariant(g); vlist << QVariant(b); vlist << QVariant(a); } plist["color"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->filterPathLen()); plist["filter on length"] = vlist; float vmin, vmax; m_paths[i]->userPathlenMinmax(vmin, vmax); vlist.clear(); vlist << QVariant("string"); vlist << QVariant(QString("%1 %2").arg(vmin).arg(vmax)); plist["length bounds"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->scaleType()); plist["scale type"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->depthcue()); plist["depthcue"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(m_paths[i]->segments()); vlist << QVariant(1); vlist << QVariant(100); plist["smoothness"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(m_paths[i]->sections()); vlist << QVariant(1); vlist << QVariant(100); plist["sections"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(m_paths[i]->sparseness()); vlist << QVariant(1); vlist << QVariant(100); plist["sparseness"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(m_paths[i]->separation()); vlist << QVariant(0); vlist << QVariant(10); plist["screen separation"] = vlist; vlist.clear(); vlist << QVariant("combobox"); vlist << QVariant(m_paths[i]->capType()); vlist << QVariant("flat"); vlist << QVariant("round"); vlist << QVariant("arrow"); plist["cap style"] = vlist; vlist.clear(); vlist << QVariant("combobox"); vlist << QVariant(m_paths[i]->arrowDirection()); vlist << QVariant("forward"); vlist << QVariant("backward"); plist["arrow direction"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->animate()); plist["animate"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->allowInterpolate()); plist["interpolate"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(m_paths[i]->animateSpeed()); vlist << QVariant(10); vlist << QVariant(100); plist["animation speed"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->arrowForAll()); plist["arrows for all"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_sameForAll); plist["same for all"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->clip()); plist["clip"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->allowEditing()); plist["allow editing"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_paths[i]->blendMode()); plist["blend with volume"] = vlist; vlist.clear(); plist["command"] = vlist; vlist.clear(); QFile helpFile(":/pathgroups.help"); if (helpFile.open(QFile::ReadOnly)) { QTextStream in(&helpFile); QString line = in.readLine(); while (!line.isNull()) { if (line == "#begin") { QString keyword = in.readLine(); QString helptext; line = in.readLine(); while (!line.isNull()) { helptext += line; helptext += "\n"; line = in.readLine(); if (line == "#end") break; } vlist << keyword << helptext; } line = in.readLine(); } } plist["commandhelp"] = vlist; vlist.clear(); QString mesg; float pmin, pmax; m_paths[i]->pathlenMinmax(pmin, pmax); mesg = QString("min/max path lengths : %1 %2\n").arg(pmin).arg(pmax); float mins,maxs; mins = m_paths[i]->minScale(); maxs = m_paths[i]->maxScale(); mesg += QString("min/max scale : %1 %2\n").arg(mins).arg(maxs); vlist << mesg; plist["message"] = vlist; QStringList keys; keys << "color"; keys << "opacity"; keys << "depthcue"; keys << "gap"; keys << "filter on length"; keys << "length bounds"; keys << "scale type"; keys << "gap"; keys << "smoothness"; keys << "sections"; keys << "sparseness"; keys << "screen separation"; keys << "gap"; keys << "cap style"; keys << "arrow direction"; keys << "arrows for all"; keys << "gap"; keys << "animate"; keys << "interpolate"; keys << "animation speed"; keys << "gap"; keys << "same for all"; keys << "clip"; keys << "blend with volume"; keys << "allow editing"; keys << "command"; keys << "commandhelp"; keys << "message"; propertyEditor.set("Path Group Parameters", plist, keys); QMap<QString, QPair<QVariant, bool> > vmap; if (propertyEditor.exec() == QDialog::Accepted) vmap = propertyEditor.get(); else return true; keys = vmap.keys(); for(int ik=0; ik<keys.count(); ik++) { QPair<QVariant, bool> pair = vmap.value(keys[ik]); if (pair.second) { if (keys[ik] == "color") { QGradientStops stops = propertyEditor.getGradientStops(keys[ik]); m_paths[i]->setStops(stops); } else if (keys[ik] == "opacity") m_paths[i]->setOpacity(pair.first.toDouble()); else if (keys[ik] == "scale type") m_paths[i]->setScaleType(pair.first.toBool()); else if (keys[ik] == "sections") m_paths[i]->setSections(pair.first.toInt()); else if (keys[ik] == "smoothness") m_paths[i]->setSegments(pair.first.toInt()); else if (keys[ik] == "sparseness") m_paths[i]->setSparseness(pair.first.toInt()); else if (keys[ik] == "screen separation") m_paths[i]->setSeparation(pair.first.toInt()); else if (keys[ik] == "depthcue") m_paths[i]->setDepthcue(pair.first.toBool()); else if (keys[ik] == "animate") m_paths[i]->setAnimate(pair.first.toBool()); else if (keys[ik] == "interpolate") m_paths[i]->setAllowInterpolate(pair.first.toBool()); else if (keys[ik] == "animation speed") m_paths[i]->setAnimateSpeed(pair.first.toInt()); else if (keys[ik] == "cap style") m_paths[i]->setCapType(pair.first.toInt()); else if (keys[ik] == "arrow direction") m_paths[i]->setArrowDirection(pair.first.toInt()); else if (keys[ik] == "arrows for all") m_paths[i]->setArrowForAll(pair.first.toBool()); else if (keys[ik] == "same for all") { m_sameForAll = pair.first.toBool(); m_paths[i]->setSameForAll(m_sameForAll); } else if (keys[ik] == "clip") m_paths[i]->setClip(pair.first.toBool()); else if (keys[ik] == "allow editing") m_paths[i]->setAllowEditing(pair.first.toBool()); else if (keys[ik] == "blend with volume") m_paths[i]->setBlendMode(pair.first.toBool()); else if (keys[ik] == "filter on length") m_paths[i]->setFilterPathLen(pair.first.toBool()); else if (keys[ik] == "length bounds") { QString vstr = pair.first.toString(); QStringList vl = vstr.split(" ", QString::SkipEmptyParts); if (vl.count() == 2) m_paths[i]->setUserPathlenMinmax(vl[0].toDouble(), vl[1].toDouble()); } } } QString cmd = propertyEditor.getCommandString(); if (!cmd.isEmpty()) processCommand(i, cmd); updateGL(); } } } return true; }
bool MeshGenerator::getValues(int &depth, int &fillValue, bool &checkForMore, bool &lookInside, QGradientStops &stops, bool doBorder, int &chan, bool &avgColor) { chan = 0; depth = 1; fillValue = -1; checkForMore = true; lookInside = false; avgColor = false; m_useTagColors = false; m_scaleModel = 1.0; QGradientStops vstops; vstops << QGradientStop(0.0, QColor(50 ,50 ,50 ,255)) << QGradientStop(0.5, QColor(200,150,100,255)) << QGradientStop(1.0, QColor(255,255,255,255)); if (doBorder) fillValue = 0; PropertyEditor propertyEditor; QMap<QString, QVariantList> plist; QVariantList vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(avgColor); plist["average color"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(m_useTagColors); plist["apply tag colors"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(chan); vlist << QVariant(0); vlist << QVariant(2); plist["mop channel"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(depth); vlist << QVariant(0); vlist << QVariant(200); plist["depth"] = vlist; vlist.clear(); vlist << QVariant("int"); vlist << QVariant(fillValue); vlist << QVariant(-1); vlist << QVariant(255); plist["fillvalue"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(checkForMore); plist["greater"] = vlist; vlist.clear(); vlist << QVariant("checkbox"); vlist << QVariant(lookInside); plist["look inside"] = vlist; vlist.clear(); vlist << QVariant("float"); vlist << QVariant(m_scaleModel); vlist << QVariant(0.001); vlist << QVariant(1.0); vlist << QVariant(0.005); // singlestep vlist << QVariant(3); // decimals plist["scale"] = vlist; vlist.clear(); vlist << QVariant("colorgradient"); for(int s=0; s<vstops.size(); s++) { float pos = vstops[s].first; QColor color = vstops[s].second; int r = color.red(); int g = color.green(); int b = color.blue(); int a = color.alpha(); vlist << QVariant(pos); vlist << QVariant(r); vlist << QVariant(g); vlist << QVariant(b); vlist << QVariant(a); } plist["color gradient"] = vlist; vlist.clear(); QFile helpFile(":/mesh.help"); if (helpFile.open(QFile::ReadOnly)) { QTextStream in(&helpFile); QString line = in.readLine(); while (!line.isNull()) { if (line == "#begin") { QString keyword = in.readLine(); QString helptext; line = in.readLine(); while (!line.isNull()) { helptext += line; helptext += "\n"; line = in.readLine(); if (line == "#end") break; } vlist << keyword << helptext; } line = in.readLine(); } } plist["commandhelp"] = vlist; vlist.clear(); QString mesg; mesg += "File : "+m_vfm->fileName()+"\n"; int d = m_vfm->depth(); int w = m_vfm->width(); int h = m_vfm->height(); mesg += QString("Volume Size : %1 %2 %3\n").arg(h).arg(w).arg(d); mesg += QString("Data Min : %1 %2 %3\n").arg(m_dataMin.x).arg(m_dataMin.y).arg(m_dataMin.z); mesg += QString("Data Max : %1 %2 %3\n").arg(m_dataMax.x).arg(m_dataMax.y).arg(m_dataMax.z); if (m_voxelType > 0) mesg += "\n ** Only opacity based surface generation available for unsigned short data **\n"; mesg += "\n* You can keep on working while this process is running.\n"; vlist << mesg; plist["message"] = vlist; QStringList keys; keys << "average color"; keys << "apply tag colors"; keys << "mop channel"; keys << "isosurface value"; keys << "depth"; keys << "fillvalue"; keys << "scale"; keys << "greater"; keys << "look inside"; keys << "color gradient"; keys << "commandhelp"; keys << "message"; propertyEditor.set("Mesh Repainting Parameters", plist, keys); QMap<QString, QPair<QVariant, bool> > vmap; if (propertyEditor.exec() == QDialog::Accepted) vmap = propertyEditor.get(); else return false; for(int ik=0; ik<keys.count(); ik++) { QPair<QVariant, bool> pair = vmap.value(keys[ik]); if (pair.second) { if (keys[ik] == "average color") avgColor = pair.first.toBool(); else if (keys[ik] == "apply tag colors") m_useTagColors = pair.first.toBool(); else if (keys[ik] == "mop channel") chan = pair.first.toInt(); else if (keys[ik] == "color gradient") vstops = propertyEditor.getGradientStops(keys[ik]); else if (keys[ik] == "scale") m_scaleModel = pair.first.toFloat(); else if (keys[ik] == "depth") depth = pair.first.toInt(); else if (keys[ik] == "fillvalue") fillValue = pair.first.toInt(); else if (keys[ik] == "greater") checkForMore = pair.first.toBool(); else if (keys[ik] == "look inside") lookInside = pair.first.toBool(); } } stops = resampleGradientStops(vstops); return true; }