跳转至

example/gui/theme/ThemeSidebar.h

Left sidebar with tab items for navigation. More...

Namespaces

Name
cf
cf::ui
cf::ui::core
cf::ui::gallery

Classes

Name
class cf::ui::gallery::ThemeSidebar
Left sidebar navigation widget with clickable tab items.

Detailed Description

Left sidebar with tab items for navigation.

Author: CFDesktop Team

Version: 0.1

Date: 2026-02-28

Source code

#pragma once

#include <QList>
#include <QWidget>

namespace cf::ui::core {
struct ICFTheme;
}

namespace cf::ui::gallery {

class ThemeSidebar : public QWidget {
    Q_OBJECT

  public:
    explicit ThemeSidebar(QWidget* parent = nullptr);
    ~ThemeSidebar() override = default;

    void setActiveIndex(int index);

    int activeIndex() const { return activeIndex_; }

    void applyTheme(const cf::ui::core::ICFTheme& theme);

  signals:
    void tabClicked(int index);

  protected:
    void paintEvent(QPaintEvent* event) override;
    void mousePressEvent(QMouseEvent* event) override;
    void enterEvent(QEnterEvent* event) override;
    void leaveEvent(QEvent* event) override;
    void mouseMoveEvent(QMouseEvent* event) override;

  private:
    struct TabItem {
        QString icon;    // Emoji icon
        QString label;   // Text label (Chinese)
        QString labelEn; // English label (optional)
    };

    int tabAtPosition(const QPoint& pos) const;

    QRect tabRect(int index) const;

    QList<TabItem> tabs_;
    int activeIndex_ = 0;
    int hoverIndex_ = -1;

    // Theme colors
    QColor backgroundColor_;
    QColor activeColor_;
    QColor hoverColor_;
    QColor textColor_;
    QColor iconColor_;
    QColor borderColor_;
};

} // namespace cf::ui::gallery

Updated on 2026-03-09 at 10:14:01 +0000