409 lines
14 KiB
C++
409 lines
14 KiB
C++
|
#include "filemanagewin.h"
|
||
|
|
||
|
#include <QHBoxLayout>
|
||
|
#include <QFont>
|
||
|
#include <QScrollBar>
|
||
|
#include <QDebug>
|
||
|
|
||
|
const int BUTTON_WIDTH = 16;
|
||
|
const int BUTTON_HEIGHT = 16;
|
||
|
const int SEARCHLINE_WIDTH = 200;
|
||
|
|
||
|
FileManageWin::FileManageWin(QWidget *parent) : QWidget(parent)
|
||
|
{
|
||
|
setProperty("setWidth", 0);
|
||
|
setAutoFillBackground(true);
|
||
|
setBackgroundRole(QPalette::Base);
|
||
|
|
||
|
m_retreatBtn = new kdk::KToolButton(this);
|
||
|
connect(m_retreatBtn, &kdk::KToolButton::clicked, this, &FileManageWin::slotKdkBtnClicked);
|
||
|
m_retreatBtn->setIcon(QIcon::fromTheme("go-next-rtl-symbolic"));
|
||
|
m_retreatBtn->setIconSize(QSize(BUTTON_WIDTH, BUTTON_HEIGHT));
|
||
|
m_retreatBtn->setToolTip(tr("Go Back"));
|
||
|
m_retreatBtn->setType(kdk::KToolButtonType::Flat);
|
||
|
m_retreatBtn->setCursor(Qt::PointingHandCursor);
|
||
|
m_retreatBtn->setFocusPolicy(Qt::NoFocus);
|
||
|
m_retreatBtn->setEnabled(false);
|
||
|
|
||
|
m_forwardBtn = new kdk::KToolButton(this);
|
||
|
connect(m_forwardBtn, &kdk::KToolButton::clicked, this, &FileManageWin::slotKdkBtnClicked);
|
||
|
m_forwardBtn->setIcon(QIcon::fromTheme("go-next-symbolic"));
|
||
|
m_forwardBtn->setIconSize(QSize(BUTTON_WIDTH, BUTTON_HEIGHT));
|
||
|
m_forwardBtn->setToolTip(tr("Go Forward"));
|
||
|
m_forwardBtn->setType(kdk::KToolButtonType::Flat);
|
||
|
m_forwardBtn->setCursor(Qt::PointingHandCursor);
|
||
|
m_forwardBtn->setFocusPolicy(Qt::NoFocus);
|
||
|
m_forwardBtn->setEnabled(false);
|
||
|
|
||
|
QFont font;
|
||
|
font.setBold(true);
|
||
|
//面包屑
|
||
|
m_crumb = new kdk::KBreadCrumb(this);
|
||
|
connect(m_crumb, &kdk::KBreadCrumb::currentChanged, this, &FileManageWin::slotCrumbIndexChange);
|
||
|
m_crumb->setFont(font);
|
||
|
m_crumb->setFlat(false);
|
||
|
m_crumb->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||
|
|
||
|
m_searchBtn = new kdk::KToolButton(this);
|
||
|
connect(m_searchBtn, &kdk::KToolButton::clicked, this, &FileManageWin::slotKdkBtnClicked);
|
||
|
m_searchBtn->setIcon(QIcon::fromTheme("system-search-symbolic"));
|
||
|
m_searchBtn->setIconSize(QSize(BUTTON_WIDTH, BUTTON_HEIGHT));
|
||
|
m_searchBtn->setToolTip(tr("Search File"));
|
||
|
m_searchBtn->setType(kdk::KToolButtonType::Flat);
|
||
|
m_searchBtn->setFocusPolicy(Qt::NoFocus);
|
||
|
m_searchBtn->setCursor(Qt::PointingHandCursor);
|
||
|
|
||
|
m_searchLine = new kdk::KSearchLineEdit(this);
|
||
|
connect(m_searchLine, &kdk::KSearchLineEdit::textChanged, this, &FileManageWin::slotSearchTextChanged);
|
||
|
m_searchLine->setFixedHeight(40);
|
||
|
m_searchLine->setFixedWidth(0);
|
||
|
m_searchLine->setFocusPolicy(Qt::NoFocus);
|
||
|
m_searchLine->setClearButtonEnabled(true);
|
||
|
m_searchLine->setContextMenuPolicy(Qt::DefaultContextMenu);
|
||
|
m_searchLine->installEventFilter(this);
|
||
|
m_searchLine->hide();
|
||
|
|
||
|
m_searchLineAnimation = new QPropertyAnimation(this, "setWidth");
|
||
|
connect(m_searchLineAnimation, &QPropertyAnimation::valueChanged, this, &FileManageWin::slotAnimationValueChanged);
|
||
|
// 设置动画时长;
|
||
|
m_searchLineAnimation->setDuration(200);
|
||
|
// 设置动画变化类型;
|
||
|
m_searchLineAnimation->setEasingCurve(QEasingCurve::OutQuad);
|
||
|
|
||
|
m_editBtn = new kdk::KToolButton(this);
|
||
|
connect(m_editBtn, &kdk::KToolButton::clicked, this, &FileManageWin::slotKdkBtnClicked);
|
||
|
m_editBtn->setIcon(QIcon::fromTheme("document-edit-symbolic"));
|
||
|
m_editBtn->setIconSize(QSize(BUTTON_WIDTH, BUTTON_HEIGHT));
|
||
|
m_editBtn->setToolTip(tr("Select"));
|
||
|
m_editBtn->setType(kdk::KToolButtonType::Flat);
|
||
|
m_editBtn->setFocusPolicy(Qt::NoFocus);
|
||
|
m_editBtn->setCursor(Qt::PointingHandCursor);
|
||
|
|
||
|
m_verticalLine = new QFrame(this);
|
||
|
m_verticalLine->setLineWidth(1);
|
||
|
m_verticalLine->setFixedHeight(16);
|
||
|
m_verticalLine->setFrameShape(QFrame::VLine);
|
||
|
m_verticalLine->setFrameShadow(QFrame::Raised);
|
||
|
m_verticalLine->setFocusPolicy(Qt::NoFocus);
|
||
|
|
||
|
//模式
|
||
|
m_modeBtn = new kdk::KToolButton(this);
|
||
|
connect(m_modeBtn, &kdk::KToolButton::clicked, this, &FileManageWin::slotKdkBtnClicked);
|
||
|
m_modeBtn->setIcon(QIcon::fromTheme("view-grid-symbolic"));
|
||
|
m_modeBtn->setIconSize(QSize(BUTTON_WIDTH, BUTTON_HEIGHT));
|
||
|
m_modeBtn->setType(kdk::KToolButtonType::Flat);
|
||
|
m_modeBtn->setToolTip(tr("List Mode"));
|
||
|
m_modeBtn->setFocusPolicy(Qt::NoFocus);
|
||
|
m_modeBtn->setCursor(Qt::PointingHandCursor);
|
||
|
|
||
|
//刷新
|
||
|
m_refreshBtn = new kdk::KToolButton(this);
|
||
|
connect(m_refreshBtn, &kdk::KToolButton::clicked, this, &FileManageWin::slotKdkBtnClicked);
|
||
|
m_refreshBtn->setIcon(QIcon::fromTheme("view-refresh-symbolic"));
|
||
|
m_refreshBtn->setIconSize(QSize(BUTTON_WIDTH, BUTTON_HEIGHT));
|
||
|
m_refreshBtn->setType(kdk::KToolButtonType::Flat);
|
||
|
m_refreshBtn->setToolTip(tr("Refresh"));
|
||
|
m_refreshBtn->setFocusPolicy(Qt::NoFocus);
|
||
|
m_refreshBtn->setCursor(Qt::PointingHandCursor);
|
||
|
|
||
|
m_statusLab = new QLabel(this);
|
||
|
m_statusLab->setText(tr("Select File"));
|
||
|
m_statusLab->setFont(font);
|
||
|
m_statusLab->setFixedHeight(20);
|
||
|
m_statusLab->setFocusPolicy(Qt::NoFocus);
|
||
|
m_statusLab->hide();
|
||
|
|
||
|
m_selectBtn = new ClickLabel(this);
|
||
|
connect(m_selectBtn, &ClickLabel::clicked, this, &FileManageWin::slotBtnClicked);
|
||
|
m_selectBtn->setText(tr("Select All"));
|
||
|
m_selectBtn->setStyleSheet("color:#3790FA;");
|
||
|
m_selectBtn->setCursor(Qt::PointingHandCursor);
|
||
|
m_selectBtn->setFixedHeight(20);
|
||
|
m_selectBtn->setFocusPolicy(Qt::NoFocus);
|
||
|
m_selectBtn->hide();
|
||
|
|
||
|
m_finishBtn = new ClickLabel(this);
|
||
|
connect(m_finishBtn, &ClickLabel::clicked, this, &FileManageWin::slotBtnClicked);
|
||
|
m_finishBtn->setText(tr("Finish"));
|
||
|
m_finishBtn->setStyleSheet("color:#3790FA;");
|
||
|
m_finishBtn->setCursor(Qt::PointingHandCursor);
|
||
|
m_finishBtn->setFixedHeight(20);
|
||
|
m_finishBtn->setFocusPolicy(Qt::NoFocus);
|
||
|
m_finishBtn->hide();
|
||
|
|
||
|
QHBoxLayout *hLayout = new QHBoxLayout;
|
||
|
hLayout->setMargin(0);
|
||
|
hLayout->setSpacing(0);
|
||
|
hLayout->addWidget(m_retreatBtn);
|
||
|
hLayout->addSpacing(12);
|
||
|
hLayout->addWidget(m_forwardBtn);
|
||
|
hLayout->addWidget(m_statusLab);
|
||
|
hLayout->addSpacing(28);
|
||
|
hLayout->addWidget(m_crumb);
|
||
|
hLayout->addStretch();
|
||
|
hLayout->addWidget(m_searchBtn);
|
||
|
hLayout->addSpacing(12);
|
||
|
hLayout->addWidget(m_searchLine);
|
||
|
hLayout->addWidget(m_editBtn);
|
||
|
hLayout->addWidget(m_selectBtn);
|
||
|
hLayout->addSpacing(12);
|
||
|
hLayout->addWidget(m_verticalLine);
|
||
|
hLayout->addSpacing(12);
|
||
|
hLayout->addWidget(m_finishBtn);
|
||
|
hLayout->addWidget(m_modeBtn);
|
||
|
hLayout->addSpacing(12);
|
||
|
hLayout->addWidget(m_refreshBtn);
|
||
|
|
||
|
m_stackedWin = new QStackedWidget(this);
|
||
|
|
||
|
m_loadAnimation = new LoadAnimation(this);
|
||
|
m_stackedWin->addWidget(m_loadAnimation);
|
||
|
m_stackedWin->setCurrentIndex(FileManageWin::PageIndex::LoadPage);
|
||
|
|
||
|
QVBoxLayout *vLayout = new QVBoxLayout;
|
||
|
vLayout->setMargin(0);
|
||
|
vLayout->setSpacing(0);
|
||
|
vLayout->addLayout(hLayout);
|
||
|
vLayout->addSpacing(8);
|
||
|
vLayout->addWidget(m_stackedWin);
|
||
|
setLayout(vLayout);
|
||
|
}
|
||
|
|
||
|
void FileManageWin::setWidget(QWidget *win, FileManageWin::TabType type)
|
||
|
{
|
||
|
m_type = type;
|
||
|
changeTabMode(m_type);
|
||
|
if (m_stackedWin->count() > 1) {
|
||
|
m_stackedWin->removeWidget(m_stackedWin->widget(FileManageWin::PageIndex::InfoPage));
|
||
|
}
|
||
|
m_stackedWin->addWidget(win);
|
||
|
m_stackedWin->setCurrentIndex(FileManageWin::PageIndex::InfoPage);
|
||
|
}
|
||
|
|
||
|
void FileManageWin::pushCrumb(QString str)
|
||
|
{
|
||
|
m_crumb->addTab(str);
|
||
|
m_crumb->setCurrentIndex(m_crumb->count() - 1);
|
||
|
}
|
||
|
|
||
|
void FileManageWin::load()
|
||
|
{
|
||
|
m_stackedWin->setCurrentIndex(FileManageWin::PageIndex::LoadPage);
|
||
|
if (m_stackedWin->count() > 1) {
|
||
|
m_stackedWin->removeWidget(m_stackedWin->widget(FileManageWin::PageIndex::InfoPage));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void FileManageWin::setGoBackEnabled(bool isEnabled)
|
||
|
{
|
||
|
m_retreatBtn->setEnabled(isEnabled);
|
||
|
}
|
||
|
void FileManageWin::setGoForwardEnabled(bool isEnabled)
|
||
|
{
|
||
|
m_forwardBtn->setEnabled(isEnabled);
|
||
|
}
|
||
|
|
||
|
bool FileManageWin::eventFilter(QObject *obj, QEvent *event)
|
||
|
{
|
||
|
if (obj == m_searchLine) {
|
||
|
if (event->type() == QEvent::FocusOut) {
|
||
|
m_isSearchLineHiddenIn = true;
|
||
|
m_searchLine->clear();
|
||
|
m_searchLineAnimation->setStartValue(SEARCHLINE_WIDTH);
|
||
|
m_searchLineAnimation->setEndValue(0);
|
||
|
m_searchLineAnimation->start();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return QWidget::eventFilter(obj, event);
|
||
|
}
|
||
|
|
||
|
void FileManageWin::mousePressEvent(QMouseEvent *event)
|
||
|
{
|
||
|
hideSearchLine();
|
||
|
}
|
||
|
|
||
|
void FileManageWin::changeTabMode(FileManageWin::TabType type)
|
||
|
{
|
||
|
if (m_statusLab->text() == tr("Search File")) {
|
||
|
m_statusLab->setText(tr("Select File"));
|
||
|
}
|
||
|
switch (type) {
|
||
|
case FileManageWin::TabType::Default: {
|
||
|
m_retreatBtn->show();
|
||
|
m_forwardBtn->show();
|
||
|
m_statusLab->hide();
|
||
|
m_crumb->show();
|
||
|
m_searchBtn->show();
|
||
|
m_editBtn->hide();
|
||
|
m_verticalLine->show();
|
||
|
m_modeBtn->show();
|
||
|
m_refreshBtn->show();
|
||
|
} break;
|
||
|
case FileManageWin::TabType::AndroidHomePage: {
|
||
|
m_retreatBtn->hide();
|
||
|
m_forwardBtn->hide();
|
||
|
m_statusLab->hide();
|
||
|
m_searchBtn->show();
|
||
|
m_crumb->show();
|
||
|
m_editBtn->hide();
|
||
|
m_verticalLine->hide();
|
||
|
m_modeBtn->hide();
|
||
|
m_refreshBtn->hide();
|
||
|
} break;
|
||
|
case FileManageWin::TabType::AppHomePage: {
|
||
|
m_retreatBtn->show();
|
||
|
m_forwardBtn->hide();
|
||
|
m_statusLab->hide();
|
||
|
m_crumb->show();
|
||
|
m_searchBtn->show();
|
||
|
m_editBtn->hide();
|
||
|
m_verticalLine->hide();
|
||
|
m_modeBtn->show();
|
||
|
m_refreshBtn->show();
|
||
|
} break;
|
||
|
case FileManageWin::TabType::MultiMediaPage: {
|
||
|
m_retreatBtn->show();
|
||
|
m_forwardBtn->hide();
|
||
|
m_statusLab->hide();
|
||
|
m_crumb->show();
|
||
|
m_searchBtn->show();
|
||
|
m_editBtn->show();
|
||
|
m_verticalLine->show();
|
||
|
m_modeBtn->show();
|
||
|
m_refreshBtn->show();
|
||
|
} break;
|
||
|
case FileManageWin::TabType::SearchResultsPage: {
|
||
|
if (m_statusLab->text() == tr("Select File")) {
|
||
|
m_statusLab->setText(tr("Search File"));
|
||
|
}
|
||
|
m_retreatBtn->show();
|
||
|
m_forwardBtn->hide();
|
||
|
m_statusLab->show();
|
||
|
m_crumb->hide();
|
||
|
if (m_searchLine->isHidden()) {
|
||
|
m_searchBtn->show();
|
||
|
m_editBtn->show();
|
||
|
m_verticalLine->show();
|
||
|
}
|
||
|
m_modeBtn->show();
|
||
|
m_refreshBtn->show();
|
||
|
|
||
|
m_isSearch = true;
|
||
|
} break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void FileManageWin::hideSearchLine()
|
||
|
{
|
||
|
setFocus();
|
||
|
m_searchLine->setFocusPolicy(Qt::NoFocus);
|
||
|
}
|
||
|
|
||
|
void FileManageWin::slotCrumbIndexChange(int index)
|
||
|
{
|
||
|
hideSearchLine();
|
||
|
for (int i = m_crumb->count() - 1; i > index; i--) {
|
||
|
m_crumb->removeTab(i);
|
||
|
}
|
||
|
Q_EMIT sigCrumbIndexChange(index, m_crumb->tabText(index));
|
||
|
}
|
||
|
|
||
|
void FileManageWin::slotKdkBtnClicked()
|
||
|
{
|
||
|
hideSearchLine();
|
||
|
|
||
|
kdk::KToolButton *btn = qobject_cast<kdk::KToolButton *>(sender());
|
||
|
if (btn == m_retreatBtn) {
|
||
|
if (m_isSearch) {
|
||
|
m_isSearch = false;
|
||
|
load();
|
||
|
Q_EMIT sigBtnCliked(FileManageWin::BtnType::ReturnBtn);
|
||
|
} else {
|
||
|
Q_EMIT sigBtnCliked(FileManageWin::BtnType::GoBacktBtn);
|
||
|
}
|
||
|
} else if (btn == m_forwardBtn) {
|
||
|
Q_EMIT sigBtnCliked(FileManageWin::BtnType::GoForwardBtn);
|
||
|
} else if (btn == m_searchBtn) {
|
||
|
m_searchBtn->hide();
|
||
|
m_editBtn->hide();
|
||
|
m_verticalLine->hide();
|
||
|
m_searchLine->show();
|
||
|
m_searchLineAnimation->setStartValue(0);
|
||
|
m_searchLineAnimation->setEndValue(SEARCHLINE_WIDTH);
|
||
|
m_searchLineAnimation->start();
|
||
|
} else if (btn == m_editBtn) {
|
||
|
Q_EMIT sigBtnCliked(FileManageWin::BtnType::EditBtn);
|
||
|
m_retreatBtn->hide();
|
||
|
m_forwardBtn->hide();
|
||
|
m_crumb->hide();
|
||
|
m_editBtn->hide();
|
||
|
m_modeBtn->hide();
|
||
|
m_refreshBtn->hide();
|
||
|
m_searchBtn->hide();
|
||
|
m_statusLab->show();
|
||
|
m_selectBtn->show();
|
||
|
m_finishBtn->show();
|
||
|
} else if (btn == m_modeBtn) {
|
||
|
if (m_isListMode) {
|
||
|
Q_EMIT sigBtnCliked(FileManageWin::BtnType::ListModeBtn);
|
||
|
m_modeBtn->setIcon(QIcon::fromTheme("view-list-symbolic"));
|
||
|
m_modeBtn->setToolTip(tr("Icon Mode"));
|
||
|
m_isListMode = false;
|
||
|
} else {
|
||
|
Q_EMIT sigBtnCliked(FileManageWin::BtnType::IconModeBtn);
|
||
|
m_modeBtn->setIcon(QIcon::fromTheme("view-grid-symbolic"));
|
||
|
m_modeBtn->setToolTip(tr("List Mode"));
|
||
|
m_isListMode = true;
|
||
|
}
|
||
|
} else if (btn == m_refreshBtn) {
|
||
|
Q_EMIT sigBtnCliked(FileManageWin::BtnType::RefreshBtn);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void FileManageWin::slotBtnClicked()
|
||
|
{
|
||
|
hideSearchLine();
|
||
|
|
||
|
ClickLabel *btn = qobject_cast<ClickLabel *>(sender());
|
||
|
if (btn == m_selectBtn) {
|
||
|
if (m_selectBtn->text() == tr("Select All")) {
|
||
|
m_selectBtn->setText(tr("Deselect All"));
|
||
|
Q_EMIT sigBtnCliked(FileManageWin::BtnType::SelectBtn);
|
||
|
} else if (m_selectBtn->text() == tr("Deselect All")) {
|
||
|
m_selectBtn->setText(tr("Select All"));
|
||
|
Q_EMIT sigBtnCliked(FileManageWin::BtnType::CancelSelectBtn);
|
||
|
}
|
||
|
} else if (btn == m_finishBtn) {
|
||
|
Q_EMIT sigBtnCliked(FileManageWin::BtnType::EditFinishBtn);
|
||
|
m_selectBtn->hide();
|
||
|
m_finishBtn->hide();
|
||
|
if (m_selectBtn->text() == tr("Deselect All")) {
|
||
|
m_selectBtn->setText(tr("Select All"));
|
||
|
Q_EMIT sigBtnCliked(FileManageWin::BtnType::CancelSelectBtn);
|
||
|
}
|
||
|
changeTabMode(m_type);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void FileManageWin::slotAnimationValueChanged(const QVariant &value)
|
||
|
{
|
||
|
m_searchLine->setFixedWidth(value.toInt());
|
||
|
if (m_isSearchLineHiddenIn && value.toInt() == 0) {
|
||
|
m_searchLine->hide();
|
||
|
changeTabMode(m_type);
|
||
|
m_isSearchLineHiddenIn = false;
|
||
|
} else if (!m_isSearchLineHiddenIn && value.toInt() == SEARCHLINE_WIDTH) {
|
||
|
m_searchLine->setFocus();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void FileManageWin::slotSearchTextChanged()
|
||
|
{
|
||
|
if (m_isSearchLineHiddenIn) {
|
||
|
return;
|
||
|
}
|
||
|
load();
|
||
|
Q_EMIT sigSearchTextChanged(m_searchLine->text());
|
||
|
}
|