Commit abeedb68 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Add remove button to target selector widget

 * ... and use it.
parent 9cd64f51
......@@ -27,5 +27,6 @@
<file>images/leftselection.png</file>
<file>images/rightselection.png</file>
<file>images/midselection.png</file>
<file>images/targetremovebutton.png</file>
</qresource>
</RCC>
......@@ -16,7 +16,10 @@ TargetSelector::TargetSelector(QWidget *parent) :
m_runselected(QLatin1String(":/projectexplorer/images/targetrunselected.png")),
m_buildselected(QLatin1String(":/projectexplorer/images/targetbuildselected.png")),
m_targetaddbutton(QLatin1String(":/projectexplorer/images/targetaddbutton.png")),
m_currentTargetIndex(-1)
m_targetremovebutton(QLatin1String(":/projectexplorer/images/targetremovebutton.png")),
m_currentTargetIndex(-1),
m_addButtonEnabled(true),
m_removeButtonEnabled(false)
{
QFont f = font();
f.setPixelSize(10);
......@@ -67,6 +70,16 @@ void TargetSelector::setCurrentIndex(int index)
m_currentTargetIndex >= 0 ? m_targets.at(m_currentTargetIndex).currentSubIndex : -1);
}
void TargetSelector::setAddButtonEnabled(bool enabled)
{
m_addButtonEnabled = enabled;
}
void TargetSelector::setRemoveButtonEnabled(bool enabled)
{
m_removeButtonEnabled = enabled;
}
void TargetSelector::setCurrentSubIndex(int subindex)
{
if (subindex < 0 ||
......@@ -85,20 +98,35 @@ 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;
}
QSize TargetSelector::minimumSizeHint() const
{
return QSize((TARGET_WIDTH + 1) * m_targets.size() + ADDBUTTON_WIDTH + 2, TARGET_HEIGHT + 2);
return QSize((TARGET_WIDTH + 1) * m_targets.size() + (ADDBUTTON_WIDTH + 1) * 2 + 1, TARGET_HEIGHT + 2);
}
void TargetSelector::mousePressEvent(QMouseEvent *event)
{
if (event->x() > (TARGET_WIDTH + 1) * m_targets.size()) {
if (event->x() < ADDBUTTON_WIDTH) {
event->accept();
if (m_removeButtonEnabled)
emit removeButtonClicked();
} else if (event->x() > ADDBUTTON_WIDTH + (TARGET_WIDTH + 1) * m_targets.size()) {
// check for add button
event->accept();
emit addButtonClicked();
if (m_addButtonEnabled)
emit addButtonClicked();
} else {
// find the clicked target button
int x = 1;
int x = ADDBUTTON_WIDTH;
int index;
for (index = 0; index < m_targets.size(); ++index) {
if (event->x() <= x) {
......@@ -143,6 +171,11 @@ void TargetSelector::paintEvent(QPaintEvent *event)
int x = 1;
int index = 0;
QFontMetrics fm(font());
p.drawPixmap(x, 1, m_targetremovebutton);
x += m_targetremovebutton.width();
p.setPen(QColor(0, 0, 0));
p.drawLine(x, 1, x, TARGET_HEIGHT);
x += 1;
foreach (const Target &target, m_targets) {
const QPixmap *pixmap = &m_unselected;
if (index == m_currentTargetIndex) {
......
......@@ -26,15 +26,21 @@ public:
int currentIndex() const { return m_currentTargetIndex; }
int currentSubIndex() const { return m_targets.at(m_currentTargetIndex).currentSubIndex; }
bool isAddButtonEnabled() const;
bool isRemoveButtonEnabled() const;
public slots:
void addTarget(const QString &name);
void markActive(int index);
void removeTarget(int index);
void setCurrentIndex(int index);
void setCurrentSubIndex(int subindex);
void setAddButtonEnabled(bool enabled);
void setRemoveButtonEnabled(bool enabled);
signals:
void addButtonClicked();
void removeButtonClicked();
void currentIndexChanged(int targetIndex, int subIndex);
protected:
......@@ -46,10 +52,13 @@ private:
const QPixmap m_runselected;
const QPixmap m_buildselected;
const QPixmap m_targetaddbutton;
const QPixmap m_targetremovebutton;
QList<Target> m_targets;
int m_currentTargetIndex;
bool m_addButtonEnabled;
bool m_removeButtonEnabled;
};
} // namespace Internal
......
......@@ -130,7 +130,7 @@ TargetSettingsPanelWidget::TargetSettingsPanelWidget(Project *project) :
connect(m_project, SIGNAL(addedTarget(ProjectExplorer::Target*)),
this, SLOT(targetAdded(ProjectExplorer::Target*)));
connect(m_project, SIGNAL(aboutToRemoveTarget(ProjectExplorer::Target*)),
this, SLOT(targetRemoved(ProjectExplorer::Target*)));
this, SLOT(aboutToRemoveTarget(ProjectExplorer::Target*)));
connect(m_project, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
this, SLOT(activeTargetChanged(ProjectExplorer::Target*)));
}
......@@ -178,6 +178,8 @@ void TargetSettingsPanelWidget::setupUi()
this, SLOT(currentTargetIndexChanged(int,int)));
connect(m_selector, SIGNAL(addButtonClicked()),
this, SLOT(addTarget()));
connect(m_selector, SIGNAL(removeButtonClicked()),
this, SLOT(removeTarget()));
if (m_project->targets().count())
currentTargetIndexChanged(m_project->targets().indexOf(m_project->activeTarget()), 0);
......@@ -241,16 +243,25 @@ void TargetSettingsPanelWidget::addTarget()
dialog.exec();
}
void TargetSettingsPanelWidget::removeTarget()
{
int index = m_selector->currentIndex();
Target *t = m_project->targets().at(index);
// TODO: Ask before removal?
m_project->removeTarget(t);
}
void TargetSettingsPanelWidget::targetAdded(ProjectExplorer::Target *target)
{
Q_ASSERT(m_project == target->project());
Q_ASSERT(m_selector);
m_selector->addTarget(target->displayName());
// TODO: Disable/enable add button.
m_selector->setAddButtonEnabled(m_project->possibleTargetIds().count() > 0);
m_selector->setRemoveButtonEnabled(m_project->targets().count() > 1);
}
void TargetSettingsPanelWidget::targetRemoved(ProjectExplorer::Target *target)
void TargetSettingsPanelWidget::aboutToRemoveTarget(ProjectExplorer::Target *target)
{
Q_ASSERT(m_project == target->project());
Q_ASSERT(m_selector);
......@@ -259,7 +270,8 @@ void TargetSettingsPanelWidget::targetRemoved(ProjectExplorer::Target *target)
if (index < 0)
return;
m_selector->removeTarget(index);
// TODO: Disable/enable add button.
m_selector->setAddButtonEnabled(m_project->possibleTargetIds().count() > 0);
m_selector->setRemoveButtonEnabled(m_project->targets().count() > 2); // target is not yet removed!
}
void TargetSettingsPanelWidget::activeTargetChanged(ProjectExplorer::Target *target)
......
......@@ -85,8 +85,9 @@ public:
private slots:
void currentTargetIndexChanged(int targetIndex, int subIndex);
void addTarget();
void removeTarget();
void targetAdded(ProjectExplorer::Target *target);
void targetRemoved(ProjectExplorer::Target *target);
void aboutToRemoveTarget(ProjectExplorer::Target *target);
void activeTargetChanged(ProjectExplorer::Target *target);
private:
......
#include "targetsettingswidget.h"
#include "ui_targetsettingswidget.h"
static int WIDTH = 750;
static int WIDTH = 900;
using namespace ProjectExplorer::Internal;
......@@ -17,6 +17,8 @@ TargetSettingsWidget::TargetSettingsWidget(QWidget *parent) :
m_targetSelector->raise();
connect(m_targetSelector, SIGNAL(addButtonClicked()),
this, SIGNAL(addButtonClicked()));
connect(m_targetSelector, SIGNAL(removeButtonClicked()),
this, SIGNAL(removeButtonClicked()));
connect(m_targetSelector, SIGNAL(currentIndexChanged(int,int)),
this, SIGNAL(currentIndexChanged(int,int)));
updateTargetSelector();
......@@ -53,6 +55,16 @@ void TargetSettingsWidget::setCurrentSubIndex(int index)
m_targetSelector->setCurrentSubIndex(index);
}
void TargetSettingsWidget::setAddButtonEnabled(bool enabled)
{
m_targetSelector->setAddButtonEnabled(enabled);
}
void TargetSettingsWidget::setRemoveButtonEnabled(bool enabled)
{
m_targetSelector->setRemoveButtonEnabled(enabled);
}
QString TargetSettingsWidget::targetNameAt(int index) const
{
return m_targetSelector->targetAt(index).name;
......@@ -78,6 +90,16 @@ int TargetSettingsWidget::currentSubIndex() const
return m_targetSelector->currentSubIndex();
}
bool TargetSettingsWidget::isAddButtonEnabled() const
{
return m_targetSelector->isAddButtonEnabled();
}
bool TargetSettingsWidget::isRemoveButtonEnabled() const
{
return m_targetSelector->isRemoveButtonEnabled();
}
void TargetSettingsWidget::updateTargetSelector()
{
m_targetSelector->setGeometry((WIDTH-m_targetSelector->minimumSizeHint().width())/2, 12,
......
......@@ -25,15 +25,21 @@ public:
int currentIndex() const;
int currentSubIndex() const;
bool isAddButtonEnabled() const;
bool isRemoveButtonEnabled() const;
public slots:
void addTarget(const QString &name);
void markActive(int index);
void removeTarget(int index);
void setCurrentIndex(int index);
void setCurrentSubIndex(int index);
void setAddButtonEnabled(bool enabled);
void setRemoveButtonEnabled(bool enabled);
signals:
void addButtonClicked();
void removeButtonClicked();
void currentIndexChanged(int targetIndex, int subIndex);
protected:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment