ControlsDemo Example

#include <QFileDialog>
#include <QPrinter>
#include <QPrintDialog>
#include <QComboBox>
#include <QCheckBox>
#include <QProgressBar>
#include <QLineEdit>
#include <QRadioButton>
#include <QScrollBar>
#include <QFontComboBox>
#include <QAction>
#include <QMenu>
#include <QLabel>
#include <QSpinBox>
#include <QMessageBox>
#include <QButtonGroup>
#include <QPushButton>
#include <QSettings>
#include <QEvent>
#include <QPainter>
#include <QPaintEvent>

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

#define Prop_ContextColor   "ContextColor"

/* MainWindow */
MainWindow::MainWindow(QWidget* parent)
    : DemoRibbonWindow(parent)
    , m_progressBar(Q_NULL)
    , m_progressBar1(Q_NULL)
    , m_progressBar2(Q_NULL)
    , m_contextPage(Q_NULL)
    , m_valueProgress(0)
{
    setWindowTitle(QObject::tr("QtitanRibbon Controls"));
    setCentralWidget(new RibbonWorkspace);

    createMenuFile();
    addActionsToQuickAccessBar();
    createRibbon();
    createStatusBar();

    m_timerProgressBar.setInterval(200);
    connect(&m_timerProgressBar, SIGNAL(timeout()), this, SLOT(animateProgressBar()));

    setDefaultWidgetGeometry(this);
    QSettings settings;
    QStringList files = settings.value(QStringLiteral("recentFileList")).toStringList();
    settings.setValue(QStringLiteral("recentFileList"), files);
    emit updateRecentFileActions(files);

    RibbonCustomizeManager* customizeManager = ribbonBar()->customizeManager();
    customizeManager->setDefaultState(); //Make a default state-point for ribbon-ui elements.

    readSettings();
}

MainWindow::~MainWindow()
{
    writeSettings();
}

void MainWindow::createMenuFile()
{
    QIcon iconLogo;
    iconLogo.addPixmap(QPixmap(QStringLiteral(":/res/qtitan.png")));
    iconLogo.addPixmap(QPixmap(QStringLiteral(":/res/qtitanlogo32x32.png")));
    QAction* actionFile = ribbonBar()->addSystemButton(iconLogo, tr("&File"));
    actionFile->setToolTip(tr("Click here to see everything<br />you can do with your<br />document"));
    RibbonSystemMenu* systemMenu = qobject_cast<RibbonSystemMenu *>(actionFile->menu());
    Q_ASSERT(systemMenu != Q_NULL);

    QAction* newFile = systemMenu->addAction(DemoRibbonWindow::createIcon(Image_New), tr("&New"));
    newFile->setShortcut(tr("Ctrl+N"));
    newFile->setStatusTip(tr("Create a new document"));
    newFile->setToolTip(tr("New"));
    newFile->setEnabled(false);

    QAction* openFile = systemMenu->addAction(DemoRibbonWindow::createIcon(Image_Open, true), tr("&Open..."));
    openFile->setShortcut(tr("Ctrl+O"));
    openFile->setToolTip(tr("Open"));
    openFile->setStatusTip(tr("Open an existing document"));
    connect(openFile, SIGNAL(triggered()), this, SLOT(open()));

    QAction* saveFile = systemMenu->addAction(DemoRibbonWindow::createIcon(Image_Save, true), tr("&Save"));
    saveFile->setShortcut(tr("Ctrl+S"));
    saveFile->setToolTip(tr("Save"));
    saveFile->setStatusTip(tr("Save the active document"));
    connect(saveFile, SIGNAL(triggered()), this, SLOT(save()));

    QAction* saveAsFile = systemMenu->addAction(tr("Save &As..."));
    saveAsFile->setToolTip(tr("Save As"));
    saveAsFile->setStatusTip(tr("Save the active document with a new name"));
    connect(saveAsFile, SIGNAL(triggered()), this, SLOT(save()));

    systemMenu->addSeparator();

    QAction* printFile = systemMenu->addAction(QIcon(QStringLiteral(":/res/print.png")), tr("&Print"));
    printFile->setShortcut(tr("Ctrl+P"));
    printFile->setToolTip(tr("Print"));
    printFile->setStatusTip(tr("Print the active document"));
    connect(printFile, SIGNAL(triggered()), this, SLOT(print()));

    QAction* printPreviewFile = systemMenu->addAction(QIcon(QStringLiteral(":/res/printPreview.png")), tr("Print Pre&view"));
    printPreviewFile->setToolTip(tr("Print Preview"));
    printPreviewFile->setStatusTip(tr("Display full pages"));

    QAction* printSetupFile = systemMenu->addAction(tr("P&rint Setup..."));
    printSetupFile->setToolTip(tr("Print Setup"));
    printSetupFile->setStatusTip(tr("Change the printer and printing options"));
    connect(printSetupFile, SIGNAL(triggered()), this, SLOT(printSetup()));
    systemMenu->addSeparator();

    QAction* actClose = systemMenu->addAction(DemoRibbonWindow::createIcon(Image_Close), tr("&Close"));
    actClose->setShortcut(tr("Ctrl+C"));
    actClose->setStatusTip(tr("Exit"));
    connect(actClose, SIGNAL(triggered()), this, SLOT(close()));
    systemMenu->addPopupBarAction(actClose, Qt::ToolButtonTextBesideIcon);

    QAction* option = new QAction(QPixmap(QStringLiteral(":/res/smalloption.png")), tr("Opt&ion"), this);
    systemMenu->addPopupBarAction(option, Qt::ToolButtonTextBesideIcon);
    option->setEnabled(false);

    RibbonPageSystemRecentFileList* pageRecentFile = systemMenu->addPageRecentFile(tr("Recent Documents"));
    pageRecentFile->setSize(9);
    connect(pageRecentFile, SIGNAL(openRecentFile(const QString&)), this, SLOT(openRecentFile(const QString&)));
    connect(this, SIGNAL(updateRecentFileActions(const QStringList&)), pageRecentFile, SLOT(updateRecentFileActions(const QStringList&)));
}

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

    QAction* smallButton = quickAccessBar->addAction(DemoRibbonWindow::createIcon(Image_New), tr("New"));
    smallButton->setToolTip(tr("Create a new document"));
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));
    quickAccessBar->setActionVisible(smallButton, false);

    smallButton = quickAccessBar->addAction(DemoRibbonWindow::createIcon(Image_Open), tr("Open"));
    smallButton->setToolTip(tr("Open an existing document"));
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));
    quickAccessBar->setActionVisible(smallButton, false);

    smallButton = quickAccessBar->addAction(DemoRibbonWindow::createIcon(Image_Save), tr("Save"));
    smallButton->setToolTip(tr("Save the active document"));
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    smallButton = quickAccessBar->addAction(DemoRibbonWindow::createIcon(Image_Undo), tr("&Undo"));
    smallButton->setShortcut(QKeySequence::Undo);
    smallButton->setEnabled(false);

    smallButton = quickAccessBar->addAction(DemoRibbonWindow::createIcon(Image_Redo), tr("&Redo"));
    smallButton->setShortcut(QKeySequence::Redo);
    smallButton->setEnabled(false);
    quickAccessBar->setVisible(true);
}

void MainWindow::createRibbon()
{
    RibbonPage* pageButtons = ribbonBar()->addPage(tr("&Buttons"));
    QMenu* splitPopup = new QMenu(ribbonBar());
    connect(splitPopup->addAction(tr("Option 1")), SIGNAL(triggered()), this, SLOT(pressButton()));
    connect(splitPopup->addAction(tr("Option 2")), SIGNAL(triggered()), this, SLOT(pressButton()));
    connect(splitPopup->addAction(tr("Option 3")), SIGNAL(triggered()), this, SLOT(pressButton()));

    QIcon iconSplit;
    iconSplit.addPixmap(QPixmap(QStringLiteral(":/res/largeSplitButton.png")));
    iconSplit.addPixmap(QPixmap(QStringLiteral(":/res/smallSplitButton.png")));

    QIcon iconButtton;
    iconButtton.addPixmap(QPixmap(QStringLiteral(":/res/largeButton.png")));
    iconButtton.addPixmap(QPixmap(QStringLiteral(":/res/smallButton.png")));

    QIcon iconPopupButtton;
    iconPopupButtton.addPixmap(QPixmap(QStringLiteral(":/res/largePopupButton.png")));
    iconPopupButtton.addPixmap(QPixmap(QStringLiteral(":/res/smallPopupButton.png")));

    // Large Buttons
    RibbonGroup* groupLargeButtons = pageButtons->addGroup(tr("&Large Buttons"));
    groupLargeButtons->setOptionButtonVisible();
    QAction* act = groupLargeButtons->optionButtonAction();
    act->setToolTip(tr("Large Buttons"));
    connect(act, SIGNAL(triggered()), this, SLOT(pressButton()));

    QAction* action = groupLargeButtons->addAction(iconButtton, tr("&Button"), Qt::ToolButtonTextUnderIcon);
    RibbonControl* control = groupLargeButtons->controlByAction(action);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupLarge)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupMedium)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupSmall)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    connect(action, SIGNAL(triggered()), this, SLOT(pressButton()));

    action = groupLargeButtons->addAction(QIcon(QStringLiteral(":/res/Edit.Create.svg")), tr("Button1 &SVG"), Qt::ToolButtonTextUnderIcon);
    control = groupLargeButtons->controlByAction(action);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupLarge)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupMedium)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupSmall)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    connect(action, SIGNAL(triggered()), this, SLOT(pressButton()));

    action = groupLargeButtons->addAction(QIcon(QStringLiteral(":/res/info32x32.svg")), tr("Button2 &SVG"), Qt::ToolButtonTextUnderIcon);
    control = groupLargeButtons->controlByAction(action);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupLarge)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupMedium)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupSmall)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    connect(action, SIGNAL(triggered()), this, SLOT(pressButton()));

    action = groupLargeButtons->addAction(QIcon(QStringLiteral(":/res/largeToggleButton.png")), tr("Toggle Button"), Qt::ToolButtonTextUnderIcon);
    action->setCheckable(true);
    action->setChecked(true);
    control = groupLargeButtons->controlByAction(action);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupLarge)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupMedium)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupSmall)->setImageSize(RibbonControlSizeDefinition::ImageLarge);

    QMenu* menuPopup = groupLargeButtons->addMenu(iconPopupButtton, tr("Popup Button"), Qt::ToolButtonTextUnderIcon);
    control = groupLargeButtons->controlByAction(menuPopup->defaultAction());
    control->sizeDefinition(RibbonControlSizeDefinition::GroupLarge)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupMedium)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupSmall)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    connect(menuPopup->addAction(tr("Option 1")), SIGNAL(triggered()), this, SLOT(pressButton()));
    connect(menuPopup->addAction(tr("Option 2")), SIGNAL(triggered()), this, SLOT(pressButton()));
    connect(menuPopup->addAction(tr("Option 3")), SIGNAL(triggered()), this, SLOT(pressButton()));

    action = groupLargeButtons->addAction(iconSplit, tr("S&plit Button"), Qt::ToolButtonTextUnderIcon, splitPopup);
    control = groupLargeButtons->controlByAction(action);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupLarge)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupMedium)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    control->sizeDefinition(RibbonControlSizeDefinition::GroupSmall)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    connect(action, SIGNAL(triggered()), this, SLOT(pressButton()));

    // Small Buttons
    RibbonGroup* groupSmallButtons = pageButtons->addGroup(tr("Small Buttons"));
    groupSmallButtons->setOptionButtonVisible();
    act = groupSmallButtons->optionButtonAction();
    act->setText(tr("S&mall"));
    act->setToolTip(tr("Small Buttons"));
    connect(act, SIGNAL(triggered()), this, SLOT(pressButton()));

    QAction* smallButton = groupSmallButtons->addAction(iconButtton, tr("B&utton"), Qt::ToolButtonTextBesideIcon);
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    menuPopup = groupSmallButtons->addMenu(iconPopupButtton, tr("Popup Button"), Qt::ToolButtonTextBesideIcon);
    menuPopup->addAction(tr("Option &1"));
    menuPopup->addAction(tr("Option &2"));
    menuPopup->addAction(tr("Option &3"));

    smallButton = groupSmallButtons->addAction(iconSplit, tr("Split Button"), Qt::ToolButtonTextBesideIcon, splitPopup);
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    smallButton = groupSmallButtons->addAction(iconButtton, tr("B&utton"), Qt::ToolButtonIconOnly);
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    menuPopup = groupSmallButtons->addMenu(iconPopupButtton, tr("Popup Button"), Qt::ToolButtonIconOnly);
    menuPopup->addAction(tr("Option &1"));
    menuPopup->addAction(tr("Option &2"));
    menuPopup->addAction(tr("Option &3"));

    smallButton = groupSmallButtons->addAction(iconSplit, tr("Split Button"), Qt::ToolButtonIconOnly, splitPopup);
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    smallButton = groupSmallButtons->addAction(QIcon(QStringLiteral(":/res/info16x16.svg")), tr("Button SVG"), Qt::ToolButtonIconOnly, splitPopup);
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    // CheckBoxes and Radio Buttons
    RibbonGroup* groupCheckboxButtons = pageButtons->addGroup(tr("Checkboxes && Radio Buttons"));
    groupCheckboxButtons->setOptionButtonVisible();
    act = groupCheckboxButtons->optionButtonAction();
    act->setToolTip(tr("Checkboxes && Radio Buttons"));
    connect(act, SIGNAL(triggered()), this, SLOT(pressButton()));

    RibbonCheckBoxControl* checkBoxControl = new RibbonCheckBoxControl(tr("CheckBox 1"));
    groupCheckboxButtons->addControl(checkBoxControl);
    QCheckBox* check1 = checkBoxControl->widget();
    check1->setToolTip(tr("CheckBox 1"));
    check1->setCheckState(Qt::Checked);

    checkBoxControl = new RibbonCheckBoxControl(tr("CheckBox 2"));
    groupCheckboxButtons->addControl(checkBoxControl);
    QCheckBox* check2 = checkBoxControl->widget();
    check2->setToolTip(tr("CheckBox 2"));
    check2->setCheckState(Qt::Unchecked);

    checkBoxControl = new RibbonCheckBoxControl(tr("CheckBox 3"));
    groupCheckboxButtons->addControl(checkBoxControl);
    QCheckBox* check3 = checkBoxControl->widget();
    check3->setToolTip(tr("CheckBox 3"));
    check3->setCheckState(Qt::PartiallyChecked);

    groupCheckboxButtons->addSeparator();

    QButtonGroup* groupButton = new QButtonGroup(this);
    RibbonRadioButtonControl* radioButtonControl = new RibbonRadioButtonControl(tr("Radio Button 1"));
    groupCheckboxButtons->addControl(radioButtonControl);
    QRadioButton* radio1 = radioButtonControl->widget();
    groupButton->addButton(radio1);
    radio1->setToolTip(tr("Radio Button 1"));
    radio1->setChecked(true);

    radioButtonControl = new RibbonRadioButtonControl(tr("Radio Button 2"));
    groupCheckboxButtons->addControl(radioButtonControl);
    QRadioButton* radio2 = radioButtonControl->widget();
    groupButton->addButton(radio2);
    radio2->setToolTip(tr("Radio Button 2"));

    radioButtonControl = new RibbonRadioButtonControl(tr("Radio Button 3"));
    groupCheckboxButtons->addControl(radioButtonControl);
    QRadioButton* radio3 = radioButtonControl->widget();
    groupButton->addButton(radio3);
    radio3->setToolTip(tr("Radio Button 3"));

    // Groups
    RibbonGroup* groupGroups = pageButtons->addGroup(tr("Groups"));
    groupGroups->setControlsAlignment(Qt::AlignHCenter);
    groupGroups->setContentAlignment(Qt::AlignVCenter);
    RibbonToolBarControl* toolBarControl = new RibbonToolBarControl(groupGroups);
    smallButton = toolBarControl->addAction(DemoRibbonWindow::createIcon(Image_New),
        tr("New"), Qt::ToolButtonIconOnly);
    smallButton->setToolTip(tr("Create a new document"));
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    smallButton = toolBarControl->addAction(DemoRibbonWindow::createIcon(Image_Open),
        tr("Open"), Qt::ToolButtonIconOnly);
    smallButton->setToolTip(tr("Open an existing document"));
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    smallButton = toolBarControl->addAction(DemoRibbonWindow::createIcon(Image_Save),
        tr("Save"), Qt::ToolButtonIconOnly);
    smallButton->setToolTip(tr("Save the active document"));
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    smallButton = toolBarControl->addAction(DemoRibbonWindow::createIcon(Image_Cut),
        tr("Cut"), Qt::ToolButtonIconOnly);
    smallButton->setToolTip(tr("Cut the selection and put it on the Clipboard"));
    smallButton->setEnabled(false);
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    smallButton = toolBarControl->addAction(QIcon(QStringLiteral(":/res/smallCopy.png")),
        tr("Copy"), Qt::ToolButtonIconOnly);
    smallButton->setToolTip(tr("Copy the selection and put it on the Clipboard"));
    smallButton->setEnabled(false);
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    smallButton = toolBarControl->addAction(DemoRibbonWindow::createIcon(Image_Clipboard),
        tr("Paste"), Qt::ToolButtonIconOnly);
    smallButton->setToolTip(tr("Insert Clipboard contents"));
    smallButton->setEnabled(false);
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    toolBarControl->addSeparator();

    smallButton = toolBarControl->addAction(DemoRibbonWindow::createIcon(Image_Undo),
        tr("Undo"), Qt::ToolButtonIconOnly);
    smallButton->setToolTip(tr("Undo the last action"));
    smallButton->setEnabled(false);
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    smallButton = toolBarControl->addAction(DemoRibbonWindow::createIcon(Image_Redo),
        tr("Redo"), Qt::ToolButtonIconOnly);
    smallButton->setToolTip(tr("Redo the previously undone action"));
    smallButton->setEnabled(false);
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    toolBarControl->addSeparator();

    smallButton = toolBarControl->addAction(QIcon(QStringLiteral(":/res/smallPrint.png")),
        tr("Print"), Qt::ToolButtonIconOnly);
    smallButton->setToolTip(tr("Print the active document"));
    connect(smallButton, SIGNAL(triggered()), this, SLOT(pressButton()));

    smallButton = toolBarControl->addAction(QIcon(QStringLiteral(":/shared/res/about.png")),
        tr("About"), Qt::ToolButtonIconOnly);
    smallButton->setToolTip(tr("Display program information, version number and copyright"));
    connect(smallButton, SIGNAL(triggered()), this, SLOT(about()));

    groupGroups->addControl(toolBarControl);

    // Groups
    RibbonGroup* testGroups = pageButtons->addGroup(tr("Test"));
    QIcon icon;
    icon.addPixmap(QPixmap(QStringLiteral(":/res/test16x16.png")));
    icon.addPixmap(QPixmap(QStringLiteral(":/res/test32x32.png")));
    icon.addPixmap(QPixmap(QStringLiteral(":/res/test48x48.png")));
    icon.addPixmap(QPixmap(QStringLiteral(":/res/test64x64.png")));
    icon.addPixmap(QPixmap(QStringLiteral(":/res/test128x128.png")));

    QAction* actionTest = testGroups->addAction(icon, tr("Button &Test"), Qt::ToolButtonTextUnderIcon);
    RibbonControl* controlTest = testGroups->controlByAction(actionTest);
    controlTest->sizeDefinition(RibbonControlSizeDefinition::GroupLarge)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    controlTest->sizeDefinition(RibbonControlSizeDefinition::GroupMedium)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    controlTest->sizeDefinition(RibbonControlSizeDefinition::GroupSmall)->setImageSize(RibbonControlSizeDefinition::ImageLarge);

    actionTest = testGroups->addAction(icon, tr("Spl&it Test"), Qt::ToolButtonTextUnderIcon, splitPopup);
    controlTest = testGroups->controlByAction(actionTest);
    controlTest->sizeDefinition(RibbonControlSizeDefinition::GroupLarge)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    controlTest->sizeDefinition(RibbonControlSizeDefinition::GroupMedium)->setImageSize(RibbonControlSizeDefinition::ImageLarge);
    controlTest->sizeDefinition(RibbonControlSizeDefinition::GroupSmall)->setImageSize(RibbonControlSizeDefinition::ImageLarge);

    actionTest = testGroups->addAction(icon, tr("Button &Test"), Qt::ToolButtonTextBesideIcon);
    menuPopup = testGroups->addMenu(icon, tr("Popup Test"), Qt::ToolButtonTextBesideIcon);
    menuPopup->addAction(tr("Option &1"));
    menuPopup->addAction(tr("Option &2"));
    menuPopup->addAction(tr("Option &3"));
    testGroups->addAction(icon, tr("Split Test"), Qt::ToolButtonTextBesideIcon, splitPopup);

    RibbonPage* pageEditors = ribbonBar()->addPage(tr("&Editors"));
    RibbonGroup* groupStandard = pageEditors->addGroup(tr("Standard"));
    RibbonLineEditControl* lineEditControl = new RibbonLineEditControl();
    groupStandard->addControl(lineEditControl);
    QLineEdit* controlEdit = lineEditControl->widget();
    controlEdit->setToolTip(tr("Edit"));
    controlEdit->setText(tr("Edit"));

    RibbonComboBoxControl* comboBoxControl = new RibbonComboBoxControl();
    groupStandard->addControl(comboBoxControl);
    QComboBox* controlComboBox = comboBoxControl->widget();
    controlComboBox->setToolTip(tr("Combo"));
    controlComboBox->setEditable(true);
    controlComboBox->addItem(QPixmap(QStringLiteral(":/res/test16x16.png")), tr("ComboBox"));
    controlComboBox->addItem(QPixmap(QStringLiteral(":/res/test32x32.png")), tr("Item 1"));
    controlComboBox->addItem(QPixmap(QStringLiteral(":/res/test64x64.png")), tr("Item 2"));
    controlComboBox->addItem(QPixmap(QStringLiteral(":/res/test128x128.png")), tr("Item 3"));

    comboBoxControl = new RibbonComboBoxControl();
    groupStandard->addControl(comboBoxControl);
    controlComboBox = comboBoxControl->widget();
    controlComboBox->setToolTip(tr("Combo"));
    controlComboBox->addItem(tr("ComboBox"));
    controlComboBox->addItem(tr("Item 1"));
    controlComboBox->addItem(tr("Item 2"));

    RibbonGroup* groupExtendedEditors = pageEditors->addGroup(tr("Extended"));
    RibbonSpinBoxControl* spinBoxControl = new RibbonSpinBoxControl();
    groupExtendedEditors->addControl(spinBoxControl);
    QSpinBox* spinBox = spinBoxControl->widget();
    spinBox->setToolTip(tr("Edit"));
    spinBox->setMaximumWidth(150);
    spinBox->setMinimumWidth(150);
    action = new QWidgetAction(this);
    action->setText(tr("Edit:"));
    action->setIcon(QIcon(QStringLiteral(":/res/smallEditor.png")));
    spinBoxControl->setDefaultAction(action);

    comboBoxControl = new RibbonComboBoxControl();
    groupExtendedEditors->addControl(comboBoxControl);
    controlComboBox = comboBoxControl->widget();
    controlComboBox->setMaximumWidth(150);
    controlComboBox->setMinimumWidth(150);
    controlComboBox->setToolTip(tr("ComboBox"));
    controlComboBox->setEditable(true);
    controlComboBox->addItem(tr("ComboBox"));
    controlComboBox->addItem(tr("Item 1"));
    controlComboBox->addItem(tr("Item 2"));
    action = new QWidgetAction(this);
    action->setText(tr("Combo:"));
    action->setIcon(QIcon(QStringLiteral(":/res/smallComboBox.png")));
    comboBoxControl->setDefaultAction(action);

    comboBoxControl = new RibbonComboBoxControl();
    groupExtendedEditors->addControl(comboBoxControl);
    controlComboBox = comboBoxControl->widget();
    controlComboBox->setMaximumWidth(150);
    controlComboBox->setMinimumWidth(150);
    controlComboBox->setToolTip(tr("ComboBox"));
    controlComboBox->setEditable(true);
    controlComboBox->addItem(tr("ComboBox"));
    controlComboBox->addItem(tr("Item 1"));
    controlComboBox->addItem(tr("Item 2"));
    action = new QWidgetAction(this);
    action->setText(tr("Combo:"));
    action->setIcon(QIcon(QStringLiteral(":/res/smallComboBox.png")));
    comboBoxControl->setDefaultAction(action);

    RibbonGroup* groupDateTime = pageEditors->addGroup(tr("Date/Time"));
    RibbonTimeEditControl* timeEdit = new RibbonTimeEditControl();
    action = new QWidgetAction(this);
    action->setText(tr("Time:"));
    timeEdit->setDefaultAction(action);
    groupDateTime->addControl(timeEdit);

    RibbonDateEditControl* dateEdit = new RibbonDateEditControl();
    action = new QWidgetAction(this);
    action->setText(tr("Date 1:"));
    dateEdit->setDefaultAction(action);
    groupDateTime->addControl(dateEdit);

    dateEdit = new RibbonDateEditControl();
    action = new QWidgetAction(this);
    action->setText(tr("Date 2:"));
    dateEdit->setDefaultAction(action);
    dateEdit->setCalendarPopup(true);
    groupDateTime->addControl(dateEdit);

    groupDateTime->addSeparator();

    RibbonDateTimeEditControl* dateComboBox = new RibbonDateTimeEditControl();
    action = new QWidgetAction(this);
    action->setText(tr("Date/Time 1:"));
    dateComboBox->setDefaultAction(action);
    groupDateTime->addControl(dateComboBox);

    dateComboBox = new RibbonDateTimeEditControl();
    action = new QWidgetAction(this);
    action->setText(tr("Date/Time 2:"));
    dateComboBox->setDefaultAction(action);
    dateComboBox->setCalendarPopup(true);
    groupDateTime->addControl(dateComboBox);

    RibbonGroup* groupGallery = pageEditors->addGroup(tr("Gallery"));
    RibbonFontComboBoxControl* fontComboBox = new RibbonFontComboBoxControl();
    action = new QWidgetAction(this);
    action->setText(tr("Font:"));
    fontComboBox->setDefaultAction(action);
    groupGallery->addControl(fontComboBox);

    QFontComboBox* comboFont = fontComboBox->widget();
    comboFont->setFontFilters(QFontComboBox::MonospacedFonts);
    if (comboFont->count() > 0)
        comboFont->setCurrentIndex(0);
    else
        comboFont->setEditText(tr(""));

    RibbonPage* pageMisc = ribbonBar()->addPage(tr("&Misc"));
    const int rowHeight = ribbonBar()->rowItemHeight();

    RibbonGroup* groupLable = pageMisc->addGroup(tr("Label"));
    groupLable->addControl(new RibbonLabelControl(QObject::tr("Label Text 1")));
    groupLable->addControl(new RibbonLabelControl(QObject::tr("Label Text 2")));
    groupLable->addControl(new RibbonLabelControl(QObject::tr("Label Text 3")));

    RibbonGroup* groupBitmap = pageMisc->addGroup(tr("Bitmap"));
    groupBitmap->setControlsAlignment(Qt::AlignHCenter);
    RibbonLabelControl* labelControl = new RibbonLabelControl();
    groupBitmap->addControl(labelControl);
    QLabel* pLabel = labelControl->widget();
    pLabel->setPixmap(QPixmap(QStringLiteral(":/res/Windows.png")));

    RibbonGroup* groupBitmapLinux = pageMisc->addGroup(tr("Bitmap"));
    groupBitmapLinux->setControlsAlignment(Qt::AlignHCenter);
    labelControl = new RibbonLabelControl();
    groupBitmapLinux->addControl(labelControl);
    pLabel = labelControl->widget();
    pLabel->setPixmap(QPixmap(QStringLiteral(":/res/linux.png")));

    RibbonGroup* groupProgressBar = pageMisc->addGroup(tr("ProgressBar"));
    m_progressBar = new QProgressBar();
    m_progressBar->setAlignment(Qt::AlignHCenter);
    m_progressBar->setRange(0, 100);
    m_progressBar->setValue(40);
    m_progressBar->setMinimumWidth(100);
    m_progressBar->setMaximumHeight(22);
    groupProgressBar->addWidget(m_progressBar);

    m_progressBar1 = new QProgressBar();
    m_progressBar1->setTextVisible(false);
    m_progressBar1->setRange(0, 100);
    m_progressBar1->setValue(40);
    m_progressBar1->setMinimumWidth(100);
    m_progressBar1->setMaximumHeight(22);
    groupProgressBar->addWidget(m_progressBar1);

    checkBoxControl = new RibbonCheckBoxControl(QObject::tr("Animation bar"));
    groupProgressBar->addControl(checkBoxControl);
    QCheckBox* checkAnimationBar = checkBoxControl->widget();
    connect(checkAnimationBar, SIGNAL(stateChanged(int)), this, SLOT(startProgressBar(int)));
    checkAnimationBar->setCheckState(Qt::Unchecked);

    RibbonGroup* groupScrollBar = pageMisc->addGroup(tr("ScrollBar"));
    groupScrollBar->setContentAlignment(Qt::AlignVCenter);

    QScrollBar* scrollBar = new QScrollBar(Qt::Horizontal);
    scrollBar->setMinimumWidth(160);
    scrollBar->setMaximumHeight(20);
    scrollBar->setMinimum(0);
    scrollBar->setMaximum(20);
    groupScrollBar->addWidget(scrollBar);

    RibbonGroup* groupSlider = pageMisc->addGroup(tr("Slider"));
    RibbonSliderPaneControl* sliderPaneControl = new RibbonSliderPaneControl();
    groupSlider->addControl(sliderPaneControl);
    RibbonSliderPane* sliderPane = sliderPaneControl->widget();
    sliderPane->setScrollButtons(true);
    sliderPane->setMaximumWidth(150);
    sliderPane->setMaximumHeight(rowHeight);
    sliderPane->setRange(0, 100);
    sliderPane->setSingleStep(10);
    sliderPane->setSliderPosition(50);

    RibbonSliderControl* sliderControl = new RibbonSliderControl(Qt::Horizontal);
    groupSlider->addControl(sliderControl);
    QSlider* slider = sliderControl->widget();
    slider->setMinimumWidth(150);
    slider->setMaximumHeight(rowHeight);
    slider->setRange(0, 100);
    slider->setTickPosition(QSlider::TicksLeft);
    slider->setTickInterval(20);
    slider->setSingleStep(10);
    slider->setSliderPosition(50);
    connect(sliderPane, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
    connect(slider, SIGNAL(valueChanged(int)), sliderPane, SLOT(setValue(int)));

    sliderControl = new RibbonSliderControl(Qt::Horizontal);
    groupSlider->addControl(sliderControl);
    slider = sliderControl->widget();
    slider->setMinimumWidth(150);
    slider->setMaximumHeight(rowHeight);
    slider->setTickPosition(QSlider::TicksRight);
    slider->setTickInterval(20);

    groupSlider->addSeparator();

    sliderControl = new RibbonSliderControl(Qt::Vertical);
    groupSlider->addControl(sliderControl);
    slider = sliderControl->widget();
    slider->setMinimumHeight(rowHeight*3);
    slider->setMinimumWidth(40);
    slider->setTickPosition(QSlider::TicksLeft);
    slider->setTickInterval(20);

    sliderControl = new RibbonSliderControl(Qt::Vertical);
    groupSlider->addControl(sliderControl);
    slider = sliderControl->widget();
    slider->setMinimumWidth(40);
    slider->setMinimumHeight(rowHeight * 3);
    slider->setTickPosition(QSlider::TicksRight);
    slider->setTickInterval(20);

    groupSlider->addSeparator();

    sliderControl = new RibbonSliderControl(Qt::Vertical);
    groupSlider->addControl(sliderControl);
    slider = sliderControl->widget();
    slider->setMinimumHeight(rowHeight * 3);

    RibbonPage* contextPage = ribbonBar()->addPage(tr("&Context Tab"));
    m_contextPage = contextPage;
    m_contextPage->setContextColor(Qtitan::ContextColorRed);

    RibbonGroup* groupContextColor = m_contextPage->addGroup(tr("Context Color_1"));
    Q_ASSERT(groupContextColor != Q_NULL);

    QButtonGroup* groupColorButton = new QButtonGroup(this);
    connect(groupColorButton, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(buttonColorClicked(QAbstractButton*)));

    radioButtonControl = new RibbonRadioButtonControl(tr("Green"));
    groupContextColor->addControl(radioButtonControl);
    QRadioButton* radio = radioButtonControl->widget();
    radio->setProperty(Prop_ContextColor, Qtitan::ContextColorGreen);
    radio->setToolTip(tr("Color Green"));
    groupColorButton->addButton(radio);

    radioButtonControl = new RibbonRadioButtonControl(tr("Blue"));
    groupContextColor->addControl(radioButtonControl);
    radio = radioButtonControl->widget();
    radio->setProperty(Prop_ContextColor, Qtitan::ContextColorBlue);
    radio->setToolTip(tr("Color Blue"));
    groupColorButton->addButton(radio);

    radioButtonControl = new RibbonRadioButtonControl(tr("Red"));
    groupContextColor->addControl(radioButtonControl);
    radio = radioButtonControl->widget();
    radio->setProperty(Prop_ContextColor, Qtitan::ContextColorRed);
    radio->setToolTip(tr("Color Red"));
    radio->setChecked(true);
    groupColorButton->addButton(radio);

    radioButtonControl = new RibbonRadioButtonControl(tr("Yellow"));
    groupContextColor->addControl(radioButtonControl);
    radio = radioButtonControl->widget();
    radio->setProperty(Prop_ContextColor, Qtitan::ContextColorYellow);
    radio->setToolTip(tr("Color Yellow"));
    groupColorButton->addButton(radio);

    radioButtonControl = new RibbonRadioButtonControl(tr("Cyan"));
    groupContextColor->addControl(radioButtonControl);
    radio = radioButtonControl->widget();
    radio->setProperty(Prop_ContextColor, Qtitan::ContextColorCyan);
    radio->setToolTip(tr("Color Cyan"));
    groupColorButton->addButton(radio);

    radioButtonControl = new RibbonRadioButtonControl(tr("Purple"));
    groupContextColor->addControl(radioButtonControl);
    radio = radioButtonControl->widget();
    radio->setProperty(Prop_ContextColor, Qtitan::ContextColorPurple);
    radio->setToolTip(tr("Color Purple"));
    groupColorButton->addButton(radio);

    radioButtonControl = new RibbonRadioButtonControl(tr("Orange"));
    groupContextColor->addControl(radioButtonControl);
    radio = radioButtonControl->widget();
    radio->setProperty(Prop_ContextColor, Qtitan::ContextColorOrange);
    radio->setToolTip(tr("Color Orange"));
    groupColorButton->addButton(radio);

    groupContextColor = m_contextPage->addGroup(tr("Context Color_2"));
    Q_ASSERT(groupContextColor != Q_NULL);
    groupContextColor->setTitleElideMode(Qt::ElideNone);
    groupContextColor = m_contextPage->addGroup(tr("Context Color_3"));
    Q_ASSERT(groupContextColor != Q_NULL);
    groupContextColor->setTitleElideMode(Qt::ElideNone);

    ribbonBar()->setFrameThemeEnabled();
}

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

void MainWindow::open()
{
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open"));
    if (!fileName.isEmpty())
    {
        setCurrentFile(fileName);
        statusBar()->showMessage(tr("File loaded"), 2000);
    }
}

bool MainWindow::save()
{
    QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),tr("Document"), QLatin1Char('*') + QStringLiteral(".txt"));
    if (!fileName.isEmpty())
    {
        setCurrentFile(fileName);
        statusBar()->showMessage(tr("File saved"), 2000);
        return true;
    }
    return false;
}

void MainWindow::openRecentFile(const QString& file)
{
    QMessageBox messageBox(QMessageBox::Information, windowTitle(), QString(), QMessageBox::Ok, this);
    messageBox.setInformativeText(QStringLiteral("Open Recent File.") + QStringLiteral(" ") + file);
    messageBox.exec();
}

void MainWindow::print()
{
    QPrinter printer;
    QPrintDialog dialog(&printer, this);
    if (dialog.exec() == QDialog::Accepted) {}
}

void MainWindow::printSetup()
{
}

void MainWindow::pressButton()
{
    QMessageBox messageBox(QMessageBox::Information, windowTitle(),
        QString(), QMessageBox::Ok, this);
    messageBox.setInformativeText(QStringLiteral("Press button."));
    messageBox.exec();
}

void MainWindow::startProgressBar(int state)
{
    if (state == Qt::Checked)
    {
        m_progressBar2 = new QProgressBar();
        m_progressBar2->setMaximumWidth(200);
        int height = statusBar()->sizeHint().height();
        m_progressBar2->setMaximumHeight(height - height/3);
        statusBar()->addPermanentWidget(m_progressBar2);

        m_valueProgress = 0;
        m_timerProgressBar.start();
    }
    else if (state == Qt::Unchecked)
    {
        m_timerProgressBar.stop();
        m_valueProgress = 40;
        m_progressBar->setValue(m_valueProgress);
        m_progressBar1->setValue(m_valueProgress);
        m_progressBar2->setValue(m_valueProgress);
        statusBar()->removeWidget(m_progressBar2);

        delete m_progressBar2;
        m_progressBar2 = Q_NULL;
    }
}

void MainWindow::animateProgressBar()
{
    m_progressBar->setValue(m_valueProgress);
    m_progressBar1->setValue(m_valueProgress);
    m_progressBar2->setValue(m_valueProgress);

    m_valueProgress += 10;

    if (m_valueProgress == 100)
    {
        m_progressBar->setValue(m_valueProgress);
        m_progressBar1->setValue(m_valueProgress);
        m_progressBar2->setValue(m_valueProgress);
        m_valueProgress = 0;
    }
}

void MainWindow::buttonColorClicked(QAbstractButton* but)
{
    uint numColor = but->property(Prop_ContextColor).toUInt();
    m_contextPage->setContextColor((Qtitan::ContextColor)numColor);
}

void MainWindow::setCurrentFile(const QString& fileName)
{
    QString curFile = fileName;
    setWindowFilePath(curFile);

    QSettings settings;
    QStringList files = settings.value(QStringLiteral("recentFileList")).toStringList();
    files.removeAll(fileName);
    files.prepend(fileName);

    while (files.size() > 9)
        files.removeLast();

    settings.setValue(QStringLiteral("recentFileList"), files);
    emit updateRecentFileActions(files);
}