Skip to content

Commit

Permalink
Remove unesarry functions, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
poelzi committed Oct 20, 2020
1 parent 445a946 commit 7b2fc04
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/skin/legacyskinparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,6 @@ QWidget* LegacySkinParser::parseStarRating(const QDomElement& node) {
QWidget* LegacySkinParser::parseMainMenuButton(const QDomElement& node) {
WMainMenuBarButton* pMainmenu = new WMainMenuBarButton(m_pParent, m_pMainMenuBar);
commonWidgetSetup(node, pMainmenu);
pMainmenu->setup(node, *m_pContext);

return pMainmenu;
}
Expand Down
21 changes: 8 additions & 13 deletions src/widget/wmainmenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,10 @@ WMainMenuBar::WMainMenuBar(QWidget* pParent,
m_pConfig(pConfig),
m_pKbdConfig(pKbdConfig),
m_lastNumPlayers(0) {
initialize();
createMenu([this](QMenu* x) { addMenu(x); });
}

void WMainMenuBar::initialize() {
WMainMenuBar* target = this;
createMenu([target](QMenu* x) { target->addMenu(x); });
}

void WMainMenuBar::createMenu(std::function<void(QMenu*)> pAddMenu) {
void WMainMenuBar::createMenu(FnAddMenu fnAddMenu) {
// FILE MENU
QMenu* pFileMenu = new QMenu(tr("&File"));

Expand Down Expand Up @@ -114,7 +109,7 @@ void WMainMenuBar::createMenu(std::function<void(QMenu*)> pAddMenu) {
connect(pFileQuit, SIGNAL(triggered()), this, SIGNAL(quit()));
pFileMenu->addAction(pFileQuit);

pAddMenu(pFileMenu);
fnAddMenu(pFileMenu);

// LIBRARY MENU
QMenu* pLibraryMenu = new QMenu(tr("&Library"));
Expand Down Expand Up @@ -162,7 +157,7 @@ void WMainMenuBar::createMenu(std::function<void(QMenu*)> pAddMenu) {
this, SIGNAL(createCrate()));
pLibraryMenu->addAction(pLibraryCreateCrate);

pAddMenu(pLibraryMenu);
fnAddMenu(pLibraryMenu);

#if defined(__APPLE__)
// Note: On macOS 10.11 ff. we have to deal with "automagic" menu items,
Expand Down Expand Up @@ -319,7 +314,7 @@ void WMainMenuBar::createMenu(std::function<void(QMenu*)> pAddMenu) {
pViewFullScreen, SLOT(setChecked(bool)));
pViewMenu->addAction(pViewFullScreen);

pAddMenu(pViewMenu);
fnAddMenu(pViewMenu);

// OPTIONS MENU
QMenu* pOptionsMenu = new QMenu(tr("&Options"));
Expand Down Expand Up @@ -438,7 +433,7 @@ void WMainMenuBar::createMenu(std::function<void(QMenu*)> pAddMenu) {
this, SIGNAL(showPreferences()));
pOptionsMenu->addAction(pOptionsPreferences);

pAddMenu(pOptionsMenu);
fnAddMenu(pOptionsMenu);

// DEVELOPER MENU
if (CmdlineArgs::Instance().getDeveloper()) {
Expand Down Expand Up @@ -531,7 +526,7 @@ void WMainMenuBar::createMenu(std::function<void(QMenu*)> pAddMenu) {
this, SLOT(slotDeveloperDebugger(bool)));
pDeveloperMenu->addAction(pDeveloperDebugger);

pAddMenu(pDeveloperMenu);
fnAddMenu(pDeveloperMenu);
}

addSeparator();
Expand Down Expand Up @@ -621,7 +616,7 @@ void WMainMenuBar::createMenu(std::function<void(QMenu*)> pAddMenu) {
this, SIGNAL(showAbout()));

pHelpMenu->addAction(pHelpAboutApp);
pAddMenu(pHelpMenu);
fnAddMenu(pHelpMenu);

// we already know the num
if (m_lastNumPlayers) {
Expand Down
6 changes: 5 additions & 1 deletion src/widget/wmainmenubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include "preferences/configobject.h"
#include "preferences/usersettings.h"

namespace {
typedef std::function<void(QMenu*)> FnAddMenu;
}

class VisibilityControlConnection : public QObject {
Q_OBJECT
public:
Expand All @@ -35,7 +39,7 @@ class WMainMenuBar : public QMenuBar {
public:
WMainMenuBar(QWidget* pParent, UserSettingsPointer pConfig,
ConfigObject<ConfigValueKbd>* pKbdConfig);
void createMenu(std::function<void(QMenu*)>);
void createMenu(FnAddMenu fnAddMenu);
void setVisible(bool visible) override;
public slots:
void onLibraryScanStarted();
Expand Down
6 changes: 1 addition & 5 deletions src/widget/wmainmenubarbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
WMainMenuBarButton::WMainMenuBarButton(QWidget* pParent, WMainMenuBar* pMainMenu)
: QPushButton("...", pParent),
WBaseWidget(this),
m_pMenu(nullptr) {
m_pMenu(make_parented<QMenu>(this)) {
initialize(pMainMenu);
}

void WMainMenuBarButton::setup(const QDomNode& node, const SkinContext& context) {
}

void WMainMenuBarButton::initialize(WMainMenuBar* pMainMenu) {
m_pMenu = new QMenu(this);
setMenu(m_pMenu);
pMainMenu->createMenu([=](QMenu* x) { this->m_pMenu->addMenu(x); });
}
6 changes: 3 additions & 3 deletions src/widget/wmainmenubarbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "preferences/configobject.h"
#include "preferences/usersettings.h"
#include "skin/skincontext.h"
#include "util/parented_ptr.h"
#include "widget/wbasewidget.h"

class WMainMenuBar;
Expand All @@ -20,11 +21,10 @@ class WMainMenuBarButton : public QPushButton, public WBaseWidget {
Q_OBJECT
public:
WMainMenuBarButton(QWidget* pParent, WMainMenuBar* pMainMenu);
void setup(const QDomNode& node, const SkinContext& context);

private:
void initialize(WMainMenuBar* pMainMenu);

UserSettingsPointer m_pConfig;
QMenu* m_pMenu;
const UserSettingsPointer m_pConfig;
const parented_ptr<QMenu> m_pMenu;
};

0 comments on commit 7b2fc04

Please sign in to comment.