Skip to content

Commit

Permalink
feat: refactor mainwindow UI
Browse files Browse the repository at this point in the history
1.refactor titlebar layout
2.move tabbar from workspace to titlebar
3.update ui style of some components

Log: as title
  • Loading branch information
Lighto-Ku committed Oct 19, 2024
1 parent 1606beb commit 92ae853
Show file tree
Hide file tree
Showing 54 changed files with 945 additions and 914 deletions.
2 changes: 1 addition & 1 deletion src/dfm-base/widgets/dfmwindow/filemanagerwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ void FileManagerWindow::installTitleBar(AbstractFrame *w)
std::call_once(d->titleBarFlag, [this, w]() {
d->titleBar = w;
d->titleBar->setCurrentUrl(d->currentUrl);

initializeUi();

emit this->titleBarInstallFinished();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ void BookMarkEventCaller::sendOpenBookMarkInWindow(quint64 windowId, const QUrl

bool BookMarkEventCaller::sendCheckTabAddable(quint64 windowId)
{
return dpfSlotChannel->push("dfmplugin_workspace", "slot_Tab_Addable", windowId).toBool();
return dpfSlotChannel->push("dfmplugin_titlebar", "slot_Tab_Addable", windowId).toBool();
}
2 changes: 1 addition & 1 deletion src/plugins/common/dfmplugin-burn/utils/burnjobmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void BurnJobManager::initBurnJobConnect(AbstractBurnJob *job)
connect(job, &AbstractBurnJob::requestFailureDialog, this, &BurnJobManager::showOpticalJobFailureDialog);
connect(job, &AbstractBurnJob::requestErrorMessageDialog, DialogManagerInstance, &DialogManager::showErrorDialog);
connect(job, &AbstractBurnJob::requestCloseTab, this, [](const QUrl &url) {
dpfSlotChannel->push("dfmplugin_workspace", "slot_Tab_Close", url);
dpfSlotChannel->push("dfmplugin_titlebar", "slot_Tab_Close", url);
});
connect(job, &AbstractBurnJob::requestReloadDisc, this, [](const QString &devId) {
DevMngIns->mountBlockDevAsync(devId, {}, [devId](bool, const DFMMOUNT::OperationErrorInfo &, const QString &) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/common/dfmplugin-tag/events/tageventcaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void TagEventCaller::sendFileUpdate(const QString &path)

bool TagEventCaller::sendCheckTabAddable(quint64 windowId)
{
return dpfSlotChannel->push("dfmplugin_workspace", "slot_Tab_Addable", windowId).toBool();
return dpfSlotChannel->push("dfmplugin_titlebar", "slot_Tab_Addable", windowId).toBool();
}

QRectF TagEventCaller::getVisibleGeometry(const quint64 windowID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void Computer::followEvents()
{
dpfHookSequence->follow("dfmplugin_titlebar", "hook_Crumb_Seprate", ComputerEventReceiver::instance(), &ComputerEventReceiver::handleSepateTitlebarCrumb);
dpfHookSequence->follow("dfmplugin_sidebar", "hook_Group_Sort", ComputerEventReceiver::instance(), &ComputerEventReceiver::handleSortItem);
dpfHookSequence->follow("dfmplugin_workspace", "hook_Tab_SetTabName", ComputerEventReceiver::instance(), &ComputerEventReceiver::handleSetTabName);
dpfHookSequence->follow("dfmplugin_titlebar", "hook_Tab_SetTabName", ComputerEventReceiver::instance(), &ComputerEventReceiver::handleSetTabName);
}

void Computer::bindWindows()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void ComputerController::doSetAlias(DFMEntryFileInfoPointer info, const QString
{ "Property_Key_Editable", true }
};
dpfSlotChannel->push("dfmplugin_sidebar", "slot_Item_Update", info->urlOf(UrlInfoType::kUrl), map);
dpfSlotChannel->push("dfmplugin_workspace", "slot_Tab_SetAlias", info->targetUrl(), displayAlias);
dpfSlotChannel->push("dfmplugin_titlebar", "slot_Tab_SetAlias", info->targetUrl(), displayAlias);
Q_EMIT updateItemAlias(info->urlOf(UrlInfoType::kUrl));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void ComputerMenuScene::updateState(QMenu *parent)
break;
}

if (!dpfSlotChannel->push("dfmplugin_workspace", "slot_Tab_Addable", d->windowId).toBool())
if (!dpfSlotChannel->push("dfmplugin_titlebar", "slot_Tab_Addable", d->windowId).toBool())
disabled.append(kOpenInNewTab);

// do not show 'rename' entry for loop devices.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ void RecentEventCaller::sendCutFiles(const quint64 windowID, const QList<QUrl> &

bool RecentEventCaller::sendCheckTabAddable(quint64 windowId)
{
return dpfSlotChannel->push("dfmplugin_workspace", "slot_Tab_Addable", windowId).toBool();
return dpfSlotChannel->push("dfmplugin_titlebar", "slot_Tab_Addable", windowId).toBool();
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ void SideBarEventCaller::sendShowFilePropertyDialog(const QUrl &url)

bool SideBarEventCaller::sendCheckTabAddable(quint64 windowId)
{
return dpfSlotChannel->push("dfmplugin_workspace", "slot_Tab_Addable", windowId).toBool();
return dpfSlotChannel->push("dfmplugin_titlebar", "slot_Tab_Addable", windowId).toBool();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <QDebug>
#include <QCloseEvent>
#include <QTimer>
#include <QGraphicsEffect>

using namespace dfmplugin_sidebar;
DFMBASE_USE_NAMESPACE
Expand Down Expand Up @@ -321,12 +320,6 @@ void SideBarWidget::onItemRenamed(const QModelIndex &index, const QString &newNa

void SideBarWidget::initializeUi()
{
QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect(this);
effect->setColor(QColor(0, 0, 0, 5));
effect->setOffset(4, 0);
effect->setBlurRadius(20);
setGraphicsEffect(effect);

QHBoxLayout *hlayout = new QHBoxLayout(this);
hlayout->setContentsMargins(0, 0, 0, 0);
hlayout->setSpacing(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ inline constexpr int kIconHeight { 14 };
inline constexpr int kItemHeight { 30 };
inline constexpr int kItemMargin { 8 };
inline constexpr int kCompleterMaxHeight { 260 };
inline constexpr int kToolButtonSize { 30 };
inline constexpr int kToolButtonIconSize { 14 };
inline constexpr int kMaxTabCount { 8 };

namespace CustomKey {
inline constexpr char kUrl[] { "CrumbData_Key_Url" };
Expand Down Expand Up @@ -126,7 +129,6 @@ inline constexpr char kAcComputerTitleBar[] { "computer_title_bar" };
inline constexpr char kAcComputerTitleBarAddress[] { "AddressToolBar" };
inline constexpr char kAcComputerTitleBarBackBtn[] { "back_button" };
inline constexpr char kAcComputerTitleBarForwardBtn[] { "forword_button" };
inline constexpr char kAcComputerTitleBarBtnBox[] { "button_box" };
inline constexpr char kAcComputerTitleBarSearchBtn[] { "search_button" };
inline constexpr char kAcComputerTitleBarDetailBtn[] { "detail_button" };
inline constexpr char kAcComputerTitleBarListViewBtn[] { "listView_button" };
Expand All @@ -138,10 +140,13 @@ inline constexpr char kAcComputerTitleBarCollectionServerView[] { "collectionSer
inline constexpr char kAcComputerCrumbBarLeftArrow[] { "left_arrow" };
inline constexpr char kAcComputerCrumbBarRightArrow[] { "right_arrow" };
inline constexpr char kAcComputerCrumbBarListView[] { "crumb_list_view" };
inline constexpr char kAcViewTabBarNewButton[] { "NewTabButton" };
inline constexpr char kAcViewTabBar[] { "TabBar" };
}

DPTITLEBAR_END_NAMESPACE
Q_DECLARE_METATYPE(QList<QVariantMap> *);
Q_DECLARE_METATYPE(QUrl *);
Q_DECLARE_METATYPE(QString *);

#endif // DFMPLUGIN_TITLEBAR_GLOBAL_H
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

#include <dfm-framework/dpf.h>

Q_DECLARE_METATYPE(QString *)

using namespace dfmplugin_titlebar;
DFMGLOBAL_USE_NAMESPACE

Expand Down Expand Up @@ -43,6 +41,11 @@ void TitleBarEventCaller::sendCd(QWidget *sender, const QUrl &url)
dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kChangeCurrentUrl, id, url);
}

void TitleBarEventCaller::sendChangeCurrentUrl(quint64 windowId, const QUrl &url)
{
dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kChangeCurrentUrl, windowId, url);
}

void TitleBarEventCaller::sendOpenFile(QWidget *sender, const QUrl &url)
{
quint64 id = TitleBarHelper::windowId(sender);
Expand Down Expand Up @@ -88,9 +91,9 @@ void TitleBarEventCaller::sendCheckAddressInputStr(QWidget *sender, QString *str
dpfSignalDispatcher->publish("dfmplugin_titlebar", "signal_InputAdddressStr_Check", id, str);
}

bool TitleBarEventCaller::sendCheckTabAddable(quint64 windowId)
void TitleBarEventCaller::sendTabChanged(quint64 windowId, int tabIndex)
{
return dpfSlotChannel->push("dfmplugin_workspace", "slot_Tab_Addable", windowId).toBool();
dpfSignalDispatcher->publish("dfmplugin_titlebar", "signal_Tab_Changed", windowId, tabIndex);
}

ViewMode TitleBarEventCaller::sendGetDefualtViewMode(const QString &scheme)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ class TitleBarEventCaller
static void sendViewMode(QWidget *sender, DFMBASE_NAMESPACE::Global::ViewMode mode);
static void sendDetailViewState(QWidget *sender, bool checked);
static void sendCd(QWidget *sender, const QUrl &url);
static void sendChangeCurrentUrl(quint64 windowId, const QUrl &url);
static void sendOpenFile(QWidget *sender, const QUrl &url);
static void sendOpenWindow(const QUrl &url);
static void sendOpenTab(quint64 windowId, const QUrl &url);
static void sendSearch(QWidget *sender, const QString &keyword);
static void sendStopSearch(QWidget *sender);
static void sendShowFilterView(QWidget *sender, bool visible);
static void sendCheckAddressInputStr(QWidget *sender, QString *str);
static bool sendCheckTabAddable(quint64 windowId);
static void sendTabChanged(quint64 windowId, int tabIndex);
static DFMGLOBAL_NAMESPACE::ViewMode sendGetDefualtViewMode(const QString &scheme);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,14 @@
#include "utils/crumbinterface.h"
#include "utils/titlebarhelper.h"
#include "utils/optionbuttonmanager.h"

#include "utils/tabbarmanager.h"
using namespace dfmplugin_titlebar;
TitleBarEventReceiver *TitleBarEventReceiver::instance()
{
static TitleBarEventReceiver receiver;
return &receiver;
}

void TitleBarEventReceiver::handleTabAdded(quint64 windowId)
{
TitleBarWidget *w = TitleBarHelper::findTileBarByWindowId(windowId);
if (!w)
return;
w->navWidget()->addHistroyStack();
}

void TitleBarEventReceiver::handleTabChanged(quint64 windowId, int index)
{
TitleBarWidget *w = TitleBarHelper::findTileBarByWindowId(windowId);
if (!w)
return;
w->navWidget()->switchHistoryStack(index);
}

void TitleBarEventReceiver::handleTabMoved(quint64 windowId, int from, int to)
{
TitleBarWidget *w = TitleBarHelper::findTileBarByWindowId(windowId);
if (!w)
return;
w->navWidget()->moveNavStacks(from, to);
}

void TitleBarEventReceiver::handleTabRemovd(quint64 windowId, int index)
{
TitleBarWidget *w = TitleBarHelper::findTileBarByWindowId(windowId);
if (!w)
return;
w->navWidget()->removeNavStackAt(index);
}

bool TitleBarEventReceiver::handleCustomRegister(const QString &scheme, const QVariantMap &properties)

Check warning on line 20 in src/plugins/filemanager/core/dfmplugin-titlebar/events/titlebareventreceiver.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'handleCustomRegister' is never used.

Check warning on line 20 in src/plugins/filemanager/core/dfmplugin-titlebar/events/titlebareventreceiver.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'handleCustomRegister' is never used.
{
Q_ASSERT(!scheme.isEmpty());
Expand Down Expand Up @@ -151,3 +119,23 @@ TitleBarEventReceiver::TitleBarEventReceiver(QObject *parent)
: QObject(parent)
{
}

bool TitleBarEventReceiver::handleTabAddable(quint64 windowId)
{
return TabBarManager::instance()->canAddNewTab(windowId);
}

void TitleBarEventReceiver::handleCloseTabs(const QUrl &url)
{
TabBarManager::instance()->closeTab(url);
}

void TitleBarEventReceiver::handleSetTabAlias(const QUrl &url, const QString &name)
{
TabBarManager::instance()->setTabAlias(url, name);
}

void TitleBarEventReceiver::handleOpenNewTabTriggered(quint64 windowId, const QUrl &url)
{
TabBarManager::instance()->openNewTab(windowId, url);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ class TitleBarEventReceiver : public QObject
static TitleBarEventReceiver *instance();

public slots:
// receive other plugin signals
void handleTabAdded(quint64 windowId);
void handleTabChanged(quint64 windowId, int index);
void handleTabMoved(quint64 windowId, int from, int to);
void handleTabRemovd(quint64 windowId, int index);

// self slots
bool handleCustomRegister(const QString &scheme, const QVariantMap &properties);

Expand All @@ -40,6 +34,11 @@ public slots:
void handleWindowBackward(quint64 windowId);
void handleRemoveHistory(quint64 windowId, const QUrl &url);

bool handleTabAddable(quint64 windowId);
void handleCloseTabs(const QUrl &url);
void handleSetTabAlias(const QUrl &url, const QString &name);
void handleOpenNewTabTriggered(quint64 windowId, const QUrl &url);

private:
explicit TitleBarEventReceiver(QObject *parent = nullptr);
};
Expand Down
23 changes: 14 additions & 9 deletions src/plugins/filemanager/core/dfmplugin-titlebar/titlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ bool TitleBar::start()
void TitleBar::onWindowCreated(quint64 windId)
{
TitleBarWidget *titleWidget = new TitleBarWidget;
titleWidget->initTabBar(windId);
#ifdef ENABLE_TESTING
dpfSlotChannel->push("dfmplugin_utils", "slot_Accessible_SetAccessibleName",
qobject_cast<QWidget *>(titleWidget), AcName::kAcComputerTitleBar);
Expand Down Expand Up @@ -73,6 +74,11 @@ void TitleBar::onWindowOpened(quint64 windId)
connect(window, &FileManagerWindow::reqSearchCtrlF, titleBarWidget, &TitleBarWidget::handleHotkeyCtrlF);
connect(window, &FileManagerWindow::reqSearchCtrlL, titleBarWidget, &TitleBarWidget::handleHotkeyCtrlL);
connect(window, &FileManagerWindow::reqTriggerActionByIndex, titleBarWidget, &TitleBarWidget::handleHotketSwitchViewMode);
connect(window, &FileManagerWindow::reqActivateNextTab, titleBarWidget, &TitleBarWidget::handleHotketNextTab);
connect(window, &FileManagerWindow::reqActivatePreviousTab, titleBarWidget, &TitleBarWidget::handleHotketPreviousTab);
connect(window, &FileManagerWindow::reqCreateTab, titleBarWidget, &TitleBarWidget::handleHotketCreateNewTab);
connect(window, &FileManagerWindow::reqCloseCurrentTab, titleBarWidget, &TitleBarWidget::handleHotketCloseCurrentTab);
connect(window, &FileManagerWindow::reqActivateTabByIndex, titleBarWidget, &TitleBarWidget::handleHotketActivateTab);
}

void TitleBar::onWindowClosed(quint64 windId)
Expand All @@ -82,17 +88,10 @@ void TitleBar::onWindowClosed(quint64 windId)

void TitleBar::bindEvents()
{
dpfSignalDispatcher->subscribe("dfmplugin_workspace", "signal_Tab_Added",
TitleBarEventReceiver::instance(), &TitleBarEventReceiver::handleTabAdded);
dpfSignalDispatcher->subscribe("dfmplugin_workspace", "signal_Tab_Changed",
TitleBarEventReceiver::instance(), &TitleBarEventReceiver::handleTabChanged);
dpfSignalDispatcher->subscribe("dfmplugin_workspace", "signal_Tab_Moved",
TitleBarEventReceiver::instance(), &TitleBarEventReceiver::handleTabMoved);
dpfSignalDispatcher->subscribe("dfmplugin_workspace", "signal_Tab_Removed",
TitleBarEventReceiver::instance(), &TitleBarEventReceiver::handleTabRemovd);

dpfSignalDispatcher->subscribe(DFMBASE_NAMESPACE::kSwitchViewMode,
TitleBarEventReceiver::instance(), &TitleBarEventReceiver::handleViewModeChanged);
dpfSignalDispatcher->subscribe(DFMBASE_NAMESPACE::kOpenNewTab,
TitleBarEventReceiver::instance(), &TitleBarEventReceiver::handleOpenNewTabTriggered);

// bind self slot events slot_Spinner_Start
static constexpr auto curSpace { DPF_MACRO_TO_STR(DPTITLEBAR_NAMESPACE) };
Expand All @@ -114,6 +113,12 @@ void TitleBar::bindEvents()
TitleBarEventReceiver::instance(), &TitleBarEventReceiver::handleRemoveHistory);
dpfSlotChannel->connect(curSpace, "slot_ServerDialog_RemoveHistory",
SearchHistroyManager::instance(), &SearchHistroyManager::removeSearchHistory);
dpfSlotChannel->connect(curSpace, "slot_Tab_Addable",
TitleBarEventReceiver::instance(), &TitleBarEventReceiver::handleTabAddable);
dpfSlotChannel->connect(curSpace, "slot_Tab_Close",
TitleBarEventReceiver::instance(), &TitleBarEventReceiver::handleCloseTabs);
dpfSlotChannel->connect(curSpace, "slot_Tab_SetAlias",
TitleBarEventReceiver::instance(), &TitleBarEventReceiver::handleSetTabAlias);
}

} // namespace dfmplugin_titlebar
8 changes: 8 additions & 0 deletions src/plugins/filemanager/core/dfmplugin-titlebar/titlebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ class TitleBar : public dpf::Plugin
DPF_EVENT_REG_SLOT(slot_Navigator_Remove)
DPF_EVENT_REG_SLOT(slot_ServerDialog_RemoveHistory)

DPF_EVENT_REG_SLOT(slot_Tab_Addable)
DPF_EVENT_REG_SLOT(slot_Tab_Close)
DPF_EVENT_REG_SLOT(slot_Tab_SetAlias)

// hook events
DPF_EVENT_REG_HOOK(hook_Crumb_Seprate)
DPF_EVENT_REG_HOOK(hook_Show_Addr)
DPF_EVENT_REG_HOOK(hook_Copy_Addr)

DPF_EVENT_REG_HOOK(hook_Tab_SetTabName)
DPF_EVENT_REG_HOOK(hook_Tab_Closeable)
DPF_EVENT_REG_HOOK(hook_Tab_FileDeleteNotCdComputer)

public:
virtual void initialize() override;
virtual bool start() override;
Expand Down
Loading

0 comments on commit 92ae853

Please sign in to comment.