00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef ODINQT_H
00019 #define ODINQT_H
00020
00021 #include <tjutils/tjlog.h>
00022 #include <tjutils/tjstatic.h>
00023 #include <tjutils/tjvector.h>
00024
00025
00026
00027 #define _FONT_TYPE_ "helvetica"
00028 #define _ARRAY_WIDGET_WIDTH_ 270
00029 #define _ARRAY_WIDGET_HEIGHT_ 180
00030 #define _ARRAY_BACKGROUND_COLOR_ "Black"
00031 #define _ARRAY_FOREGROUND_COLOR1_ "White"
00032 #define _ARRAY_FOREGROUND_COLOR2_ "Grey"
00033 #define _ARRAY_GRID_COLOR_ "Green"
00034 #define _ARRAY_GRID_DARK_FACTOR_ 250
00035 #define _ARRAY_SELECTION_COLOR_ "Yellow"
00036 #define _ARRAY_HIGHLIGHT_COLOR_ "Orange"
00037 #define _ARRAY_MARKER_COLOR_ "Blue"
00038 #define _ARRAY_MARKER_BRIGHT_FACTOR_ 180
00039 #define _LAYOUT_STRETCH_FACTOR_ 1
00040 #define SLIDER_CELL_WIDTH 75
00041 #define SLIDER_CELL_HEIGHT 25
00042 #define TEXTEDIT_WIDTH 75
00043 #define TEXTEDIT_HEIGHT 25
00044 #define PLOT_SYMBOLS_SIZE 5
00045
00046
00047
00048 #ifdef USING_WIN32
00049 #define _FONT_SIZE_ 8
00050 #else
00051 #define _FONT_SIZE_ 10
00052 #endif
00053
00055
00056
00057 class QObject;
00058 class QWidget;
00059 class QString;
00060 class QGridLayout;
00061 class QPushButton;
00062 class QLineEdit;
00063 class QPopupMenu;
00064 class QMenu;
00065 class QKeySequence;
00066 class QPoint;
00067 class QSlider;
00068 class QComboBox;
00069 class QLabel;
00070 class QPainter;
00071 class QPixmap;
00072 class QMouseEvent;
00073 class QColor;
00074 class QString;
00075 class QRegion;
00076 class QApplication;
00077 class QScrollView;
00078 class QScrollArea;
00079 class QDialog;
00080 class QMainWindow;
00081 class QProgressDialog;
00082 class QImage;
00083 class QListView;
00084 class QListViewItem;
00085 class QCheckListItem;
00086 class QTableWidget;
00087 class QTableWidgetItem;
00088 class QTreeWidget;
00089 class QTreeWidgetItem;
00090 class QProgressBar;
00091 class QScrollBar;
00092 class QToolBar;
00093 class QToolButton;
00094 class QPrinter;
00095 class QPaintDevice;
00096 class QWizard;
00097 class QTextEdit;
00098 class QTextView;
00099
00100 class SlotDispatcher;
00101
00103
00107 class OdinQt {
00108 public:
00109 static const char* get_compName();
00110 };
00111
00112
00114
00115
00116 const char* c_str(const QString& qs);
00117
00118 int layout_border_size();
00119
00120 void init_label(QLabel* ql);
00121
00122 bool left_button(const QMouseEvent* qme, bool return_current_state);
00123 bool right_button(const QMouseEvent* qme, bool return_current_state);
00124 bool middle_button(const QMouseEvent* qme, bool return_current_state);
00125
00126 void add_tooltip(QWidget* w, const char* txt);
00127
00128 void set_platform_defaults(QWidget* w, bool enable=true);
00129
00130
00131 STD_string get_save_filename(const char* caption=0, const char* startwith="", const char* filter="", QWidget* parent=0);
00132 STD_string get_open_filename(const char* caption=0, const char* startwith="", const char* filter="", QWidget* parent=0);
00133 STD_string get_directory(const char* caption=0, const char* startwith="", QWidget* parent=0);
00134
00135 bool message_question(const char* text, const char* caption, QWidget* parent, bool ask=false, bool error=false);
00136
00137
00138 int paintdevice_height(const QPaintDevice* qpd);
00139 int paintdevice_width(const QPaintDevice* qpd);
00140
00141 svector get_possible_image_fileformats();
00142
00143
00145
00146
00150 class GuiGridLayout {
00151
00152 public:
00153 GuiGridLayout(QWidget *parent, int rows, int columns, bool margin=true);
00154 ~GuiGridLayout();
00155
00156 enum Alignment {Default, VCenter, Center};
00157
00158 void add_widget(QWidget *w, int row, int column, Alignment alignment=Default, int rowSpan=1, int columnSpan=1 );
00159
00160 void set_col_stretch(int col, int factor);
00161 void set_row_stretch(int row, int factor);
00162
00163 void set_col_minsize(int col, int minsize);
00164 void set_row_minsize(int row, int minsize);
00165
00166 private:
00167 QGridLayout* qgl;
00168 };
00169
00171
00175 class GuiButton {
00176
00177 public:
00178 GuiButton(QWidget *parent, QObject* receiver, const char* member, const char *onlabel, const char *offlabel=0, bool initstate=false);
00179 ~GuiButton();
00180
00181 void set_toggled(bool state);
00182
00183 void set_text(bool state);
00184
00185 void set_default(bool state);
00186
00187 bool is_on() const;
00188
00189 QWidget* get_widget();
00190
00191 private:
00192 friend class SlotDispatcher;
00193 QPushButton* qpb;
00194 SlotDispatcher* sd;
00195 const char* ontext;
00196 const char* offtext;
00197 };
00198
00200
00204 class GuiLineEdit {
00205
00206 public:
00207 GuiLineEdit(QWidget *parent, QObject* receiver, const char* member, int width=-1, int height=-1);
00208 ~GuiLineEdit();
00209
00210 void set_text(const char* txt);
00211
00212 const char* get_text() const;
00213
00214 bool is_modified();
00215
00216 QWidget* get_widget();
00217
00218 private:
00219 friend class SlotDispatcher;
00220 QLineEdit* qle;
00221 SlotDispatcher* sd;
00222 };
00223
00224
00226
00230 class GuiPopupMenu {
00231
00232 public:
00233 GuiPopupMenu(QWidget *parent);
00234 ~GuiPopupMenu();
00235
00236 void insert_item(const char* text, const QObject* receiver, const char* member, int accel=0);
00237 void insert_separator();
00238
00239 void popup(const QPoint& p);
00240
00241 private:
00242 friend class GuiMainWindow;
00243
00244 QPopupMenu* qpm;
00245 QMenu* qm;
00246 int id;
00247 };
00248
00250
00254 class GuiSlider {
00255
00256 public:
00257 GuiSlider(QWidget *parent, int minValue, int maxValue, int pageStep, int value, int tickInterval);
00258 ~GuiSlider();
00259
00260 int get_value() const;
00261 void set_value(int val);
00262 bool modified_externally() const {bool result=modified; modified=false; return result;}
00263
00264 QSlider* get_widget() {return qs;}
00265
00266 private:
00267 QSlider* qs;
00268 mutable bool modified;
00269 };
00270
00272
00273 class GuiToolBar;
00274
00278 class GuiComboBox {
00279
00280 public:
00281 GuiComboBox(QWidget* parent, const svector& names);
00282 GuiComboBox(GuiToolBar* parent, const svector& names);
00283 ~GuiComboBox();
00284
00285 void set_names(const svector& names);
00286
00287 void set_current_item(int index);
00288 int get_current_item() const;
00289
00290 QComboBox* get_widget() {return qcb;}
00291
00292 private:
00293 void common_init(QWidget* parent, const svector& names);
00294 QComboBox* qcb;
00295 };
00296
00298
00302 class GuiPainter {
00303
00304 public:
00305 GuiPainter(QPixmap* qpm);
00306 ~GuiPainter();
00307
00308
00309 void moveTo(int x, int y);
00310 void lineTo(int x, int y);
00311 bool begin(QPixmap* qpm);
00312 bool end();
00313 void setPen(const char* pencolor, int linewidth=1, bool dotted=false, float lightdark=0.0);
00314 void fillRect( int x, int y, int w, int h, const QColor& col);
00315 void drawRect(int x, int y, int w, int h);
00316 void drawText( int x, int y, const QString& txt, const QColor& col);
00317
00318 QRegion* draw_region(const STD_list<QPoint>& plist);
00319
00320 QPainter* get_painter() {return qp;}
00321
00322 void repaint(QLabel* dst);
00323
00324 private:
00325 QPainter* qp;
00326 QPixmap* qpm_cache;
00327 int x_cache, y_cache;
00328 };
00329
00331
00335 class GuiApplication {
00336
00337 public:
00338 GuiApplication(int argc=0, char *argv[]=0);
00339 ~GuiApplication();
00340
00341 int start(QWidget* mainwidget);
00342
00343 QObject* get_object();
00344
00345 static void quit();
00346
00347 static int argc();
00348 static char** argv();
00349
00350 static void process_events();
00351
00352 private:
00353 QApplication* qa;
00354
00355
00356 static int argc_cache;
00357 static char** argv_cache;
00358 static int argc4qt;
00359 static char** argv4qt;
00360
00361 };
00362
00364
00368 class GuiMainWindow {
00369
00370 public:
00371 GuiMainWindow(QWidget* parent = 0);
00372 ~GuiMainWindow();
00373
00374 void show(QWidget* central_widget, bool show_toolbutton_text=false);
00375
00376 void set_caption(const char* text);
00377
00378 void set_status_message(const char* text, int timeout_ms=0);
00379
00380 void set_status_xpm(const char** xpm);
00381
00382 QWidget* get_widget();
00383
00384 void insert_menu( const char* text, GuiPopupMenu * gpm);
00385
00386 void insert_menu_separator();
00387
00388 void close();
00389
00390
00391 private:
00392 friend class GuiToolBar;
00393
00394 QMainWindow* qmw;
00395 QLabel* statusIcon;
00396 QLabel* statusText;
00397 };
00398
00399
00401
00405 class GuiScroll {
00406
00407 public:
00408 GuiScroll(QWidget* child, QWidget* parent);
00409 ~GuiScroll();
00410
00411 QWidget* get_widget();
00412
00413 private:
00414 QScrollView* qsv;
00415 QScrollArea* qsa;
00416 };
00417
00418
00420
00421 class QDialogDerived;
00422
00426 class GuiDialog {
00427
00428 public:
00429 GuiDialog(QWidget *parent, const char* caption, bool modal=false);
00430 virtual ~GuiDialog();
00431
00432 QWidget* get_widget();
00433
00434 virtual void repaint() {}
00435 virtual void close() {}
00436
00437 void show();
00438 void cancel();
00439 void done();
00440 void hide();
00441 int exec();
00442
00443 private:
00444 QDialogDerived* qd;
00445 };
00446
00448
00452 class GuiProgressDialog {
00453
00454 public:
00455 GuiProgressDialog(QWidget *parent, bool modal, int total_steps);
00456 ~GuiProgressDialog();
00457
00458 void set_progress(int progr);
00459 int get_progress() const;
00460
00461 void set_total_steps(int steps);
00462
00463 bool was_cancelled() const;
00464
00465 void reset();
00466
00467 void set_text(const char* txt);
00468
00469 void show();
00470 void hide();
00471
00472 private:
00473 QProgressDialog* qpd;
00474 };
00475
00477
00481 class GuiImage {
00482
00483 public:
00484 GuiImage(unsigned char* data, int width, int height, bool colormap);
00485 ~GuiImage();
00486
00487 QPixmap* create_pixmap() const;
00488
00489 private:
00490 QImage* qi;
00491 };
00492
00494
00495 class GuiListItem;
00496
00497
00498 class GuiListViewCallback {
00499
00500 public:
00501 virtual void clicked(GuiListItem* item) = 0;
00502
00503 protected:
00504 GuiListViewCallback() {}
00505 };
00506
00507
00508
00512 class GuiListView {
00513
00514 public:
00515 GuiListView(QWidget *parent, const svector& column_labels, int first_column_width=-1, int min_height=-1, GuiListViewCallback* callback=0, bool tree=false);
00516 ~GuiListView();
00517
00518 QWidget* get_widget();
00519
00520 private:
00521 friend class GuiListItem;
00522 QListView* qlv;
00523 QTableWidget* qtw;
00524 QTreeWidget* qtrw;
00525 SlotDispatcher* sd;
00526 };
00527
00529
00533 class GuiListItem : public StaticHandler<GuiListItem> {
00534
00535 public:
00536 GuiListItem() {common_init();}
00537 GuiListItem(GuiListView *parent, const svector& column_entries, bool checkable=false, bool initstate=false);
00538 GuiListItem(GuiListItem *parent, GuiListItem *after, const svector& column_entries);
00539 ~GuiListItem();
00540
00541 bool is_checked() const;
00542
00543 const char* get_text() const;
00544
00545
00546 static void init_static();
00547 static void destroy_static();
00548
00549 private:
00550 friend class SlotDispatcher;
00551 void common_init();
00552 QListViewItem* qlvi;
00553 QCheckListItem* qcli;
00554 QTableWidgetItem* qtwi;
00555 QTreeWidgetItem* qtrwi;
00556 QTreeWidget* parent_qtrw;
00557
00558
00559 static STD_map<QListViewItem*,GuiListItem*>* listmap;
00560 static STD_map<QTableWidgetItem*,GuiListItem*>* tablemap;
00561 };
00562
00564
00568 class GuiProgressBar {
00569
00570 public:
00571 GuiProgressBar(QWidget *parent, int total_steps);
00572 ~GuiProgressBar();
00573
00574 void set_progress(int progr);
00575
00576 void set_min_width(int w);
00577
00578 QWidget* get_widget();
00579
00580 private:
00581 QProgressBar* qpb;
00582 };
00583
00585
00589 class GuiScrollBar {
00590
00591 public:
00592 GuiScrollBar(QWidget* parent);
00593 ~GuiScrollBar();
00594
00595 void set_values(int min, int max, int linestep, int pagestep, int value);
00596
00597 QScrollBar* get_widget();
00598
00599 private:
00600 QScrollBar* qsb;
00601 };
00602
00604
00608 class GuiToolBar {
00609
00610 public:
00611 GuiToolBar(GuiMainWindow* parent, const char* label);
00612 ~GuiToolBar();
00613
00614 QWidget* get_widget();
00615
00616 void add_separator();
00617
00618 private:
00619 friend class GuiToolButton;
00620 friend class GuiComboBox;
00621 QToolBar* qtb;
00622 };
00623
00625
00629 class GuiToolButton {
00630
00631 public:
00632 GuiToolButton(GuiToolBar* parent, const char** xpm, const char* label, QObject* receiver, const char* member, bool checkable=false, bool initstate=false );
00633 ~GuiToolButton();
00634
00635 bool is_on() const;
00636 void set_on(bool flag);
00637
00638 void set_enabled(bool flag);
00639
00640 void set_label(const char* text);
00641 void set_tooltip(const char* text);
00642
00643 private:
00644 friend class SlotDispatcher;
00645 QToolButton* qtb;
00646 SlotDispatcher* sd;
00647 };
00648
00649
00651
00655 class GuiPrinter {
00656
00657 public:
00658 GuiPrinter();
00659 ~GuiPrinter();
00660
00661 bool setup(QWidget* parent);
00662
00663 QPaintDevice* get_device();
00664
00665 private:
00666 QPrinter* qp;
00667 };
00668
00670
00674 class GuiTextView {
00675
00676 public:
00677 GuiTextView(QWidget* parent, int minwidth, int minheight);
00678 ~GuiTextView();
00679
00680 void set_text(const char* txt);
00681 void append_text(const char* txt);
00682
00683 QWidget* get_widget();
00684
00685 private:
00686
00687 void scroll_end();
00688
00689 QTextEdit* qte;
00690 };
00691
00692 #endif