void level_editor_widget::modify_sprite_properties_widget_at_tab_switch()
{
	s32 curr_tab_index = get_curr_level_editor_core_widget_index();
	
	if ( curr_tab_index == -1 )
	{
		return;
	}
	
	if ( sprite_properties_widget_enabled_vec.empty() )
	{
		return;
	}
	
	
	// Hide the_sprite_properties_widget if it has been allocated for a
	// different sublevel/tab.
	if ( the_sprite_properties_widget.get() != NULL )
	{
		the_sprite_properties_widget->hide();
		
		the_sprite_properties_widget.reset(NULL);
	}
	
	
	u32& sprite_properties_widget_enabled 
		= sprite_properties_widget_enabled_vec.at(curr_tab_index);
	
	// If the_sprite_properties_widget was previously enabled for the tab
	// to which we are switching, then re-generate it.
	if (sprite_properties_widget_enabled)
	{
		rect_selection_stuff& the_rect_selection_stuff 
			= the_core_widget_vec.at(curr_tab_index)
			->the_sfml_canvas_widget->the_rect_selection_stuff;
		
		the_sprite_properties_widget.reset(new sprite_properties_widget
			( this, the_rect_selection_stuff
			.get_single_selected_sprite_ipgws() ));
		
		vert_splitter->addWidget(the_sprite_properties_widget.get());
	}
	
}
	inline level_editor_core_widget* get_curr_level_editor_core_widget
		( const string& calling_func_name )
	{
		s32 curr_tab_index = get_curr_level_editor_core_widget_index();
		
		level_editor_core_widget* the_core_widget = NULL;
		
		if ( curr_tab_index != -1 )
		{
			the_core_widget = the_core_widget_vec.at(curr_tab_index).get();
		}
		
		if ( the_core_widget == NULL )
		{
			cout << "Weird bug in " << calling_func_name << "():  "
				<< "the_core_widget == NULL.\nExpect a segfault....";
		}
		
		return the_core_widget;
	}
	inline level_editor_core_widget* get_curr_level_editor_core_widget()
	{
		return the_core_widget_vec
			.at(get_curr_level_editor_core_widget_index()).get();
	}
	inline sublevel& get_curr_sublevel()
	{
		return the_level.sublevel_vec
			.at(get_curr_level_editor_core_widget_index());
	}
void level_editor_widget::keyPressEvent( QKeyEvent* event )
{
	// These probably ought to be in a toolbar of some sort, as well.
	
	level_editor_core_widget* the_core_widget = NULL;
	level_editor_sfml_canvas_widget* the_sfml_canvas_widget = NULL;
	
	
	s32 curr_tab_index = get_curr_level_editor_core_widget_index();
	
	if ( curr_tab_index != -1 )
	{
		the_core_widget = the_core_widget_vec.at(curr_tab_index).get();
		the_sfml_canvas_widget = the_core_widget
			->the_sfml_canvas_widget.get();
	}
	
	if ( the_core_widget == NULL )
	{
		cout << "Weird bug in keyPressEvent():  the_core_widget == "
			<< "NULL.\nExpect a segfault....";
	}
	
	
	rect_selection_stuff& the_rect_selection_stuff
		= the_sfml_canvas_widget->the_rect_selection_stuff;
	
	if ( event->key() == Qt::Key_A )
	{
		the_core_widget->zoom_in();
	}
	else if ( event->key() == Qt::Key_Z )
	{
		the_core_widget->zoom_out();
	}
	else if ( event->key() == Qt::Key_T )
	{
		// Temporary until a toggle button is created for this purpose.
		if ( !the_sfml_canvas_widget->get_block_grid_enabled() )
		{
			the_sfml_canvas_widget->enable_block_grid();
			//cout << "Tile grid now enabled.\n";
	}
		else
		{
			the_sfml_canvas_widget->disable_block_grid();
			//cout << "Tile grid now disabled.\n";
		}
	}
	//else if ( event->key() == Qt::Key_Q )
	//{
	//	if ( the_rect_selection_stuff.get_enabled() )
	//	{
	//		the_rect_selection_stuff
	//			.finalize_movement_of_selection_contents();
	//	}
	//	
	//	the_core_widget->the_mouse_mode = mm_place_level_elements;
	//	
	//	cout << "Current mouse mode:  place_level_elements\n";
	//}
	//else if ( event->key() == Qt::Key_W )
	//{
	//	if ( the_rect_selection_stuff.get_enabled() )
	//	{
	//		the_rect_selection_stuff
	//			.finalize_movement_of_selection_contents();
	//	}
	//	
	//	the_core_widget->the_mouse_mode = mm_select_single_sprite;
	//	
	//	cout << "Current mouse mode:  select_sprites\n";
	//}
	//else if ( event->key() == Qt::Key_E )
	//{
	//	the_core_widget->the_mouse_mode = mm_rect_selection;
	//	
	//	cout << "Current mouse mode:  rect_selection\n";
	//}
	else if ( event->key() == Qt::Key_C 
		&& the_core_widget->the_mouse_mode == mm_rect_selection 
		&& the_rect_selection_stuff.get_enabled() )
	{
		//cout << "Copying selection contents\n";
		
		the_rect_selection_stuff.copy_selection_contents();
	}
	else if ( event->key() == Qt::Key_V 
		&& the_core_widget->the_mouse_mode == mm_rect_selection )
	{
		if ( the_rect_selection_stuff.get_enabled() )
		{
			the_rect_selection_stuff
				.finalize_movement_of_selection_contents();
		}
		
		//cout << "Pasting the copied selection contents\n";
		
		//the_sfml_canvas_widget->the_rect_selection_stuff
		//	.paste_copied_selection_contents( vec2_s32( 0, 0 ) );
		
		sf::FloatRect visible_rect 
			= the_sfml_canvas_widget->get_visible_rect();
		
		u32 num_pixels_per_block_row 
			= the_sfml_canvas_widget->num_pixels_per_block_row;
		u32 num_pixels_per_block_column 
			= the_sfml_canvas_widget->num_pixels_per_block_column;
		u32 scale_factor = the_sfml_canvas_widget->scale_factor;
		
		vec2<double> visible_block_grid_start_pos
			( (double)visible_rect.left 
			/ (double)( num_pixels_per_block_column * scale_factor ), 
			(double)visible_rect.top / (double)( num_pixels_per_block_row
			* scale_factor ) );
		vec2<double> visible_block_grid_size_2d( (double)visible_rect.width 
			/ (double)( num_pixels_per_block_column * scale_factor ), 
			(double)visible_rect.height 
			/ (double)( num_pixels_per_block_row * scale_factor ) );
		
		// this is so that sprites larger than 16x16 pixels will be drawn if
		// their starting position is offscreen but part of them still is on
		// screen.
		--visible_block_grid_start_pos.x;
		--visible_block_grid_start_pos.y;
		
		//cout << visible_block_grid_start_pos.x << ", "
		//	<< visible_block_grid_start_pos.y << ", "
		//	<< visible_block_grid_size_2d.x << ", "
		//	<< visible_block_grid_size_2d.y << endl;
		
		++visible_block_grid_size_2d.x;
		++visible_block_grid_size_2d.y;
		
		++visible_block_grid_size_2d.x;
		++visible_block_grid_size_2d.y;
		
		if ( visible_block_grid_start_pos.x < 0 )
		{
			visible_block_grid_start_pos.x = 0;
		}
		if ( visible_block_grid_start_pos.y < 0 )
		{
			visible_block_grid_start_pos.y = 0;
		}
		
		if ( ( visible_block_grid_start_pos.x 
			+ visible_block_grid_size_2d.x )
			>= (s32)the_core_widget->the_sublevel->real_size_2d.x )
		{
			visible_block_grid_size_2d.x 
				= the_core_widget->the_sublevel->real_size_2d.x
				- visible_block_grid_start_pos.x;
		}
		if ( ( visible_block_grid_start_pos.y 
			+ visible_block_grid_size_2d.y )
			>= (s32)the_core_widget->the_sublevel->real_size_2d.y )
		{
			visible_block_grid_size_2d.y 
				= the_core_widget->the_sublevel->real_size_2d.y
				- visible_block_grid_start_pos.y;
		}
		
		
		
		// Paste at the location of the mouse.
		sf::FloatRect visible_block_grid_rect
			( visible_block_grid_start_pos.x,
			visible_block_grid_start_pos.y,
			visible_block_grid_size_2d.x, visible_block_grid_size_2d.y );
		
		
		
		sf::Vector2i mouse_pos_in_canvas_widget_coords 
			= sf::Mouse::getPosition(*the_sfml_canvas_widget);
		
		// This converts the clicked coordinate to pixel coordinates.
		sf::Vector2f mouse_pos_in_canvas_coords
			( (double)mouse_pos_in_canvas_widget_coords.x 
			/ (double)the_sfml_canvas_widget->scale_factor,
			(double)mouse_pos_in_canvas_widget_coords.y
			/ (double)the_sfml_canvas_widget->scale_factor );
		
		vec2_s32 block_grid_coords_of_mouse_pos
			= { (s32)( mouse_pos_in_canvas_coords.x
			/ ( level_editor_sfml_canvas_widget
			::num_pixels_per_block_row ) ),
			
			(s32)( ( the_sfml_canvas_widget->the_sublevel->real_size_2d.y 
			- ( ( the_sfml_canvas_widget->getSize().y / scale_factor )
			- mouse_pos_in_canvas_coords.y )
			/ level_editor_sfml_canvas_widget
			::num_pixels_per_block_column ) ) };
		
		
		if ( visible_block_grid_rect.contains
			( block_grid_coords_of_mouse_pos.x, 
			block_grid_coords_of_mouse_pos.y ) )
		{
			the_sfml_canvas_widget->the_rect_selection_stuff
				.paste_copied_selection_contents
				(block_grid_coords_of_mouse_pos);
		}
		//else
		//{
		//	the_sfml_canvas_widget->the_rect_selection_stuff
		//		.paste_copied_selection_contents( vec2_s32
		//		( visible_block_grid_start_pos.x, 
		//		visible_block_grid_start_pos.y ) );
		//}
	}
	
	
}