Add TaskbarNotificationBackend
[quassel.git] / src / qtui / chatviewsearchbar.cpp
index 121070d..bfa79e1 100644 (file)
 
 #include "chatviewsearchbar.h"
 
-#include <QAction>
+#include "action.h"
+#include "actioncollection.h"
+#include "iconloader.h"
+#include "qtui.h"
 
 ChatViewSearchBar::ChatViewSearchBar(QWidget *parent)
   : QWidget(parent)
 {
   ui.setupUi(this);
+  ui.hideButton->setIcon(BarIcon("dialog-close"));
+  ui.searchUpButton->setIcon(SmallIcon("go-up"));
+  ui.searchDownButton->setIcon(SmallIcon("go-down"));
+
   layout()->setContentsMargins(0, 0, 0, 0);
 
-  ui.searchUpButton->setEnabled(false);
-  ui.searchDownButton->setEnabled(false);
+  hide();
+
+  ActionCollection *coll = QtUi::actionCollection();
+
+  Action *toggleSearchBar = coll->add<Action>("toggleSearchBar");
+  connect(toggleSearchBar, SIGNAL(toggled(bool)), SLOT(setVisible(bool)));
+  toggleSearchBar->setText(tr("Show Search Bar"));
+  toggleSearchBar->setShortcut(Qt::CTRL + Qt::Key_F);
+  toggleSearchBar->setCheckable(true);
 
-  _toggleViewAction = new QAction(tr("Show search bar"), this);
-  _toggleViewAction->setCheckable(true);
-  _toggleViewAction->setChecked(false);
-  connect(_toggleViewAction, SIGNAL(toggled(bool)),
-         this, SLOT(setVisible(bool)));
-  setVisible(false);
+  Action *hideSearchBar = coll->add<Action>("hideSearchBar", toggleSearchBar, SLOT(setChecked(bool))); // always false
+  hideSearchBar->setShortcut(Qt::Key_Escape);
 
-  connect(ui.hideButton, SIGNAL(clicked()),
-         _toggleViewAction, SLOT(toggle()));
+  connect(ui.hideButton, SIGNAL(clicked()), toggleSearchBar, SLOT(toggle()));
 }
 
 void ChatViewSearchBar::setVisible(bool visible) {
-  QWidget::setVisible(visible);
+  // clearing the search field also removes the highlight items from the scene
+  // this should be done before the SearchBar is hidden, as the hiding triggers
+  // a resize event which can lead to strange side effects.
   ui.searchEditLine->clear();
+  QWidget::setVisible(visible);
+  if(visible) ui.searchEditLine->setFocus();
 }
+