CustomTitleBarDemo Example

#include <QApplication>
#include <QScreen>
#include <QToolBar>
#include <QMenu>

#include <DevMachines/QtitanRibbon>
#include "aboutdialog.h"
#include "mainwindow.h"

/* NavigationBarWidget */
TitleBarWidget::TitleBarWidget(QWidget* parent)
    : QWidget(parent)
{
    setAutoFillBackground(false);
    setAttribute(Qt::WA_NoSystemBackground);
    setFont(QApplication::font("QDockWidgetTitle"));
    m_ui.setupUi(this);
    m_ui.labelCaption->setText(qApp->organizationName());
    m_ui.labelCaption->setAlignment(Qt::AlignCenter);
    int heightTitle = style()->pixelMetric(QStyle::PM_TitleBarHeight, Q_NULL) + 4;
    m_ui.labelCaption->setMinimumHeight(heightTitle);
    m_ui.comboBox->addItem(QStringLiteral("https://www.devmachines.com"));
    m_ui.comboBox->addItem(QStringLiteral("https://www.qt.io"));
    m_ui.comboBox->addItem(QStringLiteral("https://www.google.com"));
    m_ui.comboBox->addItem(QStringLiteral("https://www.microsoft.com"));
    int height = m_ui.comboBox->sizeHint().height();
    m_ui.searchButton->setMinimumHeight(height);
    m_ui.searchButton->setIcon(QIcon(QStringLiteral(":/res/lens.png")));
    m_ui.refreshButton->setMinimumHeight(height);
    m_ui.refreshButton->setIcon(QIcon(QStringLiteral(":/res/refresh.png")));
    m_ui.stopButton->setMinimumHeight(height);
    m_ui.stopButton->setIcon(QIcon(QStringLiteral(":/res/stop.png")));
    m_ui.goto_forward->setMinimumHeight(height);
    m_ui.goto_forward->setIcon(QIcon(QStringLiteral(":/res/forward.png")));
    m_ui.goto_back->setMinimumHeight(height);
    m_ui.goto_back->setMinimumWidth(height);
    m_ui.goto_back->setIcon(QIcon(QStringLiteral(":/res/back.png")));
    QMenu* searchMenu = new QMenu(this);
    searchMenu->addAction(QStringLiteral("Item 1"));
    searchMenu->addAction(QStringLiteral("Item 2"));
    searchMenu->addAction(QStringLiteral("Item 3"));
    searchMenu->addAction(QStringLiteral("Item 4"));
    m_ui.searchButton->setMenu(searchMenu);
    createToolBar();
}

TitleBarWidget::~TitleBarWidget()
{
}

void TitleBarWidget::createToolBar()
{
    QToolBar* toolBar = new QToolBar(this);
    QAction* act = toolBar->addAction(QStringLiteral("Options"));
    QToolButton* but = (QToolButton*)toolBar->widgetForAction(act);
    but->setPopupMode(QToolButton::MenuButtonPopup);
    QMenu* menu = new QMenu;
    menu->addAction(QStringLiteral("Style"));
    menu->addAction(QStringLiteral("Animation"));
    menu->addAction(QStringLiteral("Font"));
    act->setMenu(menu);
    m_ui.horizontalLayout->addWidget(toolBar, 0, Qt::AlignLeft | Qt::AlignVCenter);
}

/* MainWindow */
MainWindow::MainWindow(QWidget* parent)
    : DemoMainWindow(parent)
    , m_titleBarWidget(Q_NULL)
{
    setWizardStyle(QWizard::ClassicStyle);
    m_titleBarWidget = new TitleBarWidget(this);
    setFrameThemeEnabled(true);

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
    const QRect availableGeometry = screen()->availableGeometry();
    resize(availableGeometry.width() / 2, availableGeometry.height() / 2);
    move((availableGeometry.width() - width()) / 2, (availableGeometry.height() - height()) / 2);
#else
    resize(800, 640); move(200, 200);
#endif
}

MainWindow::~MainWindow()
{
}

void MainWindow::setFrameThemeEnabled(bool enable)
{
    Q_ASSERT(this->isTopLevel());
    if (enable)
    {
        WindowTitleBar* titleBar = WindowTitleBar::get(this);
        titleBar->setStyledFrame(false);
        //titleBar->setSysMenuButtonVisible(false);
        //titleBar->setExtendViewIntoTitleBar(true);
        //titleBar->setBlurBehindWindowEnabled(true);
        titleBar->setTitleHeight(m_titleBarWidget->sizeHint().height());
        m_titleBarWidget->setParent(Q_NULL);
        titleBar->setWidget(m_titleBarWidget, WindowTitleBar::AlignLeft);
        titleBar->show();
    }
    else
    {
        if (WindowTitleBar* titleBar = WindowTitleBar::find(this))
        {
            titleBar->setWidget(Q_NULL);
            titleBar->removeAndDelete();
            m_titleBarWidget->setParent(this);
            m_titleBarWidget->show();
        }
    }
}