1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 1999-2009 Licq developers
4  *
5  * Licq is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Licq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #ifndef MLEDIT_H
21 #define MLEDIT_H
22 
23 #include "config.h"
24 
25 #ifdef USE_KDE
26 # include <KDE/KTextEdit>
27 # define MLEDIT_BASE KTextEdit
28 #else
29 # include <QTextEdit>
30 # define MLEDIT_BASE QTextEdit
31 #endif
32 
33 
34 
35 namespace LicqQtGui
36 {
37 #ifdef HAVE_HUNSPELL
38 class SpellChecker;
39 #endif
40 
41 class MLEdit : public MLEDIT_BASE
42 {
43   Q_OBJECT
44 
45 public:
46   MLEdit(bool wordWrap, QWidget* parent = 0, bool useFixedFont = false, const char* name = 0);
47   virtual ~MLEdit();
48 
49   void appendNoNewLine(const QString& s);
50   void GotoEnd();
51 
52   void setBackground(const QColor& color);
53   void setForeground(const QColor& color);
54 
55 #ifndef USE_KDE
56   /**
57    * Enable/disable automatic spell checking
58    *
59    * @param check True to enable spell checking
60    */
61   void setCheckSpellingEnabled(bool check);
62 
63   /**
64    * Is spell checking enabled?
65    *
66    * @return True if spell checking is enabled
67    */
68   bool checkSpellingEnabled() const;
69 #endif
70 
71 #ifdef HAVE_HUNSPELL
72   /**
73    * Set dictionary file to use for spelling engine
74    * Will enable spell checking if not already enabled
75    *
76    * @param dicFile Dictionary file (ending with .dic) to use
77    */
78   void setSpellingDictionary(const QString& dicFile);
79 #endif
80 
81   /**
82    * Caclulate height for widget to fit a specified number of lines with
83    * current font
84    *
85    * @param lines Number of text lines to calculate for
86    * @return Widget height in pixels
87    */
88   int heightForLines(int lines) const;
89 
90   /**
91    * Set size hint as number of lines of text
92    *
93    * @param lines Lines of text that should be visible
94    */
95   void setSizeHintLines(int lines);
96 
97   /**
98    * Get recommended widget size
99    *
100    * @return Recommended size
101    */
102   QSize sizeHint() const;
103 
104 public slots:
105   /**
106    * Clear all text from the editor without clearing undo history
107    */
108   void clearKeepUndo();
109 
110   /**
111    * Delete current line
112    */
113   void deleteLine();
114 
115   /**
116    * Delete from cursor and to begining of line
117    * This is the opposite of Ctrl+K that's implemented in QTextEdit
118    */
119   void deleteLineBackwards();
120 
121   /**
122    * Delete from cursor and to the beginning of the current word
123    */
124   void deleteWordBackwards();
125 
126 signals:
127   void ctrlEnterPressed();
128   void clicked();
129 
130   /**
131    * Scroll up shortcut was pressed
132    */
133   void scrollUpPressed();
134 
135   /**
136    * Scroll down shortcut was pressed
137    */
138   void scrollDownPressed();
139 
140 private:
141 #ifdef HAVE_HUNSPELL
142   SpellChecker* mySpellChecker;
143   QString mySpellingDictionary;
144   QPoint myMenuPos;
145 #endif
146   bool myUseFixedFont;
147   bool myFixSetTextNewlines;
148   bool myLastKeyWasReturn;
149   int myFontHeight;
150   int myLinesHint;
151 
152   virtual void keyPressEvent(QKeyEvent* event);
153   virtual void mousePressEvent(QMouseEvent* event);
154 #ifndef USE_KDE
155   virtual void contextMenuEvent(QContextMenuEvent* event);
156 #endif
157 
158 #if 0
159 //TODO: This may or may not be needed for KTextEdit in KDE 4
160 public slots:
161   void setText(const QString& text);
162   virtual void setText(const QString& text, const QString& context);
163 #endif
164 
165 private slots:
166   void updateFont();
167   void toggleAllowTab();
168 #ifdef HAVE_HUNSPELL
169   void replaceWord();
170 #endif
171 };
172 
173 } // namespace LicqQtGui
174 
175 #endif
176