2 Copyright 2007 Roberto Raggi <roberto@kdevelop.org>
3 Copyright 2007 Hamish Rodda <rodda@kde.org>
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #ifndef SUBLIME_IDEAL_H
23 #define SUBLIME_IDEAL_H
27 #include "ideallayout.h"
28 #include "sublimedefs.h"
32 class KActionCollection
;
40 class IdealToolButton
: public QToolButton
45 IdealToolButton(Qt::DockWidgetArea area
, QWidget
*parent
= 0);
47 Qt::Orientation
orientation() const;
49 virtual QSize
sizeHint() const;
52 virtual void paintEvent(QPaintEvent
*event
);
55 Qt::DockWidgetArea _area
;
58 class IdealDockWidgetButton
: public QToolButton
63 IdealDockWidgetButton(QWidget
*parent
= 0);
64 virtual ~IdealDockWidgetButton();
66 QSize
sizeHint() const;
67 QSize
minimumSizeHint() const;
70 virtual void enterEvent(QEvent
*event
);
71 virtual void leaveEvent(QEvent
*event
);
72 virtual void paintEvent(QPaintEvent
*event
);
76 class IdealButtonBarWidget
: public QWidget
81 IdealButtonBarWidget(Qt::DockWidgetArea area
, class IdealMainWidget
*parent
= 0);
83 KAction
*addWidget(const QString
& title
, IdealDockWidget
*widget
,
84 Area
* area
, View
*view
);
85 void showWidget(IdealDockWidget
* widget
);
86 void removeAction(QAction
* action
);
88 IdealMainWidget
* parentWidget() const;
90 Qt::Orientation
orientation() const;
92 IdealDockWidget
* widgetForAction(QAction
* action
) const;
95 void showWidget(bool checked
);
96 void anchor(bool anchor
);
97 void maximize(bool maximized
);
98 void actionToggled(bool state
);
101 virtual void actionEvent(QActionEvent
*event
);
104 Qt::DockWidgetArea _area
;
105 QHash
<QAction
*, IdealToolButton
*> _buttons
;
106 QHash
<QAction
*, IdealDockWidget
*> _widgets
;
107 QActionGroup
* _actions
;
110 class IdealDockWidget
: public QDockWidget
115 IdealDockWidget(QWidget
*parent
);
116 virtual ~IdealDockWidget();
119 void setArea(Area
*area
);
122 void setView(View
*view
);
124 Qt::DockWidgetArea
dockWidgetArea() const;
125 void setDockWidgetArea(Qt::DockWidgetArea dockingArea
);
127 bool isAnchored() const;
128 void setAnchored(bool anchored
, bool emitSignals
);
130 bool isMaximized() const;
131 void setMaximized(bool maximized
);
133 virtual bool event(QEvent
*event
);
135 protected: // QWidget overrides
136 virtual void contextMenuEvent(QContextMenuEvent
*);
137 virtual void mouseDoubleClickEvent(QMouseEvent
*event
);
140 void anchor(bool anchor
);
141 void maximize(bool maximize
);
145 void slotMaximize(bool maximized
);
149 Qt::Orientation m_orientation
;
150 QAbstractButton
* m_anchor
;
151 QAbstractButton
* m_close
;
154 Qt::DockWidgetArea m_docking_area
;
160 class IdealMainWidget
: public QWidget
165 IdealMainWidget(MainWindow
* parent
, KActionCollection
* ac
);
168 void setCentralWidget(QWidget
* widget
);
169 QAction
* actionForView(View
* view
) const;
170 void addView(Qt::DockWidgetArea area
, View
* View
);
171 void raiseView(View
* view
);
172 /** Remove view. If nondestructive true, view->widget()
173 is not deleted, as is left with NULL parent.
174 Otherwise, it's deleted. */
175 void removeView(View
* view
, bool nondestructive
= false);
176 void moveView(View
*view
, Qt::DockWidgetArea area
);
180 // TODO can move the object filter here with judicious focusProxy?
181 void centralWidgetFocused();
183 void showDockWidget(IdealDockWidget
* widget
, bool show
);
184 void showDock(IdealMainLayout::Role role
, bool show
);
186 void anchorDockWidget(IdealDockWidget
* widget
, bool anchor
);
188 IdealMainLayout
* mainLayout() const;
190 void anchorDockWidget(bool checked
, IdealButtonBarWidget
* bar
);
191 void maximizeDockWidget(bool checked
, IdealButtonBarWidget
* bar
);
193 QWidget
* firstWidget(IdealMainLayout::Role role
) const;
195 IdealButtonBarWidget
* barForRole(IdealMainLayout::Role role
) const;
196 IdealMainLayout::Role
roleForBar(IdealButtonBarWidget
* bar
) const;
197 KAction
* actionForRole(IdealMainLayout::Role role
) const;
199 void setAnchorActionStatus(bool checked
);
200 void setMaximizeActionStatus(bool checked
);
201 void setShowDockStatus(IdealMainLayout::Role role
, bool checked
);
204 void dockShown(Sublime::View
*, Sublime::Position pos
, bool shown
);
207 void showLeftDock(bool show
);
208 void showRightDock(bool show
);
209 void showBottomDock(bool show
);
210 void showTopDock(bool show
);
211 void toggleDocksShown();
213 void anchorCurrentDock(bool anchor
);
214 void maximizeCurrentDock(bool maximized
);
215 void selectNextDock();
216 void selectPreviousDock();
220 // helpers for toggleDocksShown
221 bool allDocksHidden();
222 bool someDockMaximized();
223 void restorePreviouslyShownDocks();
224 void hideAllShownDocks();
227 IdealButtonBarWidget
*leftBarWidget
;
228 IdealButtonBarWidget
*rightBarWidget
;
229 IdealButtonBarWidget
*bottomBarWidget
;
230 IdealButtonBarWidget
*topBarWidget
;
232 KAction
* m_showLeftDock
;
233 KAction
* m_showRightDock
;
234 KAction
* m_showBottomDock
;
235 KAction
* m_showTopDock
;
236 KAction
* m_anchorCurrentDock
;
237 KAction
* m_maximizeCurrentDock
;
238 KActionMenu
* m_docks
;
240 class IdealMainLayout
* m_mainLayout
;
242 QMap
<IdealDockWidget
*, Qt::DockWidgetArea
> docks
;
243 /** Map from View to an action that shows/hides
244 the IdealDockWidget containing that view. */
245 QMap
<View
*, QAction
*> m_view_to_action
;
246 /** Map from IdealDockWidget to an action that shows/hides
247 that IdealDockWidget. */
248 QMap
<IdealDockWidget
*, QAction
*> m_dockwidget_to_action
;
250 bool m_centralWidgetFocusing
;
252 /** Tooldock views that were shown before hideAllDocks activated */
253 QList
<View
*> m_previouslyShownDocks
;
254 bool m_switchingDocksShown
;
257 class IdealSplitterHandle
: public QWidget
262 IdealSplitterHandle(Qt::Orientation orientation
, QWidget
* parent
, IdealMainLayout::Role resizeRole
);
265 void resize(int thickness
, IdealMainLayout::Role resizeRole
);
268 virtual void paintEvent(QPaintEvent
* event
);
269 virtual void mouseMoveEvent(QMouseEvent
* event
);
270 virtual void mousePressEvent(QMouseEvent
* event
);
273 inline int convert(const QPoint
& pos
) const { return m_orientation
== Qt::Horizontal
? pos
.y() : pos
.x(); }
275 Qt::Orientation m_orientation
;
278 IdealMainLayout::Role m_resizeRole
;