Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MainWindow: Use a map instead of an array for Tools menu #6719

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
53 changes: 26 additions & 27 deletions include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ class MainWindow : public QMainWindow
return m_toolBar;
}

int addWidgetToToolBar( QWidget * _w, int _row = -1, int _col = -1 );
int addWidgetToToolBar(QWidget* _w, int _row = -1, int _col = -1);
void addSpacingToToolBar( int _size );

// wrap the widget with a window decoration and add it to the workspace
LMMS_EXPORT SubWindow* addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags = QFlag(0));
LMMS_EXPORT SubWindow* addWindowedWidget(QWidget* w, Qt::WindowFlags windowFlags = Qt::Widget);


///
Expand Down Expand Up @@ -140,8 +140,8 @@ class MainWindow : public QMainWindow
return m_keyMods.m_shift;
}

static void saveWidgetState( QWidget * _w, QDomElement & _de );
static void restoreWidgetState( QWidget * _w, const QDomElement & _de );
static void saveWidgetState(QWidget* _w, QDomElement& _de);
static void restoreWidgetState(QWidget* _w, const QDomElement& _de);

bool eventFilter(QObject* watched, QEvent* event) override;

Expand Down Expand Up @@ -180,32 +180,32 @@ private slots:
void onExportProjectMidi();

protected:
void closeEvent( QCloseEvent * _ce ) override;
void focusOutEvent( QFocusEvent * _fe ) override;
void keyPressEvent( QKeyEvent * _ke ) override;
void keyReleaseEvent( QKeyEvent * _ke ) override;
void timerEvent( QTimerEvent * _ev ) override;
void closeEvent(QCloseEvent* _ce) override;
void focusOutEvent(QFocusEvent* _fe) override;
void keyPressEvent(QKeyEvent* _ke) override;
void keyReleaseEvent(QKeyEvent* _ke) override;
void timerEvent(QTimerEvent* _ev) override;


private:
MainWindow();
MainWindow( const MainWindow & );
MainWindow(const MainWindow&);
~MainWindow() override;

void finalize();

void toggleWindow( QWidget *window, bool forceShow = false );
void toggleWindow(QWidget* window, bool forceShow = false);
void refocus();

void exportProject(bool multiExport = false);
void handleSaveResult(QString const & filename, bool songSavedSuccessfully);
void handleSaveResult(const QString& filename, bool songSavedSuccessfully);
bool guiSaveProject();
bool guiSaveProjectAs( const QString & filename );
bool guiSaveProjectAs(const QString& filename);

QMdiArea * m_workspace;
QMdiArea* m_workspace;

QWidget * m_toolBar;
QGridLayout * m_toolBarLayout;
QWidget* m_toolBar;
QGridLayout* m_toolBarLayout;

struct keyModifiers
{
Expand All @@ -220,30 +220,29 @@ private slots:
bool m_alt;
} m_keyMods;

QMenu * m_toolsMenu;
QAction * m_undoAction;
QAction * m_redoAction;
QList<PluginView *> m_tools;

QMenu* m_toolsMenu;
QAction* m_undoAction;
QAction* m_redoAction;
QMap<QString, PluginView*> m_tools;
QBasicTimer m_updateTimer;
QTimer m_autoSaveTimer;
int m_autoSaveInterval;

friend class GuiApplication;

QMenu * m_viewMenu;
QMenu* m_viewMenu;

ToolButton * m_metronomeToggle;
ToolButton* m_metronomeToggle;

SessionState m_session;

bool maximized;

private slots:
void browseHelp();
void showTool( QAction * _idx );
void showPluginTool(const QString& which);
void updateViewMenu();
void updateConfig( QAction * _who );
void updateConfig(QAction* _who);
void onToggleMetronome();
void onExportProject();
void onExportProjectTracks();
Expand All @@ -253,7 +252,7 @@ private slots:

signals:
void periodicUpdate();
void initProgress(const QString &msg);
void initProgress(const QString& msg);

} ;

Expand Down
31 changes: 17 additions & 14 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,16 @@ void MainWindow::finalize()
m_toolsMenu = new QMenu( this );
for( const Plugin::Descriptor* desc : getPluginFactory()->descriptors(Plugin::Type::Tool) )
{
m_toolsMenu->addAction( desc->logo->pixmap(), desc->displayName );
m_tools.push_back( ToolPlugin::instantiate( desc->name, /*this*/nullptr )
->createView(this) );
}
if( !m_toolsMenu->isEmpty() )
{
menuBar()->addMenu( m_toolsMenu )->setText( tr( "&Tools" ) );
connect( m_toolsMenu, SIGNAL(triggered(QAction*)),
this, SLOT(showTool(QAction*)));
const auto objectName = QString("ToolsMenuAction") + desc->displayName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why you use displayName while there is also name. Plugins are instantiated using name, so I guess name is more natural here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@irrenhaus3 Friendly reminder that this has an open comment.

m_tools[objectName] = ToolPlugin::instantiate(desc->name, nullptr)->createView(this);

//GUI
auto* action = m_toolsMenu->addAction( desc->logo->pixmap(), desc->displayName );
irrenhaus3 marked this conversation as resolved.
Show resolved Hide resolved
action->setObjectName(objectName);
connect(action, &QAction::triggered,
this, [this, action]{ this->showPluginTool(action->objectName()); });
}
menuBar()->addMenu(m_toolsMenu)->setText(tr("&Tools"));


// help-popup-menu
Expand Down Expand Up @@ -1366,12 +1366,15 @@ void MainWindow::timerEvent( QTimerEvent * _te)



void MainWindow::showTool( QAction * _idx )
void MainWindow::showPluginTool(const QString& which)
{
PluginView * p = m_tools[m_toolsMenu->actions().indexOf( _idx )];
p->show();
p->parentWidget()->show();
p->setFocus();
if (m_tools.contains(which))
{
auto* pluginView = m_tools[which];
pluginView->show();
pluginView->parentWidget()->show();
pluginView->setFocus();
}
}


Expand Down
Loading