Re: fine-tune drag'n'drop in a tree



On Thu, May 8, 2008 at 9:10 AM, Ionutz Borcoman <iborco gmail com> wrote:
> On Wednesday 07 May 2008 2:25:22 pm Murray Cumming wrote:
>  > On Sat, 2008-05-03 at 13:29 +0300, Ionutz Borcoman wrote:
>
> > You can do this by overriding the row_drop_possible_vfunc() virtual
>  > method. You can then add any logic you like, usually examining the
>  > relevant model data for that row.
>  >
>  > I do that in Glom's (ugly) layout dialog. For instance, text items can
>  > be dropped into group items, but not into other text items:
>  > http://svn.gnome.org/viewvc/glom/trunk/glom/mode_data/treestore_layout.h?vi
>  >ew=markup
>  > http://svn.gnome.org/viewvc/glom/trunk/glom/mode_data/treestore_layout.cc?v
>  >iew=markup
>  >
>  > It works well, so we should probably mention in the documentation.
>
>  After some more testing with the example from gtkmm tutorial I have managed to
>  find the effect I was looking for - I had simply to return false when the
>  parent row is top level or empty:
>
>         Gtk::TreeModel::Path dest_parent = dest;
>         bool dest_is_not_top_level = dest_parent.up();
>         if(!dest_is_not_top_level || dest_parent.empty())
>         {
>                 return false;
>         }
>
>  Can somebody please explain when these cases happen? I assume I get
>  dest_is_not_top_level if the item is the root item, but when do I get
>  dest_parent.empty()?
>
>  Other question related with the D&D in a tree (not critical, but nice to
>  have): how can I change the cursor displayed during the drag? For example to
>  display an image, or to add a "+" or "-" to the current image displayed.
>
>  And thanx for all of you that stopped me falling to the dark side of qt :-D
>
>  Cheers,
>
>  Johnny

You might find Gdk::Window::pointer_grab() to be useful for changing
the cursor (combined with pointer_ungrab() when you want to change it
back).  Alternately, if that's not flexible enough, you can probably
use the Gdk::Cursor class more directly in combination with
'drag-motion' signals and something like
Gtk::TreeView::get_path_at_pos() (If you want to change the cursor
based on which model item the mouse is currently above).  Hope that
helps.

-- 
jonner


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]