summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2019-07-25 01:02:30 +0200
committerPetr Mrázek <peterix@gmail.com>2019-07-25 01:02:30 +0200
commit7dfe73df0c26733d68abc576c3eefab1a69e2149 (patch)
tree0e490b13ad475f0d551f8087851f83869589eb09
parentc3e61536a3ba7b0dca1171df36e9aeb09b6e2a0d (diff)
downloadMultiMC-7dfe73df0c26733d68abc576c3eefab1a69e2149.tar
MultiMC-7dfe73df0c26733d68abc576c3eefab1a69e2149.tar.gz
MultiMC-7dfe73df0c26733d68abc576c3eefab1a69e2149.tar.lz
MultiMC-7dfe73df0c26733d68abc576c3eefab1a69e2149.tar.xz
MultiMC-7dfe73df0c26733d68abc576c3eefab1a69e2149.zip
NOISSUE add context menus to pages with toolbars
-rw-r--r--application/pages/global/AccountListPage.cpp16
-rw-r--r--application/pages/global/AccountListPage.h1
-rw-r--r--application/pages/instance/ModFolderPage.cpp25
-rw-r--r--application/pages/instance/ModFolderPage.h1
-rw-r--r--application/pages/instance/ScreenshotsPage.cpp9
-rw-r--r--application/pages/instance/ScreenshotsPage.h1
-rw-r--r--application/pages/instance/ServersPage.cpp10
-rw-r--r--application/pages/instance/ServersPage.h4
-rw-r--r--application/pages/instance/VersionPage.cpp10
-rw-r--r--application/pages/instance/VersionPage.h2
-rw-r--r--application/pages/instance/WorldListPage.cpp9
-rw-r--r--application/pages/instance/WorldListPage.h2
-rw-r--r--application/widgets/WideBar.cpp69
-rw-r--r--application/widgets/WideBar.h8
14 files changed, 151 insertions, 16 deletions
diff --git a/application/pages/global/AccountListPage.cpp b/application/pages/global/AccountListPage.cpp
index 5270a305..c14134f3 100644
--- a/application/pages/global/AccountListPage.cpp
+++ b/application/pages/global/AccountListPage.cpp
@@ -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)
diff --git a/application/pages/global/AccountListPage.h b/application/pages/global/AccountListPage.h
index 9de73f70..4c8bc00b 100644
--- a/application/pages/global/AccountListPage.h
+++ b/application/pages/global/AccountListPage.h
@@ -85,6 +85,7 @@ protected:
protected
slots:
+ void ShowContextMenu(const QPoint &pos);
void addAccount(const QString& errMsg="");
private:
diff --git a/application/pages/instance/ModFolderPage.cpp b/application/pages/instance/ModFolderPage.cpp
index d0de4ac2..97225832 100644
--- a/application/pages/instance/ModFolderPage.cpp
+++ b/application/pages/instance/ModFolderPage.cpp
@@ -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();
diff --git a/application/pages/instance/ModFolderPage.h b/application/pages/instance/ModFolderPage.h
index 1bdf03a2..a52e1611 100644
--- a/application/pages/instance/ModFolderPage.h
+++ b/application/pages/instance/ModFolderPage.h
@@ -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
diff --git a/application/pages/instance/ScreenshotsPage.cpp b/application/pages/instance/ScreenshotsPage.cpp
index d73fda51..efa0f9f2 100644
--- a/application/pages/instance/ScreenshotsPage.cpp
+++ b/application/pages/instance/ScreenshotsPage.cpp
@@ -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();
diff --git a/application/pages/instance/ScreenshotsPage.h b/application/pages/instance/ScreenshotsPage.h
index 22ead49a..9adf79af 100644
--- a/application/pages/instance/ScreenshotsPage.h
+++ b/application/pages/instance/ScreenshotsPage.h
@@ -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;
diff --git a/application/pages/instance/ServersPage.cpp b/application/pages/instance/ServersPage.cpp
index 44ede664..c33eef1f 100644
--- a/application/pages/instance/ServersPage.cpp
+++ b/application/pages/instance/ServersPage.cpp
@@ -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();
diff --git a/application/pages/instance/ServersPage.h b/application/pages/instance/ServersPage.h
index 9c9cc388..c81f47be 100644
--- a/application/pages/instance/ServersPage.h
+++ b/application/pages/instance/ServersPage.h
@@ -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;
diff --git a/application/pages/instance/VersionPage.cpp b/application/pages/instance/VersionPage.cpp
index 8b95c8b2..eb918626 100644
--- a/application/pages/instance/VersionPage.cpp
+++ b/application/pages/instance/VersionPage.cpp
@@ -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 &current, const QModelIndex &previous)
{
if (!current.isValid())
diff --git a/application/pages/instance/VersionPage.h b/application/pages/instance/VersionPage.h
index 553c6ae3..31344eb9 100644
--- a/application/pages/instance/VersionPage.h
+++ b/application/pages/instance/VersionPage.h
@@ -95,5 +95,5 @@ private slots:
void updateRunningStatus(bool running);
void onGameUpdateError(QString error);
void packageCurrent(const QModelIndex &current, const QModelIndex &previous);
-
+ void ShowContextMenu(const QPoint &pos);
};
diff --git a/application/pages/instance/WorldListPage.cpp b/application/pages/instance/WorldListPage.cpp
index 75805838..ca419fc5 100644
--- a/application/pages/instance/WorldListPage.cpp
+++ b/application/pages/instance/WorldListPage.cpp
@@ -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();
diff --git a/application/pages/instance/WorldListPage.h b/application/pages/instance/WorldListPage.h
index d07f8d9f..c39420da 100644
--- a/application/pages/instance/WorldListPage.h
+++ b/application/pages/instance/WorldListPage.h
@@ -92,4 +92,6 @@ private slots:
void on_actionView_Folder_triggered();
void worldChanged(const QModelIndex &current, const QModelIndex &previous);
void mceditState(LoggedProcess::State state);
+
+ void ShowContextMenu(const QPoint &pos);
};
diff --git a/application/widgets/WideBar.cpp b/application/widgets/WideBar.cpp
index ee0a67e3..cbd6c617 100644
--- a/application/widgets/WideBar.cpp
+++ b/application/widgets/WideBar.cpp
@@ -1,5 +1,6 @@
#include "WideBar.h"
#include <QToolButton>
+#include <QMenu>
class ActionButton : public QToolButton
{
@@ -20,6 +21,7 @@ private slots:
setIcon(m_action->icon());
setToolTip(m_action->toolTip());
setHidden(!m_action->isVisible());
+ setFocusPolicy(Qt::NoFocus);
}
private:
QAction * m_action;
@@ -38,22 +40,77 @@ WideBar::WideBar(QWidget* parent) : QToolBar(parent)
setMovable(false);
}
+struct WideBar::BarEntry {
+ enum Type {
+ None,
+ Action,
+ Separator,
+ Spacer
+ } type = None;
+ QAction *qAction = nullptr;
+ QAction *wideAction = nullptr;
+};
+
+
+WideBar::~WideBar()
+{
+ for(auto *iter: m_entries) {
+ delete iter;
+ }
+}
+
void WideBar::addAction(QAction* action)
{
- auto actionButton = new ActionButton(action, this);
- auto newAction = addWidget(actionButton);
- m_actionMap[action] = newAction;
+ auto entry = new BarEntry();
+ entry->qAction = addWidget(new ActionButton(action, this));
+ entry->wideAction = action;
+ entry->type = BarEntry::Action;
+ m_entries.push_back(entry);
+}
+
+void WideBar::addSeparator()
+{
+ auto entry = new BarEntry();
+ entry->qAction = QToolBar::addSeparator();
+ entry->type = BarEntry::Separator;
+ m_entries.push_back(entry);
}
void WideBar::insertSpacer(QAction* action)
{
- if(!m_actionMap.contains(action)) {
+ auto iter = std::find_if(m_entries.begin(), m_entries.end(), [action](BarEntry * entry) {
+ return entry->wideAction == action;
+ });
+ if(iter == m_entries.end()) {
return;
}
-
QWidget* spacer = new QWidget();
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- insertWidget(m_actionMap[action], spacer);
+
+ auto entry = new BarEntry();
+ entry->qAction = insertWidget((*iter)->qAction, spacer);
+ entry->type = BarEntry::Spacer;
+ m_entries.insert(iter, entry);
+}
+
+QMenu * WideBar::createContextMenu(QWidget *parent, const QString & title)
+{
+ QMenu *contextMenu = new QMenu(title, parent);
+ for(auto & item: m_entries) {
+ switch(item->type) {
+ default:
+ case BarEntry::None:
+ break;
+ case BarEntry::Separator:
+ case BarEntry::Spacer:
+ contextMenu->addSeparator();
+ break;
+ case BarEntry::Action:
+ contextMenu->addAction(item->wideAction);
+ break;
+ }
+ }
+ return contextMenu;
}
#include "WideBar.moc"
diff --git a/application/widgets/WideBar.h b/application/widgets/WideBar.h
index e5a1a737..d1b8cbe7 100644
--- a/application/widgets/WideBar.h
+++ b/application/widgets/WideBar.h
@@ -4,6 +4,8 @@
#include <QAction>
#include <QMap>
+class QMenu;
+
class WideBar : public QToolBar
{
Q_OBJECT
@@ -11,10 +13,14 @@ class WideBar : public QToolBar
public:
explicit WideBar(const QString &title, QWidget * parent = nullptr);
explicit WideBar(QWidget * parent = nullptr);
+ virtual ~WideBar();
void addAction(QAction *action);
+ void addSeparator();
void insertSpacer(QAction *action);
+ QMenu *createContextMenu(QWidget *parent = nullptr, const QString & title = QString());
private:
- QMap<QAction *, QAction *> m_actionMap;
+ struct BarEntry;
+ QList<BarEntry *> m_entries;
};