diff options
Diffstat (limited to 'src/mainwindow.cpp')
| -rw-r--r-- | src/mainwindow.cpp | 123 |
1 files changed, 85 insertions, 38 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ebb5d7ab..b19e7573 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -202,6 +202,7 @@ MainWindow::MainWindow(QSettings &initSettings , ui(new Ui::MainWindow) , m_WasVisible(false) , m_menuBarVisible(true) + , m_linksSeparator(nullptr) , m_Tutorial(this, "MainWindow") , m_OldProfileIndex(-1) , m_ModListGroupingProxy(nullptr) @@ -251,15 +252,7 @@ MainWindow::MainWindow(QSettings &initSettings updateProblemsButton(); - // Setup toolbar - - setupActionMenu(ui->actionTool); - setupActionMenu(ui->actionHelp); - setupActionMenu(ui->actionEndorseMO); - - createHelpMenu(); - createEndorseMenu(); - + setupToolbar(); toggleMO2EndorseState(); TaskProgressManager::instance().tryCreateTaskbar(); @@ -400,7 +393,7 @@ MainWindow::MainWindow(QSettings &initSettings connect(&TutorialManager::instance(), SIGNAL(windowTutorialFinished(QString)), this, SLOT(windowTutorialFinished(QString))); connect(ui->tabWidget, SIGNAL(currentChanged(int)), &TutorialManager::instance(), SIGNAL(tabChanged(int))); connect(ui->modList->header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(modListSortIndicatorChanged(int,Qt::SortOrder))); - connect(ui->linksToolBar, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(linksToolBar_customContextMenuRequested(QPoint))); + connect(ui->toolBar, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(toolBar_customContextMenuRequested(QPoint))); connect(ui->menuToolbars, &QMenu::aboutToShow, [&]{ toolbarMenu_aboutToShow(); }); connect(&m_OrganizerCore, &OrganizerCore::modInstalled, this, &MainWindow::modInstalled); @@ -601,6 +594,34 @@ static QModelIndex mapToModel(const QAbstractItemModel *targetModel, QModelIndex return result; } +void MainWindow::setupToolbar() +{ + setupActionMenu(ui->actionTool); + setupActionMenu(ui->actionHelp); + setupActionMenu(ui->actionEndorseMO); + + createHelpMenu(); + createEndorseMenu(); + + // find last separator, add a spacer just before it so the icons are + // right-aligned + m_linksSeparator = nullptr; + for (auto* a : ui->toolBar->actions()) { + if (a->isSeparator()) { + m_linksSeparator = a; + } + } + + if (m_linksSeparator) { + auto* spacer = new QWidget(ui->toolBar); + spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); + ui->toolBar->insertWidget(m_linksSeparator, spacer); + + } else { + qWarning("no separator found on the toolbar, icons won't be right-aligned"); + } +} + void MainWindow::setupActionMenu(QAction* a) { a->setMenu(new QMenu(this)); @@ -612,9 +633,11 @@ void MainWindow::setupActionMenu(QAction* a) void MainWindow::updatePinnedExecutables() { - for (auto* a : ui->linksToolBar->actions()) { - ui->linksToolBar->removeAction(a); - a->deleteLater(); + for (auto* a : ui->toolBar->actions()) { + if (a->objectName().startsWith("custom__")) { + ui->toolBar->removeAction(a); + a->deleteLater(); + } } ui->menuRun->clear(); @@ -637,13 +660,18 @@ void MainWindow::updatePinnedExecutables() qDebug("failed to connect trigger?"); } - ui->linksToolBar->addAction(exeAction); + if (m_linksSeparator) { + ui->toolBar->insertAction(m_linksSeparator, exeAction); + } else { + // separator wasn't found, add it to the end + ui->toolBar->addAction(exeAction); + } + ui->menuRun->addAction(exeAction); } } - // don't show the toolbar or menu if there are no links - ui->linksToolBar->setVisible(hasLinks); + // don't show the menu if there are no links ui->menuRun->menuAction()->setVisible(hasLinks); } @@ -660,7 +688,6 @@ void MainWindow::toolbarMenu_aboutToShow() ui->actionMainMenuToggle->setChecked(ui->menuBar->isVisible()); ui->actionToolBarMainToggle->setChecked(ui->toolBar->isVisible()); - ui->actionToolBarLinksToggle->setChecked(ui->linksToolBar->isVisible()); ui->actionToolBarSmallIcons->setChecked(ui->toolBar->iconSize() == SmallToolbarSize); ui->actionToolBarMediumIcons->setChecked(ui->toolBar->iconSize() == MediumToolbarSize); @@ -687,11 +714,6 @@ void MainWindow::on_actionToolBarMainToggle_triggered() ui->toolBar->setVisible(!ui->toolBar->isVisible()); } -void MainWindow::on_actionToolBarLinksToggle_triggered() -{ - ui->linksToolBar->setVisible(!ui->linksToolBar->isVisible()); -} - void MainWindow::on_actionToolBarSmallIcons_triggered() { setToolbarSize(SmallToolbarSize); @@ -3377,7 +3399,7 @@ void MainWindow::openExplorer_clicked() } } -void MainWindow::openOriginExplorer_clicked() +void MainWindow::openPluginOriginExplorer_clicked() { QItemSelectionModel *selection = ui->espList->selectionModel(); if (selection->hasSelection() && selection->selectedRows().count() > 0) { @@ -4721,7 +4743,7 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos) // no selection QMenu menu(this); initModListContextMenu(&menu); - menu.exec(modList->mapToGlobal(pos)); + menu.exec(modList->viewport()->mapToGlobal(pos)); } else { QMenu menu(this); @@ -4866,7 +4888,7 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos) menu.setDefaultAction(infoAction); } - menu.exec(modList->mapToGlobal(pos)); + menu.exec(modList->viewport()->mapToGlobal(pos)); } } catch (const std::exception &e) { reportError(tr("Exception: ").arg(e.what())); @@ -5005,7 +5027,7 @@ void MainWindow::on_savegameList_customContextMenuRequested(const QPoint &pos) menu.addAction(deleteMenuLabel, this, SLOT(deleteSavegame_clicked())); - menu.exec(ui->savegameList->mapToGlobal(pos)); + menu.exec(ui->savegameList->viewport()->mapToGlobal(pos)); } void MainWindow::linkToolbar() @@ -5447,6 +5469,24 @@ void MainWindow::openDataFile() m_OrganizerCore.executeFileVirtualized(this, targetInfo); } +void MainWindow::openDataOriginExplorer_clicked() +{ + if (m_ContextItem == nullptr) { + return; + } + + const auto isArchive = m_ContextItem->data(0, Qt::UserRole + 1).toBool(); + const auto isDirectory = m_ContextItem->data(0, Qt::UserRole + 3).toBool(); + + if (isArchive || isDirectory) { + return; + } + + const auto fullPath = m_ContextItem->data(0, Qt::UserRole).toString(); + + qDebug().nospace() << "opening in explorer: " << fullPath; + shell::ExploreFile(fullPath); +} void MainWindow::updateAvailable() { @@ -5490,8 +5530,15 @@ void MainWindow::on_dataTree_customContextMenuRequested(const QPoint &pos) menu.addAction(tr("Preview"), this, SLOT(previewDataFile())); } + const auto isArchive = m_ContextItem->data(0, Qt::UserRole + 1).toBool(); + const auto isDirectory = m_ContextItem->data(0, Qt::UserRole + 3).toBool(); + + if (!isArchive && !isDirectory) { + menu.addAction("Open Origin in Explorer", this, SLOT(openDataOriginExplorer_clicked())); + } + // offer to hide/unhide file, but not for files from archives - if (!m_ContextItem->data(0, Qt::UserRole + 1).toBool()) { + if (!isArchive) { if (m_ContextItem->text(0).endsWith(ModInfo::s_HiddenExt)) { menu.addAction(tr("Un-Hide"), this, SLOT(unhideFile())); } else { @@ -5504,7 +5551,7 @@ void MainWindow::on_dataTree_customContextMenuRequested(const QPoint &pos) menu.addAction(tr("Write To File..."), this, SLOT(writeDataToFile())); menu.addAction(tr("Refresh"), this, SLOT(on_btnRefreshData_clicked())); - menu.exec(dataTree->mapToGlobal(pos)); + menu.exec(dataTree->viewport()->mapToGlobal(pos)); } void MainWindow::on_conflictsCheckBox_toggled(bool) @@ -6086,7 +6133,7 @@ void MainWindow::on_bsaList_customContextMenuRequested(const QPoint &pos) QMenu menu; menu.addAction(tr("Extract..."), this, SLOT(extractBSATriggered())); - menu.exec(ui->bsaList->mapToGlobal(pos)); + menu.exec(ui->bsaList->viewport()->mapToGlobal(pos)); } void MainWindow::on_bsaList_itemChanged(QTreeWidgetItem*, int) @@ -6163,7 +6210,7 @@ void MainWindow::on_categoriesList_customContextMenuRequested(const QPoint &pos) menu.addAction(tr("Edit Categories..."), this, SLOT(editCategories())); menu.addAction(tr("Deselect filter"), this, SLOT(deselectFilters())); - menu.exec(ui->categoriesList->mapToGlobal(pos)); + menu.exec(ui->categoriesList->viewport()->mapToGlobal(pos)); } @@ -6207,23 +6254,23 @@ void MainWindow::removeFromToolbar() } -void MainWindow::linksToolBar_customContextMenuRequested(const QPoint &point) +void MainWindow::toolBar_customContextMenuRequested(const QPoint &point) { - QAction *action = ui->linksToolBar->actionAt(point); + QAction *action = ui->toolBar->actionAt(point); if (action != nullptr) { if (action->objectName().startsWith("custom_")) { m_ContextAction = action; QMenu menu; menu.addAction(tr("Remove '%1' from the toolbar").arg(action->text()), this, SLOT(removeFromToolbar())); - menu.exec(ui->linksToolBar->mapToGlobal(point)); + menu.exec(ui->toolBar->mapToGlobal(point)); return; } } // did not click a link button, show the default context menu auto* m = createPopupMenu(); - m->exec(ui->linksToolBar->mapToGlobal(point)); + m->exec(ui->toolBar->mapToGlobal(point)); } void MainWindow::on_espList_customContextMenuRequested(const QPoint &pos) @@ -6271,7 +6318,7 @@ void MainWindow::on_espList_customContextMenuRequested(const QPoint &pos) unsigned int modInfoIndex = ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(idx.data().toString())); //this is to avoid showing the option on game files like skyrim.esm if (modInfoIndex != UINT_MAX) { - menu.addAction(tr("Open Origin in Explorer"), this, SLOT(openOriginExplorer_clicked())); + menu.addAction(tr("Open Origin in Explorer"), this, SLOT(openPluginOriginExplorer_clicked())); ModInfo::Ptr modInfo = ModInfo::getByIndex(modInfoIndex); std::vector<ModInfo::EFlag> flags = modInfo->getFlags(); @@ -6282,7 +6329,7 @@ void MainWindow::on_espList_customContextMenuRequested(const QPoint &pos) } try { - menu.exec(ui->espList->mapToGlobal(pos)); + menu.exec(ui->espList->viewport()->mapToGlobal(pos)); } catch (const std::exception &e) { reportError(tr("Exception: ").arg(e.what())); } catch (...) { @@ -6858,7 +6905,7 @@ void MainWindow::dropEvent(QDropEvent *event) event->accept(); } -void MainWindow::keyPressEvent(QKeyEvent *event) +void MainWindow::keyReleaseEvent(QKeyEvent *event) { // if the menubar is hidden, pressing Alt will make it visible if (event->key() == Qt::Key_Alt) { @@ -6868,7 +6915,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event) } } - QMainWindow::keyPressEvent(event); + QMainWindow::keyReleaseEvent(event); } void MainWindow::on_clickBlankButton_clicked() |
