1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 17:42:10 +01:00
falkonOfficial/src/navigation/websearchbar.cpp

115 lines
4.4 KiB
C++
Raw Normal View History

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"
#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));
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
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()));
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);
setupSearchTypes();
2011-03-02 16:57:41 +01:00
}
void WebSearchBar::setupSearchTypes()
{
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
}
void WebSearchBar::searchChanged(const ButtonWithMenu::Item &item)
2011-03-02 16:57:41 +01:00
{
setPlaceholderText(item.text);
2011-03-02 16:57:41 +01:00
}
void WebSearchBar::search()
{
// if (text().isEmpty())
// return;
ButtonWithMenu::Item* item = m_boxSearchType->activeItem();
2011-03-02 16:57:41 +01:00
QUrl searchUrl;
if (item->text == "Google")
2011-03-02 16:57:41 +01:00
searchUrl = QUrl("http://www.google.com/search?client=qupzilla&q="+text());
if (item->text == "Seznam")
2011-03-02 16:57:41 +01:00
searchUrl = QUrl("http://search.seznam.cz/?q="+text());
if (item->text == "Wikipedia (cs)")
2011-03-02 16:57:41 +01:00
searchUrl = QUrl("http://cs.wikipedia.org/w/index.php?search="+text());
if (item->text == "Wikipedia (en)")
2011-03-02 16:57:41 +01:00
searchUrl = QUrl("http://en.wikipedia.org/w/index.php?search="+text());
if (item->text == "CSFD")
searchUrl = QUrl("http://www.csfd.cz/hledat/?q="+text());
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()) {
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);
}