Guest User

Gtkmm probe

a guest
Jan 2nd, 2016
69
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "mywindow.h"
  2. #include <iostream>
  3. #include <sstream>
  4.  
  5. MyWindow::MyWindow()
  6. {
  7.     area = new MyArea();
  8.     mybox1 = new Gtk::Box(Gtk::ORIENTATION_VERTICAL);
  9.     mybox2 = new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL);
  10.     edita = new Gtk::Entry();
  11.     editb = new Gtk::Entry();
  12.     editc = new Gtk::Entry();
  13.     editx1 = new Gtk::Entry();
  14.     editx2 = new Gtk::Entry();
  15.     editm = new Gtk::Entry();
  16.     labela = new Gtk::Label("a:");
  17.     labelb = new Gtk::Label("b:");
  18.     labelc = new Gtk::Label("c:");
  19.     labelx1 = new Gtk::Label("x1:");
  20.     labelx2 = new Gtk::Label("x2:");
  21.     labelm = new Gtk::Label("m:");
  22.     buttonOK = new Gtk::Button("OK");
  23.     set_title("Random");
  24.     set_default_size(900, 400);
  25.     mybox1->set_homogeneous(false);
  26.     mybox2->set_homogeneous(false);
  27.     add(*mybox1);
  28.     mybox1->pack_start(*area);
  29.     area->show();
  30.     mybox2->pack_start(*labela);
  31.     labela->show();
  32.     mybox2->pack_start(*edita);
  33.     edita->show();
  34.     mybox2->pack_start(*labelb);
  35.     labelb->show();
  36.     mybox2->pack_start(*editb);
  37.     editb->show();
  38.     mybox2->pack_start(*labelc);
  39.     labelc->show();
  40.     mybox2->pack_start(*editc);
  41.     editc->show();
  42.     mybox2->pack_start(*labelx1);
  43.     labelx1->show();
  44.     mybox2->pack_start(*editx1);
  45.     editx1->show();
  46.     mybox2->pack_start(*labelx2);
  47.     labelx2->show();
  48.     mybox2->pack_start(*editm);
  49.     editm->show();
  50.     mybox2->pack_start(*labelm);
  51.     labelm->show();
  52.     mybox1->pack_start(*mybox2);
  53.     mybox2->show();
  54.     buttonOK->signal_clicked().connect(sigc::bind<-1, Glib::ustring>(
  55.                                        sigc::mem_fun(*this, &MyWindow::on_button_clicked), "buttonOK"));
  56.     mybox1->pack_start(*buttonOK);
  57.     buttonOK->show();
  58.     mybox1->show();
  59. }
  60.  
  61. MyWindow::~MyWindow()
  62. {
  63.     delete buttonOK;
  64.     delete labela;
  65.     delete edita;
  66.     delete labelb;
  67.     delete editb;
  68.     delete labelc;
  69.     delete editc;
  70.     delete labelx1;
  71.     delete editx1;
  72.     delete labelx2;
  73.     delete editx2;
  74.     delete labelm;
  75.     delete editm;
  76.     delete mybox2;
  77.     delete mybox1;
  78. }
  79.  
  80. void MyWindow::on_button_clicked(Glib::ustring data)
  81. {
  82.     Glib::ustring sa = edita->get_text();
  83.     Glib::ustring sb = editb->get_text();
  84.     Glib::ustring sc = editc->get_text();
  85.     Glib::ustring sx1 = editx1->get_text();
  86.     Glib::ustring sx2 = editx2->get_text();
  87.     Glib::ustring sm = editm->get_text();
  88.     if(sa!="")
  89.     {
  90.         std::stringstream out(sa);
  91.         out >> a;
  92.     }
  93.     else a = defa;
  94.     if(sb!="")
  95.     {
  96.         std::stringstream out(sb);
  97.         out >> b;
  98.     }
  99.     else b = defb;
  100.     if(sc!="")
  101.     {
  102.         std::stringstream out(sc);
  103.         out >> c;
  104.     }
  105.     else c = defc;
  106.     if(sx1!="")
  107.     {
  108.         std::stringstream out(sx1);
  109.         out >> x1;
  110.     }
  111.     else x1 = defx1;
  112.     if(sx2!="")
  113.     {
  114.         std::stringstream out(sx2);
  115.         out >> x2;
  116.     }
  117.     else x2 = defx2;
  118.     if(sm!="")
  119.     {
  120.         std::stringstream out(sm);
  121.         out >> m;
  122.     }
  123.     else m = defm;
  124.     area->seta(a);
  125.     area->setb(b);
  126.     area->setc(c);
  127.     area->setx1(x1);
  128.     area->setx2(x2);
  129.     area->setm(m);
  130.     area->repaint();
  131. }
RAW Paste Data