forked from qt-creator/qt-creator
Improve focus and keyboard interaction with projectselector
This kills the event filter since it is not really neccessary. Most combo boxes should be disabled by default now. I Removed redundant focus widgets from the keyboard chain and I indicate that the list has focus by saturation.
This commit is contained in:
@@ -643,6 +643,7 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
|
|||||||
case CE_ComboBoxLabel:
|
case CE_ComboBoxLabel:
|
||||||
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
|
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
|
||||||
if (panelWidget(widget)) {
|
if (panelWidget(widget)) {
|
||||||
|
painter->save();
|
||||||
QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
|
QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
|
||||||
QPalette customPal = cb->palette;
|
QPalette customPal = cb->palette;
|
||||||
|
|
||||||
@@ -671,13 +672,18 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
|
|||||||
customPal.setBrush(QPalette::All, QPalette::ButtonText, QColor(0, 0, 0, 70));
|
customPal.setBrush(QPalette::All, QPalette::ButtonText, QColor(0, 0, 0, 70));
|
||||||
|
|
||||||
QString text = option->fontMetrics.elidedText(cb->currentText, Qt::ElideRight, editRect.width());
|
QString text = option->fontMetrics.elidedText(cb->currentText, Qt::ElideRight, editRect.width());
|
||||||
drawItemText(painter, editRect.translated(0, 1),
|
if ((option->state & State_Enabled))
|
||||||
visualAlignment(option->direction, Qt::AlignLeft | Qt::AlignVCenter),
|
drawItemText(painter, editRect.translated(0, 1),
|
||||||
customPal, cb->state & State_Enabled, text, QPalette::ButtonText);
|
visualAlignment(option->direction, Qt::AlignLeft | Qt::AlignVCenter),
|
||||||
|
customPal, cb->state & State_Enabled, text, QPalette::ButtonText);
|
||||||
|
else
|
||||||
|
painter->setOpacity(0.8);
|
||||||
|
|
||||||
customPal.setBrush(QPalette::All, QPalette::ButtonText, Utils::StyleHelper::panelTextColor());
|
customPal.setBrush(QPalette::All, QPalette::ButtonText, Utils::StyleHelper::panelTextColor());
|
||||||
drawItemText(painter, editRect,
|
drawItemText(painter, editRect,
|
||||||
visualAlignment(option->direction, Qt::AlignLeft | Qt::AlignVCenter),
|
visualAlignment(option->direction, Qt::AlignLeft | Qt::AlignVCenter),
|
||||||
customPal, cb->state & State_Enabled, text, QPalette::ButtonText);
|
customPal, cb->state & State_Enabled, text, QPalette::ButtonText);
|
||||||
|
painter->restore();
|
||||||
} else {
|
} else {
|
||||||
QProxyStyle::drawControl(element, option, painter, widget);
|
QProxyStyle::drawControl(element, option, painter, widget);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,10 @@ void TargetSelectorDelegate::paint(QPainter *painter,
|
|||||||
selectionGradient.load(QLatin1String(":/projectexplorer/images/targetpanel_gradient.png"));
|
selectionGradient.load(QLatin1String(":/projectexplorer/images/targetpanel_gradient.png"));
|
||||||
|
|
||||||
if (option.state & QStyle::State_Selected) {
|
if (option.state & QStyle::State_Selected) {
|
||||||
painter->fillRect(option.rect, option.palette.highlight().color().darker(140));
|
QColor color =(option.state & QStyle::State_HasFocus) ?
|
||||||
|
option.palette.highlight().color() :
|
||||||
|
option.palette.dark().color();
|
||||||
|
painter->fillRect(option.rect, color.darker(140));
|
||||||
Utils::StyleHelper::drawCornerImage(selectionGradient, painter, option.rect.adjusted(0, 0, 0, -1), 5, 5, 5, 5);
|
Utils::StyleHelper::drawCornerImage(selectionGradient, painter, option.rect.adjusted(0, 0, 0, -1), 5, 5, 5, 5);
|
||||||
painter->setPen(QColor(255, 255, 255, 60));
|
painter->setPen(QColor(255, 255, 255, 60));
|
||||||
painter->drawLine(option.rect.topLeft(), option.rect.topRight());
|
painter->drawLine(option.rect.topLeft(), option.rect.topRight());
|
||||||
@@ -363,7 +366,6 @@ MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorActi
|
|||||||
setProperty("panelwidget", true);
|
setProperty("panelwidget", true);
|
||||||
setContentsMargins(QMargins(0, 1, 1, 8));
|
setContentsMargins(QMargins(0, 1, 1, 8));
|
||||||
setWindowFlags(Qt::Popup);
|
setWindowFlags(Qt::Popup);
|
||||||
setFocusPolicy(Qt::WheelFocus);
|
|
||||||
|
|
||||||
targetSelectorAction->setIcon(style()->standardIcon(QStyle::SP_ComputerIcon));
|
targetSelectorAction->setIcon(style()->standardIcon(QStyle::SP_ComputerIcon));
|
||||||
targetSelectorAction->setProperty("titledAction", true);
|
targetSelectorAction->setProperty("titledAction", true);
|
||||||
@@ -397,18 +399,15 @@ MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorActi
|
|||||||
m_projectsBox->setFixedHeight(panelHeight);
|
m_projectsBox->setFixedHeight(panelHeight);
|
||||||
m_projectsBox->setProperty("hideborder", true);
|
m_projectsBox->setProperty("hideborder", true);
|
||||||
m_projectsBox->setObjectName(QString::fromUtf8("ProjectsBox"));
|
m_projectsBox->setObjectName(QString::fromUtf8("ProjectsBox"));
|
||||||
m_projectsBox->setFocusPolicy(Qt::WheelFocus);
|
|
||||||
m_projectsBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
m_projectsBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||||||
m_projectsBox->setMaximumWidth(200);
|
m_projectsBox->setMaximumWidth(200);
|
||||||
m_projectsBox->installEventFilter(this);
|
|
||||||
|
|
||||||
toolLayout->addWidget(lbl);
|
toolLayout->addWidget(lbl);
|
||||||
toolLayout->addWidget(new Utils::StyledSeparator);
|
toolLayout->addWidget(new Utils::StyledSeparator);
|
||||||
toolLayout->addWidget(m_projectsBox);
|
toolLayout->addWidget(m_projectsBox);
|
||||||
|
|
||||||
m_widgetStack = new QStackedWidget;
|
m_widgetStack = new QStackedWidget;
|
||||||
m_widgetStack->setFocusPolicy(Qt::WheelFocus);
|
m_widgetStack->setFocusPolicy(Qt::NoFocus);
|
||||||
m_widgetStack->installEventFilter(this);
|
|
||||||
layout->addWidget(m_widgetStack);
|
layout->addWidget(m_widgetStack);
|
||||||
|
|
||||||
connect(m_projectsBox, SIGNAL(activated(int)),
|
connect(m_projectsBox, SIGNAL(activated(int)),
|
||||||
@@ -448,7 +447,6 @@ void MiniProjectTargetSelector::addProject(ProjectExplorer::Project* project)
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(project, return);
|
QTC_ASSERT(project, return);
|
||||||
ProjectListWidget *targetList = new ProjectListWidget(project);
|
ProjectListWidget *targetList = new ProjectListWidget(project);
|
||||||
targetList->installEventFilter(this);
|
|
||||||
targetList->setStyleSheet(QString::fromLatin1("QListWidget { background: %1; border: none; }")
|
targetList->setStyleSheet(QString::fromLatin1("QListWidget { background: %1; border: none; }")
|
||||||
.arg(QColor(70, 70, 70).name()));
|
.arg(QColor(70, 70, 70).name()));
|
||||||
int pos = m_widgetStack->addWidget(targetList);
|
int pos = m_widgetStack->addWidget(targetList);
|
||||||
@@ -514,11 +512,6 @@ void MiniProjectTargetSelector::addTarget(ProjectExplorer::Target *target, bool
|
|||||||
|
|
||||||
MiniTargetWidget *targetWidget = new MiniTargetWidget(target);
|
MiniTargetWidget *targetWidget = new MiniTargetWidget(target);
|
||||||
connect(targetWidget, SIGNAL(changed()), this, SLOT(updateAction()));
|
connect(targetWidget, SIGNAL(changed()), this, SLOT(updateAction()));
|
||||||
targetWidget->installEventFilter(this);
|
|
||||||
if (targetWidget->buildSettingsComboBox())
|
|
||||||
targetWidget->buildSettingsComboBox()->installEventFilter(this);
|
|
||||||
if (targetWidget->runSettingsComboBox())
|
|
||||||
targetWidget->runSettingsComboBox()->installEventFilter(this);
|
|
||||||
targetWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
targetWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
||||||
// width==0 size hint to avoid horizontal scrolling in list widget
|
// width==0 size hint to avoid horizontal scrolling in list widget
|
||||||
lwi->setSizeHint(QSize(0, targetWidget->sizeHint().height()));
|
lwi->setSizeHint(QSize(0, targetWidget->sizeHint().height()));
|
||||||
@@ -634,48 +627,3 @@ void MiniProjectTargetSelector::paintEvent(QPaintEvent *)
|
|||||||
static QImage image(QLatin1String(":/projectexplorer/images/targetpanel_bottom.png"));
|
static QImage image(QLatin1String(":/projectexplorer/images/targetpanel_bottom.png"));
|
||||||
Utils::StyleHelper::drawCornerImage(image, &painter, bottomRect, 1, 1, 1, 1);
|
Utils::StyleHelper::drawCornerImage(image, &painter, bottomRect, 1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MiniProjectTargetSelector::eventFilter(QObject *o, QEvent *ev)
|
|
||||||
{
|
|
||||||
switch(ev->type())
|
|
||||||
{
|
|
||||||
case QEvent::KeyPress: {
|
|
||||||
|
|
||||||
QKeyEvent *kev = static_cast<QKeyEvent*>(ev);
|
|
||||||
|
|
||||||
if (kev->key() == Qt::Key_Tab) {
|
|
||||||
if(o == m_projectsBox) {
|
|
||||||
if (m_widgetStack->currentWidget())
|
|
||||||
m_widgetStack->currentWidget()->setFocus();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
m_projectsBox->setFocus();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (o == m_widgetStack->currentWidget()) {
|
|
||||||
if (kev->key() == Qt::Key_Return) {
|
|
||||||
hide();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProjectListWidget *plw = qobject_cast<ProjectListWidget*>(m_widgetStack->currentWidget());
|
|
||||||
if (kev->key() == Qt::Key_B)
|
|
||||||
{
|
|
||||||
plw->setBuildComboPopup();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (kev->key() == Qt::Key_R)
|
|
||||||
{
|
|
||||||
plw->setRunComboPopup();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -117,9 +117,6 @@ public:
|
|||||||
MiniProjectTargetSelector(QAction *projectAction, QWidget *parent = 0);
|
MiniProjectTargetSelector(QAction *projectAction, QWidget *parent = 0);
|
||||||
void setVisible(bool visible);
|
void setVisible(bool visible);
|
||||||
|
|
||||||
protected:
|
|
||||||
bool eventFilter(QObject *o, QEvent *ev);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void startupProjectChanged(ProjectExplorer::Project *project);
|
void startupProjectChanged(ProjectExplorer::Project *project);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user