Project

General

Profile

0001-Use-KTextEdit-instead-of-QLineEdit.-On-most-KDE-syst.patch

The patch - jesperht, 03/13/2009 05:35 PM

View differences:

src/uisupport/inputline.cpp
24 24
#include "tabcompleter.h"
25 25

  
26 26
InputLine::InputLine(QWidget *parent)
27
  : QLineEdit(parent),
27
  :
28
#ifdef HAVE_KDE
29
    KTextEdit(parent),
30
#else
31
    QLineEdit(parent),
32
#endif
28 33
    idx(0),
29 34
    tabCompleter(new TabCompleter(this))
30 35
{
36
#ifdef HAVE_KDE
37
//This is done to make the KTextEdit look like a lineedit
38
  setMaximumHeight(document()->size().toSize().height());
39
  setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
40
  setAcceptRichText(false);
41
  connect(this, SIGNAL(textChanged()), this, SLOT(on_textChanged()));
42
#endif
43

  
31 44
  connect(this, SIGNAL(returnPressed()), this, SLOT(on_returnPressed()));
32 45
  connect(this, SIGNAL(textChanged(QString)), this, SLOT(on_textChanged(QString)));
33 46
}
......
91 104
  case Qt::Key_Select:		// for Qtopia
92 105
    emit returnPressed();
93 106

  
107
#ifdef HAVE_KDE
108
//Since this is a ktextedit, we don't have this signal "natively"
109
  case Qt::Key_Return:
110
    emit returnPressed();
111
#endif
112

  
94 113
  default:
114
#ifdef HAVE_KDE
115
    KTextEdit::keyPressEvent(event);
116
#else
95 117
    QLineEdit::keyPressEvent(event);
118
#endif
96 119
  }
97 120
}
98 121

  
src/uisupport/inputline.h
23 23

  
24 24
#include <QtGui>
25 25

  
26
#ifdef HAVE_KDE
27
#include <KDE/KTextEdit>
28
#endif
29

  
26 30
class TabCompleter;
27 31

  
28
class InputLine : public QLineEdit {
32
class InputLine : public
33
#ifdef HAVE_KDE
34
                  KTextEdit
35
#else
36
                  QLineEdit
37
#endif
38
                          {
29 39
  Q_OBJECT
30 40

  
31 41
public:
32 42
  InputLine(QWidget *parent = 0);
33 43
  ~InputLine();
34 44

  
45
#ifdef HAVE_KDE
46
//Compatibility methods with the rest of the classes which expects this to be a QLineEdit
47
  QString text() { return toPlainText(); };
48
  int cursorPosition() { return textCursor().position(); };
49
  void insert(const QString &newText) { insertPlainText(newText); };
50
  void backspace() { keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier));  };
51
  bool hasSelectedText() { return textCursor().hasSelection(); };
52
#endif
53

  
35 54
protected:
36 55
  //    virtual bool event(QEvent *);
37 56
  virtual void keyPressEvent(QKeyEvent * event);
......
40 59
private slots:
41 60
  void on_returnPressed();
42 61
  void on_textChanged(QString newText);
62
#ifdef HAVE_KDE
63
//Needed to emulate the signal that QLineEdit has
64
  void on_textChanged() { emit textChanged(toPlainText()); };
65
#endif
43 66

  
44 67
  bool addToHistory(const QString &text, bool temporary = false);
45 68

  
46 69
signals:
47 70
  void sendText(QString text);
71
#ifdef HAVE_KDE
72
//KTextEdit does not provide this signal, so we manually emit it in keyPressEvent()
73
  void returnPressed();
74
  void textChanged(QString newText);
75
#endif
48 76

  
49 77
private:
50 78
  QStringList history;
51
-