123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #include "ui.hh"
- #include <gtkmm.h>
- #include <iostream>
- Ui::Ui(const Glib::RefPtr<Gtk::Application>& app): m_Box(Gtk::Orientation::VERTICAL), m_Box1(Gtk::Orientation::VERTICAL), m_Button("Add document"), m_Button1("Print all"){
- set_title("Priority queue (heap)");
- set_resizable(false);
-
- set_child(m_Box); //We can put a MenuBar at the top of the box and other stuff below it.
- //Define the actions:
- m_refActionGroup = Gio::SimpleActionGroup::create();
- m_refActionGroup->add_action("quit",
- sigc::mem_fun(*this, &Ui::on_action_file_quit));
-
- m_refActionGroup->add_action("about",
- sigc::mem_fun(*this, &Ui::on_action_about));
- insert_action_group("example", m_refActionGroup);
- //Define how the actions are presented in the menus and toolbars:
- m_refBuilder = Gtk::Builder::create();
- //Layout the actions in a menubar and toolbar:
- const Glib::ustring ui_info =
- "<interface>"
- " <menu id='menubar'>"
- " <submenu>"
- " <attribute name='label' translatable='yes'>_File</attribute>"
- " <section>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Quit</attribute>"
- " <attribute name='action'>example.quit</attribute>"
- " </item>"
- " </section>"
- " </submenu>"
- " <submenu>"
- " <attribute name='label' translatable='yes'>_Help</attribute>"
- " <item>"
- " <attribute name='label' translatable='yes'>_About</attribute>"
- " <attribute name='action'>example.about</attribute>"
- " </item>"
- " </submenu>"
- " </menu>"
- "</interface>";
- // Set accelerator keys:
- app->set_accel_for_action("example.quit", "<Primary>q");
- app->set_accel_for_action("example.about", "<Primary>a");
- try{
- m_refBuilder->add_from_string(ui_info);
- }
- catch(const Glib::Error& ex){
- std::cerr << "Building menus and toolbar failed: " << ex.what();
- }
- //Get the menubar:
- auto gmenu = m_refBuilder->get_object<Gio::Menu>("menubar");
- if (!gmenu)
- g_warning("GMenu not found");
- else{
- auto pMenuBar = Gtk::make_managed<Gtk::PopoverMenuBar>(gmenu);
- //Add the PopoverMenuBar to the window:
- m_Box.append(*pMenuBar);
- }
- //Get the toolbar and add it to a container widget:
- auto toolbar = m_refBuilder->get_widget<Gtk::Box>("toolbar");
- if (!toolbar)
- g_warning("toolbar not found");
- else
- m_Box.append(*toolbar);
- m_Box.append(m_Box1);
- m_Box1.append(m_Button);
- m_Box1.append(m_Button1);
- m_Box1.set_homogeneous(true);
- m_Button.set_margin(10);
- m_Button1.set_margin(10);
- m_Button.signal_clicked().connect(sigc::mem_fun(*this,
- &Ui::addDocument));
- m_Button1.signal_clicked().connect(sigc::mem_fun(*this,
- &Ui::printAll));
- }
- void Ui::addDocument(){
- uiAddDocument = new UiAddDocument(fila);
- uiAddDocument->show();
- }
- void Ui::printAll(){
- uiPrintAll = new UiPrintAll(fila);
- uiPrintAll->show();
- }
- void Ui::on_action_file_quit(){
- set_visible(false); //Closes the main window to stop the app->make_window_and_run().
- }
- void Ui::on_action_about(){
- uiAbout = new UiAbout;
- uiAbout->show();
- }
- void Ui::on_action_toggle(){
- std::cout << "The toggle menu item was selected." << std::endl;
- bool active = false;
- m_refActionRain->get_state(active);
- //The toggle action's state does not change automatically:
- active = !active;
- m_refActionRain->change_state(active);
- Glib::ustring message;
- if(active)
- message = "Toggle is active.";
- else
- message = "Toggle is not active";
- std::cout << message << std::endl;
- }
|