1 /* This file is (c) 2012 Tvangeste <i.4m.l33t@yandex.ru>
2  * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
3 
4 #ifndef TRANSLATEBOX_HH
5 #define TRANSLATEBOX_HH
6 
7 #include "extlineedit.hh"
8 #include "wordlist.hh"
9 #include "mutex.hh"
10 
11 #include <QWidget>
12 #include <QListWidget>
13 #include <QFocusEvent>
14 
15 class TranslateBox;
16 
17 class CompletionList : public WordList
18 {
19   Q_OBJECT
20 
21 public:
22   CompletionList(TranslateBox * parent);
23   int preferredHeight() const;
setTranslateLine(QLineEdit * line)24   virtual void setTranslateLine(QLineEdit * line)
25   {
26     WordList::setTranslateLine( line );
27     setFocusProxy( line );
28   }
29 
30 public slots:
31   bool acceptCurrentEntry();
32 
33 private:
34   virtual bool eventFilter( QObject *, QEvent * );
35   TranslateBox * translateBox;
36 };
37 
38 class TranslateBox : public QWidget
39 {
40   Q_OBJECT
41 
42 public:
43   explicit TranslateBox(QWidget * parent = 0);
44   void setPlaceholderText(const QString &text);
45   QLineEdit * translateLine();
46   WordList * wordList();
47   void setText(QString text, bool showPopup=true);
48   void setSizePolicy(QSizePolicy policy);
setSizePolicy(QSizePolicy::Policy hor,QSizePolicy::Policy ver)49   inline void setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver)
50   { setSizePolicy(QSizePolicy(hor, ver)); }
51 
52 signals:
53 
54 public slots:
55   void setPopupEnabled(bool enable);
56 
57 private slots:
58   void showPopup();
59   void rightButtonClicked();
60   void onTextEdit();
61 
62 private:
63   bool eventFilter(QObject *obj, QEvent *event);
64   CompletionList * word_list;
65   ExtLineEdit * translate_line;
66   bool m_popupEnabled;
67   Mutex translateBoxMutex;
68   // QCompleter * completer; // disabled for now
69 };
70 
71 #endif // TRANSLATEBOX_HH
72