1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgDescriptionDialog.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
22 #define y2log_component "qt-pkg"
23 #include <ycp/y2log.h>
25 #include <qapplication.h>
29 #include <qpushbutton.h>
30 #include <qsplitter.h>
32 #include <qvaluelist.h>
34 #include "YQPkgDescriptionDialog.h"
35 #include "YQPkgDescriptionView.h"
36 #include "YQPkgList.h"
37 #include "QY2LayoutUtils.h"
42 #define SPACING 2 // between subwidgets
43 #define MARGIN 4 // around the widget
46 YQPkgDescriptionDialog::YQPkgDescriptionDialog( QWidget * parent, const QString & pkgName )
50 setCaption( _( "Package Description" ) );
52 // Enable dialog resizing even without window manager
53 setSizeGripEnabled( true );
55 // Layout for the dialog (can't simply insert a QVBox)
57 QVBoxLayout * layout = new QVBoxLayout( this, MARGIN, SPACING );
63 QSplitter * splitter = new QSplitter( QSplitter::Vertical, this );
64 CHECK_PTR( splitter );
65 layout->addWidget( splitter );
66 splitter->setMargin( MARGIN );
71 _pkgList = new YQPkgList( splitter );
72 CHECK_PTR( _pkgList );
73 _pkgList->resize( _pkgList->width(), 80 );
78 _pkgDescription = new YQPkgDescriptionView( splitter );
79 CHECK_PTR( _pkgDescription );
80 _pkgDescription->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); // hor/vert
82 connect( _pkgList, SIGNAL( selectionChanged ( ZyppSel ) ),
83 _pkgDescription, SLOT ( showDetailsIfVisible( ZyppSel ) ) );
86 // Button box (to center the single button)
88 QHBox * hbox = new QHBox( this );
90 hbox->setSpacing( SPACING );
91 hbox->setMargin ( MARGIN );
92 layout->addWidget( hbox );
99 QPushButton * button = new QPushButton( _( "&OK" ), hbox );
101 button->setDefault( true );
103 connect( button, SIGNAL( clicked() ),
104 this, SLOT ( accept() ) );
114 YQPkgDescriptionDialog::filter( const QString & qPkgName )
116 std::string pkgName( (const char *) qPkgName );
117 YQUI::ui()->busyCursor();
121 // Search for pkgs with that name
123 for ( ZyppPoolIterator it = zyppPkgBegin();
127 ZyppObj zyppObj = (*it)->theObj();
129 if ( zyppObj && zyppObj->name() == pkgName )
130 _pkgList->addPkgItem( *it, tryCastToZyppPkg( zyppObj ) );
134 // Display description of the first pkg with that name
136 YQPkgObjListItem * firstItem = dynamic_cast<YQPkgObjListItem *> ( _pkgList->firstChild() );
139 _pkgDescription->showDetailsIfVisible( firstItem->selectable() );
141 _pkgDescription->clear();
143 YQUI::ui()->normalCursor();
148 YQPkgDescriptionDialog::isEmpty() const
150 return _pkgList->firstChild() == 0;
155 YQPkgDescriptionDialog::sizeHint() const
157 QRect available = qApp->desktop()->availableGeometry( (QWidget *) this );
158 QSize size = QDialog::sizeHint();
159 size = size.boundedTo( QSize( available.width(), available.height() ) );
166 YQPkgDescriptionDialog::showDescriptionDialog( const QString & pkgName )
168 YQPkgDescriptionDialog dialog( 0, pkgName );
175 #include "YQPkgDescriptionDialog.moc"