mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
Don't reload search results when saving search engines.
This commit is contained in:
parent
20722a1343
commit
9df1b8ca1e
@ -120,14 +120,16 @@ void WebSearchBar::setupEngines()
|
||||
m_boxSearchType->addItem(item);
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
void WebSearchBar::searchChanged(const ButtonWithMenu::Item &item)
|
||||
void WebSearchBar::searchChanged(const ButtonWithMenu::Item &item, bool reload)
|
||||
{
|
||||
setPlaceholderText(item.text);
|
||||
m_completerModel->setStringList(QStringList());
|
||||
@ -139,7 +141,7 @@ void WebSearchBar::searchChanged(const ButtonWithMenu::Item &item)
|
||||
|
||||
m_searchManager->setActiveEngine(m_activeEngine);
|
||||
|
||||
if (!text().isEmpty()) {
|
||||
if (reload && !text().isEmpty()) {
|
||||
search();
|
||||
}
|
||||
}
|
||||
@ -261,7 +263,7 @@ void WebSearchBar::contextMenuEvent(QContextMenuEvent* event)
|
||||
void WebSearchBar::focusOutEvent(QFocusEvent* e)
|
||||
{
|
||||
if (text().isEmpty()) {
|
||||
QString search = m_boxSearchType->currentItem()->text;
|
||||
QString search = m_boxSearchType->currentItem().text;
|
||||
setPlaceholderText(search);
|
||||
}
|
||||
QLineEdit::focusOutEvent(e);
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
explicit WebSearchBar(QupZilla* mainClass, QWidget* parent = 0);
|
||||
|
||||
private slots:
|
||||
void searchChanged(const ButtonWithMenu::Item &item);
|
||||
void searchChanged(const ButtonWithMenu::Item &item, bool reload = true);
|
||||
void setupEngines();
|
||||
|
||||
void search();
|
||||
|
@ -20,7 +20,6 @@
|
||||
ButtonWithMenu::ButtonWithMenu(QWidget* parent)
|
||||
: ToolButton(parent)
|
||||
, m_menu(new QMenu(this))
|
||||
, m_currentItem(0)
|
||||
{
|
||||
setPopupMode(QToolButton::InstantPopup);
|
||||
setCursor(Qt::ArrowCursor);
|
||||
@ -41,15 +40,13 @@ void ButtonWithMenu::clearItems()
|
||||
{
|
||||
m_menu->clear();
|
||||
m_items.clear();
|
||||
|
||||
m_currentItem = 0;
|
||||
}
|
||||
|
||||
void ButtonWithMenu::addItem(const Item &item)
|
||||
{
|
||||
m_items.append(item);
|
||||
|
||||
if (!m_currentItem) {
|
||||
if (m_items.count() == 1) {
|
||||
setCurrentItem(item);
|
||||
}
|
||||
|
||||
@ -77,29 +74,31 @@ void ButtonWithMenu::removeItem(const Item &item)
|
||||
return;
|
||||
}
|
||||
|
||||
if (*m_currentItem == item) {
|
||||
if (m_currentItem == item) {
|
||||
setCurrentItem(m_items.first());
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonWithMenu::setCurrentItem(const Item &item)
|
||||
void ButtonWithMenu::setCurrentItem(const Item &item, bool emitSignal)
|
||||
{
|
||||
int index = m_items.indexOf(item);
|
||||
if (index < 0) {
|
||||
if (index < 0 || m_currentItem == item) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_currentItem = const_cast<Item*>(&m_items.at(index));
|
||||
m_currentItem = item;
|
||||
|
||||
setIcon(m_currentItem->icon);
|
||||
setToolTip(m_currentItem->text);
|
||||
setIcon(m_currentItem.icon);
|
||||
setToolTip(m_currentItem.text);
|
||||
|
||||
emit activeItemChanged(*m_currentItem);
|
||||
if (emitSignal) {
|
||||
emit activeItemChanged(m_currentItem);
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonWithMenu::wheelEvent(QWheelEvent* event)
|
||||
{
|
||||
int currItemIndex = m_items.indexOf(*m_currentItem);
|
||||
int currItemIndex = m_items.indexOf(m_currentItem);
|
||||
int itemsCount = m_items.count();
|
||||
|
||||
if (itemsCount == 0) {
|
||||
@ -120,7 +119,7 @@ void ButtonWithMenu::wheelEvent(QWheelEvent* event)
|
||||
event->accept();
|
||||
}
|
||||
|
||||
ButtonWithMenu::Item* ButtonWithMenu::currentItem()
|
||||
ButtonWithMenu::Item ButtonWithMenu::currentItem()
|
||||
{
|
||||
return m_currentItem;
|
||||
}
|
||||
|
@ -42,6 +42,16 @@ public:
|
||||
bool operator==(const Item &a) {
|
||||
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);
|
||||
@ -50,9 +60,9 @@ public:
|
||||
void addItem(const Item &item);
|
||||
void addItems(const QList<Item> &items);
|
||||
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; }
|
||||
QMenu* menu() const;
|
||||
|
||||
@ -73,8 +83,7 @@ private:
|
||||
|
||||
QMenu* m_menu;
|
||||
QList<Item> m_items;
|
||||
Item* m_currentItem;
|
||||
|
||||
Item m_currentItem;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(ButtonWithMenu::Item)
|
||||
|
Loading…
Reference in New Issue
Block a user