Move the menu bar into its own file.

This commit is contained in:
spxtr 2015-12-19 21:24:48 -08:00
parent c683b54921
commit f9f2b2fd36
6 changed files with 138 additions and 121 deletions

View File

@ -4,18 +4,19 @@ add_definitions(-DQT_USE_QSTRINGBUILDER -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_
set(CMAKE_AUTOMOC ON)
set(SRCS
Host.cpp
Main.cpp
MainWindow.cpp
Host.cpp
MenuBar.cpp
RenderWidget.cpp
Resources.cpp
ToolBar.cpp
GameList/GameFile.cpp
GameList/GameList.cpp
GameList/GameTracker.cpp
GameList/GameListModel.cpp
GameList/TableProxyModel.cpp
GameList/GameTracker.cpp
GameList/ListProxyModel.cpp
GameList/TableProxyModel.cpp
)
list(APPEND LIBS core uicommon)

View File

@ -40,6 +40,17 @@ void GameList::MakeTableView()
m_table->setSortingEnabled(true);
m_table->setCurrentIndex(QModelIndex());
// TODO load from config
m_table->setColumnHidden(GameListModel::COL_PLATFORM, false);
m_table->setColumnHidden(GameListModel::COL_ID, true);
m_table->setColumnHidden(GameListModel::COL_BANNER, false);
m_table->setColumnHidden(GameListModel::COL_TITLE, false);
m_table->setColumnHidden(GameListModel::COL_DESCRIPTION, true);
m_table->setColumnHidden(GameListModel::COL_MAKER, false);
m_table->setColumnHidden(GameListModel::COL_SIZE, false);
m_table->setColumnHidden(GameListModel::COL_COUNTRY, false);
m_table->setColumnHidden(GameListModel::COL_RATING, false);
// FIXME These icon image are overly wide and should be cut down to size,
// then we can remove these lines.
m_table->setColumnWidth(GameListModel::COL_PLATFORM, 52);

View File

@ -9,7 +9,6 @@
#include <QIcon>
#include <QLineEdit>
#include <QMenu>
#include <QMenuBar>
#include <QMessageBox>
#include "Common/FileUtil.h"
@ -30,7 +29,7 @@ MainWindow::MainWindow() : QMainWindow(nullptr)
MakeToolBar();
MakeRenderWidget();
MakeStack();
MakeMenus();
MakeMenuBar();
}
MainWindow::~MainWindow()
@ -38,115 +37,14 @@ MainWindow::~MainWindow()
m_render_widget->deleteLater();
}
void MainWindow::MakeMenus()
void MainWindow::MakeMenuBar()
{
MakeFileMenu();
menuBar()->addMenu(tr("Emulation"));
menuBar()->addMenu(tr("Movie"));
menuBar()->addMenu(tr("Options"));
menuBar()->addMenu(tr("Tools"));
MakeViewMenu();
menuBar()->addMenu(tr("Help"));
}
void MainWindow::MakeFileMenu()
{
QMenu* file_menu = menuBar()->addMenu(tr("File"));
file_menu->addAction(tr("Open"), this, SLOT(Open()));
file_menu->addAction(tr("Exit"), this, SLOT(close()));
}
void MainWindow::MakeViewMenu()
{
QMenu* view_menu = menuBar()->addMenu(tr("View"));
AddTableColumnsMenu(view_menu);
AddListTypePicker(view_menu);
}
void MainWindow::AddTableColumnsMenu(QMenu* view_menu)
{
QActionGroup* column_group = new QActionGroup(this);
QMenu* cols_menu = view_menu->addMenu(tr("Table Columns"));
column_group->setExclusive(false);
QStringList col_names{
tr("Platform"),
tr("ID"),
tr("Banner"),
tr("Title"),
tr("Description"),
tr("Maker"),
tr("Size"),
tr("Country"),
tr("Quality")
};
// TODO we'll need to update SConfig with the extra columns. Then we can
// clean this up significantly.
QList<bool> show_cols{
SConfig::GetInstance().m_showSystemColumn,
SConfig::GetInstance().m_showIDColumn,
SConfig::GetInstance().m_showBannerColumn,
true,
false,
SConfig::GetInstance().m_showMakerColumn,
SConfig::GetInstance().m_showSizeColumn,
SConfig::GetInstance().m_showRegionColumn,
SConfig::GetInstance().m_showStateColumn,
};
for (int i = 0; i < GameListModel::NUM_COLS; i++)
{
QAction* action = column_group->addAction(cols_menu->addAction(col_names[i]));
action->setCheckable(true);
action->setChecked(show_cols[i]);
m_game_list->SetViewColumn(i, show_cols[i]);
connect(action, &QAction::triggered, [=]()
{
m_game_list->SetViewColumn(i, action->isChecked());
switch (i)
{
case GameListModel::COL_PLATFORM:
SConfig::GetInstance().m_showSystemColumn = action->isChecked();
break;
case GameListModel::COL_ID:
SConfig::GetInstance().m_showIDColumn = action->isChecked();
break;
case GameListModel::COL_TITLE:
SConfig::GetInstance().m_showBannerColumn = action->isChecked();
break;
case GameListModel::COL_MAKER:
SConfig::GetInstance().m_showMakerColumn = action->isChecked();
break;
case GameListModel::COL_SIZE:
SConfig::GetInstance().m_showSizeColumn = action->isChecked();
break;
case GameListModel::COL_COUNTRY:
SConfig::GetInstance().m_showRegionColumn = action->isChecked();
break;
case GameListModel::COL_RATING:
SConfig::GetInstance().m_showStateColumn = action->isChecked();
break;
default: break;
}
SConfig::GetInstance().SaveSettings();
});
}
}
void MainWindow::AddListTypePicker(QMenu* view_menu)
{
QActionGroup* list_group = new QActionGroup(this);
view_menu->addSection(tr("List Type"));
list_group->setExclusive(true);
QAction* set_table = list_group->addAction(view_menu->addAction(tr("Table")));
QAction* set_list = list_group->addAction(view_menu->addAction(tr("List")));
set_table->setCheckable(true);
set_table->setChecked(true);
set_list->setCheckable(true);
connect(set_table, &QAction::triggered, m_game_list, &GameList::SetTableView);
connect(set_list, &QAction::triggered, m_game_list, &GameList::SetListView);
m_menu_bar = new MenuBar(this);
setMenuBar(m_menu_bar);
connect(m_menu_bar, &MenuBar::Open, this, &MainWindow::Open);
connect(m_menu_bar, &MenuBar::Exit, this, &MainWindow::close);
connect(m_menu_bar, &MenuBar::ShowTable, m_game_list, &GameList::SetTableView);
connect(m_menu_bar, &MenuBar::ShowList, m_game_list, &GameList::SetListView);
}
void MainWindow::MakeToolBar()

View File

@ -9,6 +9,7 @@
#include <QString>
#include <QToolBar>
#include "DolphinQt2/MenuBar.h"
#include "DolphinQt2/RenderWidget.h"
#include "DolphinQt2/ToolBar.h"
#include "DolphinQt2/GameList/GameList.h"
@ -37,16 +38,11 @@ private slots:
void ScreenShot();
private:
void MakeToolBar();
void MakeStack();
void MakeGameList();
void MakeMenuBar();
void MakeRenderWidget();
void MakeMenus();
void MakeFileMenu();
void MakeViewMenu();
void AddTableColumnsMenu(QMenu* view_menu);
void AddListTypePicker(QMenu* view_menu);
void MakeStack();
void MakeToolBar();
void StartGame(QString path);
void ShowRenderWidget();
@ -54,6 +50,7 @@ private:
QStackedWidget* m_stack;
ToolBar* m_tool_bar;
MenuBar* m_menu_bar;
GameList* m_game_list;
RenderWidget* m_render_widget;
bool m_rendering_to_main;

View File

@ -0,0 +1,80 @@
// Copyright 2015 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <QAction>
#include <QActionGroup>
#include "Core/ConfigManager.h"
#include "DolphinQt2/MenuBar.h"
MenuBar::MenuBar(QWidget* parent)
: QMenuBar(parent)
{
AddFileMenu();
addMenu(tr("Emulation"));
addMenu(tr("Movie"));
addMenu(tr("Options"));
addMenu(tr("Tools"));
AddViewMenu();
addMenu(tr("Help"));
}
void MenuBar::AddFileMenu()
{
QMenu* file_menu = addMenu(tr("File"));
file_menu->addAction(tr("Open"), this, SIGNAL(Open()));
file_menu->addAction(tr("Exit"), this, SIGNAL(Exit()));
}
void MenuBar::AddViewMenu()
{
QMenu* view_menu = addMenu(tr("View"));
AddGameListTypeSection(view_menu);
view_menu->addSeparator();
AddTableColumnsMenu(view_menu);
}
void MenuBar::AddGameListTypeSection(QMenu* view_menu)
{
QAction* table_view = view_menu->addAction(tr("Table"));
table_view->setCheckable(true);
QAction* list_view = view_menu->addAction(tr("List"));
list_view->setCheckable(true);
QActionGroup* list_group = new QActionGroup(this);
list_group->addAction(table_view);
list_group->addAction(list_view);
// TODO load this from settings
table_view->setChecked(true);
connect(table_view, &QAction::triggered, this, &MenuBar::ShowTable);
connect(list_view, &QAction::triggered, this, &MenuBar::ShowList);
}
// TODO implement this after we stop using SConfig.
void MenuBar::AddTableColumnsMenu(QMenu* view_menu)
{
QActionGroup* column_group = new QActionGroup(this);
QMenu* cols_menu = view_menu->addMenu(tr("Table Columns"));
column_group->setExclusive(false);
QStringList col_names{
tr("Platform"),
tr("ID"),
tr("Banner"),
tr("Title"),
tr("Description"),
tr("Maker"),
tr("Size"),
tr("Country"),
tr("Quality")
};
for (int i = 0; i < col_names.count(); i++)
{
QAction* action = column_group->addAction(cols_menu->addAction(col_names[i]));
action->setCheckable(true);
}
}

View File

@ -0,0 +1,30 @@
// Copyright 2015 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <QMenu>
#include <QMenuBar>
class MenuBar final : public QMenuBar
{
Q_OBJECT
public:
MenuBar(QWidget* parent = nullptr);
signals:
void Open();
void Exit();
void ShowTable();
void ShowList();
private:
void AddFileMenu();
void AddViewMenu();
void AddGameListTypeSection(QMenu* view_menu);
void AddTableColumnsMenu(QMenu* view_menu);
};