[Lemon-commits] ladanyi: r3125 - glemon/trunk

Lemon SVN svn at lemon.cs.elte.hu
Wed Jan 10 15:37:48 CET 2007


Author: ladanyi
Date: Wed Jan 10 15:37:46 2007
New Revision: 3125

Added:
   glemon/trunk/background_chooser_dialog.cc
   glemon/trunk/background_chooser_dialog.h
Removed:
   glemon/trunk/map_window.cc
   glemon/trunk/map_window.h
Modified:
   glemon/trunk/Makefile.am
   glemon/trunk/graph_displayer_canvas.cc
   glemon/trunk/graph_displayer_canvas.h
   glemon/trunk/main_win.cc
   glemon/trunk/main_win.h
   glemon/trunk/mapstorage.cc
   glemon/trunk/mapstorage.h
   glemon/trunk/nbtab.cc

Log:
Added support for setting the background form an image file.

Modified: glemon/trunk/Makefile.am
==============================================================================
--- glemon/trunk/Makefile.am	(original)
+++ glemon/trunk/Makefile.am	Wed Jan 10 15:37:46 2007
@@ -49,8 +49,8 @@
 	dijkstrabox.cc \
 	file_chooser_extra_widget.h \
 	file_chooser_extra_widget.cc \
-	map_window.h \
-	map_window.cc
+	background_chooser_dialog.h \
+	background_chooser_dialog.cc
 
 glemon_CXXFLAGS = $(GTK_CFLAGS) $(LEMON_CFLAGS)
 # glemon_LDFLAGS = $(GTK_LIBS) $(LEMON_LIBS)

Added: glemon/trunk/background_chooser_dialog.cc
==============================================================================
--- (empty file)
+++ glemon/trunk/background_chooser_dialog.cc	Wed Jan 10 15:37:46 2007
@@ -0,0 +1,52 @@
+#include "background_chooser_dialog.h"
+#include <gtkmm/stock.h>
+#include "mapstorage.h"
+
+BackgroundChooserDialog::BackgroundChooserDialog(MapStorage* ms) :
+  mapstorage(ms),
+  btnClear(Gtk::Stock::CLEAR)
+{
+  set_has_separator(false);
+
+  Gtk::VBox* pVBox = get_vbox();
+
+  lblBackground.set_text("<b>Background image file</b>");
+  lblBackground.set_use_markup();
+  lblBackground.set_alignment(Gtk::ALIGN_LEFT);
+  lblScaling.set_text("<b>Scaling factor</b>");
+  lblScaling.set_use_markup();
+  lblScaling.set_alignment(Gtk::ALIGN_LEFT);
+  fcbBackground.set_width_chars(30);
+  fcbBackground.set_action(Gtk::FILE_CHOOSER_ACTION_OPEN);
+  if (mapstorage->isBackgroundSet())
+  {
+    fcbBackground.set_filename(mapstorage->getBackgroundFilename());
+  }
+
+  fcbBackground.signal_selection_changed().connect(
+    sigc::mem_fun(*this, &BackgroundChooserDialog::setBackground));
+
+  btnClear.signal_clicked().connect(
+    sigc::mem_fun(*this, &BackgroundChooserDialog::clearBackground));
+
+  pVBox->pack_start(lblBackground, Gtk::PACK_SHRINK);
+  pVBox->pack_start(box, Gtk::PACK_SHRINK);
+  box.pack_start(fcbBackground, Gtk::PACK_EXPAND_WIDGET);
+  box.pack_start(btnClear, Gtk::PACK_SHRINK);
+  pVBox->pack_start(lblScaling, Gtk::PACK_SHRINK);
+  pVBox->pack_start(sbScaling, Gtk::PACK_SHRINK);
+
+  add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
+
+  show_all_children();
+}
+
+void BackgroundChooserDialog::clearBackground()
+{
+  fcbBackground.unselect_all();
+}
+
+void BackgroundChooserDialog::setBackground()
+{
+  mapstorage->setBackground(fcbBackground.get_filename());
+}

Added: glemon/trunk/background_chooser_dialog.h
==============================================================================
--- (empty file)
+++ glemon/trunk/background_chooser_dialog.h	Wed Jan 10 15:37:46 2007
@@ -0,0 +1,27 @@
+#ifndef BACKGROUND_CHOOSER_DIALOG
+#define BACKGROUND_CHOOSER_DIALOG
+
+#include <gtkmm/dialog.h>
+#include <gtkmm/label.h>
+#include <gtkmm/filechooserbutton.h>
+#include <gtkmm/spinbutton.h>
+
+class MapStorage;
+
+class BackgroundChooserDialog : public Gtk::Dialog
+{
+  private:
+    MapStorage* mapstorage;
+    Gtk::Label lblBackground;
+    Gtk::Label lblScaling;
+    Gtk::FileChooserButton fcbBackground;
+    Gtk::SpinButton sbScaling;
+    Gtk::HBox box;
+    Gtk::Button btnClear;
+    void clearBackground();
+    void setBackground();
+  public:
+    BackgroundChooserDialog(MapStorage* ms);
+};
+
+#endif

Modified: glemon/trunk/graph_displayer_canvas.cc
==============================================================================
--- glemon/trunk/graph_displayer_canvas.cc	(original)
+++ glemon/trunk/graph_displayer_canvas.cc	Wed Jan 10 15:37:46 2007
@@ -25,7 +25,8 @@
   nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0),
   isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
   edgemap_to_edit(""), autoscale(true), zoomtrack(false), radius_size(20), edge_width(10),
-  was_redesigned(false), is_drawn(false), mytab(mainw)
+  was_redesigned(false), is_drawn(false), mytab(mainw),
+  background_set(false)
 {
   //base event handler is move tool
   actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
@@ -34,6 +35,32 @@
   active_node=INVALID;
   active_edge=INVALID;
   forming_edge=INVALID;
+
+  setBackground();
+}
+
+void GraphDisplayerCanvas::setBackground()
+{
+  if (background_set)
+  {
+    delete background;
+  }
+  if (mytab.mapstorage.isBackgroundSet())
+  {
+    background_set = true;
+    refBackground = Gdk::Pixbuf::create_from_file(
+      mytab.mapstorage.getBackgroundFilename());
+    background = new Gnome::Canvas::Pixbuf(
+        *(root()),
+        0.0 - refBackground->get_width() / 2.0,
+        0.0 - refBackground->get_height() / 2.0,
+        refBackground);
+    background->lower_to_bottom();
+  }
+  else
+  {
+    background_set = false;
+  }
 }
 
 GraphDisplayerCanvas::~GraphDisplayerCanvas()

Modified: glemon/trunk/graph_displayer_canvas.h
==============================================================================
--- glemon/trunk/graph_displayer_canvas.h	(original)
+++ glemon/trunk/graph_displayer_canvas.h	Wed Jan 10 15:37:46 2007
@@ -441,6 +441,12 @@
   NoteBookTab & mytab;
 
   XY calcArrowPos(XY, XY, XY, XY, int);
+
+  bool background_set;
+  Glib::RefPtr<Gdk::Pixbuf> refBackground;
+  Gnome::Canvas::Pixbuf *background;
+public:
+  void setBackground();
 };
 
 #endif //GRAPH_DISPLAYER_CANVAS_H

Modified: glemon/trunk/main_win.cc
==============================================================================
--- glemon/trunk/main_win.cc	(original)
+++ glemon/trunk/main_win.cc	Wed Jan 10 15:37:46 2007
@@ -22,6 +22,7 @@
 
 #include "main_win.h"
 #include "guipixbufs.h"
+#include "background_chooser_dialog.h"
 
 #include "i18n.h"
 
@@ -113,6 +114,8 @@
       sigc::mem_fun(*this, &MainWin::zoomFit));
   ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
       sigc::mem_fun(*this, &MainWin::zoom100));
+  ag->add( Gtk::Action::create("SetBackground", _("Set Background...")),
+	    sigc::mem_fun(*this, &MainWin::createBackgroundChooser));
   
   ag->add( Gtk::Action::create("ShowMenu", _("_Show")) );
   ag->add( Gtk::Action::create("ShowMaps", _("_Maps")),
@@ -173,6 +176,7 @@
       "      <menuitem action='ViewZoomOut' />"
       "      <menuitem action='ViewZoom100' />"
       "      <menuitem action='ViewZoomFit' />"
+      "      <menuitem action='SetBackground' />"
       "    </menu>"
       "    <menu action='ShowMenu'>"
       "      <menuitem action='ShowMaps'/>"
@@ -580,3 +584,9 @@
 {
   tabs[active_tab]->reDesignGraph();
 }
+
+void MainWin::createBackgroundChooser()
+{
+  BackgroundChooserDialog dialog(&(tabs[active_tab]->mapstorage));
+  dialog.run();
+}

Modified: glemon/trunk/main_win.h
==============================================================================
--- glemon/trunk/main_win.h	(original)
+++ glemon/trunk/main_win.h	Wed Jan 10 15:37:46 2007
@@ -261,6 +261,8 @@
   virtual void nodeViewChanged();
 
   virtual void reDesignGraph();
+
+  void createBackgroundChooser();
 };
 
 #endif //MAIN_WIN_H

Modified: glemon/trunk/mapstorage.cc
==============================================================================
--- glemon/trunk/mapstorage.cc	(original)
+++ glemon/trunk/mapstorage.cc	Wed Jan 10 15:37:46 2007
@@ -17,6 +17,7 @@
  */
 
 #include "mapstorage.h"
+#include "nbtab.h"
 #include "gui_writer.h"
 #include "gui_reader.h"
 #include <limits>
@@ -27,7 +28,7 @@
 const double a_d=0.05;
 const double p_d=40000;
 
-MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false), iterations(i_d), attraction(a_d), propulsation(p_d)
+MapStorage::MapStorage(NoteBookTab& tab) : mytab(tab), modified(false), file_name(""), arrow_pos_read_ok(false), iterations(i_d), attraction(a_d), propulsation(p_d), background_set(false)
 {
   nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
   coords.setXMap(*nodemap_storage["coordinates_x"]);
@@ -552,3 +553,39 @@
 {
   signal_design_win.emit(attraction, propulsation, iterations);
 }
+
+void MapStorage::setBackground(const std::string& file_name)
+{
+  if (file_name == background_file_name) return;
+  if (file_name == "")
+  {
+    background_file_name = "";
+    background_set = false;
+  }
+  else
+  {
+    background_file_name = file_name;
+    background_set = true;
+  }
+  mytab.gd_canvas->setBackground();
+}
+
+const std::string& MapStorage::getBackgroundFilename()
+{
+  return background_file_name;
+}
+
+bool MapStorage::isBackgroundSet()
+{
+  return background_set;
+}
+
+double MapStorage::getBackgroundScaling()
+{
+  return background_scaling;
+}
+
+void MapStorage::setBackgroundScaling(double scaling)
+{
+  background_scaling = scaling;
+}

Modified: glemon/trunk/mapstorage.h
==============================================================================
--- glemon/trunk/mapstorage.h	(original)
+++ glemon/trunk/mapstorage.h	Wed Jan 10 15:37:46 2007
@@ -25,6 +25,8 @@
 #include "xymap.h"
 #include <libgnomecanvasmm.h>
 
+class NoteBookTab;
+
 ///class MapStorage handles NodeMaps and EdgeMaps.
 
 ///Class MapStorage is responsible for storing
@@ -38,10 +40,17 @@
 ///\todo too many things are public!!
 class MapStorage
 {
+private:
+  std::string background_file_name;
+  bool background_set;
+  double background_scaling;
+  NoteBookTab& mytab;
 public:
-  enum value {DOUBLE, STRING};
-  enum type {NORMAL, GUI};
-
+  void setBackground(const std::string& file_name);
+  const std::string& getBackgroundFilename();
+  bool isBackgroundSet();
+  double getBackgroundScaling();
+  void setBackgroundScaling(double scaling);
   ///The graph for which the datas are stored.
   Graph graph;
   /// the coordinates of the nodes
@@ -122,7 +131,7 @@
 
   ///Its all activity is initializing default values
   ///for different visualization attributes.
-  MapStorage();
+  MapStorage(NoteBookTab& tab);
 
   ///Destructor of MapStorage
 

Modified: glemon/trunk/nbtab.cc
==============================================================================
--- glemon/trunk/nbtab.cc	(original)
+++ glemon/trunk/nbtab.cc	Wed Jan 10 15:37:46 2007
@@ -19,7 +19,7 @@
 #include <nbtab.h>
 #include "file_chooser_extra_widget.h"
 
-NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false)
+NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), mapstorage(*this)
 {
   Gtk::ScrolledWindow *pScrolledWindow = manage(new Gtk::ScrolledWindow);
   gd_canvas=new GraphDisplayerCanvas(*this);



More information about the Lemon-commits mailing list