📄 preferenceswindow.cc
字号:
#include "PreferencesWindow.h"#include <iostream>using namespace std;static booldo_nothing(GdkEventAny* event){ // Return true to signify that this event has been fully handled return true;}PreferencesWindow::PreferencesWindow( BaseObjectType* base_object, const Glib::RefPtr<Gnome::Glade::Xml>& glade_xml) : Gtk::Window(base_object){ // // FIRST, get the widgets I want to track // // Get the widgets I'm interested in glade_xml->get_widget("ColorSelection", d_color_sel); glade_xml->get_widget("FontSelection", d_font_sel); glade_xml->get_widget("ConfirmClose", d_confirm_close); glade_xml->get_widget("InfoLabel", d_warning_label); // Initialize the color and location to "not-yet-known" values d_location = "undefined"; d_color.set_rgb(0,0,0); // // SECOND, we handle setting up defaults and connect callbacks for // the confirmation window. // // Have the confirm-closing window's delete event (window close) do nothing d_confirm_close->signal_delete_event().connect(sigc::ptr_fun(&do_nothing)); // Have the cancel button hide the confirmation window Gtk::Button* cancel_button; glade_xml->get_widget("CancelButton", cancel_button); cancel_button->signal_clicked().connect( sigc::mem_fun(*this, &PreferencesWindow::cancel_button_pressed) ); // Have the "Exit anyway" button hide the Preferences window (which has the // result of closing everything Gtk::Button* exit_button; glade_xml->get_widget("ExitButton", exit_button); exit_button->signal_clicked().connect( sigc::mem_fun(*this, &Gtk::Widget::hide)); // Make the confirm-closing window start hidden d_confirm_close->hide(); // // THIRD, we handle setting up defaults and connect callbacks for // the preferences window. // // Keep track of when the location changes Gtk::CheckButton* here = dynamic_cast<Gtk::CheckButton*>(glade_xml->get_widget("Here")); here->signal_toggled().connect( sigc::bind<Glib::ustring>( sigc::mem_fun(*this, &PreferencesWindow::new_location_selected), "Here") ); Gtk::CheckButton* there = dynamic_cast<Gtk::CheckButton*>(glade_xml->get_widget("There")); there->signal_toggled().connect( sigc::bind<Glib::ustring>( sigc::mem_fun(*this, &PreferencesWindow::new_location_selected), "There") ); // Make 'There' be the default; note this also emits the toggled signal there->set_active(); // Keep track of when the color changes d_color_sel->signal_color_changed().connect( sigc::mem_fun(*this, &PreferencesWindow::new_color_selected)); // Set the default to whatever the ColorSelection widget defaults to d_color = d_color_sel->get_current_color(); // Turn off the opacity slider d_color_sel->set_has_opacity_control(false); // Have the quit button show the confirmation window Gtk::Button* quit_button = dynamic_cast<Gtk::Button*>(glade_xml->get_widget("QuitButton")); quit_button->signal_clicked().connect( sigc::mem_fun(*this, &PreferencesWindow::time_to_quit)); // Delete event taken care of by overriding the on_delete_event function... // Destroy even taken care of by destructor...}PreferencesWindow::~PreferencesWindow(){}voidPreferencesWindow::cancel_button_pressed(){ d_confirm_close->hide();}voidPreferencesWindow::new_location_selected(Glib::ustring location){ d_location = location;}voidPreferencesWindow::new_color_selected(){ d_color = d_color_sel->get_current_color(); }// This simple helper function which converts an RGB triplet (which is// part of a GdkColor) into a "#RRGGBB" string.static Glib::ustringconvert_color_to_string (Gdk::Color & color){ char color_string[8]; color_string[0] = '#'; // Gdk::Color stores its red, green, and blue as 0..65536 instead of 0..256 sprintf(&color_string[1], "%.2X", color.get_red() /256); sprintf(&color_string[3], "%.2X", color.get_green()/256); sprintf(&color_string[5], "%.2X", color.get_blue() /256); return color_string;}voidPreferencesWindow::time_to_quit(){ // Create a color string of the form #RRGGBB, where R, G, & B are hex digits Glib::ustring color = convert_color_to_string(d_color); // Get the warning message, and find where we want to modify it Glib::ustring message = d_warning_label->get_label(); Glib::ustring::size_type end_span = message.rfind("span"); Glib::ustring::size_type beg_span = message.rfind("span", end_span-1); // Set up the replacement text. Note that we basically found the two // places where the letter 's' in span was in a string of the form // <span bla bla bla...>yadda yadda yadda...</span> // Now, we are just replacing all the stuff between those two s's. // (And yeah, I should really check out the String Composition) // (Library at http://www.cs.auc.dk/~olau/compose/ but I'm ) // (lazy and will use sprintf for now. ) char replacement_text[500]; sprintf(replacement_text, "span font_desc=\"%s\" foreground=\"%s\">%s</", d_font_sel->get_font_name().c_str(), color.c_str(), d_location.c_str()); // Make the new message and update the label message.replace(beg_span, end_span-beg_span, replacement_text); d_warning_label->set_label(message); // Make sure the confirmation window is shown d_confirm_close->show();}boolPreferencesWindow::on_delete_event(GdkEventAny* event){ time_to_quit(); // No other handlers need be called... return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -