Commit 2dc005ca authored by Eike Ziller's avatar Eike Ziller Committed by Tobias Hunger
Browse files

Redesign project mode's target selector



Change-Id: I6df2550505b523e6c416558b5d1ad0d3f206e4f4
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent e7fea1aa
......@@ -266,13 +266,13 @@ QtcPlugin {
"images/session.png",
"images/stop.png",
"images/stop_small.png",
"images/targetaddbutton.png",
"images/targetaddbutton_disabled.png",
"images/targetleftbutton.png",
"images/targetrightbutton.png",
"images/targetbuildselected.png",
"images/targetpanel_bottom.png",
"images/targetpanel_gradient.png",
"images/targetremovebutton.png",
"images/targetremovebutton_disabled.png",
"images/targetremovebuttondark.png",
"images/targetrunselected.png",
"images/targetseparatorbackground.png",
"images/targetunselected.png",
......
......@@ -13,7 +13,6 @@
<file>images/run_small.png</file>
<file>images/session.png</file>
<file>images/stop.png</file>
<file>images/targetaddbutton.png</file>
<file>images/targetbuildselected.png</file>
<file>images/targetrunselected.png</file>
<file>images/targetseparatorbackground.png</file>
......@@ -21,7 +20,6 @@
<file>images/leftselection.png</file>
<file>images/rightselection.png</file>
<file>images/midselection.png</file>
<file>images/targetremovebutton.png</file>
<file>images/compile_error.png</file>
<file>images/compile_warning.png</file>
<file>images/BuildSettings.png</file>
......@@ -37,11 +35,13 @@
<file>images/build.png</file>
<file>images/targetpanel_bottom.png</file>
<file>images/targetpanel_gradient.png</file>
<file>images/targetaddbutton_disabled.png</file>
<file>images/targetremovebutton_disabled.png</file>
<file>images/window.png</file>
<file>images/stop_small.png</file>
<file>images/disabledbuildstep.png</file>
<file>images/unconfigured.png</file>
<file>images/targetleftbutton.png</file>
<file>images/targetrightbutton.png</file>
<file>images/targetremovebutton.png</file>
<file>images/targetremovebuttondark.png</file>
</qresource>
</RCC>
......@@ -39,7 +39,7 @@
#include <QFontMetrics>
static const int TARGET_HEIGHT = 43;
static const int ADDBUTTON_WIDTH = 27;
static const int NAVBUTTON_WIDTH = 27;
using namespace ProjectExplorer::Internal;
......@@ -48,19 +48,20 @@ TargetSelector::TargetSelector(QWidget *parent) :
m_unselected(QLatin1String(":/projectexplorer/images/targetunselected.png")),
m_runselected(QLatin1String(":/projectexplorer/images/targetrunselected.png")),
m_buildselected(QLatin1String(":/projectexplorer/images/targetbuildselected.png")),
m_targetaddbutton(QLatin1String(":/projectexplorer/images/targetaddbutton.png")),
m_targetaddbuttondisabled(QLatin1String(":/projectexplorer/images/targetaddbutton_disabled.png")),
m_targetremovebutton(QLatin1String(":/projectexplorer/images/targetremovebutton.png")),
m_targetremovebuttondisabled(QLatin1String(":/projectexplorer/images/targetremovebutton_disabled.png")),
m_targetRightButton(QLatin1String(":/projectexplorer/images/targetrightbutton.png")),
m_targetLeftButton(QLatin1String(":/projectexplorer/images/targetleftbutton.png")),
m_targetRemoveButton(QLatin1String(":/projectexplorer/images/targetremovebutton.png")),
m_targetRemoveDarkButton(QLatin1String(":/projectexplorer/images/targetremovebuttondark.png")),
m_currentTargetIndex(-1),
m_addButtonEnabled(true),
m_removeButtonEnabled(false),
m_addButtonMenu(0)
m_currentHoveredTargetIndex(-1),
m_rightButtonEnabled(true),
m_leftButtonEnabled(false)
{
QFont f = font();
f.setPixelSize(10);
f.setBold(true);
setFont(f);
setMouseTracking(true);
}
void TargetSelector::insertTarget(int index, const QString &name)
......@@ -75,6 +76,7 @@ void TargetSelector::insertTarget(int index, const QString &name)
if (m_currentTargetIndex >= index)
setCurrentIndex(m_currentTargetIndex + 1);
updateGeometry();
update();
}
......@@ -95,6 +97,7 @@ void TargetSelector::removeTarget(int index)
// force a signal since the index has changed
emit currentChanged(m_currentTargetIndex, m_targets.at(m_currentTargetIndex).currentSubIndex);
}
updateGeometry();
update();
}
......@@ -115,23 +118,6 @@ void TargetSelector::setCurrentIndex(int index)
m_currentTargetIndex >= 0 ? m_targets.at(m_currentTargetIndex).currentSubIndex : -1);
}
void TargetSelector::setAddButtonEnabled(bool enabled)
{
m_addButtonEnabled = enabled;
update();
}
void TargetSelector::setRemoveButtonEnabled(bool enabled)
{
m_removeButtonEnabled = enabled;
update();
}
void TargetSelector::setAddButtonMenu(QMenu *menu)
{
m_addButtonMenu = menu;
}
void TargetSelector::setCurrentSubIndex(int subindex)
{
if (subindex < 0 ||
......@@ -151,16 +137,6 @@ TargetSelector::Target TargetSelector::targetAt(int index) const
return m_targets.at(index);
}
bool TargetSelector::isAddButtonEnabled() const
{
return m_addButtonEnabled;
}
bool TargetSelector::isRemoveButtonEnabled() const
{
return m_removeButtonEnabled;
}
int TargetSelector::targetWidth() const
{
static int width = -1;
......@@ -174,85 +150,142 @@ int TargetSelector::targetWidth() const
QSize TargetSelector::minimumSizeHint() const
{
return QSize((targetWidth() + 1) * m_targets.size() + (ADDBUTTON_WIDTH + 1) * 2 + 3, TARGET_HEIGHT + 4);
return QSize((targetWidth() + 1) * m_targets.size() + (NAVBUTTON_WIDTH + 1) * 2 + 3, TARGET_HEIGHT + 1);
}
void TargetSelector::getControlAt(int x, int y, int *buttonIndex, int *targetIndex, int *targetSubIndex, bool *removeButton)
{
if (buttonIndex)
*buttonIndex = -1;
if (targetIndex)
*targetIndex = -1;
if (targetSubIndex)
*targetSubIndex = -1;
if (removeButton)
*removeButton = false;
// left button?
if (x >= 0 && x < NAVBUTTON_WIDTH + 2) {
if (buttonIndex)
*buttonIndex = 0;
return;
}
// right button?
if (x < width() && x > NAVBUTTON_WIDTH + (targetWidth() + 1) * m_targets.size() + 2) {
if (buttonIndex)
*buttonIndex = 1;
return;
}
// find the clicked target button
int tx = NAVBUTTON_WIDTH + 3;
int index;
for (index = 0; index < m_targets.size(); ++index) {
if (x <= tx) {
break;
}
tx += targetWidth() + 1;
}
--index;
tx -= targetWidth() + 1;
if (index >= 0 && index < m_targets.size()) {
if (targetIndex)
*targetIndex = index;
// handle clicked target
// check if user clicked on Build or Run
if (y > TARGET_HEIGHT * 3/5) {
if ((x - tx) - 2 > targetWidth() / 2) {
if (targetSubIndex)
*targetSubIndex = 1;
} else {
if (targetSubIndex)
*targetSubIndex = 0;
}
} else if (y < m_targetRemoveButton.height() + 3
&& x >= tx + targetWidth() - m_targetRemoveButton.width() - 1) {
if (removeButton)
*removeButton = true;
}
}
}
void TargetSelector::mousePressEvent(QMouseEvent *event)
{
if (event->x() < ADDBUTTON_WIDTH) {
int buttonIndex;
int targetIndex;
int targetSubIndex;
bool removeButton;
getControlAt(event->x(), event->y(), &buttonIndex, &targetIndex, &targetSubIndex, &removeButton);
if (buttonIndex == 0) {
event->accept();
if (m_removeButtonEnabled)
emit removeButtonClicked();
} else if (event->x() > ADDBUTTON_WIDTH + (targetWidth() + 1) * m_targets.size()) {
// check for add button
// TODO: handle left button
} else if (buttonIndex == 1) {
event->accept();
if (m_addButtonEnabled && m_addButtonMenu)
m_addButtonMenu->popup(mapToGlobal(event->pos()));
} else {
// find the clicked target button
int x = ADDBUTTON_WIDTH;
int index;
for (index = 0; index < m_targets.size(); ++index) {
if (event->x() <= x) {
break;
}
x += targetWidth() + 1;
// TODO: handle right button
} else if (targetIndex != -1) {
event->accept();
bool updateNeeded = false;
if (targetIndex != m_currentTargetIndex && !removeButton) {
m_currentTargetIndex = targetIndex;
updateNeeded = true;
}
--index;
if (index >= 0 && index < m_targets.size()) {
// handle clicked target
// check if user clicked on Build or Run
if (event->y() > TARGET_HEIGHT * 3/5) {
if ((event->x() - (ADDBUTTON_WIDTH + (targetWidth() + 1) * index)) - 2 > targetWidth() / 2) {
m_targets[index].currentSubIndex = 1;
} else {
m_targets[index].currentSubIndex = 0;
}
if (targetSubIndex != -1) {
if (targetSubIndex != m_targets[m_currentTargetIndex].currentSubIndex) {
m_targets[m_currentTargetIndex].currentSubIndex = targetSubIndex;
updateNeeded = true;
}
m_currentTargetIndex = index;
//TODO don't emit if nothing changed!
} else if (removeButton) {
emit removeButtonClicked(targetIndex);
}
if (updateNeeded) {
update();
emit currentChanged(m_currentTargetIndex, m_targets.at(m_currentTargetIndex).currentSubIndex);
} else {
event->ignore();
}
} else {
event->ignore();
}
}
void TargetSelector::mouseMoveEvent(QMouseEvent *event)
{
int targetIndex;
getControlAt(event->x(), event->y(), 0, &targetIndex, 0, 0);
if (m_currentHoveredTargetIndex != targetIndex) {
m_currentHoveredTargetIndex = targetIndex;
if (targetIndex != -1)
event->accept();
update();
}
}
void TargetSelector::leaveEvent(QEvent *event)
{
Q_UNUSED(event)
m_currentHoveredTargetIndex = -1;
update();
}
void TargetSelector::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
QPainter p(this);
p.setPen(QColor(89, 89, 89));
QSize size = minimumSizeHint();
//draw frame
p.drawLine(1, 0, size.width() - 2, 0);
p.drawLine(1, size.height() - 3, size.width() - 2, size.height() - 3);
p.drawLine(1, 1, 1, size.height() - 4);
p.drawLine(size.width() - 2, 1, size.width() - 2, size.height() - 4);
//draw shadow
p.setPen(QColor(0, 0, 0, 50));
p.drawLine(1, size.height() - 2, size.width() - 2, size.height() - 2);
p.setPen(QColor(0, 0, 0, 20));
p.drawLine(0, size.height() - 2, 0, size.height() - 9);
p.drawLine(size.width()-1, size.height() - 2, size.width()-1, size.height() - 9);
p.drawLine(1, size.height() - 1, size.width() - 2, size.height() - 1);
//draw targets
QColor borderColor(89, 89, 89);
int x = 2;
int index = 0;
QFontMetrics fm(font());
if (m_removeButtonEnabled)
p.drawPixmap(x, 1, m_targetremovebutton);
else
p.drawPixmap(x, 1, m_targetremovebuttondisabled);
x += m_targetremovebutton.width();
p.setPen(QColor(0, 0, 0));
//draw left button
// if (m_leftButtonEnabled)
// p.drawPixmap(x, 1, m_targetLeftButton);
x += m_targetLeftButton.width();
p.setPen(borderColor);
p.drawLine(x, 1, x, TARGET_HEIGHT);
x += 1;
// draw targets
const QString runString = runButtonString();
const QString buildString = buildButtonString();
foreach (const Target &target, m_targets) {
......@@ -274,10 +307,16 @@ void TargetSelector::paintEvent(QPaintEvent *event)
p.drawText(x + (targetWidth()- fm.width(target.name))/2 + 1, 7 + fm.ascent(),
target.name);
// // remove button
// if (m_currentHoveredTargetIndex == index) {
// p.drawPixmap(x + targetWidth() - m_targetRemoveButton.width() - 2, 3,
// index == m_currentTargetIndex ? m_targetRemoveDarkButton : m_targetRemoveButton);
// }
// Build
int margin = 2; // position centered within the rounded buttons
QFontMetrics fm = fontMetrics();
QRect textRect(x + margin, size.height() - fm.height() - 7, targetWidth()/2, fm.height());
QRect textRect(x + margin, size.height() - fm.height() - 5, targetWidth()/2, fm.height());
if (index != m_currentTargetIndex)
p.setPen(QColor(0x555555));
else
......@@ -300,9 +339,12 @@ void TargetSelector::paintEvent(QPaintEvent *event)
++x;
++index;
}
// draw add button
if (m_addButtonEnabled)
p.drawPixmap(x, 1, m_targetaddbutton);
else
p.drawPixmap(x, 1, m_targetaddbuttondisabled);
// draw right button
// if (m_rightButtonEnabled)
// p.drawPixmap(x, 1, m_targetRightButton);
//draw frame (left hand part already done)
p.setPen(borderColor);
p.drawLine(2 + m_targetLeftButton.width(), 0, x - 1, 0);
p.drawLine(x - 1, 1, x - 1, TARGET_HEIGHT);
}
......@@ -63,21 +63,15 @@ public:
int currentIndex() const { return m_currentTargetIndex; }
int currentSubIndex() const { return m_targets.at(m_currentTargetIndex).currentSubIndex; }
bool isAddButtonEnabled() const;
bool isRemoveButtonEnabled() const;
public:
void insertTarget(int index, const QString &name);
void renameTarget(int index, const QString &name);
void removeTarget(int index);
void setCurrentIndex(int index);
void setCurrentSubIndex(int subindex);
void setAddButtonEnabled(bool enabled);
void setRemoveButtonEnabled(bool enabled);
void setAddButtonMenu(QMenu *menu);
signals:
void removeButtonClicked();
void removeButtonClicked(int targetIndex);
// This signal is emitted whenever the target pointed to by the indices
// has changed.
void currentChanged(int targetIndex, int subIndex);
......@@ -85,23 +79,26 @@ signals:
protected:
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void leaveEvent(QEvent *event);
private:
void getControlAt(int x, int y, int *buttonIndex, int *targetIndex, int *targetSubIndex, bool *removeButton);
const QImage m_unselected;
const QImage m_runselected;
const QImage m_buildselected;
const QPixmap m_targetaddbutton;
const QPixmap m_targetaddbuttondisabled;
const QPixmap m_targetremovebutton;
const QPixmap m_targetremovebuttondisabled;
const QPixmap m_targetRightButton;
const QPixmap m_targetLeftButton;
const QPixmap m_targetRemoveButton;
const QPixmap m_targetRemoveDarkButton;
QList<Target> m_targets;
int m_currentTargetIndex;
bool m_addButtonEnabled;
bool m_removeButtonEnabled;
QMenu *m_addButtonMenu;
int m_currentHoveredTargetIndex;
bool m_rightButtonEnabled;
bool m_leftButtonEnabled;
};
} // namespace Internal
......
......@@ -37,11 +37,13 @@
#include "target.h"
#include "targetsettingswidget.h"
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/profile.h>
#include <projectexplorer/profilemanager.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/qtcassert.h>
#include <QCoreApplication>
......@@ -136,9 +138,10 @@ void TargetSettingsPanelWidget::setupUi()
connect(m_selector, SIGNAL(currentChanged(int,int)),
this, SLOT(currentTargetChanged(int,int)));
connect(m_selector, SIGNAL(removeButtonClicked()),
this, SLOT(removeTarget()));
connect(m_selector, SIGNAL(removeButtonClicked(int)),
this, SLOT(removeTarget(int)));
connect(m_selector, SIGNAL(manageButtonClicked()),
this, SLOT(openTargetPreferences()));
m_selector->setAddButtonMenu(m_addMenu);
connect(m_addMenu, SIGNAL(triggered(QAction*)),
......@@ -218,10 +221,9 @@ void TargetSettingsPanelWidget::addTarget(QAction *action)
m_project->addTarget(target);
}
void TargetSettingsPanelWidget::removeTarget()
void TargetSettingsPanelWidget::removeTarget(int targetIndex)
{
int index = m_selector->currentIndex();
Target *t = m_targets.at(index);
Target *t = m_targets.at(targetIndex);
ProjectExplorer::BuildManager *bm = ProjectExplorerPlugin::instance()->buildManager();
if (bm->isBuilding(t)) {
......@@ -321,7 +323,6 @@ void TargetSettingsPanelWidget::updateTargetAddAndRemoveButtons()
}
m_selector->setAddButtonEnabled(!m_addMenu->actions().isEmpty());
m_selector->setRemoveButtonEnabled(m_project->targets().count() > 1);
}
void TargetSettingsPanelWidget::renameTarget()
......@@ -335,6 +336,12 @@ void TargetSettingsPanelWidget::renameTarget()
m_selector->renameTarget(pos, t->displayName());
}
void TargetSettingsPanelWidget::openTargetPreferences()
{
Core::ICore::showOptionsDialog(QLatin1String(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY),
QLatin1String(Constants::PROFILE_SETTINGS_PAGE_ID));
}
int TargetSettingsPanelWidget::currentSubIndex() const
{
return m_selector->currentSubIndex();
......
......@@ -63,13 +63,14 @@ public:
private slots:
void currentTargetChanged(int targetIndex, int subIndex);
void removeTarget();
void removeTarget(int targetIndex);
void addTarget(QAction *);
void targetAdded(ProjectExplorer::Target *target);
void removedTarget(ProjectExplorer::Target *target);
void activeTargetChanged(ProjectExplorer::Target *target);
void updateTargetAddAndRemoveButtons();
void renameTarget();
void openTargetPreferences();
private:
Target *m_currentTarget;
......
......@@ -31,7 +31,7 @@
#include "targetsettingswidget.h"
#include "ui_targetsettingswidget.h"
static int WIDTH = 900;
#include <QPushButton>
using namespace ProjectExplorer::Internal;
......@@ -41,28 +41,41 @@ TargetSettingsWidget::TargetSettingsWidget(QWidget *parent) :
m_targetSelector(new TargetSelector(this))
{
ui->setupUi(this);
ui->separator->setStyleSheet(QLatin1String("* { "
"background-image: url(:/projectexplorer/images/targetseparatorbackground.png);"
ui->header->setStyleSheet(QLatin1String("QWidget#header {"
"border-image: url(:/projectexplorer/images/targetseparatorbackground.png) 43 0 0 0 repeat;"
"}"));
m_targetSelector->raise();
connect(m_targetSelector, SIGNAL(removeButtonClicked()),
this, SIGNAL(removeButtonClicked()));
QHBoxLayout *headerLayout = new QHBoxLayout;
headerLayout->setContentsMargins(5, 3, 0, 0);
ui->header->setLayout(headerLayout);
QWidget *buttonWidget = new QWidget(ui->header);
QVBoxLayout *buttonLayout = new QVBoxLayout;
buttonLayout->setContentsMargins(0, 0, 0, 0);
buttonLayout->setSpacing(4);
buttonWidget->setLayout(buttonLayout);
m_addButton = new QPushButton(tr("Add"), buttonWidget);
buttonLayout->addWidget(m_addButton);
m_manageButton = new QPushButton(tr("Manage ..."), buttonWidget);
connect(m_manageButton, SIGNAL(clicked()), this, SIGNAL(manageButtonClicked()));
buttonLayout->addWidget(m_manageButton);
headerLayout->addWidget(buttonWidget, 0, Qt::AlignVCenter);
headerLayout->addWidget(m_targetSelector, 0, Qt::AlignBottom);
headerLayout->addStretch(10);
connect(m_targetSelector, SIGNAL(removeButtonClicked(int)),
this, SIGNAL(removeButtonClicked(int)));
connect(m_targetSelector, SIGNAL(currentChanged(int,int)),
this, SIGNAL(currentChanged(int,int)));
m_shadow = new QWidget(this);
// Create shadow below targetselector
m_targetSelector->raise();
QPalette shadowPal = palette();
QLinearGradient grad(0, 0, 0, 2);
grad.setColorAt(0, QColor(0, 0, 0, 60));
grad.setColorAt(1, Qt::transparent);
shadowPal.setBrush(QPalette::All, QPalette::Window, grad);
m_shadow->setPalette(shadowPal);
m_shadow->setAutoFillBackground(true);
updateTargetSelector();
ui->shadow->setPalette(shadowPal);