url unglue (url u, int nr) { if (is_atomic (u)) return as_url (tree (u->t->label (0, max (N(u->t->label) - nr, 0)))); if (is_concat (u)) return u[1] * unglue (u[2], nr); if (is_or (u)) return unglue (u[1], nr) | unglue (u[2], nr); failed_error << "u = " << u << "\n"; failed_error << "nr= " << nr << "\n"; FAILED ("can't unglue from url"); return u; }
void tm_frame_rep::choose_file (object fun, string title, string type, string prompt, url name) { command cb = dialogue_command (get_server(), fun, 1); widget wid = file_chooser_widget (cb, type, prompt); if (!is_scratch (name)) { set_directory (wid, as_string (head (name))); if ((type != "image") && (type != "")) { url u= tail (name); string old_suf= suffix (u); string new_suf= format_to_suffix (type); if ((suffix_to_format (suffix (u)) != type) && (old_suf != "") && (new_suf != "")) { u= unglue (u, N(old_suf) + 1); u= glue (u, "." * new_suf); } set_file (wid, as_string (u)); } } else set_directory (wid, "."); dialogue_start (title, wid); if (type == "directory") send_keyboard_focus (get_directory (dialogue_wid)); else send_keyboard_focus (get_file (dialogue_wid)); }
url get_from_server (url u) { if (!is_rooted_tmfs (u)) return url_none (); url res= get_cache (u); if (!is_none (res)) return res; string name= as_string (u); if (ends (name, "~") || ends (name, "#")) { if (!is_rooted_tmfs (name)) return url_none (); if (!as_bool (call ("tmfs-can-autosave?", unglue (u, 1)))) return url_none (); } string r= as_string (call ("tmfs-load", object (name))); if (r == "") return url_none (); url tmp= url_temp (); (void) save_string (tmp, r, true); //return set_cache (u, tmp); return tmp; // FIXME: certain files could be cached, but others not // for instance, files which are loaded in a delayed fashion // would always be cached as empty files, which is erroneous. }
void Global::createToolBars() { // ----- Tool modes ----- // Create toolbar toolBar_ = mainWindow()->addToolBar(tr("Toolbar")); toolBar_->setOrientation(Qt::Vertical); toolBar_->setMovable(false); mainWindow()->addToolBar(Qt::LeftToolBarArea, toolBar_); // Set toolbar size int iconWidth = 32; toolBar_->setIconSize(QSize(iconWidth,iconWidth)); currentColor_->setIconSize(QSize(iconWidth,iconWidth)); currentColor_->updateIcon(); // Create actions (exclusive checkable) QActionGroup * actionGroup = new QActionGroup(this); for(int i=0; i<NUMBER_OF_TOOL_MODES; i++) { toolModeActions[i] = new ToolModeAction(static_cast<ToolMode>(i), actionGroup); toolModeActions[i]->setCheckable(true); toolModeActions[i]->setShortcutContext(Qt::ApplicationShortcut); toolBar_->addAction(toolModeActions[i]); connect(toolModeActions[i], SIGNAL(triggered(Global::ToolMode)), this, SLOT(setToolMode(Global::ToolMode))); } // Select toolModeActions[SELECT]->setText(tr("Select and move (F1)")); toolModeActions[SELECT]->setIcon(QIcon(":/images/select.png")); toolModeActions[SELECT]->setStatusTip(tr("Select objects, move objects, glue objects together, and split curves.")); toolModeActions[SELECT]->setShortcut(QKeySequence(Qt::Key_F1)); // Sketch toolModeActions[SKETCH]->setText(tr("Sketch (F2)")); toolModeActions[SKETCH]->setIcon(QIcon(":/images/sketch.png")); toolModeActions[SKETCH]->setStatusTip(tr("Sketch curves.")); toolModeActions[SKETCH]->setShortcut(QKeySequence(Qt::Key_F2)); // Paint toolModeActions[PAINT]->setText(tr("Paint (F3)")); toolModeActions[PAINT]->setIcon(QIcon(":/images/paint.png")); toolModeActions[PAINT]->setStatusTip(tr("Paint an empty space or an existing object.")); toolModeActions[PAINT]->setShortcut(QKeySequence(Qt::Key_F3)); // Sculpt toolModeActions[SCULPT]->setText(tr("Sculpt (F4)")); toolModeActions[SCULPT]->setIcon(QIcon(":/images/sculpt.png")); toolModeActions[SCULPT]->setStatusTip(tr("Sculpt curves.")); toolModeActions[SCULPT]->setShortcut(QKeySequence(Qt::Key_F4)); // ----- Color selectors ----- // Colors colorSelectorAction_ = toolBar_->addWidget(currentColor_); colorSelectorAction_->setText(tr("Color")); colorSelectorAction_->setToolTip(tr("Color (C)")); colorSelectorAction_->setStatusTip(tr("Click to open the color selector")); colorSelectorAction_->setShortcut(QKeySequence(Qt::Key_C)); colorSelectorAction_->setShortcutContext(Qt::ApplicationShortcut); connect(colorSelectorAction_, SIGNAL(triggered()), currentColor_, SLOT(click())); // ----- Tool Options ----- toolModeToolBar_ = new QToolBar("Action Bar"); toolModeToolBar_->setIconSize(QSize(200,iconWidth)); toolModeToolBar_->setMovable(false); mainWindow()->addToolBar(toolModeToolBar_); // --------------------- Color ------------------------ actionChangeColor_ = new QAction(this); actionChangeColor_->setText(tr("Change color")); actionChangeColor_->setIcon(QIcon(":/images/change-color.png")); actionChangeColor_->setStatusTip(tr("Change the color of the selected cells")); //actionChangeColor_->setShortcut(QKeySequence(Qt::Key_C)); actionChangeColor_->setShortcutContext(Qt::ApplicationShortcut); mainWindow()->addAction(actionChangeColor_); connect(actionChangeColor_, SIGNAL(triggered()), mainWindow()->scene(), SLOT(changeColor())); // --------------------- Edges ------------------------ actionChangeEdgeWidth_ = new QAction(this); actionChangeEdgeWidth_->setText(tr("Change edge width (W)")); actionChangeEdgeWidth_->setIcon(QIcon(":/images/change-width.png")); actionChangeEdgeWidth_->setStatusTip(tr("Change the width of the selected edges")); actionChangeEdgeWidth_->setShortcut(QKeySequence(Qt::Key_W)); actionChangeEdgeWidth_->setShortcutContext(Qt::ApplicationShortcut); mainWindow()->addAction(actionChangeEdgeWidth_); connect(actionChangeEdgeWidth_, SIGNAL(triggered()), mainWindow()->scene(), SLOT(changeEdgeWidth())); // --------------------- Faces ------------------------ actionCreateFace_ = new QAction(this); actionCreateFace_->setText(tr("Create Face (F)")); actionCreateFace_->setIcon(QIcon(":/images/create-face.png")); actionCreateFace_->setStatusTip(tr("Create a face whose boundary is the selected edges")); actionCreateFace_->setShortcut(QKeySequence(Qt::Key_F)); actionCreateFace_->setShortcutContext(Qt::ApplicationShortcut); mainWindow()->addAction(actionCreateFace_); connect(actionCreateFace_, SIGNAL(triggered()), mainWindow()->scene(), SLOT(createFace())); actionAddCycles_ = new QAction(this); actionAddCycles_->setText(tr("Add Holes (H)")); actionAddCycles_->setIcon(QIcon(":/images/add-cycles.png")); actionAddCycles_->setStatusTip(tr("Add holes to the selected face, whose boundaries are the selected edges")); actionAddCycles_->setShortcut(QKeySequence(Qt::Key_H)); actionAddCycles_->setShortcutContext(Qt::ApplicationShortcut); mainWindow()->addAction(actionAddCycles_); connect(actionAddCycles_, SIGNAL(triggered()), mainWindow()->scene(), SLOT(addCyclesToFace())); actionRemoveCycles_ = new QAction(this); actionRemoveCycles_->setText(tr("Remove Holes (Ctrl+H)")); actionRemoveCycles_->setIcon(QIcon(":/images/remove-cycles.png")); actionRemoveCycles_->setStatusTip(tr("Remove holes from the selected face, whose boundaries are the selected edges")); actionRemoveCycles_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_H)); actionRemoveCycles_->setShortcutContext(Qt::ApplicationShortcut); mainWindow()->addAction(actionRemoveCycles_); connect(actionRemoveCycles_, SIGNAL(triggered()), mainWindow()->scene(), SLOT(removeCyclesFromFace())); // --------------------- Topological operations ------------------------ actionGlue_ = new QAction(this); actionGlue_->setText(tr("Glue")); actionGlue_->setToolTip(tr("Glue (G)")); actionGlue_->setIcon(QIcon(":/images/glue.png")); actionGlue_->setStatusTip(tr("Glue two endpoints or two curves together")); actionGlue_->setShortcut(QKeySequence(Qt::Key_G)); actionGlue_->setShortcutContext(Qt::ApplicationShortcut); mainWindow()->addAction(actionGlue_); connect(actionGlue_, SIGNAL(triggered()), mainWindow()->scene(), SLOT(glue())); actionUnglue_ = new QAction(this); actionUnglue_->setText(tr("Explode")); actionUnglue_->setToolTip(tr("Explode (E)")); actionUnglue_->setIcon(QIcon(":/images/unglue.png")); actionUnglue_->setStatusTip(tr("Duplicate the selected objects to disconnect adjacent curves and surfaces")); //actionUnglue_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_G)); actionUnglue_->setShortcut(QKeySequence(Qt::Key_E)); actionUnglue_->setShortcutContext(Qt::ApplicationShortcut); mainWindow()->addAction(actionUnglue_); connect(actionUnglue_, SIGNAL(triggered()), mainWindow()->scene(), SLOT(unglue())); actionUncut_ = new QAction(this); actionUncut_->setText(tr("Simplify")); actionUncut_->setToolTip(tr("Simplify (Backspace)")); actionUncut_->setIcon(QIcon(":/images/simplify.png")); actionUncut_->setStatusTip(tr("Simplify the selected objects, by merging curves and surfaces together")); actionUncut_->setShortcut(QKeySequence(Qt::Key_Backspace)); actionUncut_->setShortcutContext(Qt::ApplicationShortcut); mainWindow()->addAction(actionUncut_); connect(actionUncut_, SIGNAL(triggered()), mainWindow()->scene(), SLOT(uncut())); // Desired icon size double sideLength = 40; // --------------------- Shared actions/options ------------------------ // None // --------------------- Select options ------------------------ toolModeToolBar_->addAction(actionChangeColor_); toolModeToolBar_->addAction(actionChangeEdgeWidth_); separatorSelect1_ = toolModeToolBar_->addSeparator(); toolModeToolBar_->addAction(actionCreateFace_); toolModeToolBar_->addAction(actionAddCycles_); toolModeToolBar_->addAction(actionRemoveCycles_); separatorSelect2_ = toolModeToolBar_->addSeparator(); toolModeToolBar_->widgetForAction(actionChangeColor_)->setFixedSize(sideLength,sideLength); toolModeToolBar_->widgetForAction(actionChangeEdgeWidth_)->setFixedSize(sideLength,sideLength); toolModeToolBar_->widgetForAction(actionCreateFace_)->setFixedSize(sideLength,sideLength); toolModeToolBar_->widgetForAction(actionAddCycles_)->setFixedSize(sideLength,sideLength); toolModeToolBar_->widgetForAction(actionRemoveCycles_)->setFixedSize(sideLength,sideLength); toolModeToolBar_->addAction(actionGlue_); toolModeToolBar_->addAction(actionUnglue_); toolModeToolBar_->addAction(actionUncut_); toolModeToolBar_->widgetForAction(actionGlue_)->setFixedSize(sideLength+20,sideLength); toolModeToolBar_->widgetForAction(actionUnglue_)->setFixedSize(sideLength+20,sideLength); toolModeToolBar_->widgetForAction(actionUncut_)->setFixedSize(sideLength+20,sideLength); // --------------------- Sketch options ------------------------ // Tablet pressure actionUseTabletPressure_ = new QAction(this); actionUseTabletPressure_->setCheckable(true); actionUseTabletPressure_->setChecked(true); toolModeToolBar_->addAction(actionUseTabletPressure_); toolModeToolBar_->widgetForAction(actionUseTabletPressure_)->setFixedSize(sideLength,sideLength); actionUseTabletPressure_->setText(tr("Toggle stylus pressure")); actionUseTabletPressure_->setIcon(QIcon(":/images/pressure.png")); actionUseTabletPressure_->setStatusTip(tr("Enable or disable stylus pressure (only for users with a pen tablet)")); //actionUseTabletPressure_->setShortcut(QKeySequence(Qt::Key_Backspace)); actionUseTabletPressure_->setShortcutContext(Qt::ApplicationShortcut); mainWindow()->addAction(actionUseTabletPressure_); connect(actionUseTabletPressure_, SIGNAL(triggered()), this, SLOT(toggleStylusPressure())); // Edge width edgeWidth_ = new SpinBox(); edgeWidth_->setCaption(tr(" pen width ")); edgeWidth_->setValue(settings().edgeWidth()); actionEdgeWidth_ = toolModeToolBar_->addWidget(edgeWidth_); connect(edgeWidth_, SIGNAL(valueChanged(double)), this, SLOT(setEdgeWidth_(double))); // Separator separatorSketch1_ = toolModeToolBar_->addSeparator(); // Planar map mode actionPlanarMapMode_ = new QAction(this); actionPlanarMapMode_->setCheckable(true); actionPlanarMapMode_->setChecked(true); toolModeToolBar_->addAction(actionPlanarMapMode_); toolModeToolBar_->widgetForAction(actionPlanarMapMode_)->setFixedSize(110,sideLength); actionPlanarMapMode_->setText(tr("Toggle intersections")); actionPlanarMapMode_->setIcon(QIcon(":/images/planar-map-on.png")); actionPlanarMapMode_->setStatusTip(tr("When intersections are enabled, the sketched curve automatically splits existing curves and surfaces.")); //actionPlanarMapMode_->setShortcut(QKeySequence(Qt::Key_Backspace)); actionPlanarMapMode_->setShortcutContext(Qt::ApplicationShortcut); mainWindow()->addAction(actionPlanarMapMode_); connect(actionPlanarMapMode_, SIGNAL(triggered()), this, SLOT(togglePlanarMapMode())); // Separator separatorSketch2_ = toolModeToolBar_->addSeparator(); // Snapping actionSnapMode_ = new QAction(this); actionSnapMode_->setCheckable(true); actionSnapMode_->setChecked(true); toolModeToolBar_->addAction(actionSnapMode_); toolModeToolBar_->widgetForAction(actionSnapMode_)->setFixedSize(110,sideLength); actionSnapMode_->setText(tr("Toggle snapping")); actionSnapMode_->setIcon(QIcon(":/images/snapping-on.png")); actionSnapMode_->setStatusTip(tr("When snapping is enabled, the sketched curve is automatically glued to existing curves.")); //actionSnapMode_->setShortcut(QKeySequence(Qt::Key_Backspace)); actionSnapMode_->setShortcutContext(Qt::ApplicationShortcut); mainWindow()->addAction(actionSnapMode_); connect(actionSnapMode_, SIGNAL(triggered()), this, SLOT(toggleSnapping())); // Edge width actionSnapThreshold_ = toolModeToolBar_->addWidget(snapThreshold_); // --------------------- Sculpt options ------------------------ actionSculptRadius_ = toolModeToolBar_->addWidget(sculptRadius_); // --------------------- Cut options ------------------------ // Set default Tool Mode setToolMode(SKETCH); }