summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-02-04 00:40:10 +0100
committerPetr Mrázek <peterix@gmail.com>2014-02-04 00:40:10 +0100
commit946d49675cb4725c31ab49a51f3bcae302f89a19 (patch)
tree8b1ffe190cbd75d2e8940b69d1413f755dfbea2e
parentddedd077b66f2bf45cd157d760eebdad15bcb289 (diff)
downloadMultiMC-946d49675cb4725c31ab49a51f3bcae302f89a19.tar
MultiMC-946d49675cb4725c31ab49a51f3bcae302f89a19.tar.gz
MultiMC-946d49675cb4725c31ab49a51f3bcae302f89a19.tar.lz
MultiMC-946d49675cb4725c31ab49a51f3bcae302f89a19.tar.xz
MultiMC-946d49675cb4725c31ab49a51f3bcae302f89a19.zip
Swap things around -- rename refactors, moving towards non-derpy design. Maybe.
-rw-r--r--Group.cpp16
-rw-r--r--Group.h25
-rw-r--r--GroupView.cpp68
-rw-r--r--GroupView.h25
-rw-r--r--GroupedProxyModel.cpp4
-rw-r--r--InstanceDelegate.cpp4
-rw-r--r--main.cpp4
-rw-r--r--main.h8
8 files changed, 88 insertions, 66 deletions
diff --git a/Group.cpp b/Group.cpp
index c92132ca..f216cc6e 100644
--- a/Group.cpp
+++ b/Group.cpp
@@ -17,20 +17,20 @@ Group::Group(const Group *other)
void Group::update()
{
- firstRow = firstItem().row();
+ firstItemIndex = firstItem().row();
rowHeights = QVector<int>(numRows());
for (int i = 0; i < numRows(); ++i)
{
rowHeights[i] = view->categoryRowHeight(
- view->model()->index(i * view->itemsPerRow() + firstRow, 0));
+ view->model()->index(i * view->itemsPerRow() + firstItemIndex, 0));
}
}
-Group::HitResults Group::pointIntersect(const QPoint &pos) const
+Group::HitResults Group::hitScan(const QPoint &pos) const
{
Group::HitResults results = Group::NoHit;
- int y_start = top();
+ int y_start = verticalPosition();
int body_start = y_start + headerHeight();
int body_end = body_start + contentHeight() + 5; // FIXME: wtf is this 5?
int y = pos.y();
@@ -95,7 +95,7 @@ void Group::drawHeader(QPainter *painter, const int y)
int Group::totalHeight() const
{
- return headerHeight() + 5 + contentHeight();
+ return headerHeight() + 5 + contentHeight(); // FIXME: wtf is that '5'?
}
int Group::headerHeight() const
@@ -122,10 +122,10 @@ int Group::numRows() const
return qMax(1, qCeil((qreal)numItems() / (qreal)view->itemsPerRow()));
}
-int Group::top() const
+int Group::verticalPosition() const
{
int res = 0;
- const QList<Group *> cats = view->m_categories;
+ const QList<Group *> cats = view->m_groups;
for (int i = 0; i < cats.size(); ++i)
{
if (cats.at(i) == this)
@@ -143,7 +143,7 @@ QList<QModelIndex> Group::items() const
for (int i = 0; i < view->model()->rowCount(); ++i)
{
const QModelIndex index = view->model()->index(i, 0);
- if (index.data(CategorizedViewRoles::CategoryRole).toString() == text)
+ if (index.data(GroupViewRoles::GroupRole).toString() == text)
{
indices.append(index);
}
diff --git a/Group.h b/Group.h
index 51e0470d..455ee1a8 100644
--- a/Group.h
+++ b/Group.h
@@ -10,22 +10,38 @@ class QModelIndex;
struct Group
{
+/* constructors */
Group(const QString &text, GroupView *view);
Group(const Group *other);
+
+/* data */
GroupView *view;
QString text;
bool collapsed;
QVector<int> rowHeights;
- int firstRow;
+ int firstItemIndex;
+/* logic */
+ /// do stuff. and things. TODO: redo.
void update();
+ /// draw the header at y-position.
void drawHeader(QPainter *painter, const int y);
+
+ /// height of the group, in total. includes a small bit of padding.
int totalHeight() const;
+
+ /// height of the group header, in pixels
int headerHeight() const;
+
+ /// height of the group content, in pixels
int contentHeight() const;
+
+ /// the number of visual rows this group has
int numRows() const;
- int top() const;
+
+ /// the height at which this group starts, in pixels
+ int verticalPosition() const;
enum HitResult
{
@@ -37,9 +53,12 @@ struct Group
};
Q_DECLARE_FLAGS(HitResults, HitResult)
- HitResults pointIntersect (const QPoint &pos) const;
+ /// shoot! BANG! what did we hit?
+ HitResults hitScan (const QPoint &pos) const;
+ /// super derpy thing.
QList<QModelIndex> items() const;
+ /// I don't even
int numItems() const;
QModelIndex firstItem() const;
QModelIndex lastItem() const;
diff --git a/GroupView.cpp b/GroupView.cpp
index 3296ccfb..89e3e223 100644
--- a/GroupView.cpp
+++ b/GroupView.cpp
@@ -41,14 +41,14 @@ GroupView::GroupView(QWidget *parent)
GroupView::~GroupView()
{
- qDeleteAll(m_categories);
- m_categories.clear();
+ qDeleteAll(m_groups);
+ m_groups.clear();
}
void GroupView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
const QVector<int> &roles)
{
- if (roles.contains(CategorizedViewRoles::CategoryRole) || roles.contains(Qt::DisplayRole))
+ if (roles.contains(GroupViewRoles::GroupRole) || roles.contains(Qt::DisplayRole))
{
updateGeometries();
}
@@ -74,18 +74,18 @@ void GroupView::updateGeometries()
for (int i = 0; i < model()->rowCount(); ++i)
{
- const QString category =
- model()->index(i, 0).data(CategorizedViewRoles::CategoryRole).toString();
- if (!cats.contains(category))
+ const QString groupName =
+ model()->index(i, 0).data(GroupViewRoles::GroupRole).toString();
+ if (!cats.contains(groupName))
{
- Group *old = this->category(category);
+ Group *old = this->category(groupName);
if (old)
{
- cats.insert(category, new Group(old));
+ cats.insert(groupName, new Group(old));
}
else
{
- cats.insert(category, new Group(category, this));
+ cats.insert(groupName, new Group(groupName, this));
}
}
}
@@ -95,22 +95,22 @@ void GroupView::updateGeometries()
m_editedCategory = cats[m_editedCategory->text];
}*/
- qDeleteAll(m_categories);
- m_categories = cats.values();
+ qDeleteAll(m_groups);
+ m_groups = cats.values();
- for (auto cat : m_categories)
+ for (auto cat : m_groups)
{
cat->update();
}
- if (m_categories.isEmpty())
+ if (m_groups.isEmpty())
{
verticalScrollBar()->setRange(0, 0);
}
else
{
int totalHeight = 0;
- for (auto category : m_categories)
+ for (auto category : m_groups)
{
totalHeight += category->totalHeight() + m_categoryMargin;
}
@@ -140,12 +140,12 @@ bool GroupView::isIndexHidden(const QModelIndex &index) const
Group *GroupView::category(const QModelIndex &index) const
{
- return category(index.data(CategorizedViewRoles::CategoryRole).toString());
+ return category(index.data(GroupViewRoles::GroupRole).toString());
}
Group *GroupView::category(const QString &cat) const
{
- for (auto group : m_categories)
+ for (auto group : m_groups)
{
if (group->text == cat)
{
@@ -157,9 +157,9 @@ Group *GroupView::category(const QString &cat) const
Group *GroupView::categoryAt(const QPoint &pos) const
{
- for (auto group : m_categories)
+ for (auto group : m_groups)
{
- if(group->pointIntersect(pos) & Group::CheckboxHit)
+ if(group->hitScan(pos) & Group::CheckboxHit)
{
return group;
}
@@ -420,9 +420,9 @@ void GroupView::paintEvent(QPaintEvent *event)
QPainter painter(this->viewport());
int y = -verticalOffset();
- for (int i = 0; i < m_categories.size(); ++i)
+ for (int i = 0; i < m_groups.size(); ++i)
{
- Group *category = m_categories.at(i);
+ Group *category = m_groups.at(i);
category->drawHeader(&painter, y);
y += category->totalHeight() + m_categoryMargin;
}
@@ -457,6 +457,10 @@ void GroupView::paintEvent(QPaintEvent *event)
itemDelegate()->paint(&painter, option, index);
}
+ /*
+ * Drop indicators for manual reordering...
+ */
+#if 0
if (!m_lastDragPosition.isNull())
{
QPair<Group *, int> pair = rowDropPos(m_lastDragPosition);
@@ -464,7 +468,7 @@ void GroupView::paintEvent(QPaintEvent *event)
int row = pair.second;
if (category)
{
- int internalRow = row - category->firstRow;
+ int internalRow = row - category->firstItemIndex;
QLine line;
if (internalRow >= category->numItems())
{
@@ -482,6 +486,7 @@ void GroupView::paintEvent(QPaintEvent *event)
painter.restore();
}
}
+#endif
}
void GroupView::resizeEvent(QResizeEvent *event)
@@ -552,7 +557,7 @@ void GroupView::dropEvent(QDropEvent *event)
if (model()->dropMimeData(event->mimeData(), Qt::MoveAction, row, 0, QModelIndex()))
{
model()->setData(model()->index(row, 0), categoryText,
- CategorizedViewRoles::CategoryRole);
+ GroupViewRoles::GroupRole);
event->setDropAction(Qt::MoveAction);
event->accept();
}
@@ -624,7 +629,7 @@ QRect GroupView::geometryRect(const QModelIndex &index) const
// int y = pos.second;
QRect out;
- out.setTop(cat->top() + cat->headerHeight() + 5 + categoryInternalRowTop(index));
+ out.setTop(cat->verticalPosition() + cat->headerHeight() + 5 + categoryInternalRowTop(index));
out.setLeft(m_spacing + x * (itemWidth() + m_spacing));
out.setSize(itemDelegate()->sizeHint(viewOptions(), index));
@@ -717,7 +722,6 @@ QPixmap GroupView::renderToPixmap(const QModelIndexList &indices, QRect *r) cons
option.rect = paintPairs.at(j).first.translated(-r->topLeft());
const QModelIndex &current = paintPairs.at(j).second;
itemDelegate()->paint(&painter, option, current);
- painter.drawLine(0,0, r->width(), r->height());
}
return pixmap;
}
@@ -762,7 +766,7 @@ QPair<Group *, int> GroupView::rowDropPos(const QPoint &pos)
Group *category = 0;
{
int y = 0;
- for (auto cat : m_categories)
+ for (auto cat : m_groups)
{
if (pos.y() > y && pos.y() < (y + cat->headerHeight()))
{
@@ -812,7 +816,7 @@ QPair<Group *, int> GroupView::rowDropPos(const QPoint &pos)
int internalRow = -1;
{
// FIXME rework the drag and drop code
- const int top = category->top();
+ const int top = category->verticalPosition();
for (int r = 0, h = top; r < category->numRows();
h += itemHeightForCategoryRow(category, r), ++r)
{
@@ -882,19 +886,19 @@ QModelIndex GroupView::moveCursor(QAbstractItemView::CursorAction cursorAction,
}
qDebug() << "model row: " << current.row();
auto cat = category(current);
- int i = m_categories.indexOf(cat);
+ int i = m_groups.indexOf(cat);
if(i >= 0)
{
// this is a pile of something foul
- auto real_cat = m_categories[i];
+ auto real_group = m_groups[i];
int beginning_row = 0;
- for(auto catt: m_categories)
+ for(auto group: m_groups)
{
- if(catt == real_cat)
+ if(group == real_group)
break;
- beginning_row += catt->numRows();
+ beginning_row += group->numRows();
}
- qDebug() << "category: " << real_cat->text;
+ qDebug() << "category: " << real_group->text;
QPair<int, int> pos = categoryInternalPosition(current);
int row = beginning_row + pos.second;
qDebug() << "row: " << row;
diff --git a/GroupView.h b/GroupView.h
index a7ed8e9d..329a3503 100644
--- a/GroupView.h
+++ b/GroupView.h
@@ -4,11 +4,11 @@
#include <QLineEdit>
#include <QScrollBar>
-struct CategorizedViewRoles
+struct GroupViewRoles
{
enum
{
- CategoryRole = Qt::UserRole,
+ GroupRole = Qt::UserRole,
ProgressValueRole,
ProgressMaximumRole
};
@@ -24,7 +24,7 @@ public:
GroupView(QWidget *parent = 0);
~GroupView();
- virtual QRect geometryRect(const QModelIndex &index) const;
+ QRect geometryRect(const QModelIndex &index) const;
virtual QRect visualRect(const QModelIndex &index) const override;
QModelIndex indexAt(const QPoint &point) const;
void setSelection(const QRect &rect,
@@ -54,22 +54,21 @@ public:
return;
}
- virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
- override;
+ virtual QModelIndex moveCursor(CursorAction cursorAction,
+ Qt::KeyboardModifiers modifiers) override;
virtual QRegion visualRegionForSelection(const QItemSelection &selection) const override;
-
protected
slots:
- void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
- const QVector<int> &roles);
- virtual void rowsInserted(const QModelIndex &parent, int start, int end);
- virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
- virtual void updateGeometries();
+ virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
+ const QVector<int> &roles) override;
+ virtual void rowsInserted(const QModelIndex &parent, int start, int end) override;
+ virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
+ virtual void updateGeometries() override;
protected:
- virtual bool isIndexHidden(const QModelIndex &index) const;
+ virtual bool isIndexHidden(const QModelIndex &index) const override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
@@ -87,7 +86,7 @@ protected:
private:
friend struct Group;
- QList<Group *> m_categories;
+ QList<Group *> m_groups;
int m_leftMargin;
int m_rightMargin;
diff --git a/GroupedProxyModel.cpp b/GroupedProxyModel.cpp
index ab00a412..57d7ff5c 100644
--- a/GroupedProxyModel.cpp
+++ b/GroupedProxyModel.cpp
@@ -8,8 +8,8 @@ GroupedProxyModel::GroupedProxyModel(QObject *parent) : QSortFilterProxyModel(pa
bool GroupedProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
- const QString leftCategory = left.data(CategorizedViewRoles::CategoryRole).toString();
- const QString rightCategory = right.data(CategorizedViewRoles::CategoryRole).toString();
+ const QString leftCategory = left.data(GroupViewRoles::GroupRole).toString();
+ const QString rightCategory = right.data(GroupViewRoles::GroupRole).toString();
if (leftCategory == rightCategory)
{
return left.row() < right.row();
diff --git a/InstanceDelegate.cpp b/InstanceDelegate.cpp
index 944cfd76..8527e2bc 100644
--- a/InstanceDelegate.cpp
+++ b/InstanceDelegate.cpp
@@ -253,8 +253,8 @@ void ListViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
}
drawProgressOverlay(painter, opt,
- index.data(CategorizedViewRoles::ProgressValueRole).toInt(),
- index.data(CategorizedViewRoles::ProgressMaximumRole).toInt());
+ index.data(GroupViewRoles::ProgressValueRole).toInt(),
+ index.data(GroupViewRoles::ProgressMaximumRole).toInt());
painter->restore();
}
diff --git a/main.cpp b/main.cpp
index b9ecde8f..df14e3bd 100644
--- a/main.cpp
+++ b/main.cpp
@@ -36,7 +36,7 @@ QStandardItem *createItem(const Qt::GlobalColor color, const QString &text,
QStandardItem *item = new QStandardItem;
item->setText(text);
item->setData(icon(color), Qt::DecorationRole);
- item->setData(category, CategorizedViewRoles::CategoryRole);
+ item->setData(category, GroupViewRoles::GroupRole);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
// progresser->addTrackedIndex(item);
return item;
@@ -46,7 +46,7 @@ QStandardItem *createItem(const int index, const QString &category)
QStandardItem *item = new QStandardItem;
item->setText(QString("Item #%1").arg(index));
item->setData(icon(index), Qt::DecorationRole);
- item->setData(category, CategorizedViewRoles::CategoryRole);
+ item->setData(category, GroupViewRoles::GroupRole);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
// progresser->addTrackedIndex(item);
return item;
diff --git a/main.h b/main.h
index 6883e98e..2a358329 100644
--- a/main.h
+++ b/main.h
@@ -21,7 +21,7 @@ public:
QStandardItem *addTrackedIndex(QStandardItem *item)
{
- item->setData(1000, CategorizedViewRoles::ProgressMaximumRole);
+ item->setData(1000, GroupViewRoles::ProgressMaximumRole);
m_items.append(item);
return item;
}
@@ -33,10 +33,10 @@ slots:
QList<QStandardItem *> toRemove;
for (auto item : m_items)
{
- int maximum = item->data(CategorizedViewRoles::ProgressMaximumRole).toInt();
- int value = item->data(CategorizedViewRoles::ProgressValueRole).toInt();
+ int maximum = item->data(GroupViewRoles::ProgressMaximumRole).toInt();
+ int value = item->data(GroupViewRoles::ProgressValueRole).toInt();
int newvalue = std::min(value + 3, maximum);
- item->setData(newvalue, CategorizedViewRoles::ProgressValueRole);
+ item->setData(newvalue, GroupViewRoles::ProgressValueRole);
if(newvalue >= maximum)
{