Exemple #1
0
void veta_handleevent(event_t *event){
	switch(event->type){
		case QUIT:
			uk_log("Quit");
			ui_quit();
			break;
		case RESET:
			uk_log("Reset");
			clear_selection(root_cell);
			veta_render();
			break;
		case SELECT_CELL:
			uk_log("select cell %i",event->cell);
//			debug_print_tree(root);
			select_cell(root_cell,event->cell);
			symbol *sym;
			if(NULL!=(sym=get_selected_symbol(root_cell))){
				clear_selection(root_cell);
				if(ui2_onselect_symbol(sym)) break;
				sendkey(sym->data,1,0);
			}
			refresh();
			break;
		case UNDEFINED:
			uk_log("got event UNDEFINED\n"); 
			break;
		default:
			uk_log("WARNING undefined event type");
			break;
	}
}
Exemple #2
0
static void
sync_selection_shapes_to_view(GwyCoordsView *view)
{
    CoordsView *priv = view->priv;

    GwyShapes *shapes = priv->shapes;
    if (!shapes) {
        clear_selection(view);
        return;
    }

    guint n = 0, len = gwy_coords_size(priv->coords);
    const GwyIntRange *ranges = gwy_int_set_ranges(priv->shapes_selection, &n);
    if (!n) {
        clear_selection(view);
        return;
    }

    GtkTreeView *treeview = GTK_TREE_VIEW(view);
    GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
    priv->sync_shapes_to_view = TRUE;
    select_or_unselect_range(selection, 0, ranges[0].from, FALSE);
    for (guint i = 0; ; i++) {
        select_or_unselect_range(selection, ranges[i].from, ranges[i].to, TRUE);
        if (i == n-1)
            break;
        select_or_unselect_range(selection, ranges[i].to, ranges[i+1].from,
                                 FALSE);
    }
    select_or_unselect_range(selection, ranges[n-1].to, len, FALSE);
    priv->sync_shapes_to_view = FALSE;
}
static void
restore_cursor (ETreeSelectionModel *etsm,
                ETreeModel *etm)
{
	clear_selection (etsm);
	etsm->priv->cursor_path = NULL;

	if (etsm->priv->cursor_save_id) {
		etsm->priv->cursor_path = e_tree_model_get_node_by_id (
			etm, etsm->priv->cursor_save_id);
		if (etsm->priv->cursor_path != NULL && etsm->priv->cursor_col == -1)
			etsm->priv->cursor_col = 0;

		select_single_path (etsm, etsm->priv->cursor_path);
	}

	e_selection_model_selection_changed (E_SELECTION_MODEL (etsm));

	if (etsm->priv->cursor_path) {
		gint cursor_row = get_cursor_row (etsm);
		e_selection_model_cursor_changed (
			E_SELECTION_MODEL (etsm),
			cursor_row, etsm->priv->cursor_col);
	} else {
		e_selection_model_cursor_changed (
			E_SELECTION_MODEL (etsm), -1, -1);
		e_selection_model_cursor_activated (
			E_SELECTION_MODEL (etsm), -1, -1);

	}

	free_id (etsm);
}
static void
tree_selection_model_select_all (ESelectionModel *selection)
{
	ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
	ETreePath root;

	root = e_tree_model_get_root (etsm->priv->model);
	if (root == NULL)
		return;

	clear_selection (etsm);

	/* We want to select ALL rows regardless of expanded state.
	 * ETreeTableAdapter pretends that collapsed rows don't exist,
	 * so instead we need to iterate over the ETreeModel directly. */

	e_tree_model_node_traverse (
		etsm->priv->model, root,
		tree_selection_model_traverse_cb,
		selection);

	if (etsm->priv->cursor_path == NULL)
		etsm->priv->cursor_path = e_tree_table_adapter_node_at_row (
			etsm->priv->etta, 0);

	e_selection_model_selection_changed (E_SELECTION_MODEL (etsm));

	e_selection_model_cursor_changed (
		E_SELECTION_MODEL (etsm),
		get_cursor_row (etsm), etsm->priv->cursor_col);
}
Exemple #5
0
void ViewWidget::mouse_left_press_event(QMouseEvent *event)
{
	(void)event;

	const bool ctrl_pressed =
		QApplication::keyboardModifiers() & Qt::ControlModifier;

	// Clear selection if control is not pressed and this item is unselected
	if ((!mouse_down_item_ || !mouse_down_item_->selected()) &&
		!ctrl_pressed)
		clear_selection();

	// Set the signal selection state if the item has been clicked
	if (mouse_down_item_) {
		if (ctrl_pressed)
			mouse_down_item_->select(!mouse_down_item_->selected());
		else
			mouse_down_item_->select(true);
	}

	// Save the offsets of any signals which will be dragged
	bool item_dragged = false;
	const auto items = this->items();
	for (auto &i : items)
		if (i->selected()) {
			item_dragged = true;
			i->drag();
		}

	// Do the background drag
	if (!item_dragged)
		drag();

	selection_changed();
}
/**
 * @brief Deletes an animation.
 *
 * The index of the selection may change, since animations are sorted
 * alphabetically.
 * Emits rowsAboutToBeRemoved(), removes the animation
 * and then emits rowsRemoved(), as required by QAbstractItemModel.
 *
 * Then, emits animation_deleted().
 *
 * Except for the deleted animation, the existing selection is preserved,
 * though the index of many animations can change.
 * The selection is cleared before the operations and restored after,
 * updated with the new index.
 *
 * @param index Index of the animation to delete.
 * @throws EditorException in case of error.
 */
void SpriteModel::delete_animation(const Index &index) {

  // Make some checks first.
  if (!animation_exists(index)) {
      throw EditorException(
            tr("Animation '%1' don't exists").arg(index.animation_name));
  }

  // Save and clear the selection since a lot of indexes may change.
  Index selection = get_selected_index();
  clear_selection();

  int animation_nb = get_animation_nb(index);

  // Delete the animation in the sprite file.
  sprite.remove_animation(index.animation_name.toStdString());

  // Rebuild indexes in the list model (indexes were shifted).
  build_index_map();

  // Call beginRemoveRows() as requested by QAbstractItemModel.
  beginRemoveRows(QModelIndex(), animation_nb, animation_nb);

  // Update our animation model list.
  animations.removeAt(animation_nb);

  // Notify people before restoring the selection, so that they have a
  // chance to know new indexes before receiving selection signals.
  endRemoveRows();
  emit animation_deleted(index);

  // Restore the selection.
  set_selected_index(selection);
}
Exemple #7
0
bool Mesh::complexify()
{
    if (selection != SELECTION_FACE)
        return false;

   float xyz[3] = {0}; 

   for (int v : face_selected.face->getVerts())
       for (int i = 0; i < 3; i++)
           xyz[i] += verts[v].getCoords()[i] / face_selected.face->getVerts().size();

   Vertex centroid = Vertex(xyz);
   centroid.set_deletable(true);

   addVerts(centroid);

   for (unsigned int i = 0; i < face_selected.face->getVerts().size(); i++)
   {
       Face* f = new Face();

       f->addVert(face_selected.face->getVerts()[i]);
       f->addVert(face_selected.face->getVerts()[(i + 1) % (face_selected.face->getVerts().size())]);
       f->addVert(verts.size() - 1);

       groups[face_selected.group_pos]->addFace(f);
   }

   groups[face_selected.group_pos]->eraseFaceAt(face_selected.face_pos);
   clear_selection();

   return true;
}
/**
 * @brief Changes the id of a dialog.
 *
 * The index of multiple dialogs may change, since they are sorted alphabetically.
 * In this case, emits rowsAboutToBeRemoved(), removes the dialog,
 * emits rowsRemoved() and rowsAboutToBeInserted(), adds the new dialog
 * and then emits rowsInserted(), as required by QAbstractItemModel.
 *
 * Then, emits dialog_id_changed(), no matter if the index has also changed.
 *
 * The selection is preserved, though the index of many dialogs can change.
 * The selection is cleared before the operations and restored after,
 * updated with the new indexes.
 *
 * @param id Id of an existing dialog.
 * @param new_id The new id to set.
 * @return The new id of the dialog.
 * @throws EditorException in case of error.
 */
QString DialogsModel::set_dialog_id(const QString& id, const QString& new_id) {

  if (new_id == id) {
    // Nothing to do.
    return id;
  }

  // Make some checks first.
  if (!dialog_exists(id)) {
    throw EditorException(tr("Dialog '%1' no exists").arg(id));
  }

  if (dialog_exists(new_id)) {
    throw EditorException(tr("Dialog '%1' already exists").arg(new_id));
  }

  if (!is_valid_id(new_id)) {
    throw EditorException(tr("Invalid dialog id: %1").arg(new_id));
  }

  // Save and clear the selection since a lot of indexes may change.
  QString old_selection = get_selected_id();
  clear_selection();

  // Change in to the strings file.
  resources.set_dialog_id(id.toStdString(), new_id.toStdString());

  // Remove from the indexed tree.
  QString parent_id;
  int index;
  if (dialog_tree.can_remove_key(id, parent_id, index)) {

    // Call beginRemoveRows() as requested by QAbstractItemModel.
    beginRemoveRows(id_to_index(parent_id), index, index);
    dialog_tree.remove_key(id);
    endRemoveRows();
  } else if (dialog_tree.remove_key(id)) {
    QModelIndex model_index = id_to_index(id);
    dataChanged(model_index, model_index);
  }

  // Add to the indexed tree.
  if (dialog_tree.add_key(new_id, parent_id, index)) {

    // Call beginInsertRows() as requested by QAbstractItemModel.
    beginInsertRows(id_to_index(parent_id), index, index);
    endInsertRows();
  } else {
    QModelIndex model_index = id_to_index(id);
    dataChanged(model_index, model_index);
  }

  // Notify people.
  emit dialog_id_changed(id, new_id);

  // Restore the selection.
  set_selected_id(old_selection);
  return new_id;
}
Exemple #9
0
void CL_ListView::clear()
{
	impl->cancel_edit();

	clear_selection();
	impl->document_item.remove_children();
	request_repaint();
}
/**
 * @brief Selects a dialog and deselects all others.
 * @param id The id to select.
 */
void DialogsModel::set_selected_id(const QString& id) {

  if (!dialog_tree.key_exists(id)) {
    return clear_selection();
  }

  selection_model.select(id_to_index(id), QItemSelectionModel::ClearAndSelect);
}
static void
select_single_path (ETreeSelectionModel *etsm,
                    ETreePath path)
{
	clear_selection (etsm);
	change_one_path (etsm, path, TRUE);
	etsm->priv->cursor_path = path;
	etsm->priv->start_path = NULL;
}
Exemple #12
0
bool editor_map::set_selection(const std::set<map_location>& area)
{
	clear_selection();
	BOOST_FOREACH(const map_location& loc, area) {
		if (!add_to_selection(loc))
			return false;
	}
	return true;
}
/**
 * @brief Moves a direction.
 * @param index Index of the direction to move.
 * @param new_direction_nb The new number of the direction.
 * @throws EditorException in case of error.
 */
void SpriteModel::move_direction(const Index& index, int new_direction_nb) {

  if (new_direction_nb == index.direction_nb) {
    // Nothing to do.
    return;
  }

  // Make some checks first.
  if (!direction_exists(index)) {
      QString nb = std::to_string(index.direction_nb).c_str();
      throw EditorException(
            tr("Direction %1 don't exists in animation '%2'").arg(
              nb, index.animation_name));
  }

  // Save and clear the selection.
  Index selection = get_selected_index();
  clear_selection();

  // Move the direction in the sprite file.
  get_animation(index).move_direction(index.direction_nb, new_direction_nb);

  // Call beginMoveRows() as requested by QAbstractItemModel.
  int above_row = new_direction_nb;
  if (new_direction_nb > index.direction_nb) {
    ++above_row;
  }
  QModelIndex model_index = get_model_index(Index(index.animation_name));
  beginMoveRows(model_index, index.direction_nb, index.direction_nb,
                model_index, above_row);

  // Update our animation model list.
  int animation_nb = get_animation_nb(index);
  animations[animation_nb].directions.move(index.direction_nb, new_direction_nb);

  // Update direction model indexes.
  int num_dir = animations[animation_nb].directions.size();
  for (int nb = 0; nb < num_dir; nb++) {
    animations[animation_nb].directions[nb].index->direction_nb = nb;
  }

  endMoveRows();

  // Notify people before restoring the selection, so that they have a
  // chance to know new indexes before receiving selection signals.
  emit direction_deleted(index);

  // Restore the selection.
  if (selection.direction_nb == index.direction_nb) {
    selection.direction_nb = new_direction_nb;
  }

  set_selected_index(selection);
}
static void
tree_selection_model_clear (ESelectionModel *selection)
{
	ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);

	clear_selection (etsm);

	etsm->priv->cursor_path = NULL;
	e_selection_model_selection_changed (E_SELECTION_MODEL (etsm));
	e_selection_model_cursor_changed (E_SELECTION_MODEL (etsm), -1, -1);
}
Exemple #15
0
void CSSLayout::set_selection(CSSLayoutNode start, size_t start_text_offset, CSSLayoutNode end, size_t end_text_offset)
{
	impl->throw_if_disposed();
	if (start.is_null() || end.is_null())
	{
		clear_selection();
	}
	else
	{
		impl->box_tree.set_selection(start.impl->box_node, start_text_offset, end.impl->box_node, end_text_offset);
	}
}
Exemple #16
0
void veta_symbolsloaded(symbol *symbols,int n){
	if(n==0) return;
	symbolsloaded++;
	uk_log("Symbols are loaded got %i symbols",n);

	conf_save_symbols("platform_symbols.json",symbols,n);

	int cellsize=conf_get_int("n_columns",CELLS_W)*conf_get_int("n_rows",CELLS_H);

	root_cell=create_cells(symbols,n,cellsize,TREE_DEPTH,1);
	clear_selection(root_cell);
}
static void
tree_selection_model_finalize (GObject *object)
{
	ETreeSelectionModelPrivate *priv;

	priv = E_TREE_SELECTION_MODEL_GET_PRIVATE (object);

	clear_selection (E_TREE_SELECTION_MODEL (object));
	g_hash_table_destroy (priv->paths);

	/* Chain up to parent's finalize() method. */
	G_OBJECT_CLASS (e_tree_selection_model_parent_class)->finalize (object);
}
Exemple #18
0
void
__set_origin(unsigned short offset)
{
	unsigned long flags;

	clear_selection();

	save_flags(flags); cli();
	__origin = offset;
/* 	outb_p(12, video_port_reg); */
/* 	outb_p(offset >> 8, video_port_val); */
/* 	outb_p(13, video_port_reg); */
/* 	outb_p(offset, video_port_val); */
	restore_flags(flags);
}
static void
etsm_real_move_selection_end (ETreeSelectionModel *etsm,
                              gint row)
{
	ETreePath end_path;
	gint start;

	end_path = e_tree_table_adapter_node_at_row (etsm->priv->etta, row);
	g_return_if_fail (end_path);

	start = e_tree_table_adapter_row_of_node (
		etsm->priv->etta, etsm->priv->start_path);
	clear_selection (etsm);
	select_range (etsm, start, row);
}
/**
 * @brief Inserts a direction in an animation of this sprite.
 * @param index Index of the direction to insert.
 * @param data The direction data to insert.
 * @return Index of the inserted direction.
 * @throws EditorException in case of error.
 */
int SpriteModel::insert_direction(
    const Index& index, const SpriteAnimationDirectionData& data) {

  // Make some checks first.
  if (!animation_exists(index)) {
    throw EditorException(
            tr("Animation '%1' don't exists").arg(index.animation_name));
  }

  // Save and clear the selection.
  Index selection = get_selected_index();
  clear_selection();

  // Insert the direction to the sprite file.
  SpriteAnimationData& animation_data = get_animation(index);

  animation_data.add_direction(data);

  int last_dir = animation_data.get_num_directions() - 1;
  animation_data.move_direction(last_dir, index.direction_nb);

  int direction_nb = std::min(index.direction_nb, last_dir);

  // Call beginInsertRows() as requested by QAbstractItemModel.
  QModelIndex model_index = get_model_index(Index(index.animation_name));
  beginInsertRows(model_index, direction_nb, direction_nb);

  // Update our animation model list.
  int animation_nb = get_animation_nb(index);
  auto& directions = animations[animation_nb].directions;
  directions.insert(
        direction_nb, DirectionModel(index.animation_name, direction_nb));

  // Update direction model indexes.
  for (int nb = direction_nb + 1; nb < directions.size(); nb++) {
    directions[nb].index->direction_nb = nb;
  }

  // Notify people before restoring the selection, so that they have a
  // chance to know new indexes before receiving selection signals.
  endInsertRows();
  emit direction_added(Index(index.animation_name, direction_nb));

  // Restore the selection.
  set_selected_index(selection);

  return direction_nb;
}
/**
 * @brief Deletes a direction.
 * @param index Index of the direction to delete.
 * @throws EditorException in case of error.
 */
void SpriteModel::delete_direction(const Index &index) {

  // Make some checks first.
  if (!direction_exists(index)) {
      QString nb = std::to_string(index.direction_nb).c_str();
      throw EditorException(
            tr("Direction %1 don't exists in animation '%2'").arg(
              nb, index.animation_name));
  }

  // Save and clear the selection.
  Index selection = get_selected_index();
  if (selection.animation_name == index.animation_name &&
      selection.direction_nb == index.direction_nb) {
    selection.direction_nb = -1;
  }
  clear_selection();

  // Delete the direction in the sprite file.
  get_animation(index).remove_direction(index.direction_nb);

  // Call beginRemoveRows() as requested by QAbstractItemModel.
  QModelIndex model_index = get_model_index(Index(index.animation_name));
  beginRemoveRows(model_index, index.direction_nb, index.direction_nb);

  // Update our direction model list.
  int animation_nb = get_animation_nb(index);
  auto& directions = animations[animation_nb].directions;
  directions.removeAt(index.direction_nb);

  // Update direction model indexes.
  for (int nb = index.direction_nb; nb < directions.size(); nb++) {
    directions[nb].index->direction_nb = nb;
  }

  // Notify people before restoring the selection, so that they have a
  // chance to know new indexes before receiving selection signals.
  endRemoveRows();
  emit direction_deleted(index);

  // Restore the selection.
  set_selected_index(selection);
}
/**
 * @brief Inserts an animation in this sprite.
 *
 * The index of the selection may change, since animations are sorted
 * alphabetically.
 * Emits rowsAboutToBeInserted(), inserts the animation
 * and then emits rowsInserted(), as required by QAbstractItemModel.
 *
 * Then, emits animation_created().
 *
 * The newly created animation is not initially selected.
 * The existing selection is preserved, though the index of many
 * animations can change.
 * The selection is cleared before the operations and restored after,
 * updated with the new index.
 *
 * @param index Index of the animation to insert.
 * @param data Data of the animation.
 * @throws EditorException in case of error.
 */
void SpriteModel::insert_animation(
    const Index& index, const Solarus::SpriteAnimationData& data) {

  // Make some checks first.
  if (index.animation_name.length() <= 0) {
      throw EditorException(tr("Animation name cannot be empty"));
  }

  if (animation_exists(index)) {
      throw EditorException(
            tr("Animation '%1' already exists").arg(index.animation_name));
  }

  // Save and clear the selection since a lot of indexes may change.
  Index selection = get_selected_index();
  clear_selection();

  // Add the animation to the sprite file.
  sprite.add_animation(index.animation_name.toStdString(), data);

  // Rebuild indexes in the list model (indexes were shifted).
  build_index_map();

  // Call beginInsertRows() as requested by QAbstractItemModel.
  int animation_nb = get_animation_nb(index.animation_name);
  beginInsertRows(QModelIndex(), animation_nb, animation_nb);

  // Update our animation model list.
  animations.insert(animation_nb, AnimationModel(index.animation_name));
  int num_directions = data.get_num_directions();
  for (int nb = 0; nb < num_directions; nb++) {
    animations[animation_nb].directions.append(
          DirectionModel(index.animation_name, nb));
  }

  // Notify people before restoring the selection, so that they have a
  // chance to know new indexes before receiving selection signals.
  endInsertRows();
  emit animation_created(index);

  // Restore the selection.
  set_selected_index(selection);
}
/**
 * @brief Adds a direction in an animation of this sprite.
 * @param index Index of the animation to add the direction.
 * @param frame The first frame of the direction to create.
 * @return Index of the created direction.
 * @throws EditorException in case of error.
 */
int SpriteModel::add_direction(const Index& index, const QRect& frame) {

  // Make some checks first.
  if (!animation_exists(index)) {
    throw EditorException(
            tr("Animation '%1' don't exists").arg(index.animation_name));
  }

  // Save and clear the selection.
  Index selection = get_selected_index();
  clear_selection();

  // Add the direction to the sprite file.
  SpriteAnimationData& animation_data = get_animation(index);
  SpriteAnimationDirectionData direction(
        Point::to_solarus_point(frame.topLeft()),
        Size::to_solarus_size(frame.size()));

  animation_data.add_direction(direction);

  // Rebuild indexes in the list model (indexes were shifted).
  int direction_nb = animation_data.get_num_directions() - 1;

  // Call beginInsertRows() as requested by QAbstractItemModel.
  QModelIndex model_index = get_model_index(Index(index.animation_name));
  beginInsertRows(model_index, direction_nb, direction_nb);

  // Update our animation model list.
  int animation_nb = get_animation_nb(index);
  animations[animation_nb].directions.append(
        DirectionModel(index.animation_name, direction_nb));

  // Notify people before restoring the selection, so that they have a
  // chance to know new indexes before receiving selection signals.
  endInsertRows();
  emit direction_added(Index(index.animation_name, direction_nb));

  // Restore the selection.
  set_selected_index(selection);

  return direction_nb;
}
/**
 * @brief Deletes a dialog.
 *
 * The index of multiple dialogs may change, since they are sorted alphabetically.
 * Emits rowsAboutToBeRemoved(), removes the dialog
 * and then emits rowsRemoved(), as required by QAbstractItemModel.
 *
 * Then, emits dialog_deleted().
 *
 * Except for the deleted dialog, the existing selection is preserved,
 * though the index of many dialogs can change.
 * The selection is cleared before the operations and restored after,
 * updated with the new indexes.
 *
 * @param id Id of the dialog to delete.
 * @throws EditorException in case of error.
 */
void DialogsModel::delete_dialog(const QString& id) {

  // Make some checks first.
  if (!dialog_exists(id)) {
    throw EditorException(tr("Invalid dialog id: %1").arg(id));
  }

  // Save and clear the selection since a lot of indexes may change.
  QString old_selection = get_selected_id();
  clear_selection();

  // Delete from the strings file
  resources.remove_dialog(id.toStdString());

  // Remove from the indexed tree.
  QString parent_id;
  int index;
  if (dialog_tree.can_remove_key(id, parent_id, index)) {

    // Call beginRemoveRows() as requested by QAbstractItemModel.
    beginRemoveRows(id_to_index(parent_id), index, index);

    dialog_tree.remove_key(id);

    // Notify people before restoring the selection, so that they have a
    // chance to know new indexes before receiving selection signals.
    endRemoveRows();
  } else if (dialog_tree.remove_key(id)) {
    QModelIndex model_index = id_to_index(id);
    dataChanged(model_index, model_index);
  }

  // Notify people.
  emit dialog_deleted(id);

  // Restore the selection.
  set_selected_id(old_selection);
}
void RealPlayer::SelectThing(SelectTypes Thing){
    // makes the player "pick up" a potencial building
    // player does not pay for building, but it does chech if they have enough
    // match picture with selected building
    clear_selection();
    if (MiniTurn != 0)
        return;
    BuildingTypes Build = SelectToBuild(Thing);
    TInfo::TroopTypes TType = SelectToTroop(Thing);
    int Cost = 0;
    if (Build != NoBuild){
        Cost = GetBuildingCost(Build);
    }
    else if (TType != TInfo::NoType){
        Cost = TInfo::GetTroopCost(TType);
    }
    if (Cost > Money)
        MakeDialogue("Sorry, but you do not have enough money to purchace this", "Not Enough Money");
    else{
        fullscreen->emph->add_build_choice(Thing,Qt::blue);
        SelectedThing = Thing;
    }
}
/**
 * @brief Creates a new dialog.
 *
 * The index of the selection may change, since dialog are sorted
 * alphabetically.
 * Emits rowsAboutToBeInserted(), adds the new dialog
 * and then emits rowsInserted(), as required by QAbstractItemModel.
 *
 * Then, emits dialog_created().
 *
 * The newly created dialog is not initially selected.
 * The existing selection is preserved, though the index of many
 * dialogs can change.
 * The selection is cleared before the operations and restored after,
 * updated with the new index.
 *
 * @param id Id of the dialog to create.
 * @param data Data of the dialog to create.
 * @throws EditorException in case of error.
 */
void DialogsModel::create_dialog(const QString& id, const DialogData& data) {

  // Make some checks first.
  if (!is_valid_id(id)) {
      throw EditorException(tr("Invalid dialog id: %1").arg(id));
  }

  if (dialog_exists(id)) {
      throw EditorException(tr("Dialog '%1' already exists").arg(id));
  }

  // Save and clear the selection since a lot of indexes may change.
  QString old_selection = get_selected_id();
  clear_selection();

  // Add to the strings file.
  resources.add_dialog(id.toStdString(), data);

  // Update the indexed tree.
  QString parent_id;
  int index;
  if (dialog_tree.add_key(id, parent_id, index)) {
    // Notify people before restoring the selection, so that they have a
    // chance to know new indexes before receiving selection signals.
    beginInsertRows(id_to_index(parent_id), index, index);
    endInsertRows();
  } else {
    QModelIndex model_index = id_to_index(id);
    dataChanged(model_index, model_index);
  }

  // Notify people.
  emit dialog_created(id);

  // Restore the selection.
  set_selected_id(old_selection);
}
Exemple #27
0
static void
shapes_notify(GwyCoordsView *view,
              GParamSpec *pspec,
              GwyShapes *shapes)
{
    CoordsView *priv = view->priv;

    if (gwy_strequal(pspec->name, "coords"))
        set_coords(view, gwy_shapes_get_coords(shapes));
    else if (gwy_strequal(pspec->name, "editable"))
        priv->editable = gwy_shapes_get_editable(shapes);
    else if (gwy_strequal(pspec->name, "selectable")) {
        GtkTreeView *treeview = GTK_TREE_VIEW(view);
        GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
        if (gwy_shapes_get_selectable(shapes)) {
            gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
            sync_selection_shapes_to_view(view);
        }
        else {
            clear_selection(view);
            gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE);
        }
    }
}
Exemple #28
0
void Mesh::delete_selected_face()
{
    groups[face_selected.group_pos]->eraseFaceAt(face_selected.face_pos);
    clear_selection();
}
Exemple #29
0
/* set the current selection. Invoked by ioctl() or by kernel code. */
int set_selection(const struct tiocl_selection *sel, struct tty_struct *tty, int user)
{
	int sel_mode, new_sel_start, new_sel_end, spc;
	char *bp, *obp;
	int i, ps, pe;
	unsigned int currcons = fg_console;

	poke_blanked_console();

	{ unsigned short xs, ys, xe, ye;

	  if (user) {
		  if (verify_area(VERIFY_READ, sel, sizeof(*sel)))
		  	return -EFAULT;
		  __get_user(xs, &sel->xs);
		  __get_user(ys, &sel->ys);
		  __get_user(xe, &sel->xe);
		  __get_user(ye, &sel->ye);
		  __get_user(sel_mode, &sel->sel_mode);
	  } else {
		  xs = sel->xs; /* set selection from kernel */
		  ys = sel->ys;
		  xe = sel->xe;
		  ye = sel->ye;
		  sel_mode = sel->sel_mode;
	  }
	  xs--; ys--; xe--; ye--;
	  xs = limit(xs, video_num_columns - 1);
	  ys = limit(ys, video_num_lines - 1);
	  xe = limit(xe, video_num_columns - 1);
	  ye = limit(ye, video_num_lines - 1);
	  ps = ys * video_size_row + (xs << 1);
	  pe = ye * video_size_row + (xe << 1);

	  if (sel_mode == TIOCL_SELCLEAR) {
	      /* useful for screendump without selection highlights */
	      clear_selection();
	      return 0;
	  }

	  if (mouse_reporting() && (sel_mode & TIOCL_SELMOUSEREPORT)) {
	      mouse_report(tty, sel_mode & TIOCL_SELBUTTONMASK, xs, ys);
	      return 0;
	  }
        }

	if (ps > pe)	/* make sel_start <= sel_end */
	{
		int tmp = ps;
		ps = pe;
		pe = tmp;
	}

	if (sel_cons != fg_console) {
		clear_selection();
		sel_cons = fg_console;
	}

	switch (sel_mode)
	{
		case TIOCL_SELCHAR:	/* character-by-character selection */
			new_sel_start = ps;
			new_sel_end = pe;
			break;
		case TIOCL_SELWORD:	/* word-by-word selection */
			spc = isspace(sel_pos(ps));
			for (new_sel_start = ps; ; ps -= 2)
			{
				if ((spc && !isspace(sel_pos(ps))) ||
				    (!spc && !inword(sel_pos(ps))))
					break;
				new_sel_start = ps;
				if (!(ps % video_size_row))
					break;
			}
			spc = isspace(sel_pos(pe));
			for (new_sel_end = pe; ; pe += 2)
			{
				if ((spc && !isspace(sel_pos(pe))) ||
				    (!spc && !inword(sel_pos(pe))))
					break;
				new_sel_end = pe;
				if (!((pe + 2) % video_size_row))
					break;
			}
			break;
		case TIOCL_SELLINE:	/* line-by-line selection */
			new_sel_start = ps - ps % video_size_row;
			new_sel_end = pe + video_size_row
				    - pe % video_size_row - 2;
			break;
		case TIOCL_SELPOINTER:
			highlight_pointer(pe);
			return 0;
		default:
			return -EINVAL;
	}

	/* remove the pointer */
	highlight_pointer(-1);

	/* select to end of line if on trailing space */
	if (new_sel_end > new_sel_start &&
		!atedge(new_sel_end, video_size_row) &&
		isspace(sel_pos(new_sel_end))) {
		for (pe = new_sel_end + 2; ; pe += 2)
			if (!isspace(sel_pos(pe)) ||
			    atedge(pe, video_size_row))
				break;
		if (isspace(sel_pos(pe)))
			new_sel_end = pe;
	}
	if (sel_start == -1)	/* no current selection */
		highlight(new_sel_start, new_sel_end);
	else if (new_sel_start == sel_start)
	{
		if (new_sel_end == sel_end)	/* no action required */
			return 0;
		else if (new_sel_end > sel_end)	/* extend to right */
			highlight(sel_end + 2, new_sel_end);
		else				/* contract from right */
			highlight(new_sel_end + 2, sel_end);
	}
	else if (new_sel_end == sel_end)
	{
		if (new_sel_start < sel_start)	/* extend to left */
			highlight(new_sel_start, sel_start - 2);
		else				/* contract from left */
			highlight(sel_start, new_sel_start - 2);
	}
	else	/* some other case; start selection from scratch */
	{
		clear_selection();
		highlight(new_sel_start, new_sel_end);
	}
	sel_start = new_sel_start;
	sel_end = new_sel_end;

	/* Allocate a new buffer before freeing the old one ... */
	bp = kmalloc((sel_end-sel_start)/2+1, GFP_KERNEL);
	if (!bp) {
		printk(KERN_WARNING "selection: kmalloc() failed\n");
		clear_selection();
		return -ENOMEM;
	}
	if (sel_buffer)
		kfree(sel_buffer);
	sel_buffer = bp;

	obp = bp;
	for (i = sel_start; i <= sel_end; i += 2) {
		*bp = sel_pos(i);
		if (!isspace(*bp++))
			obp = bp;
		if (! ((i + 2) % video_size_row)) {
			/* strip trailing blanks from line and add newline,
			   unless non-space at end of line. */
			if (obp != bp) {
				bp = obp;
				*bp++ = '\r';
			}
			obp = bp;
		}
	}
	sel_buffer_lth = bp - sel_buffer;
	return 0;
}
void editor_map::select_all()
{
	clear_selection();
	invert_selection();
}