forked from qt-creator/qt-creator
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 <thomas.hartmann@qt.io>
This commit is contained in:
@@ -33,6 +33,9 @@
|
|||||||
#include "qproxystyle.h"
|
#include "qproxystyle.h"
|
||||||
|
|
||||||
#include "metainfo.h"
|
#include "metainfo.h"
|
||||||
|
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QPen>
|
#include <QPen>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
@@ -42,11 +45,11 @@
|
|||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
IconCheckboxItemDelegate::IconCheckboxItemDelegate(QObject *parent,
|
IconCheckboxItemDelegate::IconCheckboxItemDelegate(QObject *parent,
|
||||||
const QPixmap &checkedPixmap,
|
const QIcon &checkedIcon,
|
||||||
const QPixmap &uncheckedPixmap)
|
const QIcon &uncheckedIcon)
|
||||||
: QStyledItemDelegate(parent),
|
: QStyledItemDelegate(parent),
|
||||||
m_checkedPixmap(checkedPixmap),
|
m_checkedIcon(checkedIcon),
|
||||||
m_uncheckedPixmap(uncheckedPixmap)
|
m_uncheckedIcon(uncheckedIcon)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
QSize IconCheckboxItemDelegate::sizeHint(const QStyleOptionViewItem & /*option*/,
|
QSize IconCheckboxItemDelegate::sizeHint(const QStyleOptionViewItem & /*option*/,
|
||||||
@@ -82,25 +85,28 @@ void IconCheckboxItemDelegate::paint(QPainter *painter,
|
|||||||
if (rowIsPropertyRole(modelIndex.model(), modelIndex))
|
if (rowIsPropertyRole(modelIndex.model(), modelIndex))
|
||||||
return; //Do not paint icons for property rows
|
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)
|
if (styleOption.state & QStyle::State_Selected)
|
||||||
NavigatorTreeView::drawSelectionBackground(painter, styleOption);
|
NavigatorTreeView::drawSelectionBackground(painter, styleOption);
|
||||||
|
|
||||||
if (!getModelNode(modelIndex).isRootNode()) {
|
if (!getModelNode(modelIndex).isRootNode()) {
|
||||||
|
QWindow *window = dynamic_cast<QWidget*>(painter->device())->window()->windowHandle();
|
||||||
|
QTC_ASSERT(window, return);
|
||||||
|
|
||||||
if (!isVisible(modelIndex))
|
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);
|
||||||
|
|
||||||
|
if (!visible) {
|
||||||
|
painter->save();
|
||||||
painter->setOpacity(0.5);
|
painter->setOpacity(0.5);
|
||||||
|
|
||||||
const bool checked = isChecked(modelIndex);
|
|
||||||
painter->drawPixmap(styleOption.rect.x() + xOffset, styleOption.rect.y() + yOffset,
|
|
||||||
checked ? m_checkedPixmap : m_uncheckedPixmap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
painter->drawPixmap(iconRect.topLeft(), iconPixmap);
|
||||||
|
|
||||||
|
if (!visible)
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ class IconCheckboxItemDelegate : public QStyledItemDelegate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit IconCheckboxItemDelegate(QObject *parent,
|
explicit IconCheckboxItemDelegate(QObject *parent,
|
||||||
const QPixmap &checkedPixmap,
|
const QIcon &checkedIcon,
|
||||||
const QPixmap &uncheckedPixmap);
|
const QIcon &uncheckedIcon);
|
||||||
|
|
||||||
QSize sizeHint(const QStyleOptionViewItem &option,
|
QSize sizeHint(const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index) const;
|
const QModelIndex &index) const;
|
||||||
@@ -46,7 +46,7 @@ public:
|
|||||||
const QModelIndex &index) const;
|
const QModelIndex &index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QPixmap m_checkedPixmap;
|
const QIcon m_checkedIcon;
|
||||||
const QPixmap m_uncheckedPixmap;
|
const QIcon m_uncheckedIcon;
|
||||||
};
|
};
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
|||||||
@@ -93,19 +93,19 @@ NavigatorView::NavigatorView(QObject* parent) :
|
|||||||
NameItemDelegate *idDelegate = new NameItemDelegate(this);
|
NameItemDelegate *idDelegate = new NameItemDelegate(this);
|
||||||
IconCheckboxItemDelegate *showDelegate =
|
IconCheckboxItemDelegate *showDelegate =
|
||||||
new IconCheckboxItemDelegate(this,
|
new IconCheckboxItemDelegate(this,
|
||||||
Utils::Icons::EYE_OPEN_TOOLBAR.pixmap(),
|
Utils::Icons::EYE_OPEN_TOOLBAR.icon(),
|
||||||
Utils::Icons::EYE_CLOSED_TOOLBAR.pixmap());
|
Utils::Icons::EYE_CLOSED_TOOLBAR.icon());
|
||||||
|
|
||||||
IconCheckboxItemDelegate *exportDelegate =
|
IconCheckboxItemDelegate *exportDelegate =
|
||||||
new IconCheckboxItemDelegate(this,
|
new IconCheckboxItemDelegate(this,
|
||||||
Icons::EXPORT_CHECKED.pixmap(),
|
Icons::EXPORT_CHECKED.icon(),
|
||||||
Icons::EXPORT_UNCHECKED.pixmap());
|
Icons::EXPORT_UNCHECKED.icon());
|
||||||
|
|
||||||
#ifdef _LOCK_ITEMS_
|
#ifdef _LOCK_ITEMS_
|
||||||
IconCheckboxItemDelegate *lockDelegate =
|
IconCheckboxItemDelegate *lockDelegate =
|
||||||
new IconCheckboxItemDelegate(this,
|
new IconCheckboxItemDelegate(this,
|
||||||
Utils::Icons::LOCKED_TOOLBAR.pixmap(),
|
Utils::Icons::LOCKED_TOOLBAR.icon(),
|
||||||
Utils::Icons::UNLOCKED_TOOLBAR.pixmap());
|
Utils::Icons::UNLOCKED_TOOLBAR.icon());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user