2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2010-2011 nowrep
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "websearchbar.h"
|
|
|
|
#include "qupzilla.h"
|
|
|
|
#include "webview.h"
|
|
|
|
#include "clickablelabel.h"
|
2011-06-06 19:38:37 +02:00
|
|
|
#include "buttonwithmenu.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
WebSearchBar::WebSearchBar(QupZilla* mainClass, QWidget* parent)
|
2011-03-02 16:57:41 +01:00
|
|
|
:LineEdit(parent)
|
|
|
|
,p_QupZilla(mainClass)
|
|
|
|
{
|
|
|
|
m_buttonSearch = new ClickableLabel(this);
|
|
|
|
m_buttonSearch->setPixmap(QPixmap(":/icons/locationbar/search.png"));
|
|
|
|
m_buttonSearch->setCursor(QCursor(Qt::PointingHandCursor));
|
2011-05-25 14:26:36 +02:00
|
|
|
m_buttonSearch->setStyleSheet("QLabel{margin-bottom:2px;}");
|
2011-03-02 17:54:22 +01:00
|
|
|
m_buttonSearch->setFocusPolicy(Qt::ClickFocus);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-06-06 19:38:37 +02:00
|
|
|
m_boxSearchType = new ButtonWithMenu(this);
|
2011-03-02 16:57:41 +01:00
|
|
|
m_boxSearchType->setMaximumSize(35, 25);
|
|
|
|
m_boxSearchType->setMinimumSize(35, 25);
|
|
|
|
|
|
|
|
this->setMinimumHeight(25);
|
|
|
|
this->setMaximumHeight(25);
|
|
|
|
m_boxSearchType->setStyleSheet("QToolButton{border-image: url(:/icons/locationbar/searchchoose.png); padding-left:-6px; margin-left:2px;}"
|
|
|
|
"QToolButton::menu-indicator {background-image: url(:icons/locationbar/arrow-down.gif); background-repeat: no-repeat;}");
|
|
|
|
|
|
|
|
addWidget(m_buttonSearch, LineEdit::RightSide);
|
|
|
|
|
|
|
|
connect(this, SIGNAL(returnPressed()), this, SLOT(search()));
|
|
|
|
connect(m_buttonSearch, SIGNAL(clicked(QPoint)), this, SLOT(search()));
|
2011-06-06 19:38:37 +02:00
|
|
|
connect(m_boxSearchType, SIGNAL(activeItemChanged(ButtonWithMenu::Item)), this, SLOT(searchChanged(ButtonWithMenu::Item)));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
setStyleSheet("QLineEdit { background: transparent; border-image: url(:/icons/locationbar/lineedit.png) ;border-width:4;color:black;}");
|
|
|
|
|
2011-03-05 11:16:23 +01:00
|
|
|
setLeftMargin(33);
|
2011-03-02 16:57:41 +01:00
|
|
|
setWidgetSpacing(0);
|
2011-06-06 19:38:37 +02:00
|
|
|
setupSearchTypes();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebSearchBar::setupSearchTypes()
|
|
|
|
{
|
2011-06-06 19:38:37 +02:00
|
|
|
QList<ButtonWithMenu::Item> items;
|
|
|
|
items.append(ButtonWithMenu::Item("Google", QIcon(":/icons/menu/google.png")));
|
|
|
|
items.append(ButtonWithMenu::Item("Seznam", QIcon(":/icons/menu/cz_seznam.png")));
|
|
|
|
items.append(ButtonWithMenu::Item("Wikipedia (en)", QIcon(":/icons/menu/icon-wikipedia.png")));
|
|
|
|
items.append(ButtonWithMenu::Item("Wikipedia (cs)", QIcon(":/icons/menu/icon-wikipedia.png")));
|
|
|
|
items.append(ButtonWithMenu::Item("CSFD", QIcon(":/icons/menu/csfd.png")));
|
|
|
|
items.append(ButtonWithMenu::Item("Youtube", QIcon(":/icons/menu/youtube.png")));
|
|
|
|
m_boxSearchType->addItems(items);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-06-06 19:38:37 +02:00
|
|
|
void WebSearchBar::searchChanged(const ButtonWithMenu::Item &item)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-06-06 19:38:37 +02:00
|
|
|
setPlaceholderText(item.text);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebSearchBar::search()
|
|
|
|
{
|
2011-03-17 15:37:21 +01:00
|
|
|
// if (text().isEmpty())
|
|
|
|
// return;
|
2011-06-06 19:38:37 +02:00
|
|
|
ButtonWithMenu::Item* item = m_boxSearchType->activeItem();
|
2011-03-02 16:57:41 +01:00
|
|
|
QUrl searchUrl;
|
2011-06-06 19:38:37 +02:00
|
|
|
if (item->text == "Google")
|
2011-03-02 16:57:41 +01:00
|
|
|
searchUrl = QUrl("http://www.google.com/search?client=qupzilla&q="+text());
|
2011-06-06 19:38:37 +02:00
|
|
|
if (item->text == "Seznam")
|
2011-03-02 16:57:41 +01:00
|
|
|
searchUrl = QUrl("http://search.seznam.cz/?q="+text());
|
2011-06-06 19:38:37 +02:00
|
|
|
if (item->text == "Wikipedia (cs)")
|
2011-03-02 16:57:41 +01:00
|
|
|
searchUrl = QUrl("http://cs.wikipedia.org/w/index.php?search="+text());
|
2011-06-06 19:38:37 +02:00
|
|
|
if (item->text == "Wikipedia (en)")
|
2011-03-02 16:57:41 +01:00
|
|
|
searchUrl = QUrl("http://en.wikipedia.org/w/index.php?search="+text());
|
2011-06-06 19:38:37 +02:00
|
|
|
if (item->text == "CSFD")
|
2011-03-17 15:37:21 +01:00
|
|
|
searchUrl = QUrl("http://www.csfd.cz/hledat/?q="+text());
|
2011-06-06 19:38:37 +02:00
|
|
|
if (item->text == "Youtube")
|
2011-03-02 16:57:41 +01:00
|
|
|
searchUrl = QUrl("http://www.youtube.com/results?search_query="+text());
|
|
|
|
|
|
|
|
p_QupZilla->weView()->load(searchUrl);
|
|
|
|
p_QupZilla->weView()->setFocus();
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void WebSearchBar::focusOutEvent(QFocusEvent* e)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
if (text().isEmpty()) {
|
2011-06-06 19:38:37 +02:00
|
|
|
QString search = m_boxSearchType->activeItem()->text;
|
2011-03-02 16:57:41 +01:00
|
|
|
//clear();
|
|
|
|
setPlaceholderText(search);
|
|
|
|
}
|
|
|
|
QLineEdit::focusOutEvent(e);
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void WebSearchBar::focusInEvent(QFocusEvent* e)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
QString search = m_boxSearchType->toolTip();
|
|
|
|
|
|
|
|
if (text() == search) {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
QLineEdit::focusInEvent(e);
|
|
|
|
}
|