CommandBar Example
#include <QtGui>
#include <QMessageBox>
#include <QLabel>
#include <QDesktopServices>
#include <QVBoxLayout>
#include <QComboBox>
#include <QApplication>
#include "window.h"
Window::Window()
: NavigationMainWindow()
{
setWindowTitle(tr("NavigationBar Application"));
NavigationStatusBar* navigationStatusBar = static_cast<NavigationStatusBar *>(statusBar());
Q_UNUSED(navigationStatusBar);
navigationBar()->setOverflowMode(NavigationBar::Menu);
QAction* action = navigationBar()->addSystemButton();
connect(action, SIGNAL(triggered()), this, SLOT(systemButtonClicked()));
action = navigationBar()->addLogoButton(QIcon(QStringLiteral(":res/logo_50.png")));
NavigationToolButton* button = navigationBar()->buttonByAction(action);
button->setDescription(tr("Logo"), tr("CRM - Navigation menu example."));
connect(action, SIGNAL(triggered()), this, SLOT(showCompanyWebSite()));
navigationBar()->addSeparator();
#if 0
action = bar->addAction(NavigationBar::Home);
action->setCheckable(true);
#endif
NavigationMainMenu* mainMenu = new NavigationMainMenu(navigationBar());
action = navigationBar()->addMainMenuButton(mainMenu);
button = navigationBar()->buttonByAction(action);
button->setDescription(tr("Main"), tr("Show work areas."));
NavigationBackstageMenu* projectServiceMenu = createProjectServiceMenu();
mainMenu->addItem(QIcon(QStringLiteral(":res/tile_icon_service_85x71.png")), tr("Project Service"), QColor(0x002D74EA), projectServiceMenu);
mainMenu->addItem(QIcon(QStringLiteral(":res/tile_icon_settings_85x71.png")), tr("Settings"));
mainMenu->addItem(QIcon(QStringLiteral(":res/tile_icon_help_85x71.png")), tr("Help Center"));
action = navigationBar()->addAction(QIcon(), tr("Project Service"), static_cast<QWidget*>(projectServiceMenu));
connect(action, SIGNAL(triggered()), this, SLOT(toolButtonClicked()));
NavigationMenu* menu2 = new NavigationBackstageMenu(navigationBar());
action = navigationBar()->addAction(QIcon(), tr("Dashboards"), static_cast<QWidget*>(menu2));
connect(action, SIGNAL(triggered()), this, SLOT(toolButtonClicked()));
action = navigationBar()->addAction(NavigationBar::MRU);
connect(action, SIGNAL(triggered()), this, SLOT(toolButtonClicked()));
button = navigationBar()->buttonByAction(action);
button->setAlignment(Qt::AlignRight);
action = navigationBar()->addAction(NavigationBar::New);
connect(action, SIGNAL(triggered()), this, SLOT(toolButtonClicked()));
button = navigationBar()->buttonByAction(action);
button->setAlignment(Qt::AlignRight);
NavigationSearchWidget* searchWidget = new NavigationSearchWidget();
action = navigationBar()->addWidget(searchWidget, QPixmap(QStringLiteral(":res/users_icon_off.png")));
button = navigationBar()->buttonByAction(action);
button->setAlignment(Qt::AlignRight);
action = navigationBar()->addAction(NavigationBar::Question);
connect(action, SIGNAL(triggered()), this, SLOT(toolButtonClicked()));
action->setCheckable(true);
button = navigationBar()->buttonByAction(action);
button->setAlignment(Qt::AlignRight);
QLabel* label = new QLabel();
label->setTextFormat(Qt::RichText);
label->setText(QStringLiteral("Jim <b>Glynn</b>"));
action = navigationBar()->addWidget(label, QPixmap(QStringLiteral(":res/user_icon.png")));
connect(action, SIGNAL(triggered()), this, SLOT(toolButtonClicked()));
button = navigationBar()->buttonByAction(action);
button->setAlignment(Qt::AlignRight);
NavigationSidePane* settingsPane = new NavigationSidePane(navigationBar());
settingsPane->setWidget(new SettingsWidget(this));
action = navigationBar()->addAction(NavigationBar::Settings, QString(), settingsPane);
action->setCheckable(true);
button = navigationBar()->buttonByAction(action);
button->setAlignment(Qt::AlignRight);
button->setDescription(tr("Settings"), tr("Customize the application."));
NavigationSidePane* helpPane = new NavigationSidePane(navigationBar());
helpPane->setWidget(createHelpWidget());
action = navigationBar()->addHelpButton(helpPane);
button = navigationBar()->buttonByAction(action);
button->setDescription(tr("Help"), tr("Find help and training."));
titleBar()->setVisible(true);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
const QRect availableGeometry = screen()->availableGeometry();
#else
QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
#endif
resize(QSize(2 * availableGeometry.width() / 3, 2 * availableGeometry.height() / 3));
move(QPoint((availableGeometry.width() - width()) / 2, (availableGeometry.height() - height()) / 2));
}
NavigationBackstageMenu* Window::createProjectServiceMenu()
{
NavigationBackstageMenu* projectServiceMenu = new NavigationBackstageMenu(navigationBar());
QAction* action = projectServiceMenu->addAction(tr("My Work"), QPixmap(QStringLiteral(":res/menu_item_icon_18.png")), tr("Dashboards"), WindowsColor(WindowsColor::MetroUI_KleinBlue));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("My Work"), QPixmap(QStringLiteral(":res/menu_item_icon_2.png")), tr("Booking and Tasks"), WindowsColor(WindowsColor::MetroUI_Cardinal));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("My Work"), QPixmap(QStringLiteral(":res/menu_item_icon_1.png")), tr("Time Entries"), WindowsColor(WindowsColor::MetroUI_Chocolate));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("My Work"), QPixmap(QStringLiteral(":res/menu_item_icon_8.png")), tr("Expenses"), WindowsColor(WindowsColor::MetroUI_Chocolate));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("My Work"), QPixmap(QStringLiteral(":res/menu_item_icon_13.png")), tr("Project Approvals"), WindowsColor(WindowsColor::MetroUI_Chocolate));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Customers"), QPixmap(QStringLiteral(":res/menu_item_icon_19.png")), tr("Customers"));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Customers"), QPixmap(QStringLiteral(":res/menu_item_icon_20.png")), tr("Contacts"));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Sales"), QPixmap(QStringLiteral(":res/menu_item_icon_21.png")), tr("Leads"), WindowsColor(WindowsColor::MetroUI_NavyBlue));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Sales"), QPixmap(QStringLiteral(":res/menu_item_icon_22.png")), tr("Opportunities"), WindowsColor(WindowsColor::MetroUI_GreenHouse));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Sales"), QPixmap(QStringLiteral(":res/menu_item_icon_8.png")), tr("Quotes"), WindowsColor(WindowsColor::MetroUI_KleinBlue));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Planning and Delivery"), QPixmap(QStringLiteral(":res/menu_item_icon_23.png")), tr("Projects"), WindowsColor(WindowsColor::MetroUI_VidaLoca));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Planning and Delivery"), QPixmap(QStringLiteral(":res/menu_item_icon_23.png")), tr("Project Templates"), WindowsColor(WindowsColor::MetroUI_VidaLoca));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Planning and Delivery"), QPixmap(QStringLiteral(":res/menu_item_icon_12.png")), tr("Project Contracts"), WindowsColor(WindowsColor::MetroUI_KleinBlue));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Planning and Delivery"), QPixmap(QStringLiteral(":res/menu_item_icon_12.png")), tr("Project Contract Milestones"), WindowsColor(WindowsColor::MetroUI_VidaLoca));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Billing"), QPixmap(QStringLiteral(":res/menu_item_icon_5.png")), tr("Invoices"), WindowsColor(WindowsColor::MetroUI_Chocolate));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Billing"), QPixmap(QStringLiteral(":res/menu_item_icon_12.png")), tr("Actuals"), WindowsColor(WindowsColor::MetroUI_Chocolate));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Billing"), QPixmap(QStringLiteral(":res/menu_item_icon_10.png")), tr("Journals"), WindowsColor(WindowsColor::MetroUI_Chocolate));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Resources"), QPixmap(QStringLiteral(":res/menu_item_icon_4.png")), tr("Resource Availability"), WindowsColor(WindowsColor::MetroUI_NavyBlue));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Resources"), QPixmap(QStringLiteral(":res/menu_item_icon_4.png")), tr("Resource Utilization"), WindowsColor(WindowsColor::MetroUI_NavyBlue));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Resources"), QPixmap(QStringLiteral(":res/menu_item_icon_4.png")), tr("Resource Requests"), WindowsColor(WindowsColor::MetroUI_NavyBlue));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Resources"), QPixmap(QStringLiteral(":res/menu_item_icon_14.png")), tr("Resources"), WindowsColor(WindowsColor::MetroUI_KleinBlue));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Tools"), QPixmap(QStringLiteral(":res/menu_item_icon_24.png")), tr("Reports"), WindowsColor(WindowsColor::MetroUI_KleinBlue));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Tools"), QPixmap(QStringLiteral(":res/menu_item_icon_25.png")), tr("Data Exports"), WindowsColor(WindowsColor::MetroUI_Watercourse));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Settings"), QPixmap(QStringLiteral(":res/menu_item_icon_3.png")), tr("Organizational Utils"), WindowsColor(WindowsColor::MetroUI_Watercourse));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Settings"), QPixmap(QStringLiteral(":res/menu_item_icon_15.png")), tr("Resource Roles"), WindowsColor(WindowsColor::MetroUI_KleinBlue));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Settings"), QPixmap(QStringLiteral(":res/menu_item_icon_16.png")), tr("Resource Skills"), WindowsColor(WindowsColor::MetroUI_KleinBlue));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Settings"), QPixmap(QStringLiteral(":res/menu_item_icon_17.png")), tr("Proficiency Models"), WindowsColor(WindowsColor::MetroUI_KleinBlue));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Settings"), QPixmap(QStringLiteral(":res/menu_item_icon_7.png")), tr("Work Hours Tempates"), WindowsColor(WindowsColor::MetroUI_VidaLoca));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr("Settings"), QPixmap(QStringLiteral(":res/menu_item_icon_6.png")), tr("Parameters"), WindowsColor(WindowsColor::MetroUI_Matterhorn));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr(""), QPixmap(QStringLiteral(":res/menu_item_icon_6.png")), tr("Transaction Categories"), WindowsColor(WindowsColor::MetroUI_Matterhorn));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr(""), QPixmap(QStringLiteral(":res/menu_item_icon_6.png")), tr("Expense Categories"), WindowsColor(WindowsColor::MetroUI_Matterhorn));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr(""), QPixmap(QStringLiteral(":res/menu_item_icon_5.png")), tr("Invoice Frequencies"), WindowsColor(WindowsColor::MetroUI_Chocolate));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr(""), QPixmap(QStringLiteral(":res/menu_item_icon_11.png")), tr("Price Lists"), WindowsColor(WindowsColor::MetroUI_KleinBlue));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
action = projectServiceMenu->addAction(tr(""), QPixmap(QStringLiteral(":res/menu_item_icon_25.png")), tr("Batch Jobs"), WindowsColor(WindowsColor::MetroUI_Watercourse));
connect(action, SIGNAL(triggered()), this, SLOT(projectServiceMenuItemClicked()));
return projectServiceMenu;
}
static QString create_link(const QString& link, const QString& text)
{
QString ret = QStringLiteral("<a style=\"text-decoration:underline;\" href=\"%1\">%2</a>").arg(link).arg(text);
return ret;
}
QWidget* Window::createHelpWidget()
{
QLabel* label = new QLabel();
QString html = create_link(QStringLiteral("#"), QStringLiteral("Help Topics"));
html += QStringLiteral("<br><br>");
html += create_link(QStringLiteral("#"), QStringLiteral("Feedback"));
html += QStringLiteral("<br><br>");
html += create_link(QStringLiteral("#"), QStringLiteral("Community"));
html += QStringLiteral("<br><br>");
html += create_link(QStringLiteral("#"), QStringLiteral("Legal Information"));
html += QStringLiteral("<br><br>");
html += create_link(QStringLiteral("#"), QStringLiteral("Privacy and cookie"));
html += QStringLiteral("<br><br>");
label->setText(html);
return label;
}
void Window::paintEvent(QPaintEvent* event)
{
NavigationMainWindow::paintEvent(event);
}
void Window::systemButtonClicked()
{
QMessageBox::information(this, tr("NavigationBar"), tr("Navigation System Button clicked"));
}
void Window::toolButtonClicked()
{
QAction* action = static_cast<QAction *>(sender());
QMessageBox::information(this, tr("NavigationBar"), QString(tr("NavigationToolButton clicked: '%1'")).arg(action->text()));
}
void Window::showCompanyWebSite()
{
QDesktopServices::openUrl(QUrl(QStringLiteral("https://www.devmachines.com")));
}
void Window::projectServiceMenuItemClicked()
{
QAction* action = static_cast<QAction *>(sender());
QMessageBox::information(this, tr("NavigationBarMenu"), QString(tr("NavigationMenuItem clicked: '%1'")).arg(action->text()));
}