GroupScrollingFeature Example

#include "QtnRibbonQuickAccessBar.h"
#include "aboutdialog.h"
#include "mainwindow.h"

/* MainWindow */
MainWindow::MainWindow(QWidget* parent)
    : DemoRibbonWindow(parent)
{
    setWindowTitle(tr("QtitanRibbon Group Scrolling"));
    addActionsToQuickAccessBar();
    createRibbonBar();
    createStatusBar();

    m_actionLogoRight = ribbonBar()->addAction(QIcon(QStringLiteral(":/res/smallRight.png")), tr("Logo Right"), Qt::ToolButtonIconOnly);
    m_actionLogoRight->setCheckable(true);
    connect(m_actionLogoRight, SIGNAL(triggered()), this, SLOT(pressLogoRight()));
    m_actionLogoLeft  = ribbonBar()->addAction(QIcon(QStringLiteral(":/res/smallLeft.png")), tr("Logo Left"), Qt::ToolButtonIconOnly);
    m_actionLogoLeft->setCheckable(true);
    connect(m_actionLogoLeft, SIGNAL(triggered()), this, SLOT(pressLogoLeft()));
    setDefaultWidgetGeometry(this, 4);
}

void MainWindow::addActionsToQuickAccessBar()
{
    RibbonQuickAccessBar* quickAccessBar = ribbonBar()->quickAccessBar();
    quickAccessBar->addAction(DemoRibbonWindow::autoSaveAction());

    QAction* smallButton = quickAccessBar->addAction(QIcon(QStringLiteral(":/res/smallNew.png")), tr("New"));
    smallButton->setToolTip(tr("Create a new document"));
    quickAccessBar->setActionVisible(smallButton, false);

    smallButton = quickAccessBar->addAction(QIcon(QStringLiteral(":/res/smallOpen.png")), tr("Open"));
    smallButton->setToolTip(tr("Open an existing document"));
    quickAccessBar->setActionVisible(smallButton, false);

    smallButton = quickAccessBar->addAction(QIcon(QStringLiteral(":/res/smallSave.png")), tr("Save"));
    smallButton->setToolTip(tr("Save the active document"));

    smallButton = quickAccessBar->addAction(QIcon(QStringLiteral(":/res/smallUndo.png")), tr("&Undo"));
    smallButton->setShortcut(QKeySequence::Undo);
    smallButton->setEnabled(false);

    smallButton = quickAccessBar->addAction(QIcon(QStringLiteral(":/res/smallRedo.png")), tr("&Redo"));
    smallButton->setShortcut(QKeySequence::Redo);
    smallButton->setEnabled(false);
    quickAccessBar->setVisible(true);
}

void MainWindow::createRibbonBar()
{
    RibbonPage* pageButtons = ribbonBar()->addPage(tr("&Buttons"));
    QIcon iconButtton(QStringLiteral(":/res/scroll.png"));
    for (int i = 0; i < 8; ++i)
    {
        RibbonGroup* ribbonGroup = pageButtons->addGroup(tr("Buttons number%1").arg(i + 1));
        if (i == 0)
            ribbonGroup->setSizeDefinition(RibbonControlSizeDefinition::GroupLarge | RibbonControlSizeDefinition::GroupSimplified);

        ribbonGroup->setIcon(iconButtton);
        ribbonGroup->setContentAlignment(Qt::AlignVCenter);
        ribbonGroup->addAction(iconButtton, tr("&Button 1"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 2"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 3"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 4"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 5"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 6"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 7"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 8"), Qt::ToolButtonTextUnderIcon);
    }

    pageButtons = ribbonBar()->addPage(tr("&Buttons 2"));
    //QIcon iconButtton(QStringLiteral(":/res/scroll.png"));
    for (int i = 0; i < 8; ++i)
    {
        RibbonGroup* ribbonGroup = pageButtons->addGroup(tr("Buttons number%1").arg(i + 1));
        if (i == 1)
            ribbonGroup->setSizeDefinition(RibbonControlSizeDefinition::GroupLarge | RibbonControlSizeDefinition::GroupSimplified);

        ribbonGroup->setIcon(iconButtton);
        ribbonGroup->setContentAlignment(Qt::AlignVCenter);
        ribbonGroup->addAction(iconButtton, tr("&Button 1"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 2"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 3"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 4"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 5"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 6"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 7"), Qt::ToolButtonTextUnderIcon);
        ribbonGroup->addAction(iconButtton, tr("&Button 8"), Qt::ToolButtonTextUnderIcon);
    }
//    ribbonBar()->setLogoPixmap(Qt::AlignRight, QPixmap(":/res/qtitan.png"));
    ribbonBar()->setFrameThemeEnabled();
}

void MainWindow::createStatusBar()
{
    RibbonSliderPane* sliderPane = new RibbonSliderPane();
    sliderPane->setScrollButtons(true);
    sliderPane->setRange(0, 100); // Range
    sliderPane->setMaximumWidth(130);
    sliderPane->setSingleStep(10);
    sliderPane->setSliderPosition(50);
    statusBar()->addPermanentWidget(sliderPane);
    statusBar();
}

void MainWindow::pressLogoRight()
{
    ribbonBar()->setLogoPixmap(QPixmap(QStringLiteral(":/res/qtitan.png")), Qt::AlignRight);
    m_actionLogoRight->setChecked(true);
    m_actionLogoLeft->setChecked(false);
}

void MainWindow::pressLogoLeft()
{
    ribbonBar()->setLogoPixmap(QPixmap(QStringLiteral(":/res/qtitan.png")), Qt::AlignLeft);
    m_actionLogoRight->setChecked(false);
    m_actionLogoLeft->setChecked(true);
}