ginebra2/UrlSearchSnippet.h
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
child 12 afcd8e6d025b
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
     4 *
     9 * Initial Contributors:
     5 * This program is free software: you can redistribute it and/or modify
    10 * Nokia Corporation - initial contribution.
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
    11 *
     8 *
    12 * Contributors:
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
    13 *
    13 *
    14 * Description: 
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
    15 *
    19 *
    16 */
    20 */
    17 
       
    18 
    21 
    19 #ifndef __URLSEARCH_SNIPPET_H
    22 #ifndef __URLSEARCH_SNIPPET_H
    20 #define __URLSEARCH_SNIPPET_H
    23 #define __URLSEARCH_SNIPPET_H
    21 
    24 
       
    25 #include "EditorWidget.h"
    22 #include "NativeChromeItem.h"
    26 #include "NativeChromeItem.h"
    23 
    27 
    24 namespace GVA {
    28 namespace GVA {
    25 
    29 
    26 class ChromeWidget;
    30 class ChromeWidget;
    27 
    31 class GUrlSearchItem : public NativeChromeItem
    28 class UrlEditorWidget : public QGraphicsTextItem
       
    29 {
    32 {
    30     Q_OBJECT
    33     Q_OBJECT
    31 
    34 
    32 public:
    35 public:
    33     UrlEditorWidget(QGraphicsItem * parent);
    36     GUrlSearchItem(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent = 0);
    34     virtual ~UrlEditorWidget();
    37     virtual ~GUrlSearchItem();
    35 
    38     QString url() const { return m_urlSearchEditor->text();}
    36     void setText(const QString & text);
    39     void setUrl(const QString &url) {m_urlSearchEditor->setText(url);}
    37 
       
    38     qreal cursorX();
       
    39 
    40 
    40 protected:
    41 protected:
    41     virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
    42     virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
    42     virtual void keyPressEvent(QKeyEvent * event);
    43     virtual void resizeEvent(QGraphicsSceneResizeEvent * event);
    43 
       
    44 signals:
       
    45     void cursorXChanged(qreal newx);
       
    46 
    44 
    47 private:
    45 private:
    48     QTextLine m_textLine;
    46     void loadToMainWindow();
    49 };
    47     void updateUrlSearchBtn();
    50 
    48     QString formattedUrl() const; 
    51 class UrlSearchSnippet : public NativeChromeItem
       
    52 {
       
    53     Q_OBJECT
       
    54 
       
    55 public:
       
    56     UrlSearchSnippet(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent = 0);
       
    57     virtual ~UrlSearchSnippet();
       
    58 
       
    59 protected:
       
    60     virtual bool eventFilter(QObject * object, QEvent * event);
       
    61     virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
       
    62     virtual void resizeEvent(QGraphicsSceneResizeEvent * event);
       
    63 
       
    64 signals:
       
    65     void activated();
       
    66 
    49 
    67 private slots:
    50 private slots:
    68     void resize();
    51     void onChromeComplete();
    69     void setUrlText(const QString & text);
       
    70     void setStarted();
    52     void setStarted();
    71     void setProgress(int percent);
    53     void setProgress(int percent);
    72     void setFinished(bool ok);
    54     void setFinished(bool ok);
       
    55     void setPageCreated();
       
    56     void setPageChanged();
    73     void clearProgress();
    57     void clearProgress();
    74     void viewChanged();
    58     void viewChanged();
    75     void makeVisible(qreal cursorX);
    59     void urlSearchActivatedByEnterKey();
    76 
    60     void urlSearchActivated();
    77 private:
    61     void updateLoadState();
    78     void internalScroll(qreal deltaX);
    62     void focusChanged(bool focusIn);
       
    63     void resize();
       
    64     void updateLoadStateAndSuggest();
       
    65     void onNewWindowTransitionComplete();
       
    66     void tapped(QPointF&);
    79 
    67 
    80 private:
    68 private:
    81     ChromeWidget * m_chrome;
    69     ChromeWidget * m_chrome;
    82     QString m_text;
       
    83     int m_percent;
       
    84     int m_pendingClearCalls;
       
    85 
    70 
    86     // Style parameters.
    71     // configurable attributes
    87 
    72     qreal m_border;
    88     QColor m_textColor;
    73     qreal m_padding;
    89     QColor m_backgroundColor;
    74     qreal m_viewPortWidth;
       
    75     qreal m_viewPortHeight;
    90     QColor m_borderColor;
    76     QColor m_borderColor;
    91 
    77 
    92     int m_border;
    78     // ui components
    93     int m_padding;
    79     QGraphicsWidget * m_viewPort;
       
    80     ActionButton * m_urlSearchBtn;
       
    81     GProgressEditor * m_urlSearchEditor;
    94 
    82 
    95     // Cached values used for painting and scrolling.
    83     // variables
       
    84     int m_pendingClearCalls;
       
    85     qreal m_iconWidth;
       
    86     qreal m_iconHeight;
       
    87     bool m_backFromNewWinTrans;
       
    88     bool m_justFocusIn;
       
    89 };
    96 
    90 
    97     qreal m_viewPortWidth;
    91 class GUrlSearchSnippet : public ChromeSnippet {
    98     qreal m_viewPortHeight;
    92   Q_OBJECT
       
    93 public:
       
    94   GUrlSearchSnippet(const QString & elementId, ChromeWidget * chrome,
       
    95               QGraphicsWidget * widget, const QWebElement & element);
       
    96   
       
    97   static GUrlSearchSnippet * instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element);
    99 
    98 
   100     // At runtime, UrlSearchSnippet is parent to a QGraphicsWidget
    99   /// The URL of the web page.
   101     // (m_viewPort) that is parent to a UrlEditorWidget (m_editor).
   100   QString url() const;
       
   101   void setUrl(const QString &url);
       
   102   Q_PROPERTY(QString url READ url WRITE setUrl)
   102 
   103 
   103     QGraphicsWidget * m_viewPort;
   104 //public slots:
   104     UrlEditorWidget * m_editor;
   105 
       
   106 private:
       
   107   GUrlSearchItem *urlSearchItem();
       
   108   GUrlSearchItem const *constUrlSearchItem() const;
   105 };
   109 };
   106 
   110 
   107 } // namespace GVA
   111 } // namespace GVA
   108 
   112 
   109 #endif // __URLSEARCH_SNIPPET_H
   113 #endif // __URLSEARCH_SNIPPET_H