]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgRepoFilterView.cc
- Don't create layouts with parent. Qt 4.x automatically reparents
[duncan/yast2-qt4.git] / src / pkg / YQPkgRepoFilterView.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:         YQPkgRepoFilterView.cc
14
15   Author:       Stefan Hundhammer <sh@suse.de>
16
17   Textdomain    "packages-qt"
18
19 /-*/
20
21
22 #define y2log_component "qt-pkg"
23 #include <ycp/y2log.h>
24
25 #include <qsplitter.h>
26
27 #include "QY2ComboTabWidget.h"
28 #include "QY2LayoutUtils.h"
29 #include <QVBoxLayout>
30 #include <QFrame>
31 #include "YQPkgRepoFilterView.h"
32 #include "YQPkgRepoList.h"
33 #include "YQPkgRpmGroupTagsFilterView.h"
34 #include "YQPkgSearchFilterView.h"
35 #include "YQPkgStatusFilterView.h"
36 #include "YQi18n.h"
37
38 #define MARGIN                  4
39
40
41 YQPkgRepoFilterView::YQPkgRepoFilterView( QWidget * parent )
42     : QWidget( parent )
43 {
44     QSplitter * splitter = new QSplitter( Qt::Vertical, this );
45     Q_CHECK_PTR( splitter );
46
47     //QVBoxLayout * upper_vbox = new QVBoxLayout( splitter );
48     
49     _repoList = new YQPkgRepoList( this );
50     //upper_vbox->addWidget(_repoList);
51     splitter->addWidget(_repoList);
52     
53     Q_CHECK_PTR( _repoList );
54     _repoList->setSizePolicy( QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Expanding ) );// hor/vert
55
56     //addVSpacing( upper_vbox, MARGIN );
57
58
59     // Directly propagate signals filterStart() and filterFinished()
60     // from primary filter to the outside
61
62     connect( _repoList, SIGNAL( filterStart() ),
63              this,              SIGNAL( filterStart() ) );
64
65     connect( _repoList, SIGNAL( filterFinished() ),
66              this,              SIGNAL( filterFinished() ) );
67
68
69     // Redirect filterMatch() and filterNearMatch() signals to secondary filter
70
71     connect( _repoList, SIGNAL( filterMatch             ( ZyppSel, ZyppPkg ) ),
72              this,              SLOT  ( primaryFilterMatch      ( ZyppSel, ZyppPkg ) ) );
73
74     connect( _repoList, SIGNAL( filterNearMatch         ( ZyppSel, ZyppPkg ) ),
75              this,              SLOT  ( primaryFilterNearMatch  ( ZyppSel, ZyppPkg ) ) );
76
77 #if 0
78     QWidget * secondary_filters =
79 #endif
80     layoutSecondaryFilters( splitter );
81
82 #if 0
83     splitter->setResizeMode( _repoList, QSplitter::Stretch        );
84     splitter->setResizeMode( secondary_filters, QSplitter::FollowSizeHint );
85 #endif
86 }
87
88
89 YQPkgRepoFilterView::~YQPkgRepoFilterView()
90 {
91     // NOP
92 }
93
94
95 QWidget *
96 YQPkgRepoFilterView::layoutSecondaryFilters( QWidget * parent )
97 {
98     QWidget *vbox = new QWidget(parent);
99     Q_CHECK_PTR( vbox );
100
101     QVBoxLayout *layout = new QVBoxLayout();
102     vbox->setLayout(layout);
103     
104     layout->addSpacing( MARGIN );
105
106     // Translators: This is a combo box where the user can apply a secondary filter
107     // in addition to the primary filter by repository - one of
108     // "All packages", "RPM groups", "search", "summary"
109     //
110     // And yes, the colon really belongs there since this is one of the very
111     // few cases where a combo box label is left to the combo box rather than
112     // above it.
113     _secondaryFilters = new QY2ComboTabWidget( _( "&Secondary Filter:" ));
114     layout->addWidget(_secondaryFilters);
115
116     Q_CHECK_PTR( _secondaryFilters );
117
118 //     _secondaryFilters->setFrameStyle( Q3Frame::Plain );
119 //     _secondaryFilters->setLineWidth( 0 );
120 //     _secondaryFilters->setMidLineWidth( 0 );
121 //     _secondaryFilters->setMargin( 0 );
122
123
124     //
125     // All Packages
126     //
127
128     _allPackages = new QWidget( this );
129     layout->addWidget(_allPackages);
130     Q_CHECK_PTR( _allPackages );
131     _secondaryFilters->addPage( _( "All Packages" ), _allPackages );
132
133
134     //
135     // RPM Groups
136     //
137
138     _rpmGroupTagsFilterView = new YQPkgRpmGroupTagsFilterView( this );
139     layout->addWidget(_rpmGroupTagsFilterView);
140
141     Q_CHECK_PTR( _rpmGroupTagsFilterView );
142     _secondaryFilters->addPage( _( "Package Groups" ), _rpmGroupTagsFilterView );
143
144     connect( _rpmGroupTagsFilterView,   SIGNAL( filterStart() ),
145              _repoList,         SLOT  ( filter()      ) );
146
147
148     //
149     // Package search view
150     //
151
152     _searchFilterView = new YQPkgSearchFilterView(this);
153     layout->addWidget(_searchFilterView);
154     Q_CHECK_PTR( _searchFilterView );
155     _secondaryFilters->addPage( _( "Search" ), _searchFilterView );
156
157     connect( _searchFilterView, SIGNAL( filterStart() ),
158              _repoList, SLOT  ( filter()      ) );
159
160     connect( _secondaryFilters, SIGNAL( currentChanged( QWidget * ) ),
161              this,              SLOT  ( filter()                  ) );
162
163
164     //
165     // Status change view
166     //
167
168     _statusFilterView = new YQPkgStatusFilterView( parent );
169     Q_CHECK_PTR( _statusFilterView );
170     _secondaryFilters->addPage( _( "Installation Summary" ), _statusFilterView );
171
172     connect( _statusFilterView, SIGNAL( filterStart() ),
173              _repoList, SLOT  ( filter()      ) );
174
175
176     return _secondaryFilters;
177 }
178
179
180 void YQPkgRepoFilterView::filter()
181 {
182     _repoList->filter();
183 }
184
185
186 void YQPkgRepoFilterView::filterIfVisible()
187 {
188     _repoList->filterIfVisible();
189 }
190
191
192 void YQPkgRepoFilterView::primaryFilterMatch( ZyppSel   selectable,
193                                                  ZyppPkg        pkg )
194 {
195     if ( secondaryFilterMatch( selectable, pkg ) )
196         emit filterMatch( selectable, pkg );
197 }
198
199
200 void YQPkgRepoFilterView::primaryFilterNearMatch( ZyppSel       selectable,
201                                                      ZyppPkg    pkg )
202 {
203     if ( secondaryFilterMatch( selectable, pkg ) )
204         emit filterNearMatch( selectable, pkg );
205 }
206
207
208 bool
209 YQPkgRepoFilterView::secondaryFilterMatch( ZyppSel      selectable,
210                                               ZyppPkg   pkg )
211 {
212     if ( _allPackages->isVisible() )
213     {
214         return true;
215     }
216     else if ( _rpmGroupTagsFilterView->isVisible() )
217     {
218         return _rpmGroupTagsFilterView->check( selectable, pkg );
219     }
220     else if ( _searchFilterView->isVisible() )
221     {
222         return _searchFilterView->check( selectable, pkg );
223     }
224     else if ( _statusFilterView->isVisible() )
225     {
226         return _statusFilterView->check( selectable, pkg );
227     }
228     else
229     {
230         return true;
231     }
232 }
233
234
235
236
237
238
239 #include "YQPkgRepoFilterView.moc"