#include "list_model.h" namespace roro { void ListModel::setCount(int count) { count_ = count < 0 ? 0 : count; if (count_ == 0) { selected_ = -1; first_ = 0; return; } select(selected_ < 0 ? 0 : selected_); } void ListModel::select(int index) { if (count_ == 0) return; selected_ = index < 0 ? 0 : index >= count_ ? count_ - 1 : index; scrollToSelection(); } void ListModel::up() { if (count_ == 0) return; select(selected_ == 0 ? count_ - 1 : selected_ - 1); } void ListModel::down() { if (count_ == 0) return; select(selected_ == count_ - 1 ? 0 : selected_ + 1); } void ListModel::pageUp() { select(selected_ - rows_); } void ListModel::pageDown() { select(selected_ + rows_); } void ListModel::scrollToSelection() { if (selected_ < first_) first_ = selected_; if (selected_ >= first_ + rows_) first_ = selected_ - rows_ + 1; int maxFirst = count_ > rows_ ? count_ - rows_ : 0; if (first_ > maxFirst) first_ = maxFirst; } } // namespace roro