1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2002-2009,2011 Licq developers <licq-dev@googlegroups.com>
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 MLVIEW_H
21 #define MLVIEW_H
22 
23 #include <QTextBrowser>
24 
25 namespace LicqQtGui
26 {
27 
28 class MLView : public QTextBrowser
29 {
30   Q_OBJECT
31 public:
32   MLView(QWidget* parent = 0);
~MLView()33   virtual ~MLView() {}
34 
35   void GotoHome();
36   void GotoEnd();
37 
38   bool hasMarkedText() const;
39   QString markedText() const;
40 
41   void setBackground(const QColor&);
42   void setForeground(const QColor&);
43   void setHandleLinks(bool enable);
44 
45   static QString toRichText(const QString& s, bool highlightURLs = false, bool useHTML = false, QRegExp highlight = QRegExp());
46 
47   /**
48    * Caclulate height for widget to fit a specified number of lines with
49    * current font
50    *
51    * @param lines Number of text lines to calculate for
52    * @return Widget height in pixels
53    */
54   int heightForLines(int lines) const;
55 
56   /**
57    * Set size hint as number of lines of text
58    *
59    * @param lines Lines of text that should be visible
60    */
61   void setSizeHintLines(int lines);
62 
63   /**
64    * Get recommended widget size
65    *
66    * @return Recommended size
67    */
68   QSize sizeHint() const;
69 
70 protected:
71   virtual void contextMenuEvent(QContextMenuEvent* event);
72   virtual QMimeData* createMimeDataFromSelection() const;
73   virtual void resizeEvent(QResizeEvent* event);
74 
75 public slots:
76   /**
77    * Append text to view area
78    *
79    * @param s Text to add
80    * @param True if s is rich text, false for plain text
81    */
82   void append(const QString& s, bool richText = true);
83 
84   virtual void setSource(const QUrl& url);
85 
86   /**
87    * Scroll the view one page down
88    */
89   void scrollPageDown();
90 
91   /**
92    * Scroll the view one page up
93    */
94   void scrollPageUp();
95 
96 private slots:
97   void slotCopyUrl();
98   void makeQuote();
99   void updateFont();
100 
101 private:
102   bool m_handleLinks;
103   QString m_url;
104   int myFontHeight;
105   int myLinesHint;
106 
107 signals:
108   void quote(const QString& text);
109 };
110 
111 } // namespace LicqQtGui
112 
113 #endif
114