Skip to content

Commit

Permalink
feat: 自定义工具栏
Browse files Browse the repository at this point in the history
1. 显示自定义工具栏;
2. 工具栏上调整控件位置;
3. 工具栏上添加和移除控件;
4. 恢复默认工具栏控件;
5. 工具栏生效。

Log: 添加自定义工具栏功能
Influence: none

Change-Id: Icb1d12d4c8881ace309e9b5cd5508bbca965c5fc
  • Loading branch information
kegechen authored and asterwyx committed Jan 17, 2023
1 parent 116aab6 commit 0386852
Show file tree
Hide file tree
Showing 22 changed files with 2,928 additions and 2 deletions.
106 changes: 104 additions & 2 deletions examples/dwidget-examples/collections/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QTextCodec>
#include <QDebug>
#include <QComboBox>
#include <QFontDatabase>

#include <DStandardItem>
#include <DTitlebar>
Expand All @@ -23,7 +24,6 @@
#include <DPrintPreviewDialog>
#include <DSettingsDialog>
#include <DSettingsWidgetFactory>
#include <QFontDatabase>

#include "buttonexample.h"
#include "editexample.h"
Expand All @@ -48,15 +48,109 @@
#include "dsettingsoption.h"
#include "dsettings.h"
#include "dfeaturedisplaydialog.h"
#include "dtitlebarsettings.h"

DCORE_USE_NAMESPACE
DWIDGET_USE_NAMESPACE

class DTitleBarToolCut : public DTitleBarToolInterface {
public:
virtual QString id() const override
{
return "builtin/edit-cut";
}
virtual QString description() override
{
return "edit-cut";
}
virtual QString iconName() override
{
return "edit-cut";
}
virtual QWidget *createView() override
{
auto view = new DIconButton();
view->setFixedSize(82, 36);
view->setIconSize(QSize(36, 36));
view->setIcon(QIcon::fromTheme("edit-cut"));
connect(this, &DTitleBarToolInterface::triggered, this, [this](){
qInfo() << "edit-cut executed";
});
connect(view, &DIconButton::clicked, this, [this](){
qInfo() << "edit-cut executed";
});
return view;
}
};

class DTitleBarToolDelete : public DTitleBarToolInterface {
public:
virtual QString id() const override
{
return "builtin/edit-delete";
}
virtual QString description() override
{
return "edit-delete";
}
virtual QString iconName() override
{
return "edit-delete";
}
virtual QWidget *createView() override
{
auto view = new DIconButton();
view->setFixedSize(82, 36);
view->setIconSize(QSize(36, 36));
view->setIcon(QIcon::fromTheme("edit-delete"));

connect(this, &DTitleBarToolInterface::triggered, this, [this](){
qInfo() << "edit-delete executed";
});
connect(view, &DIconButton::clicked, this, [this](){
qInfo() << "edit-delete executed";
});
return view;
}
};

class DTitleBarToolFind : public DTitleBarToolInterface {
public:
virtual QString id() const override
{
return "builtin/edit-find";
}
virtual QString description() override
{
return "edit-find";
}
virtual QString iconName() override
{
return "edit-find";
}
virtual QWidget *createView() override
{
auto view = new DIconButton();
view->setFixedSize(36, 36);
view->setIconSize(QSize(36, 36));
view->setIcon(QIcon::fromTheme("edit-find"));

connect(this, &DTitleBarToolInterface::triggered,this, [this](){
qInfo() << "edit-find executed";
});
connect(view, &DIconButton::clicked, this, [this](){
qInfo() << "edit-find executed";
});
return view;
}
};


MainWindow::MainWindow(QWidget *parent)
: DMainWindow(parent)
{
setWindowIcon(QIcon(":/images/logo_icon.svg"));
setMinimumSize(qApp->primaryScreen()->availableSize() / 5 * 3);
setMinimumSize(qApp->primaryScreen()->availableSize() / 5);

QHBoxLayout *mainLayout = new QHBoxLayout();
mainLayout->setMargin(0);
Expand Down Expand Up @@ -122,6 +216,14 @@ MainWindow::MainWindow(QWidget *parent)
| Qt::WindowMaximizeButtonHint
| Qt::WindowSystemMenuHint);
titlebar->setAutoHideOnFullscreen(true);

QList<DTitlebarToolBaseInterface *> tools;
tools << new DTitleBarToolCut()
<< new DTitleBarToolDelete()
<< new DTitleBarToolFind();
auto settings = titlebar->settings();
settings->initilize(tools, ":/resources/data/titlebar-settings.json");
settings->toolsEditPanel()->setMinimumWidth(this->width());
}

DButtonBox *buttonBox = new DButtonBox(titlebar);
Expand Down
1 change: 1 addition & 0 deletions examples/dwidget-examples/collections/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<qresource prefix="/">
<file>resources/data/dfm-settings.json</file>
<file>resources/data/dt-settings.json</file>
<file>resources/data/titlebar-settings.json</file>
</qresource>
</RCC>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"spacingSize": 40,
"alignment": "left",
"tools": [
{
"key": "builtin/edit-cut"
},
{
"key": "builtin/spacer",
"fixed": true,
"count": 2
},
{
"key": "builtin/edit-delete",
"fixed": true
}
]
}
5 changes: 5 additions & 0 deletions include/dtkwidget/widgets/dtitlebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

DGUI_USE_NAMESPACE
DWIDGET_BEGIN_NAMESPACE

class DSidebarHelper;
class DTitlebarSettings;
class DTitlebarPrivate;
class LIBDTKWIDGETSHARED_EXPORT DTitlebar : public QFrame, public DTK_CORE_NAMESPACE::DObject
{
Expand Down Expand Up @@ -71,6 +73,8 @@ class LIBDTKWIDGETSHARED_EXPORT DTitlebar : public QFrame, public DTK_CORE_NAMES
bool blurBackground() const;
void setFullScreenButtonVisible(bool enabled);

DTitlebarSettings *settings();

Q_SIGNALS:
void optionClicked();
void doubleClicked();
Expand Down Expand Up @@ -121,6 +125,7 @@ private Q_SLOTS:
D_PRIVATE_SLOT(void _q_aboutActionTriggered())
D_PRIVATE_SLOT(void _q_quitActionTriggered())
D_PRIVATE_SLOT(void _q_switchThemeActionTriggered(QAction*))
D_PRIVATE_SLOT(void _q_toolBarActionTriggerd())
#endif
};

Expand Down
62 changes: 62 additions & 0 deletions include/dtkwidget/widgets/dtitlebarsettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#pragma once

#include <dtkwidget_global.h>
#include <DObject>

DWIDGET_BEGIN_NAMESPACE

class LIBDTKWIDGETSHARED_EXPORT DTitlebarToolBaseInterface : public QObject
{
Q_OBJECT
public:
explicit DTitlebarToolBaseInterface(QObject *parent = nullptr) : QObject(parent) {}
virtual ~DTitlebarToolBaseInterface(){}

virtual QString id() const = 0;
virtual QString description() = 0;
virtual QString iconName() = 0;
};

class LIBDTKWIDGETSHARED_EXPORT DTitleBarToolInterface : public DTitlebarToolBaseInterface {
Q_OBJECT
public:
explicit DTitleBarToolInterface(QObject *parent = nullptr) : DTitlebarToolBaseInterface(parent) {}
virtual ~DTitleBarToolInterface(){}

virtual QWidget *createView() = 0;
Q_SIGNALS:
void triggered();
};

class LIBDTKWIDGETSHARED_EXPORT DTitleBarSpacerInterface : public DTitlebarToolBaseInterface {
Q_OBJECT
public:
explicit DTitleBarSpacerInterface(QObject *parent = nullptr) : DTitlebarToolBaseInterface(parent) {}
virtual ~DTitleBarSpacerInterface(){}

virtual QWidget *createPlaceholderView() = 0;
virtual int size() const = 0;
};

class DTitlebarSettingsPrivate;
class DTitlebarSettingsImpl;
class DTitlebar;
class LIBDTKWIDGETSHARED_EXPORT DTitlebarSettings : public DCORE_NAMESPACE::DObject
{
public:
explicit DTitlebarSettings(DTitlebar *titlebar);
bool initilize(QList<DTitlebarToolBaseInterface *> &tools, const QString &path);

QWidget *toolsEditPanel() const;

private:
D_DECLARE_PRIVATE(DTitlebarSettings)
DTitlebarSettingsImpl *impl();
friend class DTitlebar;
};

DWIDGET_END_NAMESPACE
1 change: 1 addition & 0 deletions src/widgets/assets/icons/dark/texts/fold_14px.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/widgets/assets/icons/dark/texts/spacer_fixed_34px.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/widgets/assets/icons/dtk-icon-theme.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<file>dark/actions/print_previewscale_18px.svg</file>
<file>dark/actions/printer_dropdown_14px.svg</file>
<file>dark/actions/printer_dropup_14px.svg</file>
<file>light/texts/spacer_fixed_34px.svg</file>
<file>light/texts/spacer_stretch_34px.svg</file>
<file>light/texts/fold_14px.svg</file>
<file>dark/texts/spacer_fixed_34px.svg</file>
<file>dark/texts/spacer_stretch_34px.svg</file>
<file>dark/texts/fold_14px.svg</file>
<file>dark/actions/printer_lrtb_1_24px.svg</file>
<file>dark/actions/printer_lrtb_2_24px.svg</file>
<file>dark/actions/printer_lrtb_3_24px.svg</file>
Expand Down
1 change: 1 addition & 0 deletions src/widgets/assets/icons/light/texts/fold_14px.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/widgets/assets/icons/light/texts/spacer_fixed_34px.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0386852

Please sign in to comment.