From a86522cb83ed2f665161f507531f07dc6437e13f Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 31 Oct 2008 17:30:37 +0100 Subject: Various improvements on the street from Qt demo browser to KDE reKonq! - CMakeLists.txt working - data dirs - ... --- src/searchbar.cpp | 477 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 477 insertions(+) create mode 100644 src/searchbar.cpp (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp new file mode 100644 index 00000000..f1f6ef80 --- /dev/null +++ b/src/searchbar.cpp @@ -0,0 +1,477 @@ +/* ============================================================ + * + * This file is a part of the reKonq project + * + * Copyright (C) 2008 by Andrea Diamantini + * + * + * 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 2, 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. + * + * ============================================================ */ + +#include "searchbar.h" + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + + + +SearchBar::SearchBar() : + m_searchCombo(0), + m_searchMode(UseSearchProvider), + m_urlEnterLock(false), + m_process(0) +{ + m_searchCombo = new SearchBarCombo(0); + m_searchCombo->lineEdit()->installEventFilter(this); + connect(m_searchCombo, SIGNAL(activated(const QString &)), SLOT(startSearch(const QString &))); + connect(m_searchCombo, SIGNAL(iconClicked()), SLOT(showSelectionMenu())); + m_searchCombo->setWhatsThis(i18n("Search Bar

" + "Enter a search term. Click on the icon to change search mode or provider.

")); + + m_popupMenu = 0; + + m_searchComboAction = actionCollection()->addAction("toolbar_search_bar"); + m_searchComboAction->setText(i18n("Search Bar")); + m_searchComboAction->setDefaultWidget(m_searchCombo); + m_searchComboAction->setShortcutConfigurable(false); + + + KAction *a = actionCollection()->addAction("focus_search_bar"); + a->setText(i18n("Focus Searchbar")); + a->setShortcut(Qt::CTRL+Qt::Key_S); + connect(a, SIGNAL(triggered()), this, SLOT(focusSearchbar())); + + configurationChanged(); + + // parent is the KonqMainWindow and we want to listen to PartActivateEvent events. + parent->installEventFilter(this); +} + + + +SearchBar::~SearchBar() +{ + KConfigGroup config(KGlobal::config(), "SearchBar"); + config.writeEntry("Mode", (int) m_searchMode); + config.writeEntry("CurrentEngine", m_currentEngine); + + delete m_searchCombo; + m_searchCombo = 0L; + delete m_process; + m_process=0L; +} + +static QChar delimiter() +{ + static QChar s_delimiter = 0; + if (s_delimiter == 0) { + KConfig _config("kuriikwsfilterrc", KConfig::NoGlobals); + KConfigGroup config(&_config, "General"); + s_delimiter = config.readEntry("KeywordDelimiter", int(':')); + } + return s_delimiter; +} + + + +void SearchBar::nextSearchEntry() +{ + if (m_searchMode == FindInThisPage) { + m_searchMode = UseSearchProvider; + if (!m_searchEngines.isEmpty()) { + m_currentEngine = m_searchEngines.first(); + } else { + m_currentEngine = "google"; + } + } else { + int index = m_searchEngines.indexOf(m_currentEngine); + ++index; + if (index >= m_searchEngines.count()) { + m_searchMode = FindInThisPage; + } else { + m_currentEngine = m_searchEngines.at(index); + } + } + setIcon(); +} + +void SearchBar::previousSearchEntry() +{ + if (m_searchMode == FindInThisPage) { + m_searchMode = UseSearchProvider; + if (!m_searchEngines.isEmpty()) { + m_currentEngine = m_searchEngines.last(); + } else { + m_currentEngine = "google"; + } + } else { + int index = m_searchEngines.indexOf(m_currentEngine); + if (index == 0) { + m_searchMode = FindInThisPage; + } else { + --index; + m_currentEngine = m_searchEngines.at(index); + } + } + setIcon(); +} + +void SearchBar::startSearch(const QString &search) +{ + if ( m_urlEnterLock || search.isEmpty() ) + return; + if (m_searchMode == UseSearchProvider) { + m_urlEnterLock = true; + KService::Ptr service; + KUriFilterData data; + QStringList list; + list << "kurisearchfilter" << "kuriikwsfilter"; + + service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(m_currentEngine)); + if (service) { + const QString searchProviderPrefix = service->property("Keys").toStringList().first() + delimiter(); + data.setData(searchProviderPrefix + search); + } + + if (!service || !KUriFilter::self()->filterUri(data, list)) { + data.setData(QLatin1String("google") + delimiter() + search); + KUriFilter::self()->filterUri(data, list); + } + + if (QApplication::keyboardModifiers() & Qt::ControlModifier) { + KParts::OpenUrlArguments arguments; + KParts::BrowserArguments browserArguments; + browserArguments.setNewTab(true); + if (ext) + emit ext->createNewWindow(data.uri(), arguments, browserArguments); + } else { + if (ext) { + emit ext->openUrlRequest(data.uri()); + m_part->widget()->setFocus(); // #152923 + } + } + } + + m_searchCombo->addToHistory(search); + m_searchCombo->setItemIcon(0, m_searchIcon); + + m_urlEnterLock = false; +} + +void SearchBarPlugin::setIcon() +{ + if (m_searchMode == FindInThisPage) { + m_searchIcon = SmallIcon("edit-find"); + } else { + KService::Ptr service; + KUriFilterData data; + QStringList list; + list << "kurisearchfilter" << "kuriikwsfilter"; + + service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(m_currentEngine)); + if (service) { + const QString searchProviderPrefix = service->property("Keys").toStringList().first() + delimiter(); + data.setData(searchProviderPrefix + "some keyword"); + } + + if (service && KUriFilter::self()->filterUri(data, list)) + { + QString iconPath = KStandardDirs::locate("cache", KMimeType::favIconForUrl(data.uri()) + ".png"); + if (iconPath.isEmpty()) { + m_searchIcon = SmallIcon("unknown"); + } else { + m_searchIcon = QPixmap(iconPath); + } + } + else + { + m_searchIcon = SmallIcon("google"); + } + } + + // Create a bit wider icon with arrow + QPixmap arrowmap = QPixmap(m_searchIcon.width()+5,m_searchIcon.height()+5); + arrowmap.fill(m_searchCombo->lineEdit()->palette().color(m_searchCombo->lineEdit()->backgroundRole())); + QPainter p(&arrowmap); + p.drawPixmap(0, 2, m_searchIcon); + QStyleOption opt; + opt.state = QStyle::State_None; + opt.rect = QRect(arrowmap.width()-6, arrowmap.height()-5, 6, 5); + m_searchCombo->style()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &opt, &p, m_searchCombo); + p.end(); + m_searchIcon = arrowmap; + + m_searchCombo->setIcon(m_searchIcon); +} + +void SearchBar::showSelectionMenu() +{ + if (!m_popupMenu) { + KUriFilterData data; + QStringList list; + list << "kurisearchfilter" << "kuriikwsfilter"; + + m_popupMenu = new QMenu(m_searchCombo); + m_popupMenu->setObjectName("search selection menu"); + m_popupMenu->addAction(KIcon("edit-find"), i18n("Find in This Page"), this, SLOT(useFindInThisPage())); + m_popupMenu->addSeparator(); + + int i=-1; + for (QStringList::ConstIterator it = m_searchEngines.begin(); it != m_searchEngines.end(); ++it) { + i++; + KService::Ptr service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(*it)); + if (!service) { + continue; + } + const QString searchProviderPrefix = service->property("Keys").toStringList().first() + delimiter(); + data.setData(searchProviderPrefix + "some keyword"); + + if (KUriFilter::self()->filterUri(data, list)) + { + QIcon icon; + QString iconPath = KStandardDirs::locate("cache", KMimeType::favIconForUrl(data.uri()) + ".png"); + if (iconPath.isEmpty()) { + icon = KIcon("unknown"); + } else { + icon = QPixmap(iconPath); + } + QAction* action = m_popupMenu->addAction(icon, service->name()); + action->setData(qVariantFromValue(i)); + } + } + + m_popupMenu->addSeparator(); + m_popupMenu->addAction(KIcon("preferences-web-browser-shortcuts"), i18n("Select Search Engines..."), + this, SLOT(selectSearchEngines())); + connect(m_popupMenu, SIGNAL(triggered(QAction *)), SLOT(useSearchProvider(QAction *))); + } + m_popupMenu->popup(m_searchCombo->mapToGlobal(QPoint(0, m_searchCombo->height() + 1))); +} + +void SearchBar::useFindInThisPage() +{ + m_searchMode = FindInThisPage; + setIcon(); +} + +void SearchBar::useSearchProvider(QAction *action) +{ + bool ok = false; + const int id = action->data().toInt(&ok); + if(!ok) { + // Not a search engine entry selected + return; + } + m_searchMode = UseSearchProvider; + m_currentEngine = m_searchEngines.at(id); + setIcon(); + m_searchCombo->lineEdit()->selectAll(); +} + +void SearchBar::selectSearchEngines() +{ + m_process = new KProcess; + + *m_process << "kcmshell4" << "ebrowsing"; + + connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(searchEnginesSelected(int,QProcess::ExitStatus))); + + m_process->start(); + if(!m_process->waitForStarted()) + { + kDebug(1202) << "Couldn't invoke kcmshell"; + delete m_process; + m_process = 0; + } +} + +void SearchBar::searchEnginesSelected(int exitCode, QProcess::ExitStatus exitStatus) +{ + Q_UNUSED(exitCode); + if(exitStatus == QProcess::NormalExit) { + KConfigGroup config(KGlobal::config(), "SearchBar"); + config.writeEntry("CurrentEngine", m_currentEngine); + config.sync(); + configurationChanged(); + } + delete m_process; + m_process = 0; +} + +void SearchBar::configurationChanged() +{ + KConfigGroup config(KSharedConfig::openConfig("kuriikwsfilterrc"), "General"); + const QString engine = config.readEntry("DefaultSearchEngine", "google"); + + QStringList favoriteEngines; + favoriteEngines << "google" << "google_groups" << "google_news" << "webster" << "dmoz" << "wikipedia"; + favoriteEngines = config.readEntry("FavoriteSearchEngines", favoriteEngines); + + delete m_popupMenu; + m_popupMenu = 0; + m_searchEngines.clear(); + m_searchEngines << engine; + for (QStringList::ConstIterator it = favoriteEngines.begin(); it != favoriteEngines.end(); ++it) + if(*it!=engine) + m_searchEngines << *it; + + if(engine.isEmpty()) { + m_providerName = "Google"; + } else { + KDesktopFile file("services", "searchproviders/" + engine + ".desktop"); + m_providerName = file.readName(); + } + + config = KConfigGroup(KGlobal::config(), "SearchBar"); + m_searchMode = (SearchModes) config.readEntry("Mode", (int) UseSearchProvider); + m_currentEngine = config.readEntry("CurrentEngine", engine); + + if (m_currentEngine.isEmpty()) + m_currentEngine = "google"; + + setIcon(); +} + + + +void SearchBar::updateComboVisibility() +{ + if (!m_part|| m_searchComboAction->associatedWidgets().isEmpty()) + { + m_searchCombo->setPluginActive(false); + m_searchCombo->hide(); + } else { + m_searchCombo->setPluginActive(true); + m_searchCombo->show(); + } +} + + + +void SearchBar::focusSearchbar() +{ + m_searchCombo->setFocus(Qt::ShortcutFocusReason); +} + + + +SearchBarCombo::SearchBarCombo(QWidget *parent) : + KHistoryComboBox(parent), + m_pluginActive(true) +{ + setDuplicatesEnabled(false); + setFixedWidth(180); + connect(this, SIGNAL(cleared()), SLOT(historyCleared())); + + Q_ASSERT(useCompletion()); + + KConfigGroup config(KGlobal::config(), "SearchBar"); + QStringList list = config.readEntry( "History list", QStringList() ); + list.prepend(QString()); // empty item + setHistoryItems(list, true); + Q_ASSERT(currentText().isEmpty()); // KHistoryComboBox calls clearEditText +} + +const QPixmap &SearchBarCombo::icon() const +{ + return m_icon; +} + +void SearchBarCombo::setIcon(const QPixmap &icon) +{ + m_icon = icon; + const QString editText = currentText(); + if (count() == 0) { + insertItem(0, m_icon, 0); + } else { + for(int i = 0; i < count(); i++) { + setItemIcon(i, m_icon); + } + } + setEditText(editText); +} + +int SearchBarCombo::findHistoryItem(const QString &searchText) +{ + for(int i = 0; i < count(); i++) { + if (itemText(i) == searchText) { + return i; + } + } + + return -1; +} + +void SearchBarCombo::mousePressEvent(QMouseEvent *e) +{ + QStyleOptionComplex opt; + int x0 = QStyle::visualRect(layoutDirection(), style()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxEditField, this), rect()).x(); + + if (e->x() > x0 + 2 && e->x() < lineEdit()->x()) { + emit iconClicked(); + + e->accept(); + } else { + KHistoryComboBox::mousePressEvent(e); + } +} + +void SearchBarCombo::historyCleared() +{ + setIcon(m_icon); +} + +void SearchBarCombo::setPluginActive(bool pluginActive) +{ + m_pluginActive = pluginActive; +} + +void SearchBarCombo::show() +{ + if (m_pluginActive) { + KHistoryComboBox::show(); + } +} + +SearchBarCombo::~SearchBarCombo() +{ + KConfigGroup config(KGlobal::config(), "SearchBar"); + config.writeEntry( "History list", historyItems() ); +} + +#include "searchbar.moc" -- cgit v1.2.1 From c6646ccdae1c9b25a44e93c0a31298ec89797934 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 13 Nov 2008 11:43:05 +0100 Subject: New 1st implementation of text search bar. It is currently not working. Anyway, good starting point.. --- src/searchbar.cpp | 474 ++++++++---------------------------------------------- 1 file changed, 69 insertions(+), 405 deletions(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index f1f6ef80..b0e91fa9 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -2,6 +2,7 @@  *  * This file is a part of the reKonq project  * + * Copyright 2008 Benjamin C. Meyer * Copyright (C) 2008 by Andrea Diamantini  * * @@ -18,460 +19,123 @@  * ============================================================ */ #include "searchbar.h" +#include "moc_searchbar.cpp" +#include +#include +#include +#include +#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include +#include +#include +#include #include -#include - - +#include +#include - -SearchBar::SearchBar() : - m_searchCombo(0), - m_searchMode(UseSearchProvider), - m_urlEnterLock(false), - m_process(0) +SearchBar::SearchBar(QWidget *parent) + : QWidget(parent) + , m_object(0) + , m_widget(0) + , m_lineEdit(0) { - m_searchCombo = new SearchBarCombo(0); - m_searchCombo->lineEdit()->installEventFilter(this); - connect(m_searchCombo, SIGNAL(activated(const QString &)), SLOT(startSearch(const QString &))); - connect(m_searchCombo, SIGNAL(iconClicked()), SLOT(showSelectionMenu())); - m_searchCombo->setWhatsThis(i18n("Search Bar

" - "Enter a search term. Click on the icon to change search mode or provider.

")); - - m_popupMenu = 0; - - m_searchComboAction = actionCollection()->addAction("toolbar_search_bar"); - m_searchComboAction->setText(i18n("Search Bar")); - m_searchComboAction->setDefaultWidget(m_searchCombo); - m_searchComboAction->setShortcutConfigurable(false); + initializeSearchWidget(); + // we start off hidden + setMaximumHeight(0); +// m_widget->setGeometry(0, -1 * m_widget->height(), m_widget->width(), m_widget->height()); + hide(); - KAction *a = actionCollection()->addAction("focus_search_bar"); - a->setText(i18n("Focus Searchbar")); - a->setShortcut(Qt::CTRL+Qt::Key_S); - connect(a, SIGNAL(triggered()), this, SLOT(focusSearchbar())); - - configurationChanged(); - - // parent is the KonqMainWindow and we want to listen to PartActivateEvent events. - parent->installEventFilter(this); + new QShortcut(QKeySequence(Qt::Key_Escape), this, SLOT(hide())); } - - SearchBar::~SearchBar() { - KConfigGroup config(KGlobal::config(), "SearchBar"); - config.writeEntry("Mode", (int) m_searchMode); - config.writeEntry("CurrentEngine", m_currentEngine); - - delete m_searchCombo; - m_searchCombo = 0L; - delete m_process; - m_process=0L; -} - -static QChar delimiter() -{ - static QChar s_delimiter = 0; - if (s_delimiter == 0) { - KConfig _config("kuriikwsfilterrc", KConfig::NoGlobals); - KConfigGroup config(&_config, "General"); - s_delimiter = config.readEntry("KeywordDelimiter", int(':')); - } - return s_delimiter; + delete m_object; + delete m_widget; + delete m_lineEdit; } - -void SearchBar::nextSearchEntry() +void SearchBar::initializeSearchWidget() { - if (m_searchMode == FindInThisPage) { - m_searchMode = UseSearchProvider; - if (!m_searchEngines.isEmpty()) { - m_currentEngine = m_searchEngines.first(); - } else { - m_currentEngine = "google"; - } - } else { - int index = m_searchEngines.indexOf(m_currentEngine); - ++index; - if (index >= m_searchEngines.count()) { - m_searchMode = FindInThisPage; - } else { - m_currentEngine = m_searchEngines.at(index); - } - } - setIcon(); -} + QHBoxLayout *layout = new QHBoxLayout(); -void SearchBar::previousSearchEntry() -{ - if (m_searchMode == FindInThisPage) { - m_searchMode = UseSearchProvider; - if (!m_searchEngines.isEmpty()) { - m_currentEngine = m_searchEngines.last(); - } else { - m_currentEngine = "google"; - } - } else { - int index = m_searchEngines.indexOf(m_currentEngine); - if (index == 0) { - m_searchMode = FindInThisPage; - } else { - --index; - m_currentEngine = m_searchEngines.at(index); - } - } - setIcon(); -} + KToolBar *bar1 = new KToolBar(this); + bar1->addAction( KStandardAction::close(this, SLOT( hide() ) , this ) ); + layout->addWidget( bar1 ); -void SearchBar::startSearch(const QString &search) -{ - if ( m_urlEnterLock || search.isEmpty() ) - return; - if (m_searchMode == UseSearchProvider) { - m_urlEnterLock = true; - KService::Ptr service; - KUriFilterData data; - QStringList list; - list << "kurisearchfilter" << "kuriikwsfilter"; + QLabel *label = new QLabel("Find: "); + layout->addWidget( label ); - service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(m_currentEngine)); - if (service) { - const QString searchProviderPrefix = service->property("Keys").toStringList().first() + delimiter(); - data.setData(searchProviderPrefix + search); - } + m_lineEdit = new KLineEdit(); + connect( m_lineEdit, SIGNAL( returnPressed() ), this, SLOT( slotFindNext() ) ); + connect( m_lineEdit, SIGNAL( textEdited(const QString &) ), this, SLOT( slotFindNext() ) ); + layout->addWidget( m_lineEdit ); - if (!service || !KUriFilter::self()->filterUri(data, list)) { - data.setData(QLatin1String("google") + delimiter() + search); - KUriFilter::self()->filterUri(data, list); - } + KToolBar *bar2 = new KToolBar(this); + bar2->addAction( KStandardAction::findNext(this, SLOT( slotFindNext() ) , this ) ); + bar2->addAction( KStandardAction::findPrev(this, SLOT( slotFindPrevious() ) , this ) ); + layout->addWidget( bar2 ); - if (QApplication::keyboardModifiers() & Qt::ControlModifier) { - KParts::OpenUrlArguments arguments; - KParts::BrowserArguments browserArguments; - browserArguments.setNewTab(true); - if (ext) - emit ext->createNewWindow(data.uri(), arguments, browserArguments); - } else { - if (ext) { - emit ext->openUrlRequest(data.uri()); - m_part->widget()->setFocus(); // #152923 - } - } - } + layout->addStretch(); - m_searchCombo->addToHistory(search); - m_searchCombo->setItemIcon(0, m_searchIcon); - - m_urlEnterLock = false; + setLayout(layout); } -void SearchBarPlugin::setIcon() -{ - if (m_searchMode == FindInThisPage) { - m_searchIcon = SmallIcon("edit-find"); - } else { - KService::Ptr service; - KUriFilterData data; - QStringList list; - list << "kurisearchfilter" << "kuriikwsfilter"; - - service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(m_currentEngine)); - if (service) { - const QString searchProviderPrefix = service->property("Keys").toStringList().first() + delimiter(); - data.setData(searchProviderPrefix + "some keyword"); - } - - if (service && KUriFilter::self()->filterUri(data, list)) - { - QString iconPath = KStandardDirs::locate("cache", KMimeType::favIconForUrl(data.uri()) + ".png"); - if (iconPath.isEmpty()) { - m_searchIcon = SmallIcon("unknown"); - } else { - m_searchIcon = QPixmap(iconPath); - } - } - else - { - m_searchIcon = SmallIcon("google"); - } - } - - // Create a bit wider icon with arrow - QPixmap arrowmap = QPixmap(m_searchIcon.width()+5,m_searchIcon.height()+5); - arrowmap.fill(m_searchCombo->lineEdit()->palette().color(m_searchCombo->lineEdit()->backgroundRole())); - QPainter p(&arrowmap); - p.drawPixmap(0, 2, m_searchIcon); - QStyleOption opt; - opt.state = QStyle::State_None; - opt.rect = QRect(arrowmap.width()-6, arrowmap.height()-5, 6, 5); - m_searchCombo->style()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &opt, &p, m_searchCombo); - p.end(); - m_searchIcon = arrowmap; - m_searchCombo->setIcon(m_searchIcon); -} - -void SearchBar::showSelectionMenu() +void SearchBar::setSearchBar(QObject *object) { - if (!m_popupMenu) { - KUriFilterData data; - QStringList list; - list << "kurisearchfilter" << "kuriikwsfilter"; - - m_popupMenu = new QMenu(m_searchCombo); - m_popupMenu->setObjectName("search selection menu"); - m_popupMenu->addAction(KIcon("edit-find"), i18n("Find in This Page"), this, SLOT(useFindInThisPage())); - m_popupMenu->addSeparator(); - - int i=-1; - for (QStringList::ConstIterator it = m_searchEngines.begin(); it != m_searchEngines.end(); ++it) { - i++; - KService::Ptr service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(*it)); - if (!service) { - continue; - } - const QString searchProviderPrefix = service->property("Keys").toStringList().first() + delimiter(); - data.setData(searchProviderPrefix + "some keyword"); - - if (KUriFilter::self()->filterUri(data, list)) - { - QIcon icon; - QString iconPath = KStandardDirs::locate("cache", KMimeType::favIconForUrl(data.uri()) + ".png"); - if (iconPath.isEmpty()) { - icon = KIcon("unknown"); - } else { - icon = QPixmap(iconPath); - } - QAction* action = m_popupMenu->addAction(icon, service->name()); - action->setData(qVariantFromValue(i)); - } - } - - m_popupMenu->addSeparator(); - m_popupMenu->addAction(KIcon("preferences-web-browser-shortcuts"), i18n("Select Search Engines..."), - this, SLOT(selectSearchEngines())); - connect(m_popupMenu, SIGNAL(triggered(QAction *)), SLOT(useSearchProvider(QAction *))); - } - m_popupMenu->popup(m_searchCombo->mapToGlobal(QPoint(0, m_searchCombo->height() + 1))); + m_object = object; } -void SearchBar::useFindInThisPage() -{ - m_searchMode = FindInThisPage; - setIcon(); -} -void SearchBar::useSearchProvider(QAction *action) +QObject *SearchBar::getSearchBar() const { - bool ok = false; - const int id = action->data().toInt(&ok); - if(!ok) { - // Not a search engine entry selected - return; - } - m_searchMode = UseSearchProvider; - m_currentEngine = m_searchEngines.at(id); - setIcon(); - m_searchCombo->lineEdit()->selectAll(); + return m_object; } -void SearchBar::selectSearchEngines() -{ - m_process = new KProcess; - *m_process << "kcmshell4" << "ebrowsing"; - - connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(searchEnginesSelected(int,QProcess::ExitStatus))); - - m_process->start(); - if(!m_process->waitForStarted()) - { - kDebug(1202) << "Couldn't invoke kcmshell"; - delete m_process; - m_process = 0; - } -} - -void SearchBar::searchEnginesSelected(int exitCode, QProcess::ExitStatus exitStatus) -{ - Q_UNUSED(exitCode); - if(exitStatus == QProcess::NormalExit) { - KConfigGroup config(KGlobal::config(), "SearchBar"); - config.writeEntry("CurrentEngine", m_currentEngine); - config.sync(); - configurationChanged(); - } - delete m_process; - m_process = 0; -} - -void SearchBar::configurationChanged() +void SearchBar::clear() { - KConfigGroup config(KSharedConfig::openConfig("kuriikwsfilterrc"), "General"); - const QString engine = config.readEntry("DefaultSearchEngine", "google"); - - QStringList favoriteEngines; - favoriteEngines << "google" << "google_groups" << "google_news" << "webster" << "dmoz" << "wikipedia"; - favoriteEngines = config.readEntry("FavoriteSearchEngines", favoriteEngines); - - delete m_popupMenu; - m_popupMenu = 0; - m_searchEngines.clear(); - m_searchEngines << engine; - for (QStringList::ConstIterator it = favoriteEngines.begin(); it != favoriteEngines.end(); ++it) - if(*it!=engine) - m_searchEngines << *it; - - if(engine.isEmpty()) { - m_providerName = "Google"; - } else { - KDesktopFile file("services", "searchproviders/" + engine + ".desktop"); - m_providerName = file.readName(); - } - - config = KConfigGroup(KGlobal::config(), "SearchBar"); - m_searchMode = (SearchModes) config.readEntry("Mode", (int) UseSearchProvider); - m_currentEngine = config.readEntry("CurrentEngine", engine); - - if (m_currentEngine.isEmpty()) - m_currentEngine = "google"; - - setIcon(); + m_lineEdit->setText(QString()); } - -void SearchBar::updateComboVisibility() +void SearchBar::showFind() { - if (!m_part|| m_searchComboAction->associatedWidgets().isEmpty()) + if (!isVisible()) { - m_searchCombo->setPluginActive(false); - m_searchCombo->hide(); - } else { - m_searchCombo->setPluginActive(true); - m_searchCombo->show(); + show(); } + m_lineEdit->setFocus(); + m_lineEdit->selectAll(); } - -void SearchBar::focusSearchbar() -{ - m_searchCombo->setFocus(Qt::ShortcutFocusReason); -} - - - -SearchBarCombo::SearchBarCombo(QWidget *parent) : - KHistoryComboBox(parent), - m_pluginActive(true) -{ - setDuplicatesEnabled(false); - setFixedWidth(180); - connect(this, SIGNAL(cleared()), SLOT(historyCleared())); - - Q_ASSERT(useCompletion()); - - KConfigGroup config(KGlobal::config(), "SearchBar"); - QStringList list = config.readEntry( "History list", QStringList() ); - list.prepend(QString()); // empty item - setHistoryItems(list, true); - Q_ASSERT(currentText().isEmpty()); // KHistoryComboBox calls clearEditText -} - -const QPixmap &SearchBarCombo::icon() const -{ - return m_icon; -} - -void SearchBarCombo::setIcon(const QPixmap &icon) +void SearchBar::resizeEvent(QResizeEvent *event) { - m_icon = icon; - const QString editText = currentText(); - if (count() == 0) { - insertItem(0, m_icon, 0); - } else { - for(int i = 0; i < count(); i++) { - setItemIcon(i, m_icon); - } - } - setEditText(editText); +/* if (event->size().width() != m_widget->width()) + m_widget->resize(event->size().width(), m_widget->height()); + QWidget::resizeEvent(event);*/ } -int SearchBarCombo::findHistoryItem(const QString &searchText) -{ - for(int i = 0; i < count(); i++) { - if (itemText(i) == searchText) { - return i; - } - } - - return -1; -} -void SearchBarCombo::mousePressEvent(QMouseEvent *e) +void SearchBar::frameChanged(int frame) { - QStyleOptionComplex opt; - int x0 = QStyle::visualRect(layoutDirection(), style()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxEditField, this), rect()).x(); - - if (e->x() > x0 + 2 && e->x() < lineEdit()->x()) { - emit iconClicked(); - - e->accept(); - } else { - KHistoryComboBox::mousePressEvent(e); - } + if (!m_widget) + return; + m_widget->move(0, frame); + int height = qMax(0, m_widget->y() + m_widget->height()); + setMinimumHeight(height); + setMaximumHeight(height); } -void SearchBarCombo::historyCleared() -{ - setIcon(m_icon); -} -void SearchBarCombo::setPluginActive(bool pluginActive) -{ - m_pluginActive = pluginActive; -} +void SearchBar::slotFindNext() +{} -void SearchBarCombo::show() -{ - if (m_pluginActive) { - KHistoryComboBox::show(); - } -} - -SearchBarCombo::~SearchBarCombo() -{ - KConfigGroup config(KGlobal::config(), "SearchBar"); - config.writeEntry( "History list", historyItems() ); -} +void SearchBar::slotFindPrevious() +{} -#include "searchbar.moc" -- cgit v1.2.1 From 5944fa01d76b7624bb88672c48dd4c597e3c4f02 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 14 Nov 2008 12:12:35 +0100 Subject: searchbar --> findbar Yes, I know it's a search bar and finding is not granted. But I need to distingue between this and the "other" searchbar.. --- src/searchbar.cpp | 141 ------------------------------------------------------ 1 file changed, 141 deletions(-) delete mode 100644 src/searchbar.cpp (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp deleted file mode 100644 index b0e91fa9..00000000 --- a/src/searchbar.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* ============================================================ - * - * This file is a part of the reKonq project - * - * Copyright 2008 Benjamin C. Meyer - * Copyright (C) 2008 by Andrea Diamantini - * - * - * 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 2, 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. - * - * ============================================================ */ - -#include "searchbar.h" -#include "moc_searchbar.cpp" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -SearchBar::SearchBar(QWidget *parent) - : QWidget(parent) - , m_object(0) - , m_widget(0) - , m_lineEdit(0) -{ - initializeSearchWidget(); - - // we start off hidden - setMaximumHeight(0); -// m_widget->setGeometry(0, -1 * m_widget->height(), m_widget->width(), m_widget->height()); - hide(); - - new QShortcut(QKeySequence(Qt::Key_Escape), this, SLOT(hide())); -} - -SearchBar::~SearchBar() -{ - delete m_object; - delete m_widget; - delete m_lineEdit; -} - - -void SearchBar::initializeSearchWidget() -{ - QHBoxLayout *layout = new QHBoxLayout(); - - KToolBar *bar1 = new KToolBar(this); - bar1->addAction( KStandardAction::close(this, SLOT( hide() ) , this ) ); - layout->addWidget( bar1 ); - - QLabel *label = new QLabel("Find: "); - layout->addWidget( label ); - - m_lineEdit = new KLineEdit(); - connect( m_lineEdit, SIGNAL( returnPressed() ), this, SLOT( slotFindNext() ) ); - connect( m_lineEdit, SIGNAL( textEdited(const QString &) ), this, SLOT( slotFindNext() ) ); - layout->addWidget( m_lineEdit ); - - KToolBar *bar2 = new KToolBar(this); - bar2->addAction( KStandardAction::findNext(this, SLOT( slotFindNext() ) , this ) ); - bar2->addAction( KStandardAction::findPrev(this, SLOT( slotFindPrevious() ) , this ) ); - layout->addWidget( bar2 ); - - layout->addStretch(); - - setLayout(layout); -} - - -void SearchBar::setSearchBar(QObject *object) -{ - m_object = object; -} - - -QObject *SearchBar::getSearchBar() const -{ - return m_object; -} - - -void SearchBar::clear() -{ - m_lineEdit->setText(QString()); -} - - -void SearchBar::showFind() -{ - if (!isVisible()) - { - show(); - } - m_lineEdit->setFocus(); - m_lineEdit->selectAll(); -} - - -void SearchBar::resizeEvent(QResizeEvent *event) -{ -/* if (event->size().width() != m_widget->width()) - m_widget->resize(event->size().width(), m_widget->height()); - QWidget::resizeEvent(event);*/ -} - - -void SearchBar::frameChanged(int frame) -{ - if (!m_widget) - return; - m_widget->move(0, frame); - int height = qMax(0, m_widget->y() + m_widget->height()); - setMinimumHeight(height); - setMaximumHeight(height); -} - - -void SearchBar::slotFindNext() -{} - -void SearchBar::slotFindPrevious() -{} - -- cgit v1.2.1 From 47a69e593d2d816374d263076b87a9ffb987459a Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 17 Nov 2008 00:42:18 +0100 Subject: Ported search bar. 1st implementation. For Now, just Google Search. --- src/searchbar.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/searchbar.cpp (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp new file mode 100644 index 00000000..deb8d631 --- /dev/null +++ b/src/searchbar.cpp @@ -0,0 +1,62 @@ +/* ============================================================ + * + * This file is a part of the reKonq project + * + * Copyright (C) 2008 by Andrea Diamantini + * + * + * 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 2, 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. + * + * ============================================================ */ + +// Local Includes +#include "searchbar.h" +#include "searchbar.moc" + +// Qt Includes +#include + +SearchBar::SearchBar(QWidget *parent) : + QWidget(parent), + m_lineEdit(0) +{ + m_lineEdit = new KLineEdit(this); + m_lineEdit->setClearButtonShown( true ); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(m_lineEdit); + setLayout(layout); + + connect( lineEdit() , SIGNAL( returnPressed() ) , this , SLOT( searchNow() ) ); +} + +SearchBar::~SearchBar() +{ +} + +void SearchBar::searchNow() +{ + QString searchText = m_lineEdit->text(); + + QUrl url(QLatin1String("http://www.google.com/search")); + url.addQueryItem(QLatin1String("q"), searchText); + url.addQueryItem(QLatin1String("ie"), QLatin1String("UTF-8")); + url.addQueryItem(QLatin1String("oe"), QLatin1String("UTF-8")); + url.addQueryItem(QLatin1String("client"), QLatin1String("reKonq")); + emit search(url); + +} + +KLineEdit *SearchBar::lineEdit() +{ + return m_lineEdit; +} + -- cgit v1.2.1 From b9f8ccd9099fa48406203ad5c5389266b3318d88 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 5 Dec 2008 00:27:23 +0100 Subject: QUrl --> KUrl! --- src/searchbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index deb8d631..a2f1217f 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -46,7 +46,7 @@ void SearchBar::searchNow() { QString searchText = m_lineEdit->text(); - QUrl url(QLatin1String("http://www.google.com/search")); + KUrl url(QLatin1String("http://www.google.com/search")); url.addQueryItem(QLatin1String("q"), searchText); url.addQueryItem(QLatin1String("ie"), QLatin1String("UTF-8")); url.addQueryItem(QLatin1String("oe"), QLatin1String("UTF-8")); -- cgit v1.2.1 From c0e5507895a938b19881e1747b26b9914868d61f Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 9 Dec 2008 02:29:11 +0100 Subject: Added gray "Search.." on searchbar --- src/searchbar.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index a2f1217f..61bb61a5 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -23,6 +23,7 @@ // Qt Includes #include +#include SearchBar::SearchBar(QWidget *parent) : QWidget(parent), @@ -31,6 +32,11 @@ SearchBar::SearchBar(QWidget *parent) : m_lineEdit = new KLineEdit(this); m_lineEdit->setClearButtonShown( true ); + QPalette palette; + palette.setColor( QPalette::Text, Qt::gray ); + m_lineEdit->setPalette( palette ); + m_lineEdit->setText( "Search.." ); + QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(m_lineEdit); setLayout(layout); @@ -50,7 +56,7 @@ void SearchBar::searchNow() url.addQueryItem(QLatin1String("q"), searchText); url.addQueryItem(QLatin1String("ie"), QLatin1String("UTF-8")); url.addQueryItem(QLatin1String("oe"), QLatin1String("UTF-8")); - url.addQueryItem(QLatin1String("client"), QLatin1String("reKonq")); + url.addQueryItem(QLatin1String("client"), QLatin1String("rekonq")); emit search(url); } -- cgit v1.2.1 From 2565f1a0b3fa0e345159ae0c85a701467269e1ea Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 10 Dec 2008 00:19:56 +0100 Subject: nothing important --- src/searchbar.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 61bb61a5..a48803b3 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -44,10 +44,12 @@ SearchBar::SearchBar(QWidget *parent) : connect( lineEdit() , SIGNAL( returnPressed() ) , this , SLOT( searchNow() ) ); } + SearchBar::~SearchBar() { } + void SearchBar::searchNow() { QString searchText = m_lineEdit->text(); @@ -58,9 +60,9 @@ void SearchBar::searchNow() url.addQueryItem(QLatin1String("oe"), QLatin1String("UTF-8")); url.addQueryItem(QLatin1String("client"), QLatin1String("rekonq")); emit search(url); - } + KLineEdit *SearchBar::lineEdit() { return m_lineEdit; -- cgit v1.2.1 From 70809c857d125cce1d100e88d7d8ed898669a9ee Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 12 Dec 2008 16:10:04 +0100 Subject: Fixing searchbar dimension && position --- src/searchbar.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index a48803b3..785fcce5 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -21,9 +21,9 @@ #include "searchbar.h" #include "searchbar.moc" -// Qt Includes -#include -#include +#include "browserapplication.h" +#include "browsermainwindow.h" + SearchBar::SearchBar(QWidget *parent) : QWidget(parent), @@ -50,6 +50,24 @@ SearchBar::~SearchBar() } +void SearchBar::resizeEvent( QResizeEvent * event ) +{ + QRect rect = m_lineEdit->contentsRect(); + + int width = rect.width(); + + int lineEditWidth = BrowserApplication::instance()->mainWindow()->size().width() / 5 ; // FIXME ( OR not?) + + m_lineEdit->setGeometry( rect.x() + ( width - lineEditWidth + 8 ), + rect.y() + 4, + lineEditWidth, + m_lineEdit->height() + ); + + QWidget::resizeEvent( event ); +} + + void SearchBar::searchNow() { QString searchText = m_lineEdit->text(); -- cgit v1.2.1 From 19e901a0ca9630b2003dd24ccfa6da54eb70bb09 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 14 Dec 2008 18:27:17 +0100 Subject: adjusted rekonq name commented out (hopefully, for now) resizeEvents and focusInEvents in urlbar & searchbar --- src/searchbar.cpp | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 785fcce5..29862e6d 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -1,6 +1,6 @@ /* ============================================================  * - * This file is a part of the reKonq project + * This file is a part of the rekonq project  * * Copyright (C) 2008 by Andrea Diamantini  * @@ -27,11 +27,17 @@ SearchBar::SearchBar(QWidget *parent) : QWidget(parent), - m_lineEdit(0) + m_lineEdit(new KLineEdit) { - m_lineEdit = new KLineEdit(this); m_lineEdit->setClearButtonShown( true ); + m_lineEdit->setFocusProxy( this ); + setFocusPolicy( Qt::WheelFocus ); + setMouseTracking( true ); + + QSizePolicy policy = sizePolicy(); + setSizePolicy(QSizePolicy::Preferred, policy.verticalPolicy()); + QPalette palette; palette.setColor( QPalette::Text, Qt::gray ); m_lineEdit->setPalette( palette ); @@ -41,7 +47,7 @@ SearchBar::SearchBar(QWidget *parent) : layout->addWidget(m_lineEdit); setLayout(layout); - connect( lineEdit() , SIGNAL( returnPressed() ) , this , SLOT( searchNow() ) ); + connect( m_lineEdit , SIGNAL( returnPressed() ) , this , SLOT( searchNow() ) ); } @@ -50,22 +56,22 @@ SearchBar::~SearchBar() } -void SearchBar::resizeEvent( QResizeEvent * event ) -{ - QRect rect = m_lineEdit->contentsRect(); - - int width = rect.width(); - - int lineEditWidth = BrowserApplication::instance()->mainWindow()->size().width() / 5 ; // FIXME ( OR not?) - - m_lineEdit->setGeometry( rect.x() + ( width - lineEditWidth + 8 ), - rect.y() + 4, - lineEditWidth, - m_lineEdit->height() - ); - - QWidget::resizeEvent( event ); -} +// void SearchBar::resizeEvent( QResizeEvent * event ) +// { +// QRect rect = m_lineEdit->contentsRect(); +// +// int width = rect.width(); +// +// int lineEditWidth = BrowserApplication::instance()->mainWindow()->size().width() / 5 ; // FIXME ( OR not?) +// +// m_lineEdit->setGeometry( rect.x() + ( width - lineEditWidth + 8 ), +// rect.y() + 4, +// lineEditWidth, +// m_lineEdit->height() +// ); +// +// QWidget::resizeEvent( event ); +// } void SearchBar::searchNow() -- cgit v1.2.1 From af9623896acb241a965a7d0823e12fd099031a39 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 16 Dec 2008 01:09:39 +0100 Subject: Initial solution for UI resizing.. Now we can release rekonq 0.0.2 and thinking later about the problem.. --- src/searchbar.cpp | 51 +++++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 29862e6d..0cf8e801 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -26,28 +26,24 @@ SearchBar::SearchBar(QWidget *parent) : - QWidget(parent), - m_lineEdit(new KLineEdit) + KLineEdit(parent) { - m_lineEdit->setClearButtonShown( true ); - - m_lineEdit->setFocusProxy( this ); + setMinimumWidth(180); setFocusPolicy( Qt::WheelFocus ); setMouseTracking( true ); + setAcceptDrops(true); QSizePolicy policy = sizePolicy(); setSizePolicy(QSizePolicy::Preferred, policy.verticalPolicy()); - QPalette palette; - palette.setColor( QPalette::Text, Qt::gray ); - m_lineEdit->setPalette( palette ); - m_lineEdit->setText( "Search.." ); + setClearButtonShown( true ); - QVBoxLayout *layout = new QVBoxLayout; - layout->addWidget(m_lineEdit); - setLayout(layout); + QPalette p; + p.setColor( QPalette::Text , Qt::lightGray ); + setPalette( p ); + setText( i18n("Search..") ); - connect( m_lineEdit , SIGNAL( returnPressed() ) , this , SLOT( searchNow() ) ); + connect( this, SIGNAL( returnPressed() ) , this , SLOT( searchNow() ) ); } @@ -56,27 +52,9 @@ SearchBar::~SearchBar() } -// void SearchBar::resizeEvent( QResizeEvent * event ) -// { -// QRect rect = m_lineEdit->contentsRect(); -// -// int width = rect.width(); -// -// int lineEditWidth = BrowserApplication::instance()->mainWindow()->size().width() / 5 ; // FIXME ( OR not?) -// -// m_lineEdit->setGeometry( rect.x() + ( width - lineEditWidth + 8 ), -// rect.y() + 4, -// lineEditWidth, -// m_lineEdit->height() -// ); -// -// QWidget::resizeEvent( event ); -// } - - void SearchBar::searchNow() { - QString searchText = m_lineEdit->text(); + QString searchText = text(); KUrl url(QLatin1String("http://www.google.com/search")); url.addQueryItem(QLatin1String("q"), searchText); @@ -87,8 +65,13 @@ void SearchBar::searchNow() } -KLineEdit *SearchBar::lineEdit() +void SearchBar::focusInEvent(QFocusEvent *event) { - return m_lineEdit; + KLineEdit::focusInEvent(event); + + QPalette p; + p.setColor( QPalette::Text , Qt::black ); + setPalette( p ); + clear(); } -- cgit v1.2.1 From 85088c590ef99f9487abf2768f8084653cd4ab16 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 21 Dec 2008 00:07:53 +0100 Subject: - Added kWarning for fixed minimun size - updated TODO - upgraded .desktop file --- src/searchbar.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 0cf8e801..8b21daf5 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -29,6 +29,8 @@ SearchBar::SearchBar(QWidget *parent) : KLineEdit(parent) { setMinimumWidth(180); + kWarning() << "setting fixed minimum width.." ; + setFocusPolicy( Qt::WheelFocus ); setMouseTracking( true ); setAcceptDrops(true); -- cgit v1.2.1 From 2daca1034d63d71e9c6a097816fe6aa7ba47db35 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 21 Dec 2008 00:54:58 +0100 Subject: little updates.. --- src/searchbar.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 8b21daf5..977703d3 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -24,6 +24,7 @@ #include "browserapplication.h" #include "browsermainwindow.h" +#include SearchBar::SearchBar(QWidget *parent) : KLineEdit(parent) -- cgit v1.2.1 From c7048563b95f8d27b20aac0a0e1fbc5c4584c514 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 27 Dec 2008 12:54:30 +0100 Subject: BrowserMainWindow --> MainWindow --- src/searchbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 977703d3..c6889dba 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -22,7 +22,7 @@ #include "searchbar.moc" #include "browserapplication.h" -#include "browsermainwindow.h" +#include "mainwindow.h" #include -- cgit v1.2.1 From 39ff47469cdc4a7df148368ed60470dc042f677e Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 15 Feb 2009 15:44:52 +0100 Subject: {Browser,}Application. Again.. --- src/searchbar.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index c6889dba..2f03e93a 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -17,13 +17,15 @@  *  * ============================================================ */ -// Local Includes +// Self Includes #include "searchbar.h" #include "searchbar.moc" -#include "browserapplication.h" +// Local Includes +#include "application.h" #include "mainwindow.h" +// KDE Includes #include SearchBar::SearchBar(QWidget *parent) : -- cgit v1.2.1 From b5044060c9263d223c99055b9bd6b93c9fb966c7 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 11 Mar 2009 00:55:47 +0100 Subject: Forwarding class declarations to speed up compilation.. --- src/searchbar.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 2f03e93a..1145d36e 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -26,8 +26,14 @@ #include "mainwindow.h" // KDE Includes +#include #include +// Qt Includes +#include +#include + + SearchBar::SearchBar(QWidget *parent) : KLineEdit(parent) { -- cgit v1.2.1 From 39409ac6a2880ad815d6096231d0fcdcfd2547f6 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 22 Mar 2009 10:21:09 +0100 Subject: Fixed Copyright intro --- src/searchbar.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 1145d36e..7d599bfb 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -1,21 +1,22 @@ /* ============================================================ - * - * This file is a part of the rekonq project - * - * Copyright (C) 2008 by Andrea Diamantini - * - * - * 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 2, 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. - * - * ============================================================ */ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2008 by Andrea Diamantini +* +* +* 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 2, 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. +* +* ============================================================ */ + // Self Includes #include "searchbar.h" -- cgit v1.2.1 From c77009fa70847fc12e1b0dbb9826513b22d27e12 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 24 Mar 2009 11:04:50 +0100 Subject: Added Google Suggest. Thanks, Ariyagit status --- src/searchbar.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 7d599bfb..80b231ac 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -33,6 +33,7 @@ // Qt Includes #include #include +#include SearchBar::SearchBar(QWidget *parent) : @@ -50,12 +51,20 @@ SearchBar::SearchBar(QWidget *parent) : setClearButtonShown( true ); - QPalette p; - p.setColor( QPalette::Text , Qt::lightGray ); - setPalette( p ); - setText( i18n("Search..") ); + // better solution than using QPalette(s).. + setClickMessage( i18n("Search..") ); + + // setting QNetworkAccessManager.. + netMan = new QNetworkAccessManager(this); + connect(netMan, SIGNAL(finished(QNetworkReply*)), this, SLOT(handleNetworkData(QNetworkReply*))); - connect( this, SIGNAL( returnPressed() ) , this , SLOT( searchNow() ) ); + timer = new QTimer(this); + timer->setSingleShot(true); + timer->setInterval(300); + connect(timer, SIGNAL(timeout()), SLOT(autoSuggest())); + connect(this, SIGNAL(textEdited(QString)), timer, SLOT(start())); + + connect(this, SIGNAL( returnPressed() ) , this , SLOT( searchNow() ) ); } @@ -66,6 +75,7 @@ SearchBar::~SearchBar() void SearchBar::searchNow() { + timer->stop(); QString searchText = text(); KUrl url(QLatin1String("http://www.google.com/search")); @@ -87,3 +97,37 @@ void SearchBar::focusInEvent(QFocusEvent *event) clear(); } + +void SearchBar::autoSuggest() +{ + QString str = text(); + QString url = QString("http://google.com/complete/search?output=toolbar&q=%1").arg(str); + netMan->get(QNetworkRequest(QString(url))); +} + + +void SearchBar::handleNetworkData(QNetworkReply *networkReply) +{ + QUrl url = networkReply->url(); + if (!networkReply->error()) + { + QStringList choices; + + QString response(networkReply->readAll()); + QXmlStreamReader xml(response); + while (!xml.atEnd()) + { + xml.readNext(); + if (xml.tokenType() == QXmlStreamReader::StartElement) + if (xml.name() == "suggestion") + { + QStringRef str = xml.attributes().value("data"); + choices << str.toString(); + } + } + + setCompletedItems(choices, true); + } + + networkReply->deleteLater(); +} \ No newline at end of file -- cgit v1.2.1 From a934072cf9695e46e793898102590322f43c0733 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 28 Mar 2009 15:53:26 +0100 Subject: astyle. First round.. --- src/searchbar.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 80b231ac..0d318edb 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -36,23 +36,23 @@ #include -SearchBar::SearchBar(QWidget *parent) : - KLineEdit(parent) +SearchBar::SearchBar(QWidget *parent) : + KLineEdit(parent) { setMinimumWidth(180); kWarning() << "setting fixed minimum width.." ; - setFocusPolicy( Qt::WheelFocus ); - setMouseTracking( true ); + setFocusPolicy(Qt::WheelFocus); + setMouseTracking(true); setAcceptDrops(true); QSizePolicy policy = sizePolicy(); setSizePolicy(QSizePolicy::Preferred, policy.verticalPolicy()); - setClearButtonShown( true ); + setClearButtonShown(true); // better solution than using QPalette(s).. - setClickMessage( i18n("Search..") ); + setClickMessage(i18n("Search..")); // setting QNetworkAccessManager.. netMan = new QNetworkAccessManager(this); @@ -64,7 +64,7 @@ SearchBar::SearchBar(QWidget *parent) : connect(timer, SIGNAL(timeout()), SLOT(autoSuggest())); connect(this, SIGNAL(textEdited(QString)), timer, SLOT(start())); - connect(this, SIGNAL( returnPressed() ) , this , SLOT( searchNow() ) ); + connect(this, SIGNAL(returnPressed()) , this , SLOT(searchNow())); } @@ -92,8 +92,8 @@ void SearchBar::focusInEvent(QFocusEvent *event) KLineEdit::focusInEvent(event); QPalette p; - p.setColor( QPalette::Text , Qt::black ); - setPalette( p ); + p.setColor(QPalette::Text , Qt::black); + setPalette(p); clear(); } @@ -109,7 +109,7 @@ void SearchBar::autoSuggest() void SearchBar::handleNetworkData(QNetworkReply *networkReply) { QUrl url = networkReply->url(); - if (!networkReply->error()) + if (!networkReply->error()) { QStringList choices; -- cgit v1.2.1 From 82374509e534a9bdcd70969a6f0f1881a8ab4174 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 6 Apr 2009 17:24:56 +0200 Subject: SearchBar: adopting coding style rules.. --- src/searchbar.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 0d318edb..d5b68e54 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -37,7 +37,9 @@ SearchBar::SearchBar(QWidget *parent) : - KLineEdit(parent) + KLineEdit(parent) + , m_networkAccessManager(new QNetworkAccessManager(this)) + , m_timer(new QTimer(this)) { setMinimumWidth(180); kWarning() << "setting fixed minimum width.." ; @@ -55,15 +57,15 @@ SearchBar::SearchBar(QWidget *parent) : setClickMessage(i18n("Search..")); // setting QNetworkAccessManager.. - netMan = new QNetworkAccessManager(this); - connect(netMan, SIGNAL(finished(QNetworkReply*)), this, SLOT(handleNetworkData(QNetworkReply*))); + connect(m_networkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(handleNetworkData(QNetworkReply*))); - timer = new QTimer(this); - timer->setSingleShot(true); - timer->setInterval(300); - connect(timer, SIGNAL(timeout()), SLOT(autoSuggest())); - connect(this, SIGNAL(textEdited(QString)), timer, SLOT(start())); + // setting QTimer.. + m_timer->setSingleShot(true); + m_timer->setInterval(300); + connect(m_timer, SIGNAL(timeout()), SLOT(autoSuggest())); + connect(this, SIGNAL(textEdited(QString)), m_timer, SLOT(start())); + // connect searchNow slot.. connect(this, SIGNAL(returnPressed()) , this , SLOT(searchNow())); } @@ -75,7 +77,7 @@ SearchBar::~SearchBar() void SearchBar::searchNow() { - timer->stop(); + m_timer->stop(); QString searchText = text(); KUrl url(QLatin1String("http://www.google.com/search")); @@ -91,9 +93,9 @@ void SearchBar::focusInEvent(QFocusEvent *event) { KLineEdit::focusInEvent(event); - QPalette p; - p.setColor(QPalette::Text , Qt::black); - setPalette(p); +// QPalette p; +// p.setColor(QPalette::Text , Qt::black); +// setPalette(p); clear(); } @@ -102,7 +104,7 @@ void SearchBar::autoSuggest() { QString str = text(); QString url = QString("http://google.com/complete/search?output=toolbar&q=%1").arg(str); - netMan->get(QNetworkRequest(QString(url))); + m_networkAccessManager->get(QNetworkRequest(QString(url))); } -- cgit v1.2.1 From 5a9d9ad3b251ab1ff3c62af465f37bdf5fd0bf6e Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 8 Apr 2009 10:51:29 +0200 Subject: Removed unuseful commented code --- src/searchbar.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index d5b68e54..6e391d5c 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -92,10 +92,6 @@ void SearchBar::searchNow() void SearchBar::focusInEvent(QFocusEvent *event) { KLineEdit::focusInEvent(event); - -// QPalette p; -// p.setColor(QPalette::Text , Qt::black); -// setPalette(p); clear(); } -- cgit v1.2.1 From db75cbfd9bbb52858d6434e96ac914424a66fe09 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 22 Apr 2009 01:24:48 +0200 Subject: Trivial fixes --- src/searchbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 6e391d5c..bf037b9a 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -128,4 +128,4 @@ void SearchBar::handleNetworkData(QNetworkReply *networkReply) } networkReply->deleteLater(); -} \ No newline at end of file +} -- cgit v1.2.1 From 7557af13f9f904cb9a6240d2101fb14e1ffdca99 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 22 Apr 2009 01:33:28 +0200 Subject: Fixing Copyrights --- src/searchbar.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index bf037b9a..3732d0c5 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -2,7 +2,8 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2008 by Andrea Diamantini +* Copyright (C) 2008-2009 by Andrea Diamantini +* Copyright (C) 2009 rekonq team. Please, see AUTHORS file for details * * * This program is free software; you can redistribute it -- cgit v1.2.1 From e657ef44ef1eef1f998101ab3dcce1a251d729fc Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 26 Apr 2009 01:45:38 +0200 Subject: Fixed copyright strings, per file, as decided --- src/searchbar.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 3732d0c5..b05476f0 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -3,7 +3,6 @@ * This file is a part of the rekonq project * * Copyright (C) 2008-2009 by Andrea Diamantini -* Copyright (C) 2009 rekonq team. Please, see AUTHORS file for details * * * This program is free software; you can redistribute it -- cgit v1.2.1 From f10f86a1e74aa2180786cf0ee727f41258b156ba Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 29 Apr 2009 00:37:22 +0200 Subject: Searchbar fixes: no KDebug && QTimer shot in 200 ms --- src/searchbar.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index b05476f0..c9fef5c7 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -28,7 +28,6 @@ // KDE Includes #include -#include // Qt Includes #include @@ -42,7 +41,6 @@ SearchBar::SearchBar(QWidget *parent) : , m_timer(new QTimer(this)) { setMinimumWidth(180); - kWarning() << "setting fixed minimum width.." ; setFocusPolicy(Qt::WheelFocus); setMouseTracking(true); @@ -61,7 +59,7 @@ SearchBar::SearchBar(QWidget *parent) : // setting QTimer.. m_timer->setSingleShot(true); - m_timer->setInterval(300); + m_timer->setInterval(200); connect(m_timer, SIGNAL(timeout()), SLOT(autoSuggest())); connect(this, SIGNAL(textEdited(QString)), m_timer, SLOT(start())); -- cgit v1.2.1 From 82862fbd150afae0101757d1d6081e0e6ddf7baa Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 29 Apr 2009 11:24:11 +0200 Subject: astyle --- src/searchbar.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index c9fef5c7..fad35748 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -36,9 +36,9 @@ SearchBar::SearchBar(QWidget *parent) : - KLineEdit(parent) - , m_networkAccessManager(new QNetworkAccessManager(this)) - , m_timer(new QTimer(this)) + KLineEdit(parent) + , m_networkAccessManager(new QNetworkAccessManager(this)) + , m_timer(new QTimer(this)) { setMinimumWidth(180); -- cgit v1.2.1 From 06b2dc0ce6ec6dd4cb090c22e2f9f8521138146b Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 6 May 2009 03:09:23 +0200 Subject: EBN Krazy fixes. 1st round.. --- src/searchbar.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/searchbar.cpp') diff --git a/src/searchbar.cpp b/src/searchbar.cpp index fad35748..685a8ec5 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -30,10 +30,12 @@ #include // Qt Includes -#include -#include -#include - +#include +#include +#include +#include +#include +#include SearchBar::SearchBar(QWidget *parent) : KLineEdit(parent) -- cgit v1.2.1