Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
refactor(listview): using new interface & adjust ui.
Browse files Browse the repository at this point in the history
Change-Id: Ib1dc73c9fa7121c01c515c3a4cc1c99a4698952f
  • Loading branch information
reionwong committed Feb 28, 2018
1 parent da61958 commit e00d1c1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 42 deletions.
37 changes: 16 additions & 21 deletions deepin-font-installer/listitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

ListItem::ListItem(DFontInfo *fontInfo, QPixmap *iconPixmap, QPixmap *closeNormalPixmap, QPixmap *closeHoverPixmap, QPixmap *closePressPixmap)
: m_fontInfo(fontInfo),
m_status(ListItem::None),
m_fontStatus(FontStatus::None),
m_iconPixmap(iconPixmap),
m_closeNormalPixmap(closeNormalPixmap),
m_closeHoverPixmap(closeHoverPixmap),
Expand All @@ -42,32 +42,27 @@ bool ListItem::sameAs(DSimpleListItem *item)
return getFilePath() == (static_cast<ListItem*>(item))->getFilePath();
}

void ListItem::drawBackground(QRect rect, QPainter *painter, int index, bool isSelect)
void ListItem::setFontStatus(FontStatus status)
{
// draw line.
painter->setOpacity(1);
painter->setPen(QColor(151, 151, 151, 255 * 0.1));
painter->drawLine(QPoint(50, rect.y() + rect.height() - 1),
QPoint(rect.width() - 10, rect.y() + rect.height() - 1));
m_fontStatus = status;
}

void ListItem::drawHover(QRect rect, QPainter *painter)
void ListItem::drawBackground(QRect rect, QPainter *painter, int index, bool isSelect, bool isHover)
{
m_rect = rect;

QPainterPath path;
path.addRect(QRectF(rect));

painter->setOpacity(1);
painter->fillPath(path, QColor(0, 0, 0, 255 * 0.05));
}
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0, 0, 0, 255 * 0.05));

void ListItem::setStatus(Status status)
{
m_status = status;
if (isHover) {
painter->drawRoundedRect(QRect(8, rect.y(), rect.width() - 16, rect.height()), 4, 4);
} else {
// draw bottom line.
painter->drawRect(QRect(50, m_rect.y(), m_rect.width() - 62, 1));
}
}

void ListItem::drawForeground(QRect rect, QPainter *painter, int column, int index, bool isSelect)
void ListItem::drawForeground(QRect rect, QPainter *painter, int column, int index, bool isSelect, bool isHover)
{
QFont font;
font.setPointSize(11);
Expand Down Expand Up @@ -108,7 +103,7 @@ void ListItem::drawForeground(QRect rect, QPainter *painter, int column, int ind
QRect statusRect = rect;
QString statusStr = "";

switch (m_status) {
switch (m_fontStatus) {
case Installed:
painter->setPen(QColor("#528315"));
statusStr = tr("Installed");
Expand All @@ -134,7 +129,7 @@ void ListItem::drawForeground(QRect rect, QPainter *painter, int column, int ind
const bool isInstalled = m_fontInfo->isInstalled;
const bool isSampleVersion = m_fontInfo->sysVersion == m_fontInfo->version;

if (isInstalled && m_status == ListItem::None) {
if (isInstalled && m_fontStatus == FontStatus::None) {
if (isSampleVersion) {
descStr = QString(tr("Same version installed"));
} else {
Expand All @@ -151,7 +146,7 @@ void ListItem::drawForeground(QRect rect, QPainter *painter, int column, int ind
descStr = painter->fontMetrics().elidedText(descStr, Qt::ElideRight, rect.width() - statusWidth - iconWidth - 50);
painter->drawText(descRect, Qt::AlignLeft | Qt::AlignTop, descStr);

if (m_status == Installed) {
if (m_fontStatus == Installed) {
return;
}

Expand Down
19 changes: 9 additions & 10 deletions deepin-font-installer/listitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ enum CloseButtonStatus {
Hide, Normal, Hover, Press
};

enum FontStatus {
None, Installing, Installed
};

class ListItem : public DSimpleListItem
{
Q_OBJECT
Expand All @@ -37,30 +41,25 @@ class ListItem : public DSimpleListItem
ListItem(DFontInfo *fontInfo, QPixmap *iconPixmap, QPixmap *closeNormalPixmap, QPixmap *closeHoverPixmap, QPixmap *closePressPixmap);
~ListItem();

enum Status {
None, Installing, Installed
};

bool sameAs(DSimpleListItem *item);
void setStatus(Status status);
void drawBackground(QRect rect, QPainter *painter, int index, bool isSelect);
void drawForeground(QRect rect, QPainter *painter, int column, int index, bool isSelect);
void drawHover(QRect rect, QPainter *painter);
void setFontStatus(FontStatus status);
void drawBackground(QRect rect, QPainter *painter, int index, bool isSelect, bool isHover);
void drawForeground(QRect rect, QPainter *painter, int column, int index, bool isSelect, bool isHover);
DFontInfo *getFontInfo() { return m_fontInfo; }
QString getFilePath();
void setCloseButtonStatus(CloseButtonStatus status);
bool isHoverCloseButton(QPoint pos);

private:
DFontInfo *m_fontInfo;
Status m_status;
FontStatus m_fontStatus;
QPixmap *m_iconPixmap;
QPixmap *m_closeNormalPixmap;
QPixmap *m_closePressPixmap;
QPixmap *m_closeHoverPixmap;
CloseButtonStatus m_close_button_status;

int closeButtonPadding = 36;
int closeButtonPadding = 30;
QRect m_rect;
};

Expand Down
17 changes: 7 additions & 10 deletions deepin-font-installer/listview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ ListView::ListView(QWidget *parent)
// set fixed height.
setFixedHeight(280);

// Enable hover effect.
setHoverEffect(true);

// init scrollbar attributes.
scrollbarColor = "#101010";
scrollbarNormalOpacity = 0.5;
Expand All @@ -59,20 +56,20 @@ void ListView::handleMouseHoverChanged(DSimpleListItem* oldItem, DSimpleListItem
{
if (oldItem == nullptr || !oldItem->sameAs(newItem)) {
if (oldItem != nullptr) {
(static_cast<ListItem *>(oldItem))->setCloseButtonStatus(Hide);
(static_cast<ListItem *>(oldItem))->setCloseButtonStatus(CloseButtonStatus::Hide);
}

if (newItem != nullptr) {
(static_cast<ListItem *>(newItem))->setCloseButtonStatus(Normal);
(static_cast<ListItem *>(newItem))->setCloseButtonStatus(CloseButtonStatus::Normal);
}

repaint();
} else {
if ((static_cast<ListItem *>(newItem))->isHoverCloseButton(pos)) {
(static_cast<ListItem *>(newItem))->setCloseButtonStatus(Hover);
(static_cast<ListItem *>(newItem))->setCloseButtonStatus(CloseButtonStatus::Hover);
repaint();
} else {
(static_cast<ListItem *>(newItem))->setCloseButtonStatus(Normal);
(static_cast<ListItem *>(newItem))->setCloseButtonStatus(CloseButtonStatus::Normal);
repaint();
}
}
Expand All @@ -82,7 +79,7 @@ void ListView::handleMousePressChanged(DSimpleListItem* item, int columnIndex, Q
{
if (item != nullptr) {
if ((static_cast<ListItem *>(item))->isHoverCloseButton(pos)) {
(static_cast<ListItem *>(item))->setCloseButtonStatus(Press);
(static_cast<ListItem *>(item))->setCloseButtonStatus(CloseButtonStatus::Press);
repaint();
}
}
Expand All @@ -91,11 +88,11 @@ void ListView::handleMousePressChanged(DSimpleListItem* item, int columnIndex, Q
void ListView::handleMouseReleaseChanged(DSimpleListItem* item, int columnIndex, QPoint pos)
{
if ((static_cast<ListItem *>(item))->isHoverCloseButton(pos)) {
(static_cast<ListItem *>(item))->setCloseButtonStatus(Hover);
(static_cast<ListItem *>(item))->setCloseButtonStatus(CloseButtonStatus::Hover);
emit closeBtnClicked(item);
repaint();
} else {
(static_cast<ListItem *>(item))->setCloseButtonStatus(Normal);
(static_cast<ListItem *>(item))->setCloseButtonStatus(CloseButtonStatus::Normal);
repaint();
}
}
2 changes: 1 addition & 1 deletion deepin-font-installer/multifilepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void MultiFilePage::onProgressChanged(const QString &filePath, const double &per
m_progress->setValue(static_cast<int>(percent));

ListItem *item = m_listItems.find(filePath).value();
item->setStatus(ListItem::Installed);
item->setFontStatus(FontStatus::Installed);
m_listView->update();

emit installing();
Expand Down

0 comments on commit e00d1c1

Please sign in to comment.