-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprilistwid.cpp
More file actions
94 lines (83 loc) · 2.66 KB
/
prilistwid.cpp
File metadata and controls
94 lines (83 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "prilistwid.h"
#include <QPainter>
#include <QGuiApplication>
#include "protreeitem.h"
#include "const.h"
#include "prelistitem.h"
PriListWid::PriListWid(QWidget *parent):QListWidget(parent),m_global(0),m_lastIndex(17)
{
this->setViewMode(QListWidget::IconMode);
this->setIconSize(QSize(PREICON_SIZE,PREICON_SIZE));
this->setSpacing(5);
connect(this,&PriListWid::itemPressed,this,&PriListWid::SlotItemPressed);
}
PriListWid::~PriListWid()
{
}
void PriListWid::AddListItem(const QString &path)
{
QPixmap srcPixmap(path);
srcPixmap = srcPixmap.scaled(PREICON_SIZE,PREICON_SIZE,Qt::KeepAspectRatioByExpanding);
QPixmap distPixmap(QSize(PREICON_SIZE,PREICON_SIZE));
distPixmap.fill(QColor(220,220,220,50));
QPainter painter(&distPixmap);
int distcWidth = distPixmap.width();
int distHeight = distPixmap.height();
int srcWidth = srcPixmap.width();
int srcHeight = srcPixmap.height();
int x = (distcWidth - srcWidth)/2;
int y = (distHeight -srcHeight)/2;
painter.drawPixmap(x,y,srcPixmap);
m_global++;
PreListItem *pItem = new PreListItem(QIcon(distPixmap),path,m_global,this);
pItem->setSizeHint(QSize(PREICON_SIZE,PREICON_SIZE));
this->addItem(pItem);
m_setItems[path] = pItem;
if(m_global == 1){
m_posOrigin = this->pos();
}
}
void PriListWid::SlotUpPreList(QTreeWidgetItem *treeItem)
{
if(!treeItem){
return;
}
ProTreeItem *proItem = dynamic_cast<ProTreeItem *>(treeItem);
QString path = proItem->GetPath();
auto iter = m_setItems.find(path);
if(iter != m_setItems.end()){
return;
}
AddListItem(path);
}
void PriListWid::SlotSelectItem(QTreeWidgetItem *treeItem)
{
if(!treeItem)
return;
ProTreeItem *proItem = dynamic_cast<ProTreeItem *>(treeItem);
QString path = proItem->GetPath();
auto iter = m_setItems.find(path);
if(iter == m_setItems.end()){
return;
}
PreListItem *listItem = dynamic_cast<PreListItem *>(iter.value());
int index = listItem->GetIndex();
if(index > 17){
QPoint posCur = this->pos();
this->move(posCur.x() - (index -m_lastIndex)*100,posCur.y());
}else{
this->move(m_posOrigin);
m_lastIndex = 17;
}
this->setCurrentItem(iter.value());
}
void PriListWid::SlotItemPressed(QListWidgetItem *item)
{
if(QGuiApplication::mouseButtons() != Qt::LeftButton){
return;
}
PreListItem *listItem = dynamic_cast<PreListItem *>(item);
QString path = listItem->GetPath();
this->setCurrentItem(item);
emit SigupSelectShow(path);
}