Tray::Tray(QObject *parent) : QObject(parent) { //创建图标 QIcon icon = QIcon("TrayIcon.png"); trayIcon = new QSystemTrayIcon(this); trayIcon->setIcon(icon); trayIcon->setToolTip(tr("气象数据下载器")); trayIcon->show(); //气泡提示 QString titlec=tr("气象数据下载器"); QString textc=tr("程序已转到后台服务"); trayIcon->showMessage(titlec,textc,QSystemTrayIcon::Information,5000); //添加单/双击鼠标相应 connect(trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,SLOT(trayiconActivated(QSystemTrayIcon::ActivationReason))); //创建动作 minimizeAction = new QAction(tr("最小化"), this); connect(minimizeAction, SIGNAL(triggered()), SIGNAL(signal_hide())); restoreAction = new QAction(tr("还原"), this); connect(restoreAction, SIGNAL(triggered()),SIGNAL(signal_showNormal())); quitAction = new QAction(tr("退出"), this); connect(quitAction, SIGNAL(triggered()),SIGNAL(signal_quit())); //创建右键弹出菜单 trayIconMenu = new QMenu; trayIconMenu->addAction(minimizeAction); trayIconMenu->addAction(restoreAction); trayIconMenu->addSeparator();//分隔 trayIconMenu->addAction(quitAction); trayIcon->setContextMenu(trayIconMenu); }
void FreeWindow::Hide() { if (COREMANAGER->HasWindow(*this)) { COREMANAGER->RemoveWindow(*this); visible = false; signal_hide(*this); } }
ScriptSlots::ScriptSlots() : m_closeButton(Gtk::Stock::CLOSE) { m_instrument = NULL; add(m_vbox); m_generalInfoLabel.set_text(_( "Each row (\"slot\") references one instrument script that shall be " "executed by the sampler for currently selected instrument. Slots are " "executed consecutively from top down." )); m_generalInfoLabel.set_line_wrap(); m_vbox.pack_start(m_generalInfoLabel, Gtk::PACK_SHRINK); m_dragHintLabel.set_text(_( "Drag & drop a script from main window to this window to add a new " "script slot for this instrument." )); m_dragHintLabel.set_line_wrap(); m_scrolledWindow.add(m_vboxSlots); m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); m_vbox.pack_start(m_scrolledWindow); m_vbox.pack_start(m_dragHintLabel, Gtk::PACK_SHRINK); m_buttonBox.set_layout(Gtk::BUTTONBOX_END); m_buttonBox.pack_start(m_closeButton); m_closeButton.set_can_default(); m_closeButton.grab_focus(); m_vbox.pack_start(m_buttonBox, Gtk::PACK_SHRINK); m_closeButton.signal_clicked().connect( sigc::mem_fun(*this, &ScriptSlots::onButtonClose) ); signal_hide().connect( sigc::mem_fun(*this, &ScriptSlots::onWindowHide) ); // establish drag&drop between scripts tree view on main diwno and this // ScriptSlots window std::vector<Gtk::TargetEntry> drag_target_gig_script; drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script")); drag_dest_set(drag_target_gig_script); signal_drag_data_received().connect( sigc::mem_fun(*this, &ScriptSlots::onScriptDragNDropDataReceived) ); show_all_children(); resize(460,300); }
void ExampleApplication::create_window() { auto win = new ExampleWindow(); //Make sure that the application runs for as long this window is still open: add_window(*win); //Delete the window when it is hidden. //That's enough for this simple example. win->signal_hide().connect(sigc::bind<Gtk::Window*>( sigc::mem_fun(*this, &ExampleApplication::on_window_hide), win)); win->show_all(); }
void gTox::on_open(const Gio::Application::type_vec_files& files, const Glib::ustring& hint) { utils::debug::scope_log log(DBG_LVL_1("gtox"), {}); //open file ! for (auto file : files) { mark_busy(); auto tmp = dialog::main::create(file->get_path()); unmark_busy(); add_window(*tmp); auto tmp_ptr = tmp.raw(); tmp->signal_hide().connect_notify([tmp_ptr]() { utils::debug::scope_log log(DBG_LVL_2("gtox"), {}); delete tmp_ptr; }); tmp->show(); } Gtk::Application::on_open(files, hint); }
MainWindow::MainWindow() { set_title("Handle Project"); set_icon_from_file("images/HaPr_high_80x100_ver2.gif"); set_size_request(200, 200); set_default_size(500, 300); set_position(Gtk::WIN_POS_CENTER); signal_hide().connect(sigc::mem_fun(*this, &MainWindow::on_action_file_exit)); Gtk::VBox *const main_box = new Gtk::VBox(false, 0); add(*Gtk::manage(main_box)); create_menu(main_box); std::list<Project> active_projects = get_projects_from_db(); Glib::ustring str_no_proj, str_late_proj, str_history_proj; std::stringstream ss, ss2, ss3; no_active = active_projects.size(); ss << no_active; ss >> str_no_proj; std::list<Project> hist_projects = get_projects_from_db(HISTORY_PROJECT); no_history = hist_projects.size(); ss3 << no_history; ss3 >> str_history_proj; no_late = 0; for(std::list<Project>::iterator it = active_projects.begin(); it != active_projects.end(); it++) { if(it->is_late()) no_late++; } ss2 << no_late; ss2 >> str_late_proj; treeview = new Gtk::TreeView(); Gtk::manage(treeview); scrollview.add(*treeview); scrollview.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); treeviewhist = new Gtk::TreeView(); Gtk::manage(treeviewhist); Gtk::ScrolledWindow *scrollhistory = new Gtk::ScrolledWindow(); Gtk::manage(scrollhistory); scrollhistory->add(*treeviewhist); scrollhistory->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); tabview = new Gtk::Notebook(); Gtk::manage(tabview); tabview->append_page(scrollview, _("_Active projects"), true); tabview->append_page(*scrollhistory, _("P_roject history"), true); main_box->pack_start(*tabview); //Table for active projects. Gtk::TreeModel::ColumnRecord *col_record = new Gtk::TreeModel::ColumnRecord(); col_id = new Gtk::TreeModelColumn<time_t>(); col_no = new Gtk::TreeModelColumn<std::string>(); col_name = new Gtk::TreeModelColumn<std::string>(); col_desc = new Gtk::TreeModelColumn<std::string>(); col_leader_name = new Gtk::TreeModelColumn<std::string>(); col_leader_surname = new Gtk::TreeModelColumn<std::string>(); col_start_date = new Gtk::TreeModelColumn<std::string>(); col_end_date = new Gtk::TreeModelColumn<std::string>(); col_record->add(*col_id); col_record->add(*col_no); col_record->add(*col_name); col_record->add(*col_desc); col_record->add(*col_leader_name); col_record->add(*col_leader_surname); col_record->add(*col_start_date); col_record->add(*col_end_date); ref_tree_model = Gtk::ListStore::create(*col_record); treeview->set_model(ref_tree_model); int j = 0; Gtk::TreeModel::Row row; for(std::list<Project>::iterator it = active_projects.begin(); it != active_projects.end(); it++) { row = *(ref_tree_model->append()); row[*col_id] = it->get_id(); row[*col_no] = it->get_project_no(); row[*col_name] = it->get_project_name(); row[*col_desc] = it->get_description(); row[*col_leader_name] = it->get_project_leader_name(); row[*col_leader_surname] = it->get_project_leader_surname(); row[*col_start_date] = it->get_start_date_str_eu(); row[*col_end_date] = it->get_end_date_str_eu(); j++; } treeview->append_column(_("Number"), *col_no); treeview->append_column(_("Name"), *col_name); treeview->append_column(_("Description"), *col_desc); treeview->append_column(_("Leader name"), *col_leader_name); treeview->append_column(_("Leader surmane"), *col_leader_surname); treeview->append_column(_("Start date"), *col_start_date); treeview->append_column(_("End date"), *col_end_date); treeview->set_headers_clickable(true); treeview->set_grid_lines(Gtk::TREE_VIEW_GRID_LINES_BOTH); for(int i=0; i < 7; i++) { Gtk::TreeView::Column *pColumn = treeview->get_column(i); pColumn->set_resizable(true); pColumn->set_sort_column(i+1); } //Table for history. Gtk::TreeModel::ColumnRecord *col_record_hist = new Gtk::TreeModel::ColumnRecord(); col_id_hist = new Gtk::TreeModelColumn<time_t>(); col_no_hist = new Gtk::TreeModelColumn<std::string>(); col_desc_hist = new Gtk::TreeModelColumn<std::string>(); col_name_hist = new Gtk::TreeModelColumn<std::string>(); col_leader_name_hist = new Gtk::TreeModelColumn<std::string>(); col_leader_surname_hist = new Gtk::TreeModelColumn<std::string>(); col_start_date_hist = new Gtk::TreeModelColumn<std::string>(); col_end_date_hist = new Gtk::TreeModelColumn<std::string>(); col_record_hist->add(*col_id_hist); col_record_hist->add(*col_no_hist); col_record_hist->add(*col_name_hist); col_record_hist->add(*col_desc_hist); col_record_hist->add(*col_leader_name_hist); col_record_hist->add(*col_leader_surname_hist); col_record_hist->add(*col_start_date_hist); col_record_hist->add(*col_end_date_hist); ref_tree_model_hist = Gtk::ListStore::create(*col_record_hist); treeviewhist->set_model(ref_tree_model_hist); Gtk::TreeModel::Row row_hist; for(std::list<Project>::iterator it = hist_projects.begin(); it != hist_projects.end(); it++) { row_hist = *(ref_tree_model_hist->append()); row_hist[*col_id_hist] = it->get_id(); row_hist[*col_no_hist] = it->get_project_no(); row_hist[*col_name_hist] = it->get_project_name(); row_hist[*col_desc_hist] = it->get_description(); row_hist[*col_leader_name_hist] = it->get_project_leader_name(); row_hist[*col_leader_surname_hist] = it->get_project_leader_surname(); row_hist[*col_start_date_hist] = it->get_start_date_str_eu(); row_hist[*col_end_date_hist] = it->get_end_date_str_eu(); j++; } treeviewhist->append_column(_("Number"), *col_no_hist); treeviewhist->append_column(_("Name"), *col_name_hist); treeviewhist->append_column(_("Description"), *col_desc_hist); treeviewhist->append_column(_("Leader name"), *col_leader_name_hist); treeviewhist->append_column(_("Leader surmane"), *col_leader_surname_hist); treeviewhist->append_column(_("Start date"), *col_start_date_hist); treeviewhist->append_column(_("End date"), *col_end_date_hist); treeviewhist->set_headers_clickable(true); treeviewhist->set_grid_lines(Gtk::TREE_VIEW_GRID_LINES_BOTH); for(int i=0; i < 7; i++) { Gtk::TreeView::Column *pColumn_hist = treeviewhist->get_column(i); pColumn_hist->set_resizable(true); pColumn_hist->set_sort_column(i+1); } Gtk::HBox *const status_box = new Gtk::HBox(false, 0); Gtk::manage(status_box); active_label = new Gtk::Label(_("Number of active projects: ") + str_no_proj); late_label = new Gtk::Label(_("Number of late projects: ") + str_late_proj); history_label = new Gtk::Label(_("Number of projects in history: ") + str_history_proj); Gtk::manage(active_label); Gtk::manage(late_label); Gtk::manage(history_label); status_box->pack_start(*active_label); status_box->pack_start(*late_label); status_box->pack_start(*history_label); main_box->pack_start(*status_box, Gtk::PACK_SHRINK); show_all_children(); }
void gTox::on_activate() { utils::debug::scope_log log(DBG_LVL_1("gtox"), {}); Glib::Dir dir(m_config_path); std::vector<std::string> accounts(dir.begin(), dir.end()); accounts.resize(std::distance( accounts.begin(), std::remove_if( accounts.begin(), accounts.end(), [](const std::string& name) { utils::debug::scope_log log(DBG_LVL_3("gtox"), { name }); std::string state_ext = ".tox"; bool f_tox = !(name.size() > state_ext.size() && name.substr(name.size() - state_ext.size(), state_ext.size()) == state_ext); bool f_old_tox = (name != "tox_save"); return f_tox && f_old_tox; }))); //filter files with same name .tox //1. remove extension std::transform(accounts.begin(), accounts.end(), accounts.begin(), [](std::string a) { utils::debug::scope_log log(DBG_LVL_3("gtox"), { a }); auto a_p = a.find_last_of("."); if (a_p != std::string::npos) { a.resize(a_p); } return a; }); //2. sort std::sort(accounts.begin(), accounts.end()); //3. remove duplicates accounts.erase(std::unique(accounts.begin(), accounts.end()), accounts.end()); //4. make the full paths std::transform(accounts.begin(), accounts.end(), accounts.begin(), [this](const std::string& name) { utils::debug::scope_log log(DBG_LVL_3("gtox"), { name }); return Glib::build_filename(m_config_path, name + ".tox"); }); // start profile select mark_busy(); auto profile = dialog::profile_selection::create(accounts); unmark_busy(); add_window(*profile); profile->present(); auto profile_ptr = profile.raw(); if (profile->get_path().empty()) { profile->signal_hide().connect_notify([this, profile_ptr]() { utils::debug::scope_log log(DBG_LVL_2("gtox"), {}); if (!profile_ptr->get_path().empty()) { open(Gio::File::create_for_path(profile_ptr->get_path())); } else if (!profile_ptr->is_aborted()) { mark_busy(); auto assistant = dialog::profile_create::create(m_config_path); unmark_busy(); add_window(*assistant); assistant->present(); auto assistant_ptr = assistant.raw(); assistant->signal_hide().connect_notify([this, assistant_ptr]() { utils::debug::scope_log log(DBG_LVL_2("gtox"), {}); Glib::ustring path = assistant_ptr->get_path(); remove_window(*assistant_ptr); delete assistant_ptr; if (!path.empty()) { open(Gio::File::create_for_path(path)); } else { activate(); } }, true); } remove_window(*profile_ptr); delete profile_ptr; }, true); profile->show(); } else { if (!profile->is_aborted()) { activate(); } } Gtk::Application::on_activate(); }