#include "networkmodel.h"
#include "buffermodel.h"
#include "nickviewfilter.h"
+#include "qtuisettings.h"
NickListWidget::NickListWidget(QWidget *parent)
- : QWidget(parent),
- _bufferModel(0),
- _selectionModel(0)
+ : AbstractItemView(parent),
+ _showNickListAction(new QAction(tr("Nicks"), this)),
+ _showDockAction(0)
{
+ _showNickListAction->setCheckable(true);
+ QtUiSettings s;
+ _showNickListAction->setChecked(s.value("ShowNickListAction", QVariant(true)).toBool());
ui.setupUi(this);
+ connect(_showNickListAction, SIGNAL(toggled(bool)), this, SLOT(showWidget(bool)));
}
-void NickListWidget::setModel(BufferModel *bufferModel) {
- if(_bufferModel) {
- disconnect(_bufferModel, 0, this, 0);
- }
-
- _bufferModel = bufferModel;
+NickListWidget::~NickListWidget() {
+ QtUiSettings s;
+ s.setValue("ShowNickListAction", showNickListAction()->isChecked());
+}
- if(bufferModel) {
- connect(bufferModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
- this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int)));
- }
+void NickListWidget::setShowDockAction(QAction *action) {
+ _showDockAction = action;
+}
+
+QAction *NickListWidget::showDockAction() const {
+ return _showDockAction;
+}
+
+QAction *NickListWidget::showNickListAction() const {
+ return _showNickListAction;
}
-void NickListWidget::setSelectionModel(QItemSelectionModel *selectionModel) {
- if(_selectionModel) {
- disconnect(_selectionModel, 0, this, 0);
+void NickListWidget::showWidget(bool visible) {
+ if(!selectionModel())
+ return;
+
+ QModelIndex currentIndex = selectionModel()->currentIndex();
+ if(currentIndex.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer && showDockAction()) {
+ if(visible != showDockAction()->isChecked()) {
+ // show or hide
+ showDockAction()->trigger();
+ }
}
+}
- _selectionModel = selectionModel;
+void NickListWidget::changedVisibility(bool visible) {
+ if(!selectionModel())
+ return;
- if(selectionModel) {
- connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
- this, SLOT(currentChanged(QModelIndex, QModelIndex)));
+ QModelIndex currentIndex = selectionModel()->currentIndex();
+ if(currentIndex.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer && !visible) {
+ showNickListAction()->setChecked(false);
}
}
if(bufferType != BufferInfo::ChannelBuffer) {
ui.stackedWidget->setCurrentWidget(ui.emptyPage);
+ if(showDockAction() && showDockAction()->isChecked()) {
+ // hide
+ showDockAction()->trigger();
+ }
return;
+ } else {
+ if(showNickListAction()->isChecked())
+ if(showDockAction()&& !showDockAction()->isChecked()) {
+ // show
+ showDockAction()->trigger();
+ }
}
if(newBufferId == oldBufferId)