From 33f60adc582658c3bf78608f5bf715850ca3a7bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8D=9A=E6=96=87?= Date: Tue, 12 Jul 2016 16:33:01 +0800 Subject: [PATCH] optimize indicator Change-Id: I3e4c6e872390583f9a07375f06404a15ca5388f6 --- frame/frame.pro | 3 + frame/item/appitem.cpp | 82 +++++++++++++----- frame/item/appitem.h | 4 + frame/item/resources.qrc | 8 ++ frame/item/resources/indicator.png | Bin 0 -> 136 bytes frame/item/resources/indicator_active.png | Bin 0 -> 180 bytes frame/item/resources/indicator_active_ver.png | Bin 0 -> 188 bytes frame/item/resources/indicator_ver.png | Bin 0 -> 134 bytes 8 files changed, 76 insertions(+), 21 deletions(-) create mode 100644 frame/item/resources.qrc create mode 100644 frame/item/resources/indicator.png create mode 100644 frame/item/resources/indicator_active.png create mode 100644 frame/item/resources/indicator_active_ver.png create mode 100644 frame/item/resources/indicator_ver.png diff --git a/frame/frame.pro b/frame/frame.pro index e19964ee0..c2bf2f4c3 100644 --- a/frame/frame.pro +++ b/frame/frame.pro @@ -57,3 +57,6 @@ dbus_service.path = /usr/share/dbus-1/services target.path = $${PREFIX}/bin/ INSTALLS += target dbus_service + +RESOURCES += \ + item/resources.qrc diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index 174af07be..e8740b751 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -15,7 +15,11 @@ QPoint AppItem::MousePressPos; AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent) : DockItem(App, parent), m_itemEntry(new DBusDockEntry(entry.path(), this)), - m_draging(false) + m_draging(false), + m_horizontalIndicator(QPixmap(":/indicator/resources/indicator.png")), + m_verticalIndicator(QPixmap(":/indicator/resources/indicator_ver.png")), + m_activeHorizontalIndicator(QPixmap(":/indicator/resources/indicator_active.png")), + m_activeVerticalIndicator(QPixmap(":/indicator/resources/indicator_active_ver.png")) { setAcceptDrops(true); @@ -116,38 +120,74 @@ void AppItem::paintEvent(QPaintEvent *e) { if (!m_titles.isEmpty()) { - const int activeLineWidth = 2; - const int activeLineLength = 20; - QRect activeRect = itemRect; + QPoint p; + QPixmap pixmap; + QPixmap activePixmap; switch (DockPosition) { case Top: - activeRect.setBottom(activeRect.top() + activeLineWidth); - activeRect.moveBottom(activeRect.bottom() + 1); - activeRect.setWidth(activeLineLength); - activeRect.moveLeft((itemRect.width() - activeRect.width()) / 2); + pixmap = m_horizontalIndicator; + activePixmap = m_activeHorizontalIndicator; + p.setX((itemRect.width() - pixmap.width()) / 2); + p.setY(1); break; case Bottom: - activeRect.setTop(activeRect.bottom() - activeLineWidth); - activeRect.moveTop(activeRect.top() - 1); - activeRect.setWidth(activeLineLength); - activeRect.moveLeft((itemRect.width() - activeRect.width()) / 2); + pixmap = m_horizontalIndicator; + activePixmap = m_activeHorizontalIndicator; + p.setX((itemRect.width() - pixmap.width()) / 2); + p.setY(itemRect.height() - pixmap.height() - 1); break; case Left: - activeRect.setRight(activeRect.left() + activeLineWidth); - activeRect.moveRight(activeRect.right() + 1); - activeRect.setHeight(activeLineLength); - activeRect.moveTop((itemRect.height() - activeRect.height()) / 2); + pixmap = m_verticalIndicator; + activePixmap = m_activeVerticalIndicator; + p.setX(1); + p.setY((itemRect.height() - pixmap.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); + pixmap = m_verticalIndicator; + activePixmap = m_activeVerticalIndicator; + p.setX(itemRect.width() - pixmap.width() - 1); + p.setY((itemRect.height() - pixmap.height()) / 2); break; } - painter.fillRect(activeRect, QColor(163, 167, 166)); + if (m_active) + 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)); } } diff --git a/frame/item/appitem.h b/frame/item/appitem.h index 2c8a57c60..d8a99b60c 100644 --- a/frame/item/appitem.h +++ b/frame/item/appitem.h @@ -47,6 +47,10 @@ private: QString m_id; QPixmap m_smallIcon; QPixmap m_largeIcon; + QPixmap m_horizontalIndicator; + QPixmap m_verticalIndicator; + QPixmap m_activeHorizontalIndicator; + QPixmap m_activeVerticalIndicator; static int IconBaseSize; static QPoint MousePressPos; diff --git a/frame/item/resources.qrc b/frame/item/resources.qrc new file mode 100644 index 000000000..f9318f8cd --- /dev/null +++ b/frame/item/resources.qrc @@ -0,0 +1,8 @@ + + + resources/indicator_active.png + resources/indicator.png + resources/indicator_ver.png + resources/indicator_active_ver.png + + diff --git a/frame/item/resources/indicator.png b/frame/item/resources/indicator.png new file mode 100644 index 0000000000000000000000000000000000000000..907ba6ed639eeb696b378bc2e92c90da2eef8241 GIT binary patch literal 136 zcmeAS@N?(olHy`uVBq!ia0vp^B0$W&x{A8C%-raoJu3UX4P zCfi3iYH22WQ%mvv4FO#q2%Lks`_ literal 0 HcmV?d00001 diff --git a/frame/item/resources/indicator_active_ver.png b/frame/item/resources/indicator_active_ver.png new file mode 100644 index 0000000000000000000000000000000000000000..4fdfd4a66f95c46ccfd8586ec1e19dd666125606 GIT binary patch literal 188 zcmeAS@N?(olHy`uVBq!ia0vp^Oh7Ec!3HFkTfSKYq*&4&eH|GXHuiJ>Nn{1`i#=T& zLpWr0dk+d8HsD}+-%#@;?ow)(XZNn{1`Z9QEa zLpWrU|NQ^IpOsl)1B0P>-Ld*NSr(1EBpie87`!bI44ZMqe1=E|quF!rO(GH2T~ZsW g_Z=!}l;ALB*l>-n{eH3p2hbn}Pgg&ebxsLQ04HlGZvX%Q literal 0 HcmV?d00001