]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQSimplePatchSelector.cc
- Don't create layouts with parent. Qt 4.x automatically reparents
[duncan/yast2-qt4.git] / src / pkg / YQSimplePatchSelector.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQSimplePatchSelector.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   Textdomain "packages-qt"
18
19 /-*/
20
21 #include <QApplication>
22 #include <QBoxLayout>
23 #include <QHeaderView>
24 #include <QPushButton>
25 #include <QSplitter>
26
27 #define y2log_component "qt-pkg"
28 #include <ycp/y2log.h>
29
30 #include "QY2LayoutUtils.h"
31
32 #include "YQSimplePatchSelector.h"
33 #include "YQPkgConflictDialog.h"
34 #include "YQPkgDiskUsageList.h"
35 #include "YQPkgPatchFilterView.h"
36 #include "YQPkgPatchList.h"
37 #include "YQWizard.h"
38 #include "YQDialog.h"
39
40 #include "utf8.h"
41 #include "YQUI.h"
42 #include "YEvent.h"
43 #include "YQi18n.h"
44
45
46 using std::max;
47 using std::string;
48
49 #define SHOW_DISK_USAGE         0
50
51 #define SPACING                 6
52 #define MARGIN                  6
53
54
55
56 YQSimplePatchSelector::YQSimplePatchSelector( YWidget * parent, long modeFlags )
57     : YQPackageSelectorBase( parent, modeFlags )
58 {
59     _patchFilterView    = 0;
60     _patchList          = 0;
61     _diskUsageList      = 0;
62     _wizard             = findWizard();
63
64     basicLayout();
65     makeConnections();
66
67 #if 0
68     _patchList->fillList();
69     _patchList->selectSomething();
70 #endif
71
72     if ( _diskUsageList )
73         _diskUsageList->updateDiskUsage();
74 }
75
76
77
78 YQWizard *
79 YQSimplePatchSelector::findWizard() const
80 {
81     YQWizard * wizard = 0;
82
83     YQDialog * dialog = dynamic_cast<YQDialog *> ( YDialog::currentDialog() );
84
85     if ( dialog )
86         wizard = dialog->findWizard();
87
88     return wizard;
89 }
90
91
92
93 void
94 YQSimplePatchSelector::basicLayout()
95 {
96     QSplitter * splitter = new QSplitter( Qt::Vertical, this );
97     Q_CHECK_PTR( splitter );
98
99     //
100     // PatchFilterView
101     //
102
103     QBoxLayout *layout = new QVBoxLayout;
104     layout->setMargin( MARGIN );
105     QWidget * upper_vbox = new QWidget( splitter );
106     Q_CHECK_PTR( upper_vbox );
107     upper_vbox->setLayout(layout);
108     splitter->addWidget(upper_vbox);
109
110
111     splitter->setStretchFactor( 0, 1 );
112
113     _patchFilterView = new YQPkgPatchFilterView( upper_vbox );
114     Q_CHECK_PTR( _patchFilterView );
115     layout->addWidget(_patchFilterView);
116
117     _patchList = _patchFilterView->patchList();
118     Q_CHECK_PTR( _patchList );
119     
120     //addVSpacing( upper_vbox, MARGIN );
121
122     //
123     // Disk Usage
124     //
125
126
127 #if SHOW_DISK_USAGE
128     layout = new QVBoxLayout;
129     QWidget * lower_vbox = new QWidget( splitter );
130     lower_vbox->setLayout(layout);
131
132     Q_CHECK_PTR( lower_vbox );
133     //addVSpacing( lower_vbox, MARGIN );
134
135     _diskUsageList = new YQPkgDiskUsageList( lower_vbox );
136     Q_CHECK_PTR( _diskUsageList );
137     layout->addWidget(_diskUsageList);
138     
139     splitter->setResizeMode( lower_vbox, QSplitter::FollowSizeHint );
140 #endif
141
142
143     //
144     // Buttons
145     //
146     
147     if ( _wizard )      // No button box - add "Details..." button here
148     {
149         //
150         // "Details" button
151         //
152
153         //addVSpacing( this, SPACING );
154         layout = new QHBoxLayout;
155         QWidget * hbox = new QWidget( this );
156         Q_CHECK_PTR( hbox );
157         hbox->setLayout(layout);
158         QPushButton * details_button = new QPushButton( _( "&Details..." ), hbox );
159         layout->addWidget(details_button);
160         Q_CHECK_PTR( details_button );
161
162         connect( details_button, SIGNAL( clicked() ),
163                  this,           SLOT  ( detailedPackageSelection() ) );
164
165         //addHStretch( hbox );
166     }
167     else // ! _wizard
168     {
169         layoutButtons( this );
170     }
171 }
172
173
174 void
175 YQSimplePatchSelector::layoutButtons( QWidget * parent )
176 {
177     QWidget * button_box = new QWidget( parent );
178     QHBoxLayout *layout = new QHBoxLayout;
179     Q_CHECK_PTR( button_box );
180     button_box->setLayout(layout);
181     layout->setMargin ( MARGIN  );
182     layout->setSpacing( SPACING );
183
184
185     QPushButton * details_button = new QPushButton( _( "&Details..." ), button_box );
186     Q_CHECK_PTR( details_button );
187     layout->addWidget(details_button);
188     details_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
189
190     connect( details_button,    SIGNAL( clicked() ),
191              this,              SLOT  ( detailedPackageSelection() ) );
192
193
194     layout->addStretch();
195
196     QPushButton * cancel_button = new QPushButton( _( "&Cancel" ), button_box );
197     Q_CHECK_PTR( cancel_button );
198     layout->addWidget(cancel_button);
199     cancel_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
200
201     connect( cancel_button, SIGNAL( clicked() ),
202              this,          SLOT  ( reject()   ) );
203
204
205     QPushButton * accept_button = new QPushButton( _( "&Accept" ), button_box );
206     Q_CHECK_PTR( accept_button );
207     layout->addWidget(accept_button);
208     accept_button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); // hor/vert
209
210     connect( accept_button, SIGNAL( clicked() ),
211              this,          SLOT  ( accept()   ) );
212
213     button_box->setFixedHeight( button_box->sizeHint().height() );
214 }
215
216
217
218 void
219 YQSimplePatchSelector::makeConnections()
220 {
221     if ( _patchList && _diskUsageList )
222     {
223         connect( _patchList,     SIGNAL( updatePackages()  ),
224                  _diskUsageList, SLOT  ( updateDiskUsage() ) );
225     }
226
227     y2milestone( "Connection set up" );
228
229     if ( _wizard )
230     {
231         connect( _wizard,       SIGNAL( nextClicked()   ),
232                  this,          SLOT  ( accept()        ) );
233
234         connect( _wizard,       SIGNAL( backClicked()   ),
235                  this,          SLOT  ( reject()        ) );
236
237         connect( _wizard,       SIGNAL( abortClicked()  ),
238                  this,          SLOT  ( reject()        ) );
239     }
240 }
241
242
243 void
244 YQSimplePatchSelector::detailedPackageSelection()
245 {
246     y2milestone( "\"Details..\" button clicked" );
247     YQUI::ui()->sendEvent( new YMenuEvent( YCPSymbol( "details" ) ) );
248 }
249
250
251 void
252 YQSimplePatchSelector::debugTrace()
253 {
254     y2warning( "debugTrace" );
255 }
256
257
258
259 #include "YQSimplePatchSelector.moc"