NOISSUE add context menus to pages with toolbars
This commit is contained in:
@ -43,20 +43,23 @@ AccountListPage::AccountListPage(QWidget *parent)
|
||||
"If you're new here, you can click the \"Add\" button to add your Mojang or Minecraft account."
|
||||
));
|
||||
ui->listView->setEmptyMode(VersionListView::String);
|
||||
ui->listView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
m_accounts = MMC->accounts();
|
||||
|
||||
ui->listView->setModel(m_accounts.get());
|
||||
ui->listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
// Expand the account column
|
||||
ui->listView->header()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
|
||||
QItemSelectionModel *selectionModel = ui->listView->selectionModel();
|
||||
|
||||
connect(selectionModel, &QItemSelectionModel::selectionChanged,
|
||||
[this](const QItemSelection &sel, const QItemSelection &dsel)
|
||||
{ updateButtonStates(); });
|
||||
connect(selectionModel, &QItemSelectionModel::selectionChanged, [this](const QItemSelection &sel, const QItemSelection &dsel) {
|
||||
updateButtonStates();
|
||||
});
|
||||
connect(ui->listView, &VersionListView::customContextMenuRequested, this, &AccountListPage::ShowContextMenu);
|
||||
|
||||
connect(m_accounts.get(), SIGNAL(listChanged()), SLOT(listChanged()));
|
||||
connect(m_accounts.get(), SIGNAL(activeAccountChanged()), SLOT(listChanged()));
|
||||
@ -69,6 +72,13 @@ AccountListPage::~AccountListPage()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void AccountListPage::ShowContextMenu(const QPoint& pos)
|
||||
{
|
||||
auto menu = ui->toolBar->createContextMenu(this, tr("Context menu"));
|
||||
menu->exec(ui->listView->mapToGlobal(pos));
|
||||
delete menu;
|
||||
}
|
||||
|
||||
void AccountListPage::changeEvent(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::LanguageChange)
|
||||
|
@ -85,6 +85,7 @@ protected:
|
||||
|
||||
protected
|
||||
slots:
|
||||
void ShowContextMenu(const QPoint &pos);
|
||||
void addAccount(const QString& errMsg="");
|
||||
|
||||
private:
|
||||
|
@ -32,10 +32,17 @@
|
||||
#include "minecraft/ComponentList.h"
|
||||
#include <DesktopServices.h>
|
||||
|
||||
ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<SimpleModList> mods, QString id,
|
||||
QString iconName, QString displayName, QString helpPage,
|
||||
QWidget *parent)
|
||||
: QMainWindow(parent), ui(new Ui::ModFolderPage)
|
||||
ModFolderPage::ModFolderPage(
|
||||
BaseInstance *inst,
|
||||
std::shared_ptr<SimpleModList> mods,
|
||||
QString id,
|
||||
QString iconName,
|
||||
QString displayName,
|
||||
QString helpPage,
|
||||
QWidget *parent
|
||||
) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::ModFolderPage)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->actionsToolbar->insertSpacer(ui->actionView_configs);
|
||||
@ -57,6 +64,9 @@ ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<SimpleModList>
|
||||
ui->modTreeView->setModel(m_filterModel);
|
||||
ui->modTreeView->installEventFilter(this);
|
||||
ui->modTreeView->sortByColumn(1, Qt::AscendingOrder);
|
||||
ui->modTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->modTreeView, &ModListView::customContextMenuRequested, this, &ModFolderPage::ShowContextMenu);
|
||||
|
||||
auto smodel = ui->modTreeView->selectionModel();
|
||||
connect(smodel, &QItemSelectionModel::currentChanged, this, &ModFolderPage::modCurrent);
|
||||
connect(ui->filterEdit, &QLineEdit::textChanged, this, &ModFolderPage::on_filterTextChanged );
|
||||
@ -70,6 +80,13 @@ QMenu * ModFolderPage::createPopupMenu()
|
||||
return filteredMenu;
|
||||
}
|
||||
|
||||
void ModFolderPage::ShowContextMenu(const QPoint& pos)
|
||||
{
|
||||
auto menu = ui->actionsToolbar->createContextMenu(this, tr("Context menu"));
|
||||
menu->exec(ui->modTreeView->mapToGlobal(pos));
|
||||
delete menu;
|
||||
}
|
||||
|
||||
void ModFolderPage::openedImpl()
|
||||
{
|
||||
m_mods->startWatching();
|
||||
|
@ -102,6 +102,7 @@ slots:
|
||||
void on_actionDisable_triggered();
|
||||
void on_actionView_Folder_triggered();
|
||||
void on_actionView_configs_triggered();
|
||||
void ShowContextMenu(const QPoint &pos);
|
||||
};
|
||||
|
||||
class CoreModFolderPage : public ModFolderPage
|
||||
|
@ -235,6 +235,8 @@ ScreenshotsPage::ScreenshotsPage(QString path, QWidget *parent)
|
||||
ui->listView->installEventFilter(this);
|
||||
ui->listView->setEditTriggers(0);
|
||||
ui->listView->setItemDelegate(new CenteredEditingDelegate(this));
|
||||
ui->listView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->listView, &QListView::customContextMenuRequested, this, &ScreenshotsPage::ShowContextMenu);
|
||||
connect(ui->listView, SIGNAL(activated(QModelIndex)), SLOT(onItemActivated(QModelIndex)));
|
||||
}
|
||||
|
||||
@ -266,6 +268,13 @@ ScreenshotsPage::~ScreenshotsPage()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ScreenshotsPage::ShowContextMenu(const QPoint& pos)
|
||||
{
|
||||
auto menu = ui->toolBar->createContextMenu(this, tr("Context menu"));
|
||||
menu->exec(ui->listView->mapToGlobal(pos));
|
||||
delete menu;
|
||||
}
|
||||
|
||||
QMenu * ScreenshotsPage::createPopupMenu()
|
||||
{
|
||||
QMenu* filteredMenu = QMainWindow::createPopupMenu();
|
||||
|
@ -77,6 +77,7 @@ private slots:
|
||||
void on_actionRename_triggered();
|
||||
void on_actionView_Folder_triggered();
|
||||
void onItemActivated(QModelIndex);
|
||||
void ShowContextMenu(const QPoint &pos);
|
||||
|
||||
private:
|
||||
Ui::ScreenshotsPage *ui;
|
||||
|
@ -564,6 +564,9 @@ ServersPage::ServersPage(MinecraftInstance * inst, QWidget* parent)
|
||||
m_model = new ServersModel(inst->gameRoot(), this);
|
||||
ui->serversView->setIconSize(QSize(64,64));
|
||||
ui->serversView->setModel(m_model);
|
||||
ui->serversView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->serversView, &QTreeView::customContextMenuRequested, this, &ServersPage::ShowContextMenu);
|
||||
|
||||
auto head = ui->serversView->header();
|
||||
if(head->count())
|
||||
{
|
||||
@ -596,6 +599,13 @@ ServersPage::~ServersPage()
|
||||
m_model->saveNow();
|
||||
}
|
||||
|
||||
void ServersPage::ShowContextMenu(const QPoint& pos)
|
||||
{
|
||||
auto menu = ui->toolBar->createContextMenu(this, tr("Context menu"));
|
||||
menu->exec(ui->serversView->mapToGlobal(pos));
|
||||
delete menu;
|
||||
}
|
||||
|
||||
QMenu * ServersPage::createPopupMenu()
|
||||
{
|
||||
QMenu* filteredMenu = QMainWindow::createPopupMenu();
|
||||
|
@ -79,7 +79,9 @@ private slots:
|
||||
|
||||
void nameEdited(const QString & name);
|
||||
void addressEdited(const QString & address);
|
||||
void resourceIndexChanged(int index);
|
||||
void resourceIndexChanged(int index);\
|
||||
|
||||
void ShowContextMenu(const QPoint &pos);
|
||||
|
||||
private: // data
|
||||
int currentServer = -1;
|
||||
|
@ -123,6 +123,8 @@ VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent)
|
||||
ui->packageView->setModel(proxy);
|
||||
ui->packageView->installEventFilter(this);
|
||||
ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
ui->packageView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged, this, &VersionPage::versionCurrent);
|
||||
auto smodel = ui->packageView->selectionModel();
|
||||
connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent);
|
||||
@ -132,6 +134,7 @@ VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent)
|
||||
updateVersionControls();
|
||||
preselect(0);
|
||||
connect(m_inst, &BaseInstance::runningStatusChanged, this, &VersionPage::updateRunningStatus);
|
||||
connect(ui->packageView, &ModListView::customContextMenuRequested, this, &VersionPage::ShowContextMenu);
|
||||
}
|
||||
|
||||
VersionPage::~VersionPage()
|
||||
@ -139,6 +142,13 @@ VersionPage::~VersionPage()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void VersionPage::ShowContextMenu(const QPoint& pos)
|
||||
{
|
||||
auto menu = ui->toolBar->createContextMenu(this, tr("Context menu"));
|
||||
menu->exec(ui->packageView->mapToGlobal(pos));
|
||||
delete menu;
|
||||
}
|
||||
|
||||
void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
if (!current.isValid())
|
||||
|
@ -95,5 +95,5 @@ private slots:
|
||||
void updateRunningStatus(bool running);
|
||||
void onGameUpdateError(QString error);
|
||||
void packageCurrent(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
|
||||
void ShowContextMenu(const QPoint &pos);
|
||||
};
|
||||
|
@ -45,6 +45,8 @@ WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worl
|
||||
ui->worldTreeView->setSortingEnabled(true);
|
||||
ui->worldTreeView->setModel(proxy);
|
||||
ui->worldTreeView->installEventFilter(this);
|
||||
ui->worldTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->worldTreeView, &QTreeView::customContextMenuRequested, this, &WorldListPage::ShowContextMenu);
|
||||
|
||||
auto head = ui->worldTreeView->header();
|
||||
head->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
@ -70,6 +72,13 @@ WorldListPage::~WorldListPage()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void WorldListPage::ShowContextMenu(const QPoint& pos)
|
||||
{
|
||||
auto menu = ui->toolBar->createContextMenu(this, tr("Context menu"));
|
||||
menu->exec(ui->worldTreeView->mapToGlobal(pos));
|
||||
delete menu;
|
||||
}
|
||||
|
||||
QMenu * WorldListPage::createPopupMenu()
|
||||
{
|
||||
QMenu* filteredMenu = QMainWindow::createPopupMenu();
|
||||
|
@ -92,4 +92,6 @@ private slots:
|
||||
void on_actionView_Folder_triggered();
|
||||
void worldChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
void mceditState(LoggedProcess::State state);
|
||||
|
||||
void ShowContextMenu(const QPoint &pos);
|
||||
};
|
||||
|
Reference in New Issue
Block a user