void StackMaze::generate() { // Generate cell lists m_visited = QVector< QVector<bool> >(columns(), QVector<bool>(rows())); QList<QPoint> active; // Start maze QPoint start(0, randomInt(rows())); m_visited[start.x()][start.y()] = true; active.append(start); // Loop through active list QPoint cell, neighbor; int pos; while (!active.isEmpty()) { pos = nextActive(active.size()); cell = active.at(pos); neighbor = randomNeighbor(m_visited, cell); if (neighbor.x() != -1) { mergeCells(cell, neighbor); active.append(neighbor); } else { active.takeAt(pos); } } m_visited.clear(); }
TreeWidget::TreeWidget(QWidget* parent) : QTreeWidget(parent) { d.block = false; d.blink = false; d.pressedItem = 0; d.sortingBlocked = false; qRegisterMetaType<TreeItem*>(); setAnimated(true); setColumnCount(2); setIndentation(0); setHeaderHidden(true); setRootIsDecorated(false); setFocusPolicy(Qt::NoFocus); setFrameStyle(QFrame::NoFrame); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); #ifdef Q_OS_MAC setVerticalScrollMode(ScrollPerPixel); #endif setItemDelegate(new TreeDelegate(this)); setSortingEnabled(true); sortByColumn(0, Qt::AscendingOrder); header()->setStretchLastSection(false); header()->setResizeMode(0, QHeaderView::Stretch); header()->setResizeMode(1, QHeaderView::Fixed); #ifdef Q_OS_WIN header()->resizeSection(1, fontMetrics().width("9999")); #else header()->resizeSection(1, fontMetrics().width("999")); #endif connect(this, SIGNAL(itemExpanded(QTreeWidgetItem*)), this, SLOT(onItemExpanded(QTreeWidgetItem*))); connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(onItemCollapsed(QTreeWidgetItem*))); connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(onCurrentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*))); #ifdef Q_OS_MAC QString navigate(tr("Ctrl+Alt+%1")); QString nextActive(tr("Shift+Ctrl+Alt+%1")); #else QString navigate(tr("Alt+%1")); QString nextActive(tr("Shift+Alt+%1")); #endif QShortcut* shortcut = new QShortcut(this); shortcut->setKey(QKeySequence(navigate.arg("Up"))); connect(shortcut, SIGNAL(activated()), this, SLOT(moveToPrevItem())); shortcut = new QShortcut(this); shortcut->setKey(QKeySequence(navigate.arg("Down"))); connect(shortcut, SIGNAL(activated()), this, SLOT(moveToNextItem())); shortcut = new QShortcut(this); shortcut->setKey(QKeySequence(nextActive.arg("Up"))); connect(shortcut, SIGNAL(activated()), this, SLOT(moveToPrevActiveItem())); shortcut = new QShortcut(this); shortcut->setKey(QKeySequence(nextActive.arg("Down"))); connect(shortcut, SIGNAL(activated()), this, SLOT(moveToNextActiveItem())); shortcut = new QShortcut(this); shortcut->setKey(QKeySequence(navigate.arg("Right"))); connect(shortcut, SIGNAL(activated()), this, SLOT(expandCurrentConnection())); shortcut = new QShortcut(this); shortcut->setKey(QKeySequence(navigate.arg("Left"))); connect(shortcut, SIGNAL(activated()), this, SLOT(collapseCurrentConnection())); shortcut = new QShortcut(this); shortcut->setKey(QKeySequence(tr("Ctrl+L"))); connect(shortcut, SIGNAL(activated()), this, SLOT(moveToMostActiveItem())); shortcut = new QShortcut(this); shortcut->setKey(QKeySequence(tr("Ctrl+R"))); connect(shortcut, SIGNAL(activated()), this, SLOT(resetItems())); }