[gtkmm] How to detect when user grabs and releases a slider?



Hi,
I'm developping an audio player app.
It features a slider which displays the current position in the track. I
managed to do this with the Range widget and a timeout connection that
updates it every 10 miliseconds (see code below).

My problem now is that the slider should also alow the user to change the
position in the song.
As soon as the user grabs the slider, the timeout connection should be
disconnected,
and as soon as the user releases the slider, the timeout connection should
be connected again.
I've looked through the documentation and tried lots of code
(signal_move_slider(), working with booleans, ...)
but I can't seem to find anything that signals when the user grabs and
releases the slider.
Can anyone give me some pointers on how to detect this?

tnx,
battersea


code:

class AudioDeck {
...
public:
 long int getPosition(); // returns the position in the song in miliseconds
 bool setPosition(long int pos); // sets the position in the song in
miliseconds
 long int getLength(); // returns the length of the song in miliseconds
...
};


class AudioDeckWindow : public Gtk::Window {
private:
 AudioDeck* fDeck;
 Gtk::Range* fPositionSlider;
 SigC::Connection fTimeOutConnection;

public:
 DeckWindow(AudioDeck* d) : fDeck(d), fPositionSlider(0) {
  ...
  fPositionSlider = Gtk::manage(new Gtk::HScale(0, 0, 1));
  fPositionSlider->set_update_policy(Gtk::UPDATE_DISCONTINUOUS);
  ...
 }

protected:
 void load() {
  ... // let the user choose a song and load it into the deck
  fPositionSlider->set_range(0, fDeck->getLength());
 }

 void play() {
  ... // start playing the deck
  fTimeOutConnection = Glib::signal_timeout().connect(SigC::slot(*this,
&DeckWindow::updatePositionInGui), 10);
 }

 void stop() {
  ... // stop playing the deck
  fTimeOutConnection.disconnect();
 }

 bool updatePositionInGui() {
  fPositionSlider->set_value(fDeck->getPosition());
 }
};





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