libyui-qt-pkg  2.42.13
 All Classes Functions Variables Enumerations
YQPkgFilterTab.h
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgFilterTab.h
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38 /-*/
39 
40 #ifndef YQPkgFilterTab_h
41 #define YQPkgFilterTab_h
42 
43 #include <QWidget>
44 #include <QHash>
45 #include <QTabWidget>
46 #include "ImplPtr.h"
47 
49 class YQPkgFilterPage;
50 class YQPkgDiskUsageList;
51 class QAction;
52 
53 
54 /**
55  * Widget for "tabbed browsing" in packages:
56  *
57  * /------\/------\/------\
58  * [View v] | Tab1 || Tab2 || Tab3 | [Close]
59  * +-----------------+------------------------------------+
60  * | | |
61  * | QStackedWidget: | Right pane |
62  * | | |
63  * | Filter pages | (application defined) |
64  * | | |
65  * | | |
66  * | | |
67  * . . .
68  * . . .
69  * . . .
70  * | | |
71  * +-----------------+------------------------------------+
72  *
73  * Each filter page corresponds to one tab and a number of widgets in a
74  * QStackedWidget in the left filter pane. When tabs are switched, the
75  * corresponding filter page is raised to the top of the widget stack.
76  * The right pane, however, remains unchanged.
77  *
78  * Only a small numbers of filter pages is displayed as open tabs right
79  * away. Each of the other filter pages is shown in a new tabs when the user
80  * requests it via the pop-up menu on [View] button. Similarly, the tabs for all
81  * but the last filter pages can be closed with the [Close] button.
82  *
83  * The left (filter page) and right panes are separated with a user-moveable
84  * splitter.
85  **/
86 class YQPkgFilterTab: public QTabWidget
87 {
88  Q_OBJECT
89 
90 public:
91 
92  /**
93  * Constructor. 'settingsName' is the name to use to save and load settings.
94  **/
95  YQPkgFilterTab( QWidget * parent, const QString & settingsName );
96 
97  /**
98  * Destructor.
99  **/
100  virtual ~YQPkgFilterTab();
101 
102  /**
103  * Add a page with a user-visible "pageLabel", a widget with the page
104  * content and an internal name (or ID).
105  * 'pageContent' will be reparented to a subwidget of this class.
106  **/
107  void addPage( const QString & pageLabel,
108  QWidget * pageContent,
109  const QString & internalName );
110 
111  /**
112  * Return the right pane.
113  **/
114  QWidget * rightPane() const;
115 
116  /**
117  * Return the disk usage list widget or 0 if there is none.
118  **/
120 
121  /**
122  * Find a filter page by its content widget (the widget that was passed
123  * to addPage() ).
124  * Return 0 if there is no such page.
125  **/
126  YQPkgFilterPage * findPage( QWidget * pageContent );
127 
128  /**
129  * Find a filter page by its internal name.
130  * Return 0 if there is no such page.
131  **/
132  YQPkgFilterPage * findPage( const QString & internalName );
133 
134  /**
135  * Find a filter page by its tab index.
136  * Return 0 if there is no such page.
137  **/
138  YQPkgFilterPage * findPage( int tabIndex );
139 
140  /**
141  * Return the number of open tabs.
142  **/
143  int tabCount() const;
144 
145  /**
146  * Event filter to catch mouse right clicks on open tabs for the tab
147  * context menu. Returns 'true' if the event is processed and consumed,
148  * 'false' if processed should be continued by the watched object itself.
149  *
150  * Reimplemented from QObject.
151  **/
152  virtual bool eventFilter ( QObject * watchedObj, QEvent * event );
153 
154 
155 signals:
156 
157  /**
158  * Emitted when the current page changes.
159  * NOT emitted initially for the very first page that is shown.
160  **/
161  void currentChanged( QWidget * newPageContent );
162 
163 
164 public slots:
165 
166  /**
167  * Show a page. Create a tab for that page if it doesn't already exist.
168  **/
169  void showPage( QWidget * page );
170  void showPage( const QString & internalName );
171 
172  /**
173  * Close the current page unless this is the last visible page.
174  **/
175  void closeCurrentPage();
176 
177  /**
178  * Load settings, including which tabs are to be opened and in which order.
179  * Return 'true' if settings could be loaded, 'false' if not.
180  *
181  * Applications should call this after all pages have been added so the
182  * open tabs can be restored the same way as the user left the program.
183  * If tabCount() is still 0 afterwards, there were no settings, so it might
184  * make sense to open a number of default pages.
185  **/
186  void loadSettings();
187 
188  /**
189  * Save the current settings, including which tabs are currently open and
190  * in which order. This is implicitly done in the destructor.
191  **/
192  void saveSettings();
193 
194  /**
195  * Close all currently open pages.
196  **/
197  void closeAllPages();
198 
199 
200 protected slots:
201 
202  /**
203  * Show the page with the specified tab index.
204  **/
205  void showPage( int tabIndex );
206 
207  /**
208  * Show the page with the widget of this action's data().
209  **/
210  void showPage( QAction * action );
211 
212  /**
213  * Move the current tab page (from the context menu) one position to the
214  * left.
215  **/
216  void contextMovePageLeft();
217 
218  /**
219  * Move the current tab page (from the context menu) one position to the
220  * right.
221  **/
222  void contextMovePageRight();
223 
224  /**
225  * Close the current tab page (from the context menu).
226  **/
227  void contextClosePage();
228 
229 
230 protected:
231 
232  /**
233  * Show a page.
234  **/
235  void showPage( YQPkgFilterPage * page );
236 
237  /**
238  * Open the tab context menu for the tab at the specified position.
239  * Return 'true' upon success (i.e., there is a tab at that position),
240  * 'false' upon failure.
241  **/
242  bool postTabContextMenu( const QPoint & pos );
243 
244  /**
245  * Swap two tabs and adjust their tab indices accordingly.
246  **/
247  void swapTabs( YQPkgFilterPage * page1, YQPkgFilterPage * page2 );
248 
249 
250 private:
251 
252  ImplPtr<YQPkgFilterTabPrivate> priv;
253 };
254 
255 
256 
257 /**
258  * Helper class for filter pages
259  **/
261 {
262  YQPkgFilterPage( const QString & pageLabel,
263  QWidget * content,
264  const QString & internalName )
265  : content( content )
266  , label( pageLabel )
267  , id( internalName )
268  , closeEnabled( true )
269  , tabIndex( -1 )
270  {}
271 
272  QWidget * content;
273  QString label; // user visible text
274  QString id; // internal name
275  bool closeEnabled;
276  int tabIndex; // index of the corresponding tab or -1 if none
277 };
278 
279 
280 #endif // YQPkgFilterTab_h
void contextMovePageRight()
bool postTabContextMenu(const QPoint &pos)
void showPage(QWidget *page)
QWidget * rightPane() const
void addPage(const QString &pageLabel, QWidget *pageContent, const QString &internalName)
virtual ~YQPkgFilterTab()
YQPkgDiskUsageList * diskUsageList() const
YQPkgFilterTab(QWidget *parent, const QString &settingsName)
void swapTabs(YQPkgFilterPage *page1, YQPkgFilterPage *page2)
void currentChanged(QWidget *newPageContent)
virtual bool eventFilter(QObject *watchedObj, QEvent *event)
YQPkgFilterPage * findPage(QWidget *pageContent)
void contextMovePageLeft()
int tabCount() const
List of disk usage of all attached partitions.