DocumentDemo Example

#include <QLabel>
#include <QHeaderView>
#include <QListWidget>
#include <QToolButton>
#include "viewpanels.h"

static QIcon getIconToolBox(const QPixmap& pixmap, int index)
{
    QRect rcImage(index * 16, 0, 16, 16);
    QImage copyImage = pixmap.copy(rcImage.left(), rcImage.top(), 16, 16).toImage();
    copyImage.setAlphaChannel(copyImage.createMaskFromColor(QColor(0, 255, 0).rgb(), Qt::MaskOutColor));
    return QIcon(QPixmap::fromImage(copyImage));
}

/* DockWidgetPanelCreator */
DockWidgetPanelCreator::DockWidgetPanelCreator(const QString& caption, DockMainWindow* parent)
    : QObject(parent)
{
    m_dockWidgetPanel = new DockWidgetPanel(caption, parent->dockPanelManager());
}

DockWidgetPanelCreator::~DockWidgetPanelCreator()
{
}

/* FileViewPanelCreator */
FileViewPanelCreator::FileViewPanelCreator(DockMainWindow* parent)
    : DockWidgetPanelCreator(tr("Solution Explorer"), parent)
    , baseLayoutWidget(Q_NULL)
    , baseLayout(Q_NULL)
{
    baseLayoutWidget = new QWidget();
    baseLayout = new QVBoxLayout;
    baseLayout->setContentsMargins(0, 0, 0, 0);
    baseLayout->setSpacing(0);
    baseLayoutWidget->setFocusPolicy(Qt::NoFocus);
    baseLayoutWidget->setLayout(baseLayout);
    m_dockWidgetPanel->setWidget(baseLayoutWidget);
    fillToolBar();
    fillFileView();
}

FileViewPanelCreator::~FileViewPanelCreator()
{
}

void FileViewPanelCreator::fillToolBar()
{
/*
    DockToolBar* viewToolBar = new DockToolBar(m_dockWidgetPanel);
    viewToolBar->setFocusPolicy(Qt::NoFocus);
    QAction* act = viewToolBar->addAction(QIcon(QStringLiteral(":/res/newfile16x16.png")), tr("Properties"));
    act->setToolTip(tr("Show Properties"));
    baseLayout->addWidget(viewToolBar);
*/
}

void FileViewPanelCreator::fillFileView()
{
    QTreeWidget* treeWidget = new QTreeWidget;
    treeWidget->setFrameShape(QFrame::NoFrame);
    baseLayoutWidget->setFocusProxy(treeWidget);
    treeWidget->setFocusPolicy(Qt::StrongFocus);
    treeWidget->setAlternatingRowColors(false);

    treeWidget->setMinimumWidth(190);
    treeWidget->setHeaderHidden(true);

    QStringList strings;
    strings.append(tr("Solution 'qtitandocking'"));
    QTreeWidgetItem* mainItem = new QTreeWidgetItem(strings);
    mainItem->setExpanded(true);
    mainItem->setIcon(0, QIcon(QStringLiteral(":/res/solution.svg")));
    treeWidget->insertTopLevelItem(0, mainItem);
    treeWidget->expandItem(mainItem);

    strings.clear();
    strings.append(tr("DockApplication"));
    QTreeWidgetItem* itemAppl = new QTreeWidgetItem(mainItem, strings);
    QFont font = itemAppl->font(0);
    font.setBold(true);
    itemAppl->setFont(0, font);
    itemAppl->setIcon(0, QIcon(QStringLiteral(":/res/cpp_project.png")));
    itemAppl->setExpanded(true);
    treeWidget->insertTopLevelItem(1, itemAppl);
    treeWidget->expandItem(itemAppl);

    ////////////////////////////////////////////////////////////////////
    strings.clear();
    strings.append(tr("Source Files"));
    QTreeWidgetItem* itemSource = new QTreeWidgetItem(itemAppl, strings);
    itemSource->setIcon(0, QIcon(QStringLiteral(":/res/filterfolderOpen.png")));
    itemSource->setExpanded(true);
    treeWidget->insertTopLevelItem(1, itemSource);
    treeWidget->expandItem(itemAppl);

    strings.clear();
    strings.append(tr("main.cpp"));
    QTreeWidgetItem* item = new QTreeWidgetItem(itemSource, strings);
    item->setIcon(0, QIcon(QStringLiteral(":/res/cpp.png")));
    treeWidget->insertTopLevelItem(1, item);
    treeWidget->expandItem(item);

    strings.clear();
    strings.append(tr("mainwindow.cpp"));
    item = new QTreeWidgetItem(itemSource, strings);
    item->setIcon(0, QIcon(QStringLiteral(":/res/cpp.png")));
    treeWidget->insertTopLevelItem(1, item);
    treeWidget->expandItem(item);

    strings.clear();
    strings.append(tr("mdichild.cpp"));
    item = new QTreeWidgetItem(itemSource, strings);
    item->setIcon(0, QIcon(QStringLiteral(":/res/cpp.png")));
    treeWidget->insertTopLevelItem(1, item);
    treeWidget->expandItem(item);

    strings.clear();
    strings.append(tr("fileviewpanel.cpp"));
    item = new QTreeWidgetItem(itemSource, strings);
    item->setIcon(0, QIcon(QStringLiteral(":/res/cpp.png")));
    treeWidget->insertTopLevelItem(1, item);
    treeWidget->expandItem(item);

    ////////////////////////////////////////////////////////////////////
    strings.clear();
    strings.append(tr("Header Files"));
    QTreeWidgetItem* itemHeader = new QTreeWidgetItem(itemAppl, strings);
    itemHeader->setIcon(0, QIcon(QStringLiteral(":/res/filterfolderOpen.png")));
    itemHeader->setExpanded(true);
    treeWidget->insertTopLevelItem(1, itemHeader);
    treeWidget->expandItem(itemAppl);

    strings.clear();
    strings.append(tr("mainwindow.h"));
    item = new QTreeWidgetItem(itemHeader, strings);
    item->setIcon(0, QIcon(QStringLiteral(":/res/header.png")));
    treeWidget->insertTopLevelItem(1, item);
    treeWidget->expandItem(item);

    strings.clear();
    strings.append(tr("mdichild.h"));
    item = new QTreeWidgetItem(itemHeader, strings);
    item->setIcon(0, QIcon(QStringLiteral(":/res/header.png")));
    treeWidget->insertTopLevelItem(1, item);
    treeWidget->expandItem(item);

    strings.clear();
    strings.append(tr("fileviewpanel.h"));
    item = new QTreeWidgetItem(itemHeader, strings);
    item->setIcon(0, QIcon(QStringLiteral(":/res/header.png")));
    treeWidget->insertTopLevelItem(1, item);
    treeWidget->expandItem(item);

    ////////////////////////////////////////////////////////////////////
    strings.clear();
    strings.append(tr("Resource Files"));
    QTreeWidgetItem* itemResource = new QTreeWidgetItem(itemAppl, strings);
    itemResource->setIcon(0, QIcon(QStringLiteral(":/res/filterfolderOpen.png")));
    itemResource->setExpanded(true);
    treeWidget->insertTopLevelItem(1, itemResource);
    treeWidget->expandItem(itemAppl);

    strings.clear();
    strings.append(tr("documentdemo.qrc"));
    item = new QTreeWidgetItem(itemResource, strings);
    item->setIcon(0, QIcon(QStringLiteral(":/res/header.png")));
    treeWidget->insertTopLevelItem(1, item);
    treeWidget->expandItem(item);

    baseLayout->addWidget(treeWidget, 1);
}

/* ClassViewPanelCreator */
ClassViewPanelCreator::ClassViewPanelCreator(DockMainWindow* parent)
    : DockWidgetPanelCreator(tr("Class View"), parent)
{
    baseLayoutWidget = new QWidget();
    baseLayout = new QVBoxLayout;
    baseLayout->setContentsMargins(0, 0, 0, 0);
    baseLayout->setSpacing(0);
    baseLayoutWidget->setFocusPolicy(Qt::NoFocus);
    baseLayoutWidget->setLayout(baseLayout);
    m_dockWidgetPanel->setWidget(baseLayoutWidget);
    fillToolBar();
    fillClassView();
}

ClassViewPanelCreator::~ClassViewPanelCreator()
{
}

void ClassViewPanelCreator::fillToolBar()
{
    DockToolBar* viewToolBar = new DockToolBar(m_dockWidgetPanel);
    viewToolBar->setFocusPolicy(Qt::NoFocus);
    QAction* act = viewToolBar->addAction(QIcon(QStringLiteral(":/res/newfolder16x16.png")), tr("Class View New Folder"));
    act->setToolTip(tr("Class View New Folder"));
    viewToolBar->addSeparator();
    act = viewToolBar->addAction(QIcon(QStringLiteral(":/res/backward16x16.png")), tr("Back"));
    act->setToolTip(tr("Back"));
    act = viewToolBar->addAction(QIcon(QStringLiteral(":/res/forward16x16.png")), tr("Forward"));
    act->setToolTip(tr("Forward"));
    viewToolBar->addSeparator();

    QMenu* menu = new QMenu(viewToolBar);
    act = menu->addAction(tr("Show Base Types"));
    act->setCheckable(true); act->setChecked(true);
    act = menu->addAction(tr("Show Derived Types"));
    act->setCheckable(true); act->setChecked(true);
    menu->addSeparator();
    act = menu->addAction(tr("Show Project References"));
    act->setCheckable(true); act->setChecked(true);
    act = menu->addAction(tr("Show Hidden Types And Members"));
    act->setCheckable(true); act->setChecked(true);
    menu->addSeparator();
    act = menu->addAction(tr("Show Public Members"));
    act->setCheckable(true); act->setChecked(true);
    act = menu->addAction(tr("Show Protected Members"));
    act->setCheckable(true); act->setChecked(true);
    act = menu->addAction(tr("Show Private Members"));
    act->setCheckable(true); act->setChecked(true);
    act = menu->addAction(tr("Show Other Members"));
    act->setCheckable(true); act->setChecked(true);
    menu->addSeparator();
    act = menu->addAction(tr("Show Inherited Members"));
    act->setCheckable(true); act->setChecked(true);

    act = viewToolBar->addAction(QIcon(QStringLiteral(":/res/settings16x16.png")), tr("Class View Settings"));
    act->setToolTip(tr("Class View Settings"));
    act->setMenu(menu);

    QToolButton* button = qobject_cast<QToolButton*>(viewToolBar->widgetForAction(act));
    button->setPopupMode(QToolButton::MenuButtonPopup);

    baseLayout->addWidget(viewToolBar);
}

void ClassViewPanelCreator::fillClassView()
{
    QTreeWidget* treeWidget = new QTreeWidget;
    treeWidget->setFrameShape(QFrame::NoFrame);
    baseLayoutWidget->setFocusProxy(treeWidget);
    treeWidget->setFocusPolicy(Qt::StrongFocus);
    treeWidget->setAlternatingRowColors(false);

    treeWidget->setMinimumWidth(190);
    treeWidget->setHeaderHidden(true);

    QStringList strings;
    strings.append(tr("Docking_DocumentDemo"));
    QTreeWidgetItem* projectItem = new QTreeWidgetItem(strings);
    projectItem->setExpanded(true);
    QFont font = projectItem->font(0);
    font.setBold(true);
    projectItem->setFont(0, font);
    projectItem->setIcon(0, QIcon(QStringLiteral(":/res/cpp_projectnode16x16.png")));
    treeWidget->insertTopLevelItem(0, projectItem);
    treeWidget->expandItem(projectItem);

    strings.clear();
    strings.append(tr("Global Functions and Variables"));
    QTreeWidgetItem* itemSource = new QTreeWidgetItem(projectItem, strings);
    itemSource->setIcon(0, QIcon(QStringLiteral(":/res/method16x16.png")));
    itemSource->setExpanded(true);
    treeWidget->insertTopLevelItem(1, itemSource);

    strings.clear();
    strings.append(tr("Macros and Constants"));
    itemSource = new QTreeWidgetItem(projectItem, strings);
    itemSource->setIcon(0, QIcon(QStringLiteral(":/res/action16x16.png")));
    itemSource->setExpanded(true);
    treeWidget->insertTopLevelItem(1, itemSource);

    creatNodeView(tr("AboutDialog"), projectItem, treeWidget);
    creatNodeView(tr("ClassViewPanelCreator"), projectItem, treeWidget);
    creatNodeView(tr("DemoDockWindow"), projectItem, treeWidget);
    creatNodeView(tr("DockWidgetPanelCreator"), projectItem, treeWidget);
    creatNodeView(tr("FileViewPanelCreator"), projectItem, treeWidget);
    creatNodeView(tr("MainWindow"), projectItem, treeWidget);
    creatNodeView(tr("MdiChild"), projectItem, treeWidget);
    creatNodeView(tr("OutputListPanelCreator"), projectItem, treeWidget);
    creatNodeView(tr("QTextDocument"), projectItem, treeWidget);
    creatNodeView(tr("TitleBarCaption"), projectItem, treeWidget);

    baseLayout->addWidget(treeWidget);
}

void ClassViewPanelCreator::creatNodeView(const QString& str, QTreeWidgetItem* parentItem, QTreeWidget* treeWidget)
{
    QStringList strings;
    strings.append(str);
    QTreeWidgetItem* itemSource = new QTreeWidgetItem(parentItem, strings);
    itemSource->setIcon(0, QIcon(QStringLiteral(":/res/class16x16.png")));
    treeWidget->insertTopLevelItem(1, itemSource);
    strings.clear();
    strings.append(tr("Base Types"));
    itemSource = new QTreeWidgetItem(itemSource, strings);
    itemSource->setIcon(0, QIcon(QStringLiteral(":/res/projectfolderopen16x16.png")));
    treeWidget->insertTopLevelItem(1, itemSource);
}

/* ResourceViewPanelCreator */
ResourceViewPanelCreator::ResourceViewPanelCreator(DockMainWindow* parent)
    : DockWidgetPanelCreator(tr("Resource View"), parent)
{
    baseLayoutWidget = new QWidget();
    baseLayout = new QVBoxLayout;
    baseLayout->setContentsMargins(0, 0, 0, 0);
    baseLayout->setSpacing(0);
    baseLayoutWidget->setFocusPolicy(Qt::NoFocus);
    baseLayoutWidget->setLayout(baseLayout);
    m_dockWidgetPanel->setWidget(baseLayoutWidget);
    fillResourceView();
}

ResourceViewPanelCreator::~ResourceViewPanelCreator()
{
}

void ResourceViewPanelCreator::fillResourceView()
{
    QTreeWidget* treeWidget = new QTreeWidget;
    treeWidget->setFrameShape(QFrame::NoFrame);
    baseLayoutWidget->setFocusProxy(treeWidget);
    treeWidget->setFocusPolicy(Qt::StrongFocus);
    treeWidget->setAlternatingRowColors(false);

    treeWidget->setMinimumWidth(190);
    treeWidget->setHeaderHidden(true);

    QStringList strings;
    strings.append(tr("Docking_DocumentDemo"));
    QTreeWidgetItem* item = new QTreeWidgetItem(strings);
    item->setIcon(0, QIcon(QStringLiteral(":/res/cpp_project.png")));
    treeWidget->insertTopLevelItem(0, item);

    strings.clear();
    strings.append(tr("Docking_DynamicPanels"));
    item = new QTreeWidgetItem(strings);
    item->setIcon(0, QIcon(QStringLiteral(":/res/cpp_project.png")));
    treeWidget->insertTopLevelItem(0, item);

    strings.clear();
    strings.append(tr("Docking_MDIWindowDemo"));
    item = new QTreeWidgetItem(strings);
    item->setIcon(0, QIcon(QStringLiteral(":/res/cpp_project.png")));
    treeWidget->insertTopLevelItem(0, item);

    strings.clear();
    strings.append(tr("Docking_SimplePanels"));
    item = new QTreeWidgetItem(strings);
    item->setIcon(0, QIcon(QStringLiteral(":/res/cpp_project.png")));
    treeWidget->insertTopLevelItem(0, item);

    baseLayout->addWidget(treeWidget);
}

/* OutputListPanelCreator */
OutputListPanelCreator::OutputListPanelCreator(DockMainWindow* parent)
    : DockWidgetPanelCreator(tr("Output"), parent)
{
    QLabel* baseOutput = new QLabel(m_dockWidgetPanel);
    baseOutput->setAutoFillBackground(true);
    QPalette palette = baseOutput->palette();
    palette.setColor(baseOutput->backgroundRole(), palette.color(QPalette::Base));
    baseOutput->setPalette(palette);

    baseOutput->setAlignment(Qt::AlignTop | Qt::AlignLeft);
    baseOutput->setText(tr("The program '[13056] Docking_DocumentDemod.exe' has exited with code 0 (0x0)."));
    m_dockWidgetPanel->setWidget(baseOutput);
}

OutputListPanelCreator::~OutputListPanelCreator()
{
}

/* WatchPanelCreator */
WatchPanelCreator::WatchPanelCreator(DockMainWindow* parent)
    : DockWidgetPanelCreator(tr("Watch"), parent)
{
    m_watchList = new QTableWidget(m_dockWidgetPanel);
    m_dockWidgetPanel->setWidget(m_watchList);

    m_watchList->setColumnCount(3);
    m_watchList->setRowCount(6);
    m_watchList->setShowGrid(true);
    m_watchList->setWordWrap(true);
    QHeaderView* vHeader = m_watchList->verticalHeader();
    vHeader->setVisible(false);

    m_watchList->setShowGrid(false);
    m_watchList->setSelectionBehavior(QAbstractItemView::SelectRows);
    m_watchList->setEditTriggers(QAbstractItemView::NoEditTriggers);
    m_watchList->setSelectionMode(QAbstractItemView::SingleSelection);
    m_watchList->horizontalHeader()->setStretchLastSection(true);

    m_watchList->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Variable")));
    m_watchList->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Value")));
    m_watchList->setHorizontalHeaderItem(2, new QTableWidgetItem(tr("Type")));

    int height = m_watchList->horizontalHeader()->sizeHint().height();
    m_watchList->setRowHeight(0, height);
    m_watchList->setItem(0, 0, new QTableWidgetItem(tr("m_size")));
    m_watchList->setItem(0, 1, new QTableWidgetItem(tr("120")));

    m_watchList->setItem(1, 0, new QTableWidgetItem(tr("strName")));
    m_watchList->setItem(1, 1, new QTableWidgetItem(tr("\"John\"")));
}

WatchPanelCreator::~WatchPanelCreator()
{
}

/* WatchPanel */
ToolBoxPanelCreator::ToolBoxPanelCreator(DockMainWindow* parent)
    : DockWidgetPanelCreator(tr("ToolBox"), parent)
{
    m_toolBox = new QTreeWidget();
    m_toolBox->setFrameShape(QFrame::NoFrame);
    m_toolBox->setHeaderHidden(true);
    m_dockWidgetPanel->setWidget(m_toolBox);

    ///////////////////////////////////////////////////////////////////////
    QPixmap pixmap1(QStringLiteral(":/res/toolbox1.png"));

    QStringList strings;
    strings.append(tr("Windows Forms"));
    QTreeWidgetItem* formItem = new QTreeWidgetItem(strings);
    m_toolBox->insertTopLevelItem(0, formItem);
    m_toolBox->expandItem(formItem);

    QString sourceForms = tr("Pointer\nLabel\nButton\nText Box\nMain Menu\nCheck Box\nRadio Button\nGroup Box\nPicture Box\nPanel\nData Grid\nList Box\nChecked List Box\nCombo Box\nList View\nTree View\nTab Control\nDate Time Picker\nMonth Calendar\nHorizontal Scroll Bar\nVertical Scroll Bar\nTimer\nSplitter\nDomain UpDown\nNumeric UpDown\nTrack Bar\nProgress Bar\nRich Text Box");
    QStringList lstForms = sourceForms.split(QLatin1Char('\n'));
    int index = 0;
    for (QStringList::const_iterator it = lstForms.constBegin(); it != lstForms.constEnd(); ++it)
    {
        strings.clear();
        strings.append((*it));
        QTreeWidgetItem* item = new QTreeWidgetItem(formItem, strings);
        item->setIcon(0, getIconToolBox(pixmap1, index));
        m_toolBox->insertTopLevelItem(1, item);
        index++;
    }
    ///////////////////////////////////////////////////////////////////////
    QPixmap pixmap2(QStringLiteral(":/res/toolbox2.png"));

    strings.clear();
    strings.append(tr("Components"));
    QTreeWidgetItem* componentsItem = new QTreeWidgetItem(strings);
    m_toolBox->insertTopLevelItem(1, componentsItem);
    m_toolBox->expandItem(componentsItem);

    QString sourceComponents = tr("Pointer\nData Set\nOleDb Data Adapter\nOleDb Connection");
    QStringList lstComponents = sourceComponents.split(QLatin1Char('\n'));
    index = 0;
    for (QStringList::const_iterator it = lstComponents.constBegin(); it != lstComponents.constEnd(); ++it)
    {
        strings.clear();
        strings.append((*it));
        QTreeWidgetItem* item = new QTreeWidgetItem(componentsItem, strings);
        item->setIcon(0, getIconToolBox(pixmap2, index));
        m_toolBox->insertTopLevelItem(1, item);
        index++;
    }
    ///////////////////////////////////////////////////////////////////////
    QPixmap pixmap3(QStringLiteral(":/res/toolbox3.png"));

    strings.clear();
    strings.append(tr("Data"));
    QTreeWidgetItem* dataItem = new QTreeWidgetItem(strings);
    m_toolBox->insertTopLevelItem(2, dataItem);
    m_toolBox->expandItem(dataItem);

    QString sourceData = tr("Pointer\nData Set\nOleDb Data Adapter\nOleDb Connection");
    QStringList lstData = sourceComponents.split(QLatin1Char('\n'));
    index = 0;
    for (QStringList::const_iterator it = lstData.constBegin(); it != lstData.constEnd(); ++it)
    {
        strings.clear();
        strings.append((*it));
        QTreeWidgetItem* item = new QTreeWidgetItem(dataItem, strings);
        item->setIcon(0, getIconToolBox(pixmap3, index));
        m_toolBox->insertTopLevelItem(1, item);
        index++;
    }
}

ToolBoxPanelCreator::~ToolBoxPanelCreator()
{
}