Commit 7af1e211 authored by Jens Bache-Wiig's avatar Jens Bache-Wiig

Improved styling of project target selector

parent 8fbf0dd0
......@@ -352,4 +352,46 @@ void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const Q
}
}
// Draws a CSS-like border image where the defined borders are not stretched
void StyleHelper::drawCornerImage(const QImage &img, QPainter *painter, QRect rect,
int left, int top, int right, int bottom)
{
QSize size = img.size();
if (top > 0) { //top
painter->drawImage(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), img,
QRect(left, 0, size.width() -right - left, top));
if (left > 0) //top-left
painter->drawImage(QRect(rect.left(), rect.top(), left, top), img,
QRect(0, 0, left, top));
if (right > 0) //top-right
painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top(), right, top), img,
QRect(size.width() - right, 0, right, top));
}
//left
if (left > 0)
painter->drawImage(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), img,
QRect(0, top, left, size.height() - bottom - top));
//center
painter->drawImage(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left,
rect.height() - bottom - top), img,
QRect(left, top, size.width() -right -left,
size.height() - bottom - top));
if (right > 0) //right
painter->drawImage(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), img,
QRect(size.width() - right, top, right, size.height() - bottom - top));
if (bottom > 0) { //bottom
painter->drawImage(QRect(rect.left() +left, rect.top() + rect.height() - bottom,
rect.width() - right - left, bottom), img,
QRect(left, size.height() - bottom,
size.width() - right - left, bottom));
if (left > 0) //bottom-left
painter->drawImage(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), img,
QRect(0, size.height() - bottom, left, bottom));
if (right > 0) //bottom-right
painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), img,
QRect(size.width() - right, size.height() - bottom, right, bottom));
}
}
} // namespace Utils
......@@ -78,6 +78,9 @@ public:
// Pixmap cache should only be enabled for X11 due to slow gradients
static bool usePixmapCache() { return true; }
static void drawCornerImage(const QImage &img, QPainter *painter, QRect rect,
int left = 0, int top = 0, int right = 0, int bottom = 0);
private:
static QColor m_baseColor;
};
......
......@@ -225,6 +225,7 @@ void FancyToolButton::actionChanged()
FancyActionBar::FancyActionBar(QWidget *parent)
: QWidget(parent)
{
setObjectName(QString::fromUtf8("actionbar"));
m_actionsLayout = new QVBoxLayout;
QVBoxLayout *spacerLayout = new QVBoxLayout;
spacerLayout->addLayout(m_actionsLayout);
......
......@@ -293,6 +293,10 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
painter->restore();
}
#endif
if (!enabled)
painter->setOpacity(0.7);
int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height();
tabIconRect.adjust(0, 4, 0, -textHeight);
int iconSize = qMin(tabIconRect.width(), tabIconRect.height());
......
......@@ -88,7 +88,6 @@ bool panelWidget(const QWidget *widget)
while (p) {
if (qobject_cast<const QToolBar *>(p) ||
qobject_cast<const QStatusBar *>(p) ||
qobject_cast<const QAbstractItemView *>(p) ||
qobject_cast<const QMenuBar *>(p))
return styleEnabled(widget);
if (p->property("panelwidget").toBool())
......@@ -151,48 +150,6 @@ ManhattanStyle::~ManhattanStyle()
d = 0;
}
// Draws a CSS-like border image where the defined borders are not stretched
void drawCornerImage(const QImage &img, QPainter *painter, QRect rect,
int left = 0, int top = 0, int right = 0,
int bottom = 0)
{
QSize size = img.size();
if (top > 0) { //top
painter->drawImage(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), img,
QRect(left, 0, size.width() -right - left, top));
if (left > 0) //top-left
painter->drawImage(QRect(rect.left(), rect.top(), left, top), img,
QRect(0, 0, left, top));
if (right > 0) //top-right
painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top(), right, top), img,
QRect(size.width() - right, 0, right, top));
}
//left
if (left > 0)
painter->drawImage(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), img,
QRect(0, top, left, size.height() - bottom - top));
//center
painter->drawImage(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left,
rect.height() - bottom - top), img,
QRect(left, top, size.width() -right -left,
size.height() - bottom - top));
if (right > 0) //right
painter->drawImage(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), img,
QRect(size.width() - right, top, right, size.height() - bottom - top));
if (bottom > 0) { //bottom
painter->drawImage(QRect(rect.left() +left, rect.top() + rect.height() - bottom,
rect.width() - right - left, bottom), img,
QRect(left, size.height() - bottom,
size.width() - right - left, bottom));
if (left > 0) //bottom-left
painter->drawImage(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), img,
QRect(0, size.height() - bottom, left, bottom));
if (right > 0) //bottom-right
painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), img,
QRect(size.width() - right, size.height() - bottom, right, bottom));
}
}
QPixmap ManhattanStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const
{
return QProxyStyle::generatedIconPixmap(iconMode, pixmap, opt);
......@@ -464,27 +421,6 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
}
switch (element) {
/*
case PE_PanelItemViewItem:
if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) {
if (vopt->state & State_Selected) {
QLinearGradient gradient;
gradient.setStart(option->rect.topLeft());
gradient.setFinalStop(option->rect.bottomRight());
gradient.setColorAt(0, option->palette.highlight().color().lighter(115));
gradient.setColorAt(1, option->palette.highlight().color().darker(135));
painter->fillRect(option->rect, gradient);
} else {
if (vopt->backgroundBrush.style() != Qt::NoBrush) {
QPointF oldBO = painter->brushOrigin();
painter->setBrushOrigin(vopt->rect.topLeft());
painter->fillRect(vopt->rect, vopt->backgroundBrush);
painter->setBrushOrigin(oldBO);
}
}
}
break;
*/
case PE_PanelLineEdit:
{
painter->save();
......@@ -495,9 +431,9 @@ case PE_PanelItemViewItem:
painter->fillRect(filledRect, option->palette.base());
if (option->state & State_Enabled)
drawCornerImage(d->lineeditImage, painter, option->rect, 5, 5, 5, 5);
Utils::StyleHelper::drawCornerImage(d->lineeditImage, painter, option->rect, 5, 5, 5, 5);
else
drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 5, 5, 5, 5);
Utils::StyleHelper::drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 5, 5, 5, 5);
if (option->state & State_HasFocus || option->state & State_MouseOver) {
QColor hover = Utils::StyleHelper::baseColor();
......@@ -945,29 +881,34 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
painter->save();
bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull();
bool reverse = option->direction == Qt::RightToLeft;
bool drawborder = !(widget && widget->property("hideborder").toBool());
bool alignarrow = !(widget && widget->property("alignarrow").toBool());
// Draw tool button
QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight());
grad.setColorAt(0, QColor(255, 255, 255, 20));
grad.setColorAt(0.4, QColor(255, 255, 255, 60));
grad.setColorAt(0.7, QColor(255, 255, 255, 50));
grad.setColorAt(1, QColor(255, 255, 255, 40));
painter->setPen(QPen(grad, 0));
painter->drawLine(rect.topRight(), rect.bottomRight());
grad.setColorAt(0, QColor(0, 0, 0, 30));
grad.setColorAt(0.4, QColor(0, 0, 0, 70));
grad.setColorAt(0.7, QColor(0, 0, 0, 70));
grad.setColorAt(1, QColor(0, 0, 0, 40));
painter->setPen(QPen(grad, 0));
if (!reverse)
painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0));
else
painter->drawLine(rect.topLeft(), rect.bottomLeft());
if (drawborder) {
QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight());
grad.setColorAt(0, QColor(255, 255, 255, 20));
grad.setColorAt(0.4, QColor(255, 255, 255, 60));
grad.setColorAt(0.7, QColor(255, 255, 255, 50));
grad.setColorAt(1, QColor(255, 255, 255, 40));
painter->setPen(QPen(grad, 0));
painter->drawLine(rect.topRight(), rect.bottomRight());
grad.setColorAt(0, QColor(0, 0, 0, 30));
grad.setColorAt(0.4, QColor(0, 0, 0, 70));
grad.setColorAt(0.7, QColor(0, 0, 0, 70));
grad.setColorAt(1, QColor(0, 0, 0, 40));
painter->setPen(QPen(grad, 0));
if (!reverse)
painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0));
else
painter->drawLine(rect.topLeft(), rect.bottomLeft());
}
QStyleOption toolbutton = *option;
if (isEmpty)
toolbutton.state &= ~(State_Enabled | State_Sunken);
painter->save();
painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0));
if (drawborder)
painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0));
drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget);
painter->restore();
// Draw arrow
......@@ -975,6 +916,11 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
int left = !reverse ? rect.right() - menuButtonWidth : rect.left();
int right = !reverse ? rect.right() : rect.left() + menuButtonWidth;
QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9);
if (!alignarrow) {
int leftOffset = option->fontMetrics.width(cb->currentText) + 12;
arrowRect.moveLeft(leftOffset);
}
if (option->state & State_On)
arrowRect.translate(QProxyStyle::pixelMetric(PM_ButtonShiftHorizontal, option, widget),
QProxyStyle::pixelMetric(PM_ButtonShiftVertical, option, widget));
......
......@@ -52,6 +52,7 @@
#include <QtGui/QStackedWidget>
#include <QtGui/QKeyEvent>
#include <QtGui/QPainter>
#include <QtGui/QItemDelegate>
#include <QtGui/QApplication>
......@@ -78,6 +79,40 @@ static QIcon createCenteredIcon(const QIcon &icon, const QIcon &overlay)
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
class TargetSelectorDelegate : public QItemDelegate
{
public:
TargetSelectorDelegate(QObject *parent) : QItemDelegate(parent) { }
private:
void paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const;
mutable QImage selectionGradient;
};
void TargetSelectorDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &) const
{
painter->save();
painter->setClipping(false);
if (selectionGradient.isNull())
selectionGradient.load(QLatin1String(":/projectexplorer/images/targetpanel_gradient.png"));
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight().color().darker(140));
Utils::StyleHelper::drawCornerImage(selectionGradient, painter, option.rect.adjusted(0, 0, 0, -1), 5, 5, 5, 5);
painter->setPen(QColor(255, 255, 255, 60));
painter->drawLine(option.rect.topLeft(), option.rect.topRight());
painter->setPen(QColor(255, 255, 255, 30));
painter->drawLine(option.rect.bottomLeft() - QPoint(0,1), option.rect.bottomRight() - QPoint(0,1));
painter->setPen(QColor(0, 0, 0, 80));
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
}
painter->restore();
}
ProjectListWidget::ProjectListWidget(ProjectExplorer::Project *project, QWidget *parent)
: QListWidget(parent), m_project(project)
{
......@@ -85,6 +120,7 @@ ProjectListWidget::ProjectListWidget(ProjectExplorer::Project *project, QWidget
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setAlternatingRowColors(false);
setFocusPolicy(Qt::WheelFocus);
setItemDelegate(new TargetSelectorDelegate(this));
connect(this, SIGNAL(currentRowChanged(int)), SLOT(setTarget(int)));
}
......@@ -100,7 +136,17 @@ QSize ProjectListWidget::sizeHint() const
for (int itemPos = 0; itemPos < count(); ++itemPos)
height += item(itemPos)->sizeHint().height();
return QListWidget::sizeHint().expandedTo(QSize(0, height));
// We try to keep the height of the popup equal to the actionbar
QSize size(QListWidget::sizeHint().width(), height);
static QStatusBar *statusBar = Core::ICore::instance()->statusBar();
static QWidget *actionBar = Core::ICore::instance()->mainWindow()->findChild<QWidget*>("actionbar");
Q_ASSERT(actionBar);
QMargins popupMargins = window()->contentsMargins();
if (actionBar)
size.setHeight(qMax(actionBar->height() - statusBar->height() -
(popupMargins.top() + popupMargins.bottom()), height));
return size;
}
void ProjectListWidget::setRunComboPopup()
......@@ -134,6 +180,8 @@ MiniTargetWidget::MiniTargetWidget(Target *target, QWidget *parent) :
if (hasBuildConfiguration()) {
m_buildComboBox = new QComboBox;
m_buildComboBox->setProperty("alignarrow", true);
m_buildComboBox->setProperty("hideborder", true);
m_buildComboBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
m_buildComboBox->setToolTip(tr("Make active and press 'b' to select."));
} else {
......@@ -141,22 +189,22 @@ MiniTargetWidget::MiniTargetWidget(Target *target, QWidget *parent) :
}
m_runComboBox = new QComboBox;
m_runComboBox ->setProperty("alignarrow", true);
m_runComboBox ->setProperty("hideborder", true);
m_runComboBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
m_runComboBox->setToolTip(tr("Make active and press 'r' to select."));
int fontSize = font().pointSize();
setStyleSheet(QString::fromLatin1("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; border: 1px solid lightgrey; } "
"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()));
setStyleSheet(QString::fromLatin1("QLabel { font-size: %2pt; color: white; } "
"#target { font: bold %1pt;} "
"#buildLabel{ font: bold; color: rgba(255, 255, 255, 160)} "
"#runLabel { font: bold ; color: rgba(255, 255, 255, 160)} "
).arg(fontSize).arg(fontSize - 2));
QGridLayout *gridLayout = new QGridLayout(this);
m_targetName = new QLabel(m_target->displayName());
m_targetName->setObjectName(QLatin1String("target"));
m_targetName->setObjectName(QString::fromUtf8("target"));
m_targetIcon = new QLabel();
updateIcon();
if (hasBuildConfiguration()) {
......@@ -201,14 +249,17 @@ MiniTargetWidget::MiniTargetWidget(Target *target, QWidget *parent) :
runHelperLayout->addWidget(m_runComboBox);
QFormLayout *formLayout = new QFormLayout;
formLayout->setLabelAlignment(Qt::AlignRight);
QLabel *lbl;
if (hasBuildConfiguration()) {
lbl = new QLabel(tr("Build:"));
lbl->setIndent(6);
lbl->setObjectName(QString::fromUtf8("buildLabel"));
lbl->setIndent(10);
formLayout->addRow(lbl, buildHelperLayout);
}
lbl = new QLabel(tr("Run:"));
lbl->setIndent(6);
lbl->setObjectName(QString::fromUtf8("runLabel"));
lbl->setIndent(10);
formLayout->addRow(lbl, runHelperLayout);
gridLayout->addWidget(m_targetName, 0, 0);
......@@ -305,6 +356,8 @@ bool MiniTargetWidget::hasBuildConfiguration() const
MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorAction, QWidget *parent) :
QWidget(parent), m_projectAction(targetSelectorAction)
{
setProperty("panelwidget", true);
setContentsMargins(QMargins(0, 1, 1, 8));
setWindowFlags(Qt::Popup);
setFocusPolicy(Qt::WheelFocus);
......@@ -327,8 +380,18 @@ MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorActi
QFont f = lbl->font();
f.setBold(true);
lbl->setFont(f);
int panelHeight = lbl->fontMetrics().height() + 12;
bar->ensurePolished(); // Required since manhattanstyle overrides height
bar->setFixedHeight(panelHeight);
m_projectsBox = new QComboBox;
m_projectsBox->setObjectName(QLatin1String("ProjectsBox"));
f.setBold(false);
m_projectsBox->setFont(f);
m_projectsBox->ensurePolished();
m_projectsBox->setFixedHeight(panelHeight);
m_projectsBox->setProperty("hideborder", true);
m_projectsBox->setObjectName(QString::fromUtf8("ProjectsBox"));
m_projectsBox->setFocusPolicy(Qt::WheelFocus);
m_projectsBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
m_projectsBox->setMaximumWidth(200);
......@@ -369,7 +432,7 @@ void MiniProjectTargetSelector::addProject(ProjectExplorer::Project* project)
ProjectListWidget *targetList = new ProjectListWidget(project);
targetList->installEventFilter(this);
targetList->setStyleSheet(QString::fromLatin1("QListWidget { background: %1; border: none; }")
.arg(Utils::StyleHelper::baseColor().name()));
.arg(QColor(70, 70, 70).name()));
int pos = m_widgetStack->addWidget(targetList);
m_projectsBox->addItem(project->displayName(), QVariant::fromValue(project));
......@@ -413,7 +476,6 @@ void MiniProjectTargetSelector::addTarget(ProjectExplorer::Target *target, bool
connect(target, SIGNAL(iconChanged()), this, SLOT(updateAction()));
connect(target, SIGNAL(overlayIconChanged()), this, SLOT(updateAction()));
ProjectListWidget *plw = qobject_cast<ProjectListWidget*>(m_widgetStack->widget(index));
QListWidgetItem *lwi = new QListWidgetItem();
// Sort on insert:
......@@ -540,6 +602,18 @@ void MiniProjectTargetSelector::changeStartupProject(ProjectExplorer::Project *p
updateAction();
}
void MiniProjectTargetSelector::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(Utils::StyleHelper::borderColor());
painter.drawLine(rect().topLeft(), rect().topRight());
painter.drawLine(rect().topRight(), rect().bottomRight());
QRect bottomRect(0, rect().height() - 8, rect().width(), 8);
static QImage image(QLatin1String(":/projectexplorer/images/targetpanel_bottom.png"));
Utils::StyleHelper::drawCornerImage(image, &painter, bottomRect, 1, 1, 1, 1);
}
bool MiniProjectTargetSelector::eventFilter(QObject *o, QEvent *ev)
{
switch(ev->type())
......
......@@ -131,6 +131,7 @@ private slots:
void emitStartupProjectChanged(int index);
void changeStartupProject(ProjectExplorer::Project *project);
void updateAction();
void paintEvent(QPaintEvent *);
private:
int indexFor(ProjectExplorer::Project *project) const;
......
......@@ -38,5 +38,7 @@
<file>images/ConnectionOff.png</file>
<file>images/ConnectionOn.png</file>
<file>images/build.png</file>
<file>images/targetpanel_bottom.png</file>
<file>images/targetpanel_gradient.png</file>
</qresource>
</RCC>
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