Files
o3de/Code/Framework/AzQtComponents/AzQtComponents/Gallery/BreadCrumbsPage.cpp
T
Steve Pham 38261d0800 Shorten copyright headers by splitting into 2 lines (#2213)
* Updated all copyright headers to split the longer original copyright line into 2 shorter lines

Signed-off-by: Steve Pham <spham@amazon.com>
2021-07-16 15:25:48 -07:00

107 lines
3.1 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "BreadCrumbsPage.h"
#include <AzQtComponents/Gallery/ui_BreadCrumbsPage.h>
#include <QDebug>
#include <QStyle>
#include <QToolButton>
#include <QToolBar>
#include <QPushButton>
#include <QFileDialog>
#include <AzQtComponents/Components/Widgets/BreadCrumbs.h>
BreadCrumbsPage::BreadCrumbsPage(QWidget* parent)
: QWidget(parent)
, ui(new Ui::BreadCrumbsPage)
{
ui->setupUi(this);
AzQtComponents::BreadCrumbs* breadCrumbs = new AzQtComponents::BreadCrumbs(this);
// Seed the bread crumbs with an arbitrary path, to make the example obvious
breadCrumbs->pushPath("C:/Documents/SubDirectory1/SubDirectory2/SubDirectory3");
// Have the bread crumb widget create the right buttons for us and we just lay them out
ui->horizontalLayout->addWidget(breadCrumbs->createBackForwardToolBar());
ui->horizontalLayout->addWidget(breadCrumbs->createSeparator());
ui->horizontalLayout->addWidget(breadCrumbs);
ui->horizontalLayout->addWidget(breadCrumbs->createSeparator());
auto browseButton = breadCrumbs->createButton(AzQtComponents::NavigationButton::Browse);
ui->horizontalLayout->addWidget(browseButton);
connect(browseButton, &QPushButton::pressed, breadCrumbs, [breadCrumbs] {
QString newPath = QFileDialog::getExistingDirectory(breadCrumbs, "Please select a new path to push into the bread crumbs");
if (!newPath.isEmpty())
{
breadCrumbs->pushPath(newPath);
}
});
connect(breadCrumbs, &AzQtComponents::BreadCrumbs::pathChanged, this, [](const QString& newPath) {
qDebug() << QString("New path: %1").arg(newPath);
});
QString exampleText = R"(
The BreadCrumbs widget can be used to show paths, and provide functionality to click on pieces of the path and jump to them.<br/><br/>
Some sample code:<br/><br/>
<pre>
#include &lt;AzQtComponents/Components/Widgets/BreadCrumbs.h&gt;
// Create a new BreadCrumbs widget:
AzQtComponents::BreadCrumbs* breadCrumbs = new AzQtComponents::BreadCrumbs(this);
// To set the initial path or jump to another
QString somePath = "C:\\Documents";
breadCrumbs->pushPath(somePath);
// To navigate:
breadCrumbs->back();
breadCrumbs->forward();
// Listen for path changes
connect(breadCrumbs, &AzQtComponents::BreadCrumbs::pathChanged, this, [](const QString& newPath){
// Handle path change
});
// To get the current path:
QString currentPath = breadCrumbs->currentPath();
// Create auto-connected navigation buttons and layout everything in a group widget:
QWidget* group = new QWidget(this);
QHBoxLayout* groupLayout = new QHBoxLayout(group);
AzQtComponents::BreadCrumbs* breadCrumbs = new AzQtComponents::BreadCrumbs(group);
layout->addWidget(breadCrumbs->createBackForwardToolBar());
layout->addWidget(breadCrumbs);
</pre>
)";
ui->exampleText->setHtml(exampleText);
}
BreadCrumbsPage::~BreadCrumbsPage()
{
}
#include "Gallery/moc_BreadCrumbsPage.cpp"