StyledWidgetsDemo Example

#include <QApplication>
#include <QScreen>
#include <QMenu>
#include <QMenuBar>
#include <QToolBar>
#include <QStyleFactory>
#include <QDockWidget>
#include <QMdiArea>
#include <QTableWidget>
#include <QMdiSubWindow>
#include <QSettings>
#include <QToolButton>
#include <QTextEdit>
#include <QDialog>
#include <QActionGroup>
#include <QVBoxLayout>
#include <QCommandLinkButton>
#include <QPainter>
#include <qmath.h>
#include <QScrollArea>
#include <QSplitter>

#include <aboutdialog.h>
#include "dockwidgets.h"
#include "mainwindow.h"
#include "ui_StyledDialog.h"

#define QTN_DC_STYLE 1

/* MainWindow */
MainWindow::MainWindow()
    : QMainWindow(), m_styleWindow(Q_NULL)
{
    setWindowTitle(tr("StyledWidgets Demo"));
    m_styleName = QStringLiteral("Default");
    m_defaultStyle = qApp->style()->objectName();
    //CommonStyle::ensureStyle();

    /*QPalette p;
    p.setColor(backgroundRole(), Qt::transparent);
    setAutoFillBackground(false);
    setPalette(p);*/

    WindowTitleBar* bar = WindowTitleBar::get(this);
    //bar->setBackgroundColor(Qt::green);
    bar->setBlurBehindWindowEffect(WindowTitleBar::Mica);
    bar->setSystemButtonVisible(WindowTitleBar::DarkModeButton, true);
    bar->setSystemButtonVisible(WindowTitleBar::SettingsButton, true);
    bar->setSystemButtonVisible(WindowTitleBar::BackButton, true);
    //titleBar()->setExtendViewIntoTitleBar(true);
    connect(bar, SIGNAL(darkModeActivated(bool)), this, SLOT(darkModeActivated(bool)));
    connect(bar, SIGNAL(showSettings()), this, SLOT(showSettings()));
    connect(bar, SIGNAL(showHelp()), this, SLOT(showHelp()));
    bar->setVisible(true);

    m_mdiArea = new QMdiArea;
#if 1
    m_mdiArea->setViewMode(QMdiArea::SubWindowView);
#else
    m_mdiArea->setViewMode(QMdiArea::TabbedView);
#endif
    m_mdiArea->setTabsClosable(true);

    createActions();
    createDockWindows();
    createMenuBar();
    createToolBar();
    createMdiChild();

    setCentralWidget(m_mdiArea);
    statusBar();
    setToolButtonStyle(Qt::ToolButtonFollowStyle);
    readSettings();
}

MainWindow::~MainWindow()
{
}

void MainWindow::closeEvent(QCloseEvent* event)
{
    writeSettings();
    QMainWindow::closeEvent(event);
}

void MainWindow::createActions()
{
    // Group File
    m_actNew = new QAction(QIcon(QLatin1String(":/res/new.png")), tr("&New"), this);
    m_actNew->setStatusTip(tr("Create a new document"));
    m_actNew->setPriority(QAction::LowPriority);
    m_actNew->setShortcut(QKeySequence::New);
    connect(m_actNew, SIGNAL(triggered()), this, SLOT(createMdiChild()));

    m_actOpen = new QAction(QIcon(QLatin1String(":/res/open.png")), tr("&Open..."), this);
    m_actOpen->setStatusTip(tr("Open an existing document"));
    m_actOpen->setShortcut(QKeySequence::Open);

    m_actSave = new QAction(QIcon(QLatin1String(":/res/save.png")), tr("&Save"), this);
    m_actSave->setStatusTip(tr("Save the active document"));
    m_actSave->setShortcut(QKeySequence::Save);

    m_actClose = new QAction(tr("&Close"), this);
    m_actClose->setStatusTip(tr("Close the active document"));

    m_actSaveAs = new QAction(tr("Save &As..."), this);
    m_actSaveAs->setPriority(QAction::LowPriority);
    m_actSaveAs->setStatusTip(tr("Save the active document with a new name"));

    m_actPrint = new QAction(QIcon(QLatin1String(":/res/print.png")),tr("&Print..."), this);
    m_actPrint->setPriority(QAction::LowPriority);
    m_actPrint->setShortcut(QKeySequence::Print);
    m_actPrint->setStatusTip(tr("Print the active document"));

    m_actPrintPreview = new QAction(QIcon(QLatin1String(":/res/printpreview.png")),tr("Print Preview..."), this);
    m_actPrintPreview->setStatusTip(tr("Display full pages"));

    m_actExit = new QAction(tr("E&xit"), this);
    m_actExit->setStatusTip(tr("Quit the application; prompts to save documents"));
    connect(m_actExit, SIGNAL(triggered()), this, SLOT(close()));

    // Group help
    m_actHelp = new QAction(QIcon(QLatin1String(":/shared/res/about.png")), tr("&About Custom Styles Sample..."), this);
    m_actHelp->setStatusTip(tr("Display program information, version number and copyright"));
    connect(m_actHelp, SIGNAL(triggered()), this, SLOT(about()));
}

class CustomMenu : public QMenu
{
public:
    CustomMenu(const QString& title, QWidget* parent = nullptr) : QMenu(title, parent)
    {}
protected:
    void changeEvent(QEvent* e) override
    {
        if (e->type() == QEvent::PaletteChange)
        {
            QColor c = palette().window().color();
            c = c;
        }
        QMenu::changeEvent(e);
    }
};

void MainWindow::createMenuBar()
{
    QMenuBar* mainMenuBar = menuBar();

    QMenu* menuFile = new QMenu(tr("&File"), this);
    mainMenuBar->addMenu(menuFile);

    menuFile->addAction(m_actNew);
    menuFile->addAction(m_actOpen);
    menuFile->addAction(m_actClose);
    menuFile->addAction(m_actSave);
    menuFile->addAction(m_actSaveAs);

    menuFile->addSeparator();

    menuFile->addAction(m_actPrint);

    menuFile->addAction(m_actPrintPreview);
    menuFile->addSeparator();

    menuFile->addAction(m_actExit);

    m_viewMenu = new QMenu(tr("&View"), this);
    mainMenuBar->addMenu(m_viewMenu);
    m_viewMenu->addAction(m_styleDockWidget->toggleViewAction());
    m_viewMenu->addAction(m_modulesDockWidget->toggleViewAction());
    m_viewMenu->addAction(m_toolBoxDockWidget->toggleViewAction());
    m_viewMenu->addSeparator();

    m_styleMenu = new CustomMenu(tr("&Custom Styles"), this);
    QActionGroup* actionGroup = new QActionGroup(m_styleMenu);
    connect(m_styleMenu, SIGNAL(triggered(QAction*)), this, SLOT(styleChanged(QAction*)));

    QAction* action = m_styleMenu->addAction(tr("Default"));
    action->setObjectName(QStringLiteral("Default"));
    action->setCheckable(true);
    action->setChecked(true);
    actionGroup->addAction(action);

    action = m_styleMenu->addAction(tr("Fusion"));
    action->setObjectName(QStringLiteral("Fusion"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    m_styleMenu->addSeparator();

    QMenu* adobePhotoshopMenu = new QMenu(tr("Adobe Photoshop"), this);
    m_styleMenu->addMenu(adobePhotoshopMenu);

    action = adobePhotoshopMenu->addAction(tr("Light Gray"));
    action->setObjectName(QStringLiteral("AdobePhotoshopLightGray"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    action = adobePhotoshopMenu->addAction(tr("Gray"));
    action->setObjectName(QStringLiteral("AdobePhotoshopGray"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    action = adobePhotoshopMenu->addAction(tr("Dark Gray"));
    action->setObjectName(QStringLiteral("AdobePhotoshopDarkGray"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    action = adobePhotoshopMenu->addAction(tr("Black"));
    action->setObjectName(QStringLiteral("AdobePhotoshopBlack"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    QMenu* visualStudioMenu = new QMenu(tr("Visual Studio 2019"), this);
    m_styleMenu->addMenu(visualStudioMenu);

    action = visualStudioMenu->addAction(tr("Light"));
    action->setObjectName(QStringLiteral("VisualStudioLight"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    action = visualStudioMenu->addAction(tr("Blue"));
    action->setObjectName(QStringLiteral("VisualStudioBlue"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    action = visualStudioMenu->addAction(tr("Dark"));
    action->setObjectName(QStringLiteral("VisualStudioDark"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    m_styleMenu->addSeparator();

    QMenu* office2013Menu = new QMenu(tr("Office 2013"), this);
    m_styleMenu->addMenu(office2013Menu);
    m_styleMenu->addSeparator();

    action = office2013Menu->addAction(tr("White"));
    action->setObjectName(QStringLiteral("Office2013White"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    action = office2013Menu->addAction(tr("Light Gray"));
    action->setObjectName(QStringLiteral("Office2013Gray"));
    action->setCheckable(true);
    m_styleMenu->addMenu(office2013Menu);
    actionGroup->addAction(action);

    action = office2013Menu->addAction(tr("Dark Gray"));
    action->setObjectName(QStringLiteral("Office2013Dark"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    QMenu* office2016Menu = new QMenu(tr("Office 2016"), this);
    m_styleMenu->addMenu(office2016Menu);
    m_styleMenu->addSeparator();

    action = office2016Menu->addAction(tr("Colorful"));
    action->setObjectName(QStringLiteral("Office2016Colorful"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    action = office2016Menu->addAction(tr("White"));
    action->setObjectName(QStringLiteral("Office2016White"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    action = office2016Menu->addAction(tr("Dark Gray"));
    action->setObjectName(QStringLiteral("Office2016DarkGray"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    action = office2016Menu->addAction(tr("Black"));
    action->setObjectName(QStringLiteral("Office2016Black"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    QMenu* windowsUUStyleMenu = new QMenu(tr("Windows UI"), this);
    m_styleMenu->addMenu(windowsUUStyleMenu);
    m_styleMenu->addSeparator();

    action = windowsUUStyleMenu->addAction(tr("Light"));
    action->setObjectName(QStringLiteral("WindowsUILight"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    action = windowsUUStyleMenu->addAction(tr("Dark"));
    action->setObjectName(QStringLiteral("WindowsUIDark"));
    action->setCheckable(true);
    actionGroup->addAction(action);

    m_viewMenu->addMenu(m_styleMenu);
    m_viewMenu->addSeparator();
    QAction* actStyleDialog = new QAction(tr("Style Dialog..."), this);
    m_viewMenu->addAction(actStyleDialog);
    connect(actStyleDialog, SIGNAL(triggered()), this, SLOT(createStyleDialog()));

    QAction* formAct = new QAction(tr("Style Window..."), this);
    m_viewMenu->addAction(formAct);
    connect(formAct, SIGNAL(triggered()), this, SLOT(showStyleWindow()));

    QMenu* menuHelp = new QMenu(tr("&Help"), this);
    mainMenuBar->addMenu(menuHelp);
    menuHelp->addAction(m_actHelp);
}

void MainWindow::createToolBar()
{
    QToolBar* standardBar = new QToolBar(tr("StandardBar"), this);
    standardBar->setAllowedAreas(Qt::AllToolBarAreas);
    standardBar->addAction(m_actNew);
    standardBar->addAction(m_actOpen);
    standardBar->addAction(m_actSave);
    standardBar->addSeparator();
    standardBar->addAction(m_actPrint);
    standardBar->addAction(m_actPrintPreview);
    addToolBar(standardBar);

    QToolBar* customBar = new QToolBar(tr("Custom Styles"), this);
    customBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
    customBar->setAllowedAreas(Qt::AllToolBarAreas);
    QAction* actTheme = new QAction(QIcon(QLatin1String(":/res/customthemes.png")), tr("Custom Styles"), this);
    actTheme->setMenu(m_styleMenu);
    customBar->addAction(actTheme);

    QToolButton* button = qobject_cast<QToolButton*>(customBar->widgetForAction(actTheme));
    Q_ASSERT(button != Q_NULL);
    button->setPopupMode(QToolButton::InstantPopup);
    button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    addToolBar(customBar);

    QToolBar* explorerBar = new QToolBar(tr("Explorer"), this);
    explorerBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
    explorerBar->setAllowedAreas(Qt::AllToolBarAreas);
    QAction* act = explorerBar->addAction(QIcon(QLatin1String(":/res/back.png")), tr("Back"));
    act->setStatusTip(tr("Back"));
    act = explorerBar->addAction(QIcon(QLatin1String(":/res/forward.png")), tr("Forward"));
    act->setStatusTip(tr("Forward"));
    explorerBar->addSeparator();
    act = explorerBar->addAction(QIcon(QLatin1String(":/res/up.png")), tr("Up"));
    act->setStatusTip(tr("Up"));

    Qtitan::PopupMenu* popupMenu = new Qtitan::PopupMenu();
    //popupMenu->setMultiColumn(true);
    popupMenu->setMaxItemCount(5);
    QPushButton* b1 = new QPushButton("Text Preivew");
    popupMenu->setPreviewWidget(b1);
    act->setMenu(popupMenu);

    button = qobject_cast<QToolButton*>(explorerBar->widgetForAction(act));
    Q_ASSERT(button != Q_NULL);
    button->setPopupMode(QToolButton::MenuButtonPopup);

    for (int i = 0; i < SegoeMDL2Font::NumSymbols; ++i)
    {
        QString text = tr("Menu Item %1").arg(i);
        popupMenu->addAction(SegoeMDL2Font::icon(SegoeMDL2Font::IconSymbol(i + 100)), text);
        if (i == 450)
            break;
    }

    act = explorerBar->addAction(QIcon(QLatin1String(":/res/viewsearch.png")), tr("Search"));
    act->setStatusTip(tr("Search"));

    QMenu* scrollMenu = new QMenu();
    scrollMenu->setTearOffEnabled(true);
    act->setMenu(scrollMenu);
    for (int i = 0; i < 500; ++i)
    {
        QString text = tr("Menu Item %1").arg(i);
        scrollMenu->addAction(SegoeMDL2Font::icon(SegoeMDL2Font::IconSymbol(i + 100)), text);
    }

    act = explorerBar->addAction(QIcon(QLatin1String(":/res/viewfolders.png")), tr("Folders"));
    act->setStatusTip(tr("Folders"));
    act = explorerBar->addAction(QIcon(QLatin1String(":/res/viewhistory.png")), tr("History"));
    act->setStatusTip(tr("History"));
    explorerBar->addSeparator();
    act = explorerBar->addAction(QIcon(QLatin1String(":/res/moveto.png")), tr("Move To"));
    act->setStatusTip(tr("Move To"));
    act = explorerBar->addAction(QIcon(QLatin1String(":/res/copyto.png")), tr("Copy To"));
    act->setStatusTip(tr("Copy To"));
    act = explorerBar->addAction(QIcon(QLatin1String(":/res/delete.png")), tr("Delete"));
    act->setStatusTip(tr("Delete"));
    act = explorerBar->addAction(QIcon(QLatin1String(":/res/undo.png")), tr("Undo"));
    act->setStatusTip(tr("Undo"));
    explorerBar->addSeparator();
    act = explorerBar->addAction(QIcon(QLatin1String(":/res/views.png")), tr("Views"));
    act->setStatusTip(tr("Views"));
    addToolBar(explorerBar);
}

void MainWindow::createDockWindows()
{
    setDockOptions(dockOptions() |
        QMainWindow::GroupedDragging | QMainWindow::AllowNestedDocks);

    m_styleDockWidget = new QDockWidget(tr("Styles"), this);
    m_styleDockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
    m_styleDockWidget->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetVerticalTitleBar |
        QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
    m_styleDockWidget->setWidget(new StyleDockPanel());

    m_fileBrowserDockWidget = new QDockWidget(tr("File Browser"), this);
    m_fileBrowserDockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
    m_fileBrowserDockWidget->setFeatures(QDockWidget::DockWidgetClosable/* | QDockWidget::DockWidgetVerticalTitleBar |
        QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable*/);

    m_fileBrowserDockWidget->setWidget(new FileBrowserDockPanel());

    m_toolBoxDockWidget = new QDockWidget(tr("ToolBox"), this);
    m_toolBoxDockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
    m_toolBoxDockWidget->setWidget(new ToolBoxDockPanel());
    addDockWidget(Qt::LeftDockWidgetArea, m_toolBoxDockWidget);

    m_modulesDockWidget = new QDockWidget(tr("Modules"), this);
    m_modulesDockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
    m_modulesDockWidget->setWidget(new ModulesDockPanel());

    m_treeViewDockWidget = new QDockWidget(tr("Tree View"), this);
    m_treeViewDockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
    m_treeViewDockWidget->setWidget(new TreeViewDockPanel());

    m_cardDockWidget = new QDockWidget(tr("Card View"), this);
    m_cardDockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
    m_cardDockWidget->setWidget(new CardDockPanel());

    addDockWidget(Qt::LeftDockWidgetArea, m_styleDockWidget);
    addDockWidget(Qt::BottomDockWidgetArea, m_fileBrowserDockWidget);
    addDockWidget(Qt::BottomDockWidgetArea, m_modulesDockWidget);
    addDockWidget(Qt::RightDockWidgetArea, m_treeViewDockWidget);
    addDockWidget(Qt::RightDockWidgetArea, m_cardDockWidget);
}

void MainWindow::showStyleWindow()
{
    if (m_styleWindow == Q_NULLPTR)
        m_styleWindow = new StyleWindow(this);
    m_styleWindow->show();
}

void MainWindow::createStyleDialog()
{
    QDialog dlg(this, Qt::WindowCloseButtonHint);
    Ui::StyledDialog uiDialog;
    uiDialog.setupUi(&dlg);

    // QTreeWidget
    QStringList strings;
    strings.append(tr("Item 1"));
    QTreeWidgetItem* item = new QTreeWidgetItem(strings);
    uiDialog.treeWidget->insertTopLevelItem(0, item);
    strings.clear();
    strings.append(tr("Item 2"));
    uiDialog.treeWidget->insertTopLevelItem(1, new QTreeWidgetItem(item, strings));
    strings.clear();
    strings.append(tr("Item 3"));
    uiDialog.treeWidget->insertTopLevelItem(2, new QTreeWidgetItem(item, strings));
    strings.clear();
    strings.append(tr("Item 4"));
    uiDialog.treeWidget->insertTopLevelItem(3, new QTreeWidgetItem(item, strings));
    strings.clear();
    strings.append(tr("Item 5"));
    uiDialog.treeWidget->insertTopLevelItem(4, new QTreeWidgetItem(item, strings));
    strings.clear();
    strings.append(tr("Item 6"));
    uiDialog.treeWidget->insertTopLevelItem(6, new QTreeWidgetItem(item, strings));
    uiDialog.treeWidget->expandItem(item);

    // QtableView
    uiDialog.tableWidget->setColumnCount(2);
    uiDialog.tableWidget->setRowCount(6);
    uiDialog.tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
    uiDialog.tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
    uiDialog.tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);

    uiDialog.tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Col 1")));
    uiDialog.tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Col 2")));
    int height = uiDialog.tableWidget->horizontalHeader()->sizeHint().height();
    uiDialog.tableWidget->setRowHeight(0, height);
    uiDialog.tableWidget->setRowHeight(1, height);
    uiDialog.tableWidget->setRowHeight(2, height);
    uiDialog.tableWidget->setRowHeight(3, height);
    uiDialog.tableWidget->setRowHeight(4, height);
    uiDialog.tableWidget->setRowHeight(5, height);
    // QListWidget
    uiDialog.listWidget->insertItem(0, tr("Item 1"));
    uiDialog.listWidget->insertItem(1, tr("Item 2"));
    uiDialog.listWidget->insertItem(2, tr("Item 3"));
    uiDialog.listWidget->insertItem(3, tr("Item 4"));
    uiDialog.listWidget->insertItem(4, tr("Item 5"));
    uiDialog.listWidget->insertItem(5, tr("Item 6"));
    uiDialog.listWidget->setCurrentRow(3);

    uiDialog.comboBox->addItem(tr("Normal 1"));
    uiDialog.comboBox->addItem(tr("Normal 2"));
    uiDialog.comboBox->addItem(tr("Normal 3"));
    uiDialog.comboBox->addItem(tr("Normal 4"));
    uiDialog.comboBox->addItem(tr("Normal 5"));

    uiDialog.comboBox_2->addItem(tr("Disabled"));
    uiDialog.lineEdit->setText(tr("Normal"));

    QToolButton* button1 = new QToolButton(uiDialog.tab_2);
    button1->setIcon(style()->standardIcon(QStyle::SP_MessageBoxCritical));
    QMenu* menu = new QMenu(uiDialog.tab_2);
    menu->addAction(tr("Test1"));
    menu->addAction(tr("Test2"));
    menu->addAction(tr("Test3"));
    button1->setMenu(menu);
    button1->setPopupMode(QToolButton::InstantPopup);
    button1->setText(tr("Button1"));
    button1->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    button1->move(10, 10);
    button1->resize(button1->sizeHint() + QSize(10, 10));

    QToolButton* button2 = new QToolButton(uiDialog.tab_2);
    button2->setIcon(style()->standardIcon(QStyle::SP_MessageBoxCritical));
    button2->setMenu(menu);
    button2->setPopupMode(QToolButton::DelayedPopup);
    button2->setText(tr("Button2"));
    button2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    button2->move(button1->width() + 20, 10);
    button2->resize(button2->sizeHint() + QSize(10, 10));
    button2->setEnabled(false);

    ToggleSwitch* toggleSwitch = new ToggleSwitch(uiDialog.tab_2);
//    toggleSwitch->setEnabled(false);
//    toggleSwitch->setShape(ToggleSwitch::RoundedSmallGroove);
//    toggleSwitch->setLabelOff(tr("Label Off"));
//    toggleSwitch->setLabelOn(tr("Label On"));
    toggleSwitch->move(button1->width() + button2->width() + 30, 10);
//    toggleSwitch->resize(QSize(68, 30));

#ifdef QTN_CALCULATOR
    QRect rect = button1->geometry();
    QLabel* labCalc = new QLabel("Calculator:", uiDialog.tab_2);
    labCalc->setGeometry(QRect(QPoint(rect.bottomLeft() + QPoint(0, 10)), labCalc->sizeHint()));

    m_calculator = new CalculatorWidget(uiDialog.tab_2);
    rect = labCalc->geometry();
    m_calculator->setGeometry(QRect(QPoint(rect.bottomLeft() + QPoint(0, 6)), QSize(200, 250)));
    connect(m_calculator, SIGNAL(executeAction(int)), this, SLOT(executeAction(int)));
    m_calculator->show();

    QRect rcCalc = m_calculator->geometry();
    QCheckBox* extActions = new QCheckBox(QString("Extended actions"), uiDialog.tab_2);
    extActions->move(QPoint(rcCalc.bottomLeft() + QPoint(0, 10)));
    connect(extActions, SIGNAL(stateChanged(int)), this, SLOT(extActionsOn(int)));
    extActions->show();

    QRect extActionsRect = extActions->geometry();
    QCheckBox* userActions = new QCheckBox(QString("User actions"), uiDialog.tab_2);
    userActions->move(QPoint(extActionsRect.bottomLeft() + QPoint(0, 6)));
    connect(userActions, SIGNAL(stateChanged(int)), this, SLOT(userActionsOn(int)));
    userActions->show();

    rect = button1->geometry();
    QLabel* labCalcBox = new QLabel("Calculator box:", uiDialog.tab_2);
    labCalcBox->setGeometry(QRect(QPoint(QPoint(m_calculator->geometry().right() + 10, rect.bottom()) + QPoint(0, 10)), labCalcBox->sizeHint()));

    CalculatorComboBox* calcBox = new CalculatorComboBox(uiDialog.tab_2);
    calcBox->setLineEdit(new QLineEdit);
    calcBox->move(QPoint(rcCalc.topRight() + QPoint(10, 0)));
    calcBox->resize(QSize(180, calcBox->sizeHint().height()));
    calcBox->show();
#endif
    dlg.exec();
}

#ifdef QTN_CALCULATOR
void MainWindow::executeAction(int keyAction)
{
    double val = m_calculator->value();
    if (keyAction == CalculatorWidget::keyActionUser)
        val = qFabs(val); // Abs
    else if (keyAction == CalculatorWidget::keyActionUser + 1)
        val = qAsin(val);
    else if (keyAction == CalculatorWidget::keyActionUser + 2)
        val = qAcos(val);
    else if (keyAction == CalculatorWidget::keyActionUser + 3)
        val = qAtan(val);
    m_calculator->setValue(val);
}

void MainWindow::extActionsOn(int state)
{
    if (state == Qt::Checked)
    {
        QVector<uint> m_lstExtActions;
        m_lstExtActions.append(CalculatorWidget::keyActionAdvSin);
        m_lstExtActions.append(CalculatorWidget::keyActionAdvCos);
        m_lstExtActions.append(CalculatorWidget::keyActionAdvTan);
        m_lstExtActions.append(CalculatorWidget::keyActionAdvExp);
        m_lstExtActions.append(CalculatorWidget::keyActionAdvX3);
        m_lstExtActions.append(CalculatorWidget::keyActionAdvX2);
        m_lstExtActions.append(CalculatorWidget::keyActionAdvLn);
        m_lstExtActions.append(CalculatorWidget::keyActionAdvLog);
        m_lstExtActions.append(CalculatorWidget::keyActionAdv10x);
        m_lstExtActions.append(CalculatorWidget::keyActionAdvPi);
        m_calculator->addExtendedActions(m_lstExtActions);
    }
    else if (state == Qt::Unchecked)
    {
        m_calculator->removeExtendedActions();
    }
    m_calculator->setValue(0.0);
    m_calculator->setError(false);
}

void MainWindow::userActionsOn(int state)
{
    if (state == Qt::Checked)
    {
        QStringList m_lstUserActions;
        m_lstUserActions.append("abs");
        m_lstUserActions.append("sinh");
        m_lstUserActions.append("cosh");
        m_lstUserActions.append("tanh");
        m_calculator->addUserActions(m_lstUserActions);
    }
    else if (state == Qt::Unchecked)
    {
        m_calculator->removeUserActions();
    }
    m_calculator->setValue(0.0);
    m_calculator->setError(false);
}
#endif

QTextEdit* MainWindow::createMdiChild()
{
    static int sequenceNumber = 1;
    QString curFile = tr("document%1.txt").arg(sequenceNumber++);
    QTextEdit* child1 = new QTextEdit;
    QTextEdit* child2 = new QTextEdit;
    QSplitter* splitter = new QSplitter();
    splitter->setOrientation(Qt::Vertical);
    splitter->addWidget(child1);
    splitter->addWidget(child2);

    splitter->setWindowIcon(QIcon(QLatin1String(":/res/new.png")));
    splitter->setWindowTitle(curFile + QLatin1String("[*]"));

    QMdiSubWindow* subWindow = m_mdiArea->addSubWindow(splitter);
    subWindow->setWindowState(Qt::WindowMaximized);
    subWindow->show();
    return child1;
}

void MainWindow::setStyleByName(const QString& name)
{
    if (m_styleName == name)
        return;

    if (name == QLatin1String("Default"))
    {
        qApp->setStyle(m_defaultStyle);
    }
    else if (name == QLatin1String("Fusion"))
    {
        qApp->setStyle(QLatin1String("fusion"));
    }
    else if (name == QLatin1String("AdobePhotoshopLightGray") ||
        name == QLatin1String("AdobePhotoshopGray") ||
        name == QLatin1String("AdobePhotoshopDarkGray") ||
        name == QLatin1String("AdobePhotoshopBlack"))
    {
        AdobePhotoshopStyle* style = qobject_cast<AdobePhotoshopStyle*>(qApp->style());
        if (style == Q_NULL)
            style = new AdobePhotoshopStyle();
        if (name == QLatin1String("AdobePhotoshopLightGray"))
            style->setTheme(AdobePhotoshopStyle::LightGray);
        if (name == QLatin1String("AdobePhotoshopGray"))
            style->setTheme(AdobePhotoshopStyle::Gray);
        if (name == QLatin1String("AdobePhotoshopDarkGray"))
            style->setTheme(AdobePhotoshopStyle::DarkGray);
        if (name == QLatin1String("AdobePhotoshopBlack"))
            style->setTheme(AdobePhotoshopStyle::Black);
        qApp->setStyle(style);
    }

    else if (name == QLatin1String("VisualStudioLight") ||
        name == QLatin1String("VisualStudioBlue") ||
        name == QLatin1String("VisualStudioDark"))
    {
        VisualStudio2019Style* style = qobject_cast<VisualStudio2019Style*>(qApp->style());
        if (style == Q_NULL)
            style = new VisualStudio2019Style();
        if (name == QLatin1String("VisualStudioLight"))
            style->setTheme(VisualStudio2019Style::Light);
        if (name == QLatin1String("VisualStudioBlue"))
            style->setTheme(VisualStudio2019Style::Blue);
        if (name == QLatin1String("VisualStudioDark"))
            style->setTheme(VisualStudio2019Style::Dark);
        qApp->setStyle(style);
    }
    else if (name == QLatin1String("Office2013White") ||
        name == QLatin1String("Office2013Gray") ||
        name == QLatin1String("Office2013Dark"))
    {
        Office2013Style* style = qobject_cast<Office2013Style*>(qApp->style());
        if (style == Q_NULL)
            style = new Office2013Style();
        if (name == QLatin1String("Office2013White"))
            style->setTheme(Office2013Style::White);
        else if (name == QLatin1String("Office2013Gray"))
            style->setTheme(Office2013Style::Gray);
        else if (name == QLatin1String("Office2013Dark"))
            style->setTheme(Office2013Style::Dark);
        qApp->setStyle(style);
    }
    else if (name == QLatin1String("Office2016Colorful") ||
        name == QLatin1String("Office2016White") ||
        name == QLatin1String("Office2016DarkGray") ||
        name == QLatin1String("Office2016Black"))
    {
        Office2016Style* style = qobject_cast<Office2016Style*>(qApp->style());
        if (style == Q_NULL)
            style = new Office2016Style();
        if (name == QLatin1String("Office2016Colorful"))
            style->setTheme(Office2016Style::Colorful);
        else if (name == QLatin1String("Office2016White"))
            style->setTheme(Office2016Style::White);
        else if (name == QLatin1String("Office2016DarkGray"))
            style->setTheme(Office2016Style::DarkGray);
        else if (name == QLatin1String("Office2016Black"))
            style->setTheme(Office2016Style::Black);
        qApp->setStyle(style);
    }
    else if (name == QLatin1String("WindowsUILight") || name == QLatin1String("WindowsUIDark"))
    {
        WindowsUIStyle* style = qobject_cast<WindowsUIStyle*>(qApp->style());
        if (style == Q_NULL)
            style = new WindowsUIStyle();

        if (name == QLatin1String("WindowsUILight"))
            style->setTheme(WindowsUIStyle::Light);
        else if (name == QLatin1String("WindowsUIDark"))
            style->setTheme(WindowsUIStyle::Dark);
        qApp->setStyle(style);
    }
    else
    {
        Q_ASSERT(false);
        return;
    }
    m_styleName = name;
    CommonStyle::ensureStyle();
}

void MainWindow::styleChanged(QAction* action)
{
    setStyleByName(action->objectName());
}

void MainWindow::readSettings()
{
    QSettings settings(QLatin1String("MainWindow"), QLatin1String("Qtitan MainWindow Sample"));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
    const QRect availableGeometry = screen()->availableGeometry();
    QRect geom = QRect(QPoint((availableGeometry.width() - width()) / 2, (availableGeometry.height() - height()) / 2),
        QSize(2 * availableGeometry.width() / 3, 2 * availableGeometry.height() / 3));
#else
    QRect geom = QRect(QPoint(200, 200), QSize(800, 640));
#endif
    QString styleName = settings.value(QStringLiteral("style"), QStringLiteral("Default")).toString();
    QPoint pos = settings.value(QLatin1String("pos"), geom.topLeft()).toPoint();
    QSize size = settings.value(QLatin1String("size"), geom.size()).toSize();
    resize(size);
    move(pos);
    setStyleByName(styleName);
}

void MainWindow::writeSettings()
{
    QSettings settings(QLatin1String("MainWindow"), QLatin1String("Qtitan MainWindow Sample"));
    settings.setValue(QLatin1String("pos"), pos());
    settings.setValue(QLatin1String("size"), size());
    settings.setValue(QStringLiteral("style"), m_styleName);
}

void MainWindow::about()
{
    AboutDialog::show(this, tr("About Qtitan MainWindow"), tr("OfficeStyle"), QLatin1String(QTN_VERSION_STYLE_STR));
}

// Title Bar buttons
void MainWindow::darkModeActivated(bool darkMode)
{
    QString name = darkMode ? QLatin1String("WindowsUIDark") : QLatin1String("WindowsUILight");
    setStyleByName(name);
}

void MainWindow::showSettings()
{
    //do nothing.
}

void MainWindow::showHelp()
{
    about();
}

/* StyleWindow */
StyleWindow::StyleWindow(QWidget* parent)
    : QMainWindow(parent), m_forms(Q_NULL)
{
    m_forms = new QTabWidget(this);
    //m_forms->tabBar()->setDrawBase(true);
    //m_forms->tabBar()->setShape(QTabBar::TriangularEast);
    //m_forms->tabBar()->setDocumentMode(true);
    //m_forms->setDocumentMode(true);

    m_forms->setTabsClosable(true);
    m_forms->setMovable(true);
    m_forms->addTab(createPaletteForm(), tr("Palette"));
    m_forms->addTab(createIconForm(), tr("Icons"));
    m_forms->addTab(createPushButtonForm(), tr("Buttons"));
    m_forms->addTab(createCheckBoxForm(), tr("Check-boxes"));
    m_forms->addTab(createRadioButtonForm(), tr("Radio-buttons"));
    m_forms->addTab(createToggleSwitchForm(), tr("Switches"));

    setCentralWidget(m_forms);
    m_forms->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
}

class PaletteColorItem: public QWidget
{
public:
    PaletteColorItem(QPalette::ColorGroup group, QPalette::ColorRole role)
        : QWidget(), m_group(group), m_role(role) {}
    QSize sizeHint() const override
    {
        return QSize(70, 30);
    }
protected:
    void paintEvent(QPaintEvent* event) override
    {
        Q_UNUSED(event);
        QPalette palette = qApp->palette();

        QPainter painter(this);
        painter.fillRect(rect(), palette.color(m_group, m_role));
    }
private:
    QPalette::ColorGroup m_group;
    QPalette::ColorRole m_role;
};

class StandardPixmapItem : public QWidget
{
public:
    StandardPixmapItem(QStyle::StandardPixmap pixmap, QStyle::PixelMetric size, QIcon::Mode mode, QIcon::State state)
        : QWidget(), m_pixmap(pixmap), m_size(size), m_mode(mode), m_state(state) {}
    QSize sizeHint() const override
    {
        int val = style()->pixelMetric(m_size, Q_NULL, Q_NULL);
        return QSize(val, val);
    }
protected:
    void paintEvent(QPaintEvent* event) override
    {
        Q_UNUSED(event);
        QPainter painter(this);
        QIcon icon = style()->standardIcon(m_pixmap, Q_NULL, Q_NULL);
        icon.paint(&painter, rect(), Qt::AlignCenter, m_mode, m_state);
    }
private:
    QStyle::StandardPixmap m_pixmap;
    QStyle::PixelMetric m_size;
    QIcon::Mode m_mode;
    QIcon::State m_state;
};

class PaletteForm : public QScrollArea
{
public:
    PaletteForm(QWidget* parent = Q_NULL)
        : QScrollArea(parent)
    {
        QWidget* view = new QWidget();
        QGridLayout* layout = new QGridLayout(view);
        layout->setSizeConstraint(QLayout::SetFixedSize);
        QLabel* activeLabel = new QLabel(tr("Active"));
        QLabel* inactiveLabel = new QLabel(tr("Inactive"));
        QLabel* disabledLabel = new QLabel(tr("Disabled"));

        int row = 0;
        QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
        layout->addItem(spacer, row, 0);
        layout->addWidget(activeLabel, row, 1);
        layout->addWidget(inactiveLabel, row, 2);
        layout->addWidget(disabledLabel, row, 3);
        ++row;

        for (int i = 0; i < QPalette::NColorRoles; ++i)
        {
            QLabel* roleName = new QLabel();
            roleName->setText(getRoleName(QPalette::ColorRole(i)));
            layout->addWidget(roleName, row, 0);
            PaletteColorItem* activeItem = new PaletteColorItem(QPalette::Active, QPalette::ColorRole(i));
            PaletteColorItem* inactiveItem = new PaletteColorItem(QPalette::Inactive, QPalette::ColorRole(i));
            PaletteColorItem* disabledItem = new PaletteColorItem(QPalette::Disabled, QPalette::ColorRole(i));
            layout->addWidget(activeItem, row, 1);
            layout->addWidget(inactiveItem, row, 2);
            layout->addWidget(disabledItem, row, 3);
            ++row;
        }
        setWidget(view);
    }
protected:
    QString getRoleName(QPalette::ColorRole role) {
        switch (role)
        {
        case QPalette::WindowText: return QLatin1String("WindowText");
        case QPalette::Button: return QLatin1String("Button");
        case QPalette::Light: return QLatin1String("Light");
        case QPalette::Midlight: return QLatin1String("Midlight");
        case QPalette::Dark: return QLatin1String("Dark");
        case QPalette::Mid: return QLatin1String("Mid");
        case QPalette::Text: return QLatin1String("Text");
        case QPalette::BrightText: return QLatin1String("BrightText");
        case QPalette::ButtonText: return QLatin1String("ButtonText");
        case QPalette::Base: return QLatin1String("Base");
        case QPalette::Window: return QLatin1String("Window");
        case QPalette::Shadow: return QLatin1String("Shadow");
        case QPalette::Highlight: return QLatin1String("Highlight");
        case QPalette::HighlightedText: return QLatin1String("HighlightedText");
        case QPalette::Link: return QLatin1String("Link");
        case QPalette::LinkVisited: return QLatin1String("LinkVisited");
        case QPalette::AlternateBase: return QLatin1String("AlternateBase");
        case QPalette::NoRole: return QLatin1String("NoRole");
        case QPalette::ToolTipBase: return QLatin1String("ToolTipBase");
        case QPalette::ToolTipText: return QLatin1String("ToolTipText");
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
        case QPalette::PlaceholderText: return QLatin1String("PlaceholderText");
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0))
        case QPalette::Accent: return QLatin1String("Accent");
#endif
        default:
            Q_ASSERT(false);
        }
        return QString();
    }
private:
};

class StandardIconForm : public QScrollArea
{
public:
    StandardIconForm(QWidget* parent = Q_NULL)
        : QScrollArea(parent)
    {
        QWidget* view = new QWidget();
        QGridLayout* layout = new QGridLayout(view);
        layout->setSizeConstraint(QLayout::SetFixedSize);
        QLabel* normalLabel = new QLabel(tr("Normal"));
        QLabel* activeLabel = new QLabel(tr("Active"));
        QLabel* disabledLabel = new QLabel(tr("Disabled"));
        QLabel* selectedLabel = new QLabel(tr("Selected"));

        int row = 0;
        QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
        layout->addItem(spacer, row, 0);
        layout->addWidget(normalLabel, row, 1);
        layout->addWidget(activeLabel, row, 2);
        layout->addWidget(disabledLabel, row, 3);
        layout->addWidget(selectedLabel, row, 4);
        ++row;
#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
        for (int i = 0; i < QStyle::StandardPixmap::NStandardPixmap; ++i)
#elif (QT_VERSION > QT_VERSION_CHECK(5, 15, 0))
        for (int i = 0; i <= QStyle::StandardPixmap::SP_RestoreDefaultsButton; ++i)
#else
        for (int i = 0; i < QStyle::StandardPixmap::SP_LineEditClearButton; ++i)
#endif
        {
            QLabel* pixmapName = new QLabel();
            pixmapName->setText(getIconName(QStyle::StandardPixmap(i)));
            layout->addWidget(pixmapName, row, 0);

            StandardPixmapItem* normalItem = new StandardPixmapItem(QStyle::StandardPixmap(i), QStyle::PM_LargeIconSize, QIcon::Normal, QIcon::On);
            StandardPixmapItem* activeItem = new StandardPixmapItem(QStyle::StandardPixmap(i), QStyle::PM_LargeIconSize,  QIcon::Active, QIcon::On);
            StandardPixmapItem* disabledItem = new StandardPixmapItem(QStyle::StandardPixmap(i), QStyle::PM_LargeIconSize, QIcon::Disabled, QIcon::On);
            StandardPixmapItem* selectedItem = new StandardPixmapItem(QStyle::StandardPixmap(i), QStyle::PM_LargeIconSize, QIcon::Selected, QIcon::On);
            layout->addWidget(normalItem, row, 1);
            layout->addWidget(activeItem, row, 2);
            layout->addWidget(disabledItem, row, 3);
            layout->addWidget(selectedItem, row, 4);
            ++row;
        }
        setWidget(view);
    }
protected:
private:
    QString getIconName(QStyle::StandardPixmap pixmap) {
        switch (pixmap)
        {
        case QStyle::SP_TitleBarMenuButton: return QLatin1String("SP_TitleBarMenuButton");
        case QStyle::SP_TitleBarMinButton: return QLatin1String("SP_TitleBarMinButton");
        case QStyle::SP_TitleBarMaxButton: return QLatin1String("SP_TitleBarMaxButton");
        case QStyle::SP_TitleBarCloseButton: return QLatin1String("SP_TitleBarCloseButton");
        case QStyle::SP_TitleBarNormalButton: return QLatin1String("SP_TitleBarNormalButton");
        case QStyle::SP_TitleBarShadeButton: return QLatin1String("SP_TitleBarShadeButton");
        case QStyle::SP_TitleBarUnshadeButton: return QLatin1String("SP_TitleBarUnshadeButton");
        case QStyle::SP_TitleBarContextHelpButton: return QLatin1String("SP_TitleBarContextHelpButton");
        case QStyle::SP_DockWidgetCloseButton: return QLatin1String("SP_DockWidgetCloseButton");
        case QStyle::SP_MessageBoxInformation: return QLatin1String("SP_MessageBoxInformation");
        case QStyle::SP_MessageBoxWarning: return QLatin1String("SP_MessageBoxWarning");
        case QStyle::SP_MessageBoxCritical: return QLatin1String("SP_MessageBoxCritical");
        case QStyle::SP_MessageBoxQuestion: return QLatin1String("SP_MessageBoxQuestion");
        case QStyle::SP_DesktopIcon: return QLatin1String("SP_DesktopIcon");
        case QStyle::SP_TrashIcon: return QLatin1String("SP_TrashIcon");
        case QStyle::SP_ComputerIcon: return QLatin1String("SP_ComputerIcon");
        case QStyle::SP_DriveFDIcon: return QLatin1String("SP_DriveFDIcon");
        case QStyle::SP_DriveHDIcon: return QLatin1String("SP_DriveHDIcon");
        case QStyle::SP_DriveCDIcon: return QLatin1String("SP_DriveCDIcon");
        case QStyle::SP_DriveDVDIcon: return QLatin1String("SP_DriveDVDIcon");
        case QStyle::SP_DriveNetIcon: return QLatin1String("SP_DriveNetIcon");
        case QStyle::SP_DirOpenIcon: return QLatin1String("SP_DirOpenIcon");
        case QStyle::SP_DirClosedIcon: return QLatin1String("SP_DirClosedIcon");
        case QStyle::SP_DirLinkIcon: return QLatin1String("SP_DirLinkIcon");
        case QStyle::SP_DirLinkOpenIcon: return QLatin1String("SP_DirLinkOpenIcon");
        case QStyle::SP_FileIcon: return QLatin1String("SP_FileIcon");
        case QStyle::SP_FileLinkIcon: return QLatin1String("SP_FileLinkIcon");
        case QStyle::SP_ToolBarHorizontalExtensionButton: return QLatin1String("SP_ToolBarHorizontalExtensionButton");
        case QStyle::SP_ToolBarVerticalExtensionButton: return QLatin1String("SP_ToolBarVerticalExtensionButton");
        case QStyle::SP_FileDialogStart: return QLatin1String("SP_FileDialogStart");
        case QStyle::SP_FileDialogEnd: return QLatin1String("SP_FileDialogEnd");
        case QStyle::SP_FileDialogToParent: return QLatin1String("SP_FileDialogToParent");
        case QStyle::SP_FileDialogNewFolder: return QLatin1String("SP_FileDialogNewFolder");
        case QStyle::SP_FileDialogDetailedView: return QLatin1String("SP_FileDialogDetailedView");
        case QStyle::SP_FileDialogInfoView: return QLatin1String("SP_FileDialogInfoView");
        case QStyle::SP_FileDialogContentsView: return QLatin1String("SP_FileDialogContentsView");
        case QStyle::SP_FileDialogListView: return QLatin1String("SP_FileDialogListView");
        case QStyle::SP_FileDialogBack: return QLatin1String("SP_FileDialogBack");
        case QStyle::SP_DirIcon: return QLatin1String("SP_DirIcon");
        case QStyle::SP_DialogOkButton: return QLatin1String("SP_DialogOkButton");
        case QStyle::SP_DialogCancelButton: return QLatin1String("SP_DialogCancelButton");
        case QStyle::SP_DialogHelpButton: return QLatin1String("SP_DialogHelpButton");
        case QStyle::SP_DialogOpenButton: return QLatin1String("SP_DialogOpenButton");
        case QStyle::SP_DialogSaveButton: return QLatin1String("SP_DialogSaveButton");
        case QStyle::SP_DialogCloseButton: return QLatin1String("SP_DialogCloseButton");
        case QStyle::SP_DialogApplyButton: return QLatin1String("SP_DialogApplyButton");
        case QStyle::SP_DialogResetButton: return QLatin1String("SP_DialogResetButton");
        case QStyle::SP_DialogDiscardButton: return QLatin1String("SP_DialogDiscardButton");
        case QStyle::SP_DialogYesButton: return QLatin1String("SP_DialogYesButton");
        case QStyle::SP_DialogNoButton: return QLatin1String("SP_DialogNoButton");
        case QStyle::SP_ArrowUp: return QLatin1String("SP_ArrowUp");
        case QStyle::SP_ArrowDown: return QLatin1String("SP_ArrowDown");
        case QStyle::SP_ArrowLeft: return QLatin1String("SP_ArrowLeft");
        case QStyle::SP_ArrowRight: return QLatin1String("SP_ArrowRight");
        case QStyle::SP_ArrowBack: return QLatin1String("SP_ArrowBack");
        case QStyle::SP_ArrowForward: return QLatin1String("SP_ArrowForward");
        case QStyle::SP_DirHomeIcon: return QLatin1String("SP_DirHomeIcon");
        case QStyle::SP_CommandLink: return QLatin1String("SP_CommandLink");
        case QStyle::SP_VistaShield: return QLatin1String("SP_VistaShield");
        case QStyle::SP_BrowserReload: return QLatin1String("SP_BrowserReload");
        case QStyle::SP_BrowserStop: return QLatin1String("SP_BrowserStop");
        case QStyle::SP_MediaPlay: return QLatin1String("SP_MediaPlay");
        case QStyle::SP_MediaStop: return QLatin1String("SP_MediaStop");
        case QStyle::SP_MediaPause: return QLatin1String("SP_MediaPause");
        case QStyle::SP_MediaSkipForward: return QLatin1String("SP_MediaSkipForward");
        case QStyle::SP_MediaSkipBackward: return QLatin1String("SP_MediaSkipBackward");
        case QStyle::SP_MediaSeekForward: return QLatin1String("SP_MediaSeekForward");
        case QStyle::SP_MediaSeekBackward: return QLatin1String("SP_MediaSeekBackward");
        case QStyle::SP_MediaVolume: return QLatin1String("SP_MediaVolume");
        case QStyle::SP_MediaVolumeMuted: return QLatin1String("SP_MediaVolumeMuted");
        case QStyle::SP_LineEditClearButton: return QLatin1String("SP_LineEditClearButton");
#if (QT_VERSION > QT_VERSION_CHECK(5, 15, 0))
        case QStyle::SP_DialogYesToAllButton: return QLatin1String("SP_DialogYesToAllButton");
        case QStyle::SP_DialogNoToAllButton: return QLatin1String("SP_DialogNoToAllButton");
        case QStyle::SP_DialogSaveAllButton: return QLatin1String("SP_DialogSaveAllButton");
        case QStyle::SP_DialogAbortButton: return QLatin1String("SP_DialogAbortButton");
        case QStyle::SP_DialogRetryButton: return QLatin1String("SP_DialogRetryButton");
        case QStyle::SP_DialogIgnoreButton: return QLatin1String("SP_DialogIgnoreButton");
        case QStyle::SP_RestoreDefaultsButton: return QLatin1String("SP_RestoreDefaultsButton");
#endif
#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
        case QStyle::SP_TabCloseButton: return QLatin1String("SP_TabCloseButton");
#endif
        default:
            Q_ASSERT(false);
            break;
        }
        return QString();
    }
};

class QPushButtonEx : public QPushButton
{
public:
    QPushButtonEx() : QPushButton() {

    }
protected:
    void moveEvent(QMoveEvent* e) override
    {
        QPushButton::moveEvent(e);
    }
};;

class PushButtonForm : public QWidget
{
public:
    PushButtonForm(QWidget* parent = Q_NULL) : QWidget(parent) {
        QVBoxLayout* l = new QVBoxLayout(this);
        QPushButton* button1 = new QPushButtonEx();
        button1->setText("Text button 1");
        l->addWidget(button1);
        button1->setDefault(true);
#if 1
        QPushButton* button2 = new QPushButtonEx();
        button2->setText("Text button 2");
        l->addWidget(button2);

        QPushButton* button3 = new QPushButton();
        button3->setText("Text button 3");
        l->addWidget(button3);
        button3->setEnabled(false);

        QPushButton* button4 = new QPushButton();
        button4->setText("Text button 4");
        QMenu* m = new QMenu();
        m->addAction("Click Me");
        button4->setMenu(m);
        //button4->setDefault(true);
        l->addWidget(button4);

        QCommandLinkButton* button5 = new QCommandLinkButton();
        button5->setText("Text button 5");
        button5->setDescription("Text button 5 Description");
        l->addWidget(button5);
#endif
        l->addStretch(1);
    }
protected:
    void resizeEvent(QResizeEvent* event) override {
        QWidget::resizeEvent(event);
    }
};

class CheckBoxForm : public QWidget
{
public:
    CheckBoxForm(QWidget* parent = Q_NULL) : QWidget(parent) {
        QVBoxLayout* l = new QVBoxLayout(this);

        QCheckBox* check1 = new QCheckBox();
        check1->setText("Check box text 1");
        l->addWidget(check1);
        //check1->setDefault(true);
#if 1
        QCheckBox* check2 = new QCheckBox();
        check2->setText("Check box text 2");
        check2->setTristate(true);
        l->addWidget(check2);

        QCheckBox* check3 = new QCheckBox();
        check3->setText("Check box text 3");
        check3->setChecked(true);
        check3->setEnabled(false);
        l->addWidget(check3);

        QCheckBox* check4 = new QCheckBox();
        check4->setText("Check box text 4");
        check4->setTristate(true);
        check4->setCheckState(Qt::PartiallyChecked);
        check4->setEnabled(false);
        /*QMenu* m = new QMenu();
        m->addAction("Click Me");
        check4->setMenu(m);*/
        l->addWidget(check4);
#endif
        l->addStretch(1);
    }
protected:
};

class RadioButtonForm : public QWidget
{
public:
    RadioButtonForm(QWidget* parent = Q_NULL) : QWidget(parent) {
        QVBoxLayout* l = new QVBoxLayout(this);

        QRadioButton* button1 = new QRadioButton();
        button1->setText("Radio Button 1");
        l->addWidget(button1);
        //check1->setDefault(true);
#if 1
        QRadioButton* button2 = new QRadioButton();
        button2->setText("Radio Button 2");
        l->addWidget(button2);

        QRadioButton* button3 = new QRadioButton();
        button3->setText("Radio Button 3");
        button3->setAutoExclusive(false);
        button3->setChecked(true);
        button3->setEnabled(false);
        l->addWidget(button3);

        QRadioButton* button4 = new QRadioButton();
        button4->setText("Radio Button 4");
        button4->setAutoExclusive(false);
        button4->setEnabled(false);
        l->addWidget(button4);
#endif
        l->addStretch(1);
    }
protected:
};

class ToggleSwitchForm : public QWidget
{
public:
    ToggleSwitchForm(QWidget* parent = Q_NULL) : QWidget(parent) {
        QVBoxLayout* l = new QVBoxLayout(this);

        ToggleSwitch* switch1 = new ToggleSwitch();
        switch1->setText("Toggle Switch 1");
        l->addWidget(switch1);
        //check1->setDefault(true);
#if 1
        ToggleSwitch* switch2 = new ToggleSwitch();
        switch2->setText("Toggle Switch 2");
        switch2->setTextAlignment(Qt::AlignRight);
        l->addWidget(switch2);

        ToggleSwitch* switch3 = new ToggleSwitch();
        switch3->setText("Toggle Switch 3");
        switch3->setAutoExclusive(false);
        switch3->setOn(true);
        switch3->setEnabled(false);
        l->addWidget(switch3);

        ToggleSwitch* switch4 = new ToggleSwitch();
        switch4->setText("Toggle Switch 4");
        switch4->setAutoExclusive(false);
        switch4->setOn(false);
        switch4->setEnabled(false);
        switch4->setTextAlignment(Qt::AlignRight);
        l->addWidget(switch4);
#endif
        l->addStretch(1);
    }
protected:
};

QSize StyleWindow::sizeHint() const
{
    return m_forms->sizeHint();
}

QWidget* StyleWindow::createPaletteForm()
{
    return new PaletteForm();
}

QWidget* StyleWindow::createIconForm()
{
    return new StandardIconForm();
}

QWidget* StyleWindow::createPushButtonForm()
{
    return new PushButtonForm();
}

QWidget* StyleWindow::createCheckBoxForm()
{
    return new CheckBoxForm();
}

QWidget* StyleWindow::createRadioButtonForm()
{
    return new RadioButtonForm();
}

QWidget* StyleWindow::createToggleSwitchForm()
{
    return new ToggleSwitchForm();
}