Moved out of ChatItem.
qWarning() << "BufferModel::switchToBufferIndex(const QModelIndex &):" << bufferIdx << "does not belong to BufferModel or NetworkModel";
}
+void BufferModel::switchToOrJoinBuffer(NetworkId networkId, const QString &name) {
+ BufferId bufId = Client::networkModel()->bufferId(networkId, name);
+ if(bufId.isValid()) {
+ QModelIndex targetIdx = Client::networkModel()->bufferIndex(bufId);
+ switchToBuffer(bufId);
+ if(!targetIdx.data(NetworkModel::ItemActiveRole).toBool())
+ Client::userInput(BufferInfo::fakeStatusBuffer(networkId), QString("/JOIN %1").arg(name));
+ } else
+ Client::userInput(BufferInfo::fakeStatusBuffer(networkId), QString("/JOIN %1").arg(name));
+}
+
void BufferModel::debug_currentChanged(QModelIndex current, QModelIndex previous) {
Q_UNUSED(previous);
qDebug() << "Switched current Buffer: " << current << current.data().toString() << "Buffer:" << current.data(NetworkModel::BufferIdRole).value<BufferId>();
BufferModel(NetworkModel *parent = 0);
bool filterAcceptsRow(int sourceRow, const QModelIndex &parent) const;
-
+
inline const SelectionModelSynchronizer *selectionModelSynchronizer() const { return &_selectionModelSynchronizer; }
inline QItemSelectionModel *standardSelectionModel() const { return _selectionModelSynchronizer.selectionModel(); }
-
+
inline void synchronizeSelectionModel(QItemSelectionModel *selectionModel) { _selectionModelSynchronizer.synchronizeSelectionModel(selectionModel); }
void synchronizeView(QAbstractItemView *view);
void setCurrentIndex(const QModelIndex &newCurrent);
void switchToBuffer(const BufferId &bufferId);
void switchToBufferIndex(const QModelIndex &bufferIdx);
-
+ void switchToOrJoinBuffer(NetworkId network, const QString &bufferName);
+
private slots:
void debug_currentChanged(QModelIndex current, QModelIndex previous);
void newNetwork(NetworkId id);
void networkConnectionChanged(Network::ConnectionState state);
-
+
private:
SelectionModelSynchronizer _selectionModelSynchronizer;
};
}
Clickable ContentsChatItem::clickableAt(const QPointF &pos) const {
- qint16 idx = posToCursor(pos);
- for(int i = 0; i < privateData()->clickables.count(); i++) {
- Clickable click = privateData()->clickables.at(i);
- if(idx >= click.start() && idx < click.start() + click.length())
- return click;
- }
- return Clickable();
+ return privateData()->clickables.atCursorPos(posToCursor(pos));
}
UiStyle::FormatList ContentsChatItem::formatList() const {
void ContentsChatItem::handleClick(const QPointF &pos, ChatScene::ClickMode clickMode) {
if(clickMode == ChatScene::SingleClick) {
- Clickable click = clickableAt(pos);
- if(click.isValid()) {
- QString str = data(ChatLineModel::DisplayRole).toString().mid(click.start(), click.length());
- switch(click.type()) {
- case Clickable::Url:
- if(!str.contains("://"))
- str = "http://" + str;
- QDesktopServices::openUrl(QUrl::fromEncoded(str.toUtf8(), QUrl::TolerantMode));
- break;
- case Clickable::Channel: {
- NetworkId networkId = Client::networkModel()->networkId(data(MessageModel::BufferIdRole).value<BufferId>());
- BufferId bufId = Client::networkModel()->bufferId(networkId, str);
- if(bufId.isValid()) {
- QModelIndex targetIdx = Client::networkModel()->bufferIndex(bufId);
- Client::bufferModel()->switchToBuffer(bufId);
- if(!targetIdx.data(NetworkModel::ItemActiveRole).toBool())
- Client::userInput(BufferInfo::fakeStatusBuffer(networkId), QString("/JOIN %1").arg(str));
- } else
- Client::userInput(BufferInfo::fakeStatusBuffer(networkId), QString("/JOIN %1").arg(str));
- break;
- }
- default:
- break;
- }
+ qint16 idx = posToCursor(pos);
+ Clickable foo = privateData()->clickables.atCursorPos(idx);
+ if(foo.isValid()) {
+ NetworkId networkId = Client::networkModel()->networkId(data(MessageModel::BufferIdRole).value<BufferId>());
+ QString text = data(ChatLineModel::DisplayRole).toString();
+ foo.activate(networkId, text);
}
} else if(clickMode == ChatScene::DoubleClick) {
chatScene()->setSelectingItem(this);
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+#include <QDesktopServices>
+#include <QModelIndex>
+#include <QUrl>
+
+#include "buffermodel.h"
#include "clickable.h"
+#include "client.h"
+
+void Clickable::activate(NetworkId networkId, const QString &text) const {
+ if(!isValid())
+ return;
+
+ QString str = text.mid(start(), length());
+
+ switch(type()) {
+ case Clickable::Url:
+ if(!str.contains("://"))
+ str = "http://" + str;
+ QDesktopServices::openUrl(QUrl::fromEncoded(str.toUtf8(), QUrl::TolerantMode));
+ break;
+ case Clickable::Channel:
+ Client::bufferModel()->switchToOrJoinBuffer(networkId, str);
+ break;
+ default:
+ break;
+ }
+}
// NOTE: This method is not threadsafe and not reentrant!
// (RegExps are not constant while matching, and they are static here for efficiency)
} while(type >= 0);
return result;
}
+
+Clickable ClickableList::atCursorPos(int idx) {
+ foreach(const Clickable &click, *this) {
+ if(idx >= click.start() && idx < click.start() + click.length())
+ return click;
+ }
+ return Clickable();
+}
#include <QStackedWidget>
+#include "types.h"
+
+class QModelIndex;
+
class Clickable {
public:
inline bool isValid() const { return _type != Invalid; }
+ void activate(NetworkId networkId, const QString &bufferName) const;
+
private:
Type _type;
quint16 _start;
public:
static ClickableList fromString(const QString &);
+ Clickable atCursorPos(int idx);
+
};
#endif // CLICKABLE_H_