00001 #ifndef MYTHUI_TEXT_H_
00002 #define MYTHUI_TEXT_H_
00003
00004
00005 #include <QTextLayout>
00006 #include <QColor>
00007
00008
00009 #include "mythstorage.h"
00010
00011
00012 #include "mythuitype.h"
00013
00014 class MythFontProperties;
00015
00026 class MUI_PUBLIC MythUIText : public MythUIType, public StorageUser
00027 {
00028 public:
00029 MythUIText(MythUIType *parent, const QString &name);
00030 MythUIText(const QString &text, const MythFontProperties &font,
00031 QRect displayRect, QRect altDisplayRect,
00032 MythUIType *parent, const QString &name);
00033 ~MythUIText();
00034
00035 void Reset(void);
00036
00037 virtual void SetText(const QString &text);
00038 QString GetText(void) const;
00039 QString GetDefaultText(void) const;
00040
00041 void SetTextFromMap(QHash<QString, QString> &map);
00042
00043 void SetTemplateText(const QString &text) { m_TemplateText = text; }
00044 QString GetTemplateText(void) const { return m_TemplateText; }
00045
00046 #if 0 // Not currently used
00047 void UseAlternateArea(bool useAlt);
00048 #endif
00049
00050 virtual void Pulse(void);
00051 QPoint CursorPosition(int text_offset);
00052
00053
00054 void SetDBValue(const QString &text) { SetText(text); }
00055 QString GetDBValue(void) const { return GetText(); }
00056
00057 void SetFontState(const QString&);
00058 void SetJustification(int just);
00059
00060 protected:
00061 virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset,
00062 int alphaMod, QRect clipRect);
00063
00064 virtual bool ParseElement(
00065 const QString &filename, QDomElement &element, bool showWarnings);
00066 virtual void CopyFrom(MythUIType *base);
00067 virtual void CreateCopy(MythUIType *parent);
00068 virtual void Finalize(void);
00069
00070 void SetFontProperties(const MythFontProperties &fontProps);
00071 const MythFontProperties* GetFontProperties() { return m_Font; }
00072
00073 void CycleColor(QColor startColor, QColor endColor, int numSteps);
00074 void StopCycling();
00075
00076 int GetJustification(void);
00077 void SetCutDown(Qt::TextElideMode mode);
00078 Qt::TextElideMode GetCutDown(void) const { return m_Cutdown; }
00079 void SetMultiLine(bool multiline);
00080 bool GetMultiLine(void) const { return m_MultiLine; }
00081
00082 void SetArea(const MythRect &rect);
00083 void SetPosition(const MythPoint &pos);
00084 MythRect GetDrawRect(void) { return m_drawRect; }
00085
00086 void SetCanvasPosition(int x, int y);
00087 void ShiftCanvas(int x, int y);
00088
00089 bool Layout(QString & paragraph, QTextLayout *layout, bool final,
00090 bool & overflow, qreal width, qreal & height, bool force,
00091 qreal & last_line_width, QRectF & min_rect, int & num_lines);
00092 bool LayoutParagraphs(const QStringList & paragraphs,
00093 const QTextOption & textoption,
00094 qreal width, qreal & height, QRectF & min_rect,
00095 qreal & last_line_width, int & num_lines, bool final);
00096 bool GetNarrowWidth(const QStringList & paragraphs,
00097 const QTextOption & textoption, qreal & width);
00098 void FillCutMessage(void);
00099
00100 int m_Justification;
00101 MythRect m_OrigDisplayRect;
00102 MythRect m_AltDisplayRect;
00103 MythRect m_Canvas;
00104 MythRect m_drawRect;
00105 QPoint m_cursorPos;
00106
00107 QString m_Message;
00108 QString m_CutMessage;
00109 QString m_DefaultMessage;
00110 QString m_TemplateText;
00111
00112 #if 0 // Not currently used
00113 bool m_usingAltArea;
00114 #endif
00115 bool m_ShrinkNarrow;
00116 Qt::TextElideMode m_Cutdown;
00117 bool m_MultiLine;
00118 int m_Ascent;
00119 int m_Descent;
00120 int m_leftBearing;
00121 int m_rightBearing;
00122 int m_Leading;
00123 int m_extraLeading;
00124 int m_lineHeight;
00125 int m_textCursor;
00126
00127 QVector<QTextLayout *> m_Layouts;
00128
00129 MythFontProperties* m_Font;
00130 QMap<QString, MythFontProperties> m_FontStates;
00131
00132 bool m_colorCycling;
00133 QColor m_startColor, m_endColor;
00134 int m_numSteps, m_curStep;
00135 float curR, curG, curB;
00136 float incR, incG, incB;
00137
00138 enum Constants {ScrollBounceDelay = 250};
00139 enum ScrollDir {ScrollNone, ScrollLeft, ScrollRight, ScrollUp, ScrollDown,
00140 ScrollHorizontal, ScrollVertical};
00141
00142 int m_scrollPause;
00143 int m_scrollOffset;
00144 bool m_scrollBounce;
00145 bool m_scrolling;
00146 ScrollDir m_scrollDirection;
00147
00148 enum TextCase {CaseNormal, CaseUpper, CaseLower, CaseCapitaliseFirst,
00149 CaseCapitaliseAll};
00150
00151 TextCase m_textCase;
00152
00153 friend class MythUITextEdit;
00154 friend class MythUIButton;
00155 friend class MythThemedMenu;
00156 friend class MythThemedMenuPrivate;
00157 };
00158
00159 #endif