Fluent-Qt

選單與工具列

CommandBar 命令列

具備主要與溢位動作的回應式命令列。

範例

CommandBar 命令列: 回應式文件命令列

用法

回應式文件命令列

體驗依優先順序處理的溢位收合、圖示或右側標籤、主要與次要區段、分隔線,以及選用的命令列背景。

#include <FluentQt/MenusToolbars.h>
using namespace fluent::menus_toolbars;

auto* barHost = new QWidget(this);
barHost->setFixedWidth(536);
auto* barLayout = new QHBoxLayout(barHost);
barLayout->setContentsMargins(0, 0, 0, 0);
auto* bar = new CommandBar(barHost);
bar->setAccessibleName("Document commands");
bar->setLabelPosition(
    CommandBar::LabelPosition::Right);
bar->setBackgroundVisible(false);
barLayout->addWidget(bar);

auto* addAction = new QAction(
    QIcon(":/icons/add.svg"), "Add", this);
auto* editAction = new QAction(
    QIcon(":/icons/edit.svg"), "Edit", this);
editAction->setPriority(QAction::HighPriority);
auto* shareAction = new QAction(
    QIcon(":/icons/share.svg"), "Share", this);
auto* separator = new QAction(this);
separator->setSeparator(true);
auto* syncAction = new QAction(
    QIcon(":/icons/sync.svg"), "Sync", this);
syncAction->setPriority(QAction::LowPriority);
auto* pinAction = new QAction(
    QIcon(":/icons/pin.svg"), "Pin", this);
pinAction->setCheckable(true);

bar->addPrimaryAction(addAction);
bar->addPrimaryAction(editAction);
bar->addPrimaryAction(shareAction);
bar->addPrimaryAction(separator);
bar->addPrimaryAction(syncAction);
bar->addPrimaryAction(pinAction);
bar->addSecondaryAction(new QAction(
    QIcon(":/icons/settings.svg"), "Settings", this));
bar->addSecondaryAction(new QAction(
    QIcon(":/icons/help.svg"), "Help", this));

auto* compactButton =
    new Button("Compact view", this);
auto* labelsButton =
    new Button("Labels: Right", this);
auto* backgroundButton =
    new Button("Show background", this);
connect(compactButton, &Button::clicked, barHost,
        [barHost] {
            barHost->setFixedWidth(
                barHost->width() > 300 ? 288 : 536);
        });
connect(labelsButton, &Button::clicked, bar, [=] {
    const bool showLabels =
        bar->labelPosition()
        == CommandBar::LabelPosition::Collapsed;
    bar->setLabelPosition(
        showLabels
            ? CommandBar::LabelPosition::Right
            : CommandBar::LabelPosition::Collapsed);
});
connect(backgroundButton, &Button::clicked, bar, [=] {
    bar->setBackgroundVisible(
        !bar->backgroundVisible());
});
using fluent::status_info::Toast;
for (QAction* action : bar->primaryActions() + bar->secondaryActions()) {
    if (action->isSeparator()) continue;
    connect(action, &QAction::triggered, this, [this, action] {
        QString text = action->text().section('\t', 0, 0).remove('&');
        Toast::showOrUpdateToast(this, "gallery.action-feedback", text + " selected",
            Toast::Informational, 2200, Toast::Top, QMargins(16, 50, 16, 16));
    });
}

fluent::menus_toolbars::CommandBar

繼承自 QWidget · FluentElement · QMLPlus

水平命令列,直接內嵌顯示主要動作,並將多餘項目移至右側溢位選單。

建構函式

解構函式

列舉

enum class LabelPosition

控制內嵌命令標籤是否顯示在圖示旁。

  • Collapsed
  • Right

方法

void addAction(QAction* action)

新增至主命令區(不負責銷毀 QAction)。

void insertAction(QAction* before, QAction* action)

在 `before` 之前將動作插入主要區段(不取得所有權)。

void removeAction(QAction* action)

從命令列移除動作,但不將其刪除。

bool addPrimaryAction(QAction* action)

附加至主命令區(不負責銷毀 QAction)。

bool insertPrimaryAction(QAction* before, QAction* action)

在 `before` 之前插入主要動作(不取得所有權)。

bool addSecondaryAction(QAction* action)

附加至溢位選單(不負責銷毀 QAction)。

bool insertSecondaryAction(QAction* before, QAction* action)

在 `before` 之前插入次要動作(不取得所有權)。

bool removeCommandAction(QAction* action)

從主命令區或次命令區移除動作,但不將其刪除。

void clearPrimaryActions()

清除所有主要命令而不刪除對應動作。

void clearSecondaryActions()

清除所有次要命令而不刪除對應動作。

QList<QAction*> primaryActions() const

依顯示順序傳回主要動作。

QList<QAction*> secondaryActions() const

依顯示順序傳回次要動作。

QList<QAction*> overflowedPrimaryActions() const

傳回目前已移至溢位選單的主要動作。

bool isPrimaryActionOverflowed(const QAction* action) const

傳回主要動作目前是否位於溢位選單中。

void setOverflowOpen(bool open)

當存在溢出項目時開啟或關閉溢出選單。

屬性

LabelPosition labelPosition
讀取 labelPosition()設定 setLabelPosition()變更訊號 labelPositionChanged()
bool dynamicOverflowEnabled
讀取 isDynamicOverflowEnabled()設定 setDynamicOverflowEnabled()變更訊號 dynamicOverflowEnabledChanged()
bool overflowOpen
讀取 isOverflowOpen()設定 setOverflowOpen()變更訊號 overflowOpenChanged()
bool backgroundVisible
讀取 backgroundVisible()設定 setBackgroundVisible()變更訊號 backgroundVisibleChanged()

訊號

型別與別名

受保護成員

方法

繼承自 fluent::FluentElement

列舉

enum Theme

解析設計 token 時使用的全域視覺佈景主題。

  • Light = 0
  • Dark = 1
  • HighContrast = 2

方法

static void setTheme(Theme theme)

更新全域主題,並通知使用中的 FluentElement 執行個體。

static void setThemeDeferred(Theme theme)

排程以可見元素優先的批次主題重新整理,避免阻斷目前的互動。

static Theme currentTheme()

傳回目前生效的全域主題。

static bool themeUsesDarkAppearance(Theme theme)

傳回主題是否使用深色底的視窗框架與材質 token。

static void refreshTheme()

在設計 token 變更後重新廣播目前佈景主題以觸發重繪。

static int themeGeneration()

每次主題變更時遞增的單調計數器,用於過期檢查。

Theme effectiveTheme() const

解析此元素所使用的佈景主題,並遵循繼承的 QWidget 覆寫。

bool effectiveThemeUsesDarkAppearance() const

傳回此元素的實際主題是否使用深色底 chrome。

bool setThemeOverrides(const QJsonObject& overrides)

取代此元素的稀疏色彩、圓角與字型 token 覆寫。

QJsonObject themeOverrides() const

傳回此元素的覆寫設定。

void clearThemeOverrides()

將全部 token 欄位還原為全域主題預設值。

const Colors& themeColorsRef() const

對目前使用中色組的不複製存取(適用於繪製熱路徑)。

Material::AcrylicToken themeAcrylic() const

材質、高度層級與自適應版面配置 token。

QColor themeBackdrop(bool active) const

指定啟用狀態下的視窗 chrome 背景色。

virtual void onThemeUpdated()

在全域主題變更後呼叫。

型別與別名

struct Colors

傳回給元件使用的設計 token 快照。

繼承自 fluent::QMLPlus

方法

AnchorLayout::Anchors* anchors()

傳回 QWidget 宿主的可變錨點。

void setState(const QString& name)

依名稱套用已註冊的狀態,或在 @p name 為空時還原為預設狀態。未知名稱會被忽略,離開該狀態後原有的繫結會恢復同步。

void addState(const QMLState& state)

註冊或取代具名狀態定義;若取代目前啟用中的狀態則會立即套用。

void evaluateStates()

依註冊順序重新評估狀態條件並啟用第一個符合的狀態,若無符合項目則恢復為預設狀態。相依屬性發出通知時也會自動執行;使用 extend 的衍生狀態會繼承上層變更,除非發生循環或缺失。

QMLPlusRuntime* runtime()

傳回由此宿主延遲建立並擁有的狀態觀察器。

void setAnchors(const AnchorLayout::Anchors& anchors)

取代所有宿主錨點,並使父層版面配置失效。

void resetAnchors()

清除所有宿主錨點,並使父版面配置失效。

void bind(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction dir = PropertyBinder::OneWay)

透過 PropertyBinder::bind() 將 @p source 上的 @p sourceProp 繫結至此 QWidget 宿主上的 @p targetProp。

void addTransition(const StateTransition& transition)

依優先順序註冊狀態轉場。

void setBehavior(const char* propertyName, const PropertyAnimation& animation)

設定透過 writeProperty() 或繫結寫入 @p propertyName 時使用的預設動畫。明確的 StateTransition 規則優先;直接呼叫 C++ setter 不會有動畫。

void clearBehavior(const char* propertyName)

移除後續受管理寫入所使用的預設動畫。

bool writeProperty(const char* propertyName, const QVariant& value)

透過 Behavior 寫入宿主屬性,且不移除該屬性的繫結。

Qt 基底類別文件:QWidget