From 5e57ab35afe0d5ddd960921a76ea11f22561f287 Mon Sep 17 00:00:00 2001 From: mio Date: Tue, 21 Jan 2025 17:00:36 +1000 Subject: [PATCH] Add context menu to status bar It adds an item which toggles the visibility of the Analyzer when watching videos. Signed-off-by: mio --- src/app/mainWindow.cpp | 32 ++++++++++++++++++++++++++++++++ src/app/mainWindow.h | 6 ++++++ src/app/stateChange.cpp | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/app/mainWindow.cpp b/src/app/mainWindow.cpp index 78bf592..54204e9 100644 --- a/src/app/mainWindow.cpp +++ b/src/app/mainWindow.cpp @@ -11,6 +11,7 @@ #include #include //::open() #include //::timerEvent() +#include #include #include #include @@ -108,6 +109,9 @@ MainWindow::MainWindow() setStandardToolBarMenuEnabled( false ); //bah to setupGUI()! toolBar()->show(); //it's possible it would be hidden, but we don't want that as no UI way to show it! + m_showAnalyzer = config("MainWindow")->readBoolEntry("showAnalyzer", true); + m_analyzer->setShown(m_showAnalyzer); + // only show dvd button when playing a dvd { struct KdeIsTehSuck : public TQObject @@ -241,6 +245,9 @@ MainWindow::~MainWindow() bool MainWindow::queryExit() { + config("MainWindow")->writeEntry("showAnalyzer", m_showAnalyzer); + config("MainWindow")->sync(); + if( toggleAction( "fullscreen" )->isChecked() ) { // there seems to be no other way to stop TDEMainWindow // saving the window state without any controls @@ -311,6 +318,24 @@ MainWindow::readProperties( TDEConfig *config ) engine()->play( config->readNumEntry( "time" ) ); } +void +MainWindow::contextMenuEvent(TQContextMenuEvent *ev) +{ + TQRect statusBarRect(mapTo(this, statusBar()->pos()), statusBar()->size()); + if (statusBarRect.contains(ev->pos()) && TheStream::hasVideo()) + { + ev->accept(); + + TDEPopupMenu menu; + menu.setCheckable(true); + + int id = menu.insertItem(i18n("Toggle Analyzer"), this, TQ_SLOT(toggleAnalyzer())); + menu.setItemChecked(id, m_analyzer->isVisible()); + + menu.exec(ev->globalPos()); + } +} + void MainWindow::timerEvent( TQTimerEvent* ) { @@ -360,6 +385,13 @@ MainWindow::showTime( int pos ) m_timeLabel->setText( time ); } +void +MainWindow::toggleAnalyzer() +{ + m_showAnalyzer = !m_showAnalyzer; + m_analyzer->setShown(m_showAnalyzer); +} + void MainWindow::engineMessage( const TQString &message ) { diff --git a/src/app/mainWindow.h b/src/app/mainWindow.h index 3dae1e8..fbb6be4 100644 --- a/src/app/mainWindow.h +++ b/src/app/mainWindow.h @@ -46,6 +46,7 @@ namespace Codeine void fullScreenToggled( bool ); void setAudioChannels(const TQStringList&) const; void setSubtitleChannels(const TQStringList&) const; + void toggleAnalyzer(); private: void setupActions(); @@ -55,6 +56,7 @@ namespace Codeine TQPopupMenu *menu(const TQString&); + void contextMenuEvent(TQContextMenuEvent *event) override; virtual void timerEvent( TQTimerEvent* ); virtual void dragEnterEvent( TQDragEnterEvent* ); virtual void dropEvent( TQDropEvent* ); @@ -73,6 +75,10 @@ namespace Codeine TQWidgetStack *m_widgetStack; VolumeAction *m_volumeAction; + // Keep track of Analyzer visibility separately so swapping between + // Video & Audio correctly restores the state without re-reading the config. + bool m_showAnalyzer; + //undefined MainWindow( const MainWindow& ); MainWindow &operator=( const MainWindow& ); diff --git a/src/app/stateChange.cpp b/src/app/stateChange.cpp index 73f77d0..2418209 100644 --- a/src/app/stateChange.cpp +++ b/src/app/stateChange.cpp @@ -106,7 +106,7 @@ MainWindow::engineStateChanged( Engine::State state ) /// update statusBar { using namespace Engine; - m_analyzer->setShown(state & (Playing | Paused) && (TheStream::hasVideo() && TheStream::hasAudio())); + m_analyzer->setShown(m_showAnalyzer && (TheStream::hasVideo() && TheStream::hasAudio())); m_timeLabel->setShown(state & (Playing | Paused)); }