BufferModel::BufferModel(NetworkModel *parent)
: QSortFilterProxyModel(parent),
_selectionModelSynchronizer(this),
- _propertyMapper(this)
+ _standardSelectionModel(this)
{
setSourceModel(parent);
-
- // initialize the Property Mapper
- _propertyMapper.setModel(this);
- _selectionModelSynchronizer.addRegularSelectionModel(_propertyMapper.selectionModel());
+ _selectionModelSynchronizer.addRegularSelectionModel(standardSelectionModel());
}
BufferModel::~BufferModel() {
view->setSelectionModel(mappedSelectionModel);
}
-void BufferModel::mapProperty(int column, int role, QObject *target, const QByteArray &property) {
- _propertyMapper.addMapping(column, role, target, property);
-}
-
QModelIndex BufferModel::currentIndex() {
- return propertyMapper()->selectionModel()->currentIndex();
+ return standardSelectionModel()->currentIndex();
}
void BufferModel::setCurrentIndex(const QModelIndex &newCurrent) {
- standardSelectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
- standardSelectionModel()->select(newCurrent, QItemSelectionModel::ClearAndSelect);
+ _standardSelectionModel.setCurrentIndex(newCurrent, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
+ _standardSelectionModel.select(newCurrent, QItemSelectionModel::ClearAndSelect);
}
#include "types.h"
#include "selectionmodelsynchronizer.h"
-#include "modelpropertymapper.h"
class NetworkModel;
class MappedSelectionModel;
bool filterAcceptsRow(int sourceRow, const QModelIndex &parent) const;
inline const SelectionModelSynchronizer *selectionModelSynchronizer() const { return &_selectionModelSynchronizer; }
- inline const ModelPropertyMapper *propertyMapper() const { return &_propertyMapper; }
- inline QItemSelectionModel *standardSelectionModel() const { return _propertyMapper.selectionModel(); }
-
+ inline QItemSelectionModel *standardSelectionModel() const { return const_cast<QItemSelectionModel *>(&_standardSelectionModel); }
+
void synchronizeSelectionModel(MappedSelectionModel *selectionModel);
void synchronizeView(QAbstractItemView *view);
- void mapProperty(int column, int role, QObject *target, const QByteArray &property);
QModelIndex currentIndex();
void setCurrentIndex(const QModelIndex &newCurrent);
private:
SelectionModelSynchronizer _selectionModelSynchronizer;
- ModelPropertyMapper _propertyMapper;
+ QItemSelectionModel _standardSelectionModel;
};
#endif // BUFFERMODEL_H
DEPMOD = common
QT_MOD = core network gui
SRCS += buffer.cpp buffersettings.cpp treemodel.cpp networkmodel.cpp buffermodel.cpp client.cpp clientsettings.cpp clientsyncer.cpp \
- mappedselectionmodel.cpp modelpropertymapper.cpp selectionmodelsynchronizer.cpp
+ mappedselectionmodel.cpp selectionmodelsynchronizer.cpp
HDRS += buffer.h buffersettings.h treemodel.h networkmodel.h buffermodel.h client.h clientsettings.h clientsyncer.h quasselui.h \
- mappedselectionmodel.h modelpropertymapper.h selectionmodelsynchronizer.h
+ mappedselectionmodel.h selectionmodelsynchronizer.h
#include "global.h"
BufferWidget::BufferWidget(QWidget *parent)
- : QWidget(parent),
- _bufferModel(0),
- _selectionModel(0),
+ : AbstractItemView(parent),
_currentBuffer(0)
{
ui.setupUi(this);
void BufferWidget::init() {
}
-void BufferWidget::setModel(BufferModel *bufferModel) {
- if(_bufferModel) {
- disconnect(_bufferModel, 0, this, 0);
- }
- _bufferModel = bufferModel;
-
- if(bufferModel) {
- connect(bufferModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
- this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int)));
- }
-}
-
-void BufferWidget::setSelectionModel(QItemSelectionModel *selectionModel) {
- if(_selectionModel) {
- disconnect(_selectionModel, 0, this, 0);
- }
- _selectionModel = selectionModel;
-
- if(selectionModel) {
- connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
- this, SLOT(currentChanged(QModelIndex, QModelIndex)));
- }
-}
-
void BufferWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
Q_ASSERT(model());
if(!parent.isValid()) {
#include "ui_bufferwidget.h"
+#include "abstractitemview.h"
#include "chatview.h"
#include "types.h"
class ChatWidget;
#include "buffermodel.h"
-#include <QItemSelectionModel>
//! Displays the contents of a Buffer.
/**
*/
-class BufferWidget : public QWidget {
+class BufferWidget : public AbstractItemView {
Q_OBJECT
public:
virtual ~BufferWidget();
void init();
- inline BufferModel *model() { return _bufferModel; }
- void setModel(BufferModel *bufferModel);
-
- inline QItemSelectionModel *selectionModel() const { return _selectionModel; }
- void setSelectionModel(QItemSelectionModel *selectionModel);
-
inline BufferId currentBuffer() const { return _currentBuffer; }
protected slots:
-// virtual void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
-// virtual void commitData(QWidget *editor);
virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
-// virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
-// virtual void editorDestroyed(QObject *editor);
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
-// virtual void rowsInserted(const QModelIndex &parent, int start, int end);
-// virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
private slots:
void removeBuffer(BufferId bufferId);
QHash<BufferId, ChatWidget *> _chatWidgets;
QHash<BufferId, ChatView *> _chatViews;
- QPointer<BufferModel> _bufferModel;
- QPointer<QItemSelectionModel> _selectionModel;
-
BufferId _currentBuffer;
};
InputWidget::InputWidget(QWidget *parent)
- : QWidget(parent),
- validBuffer(false),
- _bufferModel(0),
- _selectionModel(0)
+ : AbstractItemView(parent),
+ validBuffer(false)
{
ui.setupUi(this);
connect(ui.inputEdit, SIGNAL(sendText(QString)), this, SLOT(sendText(QString)));
InputWidget::~InputWidget() {
}
-void InputWidget::setModel(BufferModel *bufferModel) {
- if(_bufferModel) {
- disconnect(_bufferModel, 0, this, 0);
- }
- _bufferModel = bufferModel;
- connect(bufferModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
- this, SLOT(dataChanged(QModelIndex, QModelIndex)));
-}
-
-void InputWidget::setSelectionModel(QItemSelectionModel *selectionModel) {
- if(_selectionModel) {
- disconnect(_selectionModel, 0, this, 0);
- }
- _selectionModel = selectionModel;
- connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
- this, SLOT(currentChanged(QModelIndex, QModelIndex)));
-}
-
void InputWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) {
Q_UNUSED(previous);
void InputWidget::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
QItemSelectionRange changedArea(topLeft, bottomRight);
- QModelIndex currentIndex = Client::bufferModel()->currentIndex();
+ QModelIndex currentIndex = selectionModel()->currentIndex();
if(changedArea.contains(currentIndex)) {
ui.inputEdit->setEnabled(currentIndex.data(NetworkModel::ItemActiveRole).value<bool>());
}
#define INPUTWIDGET_H
#include "ui_inputwidget.h"
-#include <QPointer>
-#include <QItemSelectionModel>
+#include "abstractitemview.h"
#include "buffermodel.h"
#include "bufferinfo.h"
#include "identity.h"
#include "network.h"
-class InputWidget : public QWidget {
+class InputWidget : public AbstractItemView {
Q_OBJECT
public:
InputWidget(QWidget *parent = 0);
virtual ~InputWidget();
- inline BufferModel *model() { return _bufferModel; }
- void setModel(BufferModel *bufferModel);
-
- inline QItemSelectionModel *selectionModel() const { return _selectionModel; }
- void setSelectionModel(QItemSelectionModel *selectionModel);
-
const Network *currentNetwork() const;
protected slots:
-// virtual void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
-// virtual void commitData(QWidget *editor);
virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
-// virtual void editorDestroyed(QObject *editor);
-// virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
-// virtual void rowsInserted(const QModelIndex &parent, int start, int end);
-// virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
private slots:
void sendText(QString text);
bool validBuffer;
BufferInfo currentBufferInfo;
- QPointer<BufferModel> _bufferModel;
- QPointer<QItemSelectionModel> _selectionModel;
NetworkId _networkId;
IdentityId _identityId;
// attach the BufferWidget to the BufferModel and the default selection
ui.bufferWidget->setModel(Client::bufferModel());
ui.bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
-
+
if(Global::SPUTDEV) {
//showSettingsDlg();
//showAboutDlg();
// attach the NickListWidget to the BufferModel and the default selection
nickListWidget->setModel(Client::bufferModel());
nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
-
- Client::bufferModel()->mapProperty(0, NetworkModel::BufferIdRole, nickListWidget, "currentBuffer");
}
void MainWin::setupChatMonitor() {
dock->setWidget(topicwidget);
- Client::bufferModel()->mapProperty(1, Qt::DisplayRole, topicwidget, "topic");
+ topicwidget->setModel(Client::bufferModel());
+ topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
addDockWidget(Qt::TopDockWidgetArea, dock);
#include "nickviewfilter.h"
NickListWidget::NickListWidget(QWidget *parent)
- : QWidget(parent),
- _bufferModel(0),
- _selectionModel(0)
+ : AbstractItemView(parent)
{
ui.setupUi(this);
}
-void NickListWidget::setModel(BufferModel *bufferModel) {
- if(_bufferModel) {
- disconnect(_bufferModel, 0, this, 0);
- }
-
- _bufferModel = bufferModel;
-
- if(bufferModel) {
- connect(bufferModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
- this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int)));
- }
-}
-
-void NickListWidget::setSelectionModel(QItemSelectionModel *selectionModel) {
- if(_selectionModel) {
- disconnect(_selectionModel, 0, this, 0);
- }
-
- _selectionModel = selectionModel;
-
- if(selectionModel) {
- connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
- this, SLOT(currentChanged(QModelIndex, QModelIndex)));
- }
-}
-
void NickListWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) {
BufferInfo::Type bufferType = (BufferInfo::Type)current.data(NetworkModel::BufferTypeRole).toInt();
BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
#define _NICKLISTWIDGET_H_
#include "ui_nicklistwidget.h"
+#include "abstractitemview.h"
+
#include "types.h"
#include <QHash>
-#include <QPointer>
-#include <QItemSelectionModel>
-
#include "buffermodel.h"
class Buffer;
class NickView;
-class NickListWidget : public QWidget {
+class NickListWidget : public AbstractItemView {
Q_OBJECT
public:
NickListWidget(QWidget *parent = 0);
- inline BufferModel *model() { return _bufferModel; }
- void setModel(BufferModel *bufferModel);
-
- inline QItemSelectionModel *selectionModel() const { return _selectionModel; }
- void setSelectionModel(QItemSelectionModel *selectionModel);
-
protected:
virtual QSize sizeHint() const;
protected slots:
-// virtual void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
-// virtual void commitData(QWidget *editor);
virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
-// virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
-// virtual void editorDestroyed(QObject *editor);
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
-// virtual void rowsInserted(const QModelIndex &parent, int start, int end);
-// virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
private slots:
void removeBuffer(BufferId bufferId);
private:
Ui::NickListWidget ui;
QHash<BufferId, NickView *> nickViews;
-
- QPointer<BufferModel> _bufferModel;
- QPointer<QItemSelectionModel> _selectionModel;
};
#endif
TopicButton::TopicButton(QWidget *parent)
: QAbstractButton(parent)
{
+ setFixedHeight(QFontMetrics(qApp->font()).height());
}
void TopicButton::paintEvent(QPaintEvent *event) {
void TopicButton::setAndStyleText(const QString &text) {
if(QAbstractButton::text() == text)
return;
+
setText(text); // this triggers a repaint event
styledText = QtUi::style()->styleString(Message::mircToInternal(text));
foreach(QTextLayout::FormatRange fr, styledText.formats) {
height = qMax(height, QFontMetrics(fr.format.font()).height());
}
+
+ // ensure the button is editable (height != 1) if there is no text to show
+ if(text.isEmpty())
+ height = QFontMetrics(qApp->font()).height();
+
setFixedHeight(height);
}
#include <QDebug>
TopicWidget::TopicWidget(QWidget *parent)
- : QWidget(parent)
+ : AbstractItemView(parent)
{
ui.setupUi(this);
ui.topicLineEdit->hide();
ui.topicButton->show();
}
+void TopicWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) {
+ Q_UNUSED(previous);
+ setTopicForIndex(current);
+}
+
+void TopicWidget::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
+ QItemSelectionRange changedArea(topLeft, bottomRight);
+ QModelIndex currentIndex = selectionModel()->currentIndex();
+ if(changedArea.contains(currentIndex))
+ setTopicForIndex(currentIndex);
+};
+
+void TopicWidget::setTopicForIndex(const QModelIndex &index) {
+ QModelIndex topicIndex = index.sibling(index.row(), 1);
+ setTopic(topicIndex.data().toString());
+}
+
void TopicWidget::setTopic(const QString &newtopic) {
if(_topic == newtopic)
return;
}
void TopicWidget::on_topicLineEdit_returnPressed() {
+ emit topicChanged(ui.topicLineEdit->text());
switchPlain();
- emit topicChanged(topic());
}
void TopicWidget::on_topicButton_clicked() {
void TopicWidget::switchPlain() {
ui.topicLineEdit->hide();
ui.topicButton->show();
+ ui.topicLineEdit->setText(_topic);
}
+// filter for the input widget to switch back to normal mode
bool TopicWidget::eventFilter(QObject *obj, QEvent *event) {
+ if(event->type() == QEvent::FocusOut) {
+ switchPlain();
+ return true;
+ }
+
if(event->type() != QEvent::KeyPress)
return QObject::eventFilter(obj, event);
if(keyEvent->key() == Qt::Key_Escape) {
switchPlain();
- ui.topicLineEdit->setText(_topic);
return true;
}
#ifndef _TOPICWIDGET_H_
#define _TOPICWIDGET_H_
-#include <QWidget>
+#include "abstractitemview.h"
#include "ui_topicwidget.h"
-class TopicWidget : public QWidget {
+class TopicWidget : public AbstractItemView {
Q_OBJECT
- Q_PROPERTY(QString topic READ topic WRITE setTopic STORED false)
public:
TopicWidget(QWidget *parent = 0);
- inline QString topic() const { return ui.topicLineEdit->text(); }
void setTopic(const QString &newtopic);
+ void setTopicForIndex(const QModelIndex &index);
virtual bool eventFilter(QObject *obj, QEvent *event);
signals:
void topicChanged(const QString &text);
-
+
+protected slots:
+ virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
+ virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
+
private slots:
void on_topicLineEdit_returnPressed();
void on_topicButton_clicked();
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-08 by the Quassel Project *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "abstractitemview.h"
+
+AbstractItemView::AbstractItemView(QWidget *parent)
+ : QWidget(parent),
+ _model(0),
+ _selectionModel(0)
+{
+}
+
+void AbstractItemView::setModel(QAbstractItemModel *model) {
+ if(_model) {
+ disconnect(_model, 0, this, 0);
+ }
+ _model = model;
+ connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
+ this, SLOT(dataChanged(QModelIndex, QModelIndex)));
+ connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
+ this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int)));
+ connect(model, SIGNAL(rowsInserted(QModelIndex, int, int)),
+ this, SLOT(rowsInserted(QModelIndex, int, int)));
+}
+
+
+
+void AbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel) {
+ if(_selectionModel) {
+ disconnect(_selectionModel, 0, this, 0);
+ }
+ _selectionModel = selectionModel;
+ connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
+ this, SLOT(currentChanged(QModelIndex, QModelIndex)));
+ connect(selectionModel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+ this, SLOT(selectionChanged(QItemSelection, QItemSelection)));
+}
+
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-08 by the Quassel Project *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef ABSTRACTITEMVIEW_H
+#define ABSTRACTITEMVIEW_H
+
+#include <QWidget>
+#include <QAbstractItemModel>
+#include <QItemSelectionModel>
+#include <QModelIndex>
+#include <QItemSelection>
+#include <QAbstractItemDelegate>
+#include <QPointer>
+
+class AbstractItemView : public QWidget {
+ Q_OBJECT
+
+public:
+ AbstractItemView(QWidget *parent = 0);
+
+ inline QAbstractItemModel *model() { return _model; }
+ void setModel(QAbstractItemModel *model);
+
+ inline QItemSelectionModel *selectionModel() const { return _selectionModel; }
+ void setSelectionModel(QItemSelectionModel *selectionModel);
+
+protected slots:
+ virtual void closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint) {};
+ virtual void commitData(QWidget *) {};
+ virtual void currentChanged(const QModelIndex &, const QModelIndex &) {};
+ virtual void dataChanged(const QModelIndex &, const QModelIndex &) {};
+ virtual void editorDestroyed(QObject *) {};
+ virtual void rowsAboutToBeRemoved(const QModelIndex &, int, int) {};
+ virtual void rowsInserted(const QModelIndex &, int, int) {};
+ virtual void selectionChanged(const QItemSelection &, const QItemSelection &) {};
+
+protected:
+ QPointer<QAbstractItemModel> _model;
+ QPointer<QItemSelectionModel> _selectionModel;
+};
+
+#endif // ABSTRACTITEMVIEW_H
DEPMOD = common client
QT_MOD = core gui network
-SRCS += bufferview.cpp bufferviewfilter.cpp colorbutton.cpp nickviewfilter.cpp inputline.cpp nickview.cpp settingspage.cpp tabcompleter.cpp uisettings.cpp uistyle.cpp uistylesettings.cpp
-HDRS += bufferview.h bufferviewfilter.h colorbutton.h nickviewfilter.h inputline.h nickview.h settingspage.h tabcompleter.h uisettings.h uistyle.h uistylesettings.h
+SRCS += abstractitemview.cpp bufferview.cpp bufferviewfilter.cpp colorbutton.cpp nickviewfilter.cpp inputline.cpp nickview.cpp settingspage.cpp tabcompleter.cpp uisettings.cpp uistyle.cpp uistylesettings.cpp
+HDRS += abstractitemview.h bufferview.h bufferviewfilter.h colorbutton.h nickviewfilter.h inputline.h nickview.h settingspage.h tabcompleter.h uisettings.h uistyle.h uistylesettings.h
FORMNAMES =
{ using namespace Global;
quasselVersion = "0.2.0-alpha3-pre";
- quasselDate = "2008-03-11";
- quasselBuild = 628;
+ quasselDate = "2008-03-12";
+ quasselBuild = 630;
//! Minimum client build number the core needs
clientBuildNeeded = 628;