- Don't create layouts with parent. Qt 4.x automatically reparents
[duncan/yast2-qt4.git] / src / pkg / YQPkgProductDialog.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgProductDialog.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   Textdomain "packages-qt"
18
19 /-*/
20
21 #define y2log_component "qt-pkg"
22 #include <ycp/y2log.h>
23
24 #include <QApplication>
25 #include <QtGui/qdesktopwidget.h>
26 #include <QHBoxLayout>
27 #include <QLabel>
28 #include <QLayout>
29 #include <QPushButton>
30 #include <QSplitter>
31 #include <QStyle>
32 #include <QTabWidget>
33 #include <QList>
34 #include <QBoxLayout>
35
36 #include "YQPkgProductDialog.h"
37 #include "YQPkgProductList.h"
38 #include "YQPkgDependenciesView.h"
39 #include "QY2LayoutUtils.h"
40 #include "YQi18n.h"
41 #include "YQUI.h"
42
43
44 #define SPACING                 2       // between subwidgets
45 #define MARGIN                  4       // around the widget
46
47
48 YQPkgProductDialog::YQPkgProductDialog( QWidget * parent )
49     : QDialog( parent )
50 {
51     // Dialog title
52     setWindowTitle( _( "Products" ) );
53
54     // Enable dialog resizing even without window manager
55     setSizeGripEnabled( true );
56
57     // Layout for the dialog (can't simply insert a QVBox)
58
59     QVBoxLayout * layout = new QVBoxLayout();
60     Q_CHECK_PTR( layout );
61     setLayout(layout);
62     layout->setSpacing( SPACING );
63     layout->setMargin ( MARGIN  );
64
65     // VBox for splitter
66
67     QSplitter * splitter = new QSplitter( Qt::Vertical, this );
68     Q_CHECK_PTR( splitter );
69     layout->addWidget( splitter );
70     layout->setMargin( MARGIN );
71
72
73     // Product list
74
75     _productList = new YQPkgProductList( splitter );
76     Q_CHECK_PTR( _productList );
77     _productList->resize( _productList->width(), 80 );
78
79     // Prevent status changes for now - this would require solver runs etc.
80     _productList->setEditable( false );
81
82
83     // Tab widget for details views (looks better even just with one)
84
85     _detailsViews = new QTabWidget( splitter );
86     Q_CHECK_PTR( _detailsViews );
87     //_detailsViews->setMargin( MARGIN );
88     _detailsViews->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); // hor/vert
89
90     // Dependencies view
91
92     _dependenciesView = new YQPkgDependenciesView( _detailsViews );
93     Q_CHECK_PTR( _dependenciesView );
94     _detailsViews->addTab( _dependenciesView, _( "Dependencies" ) );
95     _dependenciesView->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); // hor/vert
96
97     connect( _productList,      SIGNAL( currentItemChanged    ( ZyppSel ) ),
98              _dependenciesView, SLOT  ( showDetailsIfVisible( ZyppSel ) ) );
99
100
101     // Button box (to center the single button)
102
103     QHBoxLayout * hbox = new QHBoxLayout();
104     Q_CHECK_PTR( hbox );
105     hbox->setSpacing( SPACING );
106     hbox->setMargin ( MARGIN  );
107     layout->addLayout( hbox );
108
109     //addHStretch( hbox );
110
111
112     // "OK" button
113
114     QPushButton * button = new QPushButton( _( "&OK" ), this );
115     hbox->addWidget(button);
116     Q_CHECK_PTR( button );
117     button->setDefault( true );
118
119     connect( button,    SIGNAL( clicked() ),
120              this,      SLOT  ( accept()  ) );
121
122     //addHStretch( hbox );
123 }
124
125
126 void
127 YQPkgProductDialog::polish()
128 {
129     // Delayed initialization after widget is fully created etc.
130
131     // Only now send currentItemChanged() signal so the details views display something
132     // (showDetailsIfVisible() shows only something if the widget is visible,
133     // as the method name implies)
134     _productList->selectSomething();
135 }
136
137
138 QSize
139 YQPkgProductDialog::sizeHint() const
140 {
141     QRect available = qApp->desktop()->availableGeometry( (QWidget *) this );
142     QSize size = QDialog::sizeHint();
143     size = size.boundedTo( QSize( available.width(), available.height() ) );
144
145     return size;
146 }
147
148
149 void
150 YQPkgProductDialog::showProductDialog()
151 {
152     YQPkgProductDialog dialog( 0 );
153     dialog.exec();
154 }
155
156
157
158
159 #include "YQPkgProductDialog.moc"