Commit beac7dcb authored by Alessandro Portale's avatar Alessandro Portale
Browse files

HighDPI fixes



ColorTip:
Draw the border around the color tooltip properly.

MiniProjectTargetSelector:
Fixing a few misplaced outlines

FancyActionBar:
Fixing a few misplaced outlines, also:
- deduplicate hover gradient painting code
- use pixmapcache for the hover gradient
- only draw the hover gradient if the tab is hovered
- use 0-255 as range for fading value

QtQuick Designer:
HighDPI form editor icons, and removing some since a
while unused icons.

ProjectExplorer Mode:
HighDPI graphics and fixing a few misplaced outlines

Task-number: QTCREATORBUG-15222
Change-Id: I4fcf515014317791499ad89bf6ef88d961e4b752
Reviewed-by: default avatarAlessandro Portale <alessandro.portale@theqtcompany.com>
parent 9f6cfe48
......@@ -108,19 +108,16 @@ void ColorTip::paintEvent(QPaintEvent *event)
{
QTipLabel::paintEvent(event);
QPen pen;
pen.setWidth(1);
if (m_color.value() > 100)
pen.setColor(m_color.darker());
else
pen.setColor(m_color.lighter());
QPainter painter(this);
painter.setPen(pen);
painter.setBrush(m_color);
QRect r(0, 0, rect().width() - 1, rect().height() - 1);
painter.drawTiledPixmap(r, m_tilePixmap);
painter.drawRect(r);
painter.drawTiledPixmap(rect(), m_tilePixmap);
QPen pen;
pen.setColor(m_color.value() > 100 ? m_color.darker() : m_color.lighter());
pen.setJoinStyle(Qt::MiterJoin);
const QRectF borderRect = QRectF(rect()).adjusted(0.5, 0.5, -0.5, -0.5);
painter.setPen(pen);
painter.drawRect(borderRect);
}
TextTip::TextTip(QWidget *parent) : QTipLabel(parent)
......
......@@ -44,6 +44,7 @@
#include <QStyleOption>
#include <QMouseEvent>
#include <QEvent>
#include <QPixmapCache>
#include <QPropertyAnimation>
#include <QDebug>
......@@ -145,19 +146,13 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
if (!HostOsInfo::isMacHost() // Mac UIs usually don't hover
&& m_fader > 0 && isEnabled() && !isDown() && !isChecked()) {
painter.save();
const QColor hoverColor = creatorTheme()->color(Theme::FancyToolButtonHoverColor);
QColor fadedHoverColor = hoverColor;
fadedHoverColor.setAlpha(int(m_fader * hoverColor.alpha()));
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
QLinearGradient grad(rect().topLeft(), rect().topRight());
grad.setColorAt(0, Qt::transparent);
grad.setColorAt(0.5, fadedHoverColor);
grad.setColorAt(1, Qt::transparent);
painter.fillRect(rect(), grad);
painter.setPen(QPen(grad, 1.0));
painter.drawLine(rect().topLeft(), rect().topRight());
painter.drawLine(rect().bottomLeft(), rect().bottomRight());
painter.setOpacity(m_fader);
FancyToolButton::hoverOverlay(&painter, rect());
} else {
const QColor hoverColor = creatorTheme()->color(Theme::FancyToolButtonHoverColor);
QColor fadedHoverColor = hoverColor;
fadedHoverColor.setAlpha(int(m_fader * hoverColor.alpha()));
painter.fillRect(rect(), fadedHoverColor);
}
painter.restore();
......@@ -171,12 +166,12 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
grad.setColorAt(1, Qt::transparent);
painter.fillRect(rect(), grad);
painter.setPen(QPen(grad, 1.0));
painter.drawLine(rect().topLeft(), rect().topRight());
painter.drawLine(rect().topLeft(), rect().topRight());
painter.drawLine(rect().topLeft() + QPoint(0,1), rect().topRight() + QPoint(0,1));
painter.drawLine(rect().bottomLeft(), rect().bottomRight());
painter.drawLine(rect().bottomLeft(), rect().bottomRight());
painter.drawLine(rect().topLeft() - QPoint(0,1), rect().topRight() - QPoint(0,1));
const QRectF borderRectF(QRectF(rect()).adjusted(0.5, 0.5, -0.5, -0.5));
painter.drawLine(borderRectF.topLeft(), borderRectF.topRight());
painter.drawLine(borderRectF.topLeft(), borderRectF.topRight());
painter.drawLine(borderRectF.topLeft() + QPointF(0, 1), borderRectF.topRight() + QPointF(0, 1));
painter.drawLine(borderRectF.bottomLeft(), borderRectF.bottomRight());
painter.drawLine(borderRectF.bottomLeft(), borderRectF.bottomRight());
} else {
painter.fillRect(rect(), selectedColor);
}
......@@ -281,10 +276,11 @@ void FancyActionBar::paintEvent(QPaintEvent *event)
QColor light = StyleHelper::sidebarHighlight();
QColor dark = StyleHelper::sidebarShadow();
const QRectF borderRect = QRectF(rect()).adjusted(0.5, 0.5, -0.5, -0.5);
painter.setPen(dark);
painter.drawLine(rect().topLeft(), rect().topRight());
painter.drawLine(borderRect.topLeft(), borderRect.topRight());
painter.setPen(light);
painter.drawLine(rect().topLeft() + QPoint(1,1), rect().topRight() + QPoint(0,1));
painter.drawLine(borderRect.topLeft() + QPointF(1, 1), borderRect.topRight() + QPointF(0, 1));
}
QSize FancyToolButton::sizeHint() const
......@@ -311,6 +307,38 @@ QSize FancyToolButton::minimumSizeHint() const
return QSize(8, 8);
}
void FancyToolButton::hoverOverlay(QPainter *painter, const QRect &spanRect)
{
const QSize logicalSize = spanRect.size();
const QString cacheKey = QLatin1String(Q_FUNC_INFO) + QString::number(logicalSize.width())
+ QLatin1Char('x') + QString::number(logicalSize.height());
QPixmap overlay;
if (!QPixmapCache::find(cacheKey, &overlay)) {
const int dpr = painter->device()->devicePixelRatio();
overlay = QPixmap(logicalSize * dpr);
overlay.fill(Qt::transparent);
overlay.setDevicePixelRatio(dpr);
const QColor hoverColor = creatorTheme()->color(Theme::FancyToolButtonHoverColor);
const QRect rect(QPoint(), logicalSize);
const QRectF borderRect = QRectF(rect).adjusted(0.5, 0.5, -0.5, -0.5);
QLinearGradient grad(rect.topLeft(), rect.topRight());
grad.setColorAt(0, Qt::transparent);
grad.setColorAt(0.5, hoverColor);
grad.setColorAt(1, Qt::transparent);
QPainter p(&overlay);
p.fillRect(rect, grad);
p.setPen(QPen(grad, 1.0));
p.drawLine(borderRect.topLeft(), borderRect.topRight());
p.drawLine(borderRect.bottomLeft(), borderRect.bottomRight());
QPixmapCache::insert(cacheKey, overlay);
}
painter->drawPixmap(spanRect.topLeft(), overlay);
}
void FancyToolButton::actionChanged()
{
// the default action changed in some way, e.g. it might got hidden
......
......@@ -58,6 +58,8 @@ public:
float fader() { return m_fader; }
void setFader(float value) { m_fader = value; update(); }
static void hoverOverlay(QPainter *painter, const QRect &spanRect);
private slots:
void actionChanged();
};
......
......@@ -29,6 +29,8 @@
****************************************************************************/
#include "fancytabwidget.h"
#include "fancyactionbar.h"
#include <utils/hostosinfo.h>
#include <utils/stylehelper.h>
#include <utils/styledbar.h>
......@@ -58,7 +60,7 @@ void FancyTab::fadeIn()
{
animator.stop();
animator.setDuration(80);
animator.setEndValue(40);
animator.setEndValue(1);
animator.start();
}
......@@ -320,22 +322,16 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110));
const int textFlags = Qt::AlignCenter | (drawIcon ? Qt::AlignBottom : Qt::AlignVCenter) | Qt::TextWordWrap;
if (!HostOsInfo::isMacHost() && !selected && enabled) {
const float fader = m_tabs[tabIndex]->fader();
if (fader > 0 && !HostOsInfo::isMacHost() && !selected && enabled) {
painter->save();
int fader = int(m_tabs[tabIndex]->fader());
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
QColor c = creatorTheme()->color(Theme::BackgroundColorHover);
c.setAlpha(int(255 * fader/40.0)); // FIXME: hardcoded end value 40
c.setAlpha(255 * fader);
painter->fillRect(rect, c);
} else {
QLinearGradient grad(rect.topLeft(), rect.topRight());
grad.setColorAt(0, Qt::transparent);
grad.setColorAt(0.5, QColor(255, 255, 255, fader));
grad.setColorAt(1, Qt::transparent);
painter->fillRect(rect, grad);
painter->setPen(QPen(grad, 1.0));
painter->drawLine(rect.topLeft(), rect.topRight());
painter->drawLine(rect.bottomLeft(), rect.bottomRight());
painter->setOpacity(fader);
FancyToolButton::hoverOverlay(painter, rect);
}
painter->restore();
}
......
......@@ -54,7 +54,7 @@ static const int SELECTION_IMAGE_WIDTH = 10;
static const int SELECTION_IMAGE_HEIGHT = 20;
static const int OVERFLOW_DROPDOWN_WIDTH = StyleHelper::navigationWidgetHeight();
static void drawFirstLevelSeparator(QPainter *painter, QPoint top, QPoint bottom)
static void drawFirstLevelSeparator(QPainter *painter, const QPointF &top, const QPointF &bottom)
{
QLinearGradient grad(top, bottom);
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
......@@ -62,13 +62,13 @@ static void drawFirstLevelSeparator(QPainter *painter, QPoint top, QPoint bottom
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->setPen(QPen(grad, 1));
painter->drawLine(top, bottom);
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));
painter->setPen(QPen(grad, 1));
painter->drawLine(top - QPoint(1,0), bottom - QPoint(1,0));
} else {
painter->setPen(QPen(creatorTheme()->color(Theme::DoubleTabWidget1stSeparatorColor), 0));
......@@ -84,13 +84,13 @@ static void drawSecondLevelSeparator(QPainter *painter, QPoint top, QPoint botto
grad.setColorAt(0.4, QColor(255, 255, 255, 100));
grad.setColorAt(0.7, QColor(255, 255, 255, 100));
grad.setColorAt(1, QColor(255, 255, 255, 0));
painter->setPen(QPen(grad, 0));
painter->setPen(QPen(grad, 1));
painter->drawLine(top, bottom);
grad.setColorAt(0, QColor(0, 0, 0, 0));
grad.setColorAt(0.4, QColor(0, 0, 0, 100));
grad.setColorAt(0.7, QColor(0, 0, 0, 100));
grad.setColorAt(1, QColor(0, 0, 0, 0));
painter->setPen(QPen(grad, 0));
painter->setPen(QPen(grad, 1));
painter->drawLine(top - QPoint(1,0), bottom - QPoint(1,0));
} else {
painter->setPen(QPen(creatorTheme()->color(Theme::DoubleTabWidget2ndSeparatorColor), 0));
......@@ -100,9 +100,7 @@ static void drawSecondLevelSeparator(QPainter *painter, QPoint top, QPoint botto
DoubleTabWidget::DoubleTabWidget(QWidget *parent) :
QWidget(parent),
m_left(QLatin1String(":/projectexplorer/images/leftselection.png")),
m_mid(QLatin1String(":/projectexplorer/images/midselection.png")),
m_right(QLatin1String(":/projectexplorer/images/rightselection.png")),
m_selection(StyleHelper::dpiSpecificImageFile(QLatin1String(":/projectexplorer/images/selection.png"))),
ui(new Ui::DoubleTabWidget),
m_currentIndex(-1),
m_lastVisibleIndex(-1)
......@@ -366,15 +364,16 @@ void DoubleTabWidget::paintEvent(QPaintEvent *event)
// draw top level tab bar
r.setHeight(StyleHelper::navigationWidgetHeight());
const QRectF borderRect = QRectF(r).adjusted(0.5, 0.5, -0.5, -0.5);
if (creatorTheme()->widgetStyle () == Theme::StyleDefault) {
QPoint offset = window()->mapToGlobal(QPoint(0, 0)) - mapToGlobal(r.topLeft());
QRect gradientSpan = QRect(offset, window()->size());
StyleHelper::horizontalGradient(&painter, gradientSpan, r);
painter.setPen(StyleHelper::borderColor());
QColor lighter(255, 255, 255, 40);
painter.drawLine(r.bottomLeft(), r.bottomRight());
painter.drawLine(borderRect.bottomLeft(), borderRect.bottomRight());
painter.setPen(lighter);
painter.drawLine(r.topLeft(), r.topRight());
painter.drawLine(borderRect.topLeft(), borderRect.topRight());
} else {
painter.fillRect(r, creatorTheme()->color(Theme::DoubleTabWidget1stEmptyAreaBackgroundColor));
}
......@@ -400,11 +399,8 @@ void DoubleTabWidget::paintEvent(QPaintEvent *event)
painter.fillRect(QRect(0, r.height(), r.width(), OTHER_HEIGHT), grad);
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
painter.setPen(QColor(0x505050));
painter.drawLine(0, r.height() + OTHER_HEIGHT,
r.width(), r.height() + OTHER_HEIGHT);
painter.setPen(Qt::white);
painter.drawLine(0, r.height(),
r.width(), r.height());
painter.drawLine(QPointF(0.5, r.height() + OTHER_HEIGHT - 0.5),
QPointF(r.width() - 0.5, r.height() + OTHER_HEIGHT - 0.5));
}
// top level tabs
......@@ -480,7 +476,7 @@ void DoubleTabWidget::paintEvent(QPaintEvent *event)
Tab tab = m_tabs.at(actualIndex);
if (actualIndex == m_currentIndex) {
painter.setPen(StyleHelper::borderColor());
painter.drawLine(x - 1, 0, x - 1, r.height() - 1);
painter.drawLine(QLineF(x - 0.5, 0.5, x - 0.5, r.height() - 1.5));
painter.fillRect(QRect(x, 0,
2 * MARGIN + fm.width(tab.displayName()),
r.height() + 1),
......@@ -488,7 +484,7 @@ void DoubleTabWidget::paintEvent(QPaintEvent *event)
if (actualIndex != 0 && creatorTheme()->widgetStyle() == Theme::StyleDefault) {
painter.setPen(QColor(255, 255, 255, 170));
painter.drawLine(x, 0, x, r.height());
painter.drawLine(QLineF(x + 0.5, 0.5, x + 0.5, r.height() - 0.5));
}
x += MARGIN;
painter.setPen(creatorTheme()->color(Theme::DoubleTabWidget1stTabActiveTextColor));
......@@ -497,21 +493,19 @@ void DoubleTabWidget::paintEvent(QPaintEvent *event)
x += MARGIN;
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
painter.setPen(StyleHelper::borderColor());
painter.drawLine(x, 0, x, r.height() - 1);
painter.drawLine(QLineF(x + 0.5, 0.5, x + 0.5, r.height() - 0.5));
painter.setPen(QColor(0, 0, 0, 20));
painter.drawLine(x + 1, 0, x + 1, r.height() - 1);
painter.drawLine(QLineF(x + 1.5, 0.5, x + 1.5, r.height() - 0.5));
painter.setPen(QColor(255, 255, 255, 170));
painter.drawLine(x - 1, 0, x - 1, r.height());
painter.drawLine(QLineF(x - 0.5, 0.5, x - 0.5, r.height() - 0.5));
}
} else {
if (i == 0 && creatorTheme()->widgetStyle() == Theme::StyleDefault)
drawFirstLevelSeparator(&painter, QPoint(x, 0), QPoint(x, r.height()-1));
x += MARGIN;
painter.setPen(creatorTheme()->color(Theme::DoubleTabWidget1stTabInactiveTextColor));
painter.drawText(x + 1, baseline, tab.displayName());
x += nameWidth.at(actualIndex);
x += MARGIN;
drawFirstLevelSeparator(&painter, QPoint(x, 0), QPoint(x, r.height()-1));
drawFirstLevelSeparator(&painter, QPointF(x + 0.5, 0.5), QPointF(x + 0.5, r.height() - 0.5));
}
}
......@@ -521,14 +515,14 @@ void DoubleTabWidget::paintEvent(QPaintEvent *event)
opt.rect = QRect(x, 0, OVERFLOW_DROPDOWN_WIDTH - 1, r.height() - 1);
style()->drawPrimitive(QStyle::PE_IndicatorArrowDown,
&opt, &painter, this);
drawFirstLevelSeparator(&painter, QPoint(x + OVERFLOW_DROPDOWN_WIDTH, 0),
QPoint(x + OVERFLOW_DROPDOWN_WIDTH, r.height()-1));
drawFirstLevelSeparator(&painter, QPointF(x + OVERFLOW_DROPDOWN_WIDTH + 0.5, 0.5),
QPointF(x + OVERFLOW_DROPDOWN_WIDTH + 0.5, r.height() - 0.5));
}
// second level tabs
if (m_currentIndex != -1) {
int y = r.height() + (OTHER_HEIGHT - m_left.height()) / 2.;
int imageHeight = m_left.height();
int imageHeight = static_cast<int>(m_selection.height() / m_selection.devicePixelRatio());
int y = r.height() + (OTHER_HEIGHT - imageHeight) / 2;
Tab currentTab = m_tabs.at(m_currentIndex);
QStringList subTabs = currentTab.subTabs;
x = 0;
......@@ -536,16 +530,13 @@ void DoubleTabWidget::paintEvent(QPaintEvent *event)
x += MARGIN;
int textWidth = fm.width(subTabs.at(i));
if (currentTab.currentSubTab == i) {
const QRect tabRect(x, y, 2 * SELECTION_IMAGE_WIDTH + textWidth, imageHeight);
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
painter.drawPixmap(x, y, m_left);
painter.drawPixmap(QRect(x + SELECTION_IMAGE_WIDTH, y,
textWidth, imageHeight),
m_mid, QRect(0, 0, m_mid.width(), m_mid.height()));
painter.drawPixmap(x + SELECTION_IMAGE_WIDTH + textWidth, y, m_right);
StyleHelper::drawCornerImage(m_selection, &painter, tabRect, 15, 0, 15, 0);
} else {
painter.setBrush(creatorTheme()->color(Theme::DoubleTabWidget2ndTabBackgroundColor));
painter.setPen(Qt::NoPen);
painter.drawRoundedRect(QRect(x,y,2*SELECTION_IMAGE_WIDTH+textWidth, m_mid.height()), 5,5);
painter.drawRoundedRect(tabRect, 5, 5);
}
painter.setPen(creatorTheme()->color(Theme::DoubleTabWidget2ndTabActiveTextColor));
} else {
......
......@@ -33,7 +33,7 @@
#include <QVector>
#include <QWidget>
#include <QPixmap>
#include <QImage>
namespace ProjectExplorer {
namespace Internal {
......@@ -88,9 +88,7 @@ private:
enum HitArea { HITNOTHING, HITOVERFLOW, HITTAB, HITSUBTAB };
QPair<DoubleTabWidget::HitArea, int> convertPosToTab(QPoint pos);
const QPixmap m_left;
const QPixmap m_mid;
const QPixmap m_right;
const QImage m_selection;
Ui::DoubleTabWidget *ui;
......
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