GTK+ IOStream  Beta
<< GTK+ >> add C++ IOStream operators to GTK+. Now with extra abilities ... like network serialisation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProgressBar.H
Go to the documentation of this file.
1 /* Copyright 2000-2013 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 #ifndef PROGRESSBAR_H_
18 #define PROGRESSBAR_H_
19 
20 #include <iomanip>
21 #include <gtk/gtk.h>
22 #include <math.h>
23 
24 //#define TITLE "Progress"
25 
30 class ProgressBar {
31  GtkWidget* pBar;
32  float last;
33 public:
34 
36  ProgressBar(void) {
37  pBar=NULL;
38 #if DEBUG_PB >1
39  cout<<"ProgressBar::ProgressBar()"<<endl;
40 #endif
41  pBar=gtk_progress_bar_new();
42  //gtk_progress_set_format_string (GTK_PROGRESS (pBar), "%v from [%l-%u] (=%p%%)");
43  show();
44  last=0.;
45  }
46 
48  ~ProgressBar(void) {
49 #if DEBUG_PB >1
50  cout<<"ProgressBar::~ProgressBar()"<<endl;
51 #endif
52  if (pBar)
53  g_object_unref(pBar);
54  pBar=NULL;
55  }
56 
62  ProgressBar& operator =(float what) {
63  if (what>1.0)
64  what=1.0;
65  if (fabs(what-last)>0.05) {
66  if (what<0.0)
67  gtk_progress_bar_pulse (GTK_PROGRESS_BAR(pBar));
68  else
69  gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(pBar), what);
70  last=what;
71  }
72  return *this;
73  }
74 
78  GtkWidget *getWidget(void) {
79  return pBar;
80  }
81 
84  void show(void) {
85  gtk_widget_show(pBar);
86  }
87 
90  void hide(void) {
91  gtk_widget_show(pBar);
92  }
93 };
94 #endif //PROGRESSBAR_H_