forked from blue/squawk
some thoughts about fonts, lastInteraction and label into keyDelegate
This commit is contained in:
parent
2aed8a1209
commit
15fb4bbd62
15 changed files with 166 additions and 171 deletions
|
@ -24,6 +24,7 @@
|
|||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDebug>
|
||||
#include <QFontDatabase>
|
||||
|
||||
#include "messagedelegate.h"
|
||||
#include "messagefeed.h"
|
||||
|
@ -40,6 +41,8 @@ const std::set<int> FeedView::geometryChangingRoles = {
|
|||
Models::MessageFeed::Error,
|
||||
Models::MessageFeed::Date
|
||||
};
|
||||
QFont FeedView::dividerFont = QFontDatabase::systemFont(QFontDatabase::TitleFont);
|
||||
QFontMetrics FeedView::dividerMetrics = QFontMetrics(dividerFont);
|
||||
|
||||
FeedView::FeedView(QWidget* parent):
|
||||
QAbstractItemView(parent),
|
||||
|
@ -51,8 +54,6 @@ FeedView::FeedView(QWidget* parent):
|
|||
clearWidgetsMode(false),
|
||||
modelState(Models::MessageFeed::complete),
|
||||
progress(),
|
||||
dividerFont(),
|
||||
dividerMetrics(dividerFont),
|
||||
mousePressed(false),
|
||||
dragging(false),
|
||||
hovered(Shared::Hover::nothing),
|
||||
|
@ -68,23 +69,11 @@ FeedView::FeedView(QWidget* parent):
|
|||
|
||||
progress.setParent(viewport());
|
||||
progress.resize(progressSize, progressSize);
|
||||
|
||||
dividerFont = getFont();
|
||||
dividerFont.setBold(true);
|
||||
float ndps = dividerFont.pointSizeF();
|
||||
if (ndps != -1) {
|
||||
dividerFont.setPointSizeF(ndps * 1.2);
|
||||
} else {
|
||||
dividerFont.setPointSize(dividerFont.pointSize() + 2);
|
||||
}
|
||||
}
|
||||
|
||||
FeedView::~FeedView()
|
||||
{
|
||||
}
|
||||
FeedView::~FeedView() {}
|
||||
|
||||
QModelIndex FeedView::indexAt(const QPoint& point) const
|
||||
{
|
||||
QModelIndex FeedView::indexAt(const QPoint& point) const {
|
||||
int32_t vh = viewport()->height();
|
||||
uint32_t y = vh - point.y() + vo;
|
||||
|
||||
|
@ -102,12 +91,8 @@ QModelIndex FeedView::indexAt(const QPoint& point) const
|
|||
return QModelIndex();
|
||||
}
|
||||
|
||||
void FeedView::scrollTo(const QModelIndex& index, QAbstractItemView::ScrollHint hint)
|
||||
{
|
||||
}
|
||||
|
||||
QRect FeedView::visualRect(const QModelIndex& index) const
|
||||
{
|
||||
QRect FeedView::visualRect(const QModelIndex& index) const {
|
||||
unsigned int row = index.row();
|
||||
if (!index.isValid() || row >= hints.size()) {
|
||||
qDebug() << "visualRect for" << row;
|
||||
|
@ -119,44 +104,24 @@ QRect FeedView::visualRect(const QModelIndex& index) const
|
|||
}
|
||||
}
|
||||
|
||||
int FeedView::horizontalOffset() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
QString FeedView::getSelectedText() const{return selectedText;}
|
||||
|
||||
bool FeedView::isIndexHidden(const QModelIndex& index) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//TODO!!!
|
||||
void FeedView::scrollTo(const QModelIndex& index, QAbstractItemView::ScrollHint hint) {}
|
||||
int FeedView::horizontalOffset() const {return 0;}
|
||||
bool FeedView::isIndexHidden(const QModelIndex& index) const{return false;}
|
||||
QModelIndex FeedView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) {return QModelIndex();}
|
||||
void FeedView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command) {}
|
||||
int FeedView::verticalOffset() const {return vo;}
|
||||
QRegion FeedView::visualRegionForSelection(const QItemSelection& selection) const {return QRegion();}
|
||||
|
||||
QModelIndex FeedView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
|
||||
{
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
void FeedView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command)
|
||||
{
|
||||
}
|
||||
|
||||
int FeedView::verticalOffset() const
|
||||
{
|
||||
return vo;
|
||||
}
|
||||
|
||||
QRegion FeedView::visualRegionForSelection(const QItemSelection& selection) const
|
||||
{
|
||||
return QRegion();
|
||||
}
|
||||
|
||||
void FeedView::rowsInserted(const QModelIndex& parent, int start, int end)
|
||||
{
|
||||
void FeedView::rowsInserted(const QModelIndex& parent, int start, int end){
|
||||
QAbstractItemView::rowsInserted(parent, start, end);
|
||||
|
||||
scheduleDelayedItemsLayout();
|
||||
}
|
||||
|
||||
void FeedView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
|
||||
{
|
||||
void FeedView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles) {
|
||||
if (specialDelegate) {
|
||||
for (int role : roles) {
|
||||
if (geometryChangingRoles.count(role) != 0) {
|
||||
|
@ -168,8 +133,7 @@ void FeedView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottom
|
|||
QAbstractItemView::dataChanged(topLeft, bottomRight, roles);
|
||||
}
|
||||
|
||||
void FeedView::updateGeometries()
|
||||
{
|
||||
void FeedView::updateGeometries() {
|
||||
//qDebug() << "updateGeometries";
|
||||
QScrollBar* bar = verticalScrollBar();
|
||||
|
||||
|
@ -260,8 +224,7 @@ void FeedView::updateGeometries()
|
|||
QAbstractItemView::updateGeometries();
|
||||
}
|
||||
|
||||
bool FeedView::tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* m, uint32_t totalHeight)
|
||||
{
|
||||
bool FeedView::tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* m, uint32_t totalHeight) {
|
||||
uint32_t previousOffset = elementMargin;
|
||||
QDateTime lastDate;
|
||||
for (int i = 0, size = m->rowCount(); i < size; ++i) {
|
||||
|
@ -307,9 +270,7 @@ bool FeedView::tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewIt
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
void FeedView::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
void FeedView::paintEvent(QPaintEvent* event) {
|
||||
//qDebug() << "paint" << event->rect();
|
||||
const QAbstractItemModel* m = model();
|
||||
QWidget* vp = viewport();
|
||||
|
@ -388,8 +349,7 @@ void FeedView::paintEvent(QPaintEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void FeedView::drawDateDevider(int top, const QDateTime& date, QPainter& painter)
|
||||
{
|
||||
void FeedView::drawDateDevider(int top, const QDateTime& date, QPainter& painter) {
|
||||
int divisionHeight = dateDeviderMargin * 2 + dividerMetrics.height();
|
||||
QRect r(QPoint(0, top), QSize(viewport()->width(), divisionHeight));
|
||||
painter.save();
|
||||
|
@ -398,8 +358,7 @@ void FeedView::drawDateDevider(int top, const QDateTime& date, QPainter& painter
|
|||
painter.restore();
|
||||
}
|
||||
|
||||
void FeedView::verticalScrollbarValueChanged(int value)
|
||||
{
|
||||
void FeedView::verticalScrollbarValueChanged(int value) {
|
||||
vo = verticalScrollBar()->maximum() - value;
|
||||
|
||||
positionProgress();
|
||||
|
@ -415,8 +374,7 @@ void FeedView::verticalScrollbarValueChanged(int value)
|
|||
QAbstractItemView::verticalScrollbarValueChanged(vo);
|
||||
}
|
||||
|
||||
void FeedView::setAnchorHovered(Shared::Hover type)
|
||||
{
|
||||
void FeedView::setAnchorHovered(Shared::Hover type) {
|
||||
if (hovered != type) {
|
||||
hovered = type;
|
||||
switch (hovered) {
|
||||
|
@ -433,8 +391,7 @@ void FeedView::setAnchorHovered(Shared::Hover type)
|
|||
}
|
||||
}
|
||||
|
||||
void FeedView::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
void FeedView::mouseMoveEvent(QMouseEvent* event) {
|
||||
if (!isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
@ -479,8 +436,7 @@ void FeedView::mouseMoveEvent(QMouseEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void FeedView::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
void FeedView::mousePressEvent(QMouseEvent* event) {
|
||||
QAbstractItemView::mousePressEvent(event);
|
||||
|
||||
mousePressed = event->button() == Qt::LeftButton;
|
||||
|
@ -500,8 +456,7 @@ void FeedView::mousePressEvent(QMouseEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void FeedView::mouseDoubleClickEvent(QMouseEvent* event)
|
||||
{
|
||||
void FeedView::mouseDoubleClickEvent(QMouseEvent* event) {
|
||||
QAbstractItemView::mouseDoubleClickEvent(event);
|
||||
mousePressed = event->button() == Qt::LeftButton;
|
||||
if (mousePressed) {
|
||||
|
@ -530,8 +485,7 @@ void FeedView::mouseDoubleClickEvent(QMouseEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void FeedView::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
void FeedView::mouseReleaseEvent(QMouseEvent* event) {
|
||||
QAbstractItemView::mouseReleaseEvent(event);
|
||||
|
||||
if (mousePressed) {
|
||||
|
@ -551,8 +505,7 @@ void FeedView::mouseReleaseEvent(QMouseEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void FeedView::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
void FeedView::keyPressEvent(QKeyEvent* event) {
|
||||
QKeyEvent *key_event = static_cast<QKeyEvent*>(event);
|
||||
if (key_event->matches(QKeySequence::Copy)) {
|
||||
if (selectedText.size() > 0) {
|
||||
|
@ -562,16 +515,14 @@ void FeedView::keyPressEvent(QKeyEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void FeedView::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
void FeedView::resizeEvent(QResizeEvent* event) {
|
||||
QAbstractItemView::resizeEvent(event);
|
||||
|
||||
positionProgress();
|
||||
emit resized();
|
||||
}
|
||||
|
||||
void FeedView::positionProgress()
|
||||
{
|
||||
void FeedView::positionProgress() {
|
||||
QSize layoutBounds = maximumViewportSize();
|
||||
int progressPosition = layoutBounds.height() - progressSize;
|
||||
std::deque<Hint>::size_type size = hints.size();
|
||||
|
@ -585,13 +536,7 @@ void FeedView::positionProgress()
|
|||
progress.move((width() - progressSize) / 2, progressPosition);
|
||||
}
|
||||
|
||||
QFont FeedView::getFont() const
|
||||
{
|
||||
return viewOptions().font;
|
||||
}
|
||||
|
||||
void FeedView::setItemDelegate(QAbstractItemDelegate* delegate)
|
||||
{
|
||||
void FeedView::setItemDelegate(QAbstractItemDelegate* delegate) {
|
||||
if (specialDelegate) {
|
||||
MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate());
|
||||
disconnect(del, &MessageDelegate::buttonPushed, this, &FeedView::onMessageButtonPushed);
|
||||
|
@ -613,8 +558,7 @@ void FeedView::setItemDelegate(QAbstractItemDelegate* delegate)
|
|||
}
|
||||
}
|
||||
|
||||
void FeedView::setModel(QAbstractItemModel* p_model)
|
||||
{
|
||||
void FeedView::setModel(QAbstractItemModel* p_model) {
|
||||
if (specialModel) {
|
||||
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
||||
disconnect(feed, &Models::MessageFeed::syncStateChange, this, &FeedView::onModelSyncStateChange);
|
||||
|
@ -633,24 +577,21 @@ void FeedView::setModel(QAbstractItemModel* p_model)
|
|||
}
|
||||
}
|
||||
|
||||
void FeedView::onMessageButtonPushed(const QString& messageId)
|
||||
{
|
||||
void FeedView::onMessageButtonPushed(const QString& messageId) {
|
||||
if (specialModel) {
|
||||
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
||||
feed->downloadAttachment(messageId);
|
||||
}
|
||||
}
|
||||
|
||||
void FeedView::onMessageInvalidPath(const QString& messageId)
|
||||
{
|
||||
void FeedView::onMessageInvalidPath(const QString& messageId) {
|
||||
if (specialModel) {
|
||||
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
||||
feed->reportLocalPathInvalid(messageId);
|
||||
}
|
||||
}
|
||||
|
||||
void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state)
|
||||
{
|
||||
void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state) {
|
||||
bool needToUpdateGeometry = false;
|
||||
if (modelState != state) {
|
||||
if (state == Models::MessageFeed::complete || modelState == Models::MessageFeed::complete) {
|
||||
|
@ -671,8 +612,3 @@ void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state)
|
|||
scheduleDelayedItemsLayout();
|
||||
}
|
||||
}
|
||||
|
||||
QString FeedView::getSelectedText() const
|
||||
{
|
||||
return selectedText;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue