2020-08-15 21:48:28 +00:00
|
|
|
/*
|
|
|
|
* Squawk messenger.
|
|
|
|
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
*
|
|
|
|
* 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FEEDVIEW_H
|
|
|
|
#define FEEDVIEW_H
|
|
|
|
|
|
|
|
#include <QAbstractItemView>
|
2022-04-28 21:29:44 +00:00
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QUrl>
|
2020-08-15 21:48:28 +00:00
|
|
|
|
|
|
|
#include <deque>
|
2021-04-22 22:41:32 +00:00
|
|
|
#include <set>
|
2020-08-15 21:48:28 +00:00
|
|
|
|
2021-05-15 22:07:49 +00:00
|
|
|
#include <ui/widgets/messageline/messagefeed.h>
|
|
|
|
#include <ui/utils/progress.h>
|
2020-08-15 21:48:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo write docs
|
|
|
|
*/
|
|
|
|
class FeedView : public QAbstractItemView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
FeedView(QWidget* parent = nullptr);
|
|
|
|
~FeedView();
|
|
|
|
|
|
|
|
QModelIndex indexAt(const QPoint & point) const override;
|
|
|
|
void scrollTo(const QModelIndex & index, QAbstractItemView::ScrollHint hint) override;
|
|
|
|
QRect visualRect(const QModelIndex & index) const override;
|
|
|
|
bool isIndexHidden(const QModelIndex & index) const override;
|
|
|
|
QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
|
|
|
|
void setSelection(const QRect & rect, QItemSelectionModel::SelectionFlags command) override;
|
|
|
|
QRegion visualRegionForSelection(const QItemSelection & selection) const override;
|
2021-02-01 22:55:15 +00:00
|
|
|
void setItemDelegate(QAbstractItemDelegate* delegate);
|
2021-02-06 11:02:42 +00:00
|
|
|
void setModel(QAbstractItemModel * model) override;
|
2020-08-15 21:48:28 +00:00
|
|
|
|
2020-08-20 21:32:30 +00:00
|
|
|
QFont getFont() const;
|
|
|
|
|
2021-05-03 00:35:43 +00:00
|
|
|
signals:
|
|
|
|
void resized();
|
|
|
|
|
2021-01-07 21:50:12 +00:00
|
|
|
public slots:
|
|
|
|
|
2020-08-15 21:48:28 +00:00
|
|
|
protected slots:
|
|
|
|
void rowsInserted(const QModelIndex & parent, int start, int end) override;
|
2020-08-17 10:27:14 +00:00
|
|
|
void verticalScrollbarValueChanged(int value) override;
|
2021-04-20 21:56:47 +00:00
|
|
|
void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles) override;
|
2021-05-14 19:49:38 +00:00
|
|
|
void onMessageButtonPushed(const QString& messageId);
|
2021-04-28 20:26:19 +00:00
|
|
|
void onMessageInvalidPath(const QString& messageId);
|
2021-04-30 20:07:00 +00:00
|
|
|
void onModelSyncStateChange(Models::MessageFeed::SyncState state);
|
2020-08-15 21:48:28 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int verticalOffset() const override;
|
|
|
|
int horizontalOffset() const override;
|
|
|
|
void paintEvent(QPaintEvent * event) override;
|
|
|
|
void updateGeometries() override;
|
2021-01-07 21:50:12 +00:00
|
|
|
void mouseMoveEvent(QMouseEvent * event) override;
|
2022-04-27 21:08:59 +00:00
|
|
|
void mousePressEvent(QMouseEvent * event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent * event) override;
|
2021-04-30 20:07:00 +00:00
|
|
|
void resizeEvent(QResizeEvent * event) override;
|
2020-08-15 21:48:28 +00:00
|
|
|
|
2020-08-17 10:27:14 +00:00
|
|
|
private:
|
|
|
|
bool tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* model, uint32_t totalHeight);
|
2021-05-01 23:03:08 +00:00
|
|
|
void positionProgress();
|
2021-09-21 22:17:43 +00:00
|
|
|
void drawDateDevider(int top, const QDateTime& date, QPainter& painter);
|
2022-04-28 21:29:44 +00:00
|
|
|
void setAnchorHovered(bool hovered);
|
2020-08-17 10:27:14 +00:00
|
|
|
|
2020-08-15 21:48:28 +00:00
|
|
|
private:
|
|
|
|
struct Hint {
|
|
|
|
bool dirty;
|
|
|
|
uint32_t offset;
|
|
|
|
uint32_t height;
|
2022-01-09 14:32:23 +00:00
|
|
|
uint32_t width;
|
|
|
|
uint32_t x;
|
2020-08-15 21:48:28 +00:00
|
|
|
};
|
|
|
|
std::deque<Hint> hints;
|
2020-08-17 10:27:14 +00:00
|
|
|
int vo;
|
2022-01-09 14:32:23 +00:00
|
|
|
int elementMargin;
|
2021-02-01 22:55:15 +00:00
|
|
|
bool specialDelegate;
|
2021-02-06 11:02:42 +00:00
|
|
|
bool specialModel;
|
2021-02-01 22:55:15 +00:00
|
|
|
bool clearWidgetsMode;
|
2021-04-30 20:07:00 +00:00
|
|
|
Models::MessageFeed::SyncState modelState;
|
|
|
|
Progress progress;
|
2021-09-21 22:17:43 +00:00
|
|
|
QFont dividerFont;
|
|
|
|
QFontMetrics dividerMetrics;
|
2022-04-27 21:08:59 +00:00
|
|
|
bool mousePressed;
|
2022-05-01 20:19:52 +00:00
|
|
|
bool dragging;
|
2022-04-28 21:29:44 +00:00
|
|
|
bool anchorHovered;
|
2022-05-01 20:19:52 +00:00
|
|
|
QPoint dragStartPoint;
|
|
|
|
QPoint dragEndPoint;
|
2020-08-15 21:48:28 +00:00
|
|
|
|
2021-04-22 22:41:32 +00:00
|
|
|
static const std::set<int> geometryChangingRoles;
|
|
|
|
|
2020-08-15 21:48:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //FEEDVIEW_H
|