Hello,
I write a Gtk+-based MPD-Client with gtkmm.
I want to set the progressbar'progress with a mouseclick on it, but the signal handler I assigned in the constructor seems to not get called.
Thank you for your help
OS : Ubuntu Gnome Remix 12.10
IDE: Eclipse CDT ( some basic components are loaded per Gtk::Builder from a .glade-file )
Language: C++
Gtk+-Version: 3.6 , 2.24.13
// Header showsong.h
Code:
#ifndef SHOWSONG_H_
#define SHOWSONG_H_
#include <gtkmm.h>
#include <iostream>
#include <fstream>
#include "fenster.h"
class song_ind : public Gtk::VBox
{
public:
song_ind();
virtual ~song_ind(){delete mylabel;delete myprogress;};
bool configure(void);// description in the source file
private:
Gtk::Label *mylabel;
Gtk::ProgressBar *myprogress;
void set_song_pos(GdkEventButton* event);//description in the source file
};
extern class app* myappptr;// app is a class containing references to every
// necessary widget in my program, so the pointer is
// used to connect the parts with another
extern std::ofstream file1;// test logging file
#endif /* SHOWSONG_H_ */
//Source showsong.cpp
Code:
#include "showsong.h"
// constructor
song_ind::song_ind()
{
mylabel = new Gtk::Label;
myprogress = new Gtk::ProgressBar;
// place childs
this->pack_start(*mylabel,true,true,5);
this->pack_end(*myprogress,true,true,5);
// progressbar
myprogress->set_show_text(true);
// the following signal seems to not get emitted!
this->myprogress->signal_button_release_event().connect_notify
(sigc::mem_fun(*this,&song_ind::set_song_pos));
// vbox
this->set_size_request(300,50);
this->show_all();
}
/*
* this will get the data from mpd and let the label & progressbar show it,
* it is called once every 1000 msec per timeout
* ->this works fine :)
*/
bool song_ind::configure(void)
{
double fraction,elapsed,whole;
elapsed = (double)myappptr->mympd->get_song_pos();
whole = (double)myappptr->mympd->get_song_length();
fraction = elapsed / whole ;
myprogress->set_fraction(fraction);
myprogress->set_text(sectomin(inttostr((unsigned int)elapsed)));
this->mylabel->set_label(myappptr->mympd->get_song_name());
return true;
}
/*
* this eventhandler shall react to the users click on the progressbar
* -> this is the problem, it does not get called
* purpose: on click it sets the new song position
*/
void song_ind::set_song_pos(GdkEventButton* event)
{
file1<<"click auf progress"<<std::endl;
if( (event->type == GDK_BUTTON_RELEASE) &&
(event->button == 1) )// rechte maus
{
double fraction,whole;
unsigned int elapsed;
whole = (double)myappptr->mympd->get_song_length();
fraction = (double)event->x / (double)this->myprogress->get_width();
elapsed = (int)(whole*fraction);
myappptr->mympd->set_song_pos(elapsed);
}
}