Commit 432e0c54 authored by Alessandro Portale's avatar Alessandro Portale

QmlDesigner: Let IconCheckboxItemDelegate use QIcons

For mixed-DPI screen scenarios, a pixmap can not satisfy both
resolitions. Use QIcon, instead.

Task-number: QTCREATORBUG-18869
Change-Id: I155a4300927f7a66de3d523c9daab4953b5e45c2
Reviewed-by: Thomas Hartmann's avatarThomas Hartmann <thomas.hartmann@qt.io>
parent 6b0b8c24
......@@ -33,6 +33,9 @@
#include "qproxystyle.h"
#include "metainfo.h"
#include <utils/qtcassert.h>
#include <QLineEdit>
#include <QPen>
#include <QPixmapCache>
......@@ -42,11 +45,11 @@
namespace QmlDesigner {
IconCheckboxItemDelegate::IconCheckboxItemDelegate(QObject *parent,
const QPixmap &checkedPixmap,
const QPixmap &uncheckedPixmap)
const QIcon &checkedIcon,
const QIcon &uncheckedIcon)
: QStyledItemDelegate(parent),
m_checkedPixmap(checkedPixmap),
m_uncheckedPixmap(uncheckedPixmap)
m_checkedIcon(checkedIcon),
m_uncheckedIcon(uncheckedIcon)
{}
QSize IconCheckboxItemDelegate::sizeHint(const QStyleOptionViewItem & /*option*/,
......@@ -82,25 +85,28 @@ void IconCheckboxItemDelegate::paint(QPainter *painter,
if (rowIsPropertyRole(modelIndex.model(), modelIndex))
return; //Do not paint icons for property rows
const int yOffset = (styleOption.rect.height()
- (m_checkedPixmap.height() / painter->device()->devicePixelRatio())) / 2;
const int xOffset = 2;
painter->save();
if (styleOption.state & QStyle::State_Selected)
NavigatorTreeView::drawSelectionBackground(painter, styleOption);
if (!getModelNode(modelIndex).isRootNode()) {
QWindow *window = dynamic_cast<QWidget*>(painter->device())->window()->windowHandle();
QTC_ASSERT(window, return);
if (!isVisible(modelIndex))
painter->setOpacity(0.5);
const QRect iconRect(styleOption.rect.left() + 2, styleOption.rect.top() + 2, 16, 16);
const QIcon &icon = isChecked(modelIndex) ? m_checkedIcon : m_uncheckedIcon;
const QPixmap iconPixmap = icon.pixmap(window, iconRect.size());
const bool visible = isVisible(modelIndex);
const bool checked = isChecked(modelIndex);
painter->drawPixmap(styleOption.rect.x() + xOffset, styleOption.rect.y() + yOffset,
checked ? m_checkedPixmap : m_uncheckedPixmap);
if (!visible) {
painter->save();
painter->setOpacity(0.5);
}
painter->drawPixmap(iconRect.topLeft(), iconPixmap);
if (!visible)
painter->restore();
}
}
} // namespace QmlDesigner
......@@ -35,8 +35,8 @@ class IconCheckboxItemDelegate : public QStyledItemDelegate
{
public:
explicit IconCheckboxItemDelegate(QObject *parent,
const QPixmap &checkedPixmap,
const QPixmap &uncheckedPixmap);
const QIcon &checkedIcon,
const QIcon &uncheckedIcon);
QSize sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const;
......@@ -46,7 +46,7 @@ public:
const QModelIndex &index) const;
private:
const QPixmap m_checkedPixmap;
const QPixmap m_uncheckedPixmap;
const QIcon m_checkedIcon;
const QIcon m_uncheckedIcon;
};
} // namespace QmlDesigner
......@@ -93,19 +93,19 @@ NavigatorView::NavigatorView(QObject* parent) :
NameItemDelegate *idDelegate = new NameItemDelegate(this);
IconCheckboxItemDelegate *showDelegate =
new IconCheckboxItemDelegate(this,
Utils::Icons::EYE_OPEN_TOOLBAR.pixmap(),
Utils::Icons::EYE_CLOSED_TOOLBAR.pixmap());
Utils::Icons::EYE_OPEN_TOOLBAR.icon(),
Utils::Icons::EYE_CLOSED_TOOLBAR.icon());
IconCheckboxItemDelegate *exportDelegate =
new IconCheckboxItemDelegate(this,
Icons::EXPORT_CHECKED.pixmap(),
Icons::EXPORT_UNCHECKED.pixmap());
Icons::EXPORT_CHECKED.icon(),
Icons::EXPORT_UNCHECKED.icon());
#ifdef _LOCK_ITEMS_
IconCheckboxItemDelegate *lockDelegate =
new IconCheckboxItemDelegate(this,
Utils::Icons::LOCKED_TOOLBAR.pixmap(),
Utils::Icons::UNLOCKED_TOOLBAR.pixmap());
Utils::Icons::LOCKED_TOOLBAR.icon(),
Utils::Icons::UNLOCKED_TOOLBAR.icon());
#endif
......
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