1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the demonstration applications of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL21$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** $QT_END_LICENSE$ 31 ** 32 ****************************************************************************/ 33 34 #ifndef URLLINEEDIT_H 35 #define URLLINEEDIT_H 36 37 #include <QtCore/QUrl> 38 #include <QtWidgets/QWidget> 39 #include <QtWidgets/QStyleOptionFrame> 40 41 QT_BEGIN_NAMESPACE 42 class QLineEdit; 43 QT_END_NAMESPACE 44 45 class ClearButton; 46 class ExLineEdit : public QWidget 47 { 48 Q_OBJECT 49 50 public: 51 ExLineEdit(QWidget *parent = 0); 52 lineEdit()53 inline QLineEdit *lineEdit() const { return m_lineEdit; } 54 55 void setLeftWidget(QWidget *widget); 56 QWidget *leftWidget() const; 57 58 QSize sizeHint() const; 59 60 QVariant inputMethodQuery(Qt::InputMethodQuery property) const; 61 protected: 62 void focusInEvent(QFocusEvent *event); 63 void focusOutEvent(QFocusEvent *event); 64 void keyPressEvent(QKeyEvent *event); 65 void paintEvent(QPaintEvent *event); 66 void resizeEvent(QResizeEvent *event); 67 void inputMethodEvent(QInputMethodEvent *e); 68 bool event(QEvent *event); 69 70 protected: 71 void updateGeometries(); 72 void initStyleOption(QStyleOptionFrameV2 *option) const; 73 74 QWidget *m_leftWidget; 75 QLineEdit *m_lineEdit; 76 ClearButton *m_clearButton; 77 }; 78 79 class UrlIconLabel; 80 class WebView; 81 class UrlLineEdit : public ExLineEdit 82 { 83 Q_OBJECT 84 85 public: 86 UrlLineEdit(QWidget *parent = 0); 87 void setWebView(WebView *webView); 88 89 protected: 90 void paintEvent(QPaintEvent *event); 91 void focusOutEvent(QFocusEvent *event); 92 93 private slots: 94 void webViewUrlChanged(const QUrl &url); 95 void webViewIconChanged(); 96 97 private: 98 QLinearGradient generateGradient(const QColor &color) const; 99 WebView *m_webView; 100 UrlIconLabel *m_iconLabel; 101 QColor m_defaultBaseColor; 102 103 }; 104 105 106 #endif // URLLINEEDIT_H 107 108