From 754a784dda6fe5235c59a7ce3829599ccf62eeda Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Thu, 21 May 2009 22:00:32 +0200 Subject: [PATCH] Alt-A --- src/client/CMakeLists.txt | 2 -- src/qtui/mainwin.cpp | 32 +++++++++++++++++++ src/qtui/mainwin.h | 6 ++++ src/uisupport/CMakeLists.txt | 2 ++ .../bufferhotlistfilter.cpp | 24 +++++++------- .../bufferhotlistfilter.h | 2 +- src/uisupport/flatproxymodel.cpp | 2 +- 7 files changed, 53 insertions(+), 17 deletions(-) rename src/{client => uisupport}/bufferhotlistfilter.cpp (83%) rename src/{client => uisupport}/bufferhotlistfilter.h (97%) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index f9a60f25..f60f66c5 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -10,7 +10,6 @@ set(SOURCES abstractmessageprocessor.cpp abstractui.cpp backlogrequester.cpp - bufferhotlistfilter.cpp buffermodel.cpp buffersettings.cpp bufferviewoverlay.cpp @@ -35,7 +34,6 @@ set(SOURCES set(MOC_HDRS abstractmessageprocessor.h abstractui.h - bufferhotlistfilter.h buffermodel.h bufferviewoverlay.h client.h diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 2c9e0f74..e0fff46e 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -37,6 +37,7 @@ #include "awaylogview.h" #include "action.h" #include "actioncollection.h" +#include "bufferhotlistfilter.h" #include "buffermodel.h" #include "bufferview.h" #include "bufferviewoverlay.h" @@ -58,6 +59,7 @@ #include "debugbufferviewoverlay.h" #include "debuglogwidget.h" #include "debugmessagemodelfilter.h" +#include "flatproxymodel.h" #include "iconloader.h" #include "inputwidget.h" #include "inputline.h" @@ -165,6 +167,7 @@ void MainWin::init() { setupToolBars(); setupSystray(); setupTitleSetter(); + setupHotList(); #ifndef HAVE_KDE QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this)); @@ -293,8 +296,14 @@ void MainWin::setupActions() { this, SLOT(on_actionDebugBufferViewOverlay_triggered()))); coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll, this, SLOT(on_actionDebugMessageModel_triggered()))); + coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll, + this, SLOT(on_actionDebugHotList_triggered()))); coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll, this, SLOT(on_actionDebugLog_triggered()))); + + // Navigation + coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot buffer"), coll, + this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A))); } void MainWin::setupMenus() { @@ -353,6 +362,7 @@ void MainWin::setupMenus() { _helpDebugMenu->addAction(coll->action("DebugNetworkModel")); _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay")); _helpDebugMenu->addAction(coll->action("DebugMessageModel")); + _helpDebugMenu->addAction(coll->action("DebugHotList")); _helpDebugMenu->addAction(coll->action("DebugLog")); } @@ -576,6 +586,12 @@ void MainWin::setupStatusBar() { connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool))); } +void MainWin::setupHotList() { + FlatProxyModel *flatProxy = new FlatProxyModel(this); + flatProxy->setSourceModel(Client::bufferModel()); + _bufferHotList = new BufferHotListFilter(flatProxy); +} + void MainWin::saveStatusBarStatus(bool enabled) { QtUiSettings uiSettings; uiSettings.setValue("ShowStatusBar", enabled); @@ -1007,6 +1023,15 @@ void MainWin::connectOrDisconnectFromNet() { else net->requestDisconnect(); } +void MainWin::on_jumpHotBuffer_triggered() { + if(!_bufferHotList->rowCount()) + return; + + QModelIndex topIndex = _bufferHotList->index(0, 0); + BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value(); + Client::bufferModel()->switchToBuffer(bufferId); +} + void MainWin::on_actionDebugNetworkModel_triggered() { QTreeView *view = new QTreeView; view->setAttribute(Qt::WA_DeleteOnClose); @@ -1019,6 +1044,13 @@ void MainWin::on_actionDebugNetworkModel_triggered() { view->show(); } +void MainWin::on_actionDebugHotList_triggered() { + QTreeView *view = new QTreeView; + view->setAttribute(Qt::WA_DeleteOnClose); + view->setModel(_bufferHotList); + view->show(); +} + void MainWin::on_actionDebugBufferViewOverlay_triggered() { DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0); overlay->setAttribute(Qt::WA_DeleteOnClose); diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index 13b5466e..d5690942 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -38,6 +38,7 @@ #include "uisettings.h" class ActionCollection; +class BufferHotListFilter; class BufferView; class BufferViewConfig; class ClientBufferViewConfig; @@ -124,9 +125,11 @@ class MainWin void on_actionConfigureNetworks_triggered(); void on_actionConfigureViews_triggered(); void on_actionLockLayout_toggled(bool lock); + void on_jumpHotBuffer_triggered(); void on_actionDebugNetworkModel_triggered(); void on_actionDebugBufferViewOverlay_triggered(); void on_actionDebugMessageModel_triggered(); + void on_actionDebugHotList_triggered(); void on_actionDebugLog_triggered(); void clientNetworkCreated(NetworkId); @@ -168,6 +171,7 @@ class MainWin void setupSystray(); void setupTitleSetter(); void setupToolBars(); + void setupHotList(); void updateIcon(); void enableMenus(); @@ -195,6 +199,8 @@ class MainWin DWORD dwTickCount; #endif + BufferHotListFilter *_bufferHotList; + friend class QtUi; }; diff --git a/src/uisupport/CMakeLists.txt b/src/uisupport/CMakeLists.txt index eccde9fb..e31517fd 100644 --- a/src/uisupport/CMakeLists.txt +++ b/src/uisupport/CMakeLists.txt @@ -9,6 +9,7 @@ set(SOURCES abstractitemview.cpp action.cpp actioncollection.cpp + bufferhotlistfilter.cpp bufferview.cpp bufferviewfilter.cpp bufferviewoverlayfilter.cpp @@ -37,6 +38,7 @@ set(MOC_HDRS abstractnotificationbackend.h action.h actioncollection.h + bufferhotlistfilter.h bufferview.h bufferviewfilter.h bufferviewoverlayfilter.h diff --git a/src/client/bufferhotlistfilter.cpp b/src/uisupport/bufferhotlistfilter.cpp similarity index 83% rename from src/client/bufferhotlistfilter.cpp rename to src/uisupport/bufferhotlistfilter.cpp index e3f31da8..1c262271 100644 --- a/src/client/bufferhotlistfilter.cpp +++ b/src/uisupport/bufferhotlistfilter.cpp @@ -44,30 +44,28 @@ bool BufferHotListFilter::filterAcceptsRow(int source_row, const QModelIndex &so NetworkModel::ItemType itemType = (NetworkModel::ItemType)sourceModel()->data(source_index, NetworkModel::ItemTypeRole).toInt(); return itemType == NetworkModel::NetworkItemType; } + + return true; } bool BufferHotListFilter::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const { - qDebug() << Q_FUNC_INFO; - qDebug() << source_left << source_right; int leftActivity = sourceModel()->data(source_left, NetworkModel::BufferActivityRole).toInt(); int rightActivity = sourceModel()->data(source_right, NetworkModel::BufferActivityRole).toInt(); - qDebug() << leftActivity << rightActivity; if(leftActivity != rightActivity) return leftActivity < rightActivity; MsgId leftUnreadMsgId = sourceModel()->data(source_left, NetworkModel::BufferFirstUnreadMsgIdRole).value(); MsgId rightUnreadMsgId = sourceModel()->data(source_right, NetworkModel::BufferFirstUnreadMsgIdRole).value(); - qDebug() << leftUnreadMsgId << rightUnreadMsgId; return leftUnreadMsgId > rightUnreadMsgId; // newer messages are treated to be "less" } -QVariant BufferHotListFilter::data(const QModelIndex &index, int role) const { - QVariant d = QSortFilterProxyModel::data(index, role); +// QVariant BufferHotListFilter::data(const QModelIndex &index, int role) const { +// QVariant d = QSortFilterProxyModel::data(index, role); - if(role == Qt::DisplayRole) { - int activity = QSortFilterProxyModel::data(index, NetworkModel::BufferActivityRole).toInt(); - MsgId unreadMsgId = QSortFilterProxyModel::data(index, NetworkModel::BufferFirstUnreadMsgIdRole).value(); - return QString("%1 %2 %3").arg(d.toString()).arg(activity).arg(unreadMsgId.toInt()); - } - return d; -} +// if(role == Qt::DisplayRole) { +// int activity = QSortFilterProxyModel::data(index, NetworkModel::BufferActivityRole).toInt(); +// MsgId unreadMsgId = QSortFilterProxyModel::data(index, NetworkModel::BufferFirstUnreadMsgIdRole).value(); +// return QString("%1 %2 %3").arg(d.toString()).arg(activity).arg(unreadMsgId.toInt()); +// } +// return d; +// } diff --git a/src/client/bufferhotlistfilter.h b/src/uisupport/bufferhotlistfilter.h similarity index 97% rename from src/client/bufferhotlistfilter.h rename to src/uisupport/bufferhotlistfilter.h index a3577bdd..72a7f3fb 100644 --- a/src/client/bufferhotlistfilter.h +++ b/src/uisupport/bufferhotlistfilter.h @@ -30,7 +30,7 @@ public: BufferHotListFilter(QAbstractItemModel *source, QObject *parent = 0); virtual inline int columnCount(const QModelIndex &) const { return 1; } - QVariant data(const QModelIndex &index, int role) const; +// QVariant data(const QModelIndex &index, int role) const; protected: virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; diff --git a/src/uisupport/flatproxymodel.cpp b/src/uisupport/flatproxymodel.cpp index ef190742..1d54380a 100644 --- a/src/uisupport/flatproxymodel.cpp +++ b/src/uisupport/flatproxymodel.cpp @@ -652,7 +652,7 @@ FlatProxyModel::SourceItem *FlatProxyModel::SourceItem::findChild(int proxyPos) int start = 0; int end = _childs.count() - 1; int pivot; - while(end - start != 1) { + while(end - start > 1) { pivot = (end + start) / 2; if(_childs[pivot]->pos() > proxyPos) end = pivot; -- 2.20.1