Fix no newlines warnings. Patch by Peter Oberndorfer
[kdevelopdvcssupport.git] / sublime / ideal.h
blobc2b24ac2eeee11c4a0bd8cd55c2dba34c1eeeaea
1 /*
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
9 documentation.
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
25 #include <QtGui>
27 #include "ideallayout.h"
28 #include "sublimedefs.h"
30 class KAction;
31 class KActionMenu;
32 class KActionCollection;
34 namespace Sublime {
36 class Area;
37 class View;
38 class MainWindow;
40 class IdealToolButton: public QToolButton
42 Q_OBJECT
44 public:
45 IdealToolButton(Qt::DockWidgetArea area, QWidget *parent = 0);
47 Qt::Orientation orientation() const;
49 virtual QSize sizeHint() const;
51 protected:
52 virtual void paintEvent(QPaintEvent *event);
54 private:
55 Qt::DockWidgetArea _area;
58 class IdealDockWidgetButton: public QToolButton
60 Q_OBJECT
62 public:
63 IdealDockWidgetButton(QWidget *parent = 0);
64 virtual ~IdealDockWidgetButton();
66 QSize sizeHint() const;
67 QSize minimumSizeHint() const;
69 protected:
70 virtual void enterEvent(QEvent *event);
71 virtual void leaveEvent(QEvent *event);
72 virtual void paintEvent(QPaintEvent *event);
76 class IdealButtonBarWidget: public QWidget
78 Q_OBJECT
80 public:
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;
94 private Q_SLOTS:
95 void showWidget(bool checked);
96 void anchor(bool anchor);
97 void maximize(bool maximized);
98 void actionToggled(bool state);
100 protected:
101 virtual void actionEvent(QActionEvent *event);
103 private:
104 Qt::DockWidgetArea _area;
105 QHash<QAction *, IdealToolButton *> _buttons;
106 QHash<QAction *, IdealDockWidget*> _widgets;
107 QActionGroup* _actions;
110 class IdealDockWidget : public QDockWidget
112 Q_OBJECT
114 public:
115 IdealDockWidget(QWidget *parent);
116 virtual ~IdealDockWidget();
118 Area *area() const;
119 void setArea(Area *area);
121 View *view() const;
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);
139 Q_SIGNALS:
140 void anchor(bool anchor);
141 void maximize(bool maximize);
142 void close();
144 private Q_SLOTS:
145 void slotMaximize(bool maximized);
146 void slotRemove();
148 private:
149 Qt::Orientation m_orientation;
150 QAbstractButton* m_anchor;
151 QAbstractButton* m_close;
152 Area *m_area;
153 View *m_view;
154 Qt::DockWidgetArea m_docking_area;
155 bool m_maximized;
158 class View;
160 class IdealMainWidget : public QWidget
162 Q_OBJECT
164 public:
165 IdealMainWidget(MainWindow* parent, KActionCollection* ac);
167 // Public api
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);
178 // Internal api
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);
203 Q_SIGNALS:
204 void dockShown(Sublime::View*, Sublime::Position pos, bool shown);
206 public Q_SLOTS:
207 void showLeftDock(bool show);
208 void showRightDock(bool show);
209 void showBottomDock(bool show);
210 void showTopDock(bool show);
211 void toggleDocksShown();
212 void focusEditor();
213 void anchorCurrentDock(bool anchor);
214 void maximizeCurrentDock(bool maximized);
215 void selectNextDock();
216 void selectPreviousDock();
217 void removeView();
219 private:
220 // helpers for toggleDocksShown
221 bool allDocksHidden();
222 bool someDockMaximized();
223 void restorePreviouslyShownDocks();
224 void hideAllShownDocks();
226 private:
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
259 Q_OBJECT
261 public:
262 IdealSplitterHandle(Qt::Orientation orientation, QWidget* parent, IdealMainLayout::Role resizeRole);
264 Q_SIGNALS:
265 void resize(int thickness, IdealMainLayout::Role resizeRole);
267 protected:
268 virtual void paintEvent(QPaintEvent* event);
269 virtual void mouseMoveEvent(QMouseEvent* event);
270 virtual void mousePressEvent(QMouseEvent* event);
272 private:
273 inline int convert(const QPoint& pos) const { return m_orientation == Qt::Horizontal ? pos.y() : pos.x(); }
275 Qt::Orientation m_orientation;
276 bool m_hover;
277 int m_dragStart;
278 IdealMainLayout::Role m_resizeRole;
283 #endif