]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgProductDialog.cc
picking up branches/tmp/sh/qt4-port/, merging it with trunk
[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
22 #define y2log_component "qt-pkg"
23 #include <ycp/y2log.h>
24
25 #include <qapplication.h>
26 #include <QtGui/qdesktopwidget.h>
27 #include <q3hbox.h>
28 #include <qlabel.h>
29 #include <qlayout.h>
30 #include <qpushbutton.h>
31 #include <qsplitter.h>
32 #include <qstyle.h>
33 #include <qtabwidget.h>
34 #include <q3valuelist.h>
35 //Added by qt3to4:
36 #include <q3boxlayout.h>
37
38 #include "YQPkgProductDialog.h"
39 #include "YQPkgProductList.h"
40 #include "YQPkgDependenciesView.h"
41 #include "QY2LayoutUtils.h"
42 #include "YQi18n.h"
43 #include "YQUI.h"
44
45
46 #define SPACING                 2       // between subwidgets
47 #define MARGIN                  4       // around the widget
48
49
50 YQPkgProductDialog::YQPkgProductDialog( QWidget * parent )
51     : QDialog( parent )
52 {
53     // Dialog title
54     setCaption( _( "Products" ) );
55
56     // Enable dialog resizing even without window manager
57     setSizeGripEnabled( true );
58
59     // Layout for the dialog (can't simply insert a QVBox)
60
61     Q3VBoxLayout * layout = new Q3VBoxLayout( this, MARGIN, SPACING );
62     Q_CHECK_PTR( layout );
63
64
65     // VBox for splitter
66
67     QSplitter * splitter = new QSplitter( Qt::Vertical, this );
68     Q_CHECK_PTR( splitter );
69     layout->addWidget( splitter );
70     splitter->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( selectionChanged    ( ZyppSel ) ),
98              _dependenciesView, SLOT  ( showDetailsIfVisible( ZyppSel ) ) );
99
100
101     // Button box (to center the single button)
102
103     Q3HBox * hbox = new Q3HBox( this );
104     Q_CHECK_PTR( hbox );
105     hbox->setSpacing( SPACING );
106     hbox->setMargin ( MARGIN  );
107     layout->addWidget( hbox );
108
109     addHStretch( hbox );
110
111
112     // "OK" button
113
114     QPushButton * button = new QPushButton( _( "&OK" ), hbox );
115     Q_CHECK_PTR( button );
116     button->setDefault( true );
117
118     connect( button,    SIGNAL( clicked() ),
119              this,      SLOT  ( accept()  ) );
120
121     addHStretch( hbox );
122 }
123
124
125 void
126 YQPkgProductDialog::polish()
127 {
128     // Delayed initialization after widget is fully created etc.
129
130     // Only now send selectionChanged() signal so the details views display something
131     // (showDetailsIfVisible() shows only something if the widget is visible,
132     // as the method name implies)
133     _productList->selectSomething();
134 }
135
136
137 QSize
138 YQPkgProductDialog::sizeHint() const
139 {
140     QRect available = qApp->desktop()->availableGeometry( (QWidget *) this );
141     QSize size = QDialog::sizeHint();
142     size = size.boundedTo( QSize( available.width(), available.height() ) );
143
144     return size;
145 }
146
147
148 void
149 YQPkgProductDialog::showProductDialog()
150 {
151     YQPkgProductDialog dialog( 0 );
152     dialog.exec();
153 }
154
155
156
157
158 #include "YQPkgProductDialog.moc"