diff --git a/src/plugins/projectexplorer/images/targetbuildselected.png b/src/plugins/projectexplorer/images/targetbuildselected.png new file mode 100644 index 0000000000000000000000000000000000000000..f1cf44c08b97cd29655a9af67f07e772a195060a Binary files /dev/null and b/src/plugins/projectexplorer/images/targetbuildselected.png differ diff --git a/src/plugins/projectexplorer/images/targetrunselected.png b/src/plugins/projectexplorer/images/targetrunselected.png new file mode 100644 index 0000000000000000000000000000000000000000..228287b3e102ade477734619d48d60bb15fe0427 Binary files /dev/null and b/src/plugins/projectexplorer/images/targetrunselected.png differ diff --git a/src/plugins/projectexplorer/images/targetseparatorbackground.png b/src/plugins/projectexplorer/images/targetseparatorbackground.png new file mode 100644 index 0000000000000000000000000000000000000000..ff14f0d6737a1e08d2ea6444a34d76aaf7a12511 Binary files /dev/null and b/src/plugins/projectexplorer/images/targetseparatorbackground.png differ diff --git a/src/plugins/projectexplorer/images/targetunselected.png b/src/plugins/projectexplorer/images/targetunselected.png new file mode 100644 index 0000000000000000000000000000000000000000..2df56444182b87e036c7c3343e73e183663d4bf7 Binary files /dev/null and b/src/plugins/projectexplorer/images/targetunselected.png differ diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro index da492ea272d1d7284180020571ce1dffdb52c078..981a42da11a9d60f0e7c883fc8b83cc8fe982685 100644 --- a/src/plugins/projectexplorer/projectexplorer.pro +++ b/src/plugins/projectexplorer/projectexplorer.pro @@ -66,7 +66,9 @@ HEADERS += projectexplorer.h \ projectexplorersettingspage.h \ projectwelcomepage.h \ projectwelcomepagewidget.h \ - baseprojectwizarddialog.h + baseprojectwizarddialog.h \ + targetselector.h \ + targetsettingswidget.h SOURCES += projectexplorer.cpp \ projectwindow.cpp \ buildmanager.cpp \ @@ -120,7 +122,9 @@ SOURCES += projectexplorer.cpp \ projectwelcomepage.cpp \ projectwelcomepagewidget.cpp \ corelistenercheckingforrunningbuild.cpp \ - baseprojectwizarddialog.cpp + baseprojectwizarddialog.cpp \ + targetselector.cpp \ + targetsettingswidget.cpp FORMS += processstep.ui \ editorsettingspropertiespage.ui \ runsettingspropertiespage.ui \ @@ -128,7 +132,8 @@ FORMS += processstep.ui \ projectwizardpage.ui \ removefiledialog.ui \ projectexplorersettingspage.ui \ - projectwelcomepagewidget.ui + projectwelcomepagewidget.ui \ + targetsettingswidget.ui win32 { SOURCES += applicationlauncher_win.cpp \ diff --git a/src/plugins/projectexplorer/projectexplorer.qrc b/src/plugins/projectexplorer/projectexplorer.qrc index a9e1b3488ef87e86122d933edbe2af22cbf336ef..2c1f8f1683e701b02b882971fd9ed6366b78863e 100644 --- a/src/plugins/projectexplorer/projectexplorer.qrc +++ b/src/plugins/projectexplorer/projectexplorer.qrc @@ -1,5 +1,5 @@ <RCC> - <qresource prefix="/projectexplorer" > + <qresource prefix="/projectexplorer"> <file>images/build.png</file> <file>images/build_small.png</file> <file>images/clean.png</file> @@ -19,5 +19,9 @@ <file>images/run_small.png</file> <file>images/session.png</file> <file>images/stop.png</file> + <file>images/targetbuildselected.png</file> + <file>images/targetrunselected.png</file> + <file>images/targetseparatorbackground.png</file> + <file>images/targetunselected.png</file> </qresource> </RCC> diff --git a/src/plugins/projectexplorer/targetselector.cpp b/src/plugins/projectexplorer/targetselector.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1a14de2e3eeace062f8dd15fb5f75d991f12d6bb --- /dev/null +++ b/src/plugins/projectexplorer/targetselector.cpp @@ -0,0 +1,129 @@ +#include "targetselector.h" + +#include <QtGui/QPainter> +#include <QtGui/QMouseEvent> +#include <QtGui/QFontMetrics> + +static const int TARGET_WIDTH = 109; +static const int TARGET_HEIGHT = 43; +static const int ADDBUTTON_WIDTH = 27; + +using namespace ProjectExplorer::Internal; + +TargetSelector::TargetSelector(QWidget *parent) : + QWidget(parent), + m_currentTargetIndex(-1) +{ + QFont f = font(); + f.setPixelSize(10); + f.setBold(true); + setFont(f); +} + +void TargetSelector::addTarget(const QString &name) +{ + Target target; + target.name = name; + target.currentSubIndex = 0; + m_targets.append(target); + if (m_currentTargetIndex == -1) + m_currentTargetIndex = m_targets.size() - 1; + update(); +} + +void TargetSelector::removeTarget(int index) +{ + m_targets.removeAt(index); + update(); +} + +TargetSelector::Target TargetSelector::targetAt(int index) const +{ + return m_targets.at(index); +} + +QSize TargetSelector::minimumSizeHint() const +{ + return QSize((TARGET_WIDTH + 1) * m_targets.size() + ADDBUTTON_WIDTH + 2, TARGET_HEIGHT + 2); +} + +void TargetSelector::mousePressEvent(QMouseEvent *event) +{ + if (event->x() > (TARGET_WIDTH + 1) * m_targets.size()) { + // check for add button + event->accept(); + emit addButtonClicked(); + } else { + // find the clicked target button + int x = 1; + int index; + for (index = 0; index < m_targets.size(); ++index) { + if (event->x() <= x) { + break; + } + x += TARGET_WIDTH + 1; + } + --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() - (TARGET_WIDTH + 1) * index) - 2 > TARGET_WIDTH / 2) { + m_targets[index].currentSubIndex = 1; + } else { + m_targets[index].currentSubIndex = 0; + } + } + m_currentTargetIndex = index; + //TODO don't emit if nothing changed! + update(); + emit currentIndexChanged(m_currentTargetIndex, m_targets.at(m_currentTargetIndex).currentSubIndex); + } else { + event->ignore(); + } + } +} + +void TargetSelector::paintEvent(QPaintEvent *event) +{ + static QPixmap unselected(":/projectexplorer/targetunselected.png"); + static QPixmap runselected(":/projectexplorer/targetrunselected.png"); + static QPixmap buildselected(":/projectexplorer/targetbuildselected.png"); + static QPixmap targetaddbutton(":/projectexplorer/targetaddbutton.png"); + 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() - 1, size.width() - 2, size.height() - 1); + p.drawLine(0, 1, 0, size.height() - 2); + p.drawLine(size.width() - 1, 1, size.width() - 1, size.height() - 2); + //draw targets + int x = 1; + int index = 0; + QFontMetrics fm(font()); + foreach (const Target &target, m_targets) { + QPixmap *pixmap = &unselected; + if (index == m_currentTargetIndex) { + p.setPen(QColor(255, 255, 255)); + if (target.currentSubIndex == 0) { + pixmap = &buildselected; + } else { + pixmap = &runselected; + } + } else { + p.setPen(QColor(0, 0, 0)); + } + p.drawPixmap(x, 1, *pixmap); + p.drawText(x + (TARGET_WIDTH - fm.width(target.name))/2 + 1, 7 + fm.ascent(), + target.name); + x += TARGET_WIDTH; + p.drawLine(x, 1, x, TARGET_HEIGHT); + ++x; + ++index; + } + // draw add button + p.drawPixmap(x, 1, targetaddbutton); +} diff --git a/src/plugins/projectexplorer/targetselector.h b/src/plugins/projectexplorer/targetselector.h new file mode 100644 index 0000000000000000000000000000000000000000..212f25949680cb0483b3424d023b92bdd41426b5 --- /dev/null +++ b/src/plugins/projectexplorer/targetselector.h @@ -0,0 +1,48 @@ +#ifndef TARGETSELECTOR_H +#define TARGETSELECTOR_H + +#include <QWidget> + +namespace ProjectExplorer { +namespace Internal { + +class TargetSelector : public QWidget +{ +Q_OBJECT +public: + struct Target { + QString name; + int currentSubIndex; + }; + + explicit TargetSelector(QWidget *parent = 0); + + QSize minimumSizeHint() const; + + Target targetAt(int index) const; + int targetCount() const { return m_targets.size(); } + int currentIndex() const { return m_currentTargetIndex; } + int currentSubIndex() const { return m_targets.at(m_currentTargetIndex).currentSubIndex; } + +public slots: + void addTarget(const QString &name); + void removeTarget(int index); + +signals: + void addButtonClicked(); + void currentIndexChanged(int targetIndex, int subIndex); + +protected: + void paintEvent(QPaintEvent *event); + void mousePressEvent(QMouseEvent *event); + +private: + QList<Target> m_targets; + + int m_currentTargetIndex; +}; + +} // namespace Internal +} // namespace ProjectExplorer + +#endif // TARGETSELECTOR_H diff --git a/src/plugins/projectexplorer/targetsettingswidget.cpp b/src/plugins/projectexplorer/targetsettingswidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6a45a4f9ed47cde9b8e144f8a7927b6608109edc --- /dev/null +++ b/src/plugins/projectexplorer/targetsettingswidget.cpp @@ -0,0 +1,83 @@ +#include "targetsettingswidget.h" +#include "ui_targetsettingswidget.h" + +static int WIDTH = 750; + +using namespace ProjectExplorer::Internal; + +TargetSettingsWidget::TargetSettingsWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::TargetSettingsWidget), + m_targetSelector(new TargetSelector(this)) +{ + ui->setupUi(this); + ui->separator->setStyleSheet(QLatin1String("* { " + "background-image: url(:/projectexplorer/images/targetseparatorbackground.png);" + "}")); + m_targetSelector->raise(); + connect(m_targetSelector, SIGNAL(addButtonClicked()), + this, SIGNAL(addButtonClicked())); + connect(m_targetSelector, SIGNAL(currentIndexChanged(int,int)), + this, SIGNAL(currentIndexChanged(int,int))); + updateTargetSelector(); +} + +TargetSettingsWidget::~TargetSettingsWidget() +{ + delete ui; +} + +void TargetSettingsWidget::addTarget(const QString &name) +{ + m_targetSelector->addTarget(name); + updateTargetSelector(); +} + +void TargetSettingsWidget::removeTarget(int index) +{ + m_targetSelector->removeTarget(index); +} + +QString TargetSettingsWidget::targetNameAt(int index) const +{ + return m_targetSelector->targetAt(index).name; +} + +void TargetSettingsWidget::setCentralWidget(QWidget *widget) +{ + ui->scrollArea->setWidget(widget); +} + +int TargetSettingsWidget::targetCount() const +{ + return m_targetSelector->targetCount(); +} + +int TargetSettingsWidget::currentIndex() const +{ + return m_targetSelector->currentIndex(); +} + +int TargetSettingsWidget::currentSubIndex() const +{ + return m_targetSelector->currentSubIndex(); +} + +void TargetSettingsWidget::updateTargetSelector() +{ + m_targetSelector->setGeometry((WIDTH-m_targetSelector->minimumSizeHint().width())/2, 12, + m_targetSelector->minimumSizeHint().width(), + m_targetSelector->minimumSizeHint().height()); +} + +void TargetSettingsWidget::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} diff --git a/src/plugins/projectexplorer/targetsettingswidget.h b/src/plugins/projectexplorer/targetsettingswidget.h new file mode 100644 index 0000000000000000000000000000000000000000..ca4d8b26eaaed898b8a22b7741268c659b6729c1 --- /dev/null +++ b/src/plugins/projectexplorer/targetsettingswidget.h @@ -0,0 +1,49 @@ +#ifndef TARGETSETTINGSWIDGET_H +#define TARGETSETTINGSWIDGET_H + +#include "targetselector.h" + +#include <QWidget> + +namespace ProjectExplorer { +namespace Internal { + +namespace Ui { + class TargetSettingsWidget; +} + +class TargetSettingsWidget : public QWidget { + Q_OBJECT +public: + explicit TargetSettingsWidget(QWidget *parent = 0); + ~TargetSettingsWidget(); + + void setCentralWidget(QWidget *widget); + + QString targetNameAt(int index) const; + int targetCount() const; + int currentIndex() const; + int currentSubIndex() const; + +public slots: + void addTarget(const QString &name); + void removeTarget(int index); + +signals: + void addButtonClicked(); + void currentIndexChanged(int targetIndex, int subIndex); + +protected: + void changeEvent(QEvent *e); + +private: + void updateTargetSelector(); + Ui::TargetSettingsWidget *ui; + + TargetSelector *m_targetSelector; +}; + +} // namespace Internal +} // namespace ProjectExplorer + +#endif // TARGETSETTINGSWIDGET_H diff --git a/src/plugins/projectexplorer/targetsettingswidget.ui b/src/plugins/projectexplorer/targetsettingswidget.ui new file mode 100644 index 0000000000000000000000000000000000000000..64f25f70a9655653271d7b801f6068161edbeb0d --- /dev/null +++ b/src/plugins/projectexplorer/targetsettingswidget.ui @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ProjectExplorer::Internal::TargetSettingsWidget</class> + <widget class="QWidget" name="ProjectExplorer::Internal::TargetSettingsWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>618</width> + <height>454</height> + </rect> + </property> + <property name="windowTitle"> + <string>TargetSettingsWidget</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="spacing"> + <number>0</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <widget class="QWidget" name="separator" native="true"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>50</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>50</height> + </size> + </property> + </widget> + </item> + <item> + <widget class="QScrollArea" name="scrollArea"> + <property name="widgetResizable"> + <bool>true</bool> + </property> + <widget class="QWidget" name="scrollAreaWidgetContents"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>614</width> + <height>400</height> + </rect> + </property> + </widget> + </widget> + </item> + </layout> + </widget> + <layoutdefault spacing="6" margin="11"/> + <resources/> + <connections/> +</ui>