00001 #ifndef MYTHDIALOGS_H_
00002 #define MYTHDIALOGS_H_
00003
00004 #include <qwidget.h>
00005 #include <qdialog.h>
00006 #include <qprogressbar.h>
00007 #include <qdom.h>
00008 #include <qptrlist.h>
00009 #include <qpixmap.h>
00010 #include <qpushbutton.h>
00011 #include <qlabel.h>
00012 #include <qevent.h>
00013 #include <qvaluevector.h>
00014 #include <qscrollview.h>
00015 #include <qthread.h>
00016 #include <qlayout.h>
00017
00018 #include "mythexp.h"
00019
00020 #include <vector>
00021 using namespace std;
00022
00023 class XMLParse;
00024 class UIType;
00025 class UIManagedTreeListType;
00026 class UITextType;
00027 class UIRichTextType;
00028 class UIMultiTextType;
00029 class UIPushButtonType;
00030 class UITextButtonType;
00031 class UIRemoteEditType;
00032 class UIRepeatedImageType;
00033 class UICheckBoxType;
00034 class UISelectorType;
00035 class UIBlackHoleType;
00036 class UIImageType;
00037 class UIImageGridType;
00038 class UIStatusBarType;
00039 class UIListBtnType;
00040 class UIListTreeType;
00041 class UIKeyboardType;
00042 class LayerSet;
00043 class GenericTree;
00044 class MythMediaDevice;
00045 class MythLineEdit;
00046 class MythRemoteLineEdit;
00047 class MythListBox;
00048 struct fontProp;
00049 class MythMainWindow;
00050
00051 #include "libmythui/mythmainwindow.h"
00052
00053 typedef enum DialogCode
00054 {
00055 kDialogCodeRejected = QDialog::Rejected,
00056 kDialogCodeAccepted = QDialog::Accepted,
00057 kDialogCodeListStart = 0x10,
00058 kDialogCodeButton0 = 0x10,
00059 kDialogCodeButton1 = 0x11,
00060 kDialogCodeButton2 = 0x12,
00061 kDialogCodeButton3 = 0x13,
00062 kDialogCodeButton4 = 0x14,
00063 kDialogCodeButton5 = 0x15,
00064 kDialogCodeButton6 = 0x16,
00065 kDialogCodeButton7 = 0x17,
00066 kDialogCodeButton8 = 0x18,
00067 kDialogCodeButton9 = 0x19,
00068 } DialogCode;
00069
00070 inline bool operator==(const DialogCode &a, const QDialog::DialogCode &b)
00071 { return ((int)a) == ((int)b); }
00072 inline bool operator==(const QDialog::DialogCode &a, const DialogCode &b)
00073 { return ((int)a) == ((int)b); }
00074 inline bool operator!=(const DialogCode &a, const QDialog::DialogCode &b)
00075 { return ((int)a) == ((int)b); }
00076 inline bool operator!=(const QDialog::DialogCode &a, const DialogCode &b)
00077 { return ((int)a) == ((int)b); }
00078
00079 class MPUBLIC MythDialog : public QFrame
00080 {
00081 Q_OBJECT
00082 public:
00083 MythDialog(MythMainWindow *parent, const char *name = 0,
00084 bool setsize = true);
00085
00086
00087 static const DialogCode Rejected = kDialogCodeRejected;
00088 static const DialogCode Accepted = kDialogCodeAccepted;
00089 static const DialogCode ListStart = kDialogCodeListStart;
00090
00091 DialogCode result(void) const { return rescode; }
00092
00093 virtual void Show(void);
00094
00095 void hide(void);
00096
00097 void setNoErase(void);
00098
00099 virtual bool onMediaEvent(MythMediaDevice * mediadevice);
00100
00101 void setResult(DialogCode r);
00102
00103 virtual void deleteLater(void);
00104
00105 static int CalcItemIndex(DialogCode code);
00106
00107 signals:
00108 void menuButtonPressed();
00109
00110 public slots:
00111 DialogCode exec(void);
00112 virtual void done(int);
00113 virtual void AcceptItem(int);
00114 virtual void accept();
00115 virtual void reject();
00116
00117 protected:
00118 ~MythDialog();
00119 void TeardownAll(void);
00120
00121 void keyPressEvent(QKeyEvent *e);
00122
00123 float wmult, hmult;
00124 int screenwidth, screenheight;
00125 int xbase, ybase;
00126
00127 MythMainWindow *m_parent;
00128
00129 DialogCode rescode;
00130
00131 bool in_loop;
00132
00133 QFont defaultBigFont, defaultMediumFont, defaultSmallFont;
00134 };
00135
00136 class MPUBLIC MythPopupBox : public MythDialog
00137 {
00138 Q_OBJECT
00139 public:
00140 MythPopupBox(MythMainWindow *parent, const char *name = 0);
00141 MythPopupBox(MythMainWindow *parent, bool graphicPopup,
00142 QColor popupForeground, QColor popupBackground,
00143 QColor popupHighlight, const char *name = 0);
00144
00145 void addWidget(QWidget *widget, bool setAppearance = true);
00146 void addLayout(QLayout *layout, int stretch = 0);
00147
00148 typedef enum { Large, Medium, Small } LabelSize;
00149
00150 QLabel *addLabel(QString caption, LabelSize size = Medium,
00151 bool wrap = false);
00152
00153 QButton *addButton(QString caption, QObject *target = NULL,
00154 const char *slot = NULL);
00155
00156 void ShowPopup(QObject *target = NULL, const char *slot = NULL);
00157 void ShowPopupAtXY(int destx, int desty,
00158 QObject *target = NULL, const char *slot = NULL);
00159
00160 DialogCode ExecPopup(QObject *target = NULL, const char *slot = NULL);
00161 DialogCode ExecPopupAtXY(int destx, int desty,
00162 QObject *target = NULL, const char *slot = NULL);
00163
00164 static bool showOkPopup(MythMainWindow *parent,
00165 const QString &title,
00166 const QString &message,
00167 QString button_msg = QString::null);
00168
00169 static bool showOkCancelPopup(MythMainWindow *parent, QString title,
00170 QString message, bool focusOk);
00171
00172 static DialogCode Show2ButtonPopup(
00173 MythMainWindow *parent,
00174 const QString &title, const QString &message,
00175 const QString &button1msg, const QString &button2msg,
00176 DialogCode default_button)
00177 {
00178 QStringList buttonmsgs;
00179 buttonmsgs += (button1msg.isEmpty()) ?
00180 QString("Button 1") : button1msg;
00181 buttonmsgs += (button2msg.isEmpty()) ?
00182 QString("Button 2") : button2msg;
00183 return ShowButtonPopup(
00184 parent, title, message, buttonmsgs, default_button);
00185 }
00186
00187 static DialogCode ShowButtonPopup(
00188 MythMainWindow *parent,
00189 const QString &title, const QString &message,
00190 const QStringList &buttonmsgs,
00191 DialogCode default_button);
00192
00193 static bool showGetTextPopup(MythMainWindow *parent, QString title,
00194 QString message, QString& text);
00195 static QString showPasswordPopup(MythMainWindow *parent,
00196 QString title, QString message);
00197
00198 public slots:
00199 virtual void AcceptItem(int);
00200 virtual void accept(void);
00201 virtual void reject(void);
00202
00203 signals:
00204 virtual void popupDone(int);
00205
00206 protected:
00207 ~MythPopupBox() {}
00208 bool focusNextPrevChild(bool next);
00209 void keyPressEvent(QKeyEvent *e);
00210
00211 protected slots:
00212 void defaultButtonPressedHandler(void);
00213
00214 private:
00215 QVBoxLayout *vbox;
00216 QColor popupForegroundColor;
00217 int hpadding, wpadding;
00218 bool arrowAccel;
00219 };
00220
00234 class MPUBLIC MythProgressDialog: public MythDialog
00235 {
00236 Q_OBJECT
00237 public:
00246 MythProgressDialog(const QString& message, int totalSteps = 0,
00247 bool cancelButton = false,
00248 const QObject * target = NULL,
00249 const char * slot = NULL);
00250
00251
00252
00253
00254
00255 void Close(void);
00256
00257
00258
00259
00260
00261
00262
00263
00264 void setProgress(int curprogress);
00265
00266 void setLabel(QString newlabel);
00267
00268 void keyPressEvent(QKeyEvent *);
00269
00270 virtual void deleteLater(void);
00271
00272 signals:
00273 void pressed();
00274
00275 protected:
00276 void Teardown(void);
00277 ~MythProgressDialog();
00278 QProgressBar *progress;
00279 QLabel *msglabel;
00280
00281 private:
00282 void setTotalSteps(int totalSteps);
00283 int steps;
00284 int m_totalSteps;
00285 QPtrList<class LCDTextItem> * textItems;
00286 };
00287
00294 class MPUBLIC MythBusyDialog : public MythProgressDialog
00295 {
00296 Q_OBJECT
00297 public:
00308 MythBusyDialog(const QString &title,
00309 bool cancelButton = false,
00310 const QObject * target = NULL,
00311 const char * slot = NULL);
00312
00320 void start(int interval = 100);
00321
00326 void Close();
00327
00328 public slots:
00329 virtual void deleteLater(void);
00330
00331 protected slots:
00332 void setProgress();
00333 void timeout();
00334
00335 protected:
00336 void Teardown(void);
00337 ~MythBusyDialog();
00338
00339 private:
00340 QTimer *timer;
00341 };
00342
00343 class MPUBLIC MythThemedDialog : public MythDialog
00344 {
00345 Q_OBJECT
00346 public:
00347 MythThemedDialog(MythMainWindow *parent, QString window_name,
00348 QString theme_filename = "", const char *name = 0,
00349 bool setsize = true);
00350 MythThemedDialog(MythMainWindow *parent, const char *name = 0,
00351 bool setsize = true);
00352
00353 virtual bool loadThemedWindow(QString window_name, QString theme_filename);
00354 virtual void loadWindow(QDomElement &);
00355 virtual void parseContainer(QDomElement &);
00356 virtual void parseFont(QDomElement &);
00357 virtual void parsePopup(QDomElement &);
00358 bool buildFocusList();
00359
00360 UIType *getUIObject(const QString &name);
00361
00362 UIType *getCurrentFocusWidget();
00363 void setCurrentFocusWidget(UIType *widget);
00364
00365 UIManagedTreeListType *getUIManagedTreeListType(const QString &name);
00366 UITextType *getUITextType(const QString &name);
00367 UIRichTextType *getUIRichTextType(const QString &name);
00368 UIMultiTextType *getUIMultiTextType(const QString &name);
00369 UIPushButtonType *getUIPushButtonType(const QString &name);
00370 UITextButtonType *getUITextButtonType(const QString &name);
00371 UIRemoteEditType *getUIRemoteEditType(const QString &name);
00372 UIRepeatedImageType *getUIRepeatedImageType(const QString &name);
00373 UICheckBoxType *getUICheckBoxType(const QString &name);
00374 UISelectorType *getUISelectorType(const QString &name);
00375 UIBlackHoleType *getUIBlackHoleType(const QString &name);
00376 UIImageGridType *getUIImageGridType(const QString &name);
00377 UIImageType *getUIImageType(const QString &name);
00378 UIStatusBarType *getUIStatusBarType(const QString &name);
00379 UIListBtnType *getUIListBtnType(const QString &name);
00380 UIListTreeType *getUIListTreeType(const QString &name);
00381 UIKeyboardType *getUIKeyboardType(const QString &name);
00382
00383 LayerSet* getContainer(const QString &name);
00384 fontProp* getFont(const QString &name);
00385
00386 void setContext(int a_context) { context = a_context; }
00387 int getContext(){return context;}
00388
00389 public slots:
00390 virtual void deleteLater(void);
00391 virtual void updateBackground();
00392 virtual void initForeground();
00393 virtual void updateForeground();
00395 virtual void updateForeground(const QRect &);
00397 virtual void updateForegroundRegion(const QRect &);
00398 virtual bool assignFirstFocus();
00399 virtual bool nextPrevWidgetFocus(bool up_or_down);
00400 virtual void activateCurrent();
00401
00402 protected:
00403 ~MythThemedDialog();
00404
00405 void paintEvent(QPaintEvent* e);
00406 UIType *widget_with_current_focus;
00407
00408
00409 XMLParse *getTheme() {return theme;}
00410 QDomElement& getXmlData() {return xmldata;}
00411
00412 QPixmap my_background;
00413 QPixmap my_foreground;
00414
00415 private:
00416
00417 void ReallyUpdateForeground(const QRect &);
00418
00419 void UpdateForegroundRect(const QRect &inv_rect);
00420
00421 XMLParse *theme;
00422 QDomElement xmldata;
00423 int context;
00424
00425 QPtrList<LayerSet> my_containers;
00426 QPtrList<UIType> focus_taking_widgets;
00427
00428 QRect redrawRect;
00429 };
00430
00431 class MPUBLIC MythPasswordDialog: public MythDialog
00432 {
00433 Q_OBJECT
00434
00435
00436
00437
00438
00439 public:
00440
00441 MythPasswordDialog( QString message,
00442 bool *success,
00443 QString target,
00444 MythMainWindow *parent,
00445 const char *name = 0,
00446 bool setsize = true);
00447 public slots:
00448
00449 void checkPassword(const QString &);
00450
00451 protected:
00452 ~MythPasswordDialog();
00453 void keyPressEvent(QKeyEvent *e);
00454
00455 private:
00456
00457 MythLineEdit *password_editor;
00458 QString target_text;
00459 bool *success_flag;
00460 };
00461
00462 class MPUBLIC MythSearchDialog: public MythPopupBox
00463 {
00464 Q_OBJECT
00465
00466 public:
00467
00468 MythSearchDialog(MythMainWindow *parent, const char *name = 0);
00469
00470 public:
00471 void setCaption(QString text);
00472 void setSearchText(QString text);
00473 void setItems(QStringList items);
00474 QString getResult(void);
00475
00476 public slots:
00477 virtual void deleteLater(void);
00478
00479 protected slots:
00480 void searchTextChanged(void);
00481
00482 protected:
00483 void Teardown(void);
00484 ~MythSearchDialog();
00485 void keyPressEvent(QKeyEvent *e);
00486
00487 private:
00488
00489 QLabel *caption;
00490 MythRemoteLineEdit *editor;
00491 MythListBox *listbox;
00492 QButton *ok_button;
00493 QButton *cancel_button;
00494 };
00495
00496 class MPUBLIC MythImageFileDialog: public MythThemedDialog
00497 {
00498
00499
00500
00501
00502
00503 Q_OBJECT
00504
00505 public:
00506
00507 typedef QValueVector<int> IntVector;
00508
00509 MythImageFileDialog(QString *result,
00510 QString top_directory,
00511 MythMainWindow *parent,
00512 QString window_name,
00513 QString theme_filename = "",
00514 const char *name = 0,
00515 bool setsize=true);
00516 public slots:
00517
00518 void handleTreeListSelection(int, IntVector*);
00519 void handleTreeListEntered(int, IntVector*);
00520 void buildTree(QString starting_where);
00521 void buildFileList(QString directory);
00522
00523 protected:
00524 ~MythImageFileDialog();
00525 void keyPressEvent(QKeyEvent *e);
00526
00527 private:
00528
00529 QString *selected_file;
00530 UIManagedTreeListType *file_browser;
00531 GenericTree *root_parent;
00532 GenericTree *file_root;
00533 GenericTree *initial_node;
00534 UIImageType *image_box;
00535 QStringList image_files;
00536 QString initialDir;
00537 };
00538
00539
00540
00541 class MPUBLIC MythScrollDialog : public QScrollView
00542 {
00543 Q_OBJECT
00544
00545 public:
00546
00547 enum ScrollMode {
00548 HScroll=0,
00549 VScroll
00550 };
00551
00552 MythScrollDialog(MythMainWindow *parent, ScrollMode mode=HScroll,
00553 const char *name = 0);
00554
00555 void setArea(int w, int h);
00556 void setAreaMultiplied(int areaWTimes, int areaHTimes);
00557
00558 DialogCode result(void) const;
00559
00560 public slots:
00561
00562 DialogCode exec(void);
00563 virtual void done(int);
00564 virtual void show();
00565 virtual void hide();
00566 virtual void setContentsPos(int x, int y);
00567
00568 protected slots:
00569
00570 virtual void accept();
00571 virtual void reject();
00572
00573 protected:
00574 ~MythScrollDialog();
00575 void keyPressEvent(QKeyEvent *e);
00576 virtual void paintEvent(QRegion& region, int x, int y, int w, int h);
00577
00578 void setResult(DialogCode r);
00579 void viewportPaintEvent(QPaintEvent *pe);
00580
00581 MythMainWindow *m_parent;
00582 int m_screenWidth, m_screenHeight;
00583 int m_xbase, m_ybase;
00584 float m_wmult, m_hmult;
00585
00586 ScrollMode m_scrollMode;
00587
00588 QFont m_defaultBigFont;
00589 QFont m_defaultMediumFont;
00590 QFont m_defaultSmallFont;
00591
00592 DialogCode m_resCode;
00593 bool m_inLoop;
00594
00595 QPixmap *m_bgPixmap;
00596
00597 QPixmap *m_upArrowPix;
00598 QPixmap *m_dnArrowPix;
00599 QPixmap *m_rtArrowPix;
00600 QPixmap *m_ltArrowPix;
00601
00602 bool m_showUpArrow;
00603 bool m_showDnArrow;
00604 bool m_showLtArrow;
00605 bool m_showRtArrow;
00606
00607 QRect m_upArrowRect;
00608 QRect m_dnArrowRect;
00609 QRect m_rtArrowRect;
00610 QRect m_ltArrowRect;
00611 };
00612
00613 #endif
00614