Commit c4d1553d authored by Daniel Molkentin's avatar Daniel Molkentin

Add first version of a new sidebar, including project selector.

The project selector also allows to select targets.
However, this is not yet used, since the necessary
changes are still being stabilized.

Done-with: con
parent e3675e9a
......@@ -33,6 +33,8 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QSettings>
#include <QtGui/QStatusBar>
namespace Core {
namespace Internal {
......@@ -179,6 +181,11 @@ QMainWindow *CoreImpl::mainWindow() const
return m_mainwindow;
}
QStatusBar *CoreImpl::statusBar() const
{
return m_mainwindow->statusBar();
}
// adds and removes additional active contexts, this context is appended to the
// currently active contexts. call updateContext after changing
void CoreImpl::addAdditionalContext(int context)
......
......@@ -79,6 +79,7 @@ public:
IContext *currentContextObject() const;
QMainWindow *mainWindow() const;
QStatusBar *statusBar() const;
// adds and removes additional active contexts, this context is appended to the
// currently active contexts. call updateContext after changing
......
/**************************************************************************
/********************Q******************************************************
**
** This file is part of Qt Creator
**
......@@ -29,53 +29,25 @@
#include "fancyactionbar.h"
#include <utils/stylehelper.h>
#include <coreplugin/icore.h>
#include <coreplugin/mainwindow.h>
#include <QtGui/QHBoxLayout>
#include <QtGui/QPainter>
#include <QtGui/QPicture>
#include <QtGui/QVBoxLayout>
#include <QtSvg/QSvgRenderer>
#include <QtGui/QAction>
#include <QtGui/QStatusBar>
#include <QtGui/QStyle>
#include <QtGui/QStyleOption>
using namespace Core;
using namespace Internal;
static const char* const svgIdButtonBase = "ButtonBase";
static const char* const svgIdButtonNormalBase = "ButtonNormalBase";
static const char* const svgIdButtonNormalOverlay = "ButtonNormalOverlay";
static const char* const svgIdButtonPressedBase = "ButtonPressedBase";
static const char* const svgIdButtonPressedOverlay = "ButtonPressedOverlay";
static const char* const svgIdButtonDisabledOverlay = "ButtonDisabledOverlay";
static const char* const svgIdButtonHoverOverlay = "ButtonHoverOverlay";
static const char* const elementsSvgIds[] = {
svgIdButtonBase,
svgIdButtonNormalBase,
svgIdButtonNormalOverlay,
svgIdButtonPressedBase,
svgIdButtonPressedOverlay,
svgIdButtonDisabledOverlay,
svgIdButtonHoverOverlay
};
const QMap<QString, QPicture> &buttonElementsMap()
{
static QMap<QString, QPicture> result;
if (result.isEmpty()) {
QSvgRenderer renderer(QLatin1String(":/fancyactionbar/images/fancytoolbutton.svg"));
for (size_t i = 0; i < sizeof(elementsSvgIds)/sizeof(elementsSvgIds[0]); i++) {
QString elementId(elementsSvgIds[i]);
QPicture elementPicture;
QPainter elementPainter(&elementPicture);
renderer.render(&elementPainter, elementId);
result.insert(elementId, elementPicture);
}
}
return result;
}
FancyToolButton::FancyToolButton(QWidget *parent)
: QToolButton(parent)
, m_buttonElements(buttonElementsMap())
{
setAttribute(Qt::WA_Hover, true);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
......@@ -85,40 +57,99 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
QPainter p(this);
QSize sh(sizeHint());
double scale = (double)height() / sh.height();
if (scale < 1) {
p.save();
p.scale(1, scale);
}
p.drawPicture(0, 0, m_buttonElements.value(svgIdButtonBase));
p.drawPicture(0, 0, m_buttonElements.value(isDown() ? svgIdButtonPressedBase : svgIdButtonNormalBase));
QLayout *parentLayout = qobject_cast<FancyActionBar*>(parentWidget())->actionsLayout();
int lineHeight = fontMetrics().height();
bool isTitledAction = defaultAction()->property("titledAction").toBool();
#ifndef Q_WS_MAC // Mac UIs usually don't hover
if (underMouse() && isEnabled())
p.drawPicture(0, 0, m_buttonElements.value(svgIdButtonHoverOverlay));
if (underMouse() && isEnabled() && !isDown()) {
QColor whiteOverlay(Qt::white);
whiteOverlay.setAlpha(20);
p.fillRect(rect().adjusted(1, 1, -1, -1), whiteOverlay);
}
#endif
if (scale < 1)
p.restore();
if (isDown()) {
QColor whiteOverlay(Qt::black);
whiteOverlay.setAlpha(20);
p.fillRect(rect().adjusted(1, 1, -1, -1), whiteOverlay);
}
if (!icon().isNull()) {
icon().paint(&p, rect());
} else {
const int margin = 4;
p.drawText(rect().adjusted(margin, margin, -margin, -margin), Qt::AlignCenter | Qt::TextWordWrap, text());
QPixmap borderPixmap;
QMargins margins;
if (parentLayout && parentLayout->count() > 0 &&
parentLayout->itemAt(parentLayout->count()-1)->widget() == this) {
margins = QMargins(3, 3, 2, 0);
borderPixmap = QPixmap(
QLatin1String(":/fancyactionbar/images/fancytoolbutton_bottom_outline.png"));
} else if (parentLayout && parentLayout->count() > 0 &&
parentLayout->itemAt(0)->widget() == this) {
margins = QMargins(3, 3, 2, 3);
borderPixmap = QPixmap(
QLatin1String(":/fancyactionbar/images/fancytoolbutton_top_outline.png"));
} else {
margins = QMargins(3, 3, 2, 0);
borderPixmap = QPixmap(
QLatin1String(":/fancyactionbar/images/fancytoolbutton_normal_outline.png"));
}
QRect drawRect = rect();
qDrawBorderPixmap(&p, drawRect, margins, borderPixmap);
QPixmap pix = icon().pixmap(size() - QSize(15, 15), isEnabled() ? QIcon::Normal : QIcon::Disabled);
QPoint center = rect().center();
QSize halfPixSize = pix.size()/2;
p.drawPixmap(center-QPoint(halfPixSize.width()-1, halfPixSize.height()-1), pix);
if (popupMode() == QToolButton::DelayedPopup && !isTitledAction) {
QPoint arrowOffset = center + QPoint(pix.rect().width()/2, pix.rect().height()/2);
QStyleOption opt;
if (isEnabled())
opt.state &= QStyle::State_Enabled;
else
opt.state |= QStyle::State_Enabled;
opt.rect = QRect(arrowOffset.x(), arrowOffset.y(), 6, 6);
style()->drawPrimitive(QStyle::PE_IndicatorArrowDown,
&opt, &p, this);
}
if (scale < 1) {
p.scale(1, scale);
if (isTitledAction) {
QRect r(0, lineHeight/2, rect().width(), lineHeight);
QColor penColor;
if (isEnabled())
penColor = Qt::white;
else
penColor = Qt::gray;
p.setPen(penColor);
const QString projectName = defaultAction()->property("heading").toString();
QFont f = font();
f.setPointSize(f.pointSize()-1);
p.setFont(f);
QFontMetrics fm(f);
QString ellidedProjectName = fm.elidedText(projectName, Qt::ElideMiddle, r.width());
if (isEnabled()) {
const QRect shadowR = r.translated(0, 1);
p.setPen(Qt::black);
p.drawText(shadowR, Qt::AlignVCenter|Qt::AlignHCenter, ellidedProjectName);
p.setPen(penColor);
}
p.drawText(r, Qt::AlignVCenter|Qt::AlignHCenter, ellidedProjectName);
r = QRect(0, rect().bottom()-lineHeight*1.5, rect().width(), lineHeight);
const QString buildConfiguration = defaultAction()->property("subtitle").toString();
f.setBold(true);
p.setFont(f);
QString ellidedBuildConfiguration = fm.elidedText(buildConfiguration, Qt::ElideMiddle, r.width());
if (isEnabled()) {
const QRect shadowR = r.translated(0, 1);
p.setPen(Qt::black);
p.drawText(shadowR, Qt::AlignVCenter|Qt::AlignHCenter, ellidedBuildConfiguration);
p.setPen(penColor);
}
p.drawText(r, Qt::AlignVCenter|Qt::AlignHCenter, ellidedBuildConfiguration);
}
if (isEnabled()) {
p.drawPicture(0, 0, m_buttonElements.value(isDown() ?
svgIdButtonPressedOverlay : svgIdButtonNormalOverlay));
} else {
p.drawPicture(0, 0, m_buttonElements.value(svgIdButtonDisabledOverlay));
}
}
void FancyActionBar::paintEvent(QPaintEvent *event)
......@@ -128,7 +159,12 @@ void FancyActionBar::paintEvent(QPaintEvent *event)
QSize FancyToolButton::sizeHint() const
{
return m_buttonElements.value(svgIdButtonBase).boundingRect().size();
QSize buttonSize = iconSize().expandedTo(QSize(64, 40));
if (defaultAction()->property("titledAction").toBool()) {
int lineHeight = fontMetrics().height();
buttonSize += QSize(0, lineHeight*4);
}
return buttonSize;
}
QSize FancyToolButton::minimumSizeHint() const
......@@ -149,13 +185,30 @@ FancyActionBar::FancyActionBar(QWidget *parent)
{
m_actionsLayout = new QVBoxLayout;
QHBoxLayout *centeringLayout = new QHBoxLayout;
centeringLayout->addStretch();
centeringLayout->addLayout(m_actionsLayout);
centeringLayout->addStretch();
setLayout(centeringLayout);
QVBoxLayout *spacerLayout = new QVBoxLayout;
spacerLayout->addLayout(m_actionsLayout);
int sbh = ICore::instance()->statusBar()->height();
spacerLayout->addSpacing(sbh);
spacerLayout->setMargin(0);
spacerLayout->setSpacing(0);
QHBoxLayout *orientRightLayout = new QHBoxLayout;
orientRightLayout->addStretch();
orientRightLayout->setMargin(0);
orientRightLayout->setSpacing(0);
orientRightLayout->setContentsMargins(0, 0, 1, 0);
orientRightLayout->addLayout(spacerLayout);
setLayout(orientRightLayout);
}
void FancyActionBar::addProjectSelector(QAction *action)
{
FancyToolButton* toolButton = new FancyToolButton(this);
toolButton->setDefaultAction(action);
connect(action, SIGNAL(changed()), toolButton, SLOT(actionChanged()));
m_actionsLayout->insertWidget(0, toolButton);
}
void FancyActionBar::insertAction(int index, QAction *action, QMenu *menu)
{
FancyToolButton *toolButton = new FancyToolButton(this);
......@@ -187,3 +240,8 @@ void FancyActionBar::toolButtonContextMenuActionTriggered(QAction* action)
button->defaultAction()->trigger();
}
}
QLayout *FancyActionBar::actionsLayout() const
{
return m_actionsLayout;
}
......@@ -54,9 +54,6 @@ public:
private slots:
void actionChanged();
private:
const QMap<QString, QPicture> &m_buttonElements;
};
class FancyActionBar : public QWidget
......@@ -68,6 +65,8 @@ public:
void paintEvent(QPaintEvent *event);
void insertAction(int index, QAction *action, QMenu *menu = 0);
void addProjectSelector(QAction *action);
QLayout *actionsLayout() const;
private slots:
void toolButtonContextMenuActionTriggered(QAction*);
......
......@@ -6,5 +6,8 @@
<file>images/mode_Output.png</file>
<file>images/mode_Project.png</file>
<file>images/mode_Reference.png</file>
<file>images/fancytoolbutton_bottom_outline.png</file>
<file>images/fancytoolbutton_normal_outline.png</file>
<file>images/fancytoolbutton_top_outline.png</file>
</qresource>
</RCC>
......@@ -40,6 +40,7 @@ QT_BEGIN_NAMESPACE
class QMainWindow;
class QPrinter;
class QSettings;
class QStatusBar;
template <class T> class QList;
QT_END_NAMESPACE
......@@ -104,6 +105,7 @@ public:
virtual QString resourcePath() const = 0;
virtual QMainWindow *mainWindow() const = 0;
virtual QStatusBar *statusBar() const = 0;
// adds and removes additional active contexts, this context is appended to the
// currently active contexts. call updateContext after changing
......
......@@ -205,6 +205,11 @@ void ModeManager::addAction(Command *command, int priority, QMenu *menu)
m_actionBar->insertAction(index, command->action(), menu);
}
void ModeManager::addProjectSelector(QAction *action)
{
m_actionBar->addProjectSelector(action);
}
void ModeManager::currentTabAboutToChange(int index)
{
if (index >= 0) {
......
......@@ -38,6 +38,7 @@
#include <coreplugin/core_global.h>
QT_BEGIN_NAMESPACE
class QAction;
class QSignalMapper;
class QMenu;
QT_END_NAMESPACE
......@@ -50,6 +51,7 @@ class IMode;
namespace Internal {
class FancyTabWidget;
class FancyActionBar;
class FancyConfigButton;
class MainWindow;
} // namespace Internal
......@@ -67,6 +69,7 @@ public:
IMode* mode(const QString &id) const;
void addAction(Command *command, int priority, QMenu *menu = 0);
void addProjectSelector(QAction *action);
void addWidget(QWidget *widget);
signals:
......
......@@ -46,7 +46,6 @@ class CommandQObject;
}
}
Q_DECLARE_METATYPE(ProjectExplorer::Project*)
Q_DECLARE_METATYPE(QList<ProjectExplorer::Project*>)
Q_DECLARE_METATYPE(ProjectExplorer::SessionManager*)
Q_DECLARE_METATYPE(ProjectExplorer::IProjectManager*)
......
#include "miniprojecttargetselector.h"
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
#include <utils/stylehelper.h>
#include <coreplugin/icore.h>
#include <coreplugin/mainwindow.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <projectexplorer/project.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/buildconfiguration.h>
#include <QtGui/QLayout>
#include <QtGui/QFormLayout>
#include <QtGui/QLabel>
#include <QtGui/QComboBox>
#include <QtGui/QListWidget>
#include <QtGui/QStatusBar>
#include <QtGui/QStackedWidget>
#include <QDebug>
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
MiniTargetWidget::MiniTargetWidget(Project *project, QWidget *parent) :
QWidget(parent), m_project(project)
{
m_buildComboBox = new QComboBox;
m_buildComboBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
m_runComboBox = new QComboBox;
m_runComboBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
int fontSize = font().pointSize();
setStyleSheet(QString("QWidget { font-size: %1pt; color: white; } "
"QLabel#targetName { font-size: %2pt; font-weight: bold; } "
"QComboBox { background-color: transparent; margin: 0; border: none; } "
"QComboBox QWidget { background-color: %3 } "
"QComboBox::drop-down { border: none; }"
"QComboBox::down-arrow { image: url(:/welcome/images/combobox_arrow.png); } "
).arg(fontSize-1).arg(fontSize).arg(Utils::StyleHelper::baseColor().name()));
QGridLayout *gridLayout = new QGridLayout(this);
m_targetName = new QLabel(tr("Target"));
m_targetName->setObjectName(QLatin1String("targetName"));
m_targetIcon = new QLabel();
m_targetIcon->setPixmap(style()->standardIcon(QStyle::SP_ComputerIcon).pixmap(48, 48));
Q_FOREACH(BuildConfiguration* bc, project->buildConfigurations())
addBuildConfiguration(bc);
Q_FOREACH(RunConfiguration* rc, project->runConfigurations())
addRunConfiguration(rc);
connect(project, SIGNAL(addedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
SLOT(addBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
connect(project, SIGNAL(removedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
SLOT(addBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
connect(project, SIGNAL(addedRunConfiguration(ProjectExplorer::RunConfiguration*)),
SLOT(addRunConfiguration(ProjectExplorer::RunConfiguration*)));
connect(project, SIGNAL(removedRunConfiguration(ProjectExplorer::RunConfiguration*)),
SLOT(removeRunConfiguration(ProjectExplorer::RunConfiguration*)));
connect(m_buildComboBox, SIGNAL(currentIndexChanged(int)), SLOT(setActiveBuildConfiguration(int)));
connect(m_runComboBox, SIGNAL(currentIndexChanged(int)), SLOT(setActiveRunConfiguration(int)));
connect(project, SIGNAL(activeBuildConfigurationChanged()), SLOT(setActiveBuildConfiguration()));
connect(project, SIGNAL(activeRunConfigurationChanged()), SLOT(setActiveRunConfiguration()));
QHBoxLayout *runHelperLayout = new QHBoxLayout;
runHelperLayout->setMargin(0);
runHelperLayout->setSpacing(0);
QHBoxLayout *buildHelperLayout = new QHBoxLayout;
buildHelperLayout->setMargin(0);
buildHelperLayout->setSpacing(0);
buildHelperLayout->addWidget(m_buildComboBox);
runHelperLayout->addWidget(m_runComboBox);
QFormLayout *formLayout = new QFormLayout;
QLabel *lbl = new QLabel(tr("Build:"));
lbl->setIndent(6);
formLayout->addRow(lbl, buildHelperLayout);
lbl = new QLabel(tr("Run:"));
lbl->setIndent(6);
formLayout->addRow(lbl, runHelperLayout);
gridLayout->addWidget(m_targetName, 0, 0);
gridLayout->addWidget(m_targetIcon, 0, 1, 2, 1, Qt::AlignTop|Qt::AlignHCenter);
gridLayout->addLayout(formLayout, 1, 0);
}
void MiniTargetWidget::setActiveBuildConfiguration(int index)
{
ProjectExplorer::BuildConfiguration* bc =
m_buildComboBox->itemData(index).value<ProjectExplorer::BuildConfiguration*>();
m_project->setActiveBuildConfiguration(bc);
emit activeBuildConfigurationChanged(bc);
}
void MiniTargetWidget::setActiveRunConfiguration(int index)
{
m_project->setActiveRunConfiguration(
m_runComboBox->itemData(index).value<ProjectExplorer::RunConfiguration*>());
}
void MiniTargetWidget::setActiveBuildConfiguration()
{
m_buildComboBox->setCurrentIndex(m_buildComboBox->findData(
QVariant::fromValue(m_project->activeBuildConfiguration())));
}
void MiniTargetWidget::setActiveRunConfiguration()
{
m_runComboBox->setCurrentIndex(m_runComboBox->findData(
QVariant::fromValue(m_project->activeRunConfiguration())));
}
void MiniTargetWidget::addRunConfiguration(ProjectExplorer::RunConfiguration* runConfig)
{
connect(runConfig, SIGNAL(displayNameChanged()), SLOT(updateDisplayName()));
m_runComboBox->addItem(runConfig->displayName(), QVariant::fromValue(runConfig));
if (m_project->activeRunConfiguration() == runConfig)
m_runComboBox->setCurrentIndex(m_runComboBox->count()-1);
}
void MiniTargetWidget::removeRunConfiguration(ProjectExplorer::RunConfiguration* runConfig)
{
m_runComboBox->removeItem(m_runComboBox->findData(QVariant::fromValue(runConfig)));
}
void MiniTargetWidget::addBuildConfiguration(ProjectExplorer::BuildConfiguration* buildConfig)
{
connect(buildConfig, SIGNAL(displayNameChanged()), SLOT(updateDisplayName()));
m_buildComboBox->addItem(buildConfig->displayName(), QVariant::fromValue(buildConfig));
if (m_project->activeBuildConfiguration() == buildConfig)
m_buildComboBox->setCurrentIndex(m_buildComboBox->count()-1);
}
void MiniTargetWidget::removeBuildConfiguration(ProjectExplorer::BuildConfiguration* buildConfig)
{
m_buildComboBox->removeItem(m_buildComboBox->findData(QVariant::fromValue(buildConfig)));
}
void MiniTargetWidget::updateDisplayName()
{
QObject *obj = sender();
if (RunConfiguration* runConfig = qobject_cast<RunConfiguration*>(obj))
{
m_runComboBox->setItemText(m_runComboBox->findData(QVariant::fromValue(runConfig)),
runConfig->displayName());
} else if (BuildConfiguration* buildConfig = qobject_cast<BuildConfiguration*>(obj))
{
m_buildComboBox->setItemText(m_buildComboBox->findData(QVariant::fromValue(buildConfig)),
buildConfig->displayName());
}
}
MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorAction, QWidget *parent) :
QWidget(parent), m_projectAction(targetSelectorAction)
{
setWindowFlags(Qt::Popup);
setFocusPolicy(Qt::NoFocus);
targetSelectorAction->setIcon(style()->standardIcon(QStyle::SP_ComputerIcon));
targetSelectorAction->setProperty("titledAction", true);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);
Utils::StyledBar *bar = new Utils::StyledBar;
bar->setSingleRow(true);
layout->addWidget(bar);
QHBoxLayout *toolLayout = new QHBoxLayout(bar);
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
QLabel *lbl = new QLabel(tr("Project"));
lbl->setIndent(6);
QFont f = lbl->font();
f.setBold(true);
lbl->setFont(f);
m_projectsBox = new QComboBox;
m_projectsBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
m_projectsBox->setMaximumWidth(200);
toolLayout->addWidget(lbl);
toolLayout->addWidget(new Utils::StyledSeparator);
toolLayout->addWidget(m_projectsBox);
m_widgetStack = new QStackedWidget;
m_widgetStack->setFocusPolicy(Qt::NoFocus);
layout->addWidget(m_widgetStack);
connect(m_projectsBox, SIGNAL(activated(int)), this, SLOT(emitStartupProjectChanged(int)));
}
void MiniProjectTargetSelector::setVisible(bool visible)
{
if (visible) {
resize(sizeHint());
QStatusBar *statusBar = Core::ICore::instance()->statusBar();