}
if (event->type() == QEvent::TouchBegin) {
+ // Enable scrolling by draging, disable selecting/clicking content
setDragMode(QGraphicsView::ScrollHandDrag);
setInteractive(false);
- if (verticalScrollBar()->isVisible()) return true; //if scrollbar is not visible we need to request backlog below
+ // if scrollbar is not visible we need to request backlog below else we need to accept
+ // the event now (return true) so that we will receive TouchUpdate and TouchEnd/TouchCancel
+ if (verticalScrollBar()->isVisible()) return true;
}
#if QT_VERSION >= 0x050000
#else
if (event->type() == QEvent::TouchEnd) {
#endif
+ // End scroll and reset settings to default
setDragMode(QGraphicsView::NoDrag);
setInteractive(true);
- _firstTouchUpdateHappened = false;
+ _firstTouchUpdateHappened = false;
return true;
}
- if (event->type() == QEvent::TouchUpdate) {
- if (!_firstTouchUpdateHappened) {
- QTouchEvent::TouchPoint p = ((QTouchEvent*)event)->touchPoints().at(0);
- double dx = abs (p.lastPos().x() - p.pos().x());
- double dy = abs (p.lastPos().y() - p.pos().y());
- if (dx > dy) {
- setDragMode(QGraphicsView::NoDrag);
- setInteractive(true);
- }
- _firstTouchUpdateHappened = true;
- }
- }
+ if (event->type() == QEvent::TouchUpdate) {
+ if (!_firstTouchUpdateHappened) {
+ // After the first movement of a Touch-Point, calculate the distance in both axis
+ // and if the point moved more horizontally abort scroll.
+ QTouchEvent::TouchPoint p = ((QTouchEvent*)event)->touchPoints().at(0);
+ double dx = abs (p.lastPos().x() - p.pos().x());
+ double dy = abs (p.lastPos().y() - p.pos().y());
+ if (dx > dy) {
+ setDragMode(QGraphicsView::NoDrag);
+ setInteractive(true);
+ }
+ _firstTouchUpdateHappened = true;
+ }
+ // Applying the movement happens automatically by the drag-mode
+ }
if (event->type() == QEvent::Wheel || event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate) {
if (!verticalScrollBar()->isVisible()) {
int _scrollOffset;
bool _invalidateFilter;
QSet<ChatLine *> _linesWithCache;
- bool _firstTouchUpdateHappened = false;
+ bool _firstTouchUpdateHappened = false;
};
Client::userInput(bufferInfo, QString("/JOIN %1").arg(bufferInfo.bufferName()));
}
+
void BufferView::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) {
event->accept();
removeSelectedBuffers();
}
- TreeViewTouch::keyPressEvent(event);
+ TreeViewTouch::keyPressEvent(event);
}
void BufferView::rowsInserted(const QModelIndex &parent, int start, int end)
{
- TreeViewTouch::rowsInserted(parent, start, end);
+ TreeViewTouch::rowsInserted(parent, start, end);
// ensure that newly inserted network nodes are expanded per default
if (parent.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
#if QT_VERSION < 0x050000
void BufferView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
- TreeViewTouch::dataChanged(topLeft, bottomRight);
+ TreeViewTouch::dataChanged(topLeft, bottomRight);
#else
void BufferView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
{
- TreeViewTouch::dataChanged(topLeft, bottomRight, roles);
+ TreeViewTouch::dataChanged(topLeft, bottomRight, roles);
#endif
// determine how many items have been changed and if any of them is a networkitem
return;
Client::bufferModel()->switchToOrStartQuery(networkId, ircUser->nick());
-}
\ No newline at end of file
+}
#include <QScrollBar>
TreeViewTouch::TreeViewTouch(QWidget *parent)
- : QTreeView(parent)
+ : QTreeView(parent)
{
- setAttribute(Qt::WA_AcceptTouchEvents);
+ setAttribute(Qt::WA_AcceptTouchEvents);
}
-
bool TreeViewTouch::event(QEvent *event) {
- if (event->type() == QEvent::TouchBegin) {
- _touchScrollInProgress = true;
- setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
- return true;
- }
+ if (event->type() == QEvent::TouchBegin) {
+ // Register that we may be scrolling, set the scroll mode to scroll-per-pixel
+ // and accept the event (return true) so that we will receive TouchUpdate and TouchEnd/TouchCancel
+ _touchScrollInProgress = true;
+ setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
+ return true;
+ }
- if (event->type() == QEvent::TouchUpdate && _touchScrollInProgress) {
- QTouchEvent::TouchPoint p = ((QTouchEvent*)event)->touchPoints().at(0);
- if (!_firstTouchUpdateHappened) {
- double dx = abs(p.lastPos().x() - p.pos().x());
- double dy = abs(p.lastPos().y() - p.pos().y());
- if (dx > dy) {
- _touchScrollInProgress = false;
- }
- _firstTouchUpdateHappened = true;
- }
- verticalScrollBar()->setValue(verticalScrollBar()->value() - (p.pos().y() - p.lastPos().y()));
- return true;
- }
+ if (event->type() == QEvent::TouchUpdate && _touchScrollInProgress) {
+ QTouchEvent::TouchPoint p = ((QTouchEvent*)event)->touchPoints().at(0);
+ if (!_firstTouchUpdateHappened) {
+ // After the first movement of a Touch-Point, calculate the distance in both axis
+ // and if the point moved more horizontally abort scroll.
+ double dx = abs(p.lastPos().x() - p.pos().x());
+ double dy = abs(p.lastPos().y() - p.pos().y());
+ if (dx > dy) {
+ _touchScrollInProgress = false;
+ }
+ _firstTouchUpdateHappened = true;
+ }
+ // Apply touch movement to scrollbar
+ verticalScrollBar()->setValue(verticalScrollBar()->value() - (p.pos().y() - p.lastPos().y()));
+ return true;
+ }
#if QT_VERSION >= 0x050000
- if (event->type() == QEvent::TouchEnd || event->type() == QEvent::TouchCancel) {
+ if (event->type() == QEvent::TouchEnd || event->type() == QEvent::TouchCancel) {
#else
if (event->type() == QEvent::TouchEnd) {
#endif
- _touchScrollInProgress = false;
- _firstTouchUpdateHappened = false;
- return true;
- }
+ // End scroll and reset variables
+ _touchScrollInProgress = false;
+ _firstTouchUpdateHappened = false;
+ return true;
+ }
- return QTreeView::event(event);
+ return QTreeView::event(event);
}
void TreeViewTouch::mousePressEvent(QMouseEvent * event) {
- if (!_touchScrollInProgress)
- QTreeView::mousePressEvent(event);
+ if (!_touchScrollInProgress)
+ QTreeView::mousePressEvent(event);
}
void TreeViewTouch::mouseMoveEvent(QMouseEvent * event) {
- if (!_touchScrollInProgress)
- QTreeView::mouseMoveEvent(event);
+ if (!_touchScrollInProgress)
+ QTreeView::mouseMoveEvent(event);
};
#define TREEVIEWTOUCH_H_
#include <QTreeView>
+/**
+* This class handles Touch Events for TreeViews
+*/
class TreeViewTouch :
- public QTreeView
+ public QTreeView
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit TreeViewTouch(QWidget *parent = 0);
+ explicit TreeViewTouch(QWidget *parent = 0);
protected:
- virtual bool event(QEvent *event);
- virtual void mouseMoveEvent(QMouseEvent *event);
- virtual void mousePressEvent(QMouseEvent *event);
+
+ /**
+ * Handles Events
+ *
+ * @param[in,out] an event
+ * @returns true if event got handled, false if event got ignored
+ */
+ virtual bool event(QEvent *event);
+
+ /**
+ * Handles Mouse Move Events
+ *
+ * Suppresses Events during Touch-Scroll
+ *
+ * @param[in,out] An Event
+ */
+ virtual void mouseMoveEvent(QMouseEvent *event);
+
+ /**
+ * Handles Mouse Press Events
+ *
+ * Suppresses Events during Touch-Scroll
+ *
+ * @param[in,out] An Event
+ */
+ virtual void mousePressEvent(QMouseEvent *event);
private:
- bool _touchScrollInProgress = false;
- bool _firstTouchUpdateHappened = false;
+ bool _touchScrollInProgress = false;
+ bool _firstTouchUpdateHappened = false;
};
#endif
\ No newline at end of file