diff options
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/browsermainwindow.cpp | 23 | ||||
-rw-r--r-- | src/browsermainwindow.h | 8 | ||||
-rw-r--r-- | src/searchbar.cpp | 474 | ||||
-rw-r--r-- | src/searchbar.h | 79 |
5 files changed, 99 insertions, 487 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 50b13782..a30af320 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,7 +10,7 @@ SET( rekonq_SRCS modelmenu.cpp networkaccessmanager.cpp searchlineedit.cpp -# searchbar.cpp + searchbar.cpp findwidget.cpp settings.cpp squeezelabel.cpp diff --git a/src/browsermainwindow.cpp b/src/browsermainwindow.cpp index ef796ff7..81784a62 100644 --- a/src/browsermainwindow.cpp +++ b/src/browsermainwindow.cpp @@ -82,10 +82,9 @@ BrowserMainWindow::BrowserMainWindow(QWidget *parent, Qt::WindowFlags flags) addToolBarBreak(); layout->addWidget(m_tabWidget); - // Find Widget -/* m_findWidg = new FindWidget(centralWidget); - layout->addWidget(m_findWidg);*/ -// m_findWidg->setVisible(false); + // Search Bar + m_searchBar = new SearchBar(centralWidget); + layout->addWidget(m_searchBar); centralWidget->setLayout(layout); setCentralWidget(centralWidget); @@ -269,7 +268,7 @@ void BrowserMainWindow::setupMenu() editMenu->addSeparator(); - editMenu->addAction( KStandardAction::find(this, SLOT( slotViewtFindWidget() ) , this ) ); + editMenu->addAction( KStandardAction::find(this, SLOT( slotViewSearchBar() ) , this ) ); editMenu->addAction( KStandardAction::findNext(this, SLOT( slotEditFindNext() ) , this ) ); editMenu->addAction( KStandardAction::findPrev(this, SLOT( slotEditFindPrevious() ) , this ) ); @@ -649,15 +648,6 @@ void BrowserMainWindow::closeEvent(QCloseEvent *event) } -void BrowserMainWindow::slotViewFindWidget() -{ - if ( m_findWidg->isVisible() ) - m_findWidg->setVisible( false ); - else - m_findWidg->setVisible( true ); -} - - // FIXME: reimplement me A-LA KATE search bar void BrowserMainWindow::slotEditFind() { @@ -679,7 +669,10 @@ bool ok; m_lastSearch = findWidg->*/ } - +void BrowserMainWindow::slotViewSearchBar() +{ + m_searchBar->show(); +} void BrowserMainWindow::slotEditFindNext() { diff --git a/src/browsermainwindow.h b/src/browsermainwindow.h index 66d77043..faf98e93 100644 --- a/src/browsermainwindow.h +++ b/src/browsermainwindow.h @@ -23,7 +23,7 @@ #define BROWSERMAINWINDOW_H // Local Includes -#include "findwidget.h" +#include "searchbar.h" // KDE Includes #include <KMainWindow> @@ -89,7 +89,6 @@ private slots: void slotEditFind(); void slotEditFindNext(); void slotEditFindPrevious(); -// void slotShowBookmarksDialog(); void slotAddBookmark(); void slotViewTextBigger(); void slotViewTextNormal(); @@ -97,6 +96,7 @@ private slots: void slotViewStatusbar(); void slotViewPageSource(); void slotViewFullScreen(bool enable); + void slotViewSearchBar(); void slotWebSearch(); void slotToggleInspector(bool enable); @@ -104,12 +104,10 @@ private slots: void slotSelectLineEdit(); void slotAboutToShowBackMenu(); -// void slotAboutToShowForwardMenu(); void slotAboutToShowWindowMenu(); void slotOpenActionUrl(QAction *action); void slotShowWindow(); void slotSwapFocus(); - void slotViewFindWidget(); void printRequested(QWebFrame *frame); void geometryChangeRequested(const QRect &geometry); @@ -144,7 +142,7 @@ private: KIcon m_reloadIcon; KIcon m_stopIcon; - FindWidget *m_findWidg; + SearchBar *m_searchBar; QString m_lastSearch; KBookmarkMenu* m_bookmarkMenu; 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 <ben@meyerhome.net> * Copyright (C) 2008 by Andrea Diamantini <adjam7 at gmail dot com> * * @@ -18,460 +19,123 @@ * ============================================================ */ #include "searchbar.h" +#include "moc_searchbar.cpp" +#include <KLineEdit> +#include <KAction> +#include <KIconLoader> +#include <KToolBar> +#include <KStandardAction> -#include <unistd.h> -#include <QLineEdit> -#include <QApplication> -#include <kaction.h> -#include <kconfig.h> -#include <ksharedconfig.h> -#include <kdebug.h> -#include <kdesktopfile.h> -#include <kgenericfactory.h> -#include <kglobal.h> -#include <khtml_part.h> -#include <kiconloader.h> -#include <klocale.h> -#include <kmimetype.h> -#include <kprotocolmanager.h> -#include <kstandarddirs.h> -#include <kurifilter.h> -#include <kservice.h> -#include <kactioncollection.h> - -#include <qpainter.h> -#include <qmenu.h> -#include <qtimer.h> -#include <qstyle.h> +#include <QHBoxLayout> +#include <QLabel> +#include <QEvent> #include <QPixmap> -#include <QMouseEvent> - - +#include <QShortcut> +#include <QResizeEvent> - -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<p>" - "Enter a search term. Click on the icon to change search mode or provider.</p>")); - - 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" diff --git a/src/searchbar.h b/src/searchbar.h index e574508b..287363c3 100644 --- a/src/searchbar.h +++ b/src/searchbar.h @@ -2,6 +2,7 @@ * * This file is a part of the reKonq project * + * Copyright 2008 Benjamin C. Meyer <ben@meyerhome.net> * Copyright (C) 2008 by Andrea Diamantini <adjam7 at gmail dot com> * * @@ -20,82 +21,38 @@ #ifndef SEARCHBAR_H #define SEARCHBAR_H -#include <KHistoryComboBox> -#include <KProcess> -#include <KAction> -#include <KDialog> +#include <KLineEdit> -#include <QPixmap> -#include <QString> -#include <QMenu> +#include <QWidget> -class SearchBarCombo : public KHistoryComboBox +class SearchBar : public QWidget { Q_OBJECT public: - SearchBarCombo(QWidget *parent); - ~SearchBarCombo(); - const QPixmap &icon() const; - void setIcon(const QPixmap &icon); - int findHistoryItem(const QString &text); + SearchBar(QWidget *parent = 0); + ~SearchBar(); + void setSearchBar(QObject *); + QObject *getSearchBar() const; public slots: - virtual void show(); - -signals: - void iconClicked(); + void clear(); + void showFind(); + void slotFindNext(); + void slotFindPrevious(); protected: - virtual void mousePressEvent(QMouseEvent *e); - -private slots: - void historyCleared(); - -private: - QPixmap m_icon; -}; - - -class SearchBar : public KDialog -{ - Q_OBJECT - -public: - enum SearchModes { FindInThisPage = 0, UseSearchProvider }; - - SearchBar(); - virtual ~SearchBar(); + void resizeEvent(QResizeEvent *event); private slots: - void startSearch(const QString &search); - void setIcon(); - void showSelectionMenu(); - - void useFindInThisPage(); - void useSearchProvider(QAction *); - void selectSearchEngines(); - void searchEnginesSelected(int, QProcess::ExitStatus); - void configurationChanged(); + void frameChanged(int frame); - void updateComboVisibility(); - - void focusSearchbar(); private: - void nextSearchEntry(); - void previousSearchEntry(); - + void initializeSearchWidget(); + QObject *m_object; + QWidget *m_widget; - SearchBarCombo *m_searchCombo; - KAction *m_searchComboAction; - QMenu *m_popupMenu; - QPixmap m_searchIcon; - SearchModes m_searchMode; - QString m_providerName; - bool m_urlEnterLock; - QString m_currentEngine; - QStringList m_searchEngines; - KProcess *m_process; + KLineEdit *m_lineEdit; }; #endif |