summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-02-09 20:45:18 +0100
committerPetr Mrázek <peterix@gmail.com>2014-02-09 20:45:18 +0100
commit18f532b0d7d873280ec17218196db15fa64175a2 (patch)
tree8bd80c7c1db58e7c5eb353169440e65208f71830 /gui
parent0d30a2655ffb767488d50a4a79978b3d9ddb3aa9 (diff)
downloadMultiMC-18f532b0d7d873280ec17218196db15fa64175a2.tar
MultiMC-18f532b0d7d873280ec17218196db15fa64175a2.tar.gz
MultiMC-18f532b0d7d873280ec17218196db15fa64175a2.tar.lz
MultiMC-18f532b0d7d873280ec17218196db15fa64175a2.tar.xz
MultiMC-18f532b0d7d873280ec17218196db15fa64175a2.zip
Visual and scroll behavior changes to groupview
Scroll by rows, not pixels. Paint the checkboxy thing again! Make0 it behave. Set the group header height properly.
Diffstat (limited to 'gui')
-rw-r--r--gui/groupview/Group.cpp259
-rw-r--r--gui/groupview/GroupView.cpp6
2 files changed, 135 insertions, 130 deletions
diff --git a/gui/groupview/Group.cpp b/gui/groupview/Group.cpp
index f3319dc3..51aa6658 100644
--- a/gui/groupview/Group.cpp
+++ b/gui/groupview/Group.cpp
@@ -61,143 +61,133 @@ Group::HitResults Group::hitScan(const QPoint &pos) const
void Group::drawHeader(QPainter *painter, const QStyleOptionViewItem &option)
{
- /*
- QStyleOptionViewItemV4 opt = option;
- painter->save();
-
- static const int margin = 2;
- static const int spacing = 10;
- int height = headerHeight();
- int text_height = height - 2 * margin;
-
- // set the text colors
- QPalette::ColorGroup cg = QPalette::Normal;
- painter->setPen(opt.palette.color(cg, QPalette::Text));
-
- // set up geometry
- QRect iconRect = QRect(view->m_leftMargin + margin, y + margin, text_height - 1, text_height - 1);
- QRect iconSubrect = iconRect.adjusted(margin, margin, -margin, -margin);
- QRect smallRect = iconSubrect.adjusted(margin, margin, -margin, -margin);
- int midX = iconSubrect.center().x();
- int midY = iconSubrect.center().y();
-
- // checkboxy thingy
+ painter->setRenderHint(QPainter::Antialiasing);
+
+ const QRect optRect = option.rect;
+ QFont font(QApplication::font());
+ font.setBold(true);
+ const QFontMetrics fontMetrics = QFontMetrics(font);
+
+ QColor outlineColor = option.palette.text().color();
+ outlineColor.setAlphaF(0.35);
+
+ //BEGIN: top left corner
{
- painter->drawRect(iconSubrect);
+ painter->save();
+ painter->setPen(outlineColor);
+ const QPointF topLeft(optRect.topLeft());
+ QRectF arc(topLeft, QSizeF(4, 4));
+ arc.translate(0.5, 0.5);
+ painter->drawArc(arc, 1440, 1440);
+ painter->restore();
+ }
+ //END: top left corner
- painter->setBrush(opt.palette.text());
- painter->drawRect(smallRect.x(), midY, smallRect.width(), 2);
- if(collapsed)
- {
- painter->drawRect(midX, smallRect.y(), 2, smallRect.height());
- }
+ //BEGIN: left vertical line
+ {
+ QPoint start(optRect.topLeft());
+ start.ry() += 3;
+ QPoint verticalGradBottom(optRect.topLeft());
+ verticalGradBottom.ry() += fontMetrics.height() + 5;
+ QLinearGradient gradient(start, verticalGradBottom);
+ gradient.setColorAt(0, outlineColor);
+ gradient.setColorAt(1, Qt::transparent);
+ painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient);
}
+ //END: left vertical line
- int x_left = iconRect.right();
+ //BEGIN: horizontal line
+ {
+ QPoint start(optRect.topLeft());
+ start.rx() += 3;
+ QPoint horizontalGradTop(optRect.topLeft());
+ horizontalGradTop.rx() += optRect.width() - 6;
+ painter->fillRect(QRect(start, QSize(optRect.width() - 6, 1)), outlineColor);
+ }
+ //END: horizontal line
- if(text.length())
+ //BEGIN: top right corner
{
- // the text
- int text_width = painter->fontMetrics().width(text);
- QRect textRect = QRect(x_left + spacing, y + margin, text_width, text_height);
- x_left = textRect.right();
- view->style()->drawItemText(painter, textRect, Qt::AlignHCenter | Qt::AlignVCenter,
- opt.palette, true, text);
+ painter->save();
+ painter->setPen(outlineColor);
+ QPointF topRight(optRect.topRight());
+ topRight.rx() -= 4;
+ QRectF arc(topRight, QSizeF(4, 4));
+ arc.translate(0.5, 0.5);
+ painter->drawArc(arc, 0, 1440);
+ painter->restore();
}
- // the line
- painter->drawLine(x_left + spacing, midY + 1, view->contentWidth() - view->m_rightMargin,
- midY + 1);
+ //END: top right corner
- painter->restore();
- */
- painter->setRenderHint(QPainter::Antialiasing);
+ //BEGIN: right vertical line
+ {
+ QPoint start(optRect.topRight());
+ start.ry() += 3;
+ QPoint verticalGradBottom(optRect.topRight());
+ verticalGradBottom.ry() += fontMetrics.height() + 5;
+ QLinearGradient gradient(start, verticalGradBottom);
+ gradient.setColorAt(0, outlineColor);
+ gradient.setColorAt(1, Qt::transparent);
+ painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient);
+ }
+ //END: right vertical line
- const QRect optRect = option.rect;
- QFont font(QApplication::font());
- font.setBold(true);
- const QFontMetrics fontMetrics = QFontMetrics(font);
-
- QColor outlineColor = option.palette.text().color();
- outlineColor.setAlphaF(0.35);
-
- //BEGIN: top left corner
- {
- painter->save();
- painter->setPen(outlineColor);
- const QPointF topLeft(optRect.topLeft());
- QRectF arc(topLeft, QSizeF(4, 4));
- arc.translate(0.5, 0.5);
- painter->drawArc(arc, 1440, 1440);
- painter->restore();
- }
- //END: top left corner
-
- //BEGIN: left vertical line
- {
- QPoint start(optRect.topLeft());
- start.ry() += 3;
- QPoint verticalGradBottom(optRect.topLeft());
- verticalGradBottom.ry() += fontMetrics.height() + 5;
- QLinearGradient gradient(start, verticalGradBottom);
- gradient.setColorAt(0, outlineColor);
- gradient.setColorAt(1, Qt::transparent);
- painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient);
- }
- //END: left vertical line
-
- //BEGIN: horizontal line
- {
- QPoint start(optRect.topLeft());
- start.rx() += 3;
- QPoint horizontalGradTop(optRect.topLeft());
- horizontalGradTop.rx() += optRect.width() - 6;
- painter->fillRect(QRect(start, QSize(optRect.width() - 6, 1)), outlineColor);
- }
- //END: horizontal line
-
- //BEGIN: top right corner
- {
- painter->save();
- painter->setPen(outlineColor);
- QPointF topRight(optRect.topRight());
- topRight.rx() -= 4;
- QRectF arc(topRight, QSizeF(4, 4));
- arc.translate(0.5, 0.5);
- painter->drawArc(arc, 0, 1440);
- painter->restore();
- }
- //END: top right corner
-
- //BEGIN: right vertical line
- {
- QPoint start(optRect.topRight());
- start.ry() += 3;
- QPoint verticalGradBottom(optRect.topRight());
- verticalGradBottom.ry() += fontMetrics.height() + 5;
- QLinearGradient gradient(start, verticalGradBottom);
- gradient.setColorAt(0, outlineColor);
- gradient.setColorAt(1, Qt::transparent);
- painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient);
- }
- //END: right vertical line
-
- //BEGIN: text
- {
- QRect textRect(option.rect);
- textRect.setTop(textRect.top() + 7);
- textRect.setLeft(textRect.left() + 7);
- textRect.setHeight(fontMetrics.height());
- textRect.setRight(textRect.right() - 7);
-
- painter->save();
- painter->setFont(font);
- QColor penColor(option.palette.text().color());
- penColor.setAlphaF(0.6);
- painter->setPen(penColor);
- painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text);
- painter->restore();
- }
- //END: text
+ //BEGIN: checkboxy thing
+ {
+ painter->save();
+ painter->setRenderHint(QPainter::Antialiasing, false);
+ painter->setFont(font);
+ QColor penColor(option.palette.text().color());
+ penColor.setAlphaF(0.6);
+ painter->setPen(penColor);
+ QRect iconSubRect(option.rect);
+ iconSubRect.setTop(iconSubRect.top() + 7);
+ iconSubRect.setLeft(iconSubRect.left() + 7);
+
+ int sizing = fontMetrics.height();
+ int even = ( (sizing - 1) % 2 );
+
+ iconSubRect.setHeight(sizing - even);
+ iconSubRect.setWidth(sizing - even);
+ painter->drawRect(iconSubRect);
+
+
+ /*
+ if(collapsed)
+ painter->drawText(iconSubRect, Qt::AlignHCenter | Qt::AlignVCenter, "+");
+ else
+ painter->drawText(iconSubRect, Qt::AlignHCenter | Qt::AlignVCenter, "-");
+ */
+ painter->setBrush(option.palette.text());
+ painter->fillRect(iconSubRect.x(), iconSubRect.y() + iconSubRect.height() / 2,
+ iconSubRect.width(), 2, penColor);
+ if (collapsed)
+ {
+ painter->fillRect(iconSubRect.x() + iconSubRect.width() / 2, iconSubRect.y(), 2,
+ iconSubRect.height(), penColor);
+ }
+
+ painter->restore();
+ }
+ //END: checkboxy thing
+
+ //BEGIN: text
+ {
+ QRect textRect(option.rect);
+ textRect.setTop(textRect.top() + 7);
+ textRect.setLeft(textRect.left() + 7 + fontMetrics.height() + 7);
+ textRect.setHeight(fontMetrics.height());
+ textRect.setRight(textRect.right() - 7);
+
+ painter->save();
+ painter->setFont(font);
+ QColor penColor(option.palette.text().color());
+ penColor.setAlphaF(0.6);
+ painter->setPen(penColor);
+ painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text);
+ painter->restore();
+ }
+ //END: text
}
int Group::totalHeight() const
@@ -207,11 +197,20 @@ int Group::totalHeight() const
int Group::headerHeight() const
{
+ QFont font(QApplication::font());
+ font.setBold(true);
+ QFontMetrics fontMetrics(font);
+
+ const int height = fontMetrics.height() + 1 /* 1 pixel-width gradient */
+ + 11 /* top and bottom separation */;
+ return height;
+ /*
int raw = view->viewport()->fontMetrics().height() + 4;
// add english. maybe. depends on font height.
- if(raw % 2 == 0)
+ if (raw % 2 == 0)
raw++;
- return std::min( raw , 25 );
+ return std::min(raw, 25);
+ */
}
int Group::contentHeight() const
diff --git a/gui/groupview/GroupView.cpp b/gui/groupview/GroupView.cpp
index 9954d743..5ee44cbb 100644
--- a/gui/groupview/GroupView.cpp
+++ b/gui/groupview/GroupView.cpp
@@ -121,6 +121,8 @@ void GroupView::updateGeometries()
category->m_verticalPosition = totalHeight;
totalHeight += category->totalHeight() + m_categoryMargin;
}
+ auto category = m_groups.last();
+ int itemScroll = category->contentHeight() / category->numRows();
/*
// remove the last margin (we don't want it)
totalHeight -= m_categoryMargin;
@@ -128,6 +130,10 @@ void GroupView::updateGeometries()
totalHeight += m_categoryMargin;
*/
totalHeight += m_bottomMargin;
+ verticalScrollBar()->setSingleStep ( itemScroll );
+ const int rowsPerPage = qMax ( viewport()->height() / itemScroll, 1 );
+ verticalScrollBar()->setPageStep ( rowsPerPage * itemScroll );
+
verticalScrollBar()->setRange(0, totalHeight - height());
}