mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
optimize item paint
Change-Id: Iad05a1967417cf6a3dc4f2ab47e8de0f0d1d5e50
This commit is contained in:
parent
7024805a0f
commit
327984199c
Notes:
Deepin Code Review
2016-08-19 02:26:43 +00:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Fri, 19 Aug 2016 02:26:43 +0000 Reviewed-on: https://cr.deepin.io/15363 Project: dde/dde-dock Branch: refs/heads/master
@ -182,6 +182,8 @@ DockItemController::DockItemController(QObject *parent)
|
||||
|
||||
connect(m_pluginsInter, &DockPluginsController::pluginItemInserted, this, &DockItemController::pluginItemInserted, Qt::QueuedConnection);
|
||||
connect(m_pluginsInter, &DockPluginsController::pluginItemRemoved, this, &DockItemController::pluginItemRemoved, Qt::QueuedConnection);
|
||||
|
||||
QMetaObject::invokeMethod(this, "refershItemsIcon", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void DockItemController::appItemAdded(const QDBusObjectPath &path, const int index)
|
||||
|
@ -194,49 +194,16 @@ void AppItem::paintEvent(QPaintEvent *e)
|
||||
painter.drawPixmap(p, activePixmap);
|
||||
else
|
||||
painter.drawPixmap(p, pixmap);
|
||||
|
||||
// const int activeLineWidth = 2;
|
||||
// const int activeLineLength = 20;
|
||||
// QRect activeRect = itemRect;
|
||||
// switch (DockPosition)
|
||||
// {
|
||||
// case Top:
|
||||
// activeRect.setBottom(activeRect.top() + activeLineWidth);
|
||||
// activeRect.moveBottom(activeRect.bottom() + 1);
|
||||
// activeRect.setWidth(activeLineLength);
|
||||
// activeRect.moveLeft((itemRect.width() - activeRect.width()) / 2);
|
||||
// break;
|
||||
// case Bottom:
|
||||
// activeRect.setTop(activeRect.bottom() - activeLineWidth);
|
||||
// activeRect.moveTop(activeRect.top() - 1);
|
||||
// activeRect.setWidth(activeLineLength);
|
||||
// activeRect.moveLeft((itemRect.width() - activeRect.width()) / 2);
|
||||
// break;
|
||||
// case Left:
|
||||
// activeRect.setRight(activeRect.left() + activeLineWidth);
|
||||
// activeRect.moveRight(activeRect.right() + 1);
|
||||
// activeRect.setHeight(activeLineLength);
|
||||
// activeRect.moveTop((itemRect.height() - activeRect.height()) / 2);
|
||||
// break;
|
||||
// case Right:
|
||||
// activeRect.setLeft(activeRect.right() - activeLineWidth);
|
||||
// activeRect.moveLeft(activeRect.left() - 1);
|
||||
// activeRect.setHeight(activeLineLength);
|
||||
// activeRect.moveTop((itemRect.height() - activeRect.height()) / 2);
|
||||
// break;
|
||||
// }
|
||||
|
||||
// painter.fillRect(activeRect, QColor(163, 167, 166));
|
||||
}
|
||||
}
|
||||
|
||||
// icon
|
||||
const QPixmap pixmap = DockDisplayMode == Efficient ? m_smallIcon : m_largeIcon;
|
||||
// draw icon
|
||||
painter.drawPixmap(itemRect.center() - pixmap.rect().center(), pixmap);
|
||||
// draw ligher
|
||||
// draw ligher/normal icon
|
||||
if (m_hover)
|
||||
painter.drawPixmap(itemRect.center() - pixmap.rect().center(), ImageFactory::lighterEffect(pixmap));
|
||||
else
|
||||
painter.drawPixmap(itemRect.center() - pixmap.rect().center(), pixmap);
|
||||
|
||||
// Update the window icon geometry when the icon is changed.
|
||||
m_updateIconGeometryTimer->start();
|
||||
|
@ -32,6 +32,21 @@ bool ContainerItem::contains(DockItem * const item)
|
||||
return false;
|
||||
}
|
||||
|
||||
void ContainerItem::refershIcon()
|
||||
{
|
||||
QPixmap icon;
|
||||
switch (DockPosition)
|
||||
{
|
||||
case Top: icon = QPixmap(":/icons/resources/arrow-down.svg"); break;
|
||||
case Left: icon = QPixmap(":/icons/resources/arrow-right.svg"); break;
|
||||
case Bottom: icon = QPixmap(":/icons/resources/arrow-up.svg"); break;
|
||||
case Right: icon = QPixmap(":/icons/resources/arrow-left.svg"); break;
|
||||
default: Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
m_icon = icon;
|
||||
}
|
||||
|
||||
void ContainerItem::dragEnterEvent(QDragEnterEvent *e)
|
||||
{
|
||||
if (m_containerWidget->allowDragEnter(e))
|
||||
@ -52,18 +67,8 @@ void ContainerItem::paintEvent(QPaintEvent *e)
|
||||
if (DockDisplayMode == Dock::Fashion)
|
||||
return;
|
||||
|
||||
QPixmap icon;
|
||||
switch (DockPosition)
|
||||
{
|
||||
case Top: icon = QPixmap(":/icons/resources/arrow-down.svg"); break;
|
||||
case Left: icon = QPixmap(":/icons/resources/arrow-right.svg"); break;
|
||||
case Bottom: icon = QPixmap(":/icons/resources/arrow-up.svg"); break;
|
||||
case Right: icon = QPixmap(":/icons/resources/arrow-left.svg"); break;
|
||||
default: Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
QPainter painter(this);
|
||||
painter.drawPixmap(rect().center() - icon.rect().center(), icon);
|
||||
painter.drawPixmap(rect().center() - m_icon.rect().center(), m_icon);
|
||||
}
|
||||
|
||||
void ContainerItem::mouseReleaseEvent(QMouseEvent *e)
|
||||
|
@ -19,6 +19,9 @@ public:
|
||||
void removeItem(DockItem * const item);
|
||||
bool contains(DockItem * const item);
|
||||
|
||||
public slots:
|
||||
void refershIcon();
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *e);
|
||||
void dragMoveEvent(QDragMoveEvent *e);
|
||||
@ -28,6 +31,7 @@ protected:
|
||||
|
||||
private:
|
||||
ContainerWidget *m_containerWidget;
|
||||
QPixmap m_icon;
|
||||
};
|
||||
|
||||
#endif // CONTAINERITEM_H
|
||||
|
@ -29,10 +29,11 @@ void LauncherItem::paintEvent(QPaintEvent *e)
|
||||
QPainter painter(this);
|
||||
|
||||
const QPixmap pixmap = DockDisplayMode == Fashion ? m_largeIcon : m_smallIcon;
|
||||
painter.drawPixmap(rect().center() - pixmap.rect().center(), pixmap);
|
||||
|
||||
if (m_hover)
|
||||
painter.drawPixmap(rect().center() - pixmap.rect().center(), ImageFactory::lighterEffect(pixmap));
|
||||
else
|
||||
painter.drawPixmap(rect().center() - pixmap.rect().center(), pixmap);
|
||||
}
|
||||
|
||||
void LauncherItem::resizeEvent(QResizeEvent *e)
|
||||
|
@ -20,6 +20,13 @@ QSize DatetimeWidget::sizeHint() const
|
||||
return fm.boundingRect("88:88").size() + QSize(20, 10);
|
||||
}
|
||||
|
||||
void DatetimeWidget::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
m_cachedTime.clear();
|
||||
|
||||
QWidget::resizeEvent(e);
|
||||
}
|
||||
|
||||
void DatetimeWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
@ -36,44 +43,59 @@ void DatetimeWidget::paintEvent(QPaintEvent *e)
|
||||
return;
|
||||
}
|
||||
|
||||
// draw fashion mode datetime plugin
|
||||
const int perfectIconSize = qMin(width(), height()) * 0.8;
|
||||
const QString currentTimeString = current.toString("HHmmss");
|
||||
const QRect r = rect();
|
||||
const QString currentTimeString = current.toString("HHmm");
|
||||
// check cache valid
|
||||
if (m_cachedTime != currentTimeString)
|
||||
{
|
||||
m_cachedTime = currentTimeString;
|
||||
|
||||
// draw background
|
||||
const QPixmap background = loadSvg(":/icons/resources/icons/background.svg", QSize(perfectIconSize, perfectIconSize));
|
||||
const QPoint backgroundOffset = r.center() - background.rect().center();
|
||||
painter.drawPixmap(backgroundOffset, background);
|
||||
// draw new pixmap
|
||||
m_cachedTime = currentTimeString;
|
||||
m_cachedIcon = QPixmap(size());
|
||||
m_cachedIcon.fill(Qt::transparent);
|
||||
QPainter p(&m_cachedIcon);
|
||||
|
||||
const int bigNumHeight = perfectIconSize / 2.5;
|
||||
const int bigNumWidth = double(bigNumHeight) * 8 / 18;
|
||||
const int smallNumHeight = bigNumHeight / 2;
|
||||
const int smallNumWidth = double(smallNumHeight) * 5 / 9;
|
||||
// draw fashion mode datetime plugin
|
||||
const int perfectIconSize = qMin(width(), height()) * 0.8;
|
||||
const QRect r = rect();
|
||||
|
||||
// draw big num 1
|
||||
const QString bigNum1Path = QString(":/icons/resources/icons/big%1.svg").arg(currentTimeString[0]);
|
||||
const QPixmap bigNum1 = loadSvg(bigNum1Path, QSize(bigNumWidth, bigNumHeight));
|
||||
const QPoint bigNum1Offset = backgroundOffset + QPoint(perfectIconSize / 2 - bigNumWidth * 2 + 1, perfectIconSize / 2 - bigNumHeight / 2);
|
||||
painter.drawPixmap(bigNum1Offset, bigNum1);
|
||||
// draw background
|
||||
const QPixmap background = loadSvg(":/icons/resources/icons/background.svg", QSize(perfectIconSize, perfectIconSize));
|
||||
const QPoint backgroundOffset = r.center() - background.rect().center();
|
||||
p.drawPixmap(backgroundOffset, background);
|
||||
|
||||
// draw big num 2
|
||||
const QString bigNum2Path = QString(":/icons/resources/icons/big%1.svg").arg(currentTimeString[1]);
|
||||
const QPixmap bigNum2 = loadSvg(bigNum2Path, QSize(bigNumWidth, bigNumHeight));
|
||||
const QPoint bigNum2Offset = bigNum1Offset + QPoint(bigNumWidth + 1, 0);
|
||||
painter.drawPixmap(bigNum2Offset, bigNum2);
|
||||
const int bigNumHeight = perfectIconSize / 2.5;
|
||||
const int bigNumWidth = double(bigNumHeight) * 8 / 18;
|
||||
const int smallNumHeight = bigNumHeight / 2;
|
||||
const int smallNumWidth = double(smallNumHeight) * 5 / 9;
|
||||
|
||||
// draw small num 1
|
||||
const QString smallNum1Path = QString(":/icons/resources/icons/small%1.svg").arg(currentTimeString[2]);
|
||||
const QPixmap smallNum1 = loadSvg(smallNum1Path, QSize(smallNumWidth, smallNumHeight));
|
||||
const QPoint smallNum1Offset = bigNum2Offset + QPoint(bigNumWidth + 2, smallNumHeight);
|
||||
painter.drawPixmap(smallNum1Offset, smallNum1);
|
||||
// draw big num 1
|
||||
const QString bigNum1Path = QString(":/icons/resources/icons/big%1.svg").arg(currentTimeString[0]);
|
||||
const QPixmap bigNum1 = loadSvg(bigNum1Path, QSize(bigNumWidth, bigNumHeight));
|
||||
const QPoint bigNum1Offset = backgroundOffset + QPoint(perfectIconSize / 2 - bigNumWidth * 2 + 1, perfectIconSize / 2 - bigNumHeight / 2);
|
||||
p.drawPixmap(bigNum1Offset, bigNum1);
|
||||
|
||||
// draw small num 2
|
||||
const QString smallNum2Path = QString(":/icons/resources/icons/small%1.svg").arg(currentTimeString[3]);
|
||||
const QPixmap smallNum2 = loadSvg(smallNum2Path, QSize(smallNumWidth, smallNumHeight));
|
||||
const QPoint smallNum2Offset = smallNum1Offset + QPoint(smallNumWidth + 1, 0);
|
||||
painter.drawPixmap(smallNum2Offset, smallNum2);
|
||||
// draw big num 2
|
||||
const QString bigNum2Path = QString(":/icons/resources/icons/big%1.svg").arg(currentTimeString[1]);
|
||||
const QPixmap bigNum2 = loadSvg(bigNum2Path, QSize(bigNumWidth, bigNumHeight));
|
||||
const QPoint bigNum2Offset = bigNum1Offset + QPoint(bigNumWidth + 1, 0);
|
||||
p.drawPixmap(bigNum2Offset, bigNum2);
|
||||
|
||||
// draw small num 1
|
||||
const QString smallNum1Path = QString(":/icons/resources/icons/small%1.svg").arg(currentTimeString[2]);
|
||||
const QPixmap smallNum1 = loadSvg(smallNum1Path, QSize(smallNumWidth, smallNumHeight));
|
||||
const QPoint smallNum1Offset = bigNum2Offset + QPoint(bigNumWidth + 2, smallNumHeight);
|
||||
p.drawPixmap(smallNum1Offset, smallNum1);
|
||||
|
||||
// draw small num 2
|
||||
const QString smallNum2Path = QString(":/icons/resources/icons/small%1.svg").arg(currentTimeString[3]);
|
||||
const QPixmap smallNum2 = loadSvg(smallNum2Path, QSize(smallNumWidth, smallNumHeight));
|
||||
const QPoint smallNum2Offset = smallNum1Offset + QPoint(smallNumWidth + 1, 0);
|
||||
p.drawPixmap(smallNum2Offset, smallNum2);
|
||||
}
|
||||
|
||||
// draw cached fashion mode time item
|
||||
painter.drawPixmap(rect().center() - m_cachedIcon.rect().center(), m_cachedIcon);
|
||||
}
|
||||
|
||||
void DatetimeWidget::mousePressEvent(QMouseEvent *e)
|
||||
|
@ -12,10 +12,15 @@ public:
|
||||
|
||||
private:
|
||||
QSize sizeHint() const;
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void paintEvent(QPaintEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
|
||||
const QPixmap loadSvg(const QString &fileName, const QSize size);
|
||||
|
||||
private:
|
||||
QPixmap m_cachedIcon;
|
||||
QString m_cachedTime;
|
||||
};
|
||||
|
||||
#endif // DATETIMEWIDGET_H
|
||||
|
@ -5,8 +5,11 @@ TipsWidget::TipsWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
m_mainLayout(new QHBoxLayout)
|
||||
{
|
||||
m_mainLayout->setMargin(0);
|
||||
m_mainLayout->setSpacing(0);
|
||||
|
||||
setLayout(m_mainLayout);
|
||||
setFixedHeight(32);
|
||||
setFixedHeight(26);
|
||||
}
|
||||
|
||||
void TipsWidget::clear()
|
||||
@ -27,5 +30,5 @@ void TipsWidget::addWidgets(QList<TrayWidget *> widgets)
|
||||
w->setVisible(true);
|
||||
m_mainLayout->addWidget(w);
|
||||
}
|
||||
setFixedWidth(widgets.size() * 20 + 20);
|
||||
setFixedWidth(widgets.size() * 26);
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ TrayWidget::TrayWidget(quint32 winId, QWidget *parent)
|
||||
m_updateTimer->start();
|
||||
|
||||
connect(m_updateTimer, &QTimer::timeout, this, &TrayWidget::updateIcon);
|
||||
|
||||
setFixedSize(26, 26);
|
||||
}
|
||||
|
||||
TrayWidget::~TrayWidget()
|
||||
@ -52,9 +54,18 @@ QSize TrayWidget::sizeHint() const
|
||||
|
||||
void TrayWidget::showEvent(QShowEvent *e)
|
||||
{
|
||||
m_image = getImageNonComposite();
|
||||
|
||||
QWidget::showEvent(e);
|
||||
|
||||
setX11PassMouseEvent(false);
|
||||
|
||||
// auto c = QX11Info::connection();
|
||||
// QPoint globalPos = mapToGlobal(QPoint(0, 0));
|
||||
// const uint32_t windowMoveConfigVals[2] = { uint32_t(globalPos.x()), uint32_t(globalPos.y()) };
|
||||
// xcb_configure_window(c, m_containerWid,
|
||||
// XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
|
||||
// windowMoveConfigVals);
|
||||
}
|
||||
|
||||
void TrayWidget::hideEvent(QHideEvent *e)
|
||||
@ -74,17 +85,18 @@ void TrayWidget::paintEvent(QPaintEvent *e)
|
||||
painter.begin(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
m_image = getImageNonComposite();
|
||||
if (!m_image.isNull()) {
|
||||
if (true) {
|
||||
QPainterPath path;
|
||||
path.addRoundedRect(p.x(), p.y(), iconSize, iconSize, iconSize / 2, iconSize / 2);
|
||||
// m_image = getImageNonComposite();
|
||||
// if (!m_image.isNull()) {
|
||||
// if (true) {
|
||||
// QPainterPath path;
|
||||
// path.addRoundedRect(p.x(), p.y(), iconSize, iconSize, iconSize / 2, iconSize / 2);
|
||||
|
||||
painter.setClipPath(path);
|
||||
}
|
||||
// painter.setClipPath(path);
|
||||
// }
|
||||
|
||||
painter.drawImage(p.x(), p.y(), m_image.scaled(iconSize, iconSize));
|
||||
}
|
||||
// painter.drawImage(p.x(), p.y(), m_image.scaled(iconSize, iconSize));
|
||||
// }
|
||||
painter.drawImage(rect().center() - m_image.rect().center(), m_image);
|
||||
|
||||
painter.end();
|
||||
}
|
||||
@ -226,39 +238,40 @@ void TrayWidget::updateIcon()
|
||||
{
|
||||
if (!isVisible()) return;
|
||||
|
||||
auto c = QX11Info::connection();
|
||||
// auto c = QX11Info::connection();
|
||||
|
||||
const uint32_t stackAboveData[] = {XCB_STACK_MODE_ABOVE};
|
||||
xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_STACK_MODE, stackAboveData);
|
||||
// const uint32_t stackAboveData[] = {XCB_STACK_MODE_ABOVE};
|
||||
// xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_STACK_MODE, stackAboveData);
|
||||
|
||||
QPoint globalPos = mapToGlobal(QPoint(0, 0));
|
||||
const uint32_t windowMoveConfigVals[2] = { uint32_t(globalPos.x()), uint32_t(globalPos.y()) };
|
||||
xcb_configure_window(c, m_containerWid,
|
||||
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
|
||||
windowMoveConfigVals);
|
||||
// QPoint globalPos = mapToGlobal(QPoint(0, 0));
|
||||
// const uint32_t windowMoveConfigVals[2] = { uint32_t(globalPos.x()), uint32_t(globalPos.y()) };
|
||||
// xcb_configure_window(c, m_containerWid,
|
||||
// XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
|
||||
// windowMoveConfigVals);
|
||||
|
||||
const uint32_t windowResizeConfigVals[2] = { iconSize, iconSize };
|
||||
xcb_configure_window(c, m_windowId,
|
||||
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
||||
windowResizeConfigVals);
|
||||
// const uint32_t windowResizeConfigVals[2] = { iconSize, iconSize };
|
||||
// xcb_configure_window(c, m_windowId,
|
||||
// XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
||||
// windowResizeConfigVals);
|
||||
|
||||
m_image = getImageNonComposite();
|
||||
update();
|
||||
}
|
||||
|
||||
void TrayWidget::hideIcon()
|
||||
{
|
||||
auto c = QX11Info::connection();
|
||||
//void TrayWidget::hideIcon()
|
||||
//{
|
||||
// auto c = QX11Info::connection();
|
||||
|
||||
const uint32_t stackAboveData[] = {XCB_STACK_MODE_BELOW};
|
||||
xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_STACK_MODE, stackAboveData);
|
||||
// const uint32_t stackAboveData[] = {XCB_STACK_MODE_BELOW};
|
||||
// xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_STACK_MODE, stackAboveData);
|
||||
|
||||
const uint32_t windowMoveConfigVals[2] = {0, 0};
|
||||
xcb_configure_window(c, m_containerWid,
|
||||
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
|
||||
windowMoveConfigVals);
|
||||
// const uint32_t windowMoveConfigVals[2] = {0, 0};
|
||||
// xcb_configure_window(c, m_containerWid,
|
||||
// XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
|
||||
// windowMoveConfigVals);
|
||||
|
||||
hide();
|
||||
}
|
||||
// hide();
|
||||
//}
|
||||
|
||||
void TrayWidget::sendClick(uint8_t mouseButton, int x, int y)
|
||||
{
|
||||
@ -372,9 +385,14 @@ QImage TrayWidget::getImageNonComposite() const
|
||||
|
||||
void TrayWidget::setX11PassMouseEvent(const bool pass)
|
||||
{
|
||||
auto c = QX11Info::connection();
|
||||
|
||||
if (pass)
|
||||
{
|
||||
XShapeCombineRectangles(QX11Info::display(), m_containerWid, ShapeInput, 0, 0, nullptr, 0, ShapeSet, YXBanded);
|
||||
|
||||
const uint32_t stackAboveData[] = {XCB_STACK_MODE_BELOW};
|
||||
xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_STACK_MODE, stackAboveData);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -385,5 +403,8 @@ void TrayWidget::setX11PassMouseEvent(const bool pass)
|
||||
rectangle.height = iconSize;
|
||||
|
||||
XShapeCombineRectangles(QX11Info::display(), m_containerWid, ShapeInput, 0, 0, &rectangle, 1, ShapeSet, YXBanded);
|
||||
|
||||
const uint32_t stackAboveData[] = {XCB_STACK_MODE_ABOVE};
|
||||
xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_STACK_MODE, stackAboveData);
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ private:
|
||||
|
||||
void wrapWindow();
|
||||
void updateIcon();
|
||||
void hideIcon();
|
||||
// void hideIcon();
|
||||
QImage getImageNonComposite() const;
|
||||
|
||||
private slots:
|
||||
|
Loading…
x
Reference in New Issue
Block a user