Small tweaks

This commit is contained in:
Petr Mrázek 2014-02-02 10:26:38 +01:00
parent 179451d591
commit b2bf50a6d7
4 changed files with 56 additions and 42 deletions

View File

@ -26,17 +26,17 @@ template <typename T> bool listsIntersect(const QList<T> &l1, const QList<T> t2)
} }
GroupView::GroupView(QWidget *parent) GroupView::GroupView(QWidget *parent)
: QListView(parent), m_leftMargin(5), m_rightMargin(5), m_bottomMargin(5), : QAbstractItemView(parent), m_leftMargin(5), m_rightMargin(5), m_bottomMargin(5),
m_categoryMargin(5) //, m_updatesDisabled(false), m_categoryEditor(0), m_editedCategory(0) m_categoryMargin(5) //, m_updatesDisabled(false), m_categoryEditor(0), m_editedCategory(0)
{ {
setViewMode(IconMode); // setViewMode(IconMode);
// setMovement(Snap); // setMovement(Snap);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setWordWrap(true); // setWordWrap(true);
// setDragDropMode(QListView::InternalMove); // setDragDropMode(QListView::InternalMove);
setAcceptDrops(true); setAcceptDrops(true);
setSpacing(10); // setSpacing(10);
} }
GroupView::~GroupView() GroupView::~GroupView()
@ -48,49 +48,26 @@ GroupView::~GroupView()
void GroupView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, void GroupView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
const QVector<int> &roles) const QVector<int> &roles)
{ {
// if (m_updatesDisabled)
// {
// return;
// }
QListView::dataChanged(topLeft, bottomRight, roles);
if (roles.contains(CategorizedViewRoles::CategoryRole) || roles.contains(Qt::DisplayRole)) if (roles.contains(CategorizedViewRoles::CategoryRole) || roles.contains(Qt::DisplayRole))
{ {
updateGeometries(); updateGeometries();
update();
} }
viewport()->update();
} }
void GroupView::rowsInserted(const QModelIndex &parent, int start, int end) void GroupView::rowsInserted(const QModelIndex &parent, int start, int end)
{ {
// if (m_updatesDisabled)
// {
// return;
// }
QListView::rowsInserted(parent, start, end);
updateGeometries(); updateGeometries();
update(); viewport()->update();
} }
void GroupView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) void GroupView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
{ {
// if (m_updatesDisabled)
// {
// return;
// }
QListView::rowsAboutToBeRemoved(parent, start, end);
updateGeometries(); updateGeometries();
update(); viewport()->update();
} }
void GroupView::updateGeometries() void GroupView::updateGeometries()
{ {
QListView::updateGeometries();
int previousScroll = verticalScrollBar()->value(); int previousScroll = verticalScrollBar()->value();
QMap<QString, Group *> cats; QMap<QString, Group *> cats;
@ -145,7 +122,7 @@ void GroupView::updateGeometries()
verticalScrollBar()->setValue(qMin(previousScroll, verticalScrollBar()->maximum())); verticalScrollBar()->setValue(qMin(previousScroll, verticalScrollBar()->maximum()));
update(); viewport()->update();
} }
bool GroupView::isIndexHidden(const QModelIndex &index) const bool GroupView::isIndexHidden(const QModelIndex &index) const
@ -520,7 +497,7 @@ void GroupView::paintEvent(QPaintEvent *event)
void GroupView::resizeEvent(QResizeEvent *event) void GroupView::resizeEvent(QResizeEvent *event)
{ {
QListView::resizeEvent(event); // QListView::resizeEvent(event);
// if (m_categoryEditor) // if (m_categoryEditor)
// { // {

View File

@ -15,7 +15,7 @@ struct CategorizedViewRoles
struct Group; struct Group;
class GroupView : public QListView class GroupView : public QAbstractItemView
{ {
Q_OBJECT Q_OBJECT
@ -28,6 +28,40 @@ public:
void setSelection(const QRect &rect, void setSelection(const QRect &rect,
const QItemSelectionModel::SelectionFlags commands) override; const QItemSelectionModel::SelectionFlags commands) override;
/*
* BS
*/
virtual int horizontalOffset() const override
{
return 0;
}
virtual int verticalOffset() const override
{
return 0;
}
virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override
{
return;
}
virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
override
{
return QModelIndex();
}
virtual QRegion visualRegionForSelection(const QItemSelection &) const override
{
return QRegion();
}
/*
* End of BS
*/
protected protected
slots: slots:
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,

View File

@ -103,7 +103,7 @@ void drawProgressOverlay(QPainter *painter, const QStyleOptionViewItemV4 &option
color.setAlphaF(0.70f); color.setAlphaF(0.70f);
painter->setBrush(color); painter->setBrush(color);
painter->setPen(QPen(QBrush(), 0)); painter->setPen(QPen(QBrush(), 0));
painter->drawPie(option.rect, 90 * 16, -percent * 360 * 60); painter->drawPie(option.rect, 90 * 16, -percent * 360 * 16);
painter->restore(); painter->restore();
} }

19
main.h
View File

@ -30,20 +30,23 @@ public
slots: slots:
void timeout() void timeout()
{ {
QList<QStandardItem *> toRemove;
for (auto item : m_items) for (auto item : m_items)
{ {
int maximum = item->data(CategorizedViewRoles::ProgressMaximumRole).toInt();
int value = item->data(CategorizedViewRoles::ProgressValueRole).toInt(); int value = item->data(CategorizedViewRoles::ProgressValueRole).toInt();
value += qrand() % 3; int newvalue = std::min(value + 3, maximum);
if (value >= item->data(CategorizedViewRoles::ProgressMaximumRole).toInt()) item->setData(newvalue, CategorizedViewRoles::ProgressValueRole);
if(newvalue >= maximum)
{ {
item->setData(item->data(CategorizedViewRoles::ProgressMaximumRole).toInt(), toRemove.append(item);
CategorizedViewRoles::ProgressValueRole);
}
else
{
item->setData(value, CategorizedViewRoles::ProgressValueRole);
} }
} }
for(auto remove : toRemove)
{
m_items.removeAll(remove);
}
} }
private: private: