ginebra2/EditorWidget.h
changeset 6 1c3b8676e58c
parent 5 0f2326c2a325
child 10 232fbd5a2dcb
equal deleted inserted replaced
5:0f2326c2a325 6:1c3b8676e58c
    44 
    44 
    45     qreal cursorX();
    45     qreal cursorX();
    46     qreal anchorX();
    46     qreal anchorX();
    47     QRectF selectionRectF();
    47     QRectF selectionRectF();
    48     void setText(const QString & text);
    48     void setText(const QString & text);
       
    49     void setMaxTextLength(int length);
    49     void selectAll();
    50     void selectAll();
    50     void unselect();
    51     void unselect();
    51     qreal textWidth();
    52     qreal textWidth();
    52     void setCursorPosition(int pos);
    53     void setCursorPosition(int pos);
    53     void setAutoUppercase(bool enable) { m_autoUppercase = enable; }
       
    54     bool hasSelection() { return (cursorX()!= anchorX()); }
    54     bool hasSelection() { return (cursorX()!= anchorX()); }
       
    55     Qt::InputMethodHints inputMethodHints() const { return m_hints; }
       
    56     void setInputMethodHints(Qt::InputMethodHints hints);
    55 
    57 
    56   protected:
    58   protected:
    57     virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
    59     virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
    58     virtual void keyPressEvent(QKeyEvent * event);
    60     virtual void keyPressEvent(QKeyEvent * event);
    59     virtual void keyReleaseEvent(QKeyEvent * event);
    61     virtual void keyReleaseEvent(QKeyEvent * event);
    62     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
    64     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
    63     virtual void focusInEvent(QFocusEvent * event);
    65     virtual void focusInEvent(QFocusEvent * event);
    64     virtual void focusOutEvent(QFocusEvent * event);
    66     virtual void focusOutEvent(QFocusEvent * event);
    65     virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
    67     virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
    66 
    68 
       
    69   private slots:
       
    70     void contentsChange(int position, int charsRemoved, int charsAdded);
       
    71 
    67   signals:
    72   signals:
    68     void cursorXChanged(qreal newx);
    73     void cursorXChanged(qreal newx);
    69     void textMayChanged();
    74     void textMayChanged();
    70     void focusChanged(bool focusIn);
    75     void focusChanged(bool focusIn);
    71     void tapped(QPointF& pos);
    76     void tapped(QPointF& pos);
    72 
    77 
    73   private:
    78   private:
    74     QTextLine m_textLine;
    79     QTextLine m_textLine;
    75     int m_defaultStartDragDistance;
    80     int m_defaultStartDragDistance;
    76     bool m_predictionDisabled;
    81     int m_maxTextLength;
    77     bool m_autoUppercase;
    82     Qt::InputMethodHints m_hints;
    78   };
    83   };
    79 
    84 
    80   class GLineEditor : public QGraphicsWidget
    85   class GLineEditor : public QGraphicsWidget
    81   {
    86   {
    82     Q_OBJECT
    87     Q_OBJECT
    99     void removeFocus() { m_editor->clearFocus(); }
   104     void removeFocus() { m_editor->clearFocus(); }
   100     void setCursorPosition (int pos) { m_editor->setCursorPosition(pos); }
   105     void setCursorPosition (int pos) { m_editor->setCursorPosition(pos); }
   101     void shiftToLeftEnd() { setCursorPosition(0); }
   106     void shiftToLeftEnd() { setCursorPosition(0); }
   102     int characterCount() { return m_editor->document()->characterCount(); }
   107     int characterCount() { return m_editor->document()->characterCount(); }
   103     bool hasSelection() { return m_editor->hasSelection(); }
   108     bool hasSelection() { return m_editor->hasSelection(); }
       
   109     Qt::InputMethodHints inputMethodHints() { return m_editor->inputMethodHints(); }
       
   110     // Calling this function will overwrite the existing hints
       
   111     void setInputMethodHints(Qt::InputMethodHints hints) { m_editor->setInputMethodHints(hints); }
       
   112     void setMaxTextLength(int length) { m_editor->setMaxTextLength(length); }
   104 
   113 
   105   protected:
   114   protected:
   106     virtual bool eventFilter(QObject * object, QEvent * event);
   115     virtual bool eventFilter(QObject * object, QEvent * event);
   107     virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
   116     virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
   108     virtual void resizeEvent(QGraphicsSceneResizeEvent * event);
   117     virtual void resizeEvent(QGraphicsSceneResizeEvent * event);
   193     void setText(const QString & text){ m_textEditor->setText(text); }
   202     void setText(const QString & text){ m_textEditor->setText(text); }
   194     int characterCount() { return m_textEditor->characterCount(); }
   203     int characterCount() { return m_textEditor->characterCount(); }
   195     void setCursorPosition(int pos) { m_textEditor->setCursorPosition(pos); }
   204     void setCursorPosition(int pos) { m_textEditor->setCursorPosition(pos); }
   196     void selectAll() { m_textEditor->selectAll(); }
   205     void selectAll() { m_textEditor->selectAll(); }
   197     void unselect() { m_textEditor->unselect(); }
   206     void unselect() { m_textEditor->unselect(); }
       
   207     int getTextOptions() { return (int) m_textEditor->inputMethodHints(); }
       
   208     // Calling this function will overwrite the existing options
       
   209     void setTextOptions (int flag);
       
   210     void setMaxTextLength(int length) { m_textEditor->setMaxTextLength(length); }
       
   211  
       
   212   private slots:	
       
   213 	void tapped(QPointF&);
       
   214 	void focusChanged(bool focusIn);
       
   215 
   198   protected:
   216   protected:
   199     virtual void resizeEvent(QGraphicsSceneResizeEvent * ev);
   217     virtual void resizeEvent(QGraphicsSceneResizeEvent * ev);
   200   private:
   218   private:
   201     GTextEditor * m_textEditor;
   219     GTextEditor * m_textEditor;
       
   220 	 bool m_justFocusIn;
   202   };
   221   };
   203 
   222 
   204 } // namespace GVA
   223 } // namespace GVA
   205 
   224 
   206 #endif // __EDITOR_WIDGET_H__
   225 #endif // __EDITOR_WIDGET_H__