+ vector< shared_ptr<RowItem> > row_items(view_.begin(), view_.end());
+ assert(none_of(row_items.begin(), row_items.end(),
+ [](const shared_ptr<RowItem> &r) { return !r; }));
+
+ stable_sort(row_items.begin(), row_items.end(),
+ [](const shared_ptr<RowItem> &a, const shared_ptr<RowItem> &b) {
+ return a->visual_v_offset() < b->visual_v_offset(); });
+
+ const vector< shared_ptr<TimeItem> > time_items(view_.time_items());
+ assert(none_of(time_items.begin(), time_items.end(),
+ [](const shared_ptr<TimeItem> &t) { return !t; }));
+
+ QPainter p(this);
+ p.setRenderHint(QPainter::Antialiasing);
+
+ const ViewItemPaintParams pp(rect(), view_.scale(), view_.offset());
+
+ for (const shared_ptr<TimeItem> t : time_items)
+ t->paint_back(p, pp);
+ for (const shared_ptr<RowItem> r : row_items)
+ r->paint_back(p, pp);
+
+ for (const shared_ptr<TimeItem> t : time_items)
+ t->paint_mid(p, pp);
+ for (const shared_ptr<RowItem> r : row_items)
+ r->paint_mid(p, pp);
+
+ for (const shared_ptr<RowItem> r : row_items)
+ r->paint_fore(p, pp);
+ for (const shared_ptr<TimeItem> t : time_items)
+ t->paint_fore(p, pp);
+
+ p.end();
+}
+
+void Viewport::mouseDoubleClickEvent(QMouseEvent *event)
+{
+ assert(event);
+
+ if (event->buttons() & Qt::LeftButton)
+ view_.zoom(2.0, event->x());
+ else if (event->buttons() & Qt::RightButton)
+ view_.zoom(-2.0, event->x());
+}
+
+void Viewport::wheelEvent(QWheelEvent *e)
+{
+ assert(e);
+
+ if (e->orientation() == Qt::Vertical)
+ {
+ if (e->modifiers() & Qt::ControlModifier) {
+ // Vertical scrolling with the control key pressed
+ // is intrepretted as vertical scrolling
+ view_.set_v_offset(-view_.owner_visual_v_offset() -
+ (e->delta() * height()) / (8 * 120));
+ } else {
+ // Vertical scrolling is interpreted as zooming in/out
+ view_.zoom(e->delta() / 120, e->x());
+ }
+ }
+ else if (e->orientation() == Qt::Horizontal)
+ {
+ // Horizontal scrolling is interpreted as moving left/right
+ view_.set_scale_offset(view_.scale(),
+ e->delta() * view_.scale() + view_.offset());
+ }