1 /***************************************************************************
2                           rkmdiwindow  -  description
3                              -------------------
4     begin                : Tue Sep 26 2006
5     copyright            : (C) 2006 - 2017 by Thomas Friedrichsmeier
6     email                : thomas.friedrichsmeier@kdemail.net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef RKMDIWINDOW_H
19 #define RKMDIWINDOW_H
20 
21 #include <QFrame>
22 #include <QMap>
23 #include <QUrl>
24 
25 #include <kparts/part.h>
26 
27 #include "../settings/rksettings.h"
28 
29 class QEvent;
30 class QPaintEvent;
31 class RKWorkplace;
32 class RKToolWindowBar;
33 class KMessageWidget;
34 class RCommand;
35 
36 class RKMDIStandardActionClient : public KXMLGUIClient {
37 public:
38 	RKMDIStandardActionClient ();
39 	~RKMDIStandardActionClient ();
40 };
41 
42 /** Base class for rkward document mdi windows */
43 class RKMDIWindow : public QFrame {
44 	Q_OBJECT
45 public:
46 	enum Type {
47 		DataEditorWindow=1 << 0,
48 		CommandEditorWindow=1 << 1,
49 		OutputWindow=1 << 2,
50 		HelpWindow=1 << 3,
51 		X11Window=1 << 4,
52 		ObjectWindow=1 << 5,
53 		ConsoleWindow=1 << 10,
54 		CommandLogWindow=1 << 11,
55 		WorkspaceBrowserWindow=1 << 12,
56 		SearchHelpWindow=1 << 13,
57 		PendingJobsWindow=1 << 14,
58 		FileBrowserWindow=1 << 15,
59 		DebugConsoleWindow=1 << 16,
60 		CallstackViewerWindow=1 << 17,
61 		DebugMessageWindow=1 << 18,
62 
63 		DocumentWindow=1 << 29,
64 		ToolWindow=1 << 30,
65 		AnyType=DocumentWindow | ToolWindow
66 	};
67 
68 	enum State {
69 		Attached=1,
70 		Detached=2,
71 		AnyWindowState=Attached | Detached
72 	};
73 protected:
74 /** constructor
75 @param parent parent widget
76 @param type Type of window (see RKMDIWindow::Type).*/
77 	RKMDIWindow (QWidget *parent, int type, bool tool_window=false, const char *name=0);
78 	virtual ~RKMDIWindow ();
79 public slots:
80 /** Reimplemented from QWidget::setCaption () to emit the signal captionChanged () when the caption is changed. */
81 	void setCaption (const QString &caption);
82 public:
83 /** @returns true, if the window's document was modified (and would need to be saved) */
isModified()84 	virtual bool isModified () { return false; };
85 /** @returns A long / complete caption. Default implementation simply calls shortCaption () */
86 	virtual QString fullCaption ();
87 /** @returns A short caption (e.g. only the filename without the path). Default implementation simply calls QWidget::caption () */
88 	virtual QString shortCaption ();
89 /** @returns The corresponding KPart for this window */
getPart()90 	KParts::Part *getPart () { return part; };
91 /** Is this window attached (or detached)?
92 @returns true if attached, false if detached */
isAttached()93 	bool isAttached () const { return (state == Attached); };
94 /** Is this a tool window? */
isToolWindow()95 	bool isToolWindow () const { return (type & ToolWindow); };
96 /** Returns the type of this window */
isType(Type t)97 	bool isType (Type t) const { return (type & t); };
98 /** Activate (raise) this window, regardless of whether it is attached or detached
99 @param with_focus Should the window also get keyboard focus? */
100 	virtual void activate (bool with_focus=true);
101 /** If your mdi window should perform any adjustments before being attached, reimplement this function. Default implementation does nothing, but raises an assert, if this is a tool window */
102 	virtual void prepareToBeAttached ();
103 /** If your mdi window should perform any adjustments before being detached, reimplement this function. Default implementation does nothing, but raises an assert, if this is a tool window */
104 	virtual void prepareToBeDetached ();
105 /** Tool windows will only hide themselves, and ignore the also_delete flag */
106 	virtual bool close (bool also_delete);
107 /** Set a status message to be shown in a popup inside the window. The message persists until the given R command has finished, or until this function is called with an empty string.
108 This should be used, when the information shown is currently out-of-date (e.g. when refreshing a preview / loading a plot from history), _not_ when the window
109 is simply busy (e.g. when saving the current plot to history). */
110 	void setStatusMessage (const QString& message, RCommand* command=0);
111 /** Set a style hint for the window. So far the only interpreted style hint is "preview", and not all windows implement it. Base implements hiding of "active" indicator border for "preview"s. */
112 	virtual void setWindowStyleHint (const QString& hint);
113 
114 	bool eventFilter (QObject *watched, QEvent *e) override;
115 	bool acceptsEventsFor (QObject *object);
116 /** Whether the window is active. This seems to be more reliable than hasFocus () */
117 	bool isActive ();
118 /** Like isActive (), but also returns true, if this window _would_ be the active one, if the parent topLevelWindow() _was_ the active Window. */
119 	bool isActiveInsideToplevelWindow ();
120 /** Returns a pointer to an action collection suitable to place RKStandardAction in. This collection (and the corresponding KXMLGUIClient) is created on the fly. */
121 	KActionCollection *standardActionCollection ();
122 /** plugin-accessible properties of this object in the global context. Currently used only by RKEditorDataFrame to give information on the currently active data.frame. NOTE: ATM, you cannot set arbitrary properties. Only those supported in RKStandardComponent will have an effect. */
globalContextProperty(const QString & property)123 	QString globalContextProperty (const QString& property) { return global_context_properties.value (property); };
124 signals:
125 /** This signal is emitted, whenever the window caption was changed.
126 @param RKMDIWindow* a pointer to this window */
127 	void captionChanged (RKMDIWindow *);
128 /** This signal is emitted, when the window was activated *with* focus */
129 	void windowActivated (RKMDIWindow *);
130 protected slots:
131 	void showWindowHelp ();
132 	void showWindowSettings ();
133 	void clearStatusMessage ();
134 protected:
setPart(KParts::Part * p)135 	void setPart (KParts::Part *p) { part = p; };
136 	void setMetaInfo (const QString& generic_window_name, const QUrl& help_url, RKSettings::SettingsPage settings_page=RKSettings::NoPage);
137 	void initializeActivationSignals ();
138 	void paintEvent (QPaintEvent *e) override;
139 	void changeEvent (QEvent *event) override;
140 
141 /** reimplemented from QWidget to emulate focus-follows-mouse behavior */
142 	void enterEvent (QEvent *event) override;
143 /** @see globalContextProperty() */
setGlobalContextProperty(const QString & property,const QString & value)144 	void setGlobalContextProperty (const QString& property, const QString& value) { global_context_properties.insert (property, value); };
145 
146 	KMessageWidget* status_popup;
147 	QWidget* status_popup_container;
148 	void resizeEvent (QResizeEvent *ev) override;
149 
150 friend class RKWorkplace;
151 /** type of this window */
152 	int type;
153 private slots:
154 	void slotActivateForFocusFollowsMouse ();
155 private:
156 friend class RKToolWindowBar;
157 /** state of this window (attached / detached). This is usually set from the RKWorkplace */
158 	KParts::Part *part;
159 	State state;
160 	RKToolWindowBar *tool_window_bar;
161 	bool active;
162 	bool no_border_when_active;
163 	RKMDIStandardActionClient *standard_client;
164 /** @see globalContextProperty() */
165 	QMap<QString, QString> global_context_properties;
166 	QString generic_window_name;
167 	QUrl help_url;
168 	RKSettings::SettingsPage settings_page;
169 };
170 
171 #endif
172