2011-03-26 Andreas Kling <kling@webkit.org>

        Reviewed by Kenneth Rohde Christiansen.

        [Qt] Show page icons (favicons) in QtTestBrowser location bar.
        https://bugs.webkit.org/show_bug.cgi?id=57162

        * QtTestBrowser/QtTestBrowser.qrc:
        * QtTestBrowser/favicon.png: Added.
        * QtTestBrowser/locationedit.cpp:
        (defaultPageIcon):
        (LocationEdit::LocationEdit):
        (LocationEdit::setPageIcon):
        (LocationEdit::resizeEvent):
        (LocationEdit::updateInternalGeometry):
        * QtTestBrowser/locationedit.h:
        * QtTestBrowser/mainwindow.cpp:
        (MainWindow::buildUI):
        (MainWindow::onIconChanged):
        (MainWindow::onLoadStarted):
        * QtTestBrowser/mainwindow.h:

git-svn-id: svn://svn.chromium.org/blink/trunk@82046 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ee63dac3
2011-03-26 Andreas Kling <kling@webkit.org>
Reviewed by Kenneth Rohde Christiansen.
[Qt] Show page icons (favicons) in QtTestBrowser location bar.
https://bugs.webkit.org/show_bug.cgi?id=57162
* QtTestBrowser/QtTestBrowser.qrc:
* QtTestBrowser/favicon.png: Added.
* QtTestBrowser/locationedit.cpp:
(defaultPageIcon):
(LocationEdit::LocationEdit):
(LocationEdit::setPageIcon):
(LocationEdit::resizeEvent):
(LocationEdit::updateInternalGeometry):
* QtTestBrowser/locationedit.h:
* QtTestBrowser/mainwindow.cpp:
(MainWindow::buildUI):
(MainWindow::onIconChanged):
(MainWindow::onLoadStarted):
* QtTestBrowser/mainwindow.h:
2011-03-23 Martin Robinson <mrobinson@igalia.com> 2011-03-23 Martin Robinson <mrobinson@igalia.com>
Reviewed by Xan Lopez. Reviewed by Xan Lopez.
......
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file>useragentlist.txt</file> <file>useragentlist.txt</file>
<file>favicon.png</file>
</qresource> </qresource>
</RCC> </RCC>
/* /*
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
* Copyright (C) 2011 Andreas Kling <kling@webkit.org>
* *
* All rights reserved. * All rights reserved.
* *
...@@ -29,12 +30,35 @@ ...@@ -29,12 +30,35 @@
#ifndef QT_NO_INPUTDIALOG #ifndef QT_NO_INPUTDIALOG
static const QSize gPageIconSize(16, 16);
static QPixmap defaultPageIcon()
{
static QPixmap icon;
if (icon.isNull())
icon.load(":/favicon.png");
return icon;
}
LocationEdit::LocationEdit(QWidget* parent) LocationEdit::LocationEdit(QWidget* parent)
: QLineEdit(parent) : QLineEdit(parent)
, m_progress(0) , m_progress(0)
{ {
m_clearTimer.setSingleShot(true); m_clearTimer.setSingleShot(true);
connect(&m_clearTimer, SIGNAL(timeout()), this, SLOT(reset())); connect(&m_clearTimer, SIGNAL(timeout()), this, SLOT(reset()));
m_pageIconLabel = new QLabel(this);
m_pageIconLabel->setFixedSize(gPageIconSize);
m_pageIconLabel->setPixmap(defaultPageIcon());
}
void LocationEdit::setPageIcon(const QIcon& icon)
{
if (icon.isNull())
m_pageIconLabel->setPixmap(defaultPageIcon());
else
m_pageIconLabel->setPixmap(icon.pixmap(gPageIconSize));
} }
void LocationEdit::setProgress(int progress) void LocationEdit::setProgress(int progress)
...@@ -49,6 +73,30 @@ void LocationEdit::reset() ...@@ -49,6 +73,30 @@ void LocationEdit::reset()
setProgress(0); setProgress(0);
} }
void LocationEdit::resizeEvent(QResizeEvent*)
{
updateInternalGeometry();
}
void LocationEdit::updateInternalGeometry()
{
QStyleOptionFrameV3 styleOption;
initStyleOption(&styleOption);
QRect textRect = style()->subElementRect(QStyle::SE_LineEditContents, &styleOption, this);
const int spacing = 2;
int x = textRect.x() + spacing;
int y = (textRect.center().y() + 1) - gPageIconSize.height() / 2;
m_pageIconLabel->move(x, y);
QMargins margins = textMargins();
margins.setLeft(m_pageIconLabel->sizeHint().width() + spacing);
setTextMargins(margins);
}
void LocationEdit::paintEvent(QPaintEvent* ev) void LocationEdit::paintEvent(QPaintEvent* ev)
{ {
QColor backgroundColor = QApplication::palette().color(QPalette::Base); QColor backgroundColor = QApplication::palette().color(QPalette::Base);
......
...@@ -39,6 +39,8 @@ class LocationEdit : public QLineEdit { ...@@ -39,6 +39,8 @@ class LocationEdit : public QLineEdit {
public: public:
LocationEdit(QWidget* parent = 0); LocationEdit(QWidget* parent = 0);
void setPageIcon(const QIcon&);
public slots: public slots:
void setProgress(int progress); void setProgress(int progress);
...@@ -48,10 +50,14 @@ private slots: ...@@ -48,10 +50,14 @@ private slots:
protected: protected:
virtual void paintEvent(QPaintEvent*); virtual void paintEvent(QPaintEvent*);
virtual void focusInEvent(QFocusEvent*); virtual void focusInEvent(QFocusEvent*);
virtual void resizeEvent(QResizeEvent*);
private: private:
void updateInternalGeometry();
int m_progress; int m_progress;
QTimer m_clearTimer; QTimer m_clearTimer;
QLabel* m_pageIconLabel;
}; };
#endif #endif
......
...@@ -84,6 +84,8 @@ void MainWindow::buildUI() ...@@ -84,6 +84,8 @@ void MainWindow::buildUI()
connect(page(), SIGNAL(loadProgress(int)), urlEdit, SLOT(setProgress(int))); connect(page(), SIGNAL(loadProgress(int)), urlEdit, SLOT(setProgress(int)));
#endif #endif
connect(page()->mainFrame(), SIGNAL(loadStarted()), this, SLOT(onLoadStarted()));
connect(page()->mainFrame(), SIGNAL(iconChanged()), this, SLOT(onIconChanged()));
connect(page()->mainFrame(), SIGNAL(titleChanged(const QString&)), connect(page()->mainFrame(), SIGNAL(titleChanged(const QString&)),
this, SLOT(setWindowTitle(const QString&))); this, SLOT(setWindowTitle(const QString&)));
connect(page(), SIGNAL(windowCloseRequested()), this, SLOT(close())); connect(page(), SIGNAL(windowCloseRequested()), this, SLOT(close()));
...@@ -219,3 +221,17 @@ void MainWindow::openLocation() ...@@ -219,3 +221,17 @@ void MainWindow::openLocation()
urlEdit->setFocus(); urlEdit->setFocus();
#endif #endif
} }
void MainWindow::onIconChanged()
{
#ifndef QT_NO_INPUTDIALOG
urlEdit->setPageIcon(page()->mainFrame()->icon());
#endif
}
void MainWindow::onLoadStarted()
{
#ifndef QT_NO_INPUTDIALOG
urlEdit->setPageIcon(QIcon());
#endif
}
...@@ -58,6 +58,8 @@ protected slots: ...@@ -58,6 +58,8 @@ protected slots:
void openFile(); void openFile();
void openLocation(); void openLocation();
void changeLocation(); void changeLocation();
void onIconChanged();
void onLoadStarted();
protected: protected:
QString addressUrl() const; QString addressUrl() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment