odinqt.h
1 /***************************************************************************
2  odinqt.h - description
3  -------------------
4  begin : Sun Aug 27 2000
5  copyright : (C) 2000-2015 by Thies Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef ODINQT_H
19 #define ODINQT_H
20 
21 #include <tjutils/tjlog.h>
22 #include <tjutils/tjstatic.h>
23 #include <tjutils/tjvector.h> // for svector
24 
25 
26 // global configuration
27 #define _FONT_TYPE_ "helvetica"
28 #define _ARRAY_WIDGET_WIDTH_ 270
29 #define _ARRAY_WIDGET_HEIGHT_ 180
30 #define _ARRAY_BACKGROUND_COLOR_ "Black"
31 #define _ARRAY_FOREGROUND_COLOR1_ "White"
32 #define _ARRAY_FOREGROUND_COLOR2_ "Grey"
33 #define _ARRAY_GRID_COLOR_ "Green"
34 #define _ARRAY_GRID_DARK_FACTOR_ 250
35 #define _ARRAY_SELECTION_COLOR_ "Yellow"
36 #define _ARRAY_HIGHLIGHT_COLOR_ "Orange"
37 #define _ARRAY_MARKER_COLOR_ "Blue"
38 #define _ARRAY_MARKER_BRIGHT_FACTOR_ 180
39 #define _LAYOUT_STRETCH_FACTOR_ 1
40 #define SLIDER_CELL_WIDTH 75
41 #define SLIDER_CELL_HEIGHT 25
42 #define TEXTEDIT_WIDTH 75
43 #define TEXTEDIT_HEIGHT 25
44 #define PLOT_SYMBOLS_SIZE 5
45 
46 
47 // platform-specific configuration
48 #ifdef USING_WIN32
49 #define _FONT_SIZE_ 8
50 #else
51 #define _FONT_SIZE_ 10
52 #endif
53 
55 
56 // forward declarations
57 class QObject;
58 class QWidget;
59 class QString;
60 class QGridLayout;
61 class QPushButton;
62 class QLineEdit;
63 class QPopupMenu;
64 class QMenu;
65 class QKeySequence;
66 class QPoint;
67 class QSlider;
68 class QComboBox;
69 class QLabel;
70 class QPainter;
71 class QPixmap;
72 class QMouseEvent;
73 class QColor;
74 class QString;
75 class QRegion;
76 class QApplication;
77 class QScrollView;
78 class QScrollArea;
79 class QDialog;
80 class QMainWindow;
81 class QProgressDialog;
82 class QImage;
83 class QListView;
84 class QListViewItem;
85 class QCheckListItem;
86 class QTableWidget;
87 class QTableWidgetItem;
88 class QTreeWidget;
89 class QTreeWidgetItem;
90 class QProgressBar;
91 class QScrollBar;
92 class QToolBar;
93 class QToolButton;
94 class QPrinter;
95 class QPaintDevice;
96 class QWizard;
97 class QTextEdit;
98 class QTextView;
99 
100 class SlotDispatcher;
101 
103 
107 class OdinQt {
108  public:
109  static const char* get_compName();
110 };
111 
112 
114 // Helper functions for Qt portability
115 
116 const char* c_str(const QString& qs);
117 
118 int layout_border_size();
119 
120 void init_label(QLabel* ql);
121 
122 bool left_button(const QMouseEvent* qme, bool return_current_state);
123 bool right_button(const QMouseEvent* qme, bool return_current_state);
124 bool middle_button(const QMouseEvent* qme, bool return_current_state);
125 
126 void add_tooltip(QWidget* w, const char* txt);
127 
128 void set_platform_defaults(QWidget* w, bool enable=true);
129 
130 
131 STD_string get_save_filename(const char* caption=0, const char* startwith="", const char* filter="", QWidget* parent=0);
132 STD_string get_open_filename(const char* caption=0, const char* startwith="", const char* filter="", QWidget* parent=0);
133 STD_string get_directory(const char* caption=0, const char* startwith="", QWidget* parent=0);
134 
135 bool message_question(const char* text, const char* caption, QWidget* parent, bool ask=false, bool error=false);
136 
137 
138 int paintdevice_height(const QPaintDevice* qpd);
139 int paintdevice_width(const QPaintDevice* qpd);
140 
141 svector get_possible_image_fileformats();
142 
143 
145 // Helper classes for Qt portability
146 
151 
152  public:
153  GuiGridLayout(QWidget *parent, int rows, int columns, bool margin=true);
154  ~GuiGridLayout();
155 
156  enum Alignment {Default, VCenter, Center};
157 
158  void add_widget(QWidget *w, int row, int column, Alignment alignment=Default, int rowSpan=1, int columnSpan=1 );
159 
160  void set_col_stretch(int col, int factor);
161  void set_row_stretch(int row, int factor);
162 
163  void set_col_minsize(int col, int minsize);
164  void set_row_minsize(int row, int minsize);
165 
166  private:
167  QGridLayout* qgl;
168 };
169 
171 
175 class GuiButton {
176 
177  public:
178  GuiButton(QWidget *parent, QObject* receiver, const char* member, const char *onlabel, const char *offlabel=0, bool initstate=false);
179  ~GuiButton();
180 
181  void set_toggled(bool state);
182 
183  void set_text(bool state);
184 
185  void set_default(bool state);
186 
187  bool is_on() const;
188 
189  QWidget* get_widget();
190 
191  private:
192  friend class SlotDispatcher;
193  QPushButton* qpb;
194  SlotDispatcher* sd;
195  const char* ontext;
196  const char* offtext;
197 };
198 
200 
204 class GuiLineEdit {
205 
206  public:
207  GuiLineEdit(QWidget *parent, QObject* receiver, const char* member, int width=-1, int height=-1);
208  ~GuiLineEdit();
209 
210  void set_text(const char* txt);
211 
212  const char* get_text() const;
213 
214  bool is_modified();
215 
216  QWidget* get_widget();
217 
218  private:
219  friend class SlotDispatcher;
220  QLineEdit* qle;
221  SlotDispatcher* sd;
222 };
223 
224 
226 
231 
232  public:
233  GuiPopupMenu(QWidget *parent);
234  ~GuiPopupMenu();
235 
236  void insert_item(const char* text, const QObject* receiver, const char* member, int accel=0);
237  void insert_separator();
238 
239  void popup(const QPoint& p);
240 
241  private:
242  friend class GuiMainWindow;
243 
244  QPopupMenu* qpm; // for Qt pre4
245  QMenu* qm; // for Qt4
246  int id;
247 };
248 
250 
254 class GuiSlider {
255 
256  public:
257  GuiSlider(QWidget *parent, int minValue, int maxValue, int pageStep, int value, int tickInterval);
258  ~GuiSlider();
259 
260  int get_value() const;
261  void set_value(int val);
262  bool modified_externally() const {bool result=modified; modified=false; return result;}
263 
264  QSlider* get_widget() {return qs;}
265 
266  private:
267  QSlider* qs;
268  mutable bool modified;
269 };
270 
272 
273 class GuiToolBar; // forward declarion
274 
278 class GuiComboBox {
279 
280  public:
281  GuiComboBox(QWidget* parent, const svector& names);
282  GuiComboBox(GuiToolBar* parent, const svector& names);
283  ~GuiComboBox();
284 
285  void set_names(const svector& names);
286 
287  void set_current_item(int index);
288  int get_current_item() const;
289 
290  QComboBox* get_widget() {return qcb;}
291 
292  private:
293  void common_init(QWidget* parent, const svector& names);
294  QComboBox* qcb;
295 };
296 
298 
302 class GuiPainter {
303 
304  public:
305  GuiPainter(QPixmap* qpm);
306  ~GuiPainter();
307 
308  // forwarding functions to QPainter
309  void moveTo(int x, int y);
310  void lineTo(int x, int y);
311  bool begin(QPixmap* qpm);
312  bool end();
313  void setPen(const char* pencolor, int linewidth=1, bool dotted=false, float lightdark=0.0);
314  void fillRect( int x, int y, int w, int h, const QColor& col);
315  void drawRect(int x, int y, int w, int h);
316  void drawText( int x, int y, const QString& txt, const QColor& col);
317 
318  QRegion* draw_region(const STD_list<QPoint>& plist);
319 
320  QPainter* get_painter() {return qp;}
321 
322  void repaint(QLabel* dst);
323 
324  private:
325  QPainter* qp;
326  QPixmap* qpm_cache;
327  int x_cache, y_cache;
328 };
329 
331 
336 
337  public:
338  GuiApplication(int argc=0, char *argv[]=0);
339  ~GuiApplication();
340 
341  int start(QWidget* mainwidget);
342 
343  QObject* get_object();
344 
345  static void quit();
346 
347  static int argc();
348  static char** argv();
349 
350  static void process_events();
351 
352  private:
353  QApplication* qa;
354 
355  // Cache cmdline args separately for Qt and for later use
356  static int argc_cache;
357  static char** argv_cache;
358  static int argc4qt;
359  static char** argv4qt;
360 
361 };
362 
364 
369 
370  public:
371  GuiMainWindow(QWidget* parent = 0);
372  ~GuiMainWindow();
373 
374  void show(QWidget* central_widget, bool show_toolbutton_text=false);
375 
376  void set_caption(const char* text);
377 
378  void set_status_message(const char* text, int timeout_ms=0);
379 
380  void set_status_xpm(const char** xpm);
381 
382  QWidget* get_widget();
383 
384  void insert_menu( const char* text, GuiPopupMenu * gpm);
385 
386  void insert_menu_separator();
387 
388  void close();
389 
390 
391  private:
392  friend class GuiToolBar;
393 
394  QMainWindow* qmw;
395  QLabel* statusIcon;
396  QLabel* statusText;
397 };
398 
399 
401 
405 class GuiScroll {
406 
407  public:
408  GuiScroll(QWidget* child, QWidget* parent);
409  ~GuiScroll();
410 
411  QWidget* get_widget();
412 
413  private:
414  QScrollView* qsv; // for Qt pre4
415  QScrollArea* qsa; // for Qt4
416 };
417 
418 
420 
421 class QDialogDerived; // to overload paintEvent
422 
426 class GuiDialog {
427 
428  public:
429  GuiDialog(QWidget *parent, const char* caption, bool modal=false);
430  virtual ~GuiDialog();
431 
432  QWidget* get_widget();
433 
434  virtual void repaint() {} // overload to repaint dialog
435  virtual void close() {} // overload to perform additional stuff when closing dialog
436 
437  void show();
438  void cancel();
439  void done();
440  void hide();
441  int exec();
442 
443  private:
444  QDialogDerived* qd;
445 };
446 
448 
453 
454  public:
455  GuiProgressDialog(QWidget *parent, bool modal, int total_steps);
457 
458  void set_progress(int progr);
459  int get_progress() const;
460 
461  void set_total_steps(int steps);
462 
463  bool was_cancelled() const;
464 
465  void reset();
466 
467  void set_text(const char* txt);
468 
469  void show();
470  void hide();
471 
472  private:
473  QProgressDialog* qpd;
474 };
475 
477 
481 class GuiImage {
482 
483  public:
484  GuiImage(unsigned char* data, int width, int height, bool colormap);
485  ~GuiImage();
486 
487  QPixmap* create_pixmap() const;
488 
489  private:
490  QImage* qi;
491 };
492 
494 
495 class GuiListItem; // forward declaration
496 
497 
498 class GuiListViewCallback {
499 
500  public:
501  virtual void clicked(GuiListItem* item) = 0;
502 
503  protected:
504  GuiListViewCallback() {}
505 };
506 
507 
508 
512 class GuiListView {
513 
514  public:
515  GuiListView(QWidget *parent, const svector& column_labels, int first_column_width=-1, int min_height=-1, GuiListViewCallback* callback=0, bool tree=false);
516  ~GuiListView();
517 
518  QWidget* get_widget();
519 
520  private:
521  friend class GuiListItem;
522  QListView* qlv; // for Qt pre4
523  QTableWidget* qtw; // for Qt4
524  QTreeWidget* qtrw; // for Qt4
525  SlotDispatcher* sd;
526 };
527 
529 
533 class GuiListItem : public StaticHandler<GuiListItem> {
534 
535  public:
536  GuiListItem() {common_init();} // used for constructing listmap
537  GuiListItem(GuiListView *parent, const svector& column_entries, bool checkable=false, bool initstate=false);
538  GuiListItem(GuiListItem *parent, GuiListItem *after, const svector& column_entries);
539  ~GuiListItem();
540 
541  bool is_checked() const;
542 
543  const char* get_text() const;
544 
545  // functions to initialize/delete static members by the StaticHandler template class
546  static void init_static();
547  static void destroy_static();
548 
549  private:
550  friend class SlotDispatcher;
551  void common_init();
552  QListViewItem* qlvi; // for Qt pre4
553  QCheckListItem* qcli; // for Qt pre4
554  QTableWidgetItem* qtwi; // for Qt4
555  QTreeWidgetItem* qtrwi; // for Qt4
556  QTreeWidget* parent_qtrw; // for Qt4
557 
558  // global map to retrieve GuiListItem from QListViewItem
559  static STD_map<QListViewItem*,GuiListItem*>* listmap; // for Qt pre4
560  static STD_map<QTableWidgetItem*,GuiListItem*>* tablemap; // for Qt4
561 };
562 
564 
569 
570  public:
571  GuiProgressBar(QWidget *parent, int total_steps);
572  ~GuiProgressBar();
573 
574  void set_progress(int progr);
575 
576  void set_min_width(int w);
577 
578  QWidget* get_widget();
579 
580  private:
581  QProgressBar* qpb;
582 };
583 
585 
590 
591  public:
592  GuiScrollBar(QWidget* parent);
593  ~GuiScrollBar();
594 
595  void set_values(int min, int max, int linestep, int pagestep, int value);
596 
597  QScrollBar* get_widget();
598 
599  private:
600  QScrollBar* qsb;
601 };
602 
604 
608 class GuiToolBar {
609 
610  public:
611  GuiToolBar(GuiMainWindow* parent, const char* label);
612  ~GuiToolBar();
613 
614  QWidget* get_widget();
615 
616  void add_separator();
617 
618  private:
619  friend class GuiToolButton;
620  friend class GuiComboBox;
621  QToolBar* qtb;
622 };
623 
625 
630 
631  public:
632  GuiToolButton(GuiToolBar* parent, const char** xpm, const char* label, QObject* receiver, const char* member, bool checkable=false, bool initstate=false );
633  ~GuiToolButton();
634 
635  bool is_on() const;
636  void set_on(bool flag);
637 
638  void set_enabled(bool flag);
639 
640  void set_label(const char* text);
641  void set_tooltip(const char* text);
642 
643  private:
644  friend class SlotDispatcher;
645  QToolButton* qtb;
646  SlotDispatcher* sd;
647 };
648 
649 
651 
655 class GuiPrinter {
656 
657  public:
658  GuiPrinter();
659  ~GuiPrinter();
660 
661  bool setup(QWidget* parent);
662 
663  QPaintDevice* get_device();
664 
665  private:
666  QPrinter* qp;
667 };
668 
670 
674 class GuiTextView {
675 
676  public:
677  GuiTextView(QWidget* parent, int minwidth, int minheight);
678  ~GuiTextView();
679 
680  void set_text(const char* txt);
681  void append_text(const char* txt);
682 
683  QWidget* get_widget();
684 
685  private:
686 
687  void scroll_end();
688 
689  QTextEdit* qte;
690 };
691 
692 #endif
Definition: odinqt.h:107