bool CommandPanel::processKey(Qt::Key key) { switch(key) { case Qt::Key_Left: moveToPrevItem(); break; case Qt::Key_Right: moveToNextItem(); break; case Qt::Key_Select: selectOption(options_.idFromIndex(highlightedIndex_)); break; default: if(useHotkeys_) { const CommandOption *option = options_.findItemByKey(key); if(option && option->isSelectable()) { selectOption(option->id); break; } } return false; } // return true; }
bool CommandPanel::enter() { if(highlightedIndex_>=0) { showHighlight_ = true; // resume selection } else { showHighlight_ = true; highlightedIndex_ = rects_.size()-1; moveToNextItem(); // if(highlightedIndex_==-1) return false; } repaint(rects_[highlightedIndex_]); // return true; }
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())); }