Test our newly acquired shortcut capabilities by finally allowing Ctrl+F to trigger...
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 20 Sep 2008 02:12:37 +0000 (04:12 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 20 Sep 2008 02:16:07 +0000 (04:16 +0200)
We have now a global ActionCollection (accessible through QtUi::actionCollection()) that allows the
use of global shortcuts. ChatViewSearchBar is the first widget to make use of this.

Also some cleanups.
ChatViewSearchBar now uses

15 files changed:
src/qtui/chatitem.cpp
src/qtui/chatline.cpp
src/qtui/chatlinemodelitem.cpp
src/qtui/chatscene.cpp
src/qtui/chatviewsearchbar.cpp
src/qtui/chatviewsearchbar.h
src/qtui/mainwin.cpp
src/qtui/mainwin.h
src/qtui/qtui.cpp
src/qtui/qtui.h
src/qtui/settingspages/colorsettingspage.cpp
src/qtui/settingspages/fontssettingspage.cpp
src/qtui/topiclabel.cpp
src/uisupport/actioncollection.cpp
src/uisupport/actioncollection.h

index a087d6c..28b496e 100644 (file)
@@ -30,6 +30,7 @@
 #include "chatitem.h"
 #include "chatlinemodel.h"
 #include "qtui.h"
+#include "qtuistyle.h"
 
 ChatItem::ChatItem(ChatLineModel::ColumnType col, QAbstractItemModel *model, QGraphicsItem *parent)
   : QGraphicsItem(parent),
index 24e4a5d..1a8501c 100644 (file)
@@ -32,6 +32,7 @@
 #include "networkmodel.h"
 #include "qtui.h"
 #include "qtuisettings.h"
+#include "qtuistyle.h"
 
 ChatLine::ChatLine(int row, QAbstractItemModel *model, QGraphicsItem *parent)
   : QGraphicsItem(parent),
index 90691f8..24e2273 100644 (file)
@@ -24,7 +24,7 @@
 #include "chatlinemodelitem.h"
 #include "chatlinemodel.h"
 #include "qtui.h"
-#include "uistyle.h"
+#include "qtuistyle.h"
 
 // This Struct is taken from Harfbuzz. We use it only to calc it's size.
 // we use a shared memory region so we do not have to malloc a buffer area for every line
@@ -92,7 +92,7 @@ public:
       computeWrapList();
     return _wrapList;
   }
-  
+
 private:
   inline void style() {
     QtUiStyle::StyledMessage m = QtUi::style()->styleMessage(*_msgBuffer);
@@ -168,7 +168,7 @@ private:
       // the part " || (finder.position() == contents->plainText.length())" shouldn't be necessary
       // but in rare and indeterministic cases Qt states that the end of the text is not a boundary o_O
     } while(finder.isAtBoundary() || (finder.position() == contents->plainText.length()));
-    
+
     // A QVector needs less space than a QList
     _wrapList.resize(wplist.count());
     for(int i = 0; i < wplist.count(); i++) {
index 6c54f7c..c3a07b1 100644 (file)
@@ -32,6 +32,7 @@
 #include "columnhandleitem.h"
 #include "messagefilter.h"
 #include "qtui.h"
+#include "qtuistyle.h"
 #include "chatviewsettings.h"
 
 const qreal minContentsWidth = 200;
@@ -152,7 +153,7 @@ void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
       line->setPos(0, line->pos().y() + offset);
     }
   }
-  
+
   // update sceneRect
   if(atTop || moveTop) {
     updateSceneRect(_sceneRect.adjusted(0, h, 0, 0));
index 121070d..c4c6f09 100644 (file)
@@ -20,7 +20,9 @@
 
 #include "chatviewsearchbar.h"
 
-#include <QAction>
+#include "action.h"
+#include "actioncollection.h"
+#include "qtui.h"
 
 ChatViewSearchBar::ChatViewSearchBar(QWidget *parent)
   : QWidget(parent)
@@ -31,18 +33,25 @@ ChatViewSearchBar::ChatViewSearchBar(QWidget *parent)
   ui.searchUpButton->setEnabled(false);
   ui.searchDownButton->setEnabled(false);
 
-  _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);
+  hide();
 
-  connect(ui.hideButton, SIGNAL(clicked()),
-         _toggleViewAction, SLOT(toggle()));
+  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);
+
+  Action *hideSearchBar = coll->add<Action>("hideSearchBar", toggleSearchBar, SLOT(setChecked(bool))); // always false
+  hideSearchBar->setShortcut(Qt::Key_Escape);
+
+  connect(ui.hideButton, SIGNAL(clicked()), toggleSearchBar, SLOT(toggle()));
 }
 
 void ChatViewSearchBar::setVisible(bool visible) {
   QWidget::setVisible(visible);
   ui.searchEditLine->clear();
+  if(visible) ui.searchEditLine->setFocus();
 }
+
index 043e4ba..8caf3f8 100644 (file)
@@ -39,14 +39,11 @@ public:
   inline QCheckBox *searchMsgsBox() const { return ui.searchMsgsBox; }
   inline QCheckBox *searchOnlyRegularMsgsBox() const { return ui.searchOnlyRegularMsgsBox; }
 
-  inline QAction *toggleViewAction() const { return _toggleViewAction; }
-
 public slots:
-  void setVisible(bool visible);
+  void setVisible(bool);
 
 private:
   Ui::ChatViewSearchBar ui;
-  QAction *_toggleViewAction;
 };
 
 #endif //CHATVIEWSEARCHBAR_H
index 46756e5..8896893 100644 (file)
@@ -20,6 +20,8 @@
 #include "mainwin.h"
 
 #include "aboutdlg.h"
+#include "action.h"
+#include "actioncollection.h"
 #include "bufferview.h"
 #include "bufferviewconfig.h"
 #include "bufferviewfilter.h"
@@ -82,7 +84,8 @@ MainWin::MainWin(QWidget *parent)
     offlineTrayIcon(":/icons/quassel-icon-offline.png"),
     trayIconActive(false),
 
-    timer(new QTimer(this))
+    timer(new QTimer(this)),
+    _actionCollection(new ActionCollection(this))
 {
   UiSettings uiSettings;
   QString style = uiSettings.value("Style", QString("")).toString();
@@ -97,6 +100,8 @@ MainWin::MainWin(QWidget *parent)
   systray->setIcon(offlineTrayIcon);
   setWindowIconText("Quassel IRC");
 
+  QtUi::actionCollection()->addAssociatedWidget(this);
+
   statusBar()->showMessage(tr("Waiting for core..."));
 
   installEventFilter(new JumpKeyHandler(this));
@@ -140,6 +145,7 @@ void MainWin::init() {
   setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
 
   // setup stuff...
+  setupActions();
   setupMenus();
   setupViews();
   setupNickWidget();
@@ -161,7 +167,7 @@ void MainWin::init() {
   // attach the BufferWidget to the BufferModel and the default selection
   ui.bufferWidget->setModel(Client::bufferModel());
   ui.bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
-  ui.menuViews->addAction(ui.bufferWidget->searchBar()->toggleViewAction());
+  ui.menuViews->addAction(QtUi::actionCollection()->action("toggleSearchBar"));
 
   _titleSetter.setModel(Client::bufferModel());
   _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
@@ -174,6 +180,11 @@ MainWin::~MainWin() {
   s.setValue("MainWinState", saveState());
 }
 
+void MainWin::setupActions() {
+
+
+}
+
 void MainWin::setupMenus() {
   connect(ui.actionConnectCore, SIGNAL(triggered()), this, SLOT(showCoreConnectionDlg()));
   connect(ui.actionDisconnectCore, SIGNAL(triggered()), Client::instance(), SLOT(disconnectFromCore()));
index a055115..ffa2ade 100644 (file)
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef _MAINWIN_H_
-#define _MAINWIN_H_
+#ifndef MAINWIN_H_
+#define MAINWIN_H_
 
 #include "ui_mainwin.h"
 
 #include "qtui.h"
 #include "titlesetter.h"
-#include "sessionsettings.h" 
+#include "sessionsettings.h"
 
 #include <QSystemTrayIcon>
 #include <QTimer>
 
+class ActionCollection;
 class Buffer;
 class BufferViewConfig;
 class MsgProcessorStatusWidget;
@@ -49,6 +50,7 @@ class MainWin : public QMainWindow {
     virtual ~MainWin();
 
     void init();
+
     void addBufferView(BufferViewConfig *config = 0);
 
     void displayTrayIconMessage(const QString &title, const QString &message);
@@ -121,6 +123,7 @@ class MainWin : public QMainWindow {
 
     TitleSetter _titleSetter;
 
+    void setupActions();
     void setupMenus();
     void setupViews();
     void setupNickWidget();
@@ -146,6 +149,8 @@ class MainWin : public QMainWindow {
     QList<QDockWidget *> _netViews;
     NickListWidget *nickListWidget;
 
+    ActionCollection *_actionCollection;
+
 #ifdef HAVE_DBUS
     org::freedesktop::Notifications *desktopNotifications;
     quint32 notificationId;
index ff676ad..85e6b1a 100644 (file)
 
 #include <QDebug>
 
+#include "actioncollection.h"
 #include "chatlinemodel.h"
 #include "mainwin.h"
 #include "qtuimessageprocessor.h"
+#include "qtuistyle.h"
 #include "uisettings.h"
 #include "util.h"
 
+ActionCollection *QtUi::_actionCollection = 0;
 QtUiStyle *QtUi::_style = 0;
 
-QtUi::QtUi()
-  : AbstractUi()
+QtUi::QtUi() : AbstractUi()
 {
   if(_style != 0) {
     qWarning() << "QtUi has been instantiated again!";
     return;
   }
-    
+  _actionCollection = new ActionCollection(this);
+
   UiSettings uiSettings;
   loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
 
index 2c1156f..9ac3b97 100644 (file)
 #ifndef QTUI_H
 #define QTUI_H
 
-#include "qtuistyle.h"
 #include "quasselui.h"
 
+class ActionCollection;
 class MainWin;
 class MessageModel;
 class QtUiMessageProcessor;
+class QtUiStyle;
 
 //! This class encapsulates Quassel's Qt-based GUI.
 /** This is basically a wrapper around MainWin, which is necessary because we cannot derive MainWin
@@ -42,7 +43,14 @@ public:
   MessageModel *createMessageModel(QObject *parent);
   AbstractMessageProcessor *createMessageProcessor(QObject *parent);
 
-  inline static QtUiStyle *style() { return _style; }
+  inline static QtUiStyle *style();
+
+  //! Access the global ActionCollection.
+  /** This ActionCollection is associated with the main window, i.e. it contains global
+   *  actions (and thus, shortcuts). Widgets providing application-wide shortcuts should
+   *  create appropriate Action objects using QtUi::actionCollection()->add\<Action\>().
+   */
+  inline static ActionCollection *actionCollection();
 
 public slots:
   void init();
@@ -53,7 +61,11 @@ protected slots:
 
 private:
   MainWin *mainWin;
+  static ActionCollection *_actionCollection;
   static QtUiStyle *_style;
 };
 
+ActionCollection *QtUi::actionCollection() { return _actionCollection; }
+QtUiStyle *QtUi::style() { return _style; }
+
 #endif
index 8e76c70..2a8ee4c 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "qtui.h"
 #include "qtuisettings.h"
+#include "qtuistyle.h"
 #include "colorbutton.h"
 
 #include <QColorDialog>
@@ -590,7 +591,7 @@ bool ColorSettingsPage::testHasChanged() {
   if(QtUi::style()->format(UiStyle::Sender).background().color() != ui.senderBG->color()) return true;
   if(settings["SenderUseBG"].toBool() != ui.senderUseBG->isChecked()) return true;
   if(settings["NewMsgMarkerFG"].value<QColor>() != ui.newMsgMarkerFG->color()) return true;
-  
+
   /*
   if(QtUi::style()->format(UiStyle::Nick).foreground().color() != ui.nickFG->color()) return true;
   if(QtUi::style()->format(UiStyle::Nick).background().color() != ui.nickBG->color()) return true;
index f8ba23b..7d81e7f 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "qtui.h"
 #include "qtuisettings.h"
+#include "qtuistyle.h"
 
 #include <QFontDialog>
 
@@ -49,7 +50,7 @@ FontsSettingsPage::FontsSettingsPage(QWidget *parent)
   mapper->setMapping(ui.chooseTimestamp, ui.demoTimestamp);
 
   connect(mapper, SIGNAL(mapped(QWidget *)), this, SLOT(chooseFont(QWidget *)));
-  
+
   //connect(ui.customAppFonts, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
   connect(ui.checkTopic, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
   connect(ui.checkBufferView, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
@@ -87,7 +88,7 @@ void FontsSettingsPage::load(Settings::Mode mode) {
     inputLineFont = qApp->font();
   }
   initLabel(ui.demoInputLine, inputLineFont);
-  
+
   QTextCharFormat chatFormat = QtUi::style()->format(UiStyle::None, mode);
   initLabel(ui.demoChatMessages, chatFormat.font());
   QTextCharFormat nicksFormat = QtUi::style()->format(UiStyle::Sender, mode);
@@ -114,7 +115,7 @@ void FontsSettingsPage::save() {
   QtUiSettings s;
   s.setValue("UseInputLineFont", (ui.checkInputLine->checkState() == Qt::Checked));
   s.setValue("InputLineFont", ui.demoInputLine->font());
-  
+
   QTextCharFormat chatFormat = QtUi::style()->format(UiStyle::None);
   chatFormat.setFont(ui.demoChatMessages->font());
   QtUi::style()->setFormat(UiStyle::None, chatFormat, Settings::Custom);
index b41f736..8703142 100644 (file)
@@ -31,6 +31,7 @@
 #include <QFontMetrics>
 
 #include "qtui.h"
+#include "qtuistyle.h"
 #include "message.h"
 
 TopicLabel::TopicLabel(QWidget *parent)
index a20d918..8a5d606 100644 (file)
@@ -21,6 +21,7 @@
  ***************************************************************************/
 
 #include <QAction>
+#include <QDebug>
 
 #include "actioncollection.h"
 
@@ -49,7 +50,7 @@ QList<QAction *> ActionCollection::actions() const {
 }
 
 Action *ActionCollection::addAction(const QString &name, Action *action) {
-  QAction *act = addAction(name, action);
+  QAction *act = addAction(name, static_cast<QAction *>(action));
   Q_ASSERT(act == action);
   return action;
 }
@@ -206,6 +207,10 @@ void ActionCollection::clearAssociatedWidgets() {
   _associatedWidgets.clear();
 }
 
+void ActionCollection::associatedWidgetDestroyed(QObject *obj) {
+  _associatedWidgets.removeAll(static_cast<QWidget *>(obj));
+}
+
 bool ActionCollection::unlistAction(QAction *action) {
   // This might be called with a partly destroyed QAction!
 
index 41bc044..c03daef 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef ACTIONCOLLECTION_H_
 #define ACTIONCOLLECTION_H_
 
+#include <QDebug>
 #include <QList>
 #include <QMap>
 #include <QObject>