1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Don't reload search results when saving search engines.

This commit is contained in:
nowrep 2012-02-28 18:57:05 +01:00
parent 20722a1343
commit 9df1b8ca1e
4 changed files with 32 additions and 22 deletions

View File

@ -120,14 +120,16 @@ void WebSearchBar::setupEngines()
m_boxSearchType->addItem(item); m_boxSearchType->addItem(item);
if (item.text == activeEngine) { if (item.text == activeEngine) {
m_boxSearchType->setCurrentItem(item); m_boxSearchType->setCurrentItem(item, false);
} }
} }
searchChanged(m_boxSearchType->currentItem(), false);
connect(m_searchManager, SIGNAL(enginesChanged()), this, SLOT(setupEngines())); connect(m_searchManager, SIGNAL(enginesChanged()), this, SLOT(setupEngines()));
} }
void WebSearchBar::searchChanged(const ButtonWithMenu::Item &item) void WebSearchBar::searchChanged(const ButtonWithMenu::Item &item, bool reload)
{ {
setPlaceholderText(item.text); setPlaceholderText(item.text);
m_completerModel->setStringList(QStringList()); m_completerModel->setStringList(QStringList());
@ -139,7 +141,7 @@ void WebSearchBar::searchChanged(const ButtonWithMenu::Item &item)
m_searchManager->setActiveEngine(m_activeEngine); m_searchManager->setActiveEngine(m_activeEngine);
if (!text().isEmpty()) { if (reload && !text().isEmpty()) {
search(); search();
} }
} }
@ -261,7 +263,7 @@ void WebSearchBar::contextMenuEvent(QContextMenuEvent* event)
void WebSearchBar::focusOutEvent(QFocusEvent* e) void WebSearchBar::focusOutEvent(QFocusEvent* e)
{ {
if (text().isEmpty()) { if (text().isEmpty()) {
QString search = m_boxSearchType->currentItem()->text; QString search = m_boxSearchType->currentItem().text;
setPlaceholderText(search); setPlaceholderText(search);
} }
QLineEdit::focusOutEvent(e); QLineEdit::focusOutEvent(e);

View File

@ -47,7 +47,7 @@ public:
explicit WebSearchBar(QupZilla* mainClass, QWidget* parent = 0); explicit WebSearchBar(QupZilla* mainClass, QWidget* parent = 0);
private slots: private slots:
void searchChanged(const ButtonWithMenu::Item &item); void searchChanged(const ButtonWithMenu::Item &item, bool reload = true);
void setupEngines(); void setupEngines();
void search(); void search();

View File

@ -20,7 +20,6 @@
ButtonWithMenu::ButtonWithMenu(QWidget* parent) ButtonWithMenu::ButtonWithMenu(QWidget* parent)
: ToolButton(parent) : ToolButton(parent)
, m_menu(new QMenu(this)) , m_menu(new QMenu(this))
, m_currentItem(0)
{ {
setPopupMode(QToolButton::InstantPopup); setPopupMode(QToolButton::InstantPopup);
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
@ -41,15 +40,13 @@ void ButtonWithMenu::clearItems()
{ {
m_menu->clear(); m_menu->clear();
m_items.clear(); m_items.clear();
m_currentItem = 0;
} }
void ButtonWithMenu::addItem(const Item &item) void ButtonWithMenu::addItem(const Item &item)
{ {
m_items.append(item); m_items.append(item);
if (!m_currentItem) { if (m_items.count() == 1) {
setCurrentItem(item); setCurrentItem(item);
} }
@ -77,29 +74,31 @@ void ButtonWithMenu::removeItem(const Item &item)
return; return;
} }
if (*m_currentItem == item) { if (m_currentItem == item) {
setCurrentItem(m_items.first()); setCurrentItem(m_items.first());
} }
} }
void ButtonWithMenu::setCurrentItem(const Item &item) void ButtonWithMenu::setCurrentItem(const Item &item, bool emitSignal)
{ {
int index = m_items.indexOf(item); int index = m_items.indexOf(item);
if (index < 0) { if (index < 0 || m_currentItem == item) {
return; return;
} }
m_currentItem = const_cast<Item*>(&m_items.at(index)); m_currentItem = item;
setIcon(m_currentItem->icon); setIcon(m_currentItem.icon);
setToolTip(m_currentItem->text); setToolTip(m_currentItem.text);
emit activeItemChanged(*m_currentItem); if (emitSignal) {
emit activeItemChanged(m_currentItem);
}
} }
void ButtonWithMenu::wheelEvent(QWheelEvent* event) void ButtonWithMenu::wheelEvent(QWheelEvent* event)
{ {
int currItemIndex = m_items.indexOf(*m_currentItem); int currItemIndex = m_items.indexOf(m_currentItem);
int itemsCount = m_items.count(); int itemsCount = m_items.count();
if (itemsCount == 0) { if (itemsCount == 0) {
@ -120,7 +119,7 @@ void ButtonWithMenu::wheelEvent(QWheelEvent* event)
event->accept(); event->accept();
} }
ButtonWithMenu::Item* ButtonWithMenu::currentItem() ButtonWithMenu::Item ButtonWithMenu::currentItem()
{ {
return m_currentItem; return m_currentItem;
} }

View File

@ -42,6 +42,16 @@ public:
bool operator==(const Item &a) { bool operator==(const Item &a) {
return (a.text == text) && (a.icon.pixmap(16, 16).toImage() == icon.pixmap(16, 16).toImage()); return (a.text == text) && (a.icon.pixmap(16, 16).toImage() == icon.pixmap(16, 16).toImage());
} }
bool isEmpty() {
return (text.isEmpty() && icon.isNull());
}
void clear() {
text = QString();
icon = QIcon();
userData = QVariant();
}
}; };
explicit ButtonWithMenu(QWidget* parent = 0); explicit ButtonWithMenu(QWidget* parent = 0);
@ -50,9 +60,9 @@ public:
void addItem(const Item &item); void addItem(const Item &item);
void addItems(const QList<Item> &items); void addItems(const QList<Item> &items);
void removeItem(const Item &item); void removeItem(const Item &item);
void setCurrentItem(const Item &item); void setCurrentItem(const Item &item, bool emitSignal = true);
Item* currentItem(); Item currentItem();
QList<Item> allItems() { return m_items; } QList<Item> allItems() { return m_items; }
QMenu* menu() const; QMenu* menu() const;
@ -73,8 +83,7 @@ private:
QMenu* m_menu; QMenu* m_menu;
QList<Item> m_items; QList<Item> m_items;
Item* m_currentItem; Item m_currentItem;
}; };
Q_DECLARE_METATYPE(ButtonWithMenu::Item) Q_DECLARE_METATYPE(ButtonWithMenu::Item)