From d9fd6f9c4b3b41adaeb164b1029d17d862b03255 Mon Sep 17 00:00:00 2001 From: nicholasbishop Date: Tue, 14 Aug 2007 09:00:10 +0000 Subject: [PATCH] Filter effects dialog: * Added autoscrolling during connection drag/drop. If a connection is dragged towards the top or bottom of the primitives treeview, the view will scroll with it. --- src/ui/dialog/filter-effects-dialog.cpp | 47 +++++++++++++++++++++++++ src/ui/dialog/filter-effects-dialog.h | 3 ++ 2 files changed, 50 insertions(+) diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 315b73d99..6cc5d0fa8 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1502,6 +1502,8 @@ bool FilterEffectsDialog::PrimitiveList::on_button_press_event(GdkEventButton* e } if(_in_drag) { + _scroll_connection = Glib::signal_timeout().connect(sigc::mem_fun(*this, &PrimitiveList::on_scroll_timeout), 150); + _autoscroll = 0; get_selection()->select(path); return true; } @@ -1511,6 +1513,28 @@ bool FilterEffectsDialog::PrimitiveList::on_button_press_event(GdkEventButton* e bool FilterEffectsDialog::PrimitiveList::on_motion_notify_event(GdkEventMotion* e) { + const int speed = 10; + const int limit = 15; + + Gdk::Rectangle vis; + get_visible_rect(vis); + int vis_x, vis_y; + tree_to_widget_coords(vis.get_x(), vis.get_y(), vis_x, vis_y); + const int top = vis_y + vis.get_height(); + + // When autoscrolling during a connection drag, set the speed based on + // where the mouse is in relation to the edges. + if(e->y < vis_y) + _autoscroll = -(int)(speed + (vis_y - e->y) / 5); + else if(e->y < vis_y + limit) + _autoscroll = -speed; + else if(e->y > top) + _autoscroll = (int)(speed + (e->y - top) / 5); + else if(e->y > top - limit) + _autoscroll = speed; + else + _autoscroll = 0; + queue_draw(); return Gtk::TreeView::on_motion_notify_event(e); @@ -1520,6 +1544,8 @@ bool FilterEffectsDialog::PrimitiveList::on_button_release_event(GdkEventButton* { SPFilterPrimitive *prim = get_selected(), *target; + _scroll_connection.disconnect(); + if(_in_drag && prim) { Gtk::TreePath path; Gtk::TreeViewColumn* col; @@ -1692,6 +1718,27 @@ void FilterEffectsDialog::PrimitiveList::on_drag_end(const Glib::RefPtrdocument, SP_VERB_DIALOG_FILTER_EFFECTS, _("Reorder filter primitive")); } +// If a connection is dragged towards the top or bottom of the list, the list should scroll to follow. +bool FilterEffectsDialog::PrimitiveList::on_scroll_timeout() +{ + if(_autoscroll) { + Gtk::Adjustment& a = *dynamic_cast(get_parent())->get_vadjustment(); + double v; + + v = a.get_value() + _autoscroll; + if(v < 0) + v = 0; + if(v > a.get_upper() - a.get_page_size()) + v = a.get_upper() - a.get_page_size(); + + a.set_value(v); + + queue_draw(); + } + + return true; +} + int FilterEffectsDialog::PrimitiveList::primitive_count() const { return _model->children().size(); diff --git a/src/ui/dialog/filter-effects-dialog.h b/src/ui/dialog/filter-effects-dialog.h index 95dafaff2..ace6e68bd 100644 --- a/src/ui/dialog/filter-effects-dialog.h +++ b/src/ui/dialog/filter-effects-dialog.h @@ -197,6 +197,7 @@ private: const int x1, const int y1, const int row_count); void sanitize_connections(const Gtk::TreeIter& prim_iter); void on_primitive_selection_changed(); + bool on_scroll_timeout(); FilterEffectsDialog& _dialog; Glib::RefPtr _model; @@ -207,6 +208,8 @@ private: int _in_drag; SPFilterPrimitive* _drag_prim; sigc::signal _signal_primitive_changed; + sigc::connection _scroll_connection; + int _autoscroll; std::auto_ptr _observer; }; -- 2.30.2