| 
									
										
										
										
											2009-12-02 10:12:41 +01:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-03-05 11:25:49 +01:00
										 |  |  | ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2009-12-02 10:12:41 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Commercial Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Licensees holding valid Qt Commercial licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the Qt Commercial License Agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							|  |  |  | ** a written agreement between you and Nokia. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
					
						
							|  |  |  | ** General Public License version 2.1 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
					
						
							|  |  |  | ** packaging of this file.  Please review the following information to | 
					
						
							|  |  |  | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
					
						
							|  |  |  | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** If you are unsure which license is appropriate for your use, please | 
					
						
							|  |  |  | ** contact the sales department at http://qt.nokia.com/contact.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | **************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  | #ifndef TEXTEDITOROVERLAY_H
 | 
					
						
							|  |  |  | #define TEXTEDITOROVERLAY_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-01 16:29:45 +01:00
										 |  |  | #include <QtCore/QObject>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QtGui/QTextCursor>
 | 
					
						
							|  |  |  | #include <QtGui/QColor>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QT_FORWARD_DECLARE_CLASS(QWidget) | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace TextEditor { | 
					
						
							| 
									
										
										
										
											2010-11-01 16:29:45 +01:00
										 |  |  | class BaseTextEditor; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  | namespace Internal { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-01 16:29:45 +01:00
										 |  |  | struct OverlaySelection | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-08-05 15:01:20 +02:00
										 |  |  |     OverlaySelection():m_fixedLength(-1), m_dropShadow(false){} | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  |     QTextCursor m_cursor_begin; | 
					
						
							|  |  |  |     QTextCursor m_cursor_end; | 
					
						
							| 
									
										
										
										
											2009-12-01 14:47:10 +01:00
										 |  |  |     QColor m_fg; | 
					
						
							|  |  |  |     QColor m_bg; | 
					
						
							| 
									
										
										
										
											2009-11-30 13:56:54 +01:00
										 |  |  |     int m_fixedLength; | 
					
						
							| 
									
										
										
										
											2009-12-01 19:44:31 +01:00
										 |  |  |     bool m_dropShadow; | 
					
						
							| 
									
										
										
										
											2010-11-01 16:29:45 +01:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-01 16:29:45 +01:00
										 |  |  | class TextEditorOverlay : public QObject | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-01 16:29:45 +01:00
										 |  |  |     Q_OBJECT | 
					
						
							|  |  |  |     BaseTextEditor *m_editor; | 
					
						
							|  |  |  |     QWidget *m_viewport; | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 14:47:10 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2010-11-01 16:29:45 +01:00
										 |  |  |     QList<OverlaySelection> m_selections; | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-01 16:29:45 +01:00
										 |  |  | private: | 
					
						
							|  |  |  |     bool m_visible; | 
					
						
							|  |  |  |     int m_borderWidth; | 
					
						
							|  |  |  |     int m_dropShadowWidth; | 
					
						
							|  |  |  |     bool m_alpha; | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     TextEditorOverlay(BaseTextEditor *editor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QRect rect() const; | 
					
						
							|  |  |  |     void paint(QPainter *painter, const QRect &clip); | 
					
						
							| 
									
										
										
										
											2009-12-01 14:47:10 +01:00
										 |  |  |     void fill(QPainter *painter, const QColor &color, const QRect &clip); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  |     bool isVisible() const { return m_visible; } | 
					
						
							|  |  |  |     void setVisible(bool b); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-19 18:50:50 +01:00
										 |  |  |     inline void hide() { setVisible(false); } | 
					
						
							|  |  |  |     inline void show() { setVisible(true); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  |     void setBorderWidth(int bw) {m_borderWidth = bw; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void update(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-02 14:12:59 +01:00
										 |  |  |     void setAlpha(bool enabled) { m_alpha = enabled; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  |     void clear(); | 
					
						
							| 
									
										
										
										
											2010-01-19 12:28:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     enum OverlaySelectionFlags { | 
					
						
							|  |  |  |         LockSize = 1, | 
					
						
							|  |  |  |         DropShadow = 2, | 
					
						
							|  |  |  |         ExpandBegin = 4 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void addOverlaySelection(const QTextCursor &cursor, const QColor &fg, const QColor &bg, | 
					
						
							| 
									
										
										
										
											2010-08-05 15:01:20 +02:00
										 |  |  |                              uint overlaySelectionFlags = 0); | 
					
						
							| 
									
										
										
										
											2010-01-19 12:28:50 +01:00
										 |  |  |     void addOverlaySelection(int begin, int end, const QColor &fg, const QColor &bg, | 
					
						
							| 
									
										
										
										
											2010-08-05 15:01:20 +02:00
										 |  |  |                              uint overlaySelectionFlags = 0); | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     inline bool isEmpty() const { return m_selections.isEmpty(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-02 11:29:38 +01:00
										 |  |  |     inline int dropShadowWidth() const { return m_dropShadowWidth; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-19 12:28:50 +01:00
										 |  |  |     bool hasCursorInSelection(const QTextCursor &cursor) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2010-08-05 15:01:20 +02:00
										 |  |  |     QPainterPath createSelectionPath(const QTextCursor &begin, const QTextCursor &end, const QRect& clip); | 
					
						
							| 
									
										
										
										
											2009-12-01 19:44:31 +01:00
										 |  |  |     void paintSelection(QPainter *painter, const OverlaySelection &selection); | 
					
						
							|  |  |  |     void fillSelection(QPainter *painter, const OverlaySelection &selection, const QColor &color); | 
					
						
							| 
									
										
										
										
											2009-11-25 15:55:45 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace Internal
 | 
					
						
							|  |  |  | } // namespace TextEditor
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // TEXTEDITOROVERLAY_H
 |