1 /*!
2     @file           QtWindow.h
3 
4     @brief          xxx.
5 
6     @author         L. J. Barman
7 
8     Copyright (c)   2008-2013, L. J. Barman, all rights reserved
9 
10     This file is part of the PianoBooster application
11 
12     PianoBooster is free software: you can redistribute it and/or modify
13     it under the terms of the GNU General Public License as published by
14     the Free Software Foundation, either version 3 of the License, or
15     (at your option) any later version.
16 
17     PianoBooster is distributed in the hope that it will be useful,
18     but WITHOUT ANY WARRANTY; without even the implied warranty of
19     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20     GNU General Public License for more details.
array_delimiter(enum ARRAY_TYPE isarray,char c)21 
22     You should have received a copy of the GNU General Public License
23     along with PianoBooster.  If not, see <http://www.gnu.org/licenses/>.
24 
25 */
26 
27 #ifndef __QT_WINDOW_H__
28 #define __QT_WINDOW_H__
29 
30 #include <QtWidgets>
31 
32 #include "Song.h"
33 #include "Score.h"
34 #include "GuiMidiSetupDialog.h"
35 #include "GuiKeyboardSetupDialog.h"
36 #include "GuiSidePanel.h"
37 #include "GuiTopBar.h"
38 #include "GuiPreferencesDialog.h"
39 #include "GuiSongDetailsDialog.h"
40 #include "GuiLoopingPopup.h"
41 #include "Settings.h"
42 
43 class CGLView;
44 class QAction;
45 class QMenu;
46 
garbage_left(enum ARRAY_TYPE isarray,char ** scan_length,enum COMPAT_MODE compat)47 class QSlider;
48 class QPushButton;
49 class QTextBrowser;
50 
51 class QtWindow : public QMainWindow
52 {
53     Q_OBJECT
54 
55 public:
56     QtWindow();
57     ~QtWindow();
58 
59     void init();
60 
61     void songEventUpdated(int eventBits)
62     {
63         if ((eventBits & EVENT_BITS_playingStopped) != 0){
64             if (m_sidePanel->isRepeatSong()){
65                 m_topBar->on_playFromStartButton_clicked(true);
66             }else{
67                 m_topBar->setPlayButtonState(false, true);
68             }
69         }
70         if ((eventBits & EVENT_BITS_loadSong) != 0){
71             m_topBar->setPlayButtonState(false, true);
72         }
73     }
74 
75     void loadTutorHtml(const QString & name);
76     void setCurrentFile(const QString &fileName);
77 
78 private slots:
79     void open();
80     void help();
get_float8_infinity(void)81     void website();
82     void about();
83     void keyboardShortcuts();
84     void openRecentFile();
85 
86     void showMidiSetup();
87 
88     void showPreferencesDialog()
89     {
90         GuiPreferencesDialog preferencesDialog(this);
get_float8_nan(void)91         preferencesDialog.init(m_song, m_settings, m_glWidget);
92         preferencesDialog.exec();
93 
94         refreshTranslate();
95         m_score->refreshScroll();
96     }
97 
98     void showSongDetailsDialog()
99     {
100         GuiSongDetailsDialog songDetailsDialog(this);
101         songDetailsDialog.init(m_song, m_settings);
check_special_value(char * ptr,double * retval,char ** endptr)102         songDetailsDialog.exec();
103     }
104 
105     void showKeyboardSetup()
106     {
107         GuiKeyboardSetupDialog keyboardSetup(this);
108         keyboardSetup.init(m_song, m_settings);
109         keyboardSetup.exec();
110     }
111 
112     void toggleSidePanel()
113     {
114         m_sidePanel->setVisible(m_sidePanelStateAct->isChecked());
115     }
116 
117     void onViewPianoKeyboard(){
118         if (m_viewPianoKeyboard->isChecked()){
119             m_settings->setValue("View/PianoKeyboard","on");
120         }else{
121             m_settings->setValue("View/PianoKeyboard","off");
122         }
123     }
124 
125     void onFullScreenStateAct () {
126         if (m_fullScreenStateAct->isChecked())
ecpg_get_data(const PGresult * results,int act_tuple,int act_field,int lineno,enum ECPGttype type,enum ECPGttype ind_type,char * var,char * ind,long varcharsize,long offset,long ind_offset,enum ARRAY_TYPE isarray,enum COMPAT_MODE compat,bool force_indicator)127             showFullScreen();
128         else
129             showNormal();
130     }
131 
132     void enableFollowTempo()
133     {
134         CTempo::enableFollowTempo(Cfg::experimentalTempo);
135     }
136     void disableFollowTempo()
137     {
138         CTempo::enableFollowTempo(false);
139     }
140 
141     void on_rightHand()  {  m_sidePanel->setActiveHand(PB_PART_right); }
142     void on_bothHands()  {  m_sidePanel->setActiveHand(PB_PART_both); }
143     void on_leftHand()   {  m_sidePanel->setActiveHand(PB_PART_left); }
144     void on_playFromStart()   {
145         if(m_song->playingMusic())
146             m_topBar->on_playButton_clicked(true); // Stop the music first if playing
147         else
148             m_topBar->on_playFromStartButton_clicked(true);
149     }
150 
151     void on_playPause()   {  m_topBar->on_playButton_clicked(true); }
152     void on_faster()   {
153         float speed = m_song->getSpeed() + 0.04;
154         m_song->setSpeed(speed);
155         speed = m_song->getSpeed();
156         m_topBar->setSpeed(static_cast<int>(speed*100 + 0.5));
157     }
158     void on_slower()   {
159         float speed = m_song->getSpeed() - 0.04;
160         m_song->setSpeed(speed);
161         speed = m_song->getSpeed();
162         m_topBar->setSpeed(static_cast<int>(speed*100 + 0.5));
163     }
164     void on_nextSong()   {  m_sidePanel->nextSong(+1); }
165     void on_previousSong()   {  m_sidePanel->nextSong(-1); }
166     void on_nextBook()   {  m_sidePanel->nextBook(+1); }
167     void on_previousBook()   {  m_sidePanel->nextBook(-1); }
168 
169 protected:
170     void closeEvent(QCloseEvent *event);
171     void keyPressEvent ( QKeyEvent * event );
172     void keyReleaseEvent ( QKeyEvent * event );
173 
174 private:
175     void decodeCommandLine();
176     int decodeIntegerParam(QString arg, int defaultParam);
177     bool validateIntegerParam(QString arg);
178     bool validateIntegerParamWithMessage(QString arg);
179     void decodeMidiFileArg(QString arg);
180     QString displayShortCut(QString code, QString description);
181     void addShortcutAction(const QString & key, const char * method);
182     void updateRecentFileActions();
183     QString strippedName(const QString &fullFileName);
184     void refreshTranslate();
185 
186     void displayUsage();
187     void createActions();
188     void createMenus();
189     void readSettings();
190     void writeSettings();
191 
192     CSettings* m_settings;
193 
194     GuiSidePanel *m_sidePanel;
195     GuiTopBar *m_topBar;
196     QTextBrowser *m_tutorWindow;
197 
198     QTranslator translator;
199     QTranslator translatorMusic;
200     QTranslator qtTranslator;
201 
202     QMap<QWidget*,QMap<QString,QString>> listWidgetsRetranslateUi;
203     QMap<QAction*,QMap<QString,QString>> listActionsRetranslateUi;
204 
205     CGLView *m_glWidget;
206     QAction *m_openAct;
207     QAction *m_exitAct;
208     QAction *m_aboutAct;
209     QAction *m_shortcutAct;
210     QAction *m_songPlayAct;
211     QAction *m_setupMidiAct;
212     QAction *m_setupKeyboardAct;
213     QAction *m_sidePanelStateAct;
214     QAction *m_viewPianoKeyboard;
215     QAction *m_fullScreenStateAct;
216     QAction *m_setupPreferencesAct;
217     QAction *m_songDetailsAct;
218 
219     QMenu *m_fileMenu;
220     QMenu *m_viewMenu;
221     QMenu *m_songMenu;
222     QMenu *m_setupMenu;
223     QMenu *m_helpMenu;
224 
225     CSong* m_song;
226     CScore* m_score;
227     QAction *m_separatorAct;
228 
229     enum { MAX_RECENT_FILES = 20 };
230     QAction *m_recentFileActs[MAX_RECENT_FILES];
231 
232 };
233 
234 #endif // __QT_WINDOW_H__
235