1 /****************************************************************************************
2  * Copyright (c) 2008 Peter ZHOU <peterzhoulei@gmail.com>                               *
3  * Copyright (c) 2013-2014 Anmol Ahuja <darthcodus@gmail.com>                           *
4  *                                                                                      *
5  * This program is free software; you can redistribute it and/or modify it under        *
6  * the terms of the GNU General Public License as published by the Free Software        *
7  * Foundation; either version 2 of the License, or (at your option) any later           *
8  * version.                                                                             *
9  *                                                                                      *
10  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
12  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
13  *                                                                                      *
14  * You should have received a copy of the GNU General Public License along with         *
15  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
16  ****************************************************************************************/
17 
18 #ifndef AMAROK_WINDOW_SCRIPT_H
19 #define AMAROK_WINDOW_SCRIPT_H
20 
21 #include <QFont>
22 #include <QMap>
23 #include <QMetaType>
24 #include <QObject>
25 #include <QPalette>
26 #include <QString>
27 #include <QPointer>
28 
29 class QMenu;
30 class QMainWindow;
31 class QMenu;
32 
33 namespace AmarokScript
34 {
35     class AmarokScriptEngine;
36     // SCRIPTDOX: Amarok.Window
37     class AmarokWindowScript : public QObject
38     {
39         Q_OBJECT
40 
41         Q_PROPERTY( bool isTrayIconShown READ isTrayIconShown )
42         Q_PROPERTY( QString activeBrowserName READ activeBrowserName )
43         Q_PROPERTY( QMainWindow* mainWindow READ mainWindow )
44         /**
45          * Convenience method for mainWindow.styleSheet and setStyleSheet
46          */
47         Q_PROPERTY( QString styleSheet READ styleSheet WRITE setStyleSheet )
48         Q_PROPERTY( QFont font READ font WRITE setFont )
49         Q_PROPERTY( QPalette palette READ palette WRITE setPalette )
50 
51         public:
52             explicit AmarokWindowScript( AmarokScriptEngine* scriptEngine );
53 
54             Q_INVOKABLE void addToolsMenu( QMenu *menu );
55             Q_INVOKABLE void addSettingsMenu( QMenu *menu );
56             Q_INVOKABLE bool addToolsMenu( const QString &id, const QString &menuTitle, const QString &icon = QStringLiteral("amarok") );
57             Q_INVOKABLE void addToolsSeparator();
58             Q_INVOKABLE bool addSettingsMenu( const QString &id, const QString &actionName, const QString &icon = QStringLiteral("amarok") );
59             Q_INVOKABLE bool addCustomAction( const QString &menuName, const QString &id, const QString &actionName, const QString &icon = QStringLiteral("amarok") );
60             Q_INVOKABLE void addSettingsSeparator();
61             Q_INVOKABLE void showTrayIcon( bool show );
62 
63             /**
64              * Show tooltips with the widget's name on mouseover.
65              *
66              * Must restart Amarok after invoking this function to revert tooltips
67              * to normal.
68              */
69             Q_INVOKABLE void showToolTip();
70 
71         Q_SIGNALS:
72             void prepareToQuit();
73             void newPalette( QPalette );
74 
75         private:
76             /**
77               * adds an action with the given ID and title to the given menu
78               *
79               * @param menu the menu to which the action will be added
80               * @param id the ID of the action
81               * @param actionName the title of the action
82               * @param menuProperty the name of the menu property for the script engine
83               * @param icon the icon for the action
84               *
85               * @return true if adding the action was successful, false otherwise
86               */
87             bool addMenuAction( QMenu *menu, const QString &id, const QString &actionName, const QString &menuProperty, const QString &icon );
88 
89             QString activeBrowserName();
90             bool isTrayIconShown();
91             QMainWindow* mainWindow();
92             void setStyleSheet( const QString &styleSheet );
93             QString styleSheet() const;
94             QFont font() const;
95             void setFont( const QFont &font );
96             QPalette palette() const;
97             void setPalette( const QPalette & palette );
98 
99             QMap<QString, QMenu*> m_customMenus;
100             QPointer<QMenu> m_toolsMenu;
101             QPointer<QMenu> m_settingsMenu;
102             AmarokScriptEngine*   m_scriptEngine;
103     };
104 }
105 
106 Q_DECLARE_METATYPE( QMainWindow* )
107 Q_DECLARE_METATYPE( QPalette )
108 
109 #endif
110