ginebra2/EditorWidget.h
changeset 15 73c48011b8c7
parent 10 232fbd5a2dcb
equal deleted inserted replaced
13:491a1d15372f 15:73c48011b8c7
    22 #ifndef __EDITOR_WIDGET_H__
    22 #ifndef __EDITOR_WIDGET_H__
    23 #define __EDITOR_WIDGET_H__
    23 #define __EDITOR_WIDGET_H__
    24 
    24 
    25 #include "ActionButton.h"
    25 #include "ActionButton.h"
    26 #include "NativeChromeItem.h"
    26 #include "NativeChromeItem.h"
       
    27 #include "TitleItem.h"
    27 
    28 
    28 #include <QGraphicsTextItem>
    29 #include <QGraphicsTextItem>
    29 #include <QGraphicsWidget>
    30 #include <QGraphicsWidget>
    30 #include <QtGui>
    31 #include <QtGui>
    31 
    32 
    53     void setCursorPosition(int pos);
    54     void setCursorPosition(int pos);
    54     bool hasSelection() { return (cursorX()!= anchorX()); }
    55     bool hasSelection() { return (cursorX()!= anchorX()); }
    55     Qt::InputMethodHints inputMethodHints() const { return m_hints; }
    56     Qt::InputMethodHints inputMethodHints() const { return m_hints; }
    56     void setInputMethodHints(Qt::InputMethodHints hints);
    57     void setInputMethodHints(Qt::InputMethodHints hints);
    57     void setSpecificButton(QString& commitString, QString& buttonIconPath);
    58     void setSpecificButton(QString& commitString, QString& buttonIconPath);
       
    59     void launchVKB();
       
    60     void  sendInputPanelEvent(QEvent::Type type);
    58 
    61 
    59   protected:
    62   protected:
    60     virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
    63     virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
    61     virtual void keyPressEvent(QKeyEvent * event);
    64     virtual void keyPressEvent(QKeyEvent * event);
    62     virtual void keyReleaseEvent(QKeyEvent * event);
    65     virtual void keyReleaseEvent(QKeyEvent * event);
    97 
   100 
    98     void selectAll() { m_editor->selectAll(); }
   101     void selectAll() { m_editor->selectAll(); }
    99     void unselect() { m_editor->unselect(); }
   102     void unselect() { m_editor->unselect(); }
   100 
   103 
   101     void setTextColor(QColor & color);
   104     void setTextColor(QColor & color);
       
   105 	
   102     void setBackgroundColor(QColor & color) {m_backgroundColor = color;}
   106     void setBackgroundColor(QColor & color) {m_backgroundColor = color;}
   103     void setPadding(qreal padding);
   107     void setPadding(qreal padding);
   104     void setRightTextMargin(qreal margin);
   108     void setRightTextMargin(qreal margin);
   105     QString text() const;
   109     QString text() const;
   106     void updateEditor();
   110     void updateEditor();
   107     bool tappedOnText(qreal x) const;
   111     bool tappedOnText(qreal x) const;
   108     void grabFocus() { m_editor->setFocus(); }
   112     void grabFocus() { m_editor->setFocus(); }
   109     void removeFocus() { m_editor->clearFocus(); }
   113     void removeFocus() {m_editor->clearFocus(); }
   110     void setCursorPosition (int pos) { m_editor->setCursorPosition(pos); }
   114     void setCursorPosition (int pos) { m_editor->setCursorPosition(pos); }
   111     void shiftToLeftEnd() { setCursorPosition(0); }
   115     void shiftToLeftEnd() { setCursorPosition(0); }
   112     int characterCount() { return m_editor->document()->characterCount(); }
   116     int characterCount() { return m_editor->document()->characterCount(); }
   113     bool hasSelection() { return m_editor->hasSelection(); }
   117     bool hasSelection() { return m_editor->hasSelection(); }
   114     Qt::InputMethodHints inputMethodHints() { return m_editor->inputMethodHints(); }
   118     Qt::InputMethodHints inputMethodHints() { return m_editor->inputMethodHints(); }
   115     // Calling this function will overwrite the existing hints
   119     // Calling this function will overwrite the existing hints
   116     void setInputMethodHints(Qt::InputMethodHints hints) { m_editor->setInputMethodHints(hints); }
   120     void setInputMethodHints(Qt::InputMethodHints hints) { m_editor->setInputMethodHints(hints); }
   117     void setMaxTextLength(int length) { m_editor->setMaxTextLength(length); }
   121     void setMaxTextLength(int length) { m_editor->setMaxTextLength(length);}
       
   122 #ifdef BROWSER_LAYOUT_TENONE
       
   123     void changeEditorMode(bool edit);
       
   124     void setTitle(const QString & text);
       
   125     void setTitleColor(QColor & color);
       
   126     void setTitleFont(QFont & font);
       
   127 
       
   128 #endif
   118     void setSpecificButton(QString commitString, QString buttonIcon) { m_editor->setSpecificButton(commitString, buttonIcon);}
   129     void setSpecificButton(QString commitString, QString buttonIcon) { m_editor->setSpecificButton(commitString, buttonIcon);}
       
   130     void closeVKB();
       
   131     void openVKB();
   119 
   132 
   120   protected:
   133   protected:
   121     virtual bool eventFilter(QObject * object, QEvent * event);
   134     virtual bool eventFilter(QObject * object, QEvent * event);
   122     virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
   135     virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
   123     virtual void resizeEvent(QGraphicsSceneResizeEvent * event);
   136     virtual void resizeEvent(QGraphicsSceneResizeEvent * event);
   124 
   137 
   125   signals:
   138   signals:
   126     void activated();
   139     void activated();
   127     void textMayChanged();
   140     void textMayChanged();
       
   141     void contentsChange(int position, int charsRemoved, int charsAdded);
   128     void focusChanged(bool focusIn);
   142     void focusChanged(bool focusIn);
   129     void tapped(QPointF& pos);
   143     void tapped(QPointF& pos);
       
   144     void titleMouseEvent(QPointF& pos);
   130 
   145 
   131   private slots:
   146   private slots:
   132     void makeVisible(qreal cursorX);
   147     void makeVisible(qreal cursorX);
   133 
   148 
   134   public slots:
   149   public slots:
   140   protected:
   155   protected:
   141     ChromeWidget * m_chrome;
   156     ChromeWidget * m_chrome;
   142 
   157 
   143     // Cached values used for painting and scrolling.
   158     // Cached values used for painting and scrolling.
   144     qreal m_viewPortWidth;
   159     qreal m_viewPortWidth;
   145     qreal m_viewPortHeight;
   160 #ifdef BROWSER_LAYOUT_TENONE
       
   161     qreal m_titleModeWidth;
       
   162     GTitleItem * m_title;
       
   163     QColor m_titleColor;
       
   164 #endif
   146 
   165 
   147     // At runtime, UrlSearchSnippet is parent to a QGraphicsWidget
   166     // At runtime, UrlSearchSnippet is parent to a QGraphicsWidget
   148     // (m_viewPort) that is parent to a UrlEditorWidget (m_editor).
   167     // (m_viewPort) that is parent to a UrlEditorWidget (m_editor).
   149     QGraphicsWidget * m_viewPort;
   168     QGraphicsWidget * m_viewPort;
   150     GTextLineItem * m_editor;
   169     GTextLineItem * m_editor;
   151 
   170 
   152     // Attributes
   171     // Attributes
   153     QString m_text;
   172     QString m_text;
   154     QColor m_textColor;
   173     QColor m_textColor;
       
   174 
   155     QColor m_backgroundColor;
   175     QColor m_backgroundColor;
   156     qreal m_padding;
   176     qreal m_padding;
   157     //TODO: add left margin too
   177     //TODO: add left margin too
   158     qreal m_rightTextMargin;
   178     qreal m_rightTextMargin;
   159 
   179