fixes for multi rank selection, applies ontop of first fix

This commit is contained in:
Sam Tygier 2010-05-27 21:33:39 +01:00
parent 398694e492
commit 3de639d055
2 changed files with 57 additions and 32 deletions

View File

@ -97,7 +97,7 @@ FileCatalog::FileCatalog (CoarsePanel* cp, ToolBar* tb) : listener(NULL), fslist
bRank[i]->set_relief (Gtk::RELIEF_NONE); bRank[i]->set_relief (Gtk::RELIEF_NONE);
buttonBar->pack_start (*bRank[i], Gtk::PACK_SHRINK); buttonBar->pack_start (*bRank[i], Gtk::PACK_SHRINK);
bCateg[i+2] = bRank[i]->signal_toggled().connect (sigc::bind(sigc::mem_fun(*this, &FileCatalog::categoryButtonToggled), bRank[i])); bCateg[i+2] = bRank[i]->signal_toggled().connect (sigc::bind(sigc::mem_fun(*this, &FileCatalog::categoryButtonToggled), bRank[i]));
bRank[i]->signal_button_press_event().connect (sigc::mem_fun(*this, &FileCatalog::on_my_button_press_event),false); bRank[i]->signal_button_press_event().connect (sigc::mem_fun(*this, &FileCatalog::capture_event),false);
} }
bRank[0]->set_tooltip_text (M("FILEBROWSER_SHOWRANK1HINT")); bRank[0]->set_tooltip_text (M("FILEBROWSER_SHOWRANK1HINT"));
bRank[1]->set_tooltip_text (M("FILEBROWSER_SHOWRANK2HINT")); bRank[1]->set_tooltip_text (M("FILEBROWSER_SHOWRANK2HINT"));
@ -183,7 +183,7 @@ FileCatalog::FileCatalog (CoarsePanel* cp, ToolBar* tb) : listener(NULL), fslist
#endif #endif
} }
bool FileCatalog::on_my_button_press_event(GdkEventButton* event){ bool FileCatalog::capture_event(GdkEventButton* event){
// need to record modifiers on the button press, because signal_toggled does not pass the event. // need to record modifiers on the button press, because signal_toggled does not pass the event.
modifierKey = event->state; modifierKey = event->state;
return false; return false;
@ -592,45 +592,70 @@ void FileCatalog::renameRequested (std::vector<FileBrowserEntry*> tbe) {
void FileCatalog::categoryButtonToggled (Gtk::ToggleButton* b) { void FileCatalog::categoryButtonToggled (Gtk::ToggleButton* b) {
for (int i=0; i<8; i++) for (int i=0; i<8; i++)
bCateg[i].block (true); bCateg[i].block (true);
fileBrowser->getScrollPosition (hScrollPos[lastScrollPos], vScrollPos[lastScrollPos]); fileBrowser->getScrollPosition (hScrollPos[lastScrollPos], vScrollPos[lastScrollPos]);
// seek the one pressed //find the number of the button
int toggled_button = 0;
for (int i=0; i<8; i++){
if(categoryButtons[i]==b){
toggled_button = i;
}
}
//was control key pressed
bool control_down = modifierKey & GDK_CONTROL_MASK;
// for a normal switch, untoggle the other buttons
if (!control_down || toggled_button==0 || toggled_button==7){
for (int i=0; i<8; i++) {
categoryButtons[i]->set_active (i==toggled_button);
}
}else{
// but if we have control clicked a star we need to untoggle non-stars
categoryButtons[0]->set_active(false);
categoryButtons[1]->set_active(false);
categoryButtons[7]->set_active(false);
}
// how we color the buttons depends on how many are selected
int toggled_count = 0;
for (int i=0; i<8; i++) { for (int i=0; i<8; i++) {
if (! (modifierKey & GDK_CONTROL_MASK)){ // if the contol key was not held, then untoggle other ranks if (categoryButtons[i]->get_active())
categoryButtons[i]->set_active (categoryButtons[i]==b); toggled_count ++;
}
if (categoryButtons[i]==b)
lastScrollPos = i;
} }
// if you control so that no stars are toggle on, then toggle on the one you clicked // if we have untoggled all the buttons, set to show all
// makes behaviour more natural if (toggled_count == 0){
if (modifierKey & GDK_CONTROL_MASK){ toggled_button = 0;
int activeCount = 0; categoryButtons[0]->set_active(true);
for (int i=0; i<5; i++){
if (bRank[i]->get_active()) activeCount ++;
}
if (activeCount == 0){
b->set_active();
}
} }
// change the images of the buttons to reflect current ranking // so set the right images
for (int i=0; i<5; i++) if (toggled_count == 1){
bRank[i]->set_image (*igranked[i]); int n_stars = 0;
if (! (modifierKey & GDK_CONTROL_MASK)){ // only one button is active, find out which
for (int i=0; i<5; i++) // if its not a star button, then n_stars stays on zero
if (b==bRank[i])
for (int j=0; j<=i; j++)
bRank[j]->set_image (*iranked[j]);
}else{ // if we are in control clicking mode, then light up the toggle bttons
for (int i=0; i<5; i++){ for (int i=0; i<5; i++){
if(bRank[i]->get_active()) bRank[i]->set_image (*iranked[i]); if (bRank[i]->get_active())
n_stars = i+1;
}
// color up to the correct rank
for (int i=0; i<5; i++){
if (i<n_stars)
bRank[i]->set_image (*iranked[i]);
else
bRank[i]->set_image (*igranked[i]);
}
}else{
// if several stars are selected, color them
for (int i=0; i<5; i++){
if (bRank[i]->get_active())
bRank[i]->set_image (*iranked[i]);
else
bRank[i]->set_image (*igranked[i]);
} }
} }

View File

@ -178,7 +178,7 @@ class FileCatalog : public Gtk::VBox,
void setFilterPanel (FilterPanel* fpanel); void setFilterPanel (FilterPanel* fpanel);
void exifInfoButtonToggled(); void exifInfoButtonToggled();
void categoryButtonToggled (Gtk::ToggleButton* b); void categoryButtonToggled (Gtk::ToggleButton* b);
bool on_my_button_press_event(GdkEventButton* event); bool capture_event(GdkEventButton* event);
void filterChanged (); void filterChanged ();
void runFilterDialog (); void runFilterDialog ();